You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.0 KiB
56 lines
1.0 KiB
5 years ago
|
const { User } = require('../../lib/av-live-query-weapp-min');
|
||
|
|
||
|
Page({
|
||
|
data: {
|
||
|
username: '',
|
||
|
password: '',
|
||
|
error: null,
|
||
|
authData: '',
|
||
|
},
|
||
|
onLoad: function() {
|
||
|
const user = User.current();
|
||
|
if (user) {
|
||
|
this.setData({
|
||
|
username: user.get('username'),
|
||
|
authData: JSON.stringify(user.get('authData'), undefined, 2),
|
||
|
});
|
||
|
}
|
||
|
},
|
||
|
updateUsername: function ({
|
||
|
detail: {
|
||
|
value
|
||
|
}
|
||
|
}) {
|
||
|
this.setData({
|
||
|
username: value
|
||
|
});
|
||
|
},
|
||
|
updatePassword: function ({
|
||
|
detail: {
|
||
|
value
|
||
|
}
|
||
|
}) {
|
||
|
this.setData({
|
||
|
password: value
|
||
|
});
|
||
|
},
|
||
|
save: function () {
|
||
|
this.setData({
|
||
|
error: null,
|
||
|
});
|
||
|
const { username, password } = this.data;
|
||
|
const user = User.current();
|
||
|
if (username) user.set({ username });
|
||
|
if (password) user.set({ password });
|
||
|
user.save().then(() => {
|
||
|
wx.showToast({
|
||
|
title: '更新成功',
|
||
|
icon: 'success',
|
||
|
});
|
||
|
}).catch(error => {
|
||
|
this.setData({
|
||
|
error: error.message,
|
||
|
});
|
||
|
});
|
||
|
}
|
||
|
});
|