微信小程序 提审时隐藏功能;微信小程序添加微信快捷登录、随便看看(登的user用户)
This commit is contained in:
55
weixin-miniprogram/custom-tab-bar/index.js
Normal file
55
weixin-miniprogram/custom-tab-bar/index.js
Normal 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
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
4
weixin-miniprogram/custom-tab-bar/index.json
Normal file
4
weixin-miniprogram/custom-tab-bar/index.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"component": true,
|
||||
"usingComponents": {}
|
||||
}
|
8
weixin-miniprogram/custom-tab-bar/index.wxml
Normal file
8
weixin-miniprogram/custom-tab-bar/index.wxml
Normal 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>
|
38
weixin-miniprogram/custom-tab-bar/index.wxss
Normal file
38
weixin-miniprogram/custom-tab-bar/index.wxss
Normal 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;
|
||||
}
|
97
weixin-miniprogram/custom-tab-bar/toggleCustomTabBar.js
Normal file
97
weixin-miniprogram/custom-tab-bar/toggleCustomTabBar.js
Normal 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',
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user