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

小程序:首页按钮功能完成;个人中心、生活物资页框架;体温上报定位权限获取失败提示信息;删除部分无用代码;

This commit is contained in:
2023-03-18 17:52:56 +08:00
parent 94a2dbf26d
commit ee7e2e9acb
33 changed files with 712 additions and 181 deletions

View File

@@ -11,6 +11,9 @@ Page({
*/
data: {
debugText: "调试",
displayUsername: "",
userGroup: "unknown",
filterMenuItems: [],
},
/**
@@ -19,15 +22,9 @@ Page({
onLoad(options) {
console.log("index/index onLoad", options)
// console.log("wx.getLaunchOptionsSync()", wx.getLaunchOptionsSync())
this.setData({
debugText: JSON.stringify(options, null, 4),
})
console.log("menuItemDict", menuItemDict)
this.userInfo = wx.getStorageSync("userInfo")
this.displayUsername = this.userInfo?.username ?? "请登录"
if (!this.userInfo) {
let userInfo = wx.getStorageSync("userInfo")
if (!userInfo) {
console.log("用户未登录")
wx.redirectTo({
url: '/pages/index/login'
@@ -35,13 +32,19 @@ Page({
return
} else {
// 用户已登录
this.userGroup = getUserGroupByRole(this.userInfo.role)
this.debugObject = {
userGroup: this.userGroup
}
let userGroup = getUserGroupByRole(userInfo.role)
this.setData({
debugText: JSON.stringify(options, null, 4),
userInfo: userInfo,
userGroup: userGroup,
displayUsername: userInfo?.username ?? "请登录",
filterMenuItems: this.getFilterMenuItems(menuItemDict, userGroup)
})
console.log("menuItemDict", menuItemDict)
console.log("filterMenuItems", this.data.filterMenuItems)
//判断用户是否是通过扫小程序码进来的
if (options.scene) {
if (options && options.scene) {
// 扫门禁的小程序码
if (options.scene.split('%')[0] == "guard") {
options.scene = null
@@ -52,14 +55,16 @@ Page({
}
}
// // 开发模式下自动跳转到指定页面,节省开发时间
// console.log("app.globalData", app.globalData)
// if (app.globalData.debugMode) {
// wx.switchTab({
// url: '/pages/residents/report'
// })
// return
// }
// 开发模式下自动跳转到指定页面,节省开发时间
console.log("app.globalData", app.globalData)
if (app.globalData.debugMode) {
wx.switchTab({
// url: '/pages/residents/report'
// url: '/pages/person/person'
url: '/pages/shop/shop'
})
return
}
}
},
@@ -110,5 +115,62 @@ Page({
*/
onShareAppMessage() {
console.log("index/index onShareAppMessage")
},
getFilterMenuItems(menuItemDict, userGroup) {
return Object.values(menuItemDict)
.filter((item) => item.for.indexOf(userGroup) != -1)
},
switchTo(event) {
let dataset = event.target.dataset
console.log("dataset", dataset)
switch (dataset.switchfunc) {
case 'switchTab':
wx.switchTab({
url: dataset.pageurl
})
break;
case 'navigateTo':
wx.navigateTo({
url: dataset.pageurl
})
break;
case 'redirectTo':
wx.redirectTo({
url: dataset.pageurl
})
break;
default:
console.log("切换页面失败", dataset)
break;
}
},
goCode() {
wx.switchTab({
url: '/pages/residents/code'
})
},
toggleDot(event, ownerInstance, iconName = 'code', status = undefined) {
console.log("menuItemDict[iconName]", menuItemDict[iconName])
console.log("this.data.userGroup", this.data.userGroup)
if (typeof (status) === 'undefined') {
menuItemDict[iconName].addDot = !menuItemDict[iconName].addDot;
} else {
menuItemDict[iconName].addDot = !!status;
}
this.setData({
filterMenuItems: this.getFilterMenuItems(menuItemDict, this.data.userGroup)
})
},
magicButton() {
wx.navigateTo({
url: "/pages/scan/entrance"
})
}
})

View File

@@ -1,21 +1,20 @@
<!--pages/index/index.wxml-->
<view>
<image src="../../image/home.jpg" style="width: 100vw; height: 41.5vw;"></image>
<view style="display: block; padding-left: 30px; padding-top: 12px;">
<view class="welcome-text">
<text>欢迎你,{{ displayUsername }}</text>
</view>
<view>
<text>调试信息:{{ debugText }}</text>
</view>
<view id="menu-view">
<view class="menu-item" v-for="menuItem in filterMenuItems" :key="menuItem.id">
<view :class="{ 'add-dot': menuItem.addDot }" style="display: inline-block;">
<image :src="'../../image/icon/' + menuItem.image" class="item-image" bindtap='switchTo(menuItem.switchFunc, menuItem.url)'></image>
<view class="menu-item" wx:for="{{ filterMenuItems }}" wx:for-item="menuItem" wx:key="id">
<view class="{{ menuItem.addDot ? 'add-dot' : '' }}" style="display: inline-block;">
<image src="../../image/icon/{{ menuItem.image }}" class="item-image" bindtap='switchTo' data-switchfunc="{{menuItem.switchFunc}}" data-pageurl="{{menuItem.url}}"></image>
</view>
<view>{{ menuItem.title }}</view>
</view>
</view>
<button type="primary" size="mini" bindtap="toggleDot('code', true)">显示小红点</button>
<button type="primary" size="mini" bindtap="toggleDot('code', false)">隐藏小红点</button>
<button type="warn" size="mini" bindtap="magicButton">魔法按钮</button>
<button type="primary" size="mini" bindtap="toggleDot">切换小红点</button>
<button type="warn" size="mini" bindtap="magicButton">扫描门禁</button>
<text>调试信息:{{ debugText }}</text>
</view>

View File

@@ -1 +1,24 @@
/* pages/index/index.wxss */
/* pages/index/index.wxss */
#menu-view {
display: flex;
text-align: center;
flex-wrap: wrap;
padding: 20px 10px;
}
.welcome-text {
display: block;
padding-left: 30px;
padding-top: 18px;
font-size: 20px;
}
.menu-item {
width: 25%;
margin: 10px 0;
}
.item-image {
width: 50px;
height: 50px;
}