Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
admin
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
dcc79669
authored
Mar 09, 2023
by
YunaiV
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
vue3 重构:配置管理,微调
parent
9ef85e14
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
24 deletions
+25
-24
src/api/infra/config/index.ts
+2
-2
src/config/axios/service.ts
+0
-1
src/views/infra/config/form.vue
+23
-21
No files found.
src/api/infra/config/index.ts
View file @
dcc79669
...
@@ -42,12 +42,12 @@ export const getConfigKeyApi = (configKey: string) => {
...
@@ -42,12 +42,12 @@ export const getConfigKeyApi = (configKey: string) => {
}
}
// 新增参数
// 新增参数
export
const
createConfig
Api
=
(
data
:
ConfigVO
)
=>
{
export
const
createConfig
=
(
data
:
ConfigVO
)
=>
{
return
request
.
post
({
url
:
'/infra/config/create'
,
data
})
return
request
.
post
({
url
:
'/infra/config/create'
,
data
})
}
}
// 修改参数
// 修改参数
export
const
updateConfig
Api
=
(
data
:
ConfigVO
)
=>
{
export
const
updateConfig
=
(
data
:
ConfigVO
)
=>
{
return
request
.
put
({
url
:
'/infra/config/update'
,
data
})
return
request
.
put
({
url
:
'/infra/config/update'
,
data
})
}
}
...
...
src/config/axios/service.ts
View file @
dcc79669
...
@@ -170,7 +170,6 @@ service.interceptors.response.use(
...
@@ -170,7 +170,6 @@ service.interceptors.response.use(
return
Promise
.
reject
(
new
Error
(
msg
))
return
Promise
.
reject
(
new
Error
(
msg
))
}
else
if
(
code
===
901
)
{
}
else
if
(
code
===
901
)
{
ElMessage
.
error
({
ElMessage
.
error
({
duration
:
5
,
offset
:
300
,
offset
:
300
,
dangerouslyUseHTMLString
:
true
,
dangerouslyUseHTMLString
:
true
,
message
:
message
:
...
...
src/views/infra/config/form.vue
View file @
dcc79669
...
@@ -36,7 +36,6 @@
...
@@ -36,7 +36,6 @@
<
script
setup
lang=
"ts"
>
<
script
setup
lang=
"ts"
>
import
*
as
ConfigApi
from
'@/api/infra/config'
import
*
as
ConfigApi
from
'@/api/infra/config'
// import type { FormExpose } from '@/components/Form'
// import type { FormExpose } from '@/components/Form'
import
*
as
PostApi
from
'@/api/system/post'
const
{
t
}
=
useI18n
()
// 国际化
const
{
t
}
=
useI18n
()
// 国际化
const
message
=
useMessage
()
// 消息弹窗
const
message
=
useMessage
()
// 消息弹窗
// const { proxy } = getCurrentInstance()
// const { proxy } = getCurrentInstance()
...
@@ -46,15 +45,15 @@ const modelTitle = ref('') // 弹窗的标题
...
@@ -46,15 +45,15 @@ const modelTitle = ref('') // 弹窗的标题
const
modelLoading
=
ref
(
false
)
// 弹窗的 Loading 加载
const
modelLoading
=
ref
(
false
)
// 弹窗的 Loading 加载
const
formType
=
ref
(
''
)
// 表单的类型:create - 新增;update - 修改
const
formType
=
ref
(
''
)
// 表单的类型:create - 新增;update - 修改
const
formLoading
=
ref
(
false
)
// 操作按钮的 Loading 加载
const
formLoading
=
ref
(
false
)
// 操作按钮的 Loading 加载
let
formRef
=
ref
()
// 表单的 Ref
//
let formRef = ref() // 表单的 Ref
const
formData
=
reactive
({
const
formData
=
reactive
({
id
:
undefined
,
id
:
0
,
category
:
undefined
,
category
:
''
,
name
:
undefined
,
name
:
''
,
key
:
undefined
,
key
:
''
,
value
:
undefined
,
value
:
''
,
visible
:
true
,
visible
:
true
,
remark
:
undefined
remark
:
''
})
})
const
formRules
=
reactive
({
const
formRules
=
reactive
({
category
:
[{
required
:
true
,
message
:
'参数分类不能为空'
,
trigger
:
'blur'
}],
category
:
[{
required
:
true
,
message
:
'参数分类不能为空'
,
trigger
:
'blur'
}],
...
@@ -65,6 +64,8 @@ const formRules = reactive({
...
@@ -65,6 +64,8 @@ const formRules = reactive({
})
})
// const formRef = ref
<
FormExpose
>
()
// 表单 Ref
// const formRef = ref
<
FormExpose
>
()
// 表单 Ref
const
{
proxy
}
=
getCurrentInstance
()
as
any
/** 打开弹窗 */
/** 打开弹窗 */
const
openModal
=
async
(
type
:
string
,
id
?:
number
)
=>
{
const
openModal
=
async
(
type
:
string
,
id
?:
number
)
=>
{
modelVisible
.
value
=
true
modelVisible
.
value
=
true
...
@@ -84,20 +85,21 @@ defineExpose({ openModal }) // 提供 openModal 方法,用于打开弹窗
...
@@ -84,20 +85,21 @@ defineExpose({ openModal }) // 提供 openModal 方法,用于打开弹窗
/** 提交表单 */
/** 提交表单 */
const
emit
=
defineEmits
([
'success'
])
// 定义 success 事件,用于操作成功后的回调
const
emit
=
defineEmits
([
'success'
])
// 定义 success 事件,用于操作成功后的回调
const
submitForm
=
async
()
=>
{
const
submitForm
=
async
()
=>
{
const
formRef
=
proxy
.
$refs
[
'formRef'
]
console
.
log
(
formRef
,
'======'
)
// 校验表单
// 校验表单
const
elForm
=
unref
(
formRef
)?.
getElFormRef
()
if
(
!
formRef
)
return
if
(
!
elForm
)
return
const
valid
=
await
formRef
.
validate
()
const
valid
=
await
elForm
.
validate
()
if
(
!
valid
)
return
if
(
!
valid
)
return
// 提交请求
// 提交请求
formLoading
.
value
=
true
formLoading
.
value
=
true
try
{
try
{
const
data
=
unref
(
formRef
)?.
formModel
as
PostApi
.
Post
VO
const
data
=
formData
as
ConfigApi
.
Config
VO
if
(
formType
.
value
===
'create'
)
{
if
(
formType
.
value
===
'create'
)
{
await
PostApi
.
createPostApi
(
data
)
await
ConfigApi
.
createConfig
(
data
)
message
.
success
(
t
(
'common.createSuccess'
))
message
.
success
(
t
(
'common.createSuccess'
))
}
else
{
}
else
{
await
PostApi
.
updatePostApi
(
data
)
await
ConfigApi
.
updateConfig
(
data
)
message
.
success
(
t
(
'common.updateSuccess'
))
message
.
success
(
t
(
'common.updateSuccess'
))
}
}
modelVisible
.
value
=
false
modelVisible
.
value
=
false
...
@@ -109,14 +111,14 @@ const submitForm = async () => {
...
@@ -109,14 +111,14 @@ const submitForm = async () => {
/** 重置表单 */
/** 重置表单 */
const
resetForm
=
()
=>
{
const
resetForm
=
()
=>
{
formData
.
id
=
undefined
formData
.
id
=
0
formData
.
category
=
undefined
formData
.
category
=
''
formData
.
name
=
undefined
formData
.
name
=
''
formData
.
key
=
undefined
formData
.
key
=
''
formData
.
value
=
undefined
formData
.
value
=
''
formData
.
visible
=
true
formData
.
visible
=
true
formData
.
remark
=
undefined
formData
.
remark
=
''
// proxy.$refs['formRef'].resetFields()
// proxy.$refs['formRef'].resetFields()
// formRef.value.resetFields() // TODO 芋艿:为什么拿不到
// formRef.value.resetFields() // TODO 芋艿:为什么拿不到
formRef 呢?
}
}
</
script
>
</
script
>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment