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.
|
|
|
// pages/changeuser/changeuser.js
|
|
|
|
const AV = require("../../lib/av-live-query-weapp-min")
|
|
|
|
const { jsonify } = require("../../utils/leancloudutils")
|
|
|
|
|
|
|
|
Page({
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 页面的初始数据
|
|
|
|
*/
|
|
|
|
users: null,
|
|
|
|
data: {
|
|
|
|
current_user: {},
|
|
|
|
users: []
|
|
|
|
},
|
|
|
|
login: function(event){
|
|
|
|
username = event.currentTarget.dataset.username;
|
|
|
|
if(username==this.data.current_user.username){
|
|
|
|
wx.showToast({
|
|
|
|
title: "已登陆该用户",
|
|
|
|
icon:"none"
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
console.log(username);
|
|
|
|
user = this.users.filter(user=>user.get("username")==username)[0];
|
|
|
|
passwd = user.get("passwd")?user.get("passwd"):"123456";
|
|
|
|
console.log(user.get("passwd"));
|
|
|
|
console.log("passwd");
|
|
|
|
AV.User.logIn(username, passwd).then((user)=>{
|
|
|
|
this.setData(jsonify({current_user: AV.User.current()}));
|
|
|
|
wx.showToast({
|
|
|
|
title: '更改用户成功',
|
|
|
|
icon: 'success',
|
|
|
|
});},
|
|
|
|
(error)=>{
|
|
|
|
wx.showToast({
|
|
|
|
title: "抱歉,暂时无法登陆此用户",
|
|
|
|
icon: "none"})
|
|
|
|
}).catch(error=>console.error(error.message));
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面加载
|
|
|
|
*/
|
|
|
|
onLoad: function (options) {
|
|
|
|
this.setData(jsonify({current_user: AV.User.current()}));
|
|
|
|
query = new AV.Query("User");
|
|
|
|
return query.find().then((users)=>{
|
|
|
|
this.users = users;
|
|
|
|
this.setData(jsonify({users}));
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
|
|
*/
|
|
|
|
onReady: function () {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面显示
|
|
|
|
*/
|
|
|
|
onShow: function () {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面隐藏
|
|
|
|
*/
|
|
|
|
onHide: function () {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面卸载
|
|
|
|
*/
|
|
|
|
onUnload: function () {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
|
|
*/
|
|
|
|
onPullDownRefresh: function () {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 页面上拉触底事件的处理函数
|
|
|
|
*/
|
|
|
|
onReachBottom: function () {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 用户点击右上角分享
|
|
|
|
*/
|
|
|
|
onShareAppMessage: function () {
|
|
|
|
|
|
|
|
}
|
|
|
|
})
|