Commit 0f00f711 authored by spc's avatar spc

sy webview

parent 940def5a
......@@ -60,26 +60,39 @@ export default {
// 固定写死的 URL(不从 options 读取 baseUrl)
const baseUrl = 'https://25niansuyuan.feihe.com/projects/Firmus/dev/index';
const store = useGlobalStore();
const cuk = store.cuk || uni.getStorageSync('cuk');
// 可选:设置页面标题(不从 params 移除,仍然透传到 H5)
if (options && options.title) {
try { this.pageTitle = decodeURIComponent(options.title); } catch (_) { this.pageTitle = options.title; }
}
const cuk = store.cuk;
const openId = store.openId;
const unionId = store.unionId;
// 将 options 的所有参数原样作为查询参数传给 H5,并补齐 cuk
const params = { ...(options || {}) };
if (cuk && !params.cuk) params.cuk = cuk;
// 添加用户信息参数
if (openId && !params.openId) params.openId = openId;
if (unionId && !params.unionId) params.unionId = unionId;
const paramStr = Object.keys(params)
.map(key => `${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`)
.filter(key => params[key] !== undefined && params[key] !== null && params[key] !== '')
.map(key => `${key}=${encodeURIComponent(params[key])}`)
.join('&');
// p 渠道参数
// openId 用户openid
// unionId 用户unionid
// cuk
// shareToken 分享人token
// pt 分享海报人token
// 示例:
// https://25niansuyuan.feihe.com/projects/Firmus/dev/index?p=xmh&openId=用户openid&unionId=用户unionid&&pt=yzhd123&shareToken=yzhd123&cuk=12121
this.webviewUrl = paramStr
? baseUrl + (baseUrl.includes('?') ? '&' : '?') + paramStr
: baseUrl;
console.log('Webview页面加载,URL:', this.webviewUrl);
console.log('Webview页面加载,URL:', this.webviewUrl, paramStr, cuk, openId, unionId);
},
onShareAppMessage(options) {
// 分享功能
......
......@@ -3,14 +3,18 @@ import {
} from 'pinia';
const cuk = uni.getStorageSync('cuk')
const openId = uni.getStorageSync('openId')
const unionId = uni.getStorageSync('unionId')
export const useGlobalStore = defineStore('global', {
state: () => {
return {
cuk: cuk, // 用户登录后获取的凭证,调用接口时headers中携带
curTabIndex: 0, // 当前Tab索引
isWxFriendCircle:false,
isShowLoading: false
isWxFriendCircle:false,
isShowLoading: false,
openId: openId,
unionId: unionId
};
},
actions: {
......@@ -18,8 +22,12 @@ export const useGlobalStore = defineStore('global', {
* 设置用户cuk
* @param {Object} cuk
*/
setCuk(cuk) {
setCuk(cuk,openId,unionId) {
this.cuk = cuk;
this.openId = openId;
this.unionId = unionId;
uni.setStorageSync('openId', openId);
uni.setStorageSync('unionId', unionId);
uni.setStorageSync('cuk', cuk);
},
/**
......@@ -36,9 +44,9 @@ export const useGlobalStore = defineStore('global', {
*/
setIsWxFriendCircle(v){
this.isWxFriendCircle = v
},
setIsShowLoading(v){
},
setIsShowLoading(v){
this.isShowLoading = v
}
},
......
......@@ -173,7 +173,7 @@ export const useUserStore = defineStore("userInfo", {
console.log("autoLoginByCode", data);
// 如果登录成功,获取用户信息和宝宝信息,更新到state中,方便全局使用
if (data && data.cuk) {
globalStore.setCuk(data.cuk);
globalStore.setCuk(data.cuk,data.openId,data.unionId);
await this.loadUserInfo();
await this.loadBabyInfo();
......
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