Skip to content

Commit

Permalink
publish v3.0.6 support change img with one-click
Browse files Browse the repository at this point in the history
  • Loading branch information
bergwhite committed Jul 24, 2017
1 parent b042cbd commit fc4f970
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/)

> 目录
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nodejs-chat",
"version": "3.0.5",
"version": "3.0.6",
"private": true,
"scripts": {
"build": "gulp build",
Expand Down
12 changes: 10 additions & 2 deletions public/src/js/userInfoMod.js
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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) => {
Expand Down
5 changes: 1 addition & 4 deletions views/user/userInfoMod.ejs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="user-info-wrap animated fadeIn">
<div class="user-info-img-wrap">
<div>
<img class="user-info-img" src=<%= img %>>
<img class="user-info-img info-img" src=<%= img %>>
</div>
<div>
<input placeholder="用户" class="input-default" type="text" disabled="disabled" value=<%= user %>>
Expand All @@ -15,9 +15,6 @@
<div>
<input placeholder="爱好" class="input-default info-hobbies" type="text" value=<%= hobbies %>>
</div>
<div>
<input placeholder="图片" class="input-default info-img" type="text" value=<%= img %>>
</div>
<span class="info-tip"></span>
</div>
</div>

0 comments on commit fc4f970

Please sign in to comment.