Bläddra i källkod

解决构建完成后获取 vite#define 的异常

cc12458 3 veckor sedan
förälder
incheckning
d70447dcaf

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "six-aio.web",
-  "version": "0.0.0",
+  "version": "3.0.0",
   "private": true,
   "type": "module",
   "scripts": {

+ 1 - 1
src/loader/debug.loader.ts

@@ -6,7 +6,7 @@ export default function debugLoader(tag = 'debug', ignoreDevelop = true): DEV.Lo
   return async function (app, config) {
     const query = getURLSearchParams();
     const debug = config.image.debug || query.has(tag);
-    if (import.meta.env.DEV && ignoreDevelop && !debug) return;
+    if (!debug && (import.meta.env.DEV || ignoreDevelop)) return;
 
     let lib = query.get(tag) as Lib;
     if (!lib && debug) lib = 'eruda';

+ 0 - 5
src/loader/index.ts

@@ -4,13 +4,8 @@ import { createApp } from 'vue';
 import { Toast } from '@/platform/toast.ui';
 import { getApplicationMethod } from '@/request/api';
 
-import router from '@/router';
-import pinia from '@/stores';
-
 export default async function Loader(component: Component, ...loader: DEV.Loader[]) {
   const app = createApp(component);
-  app.use(router);
-  app.use(pinia);
 
   const toast = Toast.loading(500);
 

+ 2 - 0
src/loader/launch.loader.ts

@@ -5,6 +5,8 @@ const components = import.meta.glob('@/pages/**/*.vue');
 
 export default function launchLoader(container = '#app'): DEV.Loader {
   return async function (app, config) {
+    app.use(router);
+    app.use(pinia);
 
     let currentRoute = router.currentRoute.value.fullPath;
     if (currentRoute === '/') currentRoute = '/screen';

+ 1 - 1
src/request/alova.ts

@@ -20,7 +20,7 @@ export default createAlova({
       try {
         if ( response.status >= 400 ) throw new Error(`${ response.statusText }(${ response.status })`);
 
-        if (response.headers.get('content-type') === 'text/html') return response.text();
+        if (response.headers.get('content-type')?.includes('text/html')) return response.text();
 
         let result = await response.json();
         if (method.url.startsWith(`${location.origin}${import.meta.env.BASE_URL}database`)) result = { code: 0, data: result };

+ 1 - 1
src/stores/account.store.ts

@@ -38,7 +38,7 @@ export const useAccountStore = defineStore('account', () => {
 export function getToken() {
   try {
     const value = localStorage.getItem(`${import.meta.env.SIX_APP_NAME ?? '@six/unknown'}:account`);
-    return JSON.parse(value).token;
+    return JSON.parse(value ?? '').token;
   } catch {
     return void 0;
   }

+ 4 - 2
src/tools/url.tool.ts

@@ -1,3 +1,5 @@
+const url_prefix = __APP_URL__;
+
 export function getURLSearchParams(value?: string): URLSearchParams {
   value ??= `${ location.search }&${ location.hash.split('?')[ 1 ] || '' }`;
   return new URLSearchParams(value);
@@ -9,14 +11,14 @@ export function getURLSearchParamsByUrl(value: string): URLSearchParams {
 }
 
 export function getClientURL(value: string, origin = location.origin) {
-  if ( value?.startsWith(__APP_URL__) ) return value.replace(__APP_URL__, origin);
+  if ( url_prefix && value?.startsWith(url_prefix) ) return value.replace(url_prefix, origin);
   if ( !value || /^https?:\/\//.test(value) ) return value;
   if ( value.startsWith('~') ) { value = value.slice(1); }
   return fullURL(value, origin);
 }
 
 export function getServerURL(value: string, origin = location.origin) {
-  return value?.startsWith(origin) ? value.replace(origin, __APP_URL__) : value;
+  return value?.startsWith(origin) ? value.replace(origin, url_prefix) : value;
 }
 
 function fullURL(value: string, origin = location.origin) {

+ 1 - 1
vite.config.ts

@@ -19,7 +19,7 @@ export default defineConfig((configEnv) => {
     envPrefix: 'SIX_',
     define: {
       __APP_VERSION__: JSON.stringify(process.env.npm_package_version),
-      __APP_URL__: configEnv.mode === 'development' ? JSON.stringify(env.REQUEST_API_PROXY_URL) : '',
+      __APP_URL__: configEnv.mode === 'development' ? JSON.stringify(env.REQUEST_API_PROXY_URL) : JSON.stringify(""),
       __FORBID_AUTO_PROCESS_PULSE_AGENCY__: argv.includes('--legacy-pulse-agency')
     },
     css: {