From fc4f97096405e6875774c049d38a5b3e3e0571a8 Mon Sep 17 00:00:00 2001 From: bergwhite Date: Tue, 25 Jul 2017 07:05:50 +0800 Subject: [PATCH] publish v3.0.6 support change img with one-click --- README.md | 4 +++- package.json | 2 +- public/src/js/userInfoMod.js | 12 ++++++++++-- views/user/userInfoMod.ejs | 5 +---- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index d97106e..322e4b5 100644 --- a/README.md +++ b/README.md @@ -13,8 +13,10 @@ ![NChat-qrcode](http://nchat.oss-cn-beijing.aliyuncs.com/img/NChat-qrcode.png ) -* [全栈式的开发多人在线聊天室](http://47.93.252.247:8086/) +* 全栈式的开发多人在线聊天室 * 项目只适配了移动端,请使用浏览器的手机视图查看。 + * 项目源码:[https://github.com/bergwhite/nchat](https://github.com/bergwhite/nchat) + * 在线演示:[http://47.93.252.247:8086/](http://47.93.252.247:8086/) > 目录 diff --git a/package.json b/package.json index c54838c..c24c3bd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nodejs-chat", - "version": "3.0.5", + "version": "3.0.6", "private": true, "scripts": { "build": "gulp build", diff --git a/public/src/js/userInfoMod.js b/public/src/js/userInfoMod.js index 0728c62..d197a04 100644 --- a/public/src/js/userInfoMod.js +++ b/public/src/js/userInfoMod.js @@ -1,16 +1,24 @@ (() => { const userInfoGender = document.getElementsByClassName('info-gender')[0] const userInfoImg = document.getElementsByClassName('info-img')[0] + const userDisImg = document.getElementsByClassName('user-info-img')[0] const userInfoCity = document.getElementsByClassName('info-city')[0] const userInfoHobbies = document.getElementsByClassName('info-hobbies')[0] const infoTip = document.getElementsByClassName('info-tip')[0] const infoModBtn = document.getElementsByClassName('top-next')[0] const siteOrigin = document.location.origin const ajaxUrl = `${siteOrigin}/api/user/info` - + let currentImg = '' + // 页面加载完成的时候,聚焦用户性别输入框 document.body.onload = () => userInfoGender.focus(); + // 监听点击头像换图片 + userInfoImg.addEventListener('click', (e) => { + currentImg = getRandomImg('men') + userDisImg.src = currentImg + }, false) + // 监听信息修改按钮的点击事件 infoModBtn.addEventListener('click', (e) => { e.preventDefault() @@ -26,7 +34,7 @@ function submitModUserInfo() { axios.put(ajaxUrl,{ gender: userInfoGender.value, - img: userInfoImg.value, + img: currentImg, city: userInfoCity.value, hobbies: userInfoHobbies.value }).then((res) => { diff --git a/views/user/userInfoMod.ejs b/views/user/userInfoMod.ejs index d9f874d..253c4d5 100644 --- a/views/user/userInfoMod.ejs +++ b/views/user/userInfoMod.ejs @@ -1,7 +1,7 @@
\ No newline at end of file