Files
bsmall/pages/changePwd/changePwd.js
2020-09-24 11:08:03 +08:00

56 lines
1.3 KiB
JavaScript
Executable File

const api = require("../../api/api"),
app = getApp()
Page({
data: {
userInfo: ""
},
onLoad() {
this.setData({
userInfo: app.globalData.userInfo
})
},
// 修改密码
changePwd(e){
my.showLoading();
api.request({
url : "users/password",
header: {
"Authorization": app.globalData.token
},
method: "POST",
data : {
oldpassword : e.detail.value.old,
password : e.detail.value.password,
password_confirmation : e.detail.value.confirmation
}
}).then(res=>{
my.hideLoading();
// 存储全局信息
app.globalData.isUser = true
app.globalData.token = res.data.access_token
app.globalData.expires = Math.round(new Date() / 1000) + res.data.expires_in
// 缓存信息本地
my.setStorage({
key : "userToken",
data : {
token : res.data.access_token,
expires : Math.round(new Date() / 1000) + res.data.expires_in
}
})
my.alert({
content : "密码修改成功",
success: () => {
my.navigateBack();
}
});
}).catch(err=>{
my.showToast({
content: err.data.message
});
my.hideLoading();
})
}
});