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 {
data() { export default {
return { data() {
invitationHandled: false // 在data中明确定义 return {
} invitationHandled: false
}, }
onLaunch: function() { },
console.log('App Launch'); onLaunch: function() {
if(!uni.getStorageSync('loginType')){ console.log('App Launch');
uni.clearStorageSync(); if(!uni.getStorageSync('loginType')){
uni.setStorageSync('loginType','visitor'); uni.clearStorageSync();
} uni.setStorageSync('loginType','visitor');
// 处理外部链接参数 }
this.handleExternalUrlParams();
// #ifdef APP-PLUS this.handleExternalUrlParams();
// uni.downloadFile({
// url: '/cffpUpdate/__UNI__ED34740.wgt', // App更新逻辑
// success: (downloadResult) => { // #ifdef APP-PLUS
// if (downloadResult.statusCode === 200) { plus.runtime.getProperty(plus.runtime.appid, (wgtinfo) => {
// plus.runtime.install(downloadResult.tempFilePath, { uni.getSystemInfo({
// force: true success:(systemInfo)=> {
// }, function() { uni.request({
// console.log('install success...'); url: `${apiURL}/appVersion/checkIsUpdate`,
// plus.runtime.restart(); method:'POST',
// }, function(e) { data: {
// console.error('install fail...'); appType: 1,
// }); version: wgtinfo.version,
// } systemType:systemInfo.osName.toLowerCase() === 'ios' ? 2 : 1
// } },
// }); success: (result) => {
// #endif const data = result.data.data['appVersionInfo'];
// #ifdef APP-PLUS if (data.status==1 && data.isForceUpdate && data.wgtUrl) {
plus.runtime.getProperty(plus.runtime.appid, (wgtinfo) => { uni.downloadFile({
uni.getSystemInfo({ url: `${baseURL}${data.wgtUrl}`,
success:(systemInfo)=> { success: (downloadResult) => {
uni.request({ if (downloadResult.statusCode === 200) {
url: `${apiURL}/appVersion/checkIsUpdate`, plus.runtime.install(downloadResult.tempFilePath, {
method:'POST', force: true
data: { }, function() {
appType: 1, plus.runtime.restart();
version: wgtinfo.version, }, function(e) {
systemType:systemInfo.osName.toLowerCase() === 'ios' ? 2 : 1 console.error('install fail...');
}, });
success: (result) => { }
const data = result.data.data['appVersionInfo']; }
if (data.status==1 && data.isForceUpdate && data.wgtUrl) { });
uni.downloadFile({ }
url: `${baseURL}${data.wgtUrl}`, }
success: (downloadResult) => { });
if (downloadResult.statusCode === 200) { }
plus.runtime.install(downloadResult.tempFilePath, { })
force: true })
}, function() { // #endif
plus.runtime.restart();
}, function(e) { interceptor();
console.error('install fail...'); initApp();
}); },
}
} onShow: function(options) {
}); console.log('App Show', options);
} this.checkUserStatus();
} // #ifdef APP-PLUS
}); if(options && options.query) {
} this.saveUrlParams(options.query);
}) }
}) // #endif
},
// #endif
interceptor(); onHide: function() {
initApp(); console.log('App Hide')
}, },
onShow: function(options) { methods: {
console.log('App Show', options); async checkUserStatus() {
// 每次进应用显示时检查用户状态 if(uni.getStorageSync('loginType') == 'codelogin' && uni.getStorageSync('cffp_userId')) {
this.checkUserStatus(); try {
// App平台从options获取参数 const res = await api.queryInfo({userId: uni.getStorageSync('cffp_userId')});
// #ifdef APP-PLUS if(!res['success']) {
if(options && options.query) { this.clearLoginState();
this.saveUrlParams(options.query); const pages = getCurrentPages();
} if(pages.length > 0) {
// #endif const currentRoute = pages[pages.length - 1].route;
}, const whiteList = [
onHide: function() { '/myPackageA/login/login',
console.log('App Hide') '/pages/invitationRegister/invitationlogin',
}, '/myPackageA/applyFranchise/applyFranchise',
methods: { '/pages/applyFranchise/applyFranchise',
// 检查用户状态的方法 '/myPackageA/ruleAndContract/clause',
async checkUserStatus() { '/pages/courselist/courselist',
// 只有已登录用户才需要检查 '/pages/courseDetail/courseDetail',
if(uni.getStorageSync('loginType') == 'codelogin' && uni.getStorageSync('cffp_userId')) { '/pages/orderDetail/orderDetail',
try { '/pages/orderStatus/orderStatus',
const res = await api.queryInfo({userId: uni.getStorageSync('cffp_userId')}); '/pages/index/index'
if(!res['success']) { ];
// 用户已注销,清除缓存 if(!whiteList.includes(currentRoute)) {
this.clearLoginState(); uni.navigateTo({
url: '/myPackageA/login/login'
// 如果不是在白名单页面,跳转到登录页 });
const pages = getCurrentPages(); }
if(pages.length > 0) { }
const currentRoute = pages[pages.length - 1].route; }
console.log('currentRoute',currentRoute); if (res['success']) {
const whiteList = [ const cffp_userInfo = {
'/myPackageA/login/login', name: res['data']['realName'],
'/pages/invitationRegister/invitationlogin', mobile: res['data']['mobile'],
'/myPackageA/applyFranchise/applyFranchise', partnerType:res['data']['partnerType'],
'/pages/applyFranchise/applyFranchise', nickName:res['data']['nickName'],
'/myPackageA/ruleAndContract/clause', }
'/pages/courselist/courselist', uni.setStorageSync('cffp_userInfo', JSON.stringify(cffp_userInfo))
'/pages/courseDetail/courseDetail', }
'/pages/orderDetail/orderDetail', } catch (err) {
'/pages/orderStatus/orderStatus', console.error('检查用户状态失败:', err);
'/pages/index/index' }
] // 根据需要调整 }
if(!whiteList.includes(currentRoute)) { },
uni.navigateTo({
url: '/myPackageA/login/login' clearLoginState() {
}); uni.clearStorageSync();
} uni.setStorageSync('loginType', 'visitor');
} },
}
if (res['success']) { handleExternalUrlParams() {
const cffp_userInfo = { // #ifdef H5
name: res['data']['realName'], this.handleH5UrlParams();
mobile: res['data']['mobile'], // #endif
partnerType:res['data']['partnerType'],
nickName:res['data']['nickName'], // #ifdef APP-PLUS
} this.handleAppUrlParams();
uni.setStorageSync('cffp_userInfo', JSON.stringify(cffp_userInfo)) // #endif
} },
} catch (err) {
console.error('检查用户状态失败:', err); handleH5UrlParams() {
} const url = window.location.href;
} if(url.indexOf('?') > -1) {
}, const queryString = url.split('?')[1];
// 清除登录状态 const params = this.parseQueryString(queryString);
clearLoginState() { this.saveUrlParams(params);
uni.clearStorageSync(); }
uni.setStorageSync('loginType', 'visitor'); },
// 可以在这里添加其他需要清除的状态
}, handleAppUrlParams() {
// 处理外部链接参数 plus.runtime.getProperty(plus.runtime.appid, (widgetInfo) => {
handleExternalUrlParams() { const args = plus.runtime.arguments;
// #ifdef H5 if(args) {
this.handleH5UrlParams(); const params = this.parseAppLaunchArgs(args);
// #endif this.saveUrlParams(params);
}
// #ifdef APP-PLUS });
this.handleAppUrlParams();
// #endif plus.runtime.addEventListener('newintent', (e) => {
}, const args = e.arguments;
if(args) {
// 处理H5平台的URL参数 const params = this.parseAppLaunchArgs(args);
handleH5UrlParams() { this.saveUrlParams(params);
const url = window.location.href; }
if(url.indexOf('?') > -1) { });
const queryString = url.split('?')[1]; },
const params = this.parseQueryString(queryString);
this.saveUrlParams(params); parseQueryString(queryString) {
} const params = {};
const pairs = queryString.split('&');
}, for(let i = 0; i < pairs.length; i++) {
const pair = pairs[i].split('=');
// 处理App平台的URL参数 if(pair.length === 2) {
handleAppUrlParams() { params[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1] || '');
// 处理冷启动参数 }
plus.runtime.getProperty(plus.runtime.appid, (widgetInfo) => { }
const args = plus.runtime.arguments; return params;
if(args) { },
const params = this.parseAppLaunchArgs(args);
this.saveUrlParams(params); parseAppLaunchArgs(args) {
} if(args.indexOf('?') > -1) {
}); const queryString = args.split('?')[1];
return this.parseQueryString(queryString);
// 监听热启动事件 }
plus.runtime.addEventListener('newintent', (e) => { return {};
const args = e.arguments; },
if(args) {
const params = this.parseAppLaunchArgs(args); saveUrlParams(params) {
this.saveUrlParams(params); if(Object.keys(params).length > 0) {
} console.log('获取到外部链接参数:', params);
}); try {
}, if(params.addSystemType){
uni.setStorageSync('addSystemType', params.addSystemType);
// 解析H5的查询字符串 }
parseQueryString(queryString) { } catch(e) {
const params = {}; console.error('存储外部链接参数失败:', e);
const pairs = queryString.split('&'); }
for(let i = 0; i < pairs.length; i++) { }
const pair = pairs[i].split('='); }
if(pair.length === 2) { }
params[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1] || ''); }
}
}
return params;
},
// 解析App启动参数
parseAppLaunchArgs(args) {
// 处理 scheme://path?key=value 格式
if(args.indexOf('?') > -1) {
const queryString = args.split('?')[1];
return this.parseQueryString(queryString);
}
return {};
},
// 保存URL参数到本地存储
saveUrlParams(params) {
if(Object.keys(params).length > 0) {
console.log('获取到外部链接参数:', params);
// 使用uni.setStorageSync存储到本地
try {
if(params.addSystemType){
uni.setStorageSync('addSystemType', params.addSystemType);
}
// // 可以在这里添加事件通知其他页面参数已准备好
// uni.$emit('externalParamsReady', params);
} catch(e) {
console.error('存储外部链接参数失败:', e);
}
}
}
}
}
</script> </script>
<style> <style>
@import "@/static/font1/iconfont.css"; @import "@/static/font1/iconfont.css";
@import "@/static/font/iconfont.css"; @import "@/static/font/iconfont.css";
/*每个页面公共css */ /*每个页面公共css */
@font-face { @font-face {
font-family: 'iconfont'; font-family: 'iconfont';
...@@ -253,14 +219,14 @@ ...@@ -253,14 +219,14 @@
} }
/* .container{ /* .container{
background-color: rgba(235, 239, 247, 1); background-color: rgba(235, 239, 247, 1);
min-height: 100vh; min-height: 100vh;
height: auto !important; height: auto !important;
height: 100vh; height: 100vh;
} */ } */
/* 全局基础样式 - 移动端优先 */ /* 全局基础样式 - 移动端优先 */
.container { .container {
background-color: rgba(235, 239, 247, 1); background-color: rgba(235, 239, 247, 1);
min-height: 100vh; min-height: 100vh;
height: auto !important; height: auto !important;
height: 100vh; height: 100vh;
width: 100%; width: 100%;
...@@ -270,26 +236,26 @@ ...@@ -270,26 +236,26 @@
box-sizing: border-box; box-sizing: border-box;
font-size: 28rpx; font-size: 28rpx;
} }
/* 手机端默认样式 (小于768px) */ /* 手机端默认样式 (小于768px) */
/* @media (max-width: 767px) { /* @media (max-width: 767px) {
.container { .container {
} }
} */ } */
/* 平板设备 (768px-1023px) */ /* 平板设备 (768px-1023px) */
@media (min-width: 768px) and (max-width: 1023px) { @media (min-width: 768px) and (max-width: 1023px) {
.container { .container {
/* max-width: 100%; */ /* max-width: 100%; */
} }
/* iPad竖屏*/ /* iPad竖屏*/
/* @media (orientation: portrait) { /* @media (orientation: portrait) {
.container { .container {
max-width: 650px; max-width: 650px;
} }
} */ } */
/* iPad横屏 */ /* iPad横屏 */
@media (orientation: landscape) { @media (orientation: landscape) {
.container { .container {
...@@ -300,32 +266,32 @@ ...@@ -300,32 +266,32 @@
} }
} }
} }
/* 小桌面设备 (1024px-1279px) */ /* 小桌面设备 (1024px-1279px) */
@media (min-width: 1024px) and (max-width: 1279px) { @media (min-width: 1024px) and (max-width: 1279px) {
.container { .container {
max-width: 1000px; max-width: 1000px;
} }
} }
/* 大桌面设备 (1280px以上) */ /* 大桌面设备 (1280px以上) */
@media (min-width: 1280px) { @media (min-width: 1280px) {
.container { .container {
max-width: 1200px; max-width: 1200px;
} }
} }
/* 特殊iPad Pro尺寸适配 */ /* 特殊iPad Pro尺寸适配 */
/* @media only screen /* @media only screen
and (min-device-width: 1024px) and (min-device-width: 1024px)
and (max-device-width: 1366px) and (max-device-width: 1366px)
and (-webkit-min-device-pixel-ratio: 2) { and (-webkit-min-device-pixel-ratio: 2) {
.container { .container {
max-width: 1100px; max-width: 1100px;
} }
} */ } */
.uni-popup .uni-popup__wrapper{ .uni-popup .uni-popup__wrapper{
border-radius: 30rpx; border-radius: 30rpx;
} }
......
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