fix: app启动报错问题修复

This commit is contained in:
2026-05-28 14:33:10 +08:00
parent 2eb5f30d74
commit 7a75f8b4bf
6 changed files with 70 additions and 23 deletions
+8 -5
View File
@@ -210,7 +210,8 @@
onShow(() => {
// #ifdef APP-PLUS
// 获取urlSchemes参数
const args = plus.runtime.arguments;
const args =
typeof plus !== 'undefined' && plus?.runtime ? plus.runtime.arguments : '';
if (args) {}
// 获取剪贴板
@@ -219,11 +220,13 @@
});
// #endif
});
uni.onTabBarMidButtonTap(() => {
uni.navigateTo({
url: '/pages/home/seed',
if (typeof uni.onTabBarMidButtonTap === 'function') {
uni.onTabBarMidButtonTap(() => {
uni.navigateTo({
url: '/pages/home/seed',
});
});
});
}
</script>
<style lang="scss">
+2 -2
View File
@@ -2,8 +2,8 @@
"name" : "优购商城",
"appid" : "__UNI__8B19741",
"description" : "",
"versionName" : "1.3.3",
"versionCode" : 133,
"versionName" : "1.3.5",
"versionCode" : 135,
"transformPx" : false,
"app-plus" : {
"privacy" : {
+21 -7
View File
@@ -7,13 +7,27 @@ import zIndex from '@/sheep/config/zIndex.js';
import $store from '@/sheep/store';
const sheep = {
$api,
$store,
$url,
$router,
$platform,
$helper,
$zIndex: zIndex,
get $api() {
return $api;
},
get $store() {
return $store;
},
get $url() {
return $url;
},
get $router() {
return $router;
},
get $platform() {
return $platform;
},
get $helper() {
return $helper;
},
get $zIndex() {
return zIndex;
},
};
// 加载Shopro底层依赖
+19 -2
View File
@@ -6,11 +6,27 @@
import Request from 'luch-request';
import { apiPath, baseUrl, tenantId } from '@/sheep/config';
import $store from '@/sheep/store';
import $platform from '@/sheep/platform';
import { showAuthModal } from '@/sheep/hooks/useModal';
import AuthUtil from '@/sheep/api/member/auth';
import { getTerminal } from '@/sheep/helper/const';
const getPlatformName = () => {
let name = 'H5';
// #ifdef APP-PLUS
name = 'App';
// #endif
// #ifdef MP-WEIXIN
name = 'WechatMiniProgram';
// #endif
// #ifdef H5
try {
const ua = String(navigator?.userAgent || '');
if (/MicroMessenger/i.test(ua)) name = 'WechatOfficialAccount';
} catch (e) {}
// #endif
return name;
};
const options = {
// 显示操作成功消息 默认不显示
showSuccess: false,
@@ -54,7 +70,7 @@ const http = new Request({
header: {
Accept: 'text/json',
'Content-Type': 'application/json;charset=UTF-8',
platform: $platform.name,
platform: getPlatformName(),
},
// #ifdef APP-PLUS
sslVerify: false,
@@ -105,6 +121,7 @@ http.interceptors.request.use(
if (token) {
config.header['Authorization'] = token;
}
config.header['platform'] = getPlatformName();
config.header['terminal'] = getTerminal();
config.header['Accept'] = '*/*';
+17 -5
View File
@@ -3,11 +3,23 @@ import { getTenantByWebsite } from '@/sheep/api/infra/tenant';
import { getTenantId } from '@/sheep/request';
import { defineStore } from 'pinia';
import $platform from '@/sheep/platform';
import $router from '@/sheep/router';
import user from './user';
import sys from './sys';
import { baseUrl, h5Url } from '@/sheep/config';
const toErrorPage = (errCode = '', errMsg = '') => {
const code = encodeURIComponent(String(errCode || ''));
const msg = encodeURIComponent(String(errMsg || ''));
const url = `/pages/public/error?errCode=${code}&errMsg=${msg}`;
try {
uni.reLaunch({ url });
return;
} catch (e) {}
try {
uni.redirectTo({ url });
} catch (e) {}
};
const app = defineStore({
id: 'app',
state: () => ({
@@ -54,12 +66,12 @@ const app = defineStore({
// 检查网络
const networkStatus = await $platform.checkNetwork();
if (!networkStatus) {
$router.error('NetworkError');
toErrorPage('NetworkError');
}
// 检查配置
if (typeof baseUrl === 'undefined') {
$router.error('EnvError');
toErrorPage('EnvError');
}
// 加载租户
@@ -105,7 +117,7 @@ const app = defineStore({
// }
return Promise.resolve(true);
} else {
$router.error('InitError', res.msg || '加载失败');
toErrorPage('InitError', '加载失败');
}
},
},
@@ -178,7 +190,7 @@ const adaptTemplate = async (appTemplate, templateId) => {
: await DiyApi.getUsedDiyTemplate();
// 模板不存在
if (!diyTemplate) {
$router.error('TemplateError');
toErrorPage('TemplateError');
return;
}
+3 -2
View File
@@ -5,6 +5,7 @@ import piniaPersist from 'pinia-plugin-persist-uni';
const files = import.meta.glob('./*.js', { eager: true });
const modules = {};
Object.keys(files).forEach((key) => {
if (key === './index.js') return;
modules[key.replace(/(.*\/)*([^.]+).*/gi, '$2')] = files[key].default;
});
@@ -15,6 +16,6 @@ export const setupPinia = (app) => {
app.use(pinia);
};
export default (name) => {
export default function $store(name) {
return modules[name]();
};
}