Commit 69e8e502 by 李伟康

提交

1 parent 4214a1c8
// packageActivity/pages/redEnvelope/index/index.js
import {
jumpAuthMixin
} from '~/mixins/index'
import {
domain
} from '~/api/env/index'
Page({
behaviors: [jumpAuthMixin],
/**
* 页面的初始数据
*/
......@@ -26,9 +32,55 @@ Page({
* 生命周期函数--监听页面显示
*/
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({
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})
\ 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
<web-view src="{{url}}"/>
\ No newline at end of file
......@@ -118,7 +118,6 @@ Page({
this.getSolitaireDetail(params)
} else throw message
} catch (error) {
return
console.log(error)
wx.showModal({
title: '温馨提示',
......@@ -186,5 +185,4 @@ Page({
onReachBottom() {
},
onShareAppMessage() {}
})
\ No newline at end of file
// pages/loading/loading.js
import { systemApi } from '~/api/index'
import {
systemApi
} from '~/api/index'
Page({
/**
* 页面的初始数据
......@@ -26,16 +28,20 @@ Page({
async login(options = {}) {
console.log(options, 'options.merchantId')
// wx.p.router.goHome()
if (options.merchantId){
if (options.merchantId) {
wx.$merchant_id = options.merchantId
wx.p.storage.set('merchant_info', {
merchantId: options.merchantId,
})
wx.p.storage.set('first_enter_merchantId', options.merchantId)
wx.p.storage.set('first_enter_miniprograme', true)
}
}
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
if (data)
wx.p.storage.set('merchant_info', {
......@@ -65,12 +71,16 @@ Page({
},
async getSceneById(scene) {
const id = decodeURIComponent(scene).split('=').at(-1)
console.log(decodeURIComponent(scene),'decodeURIComponent(scene)');
console.log(decodeURIComponent(scene), 'decodeURIComponent(scene)');
try {
const { code, data } = await wx.p.api.wechatApi.getSceneById({
const {
code,
data
} = await wx.p.api.wechatApi.getSceneById({
id
})
const params = data.scene.split('url='),options = {}
const params = data.scene.split('url='),
options = {}
data.scene.split('&').map(item => {
const [key, val] = item.split('=')
options[key] = val
......@@ -86,7 +96,10 @@ Page({
jumpPage(options) {
console.log(options);
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'
events.notIntercept = true
events.merchantId = options.merchantId || ''
......@@ -94,7 +107,9 @@ Page({
},
setRouteData(targetPath) {
let [url, query] = targetPath.split('?'),
events = {}
events = {
isLogin: 1
}
if (query) {
let arr = query.split('&')
arr.map(e => {
......@@ -110,4 +125,4 @@ Page({
events
}
}
})
})
\ No newline at end of file
......@@ -88,8 +88,9 @@ class Router {
* @param {*} callBack true未登录 false已登录
*/
async intercept(auto = true) {
const authStatus = wx.$LoginStatus
if (authStatus) {
const authStatus = wx.$LoginStatus,
userInfo = wx.p.cache.userInfo.getUserInfo() || {}
if (!userInfo.phone || authStatus) {
if (auto) wx.navigateTo({
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!