Commit 9c7f07b8 authored by lg's avatar lg

chore: activity/index支持传入url打开

parent 6465f253
......@@ -7,16 +7,18 @@ import {ref, watch, nextTick} from "vue";
import {onLoad, onShow, onShareAppMessage, onShareTimeline} from "@dcloudio/uni-app";
import {useGlobalStore} from "../../stores/global";
import {useUserStore} from "../../stores/user";
import {jump, JumpType} from "../../utils";
const userStore = useUserStore();
const globalStore = useGlobalStore()
function getRegistered() {
return userStore?.userInfo?.memberId != "not_login"
return userStore.userInfo?.memberId !== "not_login"
}
const pageOptions = ref({})
const src = ref("");
const registered = ref(getRegistered())
const registered = ref(false)
const urlMap = {
//'main': 'http://192.168.0.5:8001/#/page',
......@@ -29,8 +31,8 @@ onShow(() => {
registered.value = getRegistered()
})
watch(() => registered.value, (newVal) => {
if (newVal) {
watch(() => registered.value, (newVal, oldVal) => {
if (newVal !== oldVal) {
const oldSrc = src.value
src.value = ''
......@@ -40,39 +42,70 @@ watch(() => registered.value, (newVal) => {
}
})
onLoad((options) => {
console.log('页面参数:', options)
function joinUrlAndQs(url, qs) {
return qs
? url + (url.includes('?') ? (url.endsWith('?') ? '' : '&') : '?') + qs
: url
}
wx.showShareMenu({
withShareTicket: true,
menus: ['shareAppMessage', 'shareTimeline']
})
function initOk() {
console.log(userStore.userInfo)
registered.value = getRegistered()
let url = "";
const options = pageOptions.value
if (options.type) {
const type = options.type;
url = urlMap[type];
} else if (options.url) {
url = decodeURIComponent(options.url)
}
const params = {...(options || {})}
delete params.type
delete params.params
const params = {}
const {unionId, cuk} = globalStore
if (unionId && !params.unionId) params.unionId = unionId
if (cuk && !params.cuk) params.cuk = cuk
const {memberId} = userStore.userInfo
if (memberId) params.crmId = memberId
const paramStr = Object.keys(params)
.filter(key => params[key] !== undefined && params[key] !== null && params[key] !== '')
.map(key => `${key}=${encodeURIComponent(params[key])}`)
.join('&')
url = paramStr
? url + (url.includes('?') ? '&' : '?') + paramStr + (options.params ? '&' + decodeURIComponent(options.params) : '')
: url
url = joinUrlAndQs(url, paramStr)
if(options.params){
url = joinUrlAndQs(url, decodeURIComponent(options.params))
}
src.value = url
console.log('webview url:', url)
}
onLoad(async (options) => {
pageOptions.value = options
console.log('页面参数:', options)
wx.showShareMenu({
withShareTicket: true,
menus: ['shareAppMessage', 'shareTimeline']
})
await userStore.normalAutoLogin()
await userStore.loadUserInfo()
if(!registered.value) {
jump({
type: JumpType.INNER,
url: '/pages/activity/register',
})
}else{
initOk()
}
});
function onMessage(e) {
......
const hosts = [
{value: 'https://guide-api.feihe.com', alias: '生产环境'},
{value: 'https://guide-api-test.feihe.com', alias: 'test环境'},
{value: 'https://guide-api-uat.feihe.com', alias: 'uat环境'},
{value: 'https://guide-api.feihe.com', alias: '生产环境'},
{value: 'https://guide-api-test.feihe.com', alias: 'test环境'},
{value: 'https://guide-api-uat.feihe.com', alias: 'uat环境'},
]
const pages = [
{value: '/mini/#/page/momHome/index', alias: '妈妈爱活动'},
{value: '/mini/#/page/home/index', alias: '路演活动'},
{value: '/mini/#/page/momHome/index', alias: '妈妈爱活动'},
{value: '/mini/#/page/home/index?page_source=3', alias: '路演活动'},
]
const mpPage = '/pages/webview/webview'
const mpPage = 'pages/activity/index'
function joinUrlAndQs(url, qs) {
return qs
? url + (url.includes('?') ? (url.endsWith('?') ? '' : '&') : '?') + qs
: url
}
for (const page of pages) {
for (const host of hosts) {
const url = `${mpPage}?url=${encodeURIComponent(host.value + page.value)}`
console.log(`${page.alias}-${host.alias}: ${url}`)
}
for (const host of hosts) {
const url = joinUrlAndQs(mpPage, `url=${encodeURIComponent(host.value + page.value)}`)
console.log(`${page.alias}-${host.alias}: ${url}`)
}
}
This diff is collapsed.
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