fix: app启动报错问题修复
This commit is contained in:
+17
-5
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user