1
0
Code Issues Pull Requests Packages Projects Releases Wiki Activity GitHub Gitee

微信小程序 提审时隐藏功能;微信小程序添加微信快捷登录、随便看看(登的user用户)

This commit is contained in:
2023-04-17 02:36:04 +08:00
parent 62ed92029c
commit 0238251ab0
29 changed files with 1205 additions and 624 deletions

View File

@@ -1,6 +1,7 @@
// pages/index/index.js
const menuItemDict = require('../../utils/menuList.js')
const getUserGroupByRole = require('../../utils/getUserGroupByRole.js')
const toggleCustomTabBar = require('../../custom-tab-bar/toggleCustomTabBar')
import scanQRCode from '../../utils/scanQRCode'
@@ -22,6 +23,7 @@ Page({
* 生命周期函数--监听页面加载
*/
onLoad(options) {
toggleCustomTabBar.toggle(this)
console.log("index/index onLoad", options)
// console.log("wx.getLaunchOptionsSync()", wx.getLaunchOptionsSync())
@@ -39,7 +41,7 @@ Page({
debugText: JSON.stringify(options, null, 4),
userInfo: userInfo,
userGroup: userGroup,
displayUsername: userInfo?.username ?? "请登录",
displayUsername: userInfo ? (`${userInfo.realname} (${userInfo.username})`) : "请登录",
filterMenuItems: this.getFilterMenuItems(menuItemDict, userGroup)
})
console.log("menuItemDict", menuItemDict)
@@ -82,6 +84,7 @@ Page({
* 生命周期函数--监听页面显示
*/
onShow() {
toggleCustomTabBar.toggle(this)
console.log("index/index onShow")
},
@@ -122,8 +125,21 @@ Page({
getFilterMenuItems(menuItemDict, userGroup) {
return Object.values(menuItemDict)
let filterMenuItems = Object.values(menuItemDict)
.filter((item) => item.for.indexOf(userGroup) != -1)
// 动态控制显示隐藏
let indexItem = wx.getStorageSync('indexItem') || [
"/pages/index/login",
"/pages/person/person"
]
filterMenuItems = filterMenuItems
.filter((item) => {
let a = indexItem.includes(item.url)
console.log("filterMenuItems -> filter", item.url, indexItem)
return a
})
return filterMenuItems
},

View File

@@ -15,11 +15,11 @@ Page({
* 生命周期函数--监听页面加载
*/
onLoad(options) {
if (app.globalData.debugMode) {
this.setData({
debugMode: true,
})
}
// if (app.globalData.debugMode) {
// this.setData({
// debugMode: true,
// })
// }
},
/**
@@ -81,12 +81,54 @@ Page({
fastLogin() {
this.setData({
username: "user",
password: "user",
username: "#fastLogin#",
password: "#fastLogin#",
})
this.login()
},
wxLogin() {
var that = this
wx.login({
success(res) {
if (res.code) {
wx.showLoading({
title: '加载中'
})
wx.request({
url: app.globalData.baseUrl + '/user/wxlogin',
method: "POST",
header: {
"Content-Type": "application/x-www-form-urlencoded" //用于post
},
data: {
code: res.code
},
success: function (d) {
wx.hideLoading()
that._loginSuccessCallback(d)
},
fail: function () {
wx.hideLoading()
wx.showToast({
title: "请求失败",
icon: 'error',
duration: 2000
})
}
})
} else {
console.log('登录失败!' + res.errMsg)
wx.showModal({
title: '登录失败',
content: '您点击了取消按钮' + res.errMsg,
showCancel: false
})
}
}
})
},
login() {
console.log("login userInput", this.data.username, this.data.password)
if (!this.data.username || !this.data.password) {
@@ -96,6 +138,7 @@ Page({
duration: 2000
})
} else {
var that = this
wx.showLoading({
title: '加载中'
})
@@ -111,32 +154,7 @@ Page({
},
success: function (d) {
wx.hideLoading()
let result = d.data;
if (result.success) {
// 登录成功
if (![3, 4, 5, 6].includes(result.data.userInfo.roleId)) {
wx.showModal({
title: '你不是社区居民',
content: '管理员请前往网页版登录',
showCancel: false,
complete: (res) => {
//
}
})
return
}
wx.setStorageSync("userInfo", result.data.userInfo);
console.log("userInfo", wx.getStorageSync("userInfo"))
wx.switchTab({
url: '/pages/index/index'
})
} else {
wx.showToast({
title: result.msg,
icon: 'error',
duration: 2000
})
}
that._loginSuccessCallback(d)
},
fail: function () {
wx.hideLoading()
@@ -148,5 +166,34 @@ Page({
}
})
}
},
_loginSuccessCallback(d) {
let result = d.data;
if (result.success) {
// 登录成功
if (![3, 4, 5, 6].includes(result.data.userInfo.roleId)) {
wx.showModal({
title: '你不是社区居民',
content: '管理员请前往网页版登录',
showCancel: false,
complete: (res) => {
//
}
})
return
}
wx.setStorageSync("userInfo", result.data.userInfo);
console.log("userInfo", wx.getStorageSync("userInfo"))
wx.switchTab({
url: '/pages/index/index'
})
} else {
wx.showToast({
title: result.msg,
icon: 'error',
duration: 2000
})
}
}
})

View File

@@ -12,9 +12,11 @@
</view>
<view class="loginBtnView">
<!--按钮-->
<button wx:if="{{debugMode}}" class="loginBtn" type="warn" bindtap="fastLogin">DEBUG快速登录user</button>
<button class="loginBtn" type="primary" bindtap="login">登录</button>
<button class="loginBtn" type="secondary" bindtap="visitor">访客申请</button>
<!-- <button wx:if="{{debugMode}}" class="loginBtn" type="warn" bindtap="fastLogin">DEBUG快速登录user</button> -->
<button class="loginBtn" type="primary" bindtap="login">密码登录</button>
<!-- <button class="loginBtn" type="secondary" bindtap="visitor">访客申请</button> -->
<button class="loginBtn" type="primary" bindtap="wxLogin">微信登录/注册</button>
<button class="loginBtn" type="secondary" bindtap="fastLogin">随便看看</button>
</view>
</view>
</view>