56 lines
1.3 KiB
JavaScript
Executable File
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();
|
|
})
|
|
}
|
|
});
|