Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
csbr-daop
/
fe-data-trusted-space
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
332cfb2e
authored
2025-06-16 11:33:28 +0800
by
lxs
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
通过config.json配置appKey
1 parent
f8d8cc89
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
80 additions
and
17 deletions
public/config.json
src/main.ts
src/store/modules/sysConfig.ts
src/store/modules/user.ts
vite.config.ts
public/config.json
0 → 100644
View file @
332cfb2
{
"appKey"
:
"67bd2ff5e4b0cac8f9a5beea"
}
src/main.ts
View file @
332cfb2
...
...
@@ -6,11 +6,12 @@ import App from './App.vue'
// import pinia from './store'
import
router
from
'./router'
import
useSettingsStore
from
'./store/modules/settings'
;
import
sysConfigStore
from
'@/store/modules/sysConfig'
import
{
ElMessage
}
from
"element-plus"
import
{
openMessageBox
}
from
"@/utils/common"
// pinia设置
import
{
createPinia
}
from
'pinia'
import
{
createPinia
}
from
'pinia'
import
piniaPluginPersistedstate
from
'pinia-plugin-persistedstate'
// 自定义指令
...
...
@@ -25,18 +26,52 @@ import '@/assets/styles/globals.scss'
// 加载 iconify 图标(element plus)
import
{
downloadAndInstall
}
from
'@/iconify-ep'
const
pinia
=
createPinia
();
pinia
.
use
(
piniaPluginPersistedstate
);
const
app
=
createApp
(
App
)
app
.
use
(
ElementPlus
)
app
.
use
(
pinia
)
app
.
use
(
router
)
directive
(
app
)
if
(
useSettingsStore
().
settings
.
app
.
iconifyOfflineUse
)
{
downloadAndInstall
()
}
app
.
config
.
globalProperties
.
$passCode
=
"00000"
;
// 定义全局变量
app
.
config
.
globalProperties
.
$ElMessage
=
ElMessage
;
// 全局消息提示
app
.
config
.
globalProperties
.
$openMessageBox
=
openMessageBox
;
// 二次确认提示对话框。
app
.
mount
(
'#main-app'
)
// 封装请求配置文件的函数
const
loadConfig
=
async
()
=>
{
try
{
const
response
=
await
fetch
(
'/config.json'
);
if
(
!
response
.
ok
)
{
throw
new
Error
(
`请求配置失败,状态码:
${
response
.
status
}
`
);
}
const
config
=
await
response
.
json
();
return
config
;
}
catch
(
error
)
{
console
.
error
(
'加载配置时出错:'
,
error
);
throw
error
;
}
};
// 初始化应用的异步函数
const
initApp
=
async
()
=>
{
try
{
// 加载配置文件
const
config
=
await
loadConfig
();
const
pinia
=
createPinia
();
pinia
.
use
(
piniaPluginPersistedstate
);
// 将配置信息存储到 Pinia 中
const
configStore
=
sysConfigStore
(
pinia
);
configStore
.
setConfig
(
config
);
const
app
=
createApp
(
App
)
app
.
use
(
ElementPlus
)
app
.
use
(
pinia
)
app
.
use
(
router
)
directive
(
app
)
if
(
useSettingsStore
().
settings
.
app
.
iconifyOfflineUse
)
{
downloadAndInstall
()
}
app
.
config
.
globalProperties
.
$passCode
=
"00000"
;
// 定义全局变量
app
.
config
.
globalProperties
.
$ElMessage
=
ElMessage
;
// 全局消息提示
app
.
config
.
globalProperties
.
$openMessageBox
=
openMessageBox
;
// 二次确认提示对话框。
app
.
mount
(
'#main-app'
)
}
catch
(
error
)
{
console
.
error
(
'应用初始化失败:'
,
error
);
// 这里可以添加一些错误处理逻辑,比如显示错误提示给用户
}
};
// 启动应用
initApp
();
...
...
src/store/modules/sysConfig.ts
0 → 100644
View file @
332cfb2
const
sysConfigStore
=
defineStore
(
// 唯一ID
'config'
,
()
=>
{
let
configMap
:
any
=
{};
const
setConfig
=
(
val
)
=>
{
configMap
=
val
}
const
getConfig
=
(
field
)
=>
{
return
field
?
configMap
[
field
]:
configMap
;
}
return
{
configMap
,
setConfig
,
getConfig
}
},
)
export
default
sysConfigStore
src/store/modules/user.ts
View file @
332cfb2
import
useRouteStore
from
'./route'
import
useMenuStore
from
'./menu'
import
sysConfigStore
from
'./sysConfig'
import
router
from
'@/router'
import
{
ElMessage
}
from
'element-plus'
import
apiUser
from
'@/api/modules/user'
...
...
@@ -33,7 +34,8 @@ const useUserStore = defineStore(
function
getToken
(
data
,
state
)
{
data
.
platformGuid
=
"7f16f697aec111ef8656fa163e60becd"
;
data
.
userType
=
2
;
data
.
appKey
=
'67bd2ff5e4b0cac8f9a5beea'
;
// data.appKey = '67bd2ff5e4b0cac8f9a5beea';
data
.
appKey
=
sysConfigStore
().
getConfig
(
'appKey'
);
data
.
validateUri
=
location
.
origin
==
'http://localhost:9000'
?
'http://localhost:9000/'
:
location
.
origin
+
'/'
;
return
getTokenPromise
.
value
=
getTokenByCode
(
data
).
then
((
res
:
any
)
=>
{
getTokenPromise
.
value
=
null
;
...
...
vite.config.ts
View file @
332cfb2
...
...
@@ -61,6 +61,7 @@ export default ({ mode, command }) => {
build
:
{
outDir
:
mode
===
'product'
?
'dist'
:
`dist-
${
mode
}
`
,
sourcemap
:
env
.
VITE_BUILD_SOURCEMAP
===
'true'
,
copyPublicDir
:
true
,
// 确保 public 目录下的文件被复制到输出目录的根目录
},
define
:
{
__SYSTEM_INFO__
:
JSON
.
stringify
({
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment