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.

110 lines
2.3 KiB

// pages/changeuser/changeuser.js
const AV = require("../../lib/av-live-query-weapp-min")
const { jsonify } = require("../../utils/leancloudutils")
Page({
/**
* 页面的初始数据
*/
users: [],
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));
},
pull_users: function(limit){
this.setData(jsonify({ current_user: AV.User.current() }));
query = new AV.Query("User");
query.limit(limit);
query.ascending('createdAt');
query.skip(this.users.length);
return query.find().then((users) => {
this.users = this.users.concat(users);
this.setData(jsonify({ users: this.users}));
});
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.pull_users(15);
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
this.users = [];
this.pull_users(50);
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
console.log("onReachBottom")
this.pull_users(50);
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})