feat: add dynamic config
This commit is contained in:
4
resources/admin/public/static/config.js
Normal file
4
resources/admin/public/static/config.js
Normal file
@@ -0,0 +1,4 @@
|
||||
window.admin_config = {
|
||||
title: '',
|
||||
BASE_URL: '',
|
||||
}
|
@@ -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')
|
||||
}
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user