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,20 +1,27 @@
// app.js
App({
onLaunch() {
// 展示本地存储能力
const logs = wx.getStorageSync('logs') || []
logs.unshift(Date.now())
wx.setStorageSync('logs', logs)
// 登录
wx.login({
success: res => {
// 发送 res.code 到后台换取 openId, sessionKey, unionId
}
})
const toggleCustomTabBar = require('./custom-tab-bar/toggleCustomTabBar')
App({
async onLaunch() {
// 获取下拉框信息
toggleCustomTabBar.updateConfig(this.globalData.baseUrl)
// // 展示本地存储能力
// const logs = wx.getStorageSync('logs') || []
// logs.unshift(Date.now())
// wx.setStorageSync('logs', logs)
// // 登录
// wx.login({
// success: res => {
// // 发送 res.code 到后台换取 openId, sessionKey, unionId
// }
// })
},
globalData: {
debugMode: true, // 是否展示调试内容
// debugMode: true, // 是否展示调试内容
baseUrl: true ? // Api 请求域名 不带最后的 /
"https://epp.only4.work" :
"http://localhost",

View File

@@ -19,10 +19,11 @@
"navigationBarTextStyle": "white"
},
"tabBar": {
"custom": false,
"color": "#000000",
"backgroundColor": "#fff",
"selectedColor": "#FF8966",
"custom": true,
"————custom": false,
"————color": "#000000",
"————backgroundColor": "#fff",
"————selectedColor": "#FF8966",
"list": [
{
"pagePath": "pages/index/index",

View File

@@ -0,0 +1,55 @@
Component({
data: {
selected: 0,
color: "#000000",
selectedColor: "#FF8966",
list: null, // 在 toggleCustomTabBar.js 中动态设置下面的菜单项
rawList: [
{
"pagePath": "pages/index/index",
"text": "首页",
"iconPath": "image/icon/_home.png",
"selectedIconPath": "image/icon/home.png"
},
{
"pagePath": "pages/residents/code",
"text": "进出码",
"iconPath": "image/icon/_code.png",
"selectedIconPath": "image/icon/code.png"
},
{
"pagePath": "pages/residents/report",
"text": "体温上报",
"iconPath": "image/icon/_report.png",
"selectedIconPath": "image/icon/report.png"
},
{
"pagePath": "pages/shop/shop",
"text": "生活物资",
"iconPath": "image/icon/_shopping.png",
"selectedIconPath": "image/icon/shopping.png"
},
{
"pagePath": "pages/person/person",
"text": "我",
"iconPath": "image/icon/_person.png",
"selectedIconPath": "image/icon/person.png"
}
]
},
onShow() {
console.log("[CustomTabBar] onLoad")
},
attached() {
},
methods: {
switchTab(e) {
const data = e.currentTarget.dataset
const url = '/' + data.path
wx.switchTab({ url })
this.setData({
selected: data.index
})
}
}
})

View File

@@ -0,0 +1,4 @@
{
"component": true,
"usingComponents": {}
}

View File

@@ -0,0 +1,8 @@
<!--miniprogram/custom-tab-bar/index.wxml-->
<cover-view class="tab-bar">
<cover-view class="tab-bar-border"></cover-view>
<cover-view wx:for="{{list}}" wx:key="index" class="tab-bar-item" data-path="{{item.pagePath}}" data-index="{{index}}" bindtap="switchTab">
<cover-image src="../{{selected === index ? item.selectedIconPath : item.iconPath}}"></cover-image>
<cover-view style="color: {{selected === index ? selectedColor : color}}">{{item.text}}</cover-view>
</cover-view>
</cover-view>

View File

@@ -0,0 +1,38 @@
.tab-bar {
position: fixed;
bottom: 0;
left: 0;
right: 0;
height: 48px;
background: white;
display: flex;
padding-bottom: env(safe-area-inset-bottom);
}
.tab-bar-border {
background-color: rgba(0, 0, 0, 0.33);
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 1px;
transform: scaleY(0.5);
}
.tab-bar-item {
flex: 1;
text-align: center;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
.tab-bar-item cover-image {
width: 27px;
height: 27px;
}
.tab-bar-item cover-view {
font-size: 10px;
}

View File

@@ -0,0 +1,97 @@
var defaultTabbarItem = [
"pages/person/person",
"pages/residents/report",
"pages/index/index"
]
export function toggle(that) {
let pages = getCurrentPages()
let route = pages[pages.length - 1].route
console.log("[CustomTabBar] route", route)
if (!typeof that.getTabBar === 'function' || !that.getTabBar()) {
// wx.showModal({
// title: '版本太旧',
// content: '您的微信版本太旧,无法使用本小程序',
// showCancel: false,
// complete: (res) => {
// wx.exitMiniProgram()
// }
// })
return
}
// 找出要选择哪一项
let tabBar = that.getTabBar()
console.log("[CustomTabBar] tabBar", tabBar)
let data = tabBar.data
console.log("[CustomTabBar] data", data)
let showPagePathList = wx.getStorageSync('tabbarItem') || defaultTabbarItem
console.log("[CustomTabBar] showPagePathList", showPagePathList)
let list = tabBar.data.rawList.filter((page) => showPagePathList.includes(page.pagePath))
console.log("[CustomTabBar] tabBarList", list)
let selected = list ? list.indexOf(list.find(p => p.pagePath == route)) : -1
console.log("[CustomTabBar] selected", selected)
console.log("更新tabbar")
// 选中这一项
tabBar.setData({
selected: selected,
list: list
})
}
export function updateConfig(baseUrl) {
// 请求配置文件(用于审核时隐藏部分功能)
wx.request({
url: baseUrl + '/getConfig',
success(result) {
let data = result.data
if (data.tabbarItem) {
console.log("[CustomTabBar] tabbar数据拉取完毕")
wx.setStorageSync('tabbarItem', data.tabbarItem)
wx.setStorageSync('indexItem', data.indexItem)
const pages = getCurrentPages();
const indexPage = pages[0]
const currentPage = pages[pages.length - 1]
console.log("[CustomTabBar] indexPage", indexPage)
console.log("[CustomTabBar] currentPage", currentPage)
// // 更新tabbar
// toggle(currentPage)
// 刷新首页中包含了触发 toggle 的代码 此处不重复触发
// 刷新首页
indexPage && indexPage.onLoad()
// let tabBar = currentPage.getTabBar()
// tabBar.setData({
// list: tabBar.data.rawList.filter((page) => itemList.includes(page.pagePath))
// })
}
},
fail() {
wx.showModal({
title: '小程序启动失败',
content: '点击确认重试,若多次失败请检查网络连接',
complete: (res) => {
if (res.cancel) {
wx.exitMiniProgram()
}
if (res.confirm) {
wx.reLaunch({
url: 'pages/index/index',
})
}
}
})
}
})
}

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>

View File

@@ -1,5 +1,7 @@
// pages/person/person.js
const toggleCustomTabBar = require('../../custom-tab-bar/toggleCustomTabBar')
const {
user
} = require("../../utils/const")
@@ -16,7 +18,8 @@ Page({
avatarUrl: defaultAvatarUrl,
nickName: "请登录",
displayUserId: "",
menuList: [
menuList: [],
menuListRaw: [
{
id: "myOrder",
title: "我的订单",
@@ -26,14 +29,14 @@ Page({
color: 'red',
title: "退出登录",
}
]
],
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
toggleCustomTabBar.toggle(this)
},
/**
@@ -47,6 +50,20 @@ Page({
* 生命周期函数--监听页面显示
*/
onShow() {
toggleCustomTabBar.toggle(this)
// 是否隐藏 我的订单
let arr = wx.getStorageSync("indexItem")
if (!arr || !arr.includes("/pages/shop/shop")) {
this.setData({
menuList: this.data.menuListRaw.filter(i => i.id != 'myOrder')
})
} else {
this.setData({
menuList: this.data.menuListRaw
})
}
let userInfo = wx.getStorageSync("userInfo")
if (!userInfo) {
console.log("用户未登录")
@@ -109,7 +126,6 @@ Page({
console.log("e", userInfo)
this.setData({
avatarUrl: userInfo.avatarUrl,
})
},

View File

@@ -4,6 +4,7 @@ import utils from '../../utils/util'
// import drawQrcode from '../../utils/qrcode/index'
import drawQrcode from '../../utils/lib/weapp.qrcode.esm.js'
import scanQRCode from '../../utils/scanQRCode'
const toggleCustomTabBar = require('../../custom-tab-bar/toggleCustomTabBar')
const app = getApp();
@@ -25,7 +26,7 @@ Page({
* 生命周期函数--监听页面加载
*/
onLoad(options) {
toggleCustomTabBar.toggle(this)
},
/**
@@ -39,6 +40,7 @@ Page({
* 生命周期函数--监听页面显示
*/
onShow() {
toggleCustomTabBar.toggle(this)
console.log('onShow')
// setTimeout(this.refershData, 100)
this.refershData()

View File

@@ -1,6 +1,8 @@
// pages/residents/report.js
import utils from '../../utils/util'
const toggleCustomTabBar = require('../../custom-tab-bar/toggleCustomTabBar')
const app = getApp();
Page({
@@ -32,6 +34,7 @@ Page({
* 生命周期函数--监听页面加载
*/
onLoad(options) {
toggleCustomTabBar.toggle(this)
console.log("residents/report onLoad")
},
@@ -46,6 +49,7 @@ Page({
* 生命周期函数--监听页面显示
*/
onShow() {
toggleCustomTabBar.toggle(this)
console.log("residents/report onShow")
if (this.data.isSkipOnShowFunc) {
this.setData({

View File

@@ -1,5 +1,7 @@
// pages/shop/shop.js
const toggleCustomTabBar = require('../../custom-tab-bar/toggleCustomTabBar')
const goodService = require("../../services/good")
Page({
@@ -62,6 +64,7 @@ Page({
* 生命周期函数--监听页面加载
*/
onLoad(options) {
toggleCustomTabBar.toggle(this)
this.loadPageData();
},
@@ -76,7 +79,7 @@ Page({
* 生命周期函数--监听页面显示
*/
onShow() {
toggleCustomTabBar.toggle(this)
},
/**
@@ -193,7 +196,7 @@ Page({
})
})();
(async () => {
let goodCategoryListPromise = goodService.getGoodCategoryList()
Promise.all([

View File

@@ -39,55 +39,55 @@ let menuItemDict = {
switchFunc: switchTab,
url: '/pages/shop/shop'
},
'apply-record': {
for: ['visitor'],
title: "申请记录",
image: "apply.png",
switchFunc: switchTab,
url: ''
},
'apply-approval': {
for: ['admin'],
title: "申请审批",
image: "apply.png", // ApplyReplay
switchFunc: switchTab,
url: ''
},
'visitor-apply': {
for: ['admin'],
title: "访客审批",
image: "visitor.png",
switchFunc: switchTab,
url: ''
},
'abnormal': {
for: ['admin'],
title: "异常人员",
image: "danger.png",
switchFunc: switchTab,
url: ''
},
'feedback-submit': {
for: ['visitor'],
title: "提交反馈",
image: "fk.png",
switchFunc: switchTab,
url: ''
},
'feedback-list': {
for: ['visitor'],
title: "反馈查看",
image: "feedback.png",
switchFunc: switchTab,
url: ''
},
'feedback-reply': {
for: ['admin'],
title: "反馈回复",
image: "feedback.png",
switchFunc: switchTab,
url: ''
},
// 'apply-record': {
// for: ['visitor'],
// title: "申请记录",
// image: "apply.png",
// switchFunc: switchTab,
// url: ''
// },
// 'apply-approval': {
// for: ['admin'],
// title: "申请审批",
// image: "apply.png", // ApplyReplay
// switchFunc: switchTab,
// url: ''
// },
// 'visitor-apply': {
// for: ['admin'],
// title: "访客审批",
// image: "visitor.png",
// switchFunc: switchTab,
// url: ''
// },
// 'abnormal': {
// for: ['admin'],
// title: "异常人员",
// image: "danger.png",
// switchFunc: switchTab,
// url: ''
// },
// 'feedback-submit': {
// for: ['visitor'],
// title: "提交反馈",
// image: "fk.png",
// switchFunc: switchTab,
// url: ''
// },
// 'feedback-list': {
// for: ['visitor'],
// title: "反馈查看",
// image: "feedback.png",
// switchFunc: switchTab,
// url: ''
// },
// 'feedback-reply': {
// for: ['admin'],
// title: "反馈回复",
// image: "feedback.png",
// switchFunc: switchTab,
// url: ''
// },
'person': {
for: ['admin', 'user'],
title: "个人中心",
@@ -100,22 +100,22 @@ let menuItemDict = {
title: "密码修改",
image: "updPwd.png",
switchFunc: switchTab,
url: ''
url: '/pages/person/updpwd'
},
'assign': {
for: ['admin'],
title: "分配账号",
image: "count.png",
switchFunc: switchTab,
url: ''
},
'unfinish': {
for: ['admin'],
title: "今日未填", // RedList
image: "_report.png",
switchFunc: switchTab,
url: ''
}
// 'assign': {
// for: ['admin'],
// title: "分配账号",
// image: "count.png",
// switchFunc: switchTab,
// url: ''
// },
// 'unfinish': {
// for: ['admin'],
// title: "今日未填", // RedList
// image: "_report.png",
// switchFunc: switchTab,
// url: ''
// }
}
let keys = Object.keys(menuItemDict);
for (let key of keys) {