Commit 69e8e502 by 李伟康

提交

1 parent 4214a1c8
// packageActivity/pages/redEnvelope/index/index.js // packageActivity/pages/redEnvelope/index/index.js
import {
jumpAuthMixin
} from '~/mixins/index'
import {
domain
} from '~/api/env/index'
Page({ Page({
behaviors: [jumpAuthMixin],
/** /**
* 页面的初始数据 * 页面的初始数据
*/ */
...@@ -26,9 +32,55 @@ Page({ ...@@ -26,9 +32,55 @@ Page({
* 生命周期函数--监听页面显示 * 生命周期函数--监听页面显示
*/ */
onShow() { onShow() {
const {
options
} = this
if (options.isLogin) this.jumpRedEnvelopeH5()
else {
//强制登陆、防止sessionId失效
let query = ['isLogin=1']
Object.keys(options).map(key => {
query.push(`${key}=${options[key]}`)
})
let url = encodeURIComponent(`/${this.route}?${query.join('&')}`)
wx.p.router.redirectTo('/pages/loading/loading', {
url,
merchantId: options.merchantId
})
}
},
async jumpRedEnvelopeH5() {
const res = await wx.p.router.intercept()
if (!res) {
const {
userInfo
} = this.data, {
activityId,
merchantId
} = this.options, {
sessionId
} = wx.p.storage.get()
if (!userInfo.nickName) return this.getNickNameAndHeadUrl()
const {
accountId,
nickName,
unionId,
openid,
phone
} = userInfo
let user = encodeURIComponent(JSON.stringify({
accountId,
nickName,
unionId,
openid,
phone
}))
this.setData({
// url: `${domain}/scrm-wx-red-packet/#/redEnvelope?activityId=${activityId}&merchantId=${merchantId}&sessionId=${sessionId}&userInfo=${user}` //测试、预发布、生产
url: `${domain}/dj-scrm-wx-work-main-lwk/#/?activityId=${activityId}&merchantId=${merchantId}&sessionId=${sessionId}&userInfo=${user}` //开发环境
})
}
}, },
/** /**
* 生命周期函数--监听页面隐藏 * 生命周期函数--监听页面隐藏
*/ */
...@@ -55,12 +107,5 @@ Page({ ...@@ -55,12 +107,5 @@ Page({
*/ */
onReachBottom() { onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
} }
}) })
\ No newline at end of file \ No newline at end of file
<!--packageActivity/pages/redEnvelope/index/index.wxml-->
<text>packageActivity/pages/redEnvelope/index/index.wxml</text>
\ No newline at end of file \ No newline at end of file
<web-view src="{{url}}"/>
\ No newline at end of file \ No newline at end of file
...@@ -118,7 +118,6 @@ Page({ ...@@ -118,7 +118,6 @@ Page({
this.getSolitaireDetail(params) this.getSolitaireDetail(params)
} else throw message } else throw message
} catch (error) { } catch (error) {
return
console.log(error) console.log(error)
wx.showModal({ wx.showModal({
title: '温馨提示', title: '温馨提示',
...@@ -186,5 +185,4 @@ Page({ ...@@ -186,5 +185,4 @@ Page({
onReachBottom() { onReachBottom() {
}, },
onShareAppMessage() {}
}) })
\ No newline at end of file \ No newline at end of file
// pages/loading/loading.js // pages/loading/loading.js
import { systemApi } from '~/api/index' import {
systemApi
} from '~/api/index'
Page({ Page({
/** /**
* 页面的初始数据 * 页面的初始数据
...@@ -26,16 +28,20 @@ Page({ ...@@ -26,16 +28,20 @@ Page({
async login(options = {}) { async login(options = {}) {
console.log(options, 'options.merchantId') console.log(options, 'options.merchantId')
// wx.p.router.goHome() // wx.p.router.goHome()
if (options.merchantId){ if (options.merchantId) {
wx.$merchant_id = options.merchantId wx.$merchant_id = options.merchantId
wx.p.storage.set('merchant_info', { wx.p.storage.set('merchant_info', {
merchantId: options.merchantId, merchantId: options.merchantId,
}) })
wx.p.storage.set('first_enter_merchantId', options.merchantId) wx.p.storage.set('first_enter_merchantId', options.merchantId)
wx.p.storage.set('first_enter_miniprograme', true) wx.p.storage.set('first_enter_miniprograme', true)
} }
try { try {
const { code, data, message } = await wx.p.api.userApi.login() const {
code,
data,
message
} = await wx.p.api.userApi.login()
wx.$LoginStatus = code != 0 wx.$LoginStatus = code != 0
if (data) if (data)
wx.p.storage.set('merchant_info', { wx.p.storage.set('merchant_info', {
...@@ -65,12 +71,16 @@ Page({ ...@@ -65,12 +71,16 @@ Page({
}, },
async getSceneById(scene) { async getSceneById(scene) {
const id = decodeURIComponent(scene).split('=').at(-1) const id = decodeURIComponent(scene).split('=').at(-1)
console.log(decodeURIComponent(scene),'decodeURIComponent(scene)'); console.log(decodeURIComponent(scene), 'decodeURIComponent(scene)');
try { try {
const { code, data } = await wx.p.api.wechatApi.getSceneById({ const {
code,
data
} = await wx.p.api.wechatApi.getSceneById({
id id
}) })
const params = data.scene.split('url='),options = {} const params = data.scene.split('url='),
options = {}
data.scene.split('&').map(item => { data.scene.split('&').map(item => {
const [key, val] = item.split('=') const [key, val] = item.split('=')
options[key] = val options[key] = val
...@@ -86,7 +96,10 @@ Page({ ...@@ -86,7 +96,10 @@ Page({
jumpPage(options) { jumpPage(options) {
console.log(options); console.log(options);
const targetPath = decodeURIComponent(options.url), const targetPath = decodeURIComponent(options.url),
{ url, events } = this.setRouteData(targetPath), {
url,
events
} = this.setRouteData(targetPath),
routeName = this.tabList.findIndex(e => `/${e.pagePath}` == `${url}.html`) > -1 ? 'switchTab' : 'redirectTo' routeName = this.tabList.findIndex(e => `/${e.pagePath}` == `${url}.html`) > -1 ? 'switchTab' : 'redirectTo'
events.notIntercept = true events.notIntercept = true
events.merchantId = options.merchantId || '' events.merchantId = options.merchantId || ''
...@@ -94,7 +107,9 @@ Page({ ...@@ -94,7 +107,9 @@ Page({
}, },
setRouteData(targetPath) { setRouteData(targetPath) {
let [url, query] = targetPath.split('?'), let [url, query] = targetPath.split('?'),
events = {} events = {
isLogin: 1
}
if (query) { if (query) {
let arr = query.split('&') let arr = query.split('&')
arr.map(e => { arr.map(e => {
...@@ -110,4 +125,4 @@ Page({ ...@@ -110,4 +125,4 @@ Page({
events events
} }
} }
}) })
\ No newline at end of file \ No newline at end of file
...@@ -88,8 +88,9 @@ class Router { ...@@ -88,8 +88,9 @@ class Router {
* @param {*} callBack true未登录 false已登录 * @param {*} callBack true未登录 false已登录
*/ */
async intercept(auto = true) { async intercept(auto = true) {
const authStatus = wx.$LoginStatus const authStatus = wx.$LoginStatus,
if (authStatus) { userInfo = wx.p.cache.userInfo.getUserInfo() || {}
if (!userInfo.phone || authStatus) {
if (auto) wx.navigateTo({ if (auto) wx.navigateTo({
url: '/pages/Login/Login', url: '/pages/Login/Login',
}) })
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!