增加了更改用户的功能

smart_class
educoder_weapp 5 years ago
parent bf2aaac3b1
commit 0f3f8b274b

@ -1,6 +1,8 @@
{
"pages": [
"pages/classes/classes",
"pages/changeuser/changeuser",
"pages/index/index",
"pages/config/config",
"pages/https/https",
@ -9,7 +11,9 @@
"pages/game/game",
"pages/shouquan/shouquan",
"pages/outside/outside",
"pages/classroom/classroom"
"pages/classroom/classroom",
"pages/setting/setting",
"pages/user/user"
],
"window": {
"backgroundTextStyle": "light",

@ -1,10 +1,26 @@
page, .lab {
page {
height: 100%;
background-color: #f2f2f2;
}
.flex-wrap{
display: flex;
flex-direction: row;
}
.form-wrap {
border-top: 1px solid #eee;
margin: 8px 0;
}
.tappable:hover {
opacity: .6;
}
.hint,
.error {
display: block;
margin: 8px 0;
color: #888;
font-size: 14px;
}
.lab {
display: flex;

Binary file not shown.

After

Width:  |  Height:  |  Size: 1018 B

@ -0,0 +1,88 @@
// pages/changeuser/changeuser.js
const AV = require("../../lib/av-live-query-weapp-min")
const { jsonify } = require("../../utils/leancloudutils")
Page({
/**
* 页面的初始数据
*/
data: {
current_user: {},
users: []
},
login: function(event){
username = event.currentTarget.dataset.username;
//console.log(event);
console.log(username);
AV.User.logIn(username, "123456").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.setData(jsonify({users}))});
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})

@ -0,0 +1,5 @@
{
"usingComponents": {},
"navigationBarTitleText": "更改登陆用户",
"enablePullDownRefresh": false
}

@ -0,0 +1,15 @@
<!--pages/changeuser/changeuser.wxml-->
<view class="container">
<view class="current_user">
<text>当前登陆用户: </text><text class="hint">姓 名:{{current_user.name}}</text>
<text class="hint">用户名:{{current_user.username}}</text>
</view>
<text>点击切换用户:</text>
<view class="user-list form-wrap">
<block wx:for="{{users}}" wx:for-item="user" wx:key="objectId">
<view class="user-item" bindtap="login" data-username="{{user.username}}">
<text>{{user.name}}</text><text class="hint">{{user.username}}</text>
</view>
</block>
</view>
</view>

@ -0,0 +1,15 @@
/* pages/changeuser/changeuser.wxss */
.user-list{
display: flex;
flex-direction: column;
}
.user-item{
background: white;
border-bottom: 1px solid #eee;
padding: 16rpx 16px;
position: relative;
}
.user-item text{
vertical-align: middle;
}

@ -1,4 +1,5 @@
{
"navigationBarTitleText": "课程列表",
"usingComponents": {},
"enablePullDownRefresh": true
}

@ -5,10 +5,15 @@ classes: 课程列表 type: Array
class.objectId 唯一键
class.name 课程名称
-->
<view class="class-list">
<block wx:for="{{classes}}" wx:for-item="class" wx:key="objectId">
<view class="flex-wrap classroom" data-class_id="{{class.objectId}}" data-class_name="{{class.name}}" bindtap="enter_class">
<view class="form-wrap">
<view class="class-list">
<block wx:for="{{classes}}" wx:for-item="class" wx:key="objectId">
<view class="classroom" data-class_id="{{class.objectId}}" data-class_name="{{class.name}}" bindtap="enter_class">
<text>{{class.name}}</text>
</view>
</block>
</block>
</view>
<view class="footer">
<navigator url="../setting/setting" class="setting tappable">设置</navigator>
</view>
</view>

@ -1,28 +1,46 @@
.header {
height: 54px;
align-items: center;
background-color: #FFF;
}
.class-list {
padding: 4px 6px 48px;
display: flex;
flex-direction: column;
}
.classroom {
font-size: 18px;
height: 30px;
padding: 10px 12px;
overflow: hidden;
align-items: center;
background-color: #fff;
margin: 1px 0;
border-radius: 3px;
background: white;
padding: 30rpx 12px;
border-bottom: 1rpx solid #EEE;
position: relative;
}
.classroom text {
white-space: nowrap;
.classroom:after {
content: '进入课堂>';
display: block;
position: absolute;
right: 3rpx;
top: 50%;
height: 40rpx;
line-height: 40rpx;
margin-top: -20rpx;
margin-right: 30rpx;
color: #999;
}
.classroom text {
vertical-align: middle;
}
.classroom icon {
margin-right: 25rpx;
}
.footer {
position: fixed;
bottom: 0;
height: 44px;
width: 100%;
height: 50px;
line-height: 17px;
line-height: 44px;
color: #666;
border-top: 1px solid #eee;
background: #fff;
font-size: 16px;
text-align: center;
}

@ -45,7 +45,7 @@ Page({
ask: function (event) {
//学生提问的函数
console.log(event);
set_asking()
//set_asking()
},
rep: function (event) {
console.log(event);

@ -0,0 +1,4 @@
{
"navigationBarTitleText": "设置",
"enablePullDownRefresh": false
}

@ -0,0 +1,4 @@
<view class="form-wrap">
<navigator url="../user/user" class="navigator user">更改用户名密码</navigator>
<navigator url="../changeuser/changeuser" class="navigator user">更改登陆用户</navigator>
</view>

@ -0,0 +1,7 @@
.navigator {
background: white;
border-bottom: 1px solid #eee;
padding: 0 12px;
height: 46px;
line-height: 46px;
}

@ -0,0 +1,56 @@
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,
});
});
}
});

@ -0,0 +1,4 @@
{
"navigationBarTitleText": "登陆信息修改",
"enablePullDownRefresh": false
}

@ -0,0 +1,16 @@
<view class="container">
<view class="form-wrap">
<view class="flex-wrap input-wrap">
<text class="label">用户名</text>
<input value="{{username}}" bindinput="updateUsername" id="username" class="account-info-input"/>
</view>
<view class="flex-wrap input-wrap">
<text class="label">新密码</text>
<input password bindinput="updatePassword" id="password" class="account-info-input"/>
</view>
</view>
<text wx:if="{{error}}" class="error">{{error}}</text>
<button class="submit" type="primary" disabled="{{!(username || password)}}" bindtap="save">更新</button>
<text class="hint">当前用户 authData: </text>
<textarea class="hint" auto-height='true' disabled maxlength="-1" value="{{authData}}"></textarea>
</view>

@ -0,0 +1,21 @@
.input-wrap {
background: #fff;
border-bottom: 1px solid #eee;
margin: 0 -12px;
padding: 0 12px;
height: 46px;
line-height: 46px;
}
.label {
color: #999;
width: 4.5em;
}
.account-info-input {
font-size: 18px;
line-height: 100%;
height: 100%;
width: 100%;
}
textarea {
width: 100%;
}
Loading…
Cancel
Save