Commit cc4e1905 by daqian

页面授权

parent 46c1eabf
......@@ -23,6 +23,10 @@ Component({
this.setData({
baseImgUrl: app.globalData.imageUrl
})
},
observers: {
picNav() {
const { picNav } = this.data
picNav.forEach(item => {
// 存在 row 处理数据 8 商品 9 分类
......@@ -33,7 +37,6 @@ Component({
const urls = getCurrentPages()
const currentPath = urls[0]
const pageId = item.link.url
console.log('currentPath', currentPath.route,item.link.url)
item.link.newPath = `/${currentPath.route}`
}
return
......@@ -51,9 +54,20 @@ Component({
}
})
this.setData({ picNav }, () => {
console.log('ppp', this.data.picNav)
// 当前匹配路径是否需要授权 true 需要 false 不需要
picNav.forEach(item => {
let checkUrl = ''
if(item.link) {
checkUrl = item.link.newPath ? item.link.newPath : item.link.url
} else if(item.row) {
checkUrl = item.row.newPath ? item.row.newPath : item.row.url
}
wxService.NoLoginPage(checkUrl).then(res=>{
item.needAuth = res.needAuth
this.setData({ newPicNav: picNav })
})
})
}
},
/**
* 组件的初始数据
......@@ -64,7 +78,8 @@ Component({
isAuthorization: false,
isAuthorizationActiveText: '',
isAuthorizationType: 2,
baseImgUrl: ''
baseImgUrl: '',
newPicNav: []
},
/**
* 组件的方法列表
......
......@@ -2,17 +2,13 @@
<wxs src="../../wxs/utils.wxs" module="utils" />
<view class="pic-nav">
<view
wx:for="{{picNav}}"
wx:for="{{newPicNav}}"
wx:key="{{index}}"
wx:for-item="item"
class="nav-block"
>
<!-- false 不需要授权 -->
<!-- {{item.link ? item.link.url : item.row.newPath }}
{{ utils.hanlerLinkNoNeedAuth(item) }}
-->
<!-- 当前页面需要授权 且未授权-->
<view wx:if="{{item.link ? utils.hanlerLinkNeedAuth(typeOf(item.link.newPath) != undefined ? item.link.newPath : item.link.url) : utils.hanlerLinkNeedAuth(item.row.newPath ? item.row.newPath : item.row.url)}}">
<view wx:if="{{item.needAuth}}">
<button
wx:if="{{!currentHasUserInfo}}"
bindgetuserinfo="_getUserInfo"
......
......@@ -60,59 +60,28 @@ class WXService extends Http {
wx.hideLoading()
}).catch(res => {
// if (res.msg && res.msg.indexOf('未登录') > -1) {
// // 判断是否登陆过 登陆过 重新登陆 未登陆 跳转首页
// const baseUserInfo = this.getBaseUserInfo()
// if(!baseUserInfo) {
// wxService.router('/pages/userCenter/userCenter').replace()
// return false
// }
// // 条件限制 getUserInfoLimitCount:重试次数
// if (!this.getUserInfoLimitCount) {
// this.getUserInfoLimitCount = 1
// } else {
// this.getUserInfoLimitCount++
// }
// console.log('count', this.getUserInfoLimitCount)
// if (this.getUserInfoLimitCount > 3) {
// wx.showToast({
// title: '登录超出重试次数!',
// icon: 'none'
// title: '会员系统异常,请联系管理员',
// icon: 'none',
// duration: 2000
// })
// wxService.router(`/pages/userCenter/userCenter`).replace()
// return false
// } else {
// // 重新登陆 更新缓存
// this.reLogin()
// // 重新登陆之前判断是否登陆过 重新登陆
// const baseUserInfo = this.getBaseUserInfo()
// if (baseUserInfo) {
// // this.reLogin()
// return false
// }
// setTimeout(()=>{
// const pages = getCurrentPages()
// const perpage = pages[pages.length - 1]
// perpage.onShow()
// },2000)
// }
if (res.msg && res.msg.indexOf('未登录') > -1) {
if (!this.getUserInfoLimitCount) {
this.getUserInfoLimitCount = 1
} else {
this.getUserInfoLimitCount++
}
console.log('count', this.getUserInfoLimitCount)
if (this.getUserInfoLimitCount > 3) {
wx.showToast({
title: '会员系统异常,请联系管理员',
icon: 'none',
duration: 2000
})
} else {
// 重新登陆之前判断是否登陆过 重新登陆
const baseUserInfo = this.getBaseUserInfo()
if (baseUserInfo) {
// this.reLogin()
return false
}
}
} else if (res.msg && res.msg.indexOf('请重新授权') > -1) {
// } else
if (res.msg && res.msg.indexOf('请重新授权') > -1) {
wx.setStorageSync('reLoginErr', true)
wxService.router(`/pages/userCenter/userCenter`).back()
}
......@@ -425,6 +394,28 @@ class WXService extends Http {
})
}
NoLoginPage(page) {
// 首页/商品详情页/内容列表/内容详情/分类/商品列表/集点列表/分享列表
const NoLoginAuthPage = [
'/pages/userCenter/userCenter',
'/pages/productDetail/productDetail',
'/pages/category/category',
'/subPackage/page/pages/categoryPro/categoryPro',
'/pages/pointList/pointList',
'/subPackage/page/pages/friendShareList/friendShareList',
]
return new Promise((resolve,reject) => {
if(NoLoginAuthPage.indexOf(page) > -1) {
resolve({needAuth : false})
} else {
resolve({needAuth : true})
}
}).catch((err) => {
console.log('不需要登录err', err)
reject()
})
}
handlerPage(page) {
const AccreditWhitePages = [
'pages/welcome/welcome'
......@@ -481,63 +472,6 @@ class WXService extends Http {
})
}
// handlerPage (page) {
// const AccreditWhitePages = [
// 'pages/welcome/welcome'
// ] // 免授权页面白名单
// const _self = this
// const app = _self.getApp()
// const baseUserInfo = wx.getStorageSync('_baseUserInfo')
// if (baseUserInfo && baseUserInfo.isMember === '1') {
// app.globalData.openCard = true
// }
// return new Promise((resolve, reject) => {
// let accreditUserInfo = wx.getStorageSync('_accreditUserInfo')
// if (app.globalData.openCard && accreditUserInfo) {
// resolve()
// return false
// }
// if (AccreditWhitePages.indexOf(page.route) > -1) {
// resolve()
// } else if (accreditUserInfo) {
// getAppUserInfo().then(() => {
// if (this.lock) {
// return false
// }
// if ((!baseUserInfo || baseUserInfo.isMember !== '1') && needOpenCard()) {
// reject({ state: 1 })
// _self.lock = false
// } else {
// _self.lock = false
// resolve()
// }
// }).catch((res) => {
// reject()
// })
// } else {
// reject({ state: 1 })
// }
// }).catch((err) => {
// if (err && err.state === 1) {
// const modifyMottoRoute = [
// "pos/express/pages/orderList/orderList",
// "pos/express/pages/confirm/confirm"
// ]
// let router = '/pages/welcome/welcome';
// if (modifyMottoRoute.indexOf(page.route) > -1) {
// page.options.motto = 'express';
// }
// wxService.router('/pages/welcome/welcome').search({
// route: `${page.route}`,
// options: JSON.stringify(page.options)
// }).replace()
// }
// return Promise.reject()
// })
// }
// 设置异步的全局变量值
initAppGlobalDataSync() {
const app = this.getApp()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment