feat: add dynamic config

This commit is contained in:
JaguarJack 2023-03-11 17:19:15 +08:00
parent c8baf7fa68
commit 0a22e9e56f
4 changed files with 20 additions and 2 deletions

View File

@ -18,5 +18,6 @@
<body>
<div id="app"></div>
<script type="module" src="../resources/admin/app.ts"></script>
<script src="./static/config.js"></script>
</body>
</html>

View File

@ -0,0 +1,4 @@
window.admin_config = {
title: '',
BASE_URL: '',
}

View File

@ -87,3 +87,16 @@ export function setPageTitle(title: string) {
export function isFunction(value: any) {
return typeof value === 'function'
}
export function _window(key: string) {
if (window.hasOwnProperty('admin_config')) {
//@ts-ignore
return window.admin_config[key]
}
return null
}
export function getBaseUrl() {
return _window('BASE_URL') ? _window('BASE_URL') : env('VITE_BASE_URL')
}

View File

@ -1,6 +1,6 @@
import { Code } from '/admin/enum/app'
import axios, { AxiosInstance, AxiosRequestConfig } from 'axios'
import { env, getAuthToken, removeAuthToken } from './helper'
import { getAuthToken, getBaseUrl, removeAuthToken } from './helper'
import Message from './message'
import router from '/admin/router'
import ResponseData from '/admin/types/responseData'
@ -134,7 +134,7 @@ class Http {
*/
protected getConfig(): AxiosRequestConfig {
// set base url
this.config.baseURL = this.baseURL ? this.baseURL : env('VITE_BASE_URL')
this.config.baseURL = getBaseUrl()
// set timeout
this.config.timeout = this.timeout ? this.timeout : 10000