baimacms/App.vue

64 lines
1.9 KiB
Vue
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<script>
import UrlQuery from '@/scratch/url-query.js';
export default {
globalData: {
/**
* urlParams - 当前页面 URL 参数集合
*
* 来源:
* 1. H5 环境下从 window.locationsearch + hash解析
* 2. 小程序/App 环境下从页面栈 currentPage.options 获取
* 3. 分享/扫码进入时从 App.onLaunch/onShow 的 options.query 合并
*
* 目前业务中实际使用的参数:
* - token {string} 用户登录凭证
* - code {string} 淘宝后返回授权码
* - state {string} 状态值,格式通常为 "uidxxx",用于提取用户 ID淘宝授权返回
* - exuid {string} 推广人/邀请人用户 ID三方进入用户标识
* - page_uri {string} 授权成功后需要跳转的目标页面路径(必须授权过的用户该参数才有效)
*
* 注UrlQuery 支持获取任意 URL 参数,以上仅为业务代码中显式消费的字段
*/
urlParams: {}
},
onLaunch: function(options) {
console.log('App Launch');
// 获取 URL 参数并存入 globalData
let params = UrlQuery.getAll();
// #ifndef H5
// 非 H5 平台,合并 App.onLaunch 的 options.query分享/扫码进入时的参数)
if (options && options.query && typeof options.query === 'object') {
params = { ...params, ...options.query };
}
// #endif
this.globalData.urlParams = params;
console.log('URL 参数:', params);
},
onShow: function(options) {
console.log('App Show');
// 每次显示时更新参数H5 下 URL 可能变化)
let params = UrlQuery.getAll();
// #ifndef H5
if (options && options.query && typeof options.query === 'object') {
params = { ...params, ...options.query };
}
// #endif
this.globalData.urlParams = params;
},
onHide: function() {
console.log('App Hide');
}
}
</script>
<style>
/*每个页面公共css */
</style>