mirror of
https://gitee.com/yiming_chang/vue-pure-admin.git
synced 2024-12-02 03:07:37 +08:00
feat:新增全局默认参数配置
This commit is contained in:
parent
01c8619124
commit
0ee38c24c8
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "vue-ts",
|
||||
"version": "0.1.0",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "vue-ts",
|
||||
"version": "0.1.0",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"serve": "vite",
|
||||
|
3
public/serverConfig.json
Normal file
3
public/serverConfig.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"version": "1.0.0"
|
||||
}
|
@ -112,6 +112,7 @@ export default defineComponent({
|
||||
|
||||
onBeforeMount(() => {
|
||||
vm = getCurrentInstance(); //获取组件实例
|
||||
console.log('vm: ', vm.appContext.config.globalProperties.$config);
|
||||
});
|
||||
|
||||
// 点击登录或注册
|
||||
|
25
src/config/index.ts
Normal file
25
src/config/index.ts
Normal file
@ -0,0 +1,25 @@
|
||||
let config: object = {}
|
||||
|
||||
const setConfig = (cfg?: any) => {
|
||||
config = Object.assign(config, cfg)
|
||||
}
|
||||
|
||||
const getConfig = (key?: string) => {
|
||||
if (typeof key === "string") {
|
||||
const arr = key.split(".")
|
||||
if (arr && arr.length) {
|
||||
let data = config
|
||||
arr.forEach(v => {
|
||||
if (data && typeof data[v] !== "undefined") {
|
||||
data = data[v]
|
||||
} else {
|
||||
data = null
|
||||
}
|
||||
})
|
||||
return data
|
||||
}
|
||||
}
|
||||
return config
|
||||
}
|
||||
|
||||
export { getConfig, setConfig }
|
39
src/main.ts
39
src/main.ts
@ -30,6 +30,41 @@ import './style/index.scss'
|
||||
import "./assets/iconfont/iconfont.js"
|
||||
import "./assets/iconfont/iconfont.css"
|
||||
|
||||
const app = createApp(App)
|
||||
import { setConfig, getConfig } from "./config"
|
||||
import axios from 'axios'
|
||||
|
||||
const app = createApp(App)
|
||||
app.config.globalProperties.$config = getConfig()
|
||||
|
||||
// 获取项目动态全局配置
|
||||
export const getServerConfig = async (): Promise<any> => {
|
||||
return axios({
|
||||
baseURL: "",
|
||||
method: "get",
|
||||
url: (app.config.globalProperties.$baseUrl || "/") + "serverConfig.json"
|
||||
}).then(({ data: config }) => {
|
||||
let $config = app.config.globalProperties.$config
|
||||
// 自动注入项目配置
|
||||
if (app && $config && typeof config === "object") {
|
||||
$config = Object.assign($config, config)
|
||||
app.config.globalProperties.$config = $config
|
||||
// 设置全局配置
|
||||
setConfig($config)
|
||||
}
|
||||
// 设置全局baseURL
|
||||
app.config.globalProperties.$baseUrl = $config.baseURL
|
||||
return $config
|
||||
}).catch(() => { throw "请在public文件夹下添加serverConfig.json配置文件" })
|
||||
}
|
||||
|
||||
getServerConfig().then(() => {
|
||||
app
|
||||
.use(store)
|
||||
.use(router)
|
||||
.use(i18n)
|
||||
.use(ElementPlus)
|
||||
.use(VXETable)
|
||||
.mount('#app')
|
||||
})
|
||||
|
||||
|
||||
app.use(store).use(router).use(i18n).use(ElementPlus).use(VXETable).mount('#app')
|
||||
|
@ -1,11 +1,3 @@
|
||||
/*
|
||||
* @Author: your name
|
||||
* @Date: 2021-02-02 15:12:44
|
||||
* @LastEditTime: 2021-02-02 15:17:37
|
||||
* @LastEditors: Please set LastEditors
|
||||
* @Description: In User Settings Edit
|
||||
* @FilePath: \CURD-TS-self\src\utils\loaders\index.ts
|
||||
*/
|
||||
interface ProxyLoader {
|
||||
loadCss(src: string): any
|
||||
loadScript(src: string): Promise<any>
|
||||
|
Loading…
Reference in New Issue
Block a user