Commit e8c704c0 by 高淑倩

集点体验权限

parent 0f9c739e
......@@ -39,6 +39,11 @@ App({
onShow: function (options = {}) {
console.log('app-onshow', options)
const baseUserInfo = wx.getStorageSync('_baseUserInfo')
// 获取当前会员是否是体验者
const { member } = baseUserInfo
const curMemberTrial = member.trial || false
wx.setStorageSync('isExperiencer', curMemberTrial)
if (options.referrerInfo.extraData!=null){
const { activate_ticket, card_id, code, errCode, wx_activate_after_submit_url } = options.referrerInfo.extraData
let urlData = wx_activate_after_submit_url.split("?");
......
......@@ -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) {
......@@ -71,7 +117,7 @@ wxService.page({
} else if (currentEndTime < currentTime) {
// 结束时间 小于 现在时间 已结束
timeFlag = 2
} else if(currentTime < currentstartTime) {
} else if (currentTime < currentstartTime) {
// 未开始
timeFlag = 3
}
......@@ -193,11 +239,11 @@ wxService.page({
// 显示 dialog
this.isShowDialog(true)
// popupType == 0 3s 关闭
if (popupType == 0){
setTimeout(()=>{
if (popupType == 0) {
setTimeout(() => {
this.isShowDialog(false)
this.getPointDetail(id)
},3000)
}, 3000)
}
}
}
......@@ -236,45 +282,51 @@ wxService.page({
* 生命周期函数--监听页面显示
*/
onShow: function () {
// 登录接口返回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
}
// const { experAccessible } = this.data
// if (experAccessible) {
// // 登录接口返回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
})
}
// 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()
// }
},
/**
......
......@@ -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({
* 生命周期函数--监听页面显示
*/
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() {
wx.showLoading({
......@@ -46,14 +64,14 @@ wxService.page({
let currentEndTime = (new Date(endT.replace(/-/g, '/'))).getTime();
let currentstartTime = (new Date(startT.replace(/-/g, '/'))).getTime();
let currentTime = (new Date()).getTime();
// 开始时间 小于 现在 && 小于 结束时间 进行中
if (currentstartTime < currentTime && currentTime < currentEndTime) {
timeFlag = 1
} else if (currentEndTime < currentTime) {
// 结束时间 小于 现在时间 已结束
timeFlag = 2
} else if(currentTime < currentstartTime) {
} else if (currentTime < currentstartTime) {
// 未开始
timeFlag = 3
}
......
......@@ -76,24 +76,6 @@ wxService.page({
handlerDataOnPage.init(this, 'pages')
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) {
this.setData({
token: wx.getStorageSync('token'),
......@@ -105,18 +87,6 @@ wxService.page({
this.getMemberPointInfo()
// 优惠券数量
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) {
......@@ -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() {
wx.showLoading({
......
......@@ -88,6 +88,12 @@ export function getAppUserInfo () {
}
}
export function getCurrentRouter () {
var pages = getCurrentPages() // 获取加载的页面
var currentPage = pages[pages.length - 1] // 获取当前页面的对象
return currentPage
}
export default {
c1C2Map,
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
import utils from './util'
let openCardLister = null
const pathData = require('./currentAccessiblePath.js')
import * as watch from "./watch.js";
/**
* 单例
*/
......@@ -285,17 +287,54 @@ class WXService extends Http {
})
})
}
getAssPath () {
const paths = pathData
let pathArr = []
for(const key in paths){
if (paths.hasOwnProperty(key)) {
pathArr.push(key)
let pathObj = {}
pathObj[key] = paths[key]
pathArr.push(pathObj)
}
}
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) {
// const AccreditWhitePages = [
// 'pages/welcome/welcome'
......@@ -372,17 +411,34 @@ class WXService extends Http {
page (config) {
const _self = this
const { sr } = this.getApp()
config.data.experAccessible = false;
const CONFIG_PAPGE = {
onLoad: function (...args) {
const page = this
_self.initAppGlobalDataSync()
watch.setWatcher(page);
config.onLoad && config.onLoad.apply(page, args)
},
onShow: function (...args) {
const isExperiencer = wx.getStorageSync('isExperiencer')
const page = this
_self.currentPage = page
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) {
config.onReady && config.onReady.apply(this, 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