Commit cc4e1905 by daqian

页面授权

parent 46c1eabf
...@@ -23,38 +23,52 @@ Component({ ...@@ -23,38 +23,52 @@ Component({
this.setData({ this.setData({
baseImgUrl: app.globalData.imageUrl baseImgUrl: app.globalData.imageUrl
}) })
const { picNav } = this.data
picNav.forEach(item => {
// 存在 row 处理数据 8 商品 9 分类
let newRow = null
if (item.link) {
if(item.link.type == 2){
// 父组件 更新
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
} else if (item.row) {
newRow = JSON.parse(item.row)
if (newRow.type == 8) {
newRow.newPath = '/pages/productDetail/productDetail'
} else if (newRow.type == 9) {
newRow.newPath = '/subPackage/page/pages/categoryPro/categoryPro'
} else {
newRow.newPath = ''
}
// item.row = JSON.stringify(newRow)
item.row = newRow
}
})
this.setData({ picNav }, () => {
console.log('ppp', this.data.picNav)
})
}, },
observers: {
picNav() {
const { picNav } = this.data
picNav.forEach(item => {
// 存在 row 处理数据 8 商品 9 分类
let newRow = null
if (item.link) {
if(item.link.type == 2){
// 父组件 更新
const urls = getCurrentPages()
const currentPath = urls[0]
const pageId = item.link.url
item.link.newPath = `/${currentPath.route}`
}
return
} else if (item.row) {
newRow = JSON.parse(item.row)
if (newRow.type == 8) {
newRow.newPath = '/pages/productDetail/productDetail'
} else if (newRow.type == 9) {
newRow.newPath = '/subPackage/page/pages/categoryPro/categoryPro'
} else {
newRow.newPath = ''
}
// item.row = JSON.stringify(newRow)
item.row = newRow
}
})
// 当前匹配路径是否需要授权 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({ ...@@ -64,7 +78,8 @@ Component({
isAuthorization: false, isAuthorization: false,
isAuthorizationActiveText: '', isAuthorizationActiveText: '',
isAuthorizationType: 2, isAuthorizationType: 2,
baseImgUrl: '' baseImgUrl: '',
newPicNav: []
}, },
/** /**
* 组件的方法列表 * 组件的方法列表
......
...@@ -2,17 +2,13 @@ ...@@ -2,17 +2,13 @@
<wxs src="../../wxs/utils.wxs" module="utils" /> <wxs src="../../wxs/utils.wxs" module="utils" />
<view class="pic-nav"> <view class="pic-nav">
<view <view
wx:for="{{picNav}}" wx:for="{{newPicNav}}"
wx:key="{{index}}" wx:key="{{index}}"
wx:for-item="item" wx:for-item="item"
class="nav-block" 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 <button
wx:if="{{!currentHasUserInfo}}" wx:if="{{!currentHasUserInfo}}"
bindgetuserinfo="_getUserInfo" bindgetuserinfo="_getUserInfo"
......
...@@ -60,59 +60,28 @@ class WXService extends Http { ...@@ -60,59 +60,28 @@ class WXService extends Http {
wx.hideLoading() wx.hideLoading()
}).catch(res => { }).catch(res => {
// if (res.msg && res.msg.indexOf('未登录') > -1) { // 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) { // if (!this.getUserInfoLimitCount) {
// this.getUserInfoLimitCount = 1 // this.getUserInfoLimitCount = 1
// } else { // } else {
// this.getUserInfoLimitCount++ // this.getUserInfoLimitCount++
// } // }
// console.log('count', this.getUserInfoLimitCount)
// if (this.getUserInfoLimitCount > 3) { // if (this.getUserInfoLimitCount > 3) {
// wx.showToast({ // wx.showToast({
// title: '登录超出重试次数!', // title: '会员系统异常,请联系管理员',
// icon: 'none' // icon: 'none',
// duration: 2000
// }) // })
// wxService.router(`/pages/userCenter/userCenter`).replace()
// return false
// } else { // } else {
// // 重新登陆 更新缓存 // // 重新登陆之前判断是否登陆过 重新登陆
// this.reLogin() // const baseUserInfo = this.getBaseUserInfo()
// if (baseUserInfo) {
// // this.reLogin()
// return false
// }
// } // }
// } else
// setTimeout(()=>{ if (res.msg && res.msg.indexOf('请重新授权') > -1) {
// 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) {
wx.setStorageSync('reLoginErr', true) wx.setStorageSync('reLoginErr', true)
wxService.router(`/pages/userCenter/userCenter`).back() wxService.router(`/pages/userCenter/userCenter`).back()
} }
...@@ -425,6 +394,28 @@ class WXService extends Http { ...@@ -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) { handlerPage(page) {
const AccreditWhitePages = [ const AccreditWhitePages = [
'pages/welcome/welcome' 'pages/welcome/welcome'
...@@ -481,63 +472,6 @@ class WXService extends Http { ...@@ -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() { initAppGlobalDataSync() {
const app = this.getApp() 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