const app = getApp();
|
const avatorPic = '/static/avator.png';
|
const api = require('../../../utils/api');
|
const cloudApi = require('../../../utils/cloudApi')
|
Page({
|
data: {
|
page: 'pages/tabBar/count/count',
|
statusBarHeight: '',
|
username: '',
|
user: {},
|
avator: avatorPic,
|
showModal: false,
|
pwdForm: {
|
id: null,
|
password: '',
|
rePassword: ''
|
},
|
isPwd1: true,
|
isPwd2: true,
|
},
|
|
onLoad() {
|
this.setData({
|
statusBarHeight: wx.getSystemInfoSync()['statusBarHeight'],
|
username: wx.getStorageSync('username'),
|
user: wx.getStorageSync('userSet') || {}
|
});
|
wx.hideTabBar();
|
},
|
|
onFormInput(e) {
|
const field = e.currentTarget.dataset.field; // 获取字段名
|
this.setData({
|
[field]: e.detail.value // 动态更新对应字段
|
});
|
},
|
|
toHazmat() {
|
wx.setStorageSync("prevPage", '/pages/tabBar/count/count');
|
wx.navigateTo({
|
url: '/pages/tabBar/count/countDetail'
|
});
|
},
|
|
toProduct() {
|
wx.setStorageSync("prevPage", '/pages/tabBar/count/count');
|
wx.navigateTo({
|
url: '/pages/tabBar/count/productDetail'
|
});
|
},
|
|
loginOut() {
|
wx.showModal({
|
title: '提示',
|
content: '是否确认退出该账号?',
|
success: (res) => {
|
if (res.confirm) {
|
wx.clearStorageSync();
|
wx.navigateTo({
|
url: '/pages/index/index'
|
});
|
// api接口
|
// api.loginOut().then(res => {
|
// if(res.code == 200) {
|
// wx.showToast({
|
// title: '账户已退出',
|
// duration: 800
|
// });
|
// setTimeout(() => {
|
// wx.clearStorageSync();
|
// wx.navigateTo({
|
// url: '/pages/index/index'
|
// });
|
// }, 800);
|
// }
|
// });
|
}
|
}
|
});
|
},
|
|
openResetPwd() {
|
console.log(this.data.showModal,1)
|
this.setData({
|
showModal: true
|
});
|
console.log(this.data.showModal,2)
|
},
|
|
togglePwd1() {
|
this.setData({
|
isPwd1: !this.data.isPwd1
|
});
|
},
|
|
togglePwd2() {
|
this.setData({
|
isPwd2: !this.data.isPwd2
|
});
|
},
|
|
confirmPwd() {
|
// 密码验证
|
if (!this.data.pwdForm.password) {
|
wx.showToast({
|
title: '新密码不可为空',
|
icon: 'error'
|
});
|
return;
|
}
|
if (!/^(?![a-zA-Z]+$)(?!\d+$)(?![!@#$%^&\.*]+$)(?![a-zA-Z\d]+$)(?![a-zA-Z!@#$%^&\.*]+$)(?![\d!@#$%^&\.*]+$)[a-zA-Z\d!@#$%^&\.*\-_]{6,16}$/.test(this.data.pwdForm.password)) {
|
wx.showToast({
|
title: '密码须同时包含字母、数字和特殊字符,长度在6-16之间',
|
icon: 'none'
|
});
|
return;
|
}
|
if (!this.data.pwdForm.rePassword) {
|
wx.showToast({
|
title: '请再次输入新密码',
|
icon: 'error'
|
});
|
return;
|
}
|
|
if (this.data.pwdForm.password !== this.data.pwdForm.rePassword) {
|
wx.showToast({
|
title: '两次输入密码不一致',
|
icon: 'none'
|
});
|
return;
|
}
|
const Id = wx.getStorageSync("uid")
|
|
cloudApi.updateKey('userList',Id,{password: this.base64Encode(this.data.pwdForm.password)}).then(res=>{
|
if(res.result == 'success'){
|
wx.showToast({
|
title: '密码已修改,请重新登录',
|
icon: 'none',
|
duration: 1500
|
});
|
wx.clearStorageSync();
|
wx.navigateTo({
|
url: '/pages/index/index'
|
});
|
}else{
|
wx.showToast({
|
title: 密码修改失败,
|
duration: 2000
|
});
|
}
|
})
|
// const db = wx.cloud.database()
|
// db.collection('userList').doc(Id).update({
|
// data: {
|
// password: this.base64Encode(this.data.pwdForm.password)
|
// },
|
// success: function(res) {
|
// wx.showToast({
|
// title: '密码已修改,请重新登录',
|
// icon: 'none',
|
// duration: 1000
|
// });
|
// wx.clearStorageSync();
|
// wx.navigateTo({
|
// url: '/pages/index/index'
|
// });
|
// },
|
// error: function(res){
|
// wx.showToast({
|
// title: 密码修改失败,
|
// duration: 2000
|
// });
|
// }
|
// })
|
|
// api请求
|
// let data = {
|
// id: wx.getStorageSync("uid"),
|
// password: this.base64Encode(this.data.pwdForm.password)
|
// };
|
// api.resetPwd(data).then((r) => {
|
// if(r.code == 200) {
|
// wx.showToast({
|
// title: '密码已修改,请重新登录',
|
// icon: 'none',
|
// duration: 1000
|
// });
|
// loginOut().then(res => {
|
// if(res.code == 200) {
|
// setTimeout(() => {
|
// wx.clearStorageSync();
|
// wx.navigateTo({
|
// url: '/pages/index/index'
|
// });
|
// }, 1000);
|
// }
|
// });
|
// } else {
|
// wx.showToast({
|
// title: r.message,
|
// icon: 'none'
|
// });
|
// }
|
// }).catch((err) => {
|
// wx.showToast({
|
// title: err,
|
// duration: 2000
|
// });
|
// });
|
|
this.closeModal();
|
},
|
|
base64Encode(e) {
|
const utf8Bytes = unescape(encodeURIComponent(e));
|
const array = new Uint8Array(utf8Bytes.length);
|
for (let i = 0; i < utf8Bytes.length; i++) {
|
array[i] = utf8Bytes.charCodeAt(i);
|
}
|
return wx.arrayBufferToBase64(array);
|
},
|
|
closeModal() {
|
this.setData({
|
showModal: false,
|
pwdForm: {
|
id: null,
|
password: '',
|
rePassword: ''
|
},
|
isPwd1: true,
|
isPwd2: true
|
});
|
}
|
});
|