Commit e8c704c0 by 高淑倩

集点体验权限

parent 0f9c739e
...@@ -39,6 +39,11 @@ App({ ...@@ -39,6 +39,11 @@ App({
onShow: function (options = {}) { onShow: function (options = {}) {
console.log('app-onshow', options) console.log('app-onshow', options)
const baseUserInfo = wx.getStorageSync('_baseUserInfo') const baseUserInfo = wx.getStorageSync('_baseUserInfo')
// 获取当前会员是否是体验者
const { member } = baseUserInfo
const curMemberTrial = member.trial || false
wx.setStorageSync('isExperiencer', curMemberTrial)
if (options.referrerInfo.extraData!=null){ if (options.referrerInfo.extraData!=null){
const { activate_ticket, card_id, code, errCode, wx_activate_after_submit_url } = options.referrerInfo.extraData const { activate_ticket, card_id, code, errCode, wx_activate_after_submit_url } = options.referrerInfo.extraData
let urlData = wx_activate_after_submit_url.split("?"); let urlData = wx_activate_after_submit_url.split("?");
......
...@@ -41,8 +41,54 @@ wxService.page({ ...@@ -41,8 +41,54 @@ wxService.page({
/** /**
* 生命周期函数--监听页面加载 * 生命周期函数--监听页面加载
*/ */
onLoad: function (options) { onLoad() {},
watch: {
experAccessible(newVal, oldVal) {
if(newVal) {
// 登录接口返回err
const reLoginErrFlag = wx.getStorageSync('reLoginErr')
const baseUserInfo = wx.getStorageSync('_baseUserInfo')
let id
if (baseUserInfo && !reLoginErrFlag) {
this.setData({
isAuthorization: false
}, () => {
const option = this.options || {}
const { scene } = option
if (scene) {
let idParam = decodeURIComponent(scene).split('&')[0]
let shareId = idParam && idParam.split('=')[1] || 0
id = shareId
} else {
id = option.id
}
if (id) {
this.setData({
id
}, () => {
this.getPointDetail(id)
})
}
// 隐藏 dialog
this.isShowDialog(false)
})
}
else if (!baseUserInfo && reLoginErrFlag) {
this.setData({
isAuthorization: true
})
}
else {
this.setData({
isAuthorization: true
})
}
} else {
// 去别的页面
wxService.router(`/subPackage/page/pages/goToHome/goToHome`).replace()
}
}
}, },
// 集点详情 // 集点详情
getPointDetail(id) { getPointDetail(id) {
...@@ -71,7 +117,7 @@ wxService.page({ ...@@ -71,7 +117,7 @@ wxService.page({
} else if (currentEndTime < currentTime) { } else if (currentEndTime < currentTime) {
// 结束时间 小于 现在时间 已结束 // 结束时间 小于 现在时间 已结束
timeFlag = 2 timeFlag = 2
} else if(currentTime < currentstartTime) { } else if (currentTime < currentstartTime) {
// 未开始 // 未开始
timeFlag = 3 timeFlag = 3
} }
...@@ -193,11 +239,11 @@ wxService.page({ ...@@ -193,11 +239,11 @@ wxService.page({
// 显示 dialog // 显示 dialog
this.isShowDialog(true) this.isShowDialog(true)
// popupType == 0 3s 关闭 // popupType == 0 3s 关闭
if (popupType == 0){ if (popupType == 0) {
setTimeout(()=>{ setTimeout(() => {
this.isShowDialog(false) this.isShowDialog(false)
this.getPointDetail(id) this.getPointDetail(id)
},3000) }, 3000)
} }
} }
} }
...@@ -236,45 +282,51 @@ wxService.page({ ...@@ -236,45 +282,51 @@ wxService.page({
* 生命周期函数--监听页面显示 * 生命周期函数--监听页面显示
*/ */
onShow: function () { onShow: function () {
// 登录接口返回err // const { experAccessible } = this.data
const reLoginErrFlag = wx.getStorageSync('reLoginErr') // if (experAccessible) {
const baseUserInfo = wx.getStorageSync('_baseUserInfo') // // 登录接口返回err
let id // const reLoginErrFlag = wx.getStorageSync('reLoginErr')
if (baseUserInfo && !reLoginErrFlag){ // const baseUserInfo = wx.getStorageSync('_baseUserInfo')
this.setData({ // let id
isAuthorization: false // if (baseUserInfo && !reLoginErrFlag) {
},()=>{ // this.setData({
const option = this.options || {} // isAuthorization: false
const { scene } = option // }, () => {
if (scene) { // const option = this.options || {}
let idParam = decodeURIComponent(scene).split('&')[0] // const { scene } = option
let shareId = idParam && idParam.split('=')[1] || 0 // if (scene) {
id = shareId // let idParam = decodeURIComponent(scene).split('&')[0]
} else { // let shareId = idParam && idParam.split('=')[1] || 0
id = option.id // id = shareId
} // } else {
// id = option.id
// }
if (id) { // if (id) {
this.setData({ // this.setData({
id // id
}, () => { // }, () => {
this.getPointDetail(id) // this.getPointDetail(id)
}) // })
} // }
// 隐藏 dialog // // 隐藏 dialog
this.isShowDialog(false) // this.isShowDialog(false)
}) // })
} // }
else if(!baseUserInfo && reLoginErrFlag){ // else if (!baseUserInfo && reLoginErrFlag) {
this.setData({ // this.setData({
isAuthorization: true // isAuthorization: true
}) // })
} // }
else { // else {
this.setData({ // this.setData({
isAuthorization: true // isAuthorization: true
}) // })
} // }
// } else {
// // 去别的页面
// wxService.router(`/subPackage/page/pages/goToHome/goToHome`).replace()
// }
}, },
/** /**
......
...@@ -16,8 +16,17 @@ wxService.page({ ...@@ -16,8 +16,17 @@ wxService.page({
/** /**
* 生命周期函数--监听页面加载 * 生命周期函数--监听页面加载
*/ */
onLoad() { }, onLoad() {},
watch: {
experAccessible(newVal, oldVal) {
if(newVal) {
this.getPointList()
} else {
// 去别的页面
wxService.router(`/subPackage/page/pages/goToHome/goToHome`).replace()
}
}
},
/** /**
* 生命周期函数--监听页面初次渲染完成 * 生命周期函数--监听页面初次渲染完成
*/ */
...@@ -27,7 +36,16 @@ wxService.page({ ...@@ -27,7 +36,16 @@ wxService.page({
* 生命周期函数--监听页面显示 * 生命周期函数--监听页面显示
*/ */
onShow() { onShow() {
this.getPointList() // wxService.nextTick(() => {
// const { experAccessible } = this.data
// console.log('experAccessible', experAccessible)
// if (experAccessible) {
// this.getPointList()
// } else {
// // 去别的页面
// // wxService.router(`/subPackage/page/pages/goToHome/goToHome`).replace()
// }
// })
}, },
getPointList() { getPointList() {
wx.showLoading({ wx.showLoading({
...@@ -53,7 +71,7 @@ wxService.page({ ...@@ -53,7 +71,7 @@ wxService.page({
} else if (currentEndTime < currentTime) { } else if (currentEndTime < currentTime) {
// 结束时间 小于 现在时间 已结束 // 结束时间 小于 现在时间 已结束
timeFlag = 2 timeFlag = 2
} else if(currentTime < currentstartTime) { } else if (currentTime < currentstartTime) {
// 未开始 // 未开始
timeFlag = 3 timeFlag = 3
} }
......
...@@ -76,24 +76,6 @@ wxService.page({ ...@@ -76,24 +76,6 @@ wxService.page({
handlerDataOnPage.init(this, 'pages') handlerDataOnPage.init(this, 'pages')
this.initPage(this.data.pageId) this.initPage(this.data.pageId)
// _cardMemebr
// if (baseUserInfo){
// this.setData({
// token: wx.getStorageSync('token'),
// baseUserInfo,
// cardMember,
// isAuthorization: false
// })
// // 积分数量
// this.getMemberPointInfo()
// // 优惠券数量
// this.getMemberCouponInfo()
// } else {
// this.setData({
// isAuthorization: true
// })
// }
if (baseUserInfo && !reLoginErrFlag) { if (baseUserInfo && !reLoginErrFlag) {
this.setData({ this.setData({
token: wx.getStorageSync('token'), token: wx.getStorageSync('token'),
...@@ -105,18 +87,6 @@ wxService.page({ ...@@ -105,18 +87,6 @@ wxService.page({
this.getMemberPointInfo() this.getMemberPointInfo()
// 优惠券数量 // 优惠券数量
this.getMemberCouponInfo() this.getMemberCouponInfo()
// 获取当前会员是否是体验者
const { member } = baseUserInfo
const curMemberTrial = member.trial || true
console.log('curMemberTrial', curMemberTrial)
if (curMemberTrial) {
this.setData({
curMemberTrial
}, () => {
// 获取当前体验版信息
this.trialList()
})
}
}) })
} }
else if (!baseUserInfo && reLoginErrFlag) { else if (!baseUserInfo && reLoginErrFlag) {
...@@ -130,24 +100,6 @@ wxService.page({ ...@@ -130,24 +100,6 @@ wxService.page({
}) })
} }
}, },
trialList() {
console.log('wxService.getAssPath()',wxService.getAssPath())
wx.showLoading({
title: '加载中'
})
wxService.get(`/member/trial/list`).then(res => {
if (res) {
const { result, data } = res.data
if (result == 0) {
wx.hideLoading()
console.log('res', res)
this.setData({
curAccessiblePathArr: data
})
}
}
})
},
// 查询积分信息 // 查询积分信息
getMemberPointInfo() { getMemberPointInfo() {
wx.showLoading({ wx.showLoading({
......
...@@ -88,6 +88,12 @@ export function getAppUserInfo () { ...@@ -88,6 +88,12 @@ export function getAppUserInfo () {
} }
} }
export function getCurrentRouter () {
var pages = getCurrentPages() // 获取加载的页面
var currentPage = pages[pages.length - 1] // 获取当前页面的对象
return currentPage
}
export default { export default {
c1C2Map, c1C2Map,
c2C3Map c2C3Map
......
function observe(obj, key, watchFun, deep, page) {
let val = obj[key];
if (val != null && typeof val === "object" && deep) {
Object.keys(val).forEach((item) => {
observe(val, item, watchFun, deep, page);
});
}
Object.defineProperty(obj, key, {
configurable: true,
enumerable: true,
set: function(value) {
watchFun.call(page, value, val);
val = value;
if (deep) {
observe(obj, key, watchFun, deep, page);
}
},
get: function() {
return val;
}
});
}
export function setWatcher(page) {
let data = page.data;
let watch = page.watch;
if(!watch) return false
Object.keys(watch).forEach((item) => {
let targetData = data;
let keys = item.split(".");
for (let i = 0; i < keys.length - 1; i++) {
targetData = targetData[keys[i]];
}
let targetKey = keys[keys.length - 1];
let watchFun = watch[item].handler || watch[item];
let deep = watch[item].deep;
observe(targetData, targetKey, watchFun, deep, page);
});
}
...@@ -15,6 +15,8 @@ const config = require('../config/index').envInfo ...@@ -15,6 +15,8 @@ const config = require('../config/index').envInfo
import utils from './util' import utils from './util'
let openCardLister = null let openCardLister = null
const pathData = require('./currentAccessiblePath.js') const pathData = require('./currentAccessiblePath.js')
import * as watch from "./watch.js";
/** /**
* 单例 * 单例
*/ */
...@@ -285,17 +287,54 @@ class WXService extends Http { ...@@ -285,17 +287,54 @@ class WXService extends Http {
}) })
}) })
} }
getAssPath () { getAssPath () {
const paths = pathData const paths = pathData
let pathArr = [] let pathArr = []
for(const key in paths){ for(const key in paths){
if (paths.hasOwnProperty(key)) { if (paths.hasOwnProperty(key)) {
pathArr.push(key) let pathObj = {}
pathObj[key] = paths[key]
pathArr.push(pathObj)
} }
} }
return pathArr return pathArr
} }
trialList() {
let localPath = this.getAssPath()
wx.showLoading({
title: '加载中'
})
return this.get(`/member/trial/list`).then(res => {
if (res) {
const { result, data } = res.data
if (result == 0) {
wx.hideLoading()
// 对应的path
let currentPaths = [];
localPath.forEach(item=>{
if (item.hasOwnProperty(data)) {
currentPaths = item[data]
} else {
console.log(222);
}
})
return Promise.resolve({ currentPaths })
}
}
})
}
// getAssPath () {
// const paths = pathData
// let pathArr = []
// for(const key in paths){
// if (paths.hasOwnProperty(key)) {
// pathArr.push(key)
// }
// }
// return pathArr
// }
// handlerPage (page) { // handlerPage (page) {
// const AccreditWhitePages = [ // const AccreditWhitePages = [
// 'pages/welcome/welcome' // 'pages/welcome/welcome'
...@@ -372,16 +411,33 @@ class WXService extends Http { ...@@ -372,16 +411,33 @@ class WXService extends Http {
page (config) { page (config) {
const _self = this const _self = this
const { sr } = this.getApp() const { sr } = this.getApp()
config.data.experAccessible = false;
const CONFIG_PAPGE = { const CONFIG_PAPGE = {
onLoad: function (...args) { onLoad: function (...args) {
const page = this const page = this
_self.initAppGlobalDataSync() _self.initAppGlobalDataSync()
watch.setWatcher(page);
config.onLoad && config.onLoad.apply(page, args) config.onLoad && config.onLoad.apply(page, args)
}, },
onShow: function (...args) { onShow: function (...args) {
const isExperiencer = wx.getStorageSync('isExperiencer')
const page = this const page = this
_self.currentPage = page _self.currentPage = page
config.onShow && config.onShow.apply(page, args) config.onShow && config.onShow.apply(page, args)
// 获取当前页
let router = getCurrentRouter()
_self.trialList().then(res=>{
if(!res) return false
const { currentPaths } = res
if (currentPaths.indexOf( router.route) > -1 && isExperiencer) {
this.setData({
experAccessible: true
})
}
})
}, },
onReady: function (...args) { onReady: function (...args) {
......
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