Commit 9c7f07b8 authored by lg's avatar lg

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

parent 6465f253
...@@ -7,16 +7,18 @@ import {ref, watch, nextTick} from "vue"; ...@@ -7,16 +7,18 @@ import {ref, watch, nextTick} from "vue";
import {onLoad, onShow, onShareAppMessage, onShareTimeline} from "@dcloudio/uni-app"; import {onLoad, onShow, onShareAppMessage, onShareTimeline} from "@dcloudio/uni-app";
import {useGlobalStore} from "../../stores/global"; import {useGlobalStore} from "../../stores/global";
import {useUserStore} from "../../stores/user"; import {useUserStore} from "../../stores/user";
import {jump, JumpType} from "../../utils";
const userStore = useUserStore(); const userStore = useUserStore();
const globalStore = useGlobalStore() const globalStore = useGlobalStore()
function getRegistered() { function getRegistered() {
return userStore?.userInfo?.memberId != "not_login" return userStore.userInfo?.memberId !== "not_login"
} }
const pageOptions = ref({})
const src = ref(""); const src = ref("");
const registered = ref(getRegistered()) const registered = ref(false)
const urlMap = { const urlMap = {
//'main': 'http://192.168.0.5:8001/#/page', //'main': 'http://192.168.0.5:8001/#/page',
...@@ -29,8 +31,8 @@ onShow(() => { ...@@ -29,8 +31,8 @@ onShow(() => {
registered.value = getRegistered() registered.value = getRegistered()
}) })
watch(() => registered.value, (newVal) => { watch(() => registered.value, (newVal, oldVal) => {
if (newVal) { if (newVal !== oldVal) {
const oldSrc = src.value const oldSrc = src.value
src.value = '' src.value = ''
...@@ -40,39 +42,70 @@ watch(() => registered.value, (newVal) => { ...@@ -40,39 +42,70 @@ watch(() => registered.value, (newVal) => {
} }
}) })
onLoad((options) => { function joinUrlAndQs(url, qs) {
console.log('页面参数:', options) return qs
? url + (url.includes('?') ? (url.endsWith('?') ? '' : '&') : '?') + qs
: url
}
wx.showShareMenu({ function initOk() {
withShareTicket: true, console.log(userStore.userInfo)
menus: ['shareAppMessage', 'shareTimeline']
}) registered.value = getRegistered()
let url = ""; let url = "";
const options = pageOptions.value
if (options.type) { if (options.type) {
const type = options.type; const type = options.type;
url = urlMap[type]; url = urlMap[type];
} else if (options.url) {
url = decodeURIComponent(options.url)
} }
const params = {...(options || {})} const params = {}
delete params.type
delete params.params
const {unionId, cuk} = globalStore const {unionId, cuk} = globalStore
if (unionId && !params.unionId) params.unionId = unionId if (unionId && !params.unionId) params.unionId = unionId
if (cuk && !params.cuk) params.cuk = cuk if (cuk && !params.cuk) params.cuk = cuk
const {memberId} = userStore.userInfo
if (memberId) params.crmId = memberId
const paramStr = Object.keys(params) const paramStr = Object.keys(params)
.filter(key => params[key] !== undefined && params[key] !== null && params[key] !== '') .filter(key => params[key] !== undefined && params[key] !== null && params[key] !== '')
.map(key => `${key}=${encodeURIComponent(params[key])}`) .map(key => `${key}=${encodeURIComponent(params[key])}`)
.join('&') .join('&')
url = paramStr url = joinUrlAndQs(url, paramStr)
? url + (url.includes('?') ? '&' : '?') + paramStr + (options.params ? '&' + decodeURIComponent(options.params) : '') if(options.params){
: url url = joinUrlAndQs(url, decodeURIComponent(options.params))
}
src.value = url src.value = url
console.log('webview url:', 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) { function onMessage(e) {
......
...@@ -6,14 +6,20 @@ const hosts = [ ...@@ -6,14 +6,20 @@ const hosts = [
const pages = [ const pages = [
{value: '/mini/#/page/momHome/index', alias: '妈妈爱活动'}, {value: '/mini/#/page/momHome/index', alias: '妈妈爱活动'},
{value: '/mini/#/page/home/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 page of pages) {
for (const host of hosts) { for (const host of hosts) {
const url = `${mpPage}?url=${encodeURIComponent(host.value + page.value)}` const url = joinUrlAndQs(mpPage, `url=${encodeURIComponent(host.value + page.value)}`)
console.log(`${page.alias}-${host.alias}: ${url}`) console.log(`${page.alias}-${host.alias}: ${url}`)
} }
} }
...@@ -71,7 +71,8 @@ export const useUserStore = defineStore("userInfo", { ...@@ -71,7 +71,8 @@ export const useUserStore = defineStore("userInfo", {
* @param {Object} data : {encryptedData, iv, code} * @param {Object} data : {encryptedData, iv, code}
* @returns * @returns
*/ */
async phoneCallback(data, onOpenRegisterFn = () => { }, cb = null, cb2 = null, invitationInfo = null) { async phoneCallback(data, onOpenRegisterFn = () => {
}, cb = null, cb2 = null, invitationInfo = null) {
uni.login({ uni.login({
provider: "weixin", provider: "weixin",
success: async (res) => { success: async (res) => {
...@@ -165,7 +166,7 @@ export const useUserStore = defineStore("userInfo", { ...@@ -165,7 +166,7 @@ export const useUserStore = defineStore("userInfo", {
const RETRY_DELAY = 1000; // 1 second const RETRY_DELAY = 1000; // 1 second
try { try {
const { data } = await fetchBabyInfo(); const {data} = await fetchBabyInfo();
console.log("babyInfo-宝宝信息", data); console.log("babyInfo-宝宝信息", data);
if (data?.memberId !== "not_login") { if (data?.memberId !== "not_login") {
...@@ -293,7 +294,7 @@ export const useUserStore = defineStore("userInfo", { ...@@ -293,7 +294,7 @@ export const useUserStore = defineStore("userInfo", {
provider: "weixin", provider: "weixin",
success: async (res) => { success: async (res) => {
if (res.errMsg === "login:ok") { if (res.errMsg === "login:ok") {
const { data } = await autoLoginByCode(res.code); const {data} = await autoLoginByCode(res.code);
// 如果登录成功,获取用户信息和宝宝信息,更新到state中,方便全局使用 // 如果登录成功,获取用户信息和宝宝信息,更新到state中,方便全局使用
if (data && data.cuk) { if (data && data.cuk) {
globalStore.setCuk(data.cuk, data.openId, data.unionId); globalStore.setCuk(data.cuk, data.openId, data.unionId);
...@@ -317,27 +318,34 @@ export const useUserStore = defineStore("userInfo", { ...@@ -317,27 +318,34 @@ export const useUserStore = defineStore("userInfo", {
* @param {sy使用} * @param {sy使用}
* @returns * @returns
*/ */
async normalAutoLogin(cb = null) { normalAutoLogin(cb = null) {
return new Promise((resolve, reject) => {
uni.login({ uni.login({
provider: "weixin", provider: "weixin",
success: async (res) => { success: async (res) => {
if (res.errMsg === "login:ok") { if (res.errMsg === "login:ok") {
const { data } = await autoLoginByCode(res.code); const {data} = await autoLoginByCode(res.code);
// 如果登录成功,获取用户信息和宝宝信息,更新到state中,方便全局使用 // 如果登录成功,获取用户信息和宝宝信息,更新到state中,方便全局使用
if (data && data.cuk) { if (data && data.cuk) {
globalStore.setCuk(data.cuk, data.openId, data.unionId); globalStore.setCuk(data.cuk, data.openId, data.unionId);
cb && cb(); cb && cb();
resolve()
} }
} else { } else {
uni.showToast({ uni.showToast({
title: res.errMsg, title: res.errMsg,
icon: "error", icon: "error",
}); });
reject(res.errMsg)
} }
md.sensors.init(); md.sensors.init();
}, },
fail: (err) => {
reject(err)
}
}); });
})
}, },
async createBabyInfo(babyInfo) { async createBabyInfo(babyInfo) {
......
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