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