Commit 688f6e97 by zhangxingmin

push

parent f2caa581
<script> <script>
import initApp from "@/util/router.js"; import initApp from "@/util/router.js";
import {interceptor} from "@/util/interceptor"; import {interceptor} from "@/util/interceptor";
import {baseURL,apiURL,cffpURL,companyInfo} from "@/environments/environment"; import {baseURL,apiURL,cffpURL,companyInfo} from "@/environments/environment";
import api from './api/api'; import api from './api/api';
export default {
export default {
data() { data() {
return { return {
invitationHandled: false // 在data中明确定义 invitationHandled: false
} }
}, },
onLaunch: function() { onLaunch: function() {
...@@ -15,25 +16,10 @@ ...@@ -15,25 +16,10 @@
uni.clearStorageSync(); uni.clearStorageSync();
uni.setStorageSync('loginType','visitor'); uni.setStorageSync('loginType','visitor');
} }
// 处理外部链接参数
this.handleExternalUrlParams(); this.handleExternalUrlParams();
// #ifdef APP-PLUS
// uni.downloadFile({ // App更新逻辑
// url: '/cffpUpdate/__UNI__ED34740.wgt',
// success: (downloadResult) => {
// if (downloadResult.statusCode === 200) {
// plus.runtime.install(downloadResult.tempFilePath, {
// force: true
// }, function() {
// console.log('install success...');
// plus.runtime.restart();
// }, function(e) {
// console.error('install fail...');
// });
// }
// }
// });
// #endif
// #ifdef APP-PLUS // #ifdef APP-PLUS
plus.runtime.getProperty(plus.runtime.appid, (wgtinfo) => { plus.runtime.getProperty(plus.runtime.appid, (wgtinfo) => {
uni.getSystemInfo({ uni.getSystemInfo({
...@@ -69,42 +55,36 @@ ...@@ -69,42 +55,36 @@
} }
}) })
}) })
// #endif // #endif
interceptor(); interceptor();
initApp(); initApp();
}, },
onShow: function(options) { onShow: function(options) {
console.log('App Show', options); console.log('App Show', options);
// 每次进应用显示时检查用户状态
this.checkUserStatus(); this.checkUserStatus();
// App平台从options获取参数
// #ifdef APP-PLUS // #ifdef APP-PLUS
if(options && options.query) { if(options && options.query) {
this.saveUrlParams(options.query); this.saveUrlParams(options.query);
} }
// #endif // #endif
}, },
onHide: function() { onHide: function() {
console.log('App Hide') console.log('App Hide')
}, },
methods: { methods: {
// 检查用户状态的方法
async checkUserStatus() { async checkUserStatus() {
// 只有已登录用户才需要检查
if(uni.getStorageSync('loginType') == 'codelogin' && uni.getStorageSync('cffp_userId')) { if(uni.getStorageSync('loginType') == 'codelogin' && uni.getStorageSync('cffp_userId')) {
try { try {
const res = await api.queryInfo({userId: uni.getStorageSync('cffp_userId')}); const res = await api.queryInfo({userId: uni.getStorageSync('cffp_userId')});
if(!res['success']) { if(!res['success']) {
// 用户已注销,清除缓存
this.clearLoginState(); this.clearLoginState();
// 如果不是在白名单页面,跳转到登录页
const pages = getCurrentPages(); const pages = getCurrentPages();
if(pages.length > 0) { if(pages.length > 0) {
const currentRoute = pages[pages.length - 1].route; const currentRoute = pages[pages.length - 1].route;
console.log('currentRoute',currentRoute);
const whiteList = [ const whiteList = [
'/myPackageA/login/login', '/myPackageA/login/login',
'/pages/invitationRegister/invitationlogin', '/pages/invitationRegister/invitationlogin',
...@@ -116,7 +96,7 @@ ...@@ -116,7 +96,7 @@
'/pages/orderDetail/orderDetail', '/pages/orderDetail/orderDetail',
'/pages/orderStatus/orderStatus', '/pages/orderStatus/orderStatus',
'/pages/index/index' '/pages/index/index'
] // 根据需要调整 ];
if(!whiteList.includes(currentRoute)) { if(!whiteList.includes(currentRoute)) {
uni.navigateTo({ uni.navigateTo({
url: '/myPackageA/login/login' url: '/myPackageA/login/login'
...@@ -138,13 +118,12 @@ ...@@ -138,13 +118,12 @@
} }
} }
}, },
// 清除登录状态
clearLoginState() { clearLoginState() {
uni.clearStorageSync(); uni.clearStorageSync();
uni.setStorageSync('loginType', 'visitor'); uni.setStorageSync('loginType', 'visitor');
// 可以在这里添加其他需要清除的状态
}, },
// 处理外部链接参数
handleExternalUrlParams() { handleExternalUrlParams() {
// #ifdef H5 // #ifdef H5
this.handleH5UrlParams(); this.handleH5UrlParams();
...@@ -155,7 +134,6 @@ ...@@ -155,7 +134,6 @@
// #endif // #endif
}, },
// 处理H5平台的URL参数
handleH5UrlParams() { handleH5UrlParams() {
const url = window.location.href; const url = window.location.href;
if(url.indexOf('?') > -1) { if(url.indexOf('?') > -1) {
...@@ -163,12 +141,9 @@ ...@@ -163,12 +141,9 @@
const params = this.parseQueryString(queryString); const params = this.parseQueryString(queryString);
this.saveUrlParams(params); this.saveUrlParams(params);
} }
}, },
// 处理App平台的URL参数
handleAppUrlParams() { handleAppUrlParams() {
// 处理冷启动参数
plus.runtime.getProperty(plus.runtime.appid, (widgetInfo) => { plus.runtime.getProperty(plus.runtime.appid, (widgetInfo) => {
const args = plus.runtime.arguments; const args = plus.runtime.arguments;
if(args) { if(args) {
...@@ -177,7 +152,6 @@ ...@@ -177,7 +152,6 @@
} }
}); });
// 监听热启动事件
plus.runtime.addEventListener('newintent', (e) => { plus.runtime.addEventListener('newintent', (e) => {
const args = e.arguments; const args = e.arguments;
if(args) { if(args) {
...@@ -187,7 +161,6 @@ ...@@ -187,7 +161,6 @@
}); });
}, },
// 解析H5的查询字符串
parseQueryString(queryString) { parseQueryString(queryString) {
const params = {}; const params = {};
const pairs = queryString.split('&'); const pairs = queryString.split('&');
...@@ -200,9 +173,7 @@ ...@@ -200,9 +173,7 @@
return params; return params;
}, },
// 解析App启动参数
parseAppLaunchArgs(args) { parseAppLaunchArgs(args) {
// 处理 scheme://path?key=value 格式
if(args.indexOf('?') > -1) { if(args.indexOf('?') > -1) {
const queryString = args.split('?')[1]; const queryString = args.split('?')[1];
return this.parseQueryString(queryString); return this.parseQueryString(queryString);
...@@ -210,25 +181,20 @@ ...@@ -210,25 +181,20 @@
return {}; return {};
}, },
// 保存URL参数到本地存储
saveUrlParams(params) { saveUrlParams(params) {
if(Object.keys(params).length > 0) { if(Object.keys(params).length > 0) {
console.log('获取到外部链接参数:', params); console.log('获取到外部链接参数:', params);
// 使用uni.setStorageSync存储到本地
try { try {
if(params.addSystemType){ if(params.addSystemType){
uni.setStorageSync('addSystemType', params.addSystemType); uni.setStorageSync('addSystemType', params.addSystemType);
} }
// // 可以在这里添加事件通知其他页面参数已准备好
// uni.$emit('externalParamsReady', params);
} catch(e) { } catch(e) {
console.error('存储外部链接参数失败:', e); console.error('存储外部链接参数失败:', e);
} }
} }
} }
} }
} }
</script> </script>
<style> <style>
......
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