support sub path

This commit is contained in:
MaysWind
2025-03-04 23:39:16 +08:00
parent e83b959930
commit 872639fefa
4 changed files with 24 additions and 11 deletions
+2 -2
View File
@@ -22,9 +22,9 @@ function isMobileDevice(): boolean {
function navigate(type: string): void {
if (__EZBOOKKEEPING_IS_PRODUCTION__) {
window.location.replace(`${type}/`);
window.location.replace(`${type}#/`);
} else {
window.location.replace(`${type}.html`);
window.location.replace(`${type}.html#/`);
}
}
+6 -5
View File
@@ -133,6 +133,7 @@ import {
} from './server_settings.ts';
import { getTimezoneOffsetMinutes } from './datetime.ts';
import { generateRandomUUID } from './misc.ts';
import { getBasePath } from './web.ts';
interface ApiRequestConfig extends AxiosRequestConfig {
readonly headers: AxiosRequestHeaders;
@@ -147,7 +148,7 @@ export type ApiResponsePromise<T> = Promise<AxiosResponse<ApiResponse<T>>>;
let needBlockRequest = false;
const blockedRequests: ((token: string | undefined) => void)[] = [];
axios.defaults.baseURL = BASE_API_URL_PATH;
axios.defaults.baseURL = getBasePath() + BASE_API_URL_PATH;
axios.defaults.timeout = DEFAULT_API_TIMEOUT;
axios.interceptors.request.use((config: ApiRequestConfig) => {
const token = getCurrentToken();
@@ -560,11 +561,11 @@ export default {
} as ApiRequestConfig);
},
generateQrCodeUrl: (qrCodeName: string): string => {
return `${BASE_QRCODE_PATH}/${qrCodeName}.png`;
return `${getBasePath()}${BASE_QRCODE_PATH}/${qrCodeName}.png`;
},
generateMapProxyTileImageUrl: (mapProvider: string, language: string): string => {
const token = getCurrentToken();
let url = `${BASE_PROXY_URL_PATH}/map/tile/{z}/{x}/{y}.png?provider=${mapProvider}&token=${token}`;
let url = `${getBasePath()}${BASE_PROXY_URL_PATH}/map/tile/{z}/{x}/{y}.png?provider=${mapProvider}&token=${token}`;
if (language) {
url = url + `&language=${language}`;
@@ -574,7 +575,7 @@ export default {
},
generateMapProxyAnnotationImageUrl: (mapProvider: string, language: string): string => {
const token = getCurrentToken();
let url = `${BASE_PROXY_URL_PATH}/map/annotation/{z}/{x}/{y}.png?provider=${mapProvider}&token=${token}`;
let url = `${getBasePath()}${BASE_PROXY_URL_PATH}/map/annotation/{z}/{x}/{y}.png?provider=${mapProvider}&token=${token}`;
if (language) {
url = url + `&language=${language}`;
@@ -598,7 +599,7 @@ export default {
return `${AMAP_JAVASCRIPT_URL}&key=${getAmapApplicationKey()}&plugin=AMap.ToolBar&callback=${callbackFnName}`;
},
generateAmapApiInternalProxyUrl: (): string => {
return `${window.location.origin}${BASE_AMAP_API_PROXY_URL_PATH}`;
return `${window.location.origin}${getBasePath()}${BASE_AMAP_API_PROXY_URL_PATH}`;
},
getInternalAvatarUrlWithToken(avatarUrl: string, disableBrowserCache?: boolean | string): string {
if (!avatarUrl) {
+6 -4
View File
@@ -1,3 +1,5 @@
import { getBasePath } from './web.ts';
export function isProduction(): boolean {
return __EZBOOKKEEPING_IS_PRODUCTION__;
}
@@ -28,15 +30,15 @@ export function getBuildTime(): string {
export function getMobileVersionPath(): string {
if (isProduction()) {
return '../mobile';
return getBasePath() + '/mobile#/';
} else {
return 'mobile.html';
return getBasePath() + '/mobile.html#/';
}
}
export function getDesktopVersionPath(): string {
if (isProduction()) {
return '../desktop';
return getBasePath() + '/desktop#/';
} else {
return 'desktop.html';
return getBasePath() + '/desktop.html#/';
}
}
+10
View File
@@ -0,0 +1,10 @@
export function getBasePath(): string {
const path = window.location.pathname;
const lastSlashIndex = path.lastIndexOf('/');
if (lastSlashIndex < 0) {
return path;
}
return path.substring(0, lastSlashIndex);
}