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
30dea302
authored
Mar 10, 2023
by
YunaiV
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
重构:调整 formData 使用 ref。原因是,原本的 reactive 无法整个赋值
parent
d989fa20
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
7 deletions
+7
-7
src/views/infra/config/form.vue
+7
-7
No files found.
src/views/infra/config/form.vue
View file @
30dea302
...
@@ -40,6 +40,7 @@
...
@@ -40,6 +40,7 @@
</template>
</template>
<
script
setup
lang=
"ts"
>
<
script
setup
lang=
"ts"
>
import
*
as
ConfigApi
from
'@/api/infra/config'
import
*
as
ConfigApi
from
'@/api/infra/config'
const
{
t
}
=
useI18n
()
// 国际化
const
{
t
}
=
useI18n
()
// 国际化
const
message
=
useMessage
()
// 消息弹窗
const
message
=
useMessage
()
// 消息弹窗
...
@@ -47,7 +48,7 @@ const modelVisible = ref(false) // 弹窗的是否展示
...
@@ -47,7 +48,7 @@ const modelVisible = ref(false) // 弹窗的是否展示
const
modelTitle
=
ref
(
''
)
// 弹窗的标题
const
modelTitle
=
ref
(
''
)
// 弹窗的标题
const
formLoading
=
ref
(
false
)
// 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
const
formLoading
=
ref
(
false
)
// 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
const
formType
=
ref
(
''
)
// 表单的类型:create - 新增;update - 修改
const
formType
=
ref
(
''
)
// 表单的类型:create - 新增;update - 修改
const
formData
=
re
active
({
const
formData
=
re
f
({
id
:
undefined
,
id
:
undefined
,
category
:
''
,
category
:
''
,
name
:
''
,
name
:
''
,
...
@@ -75,9 +76,7 @@ const openModal = async (type: string, id?: number) => {
...
@@ -75,9 +76,7 @@ const openModal = async (type: string, id?: number) => {
if
(
id
)
{
if
(
id
)
{
formLoading
.
value
=
true
formLoading
.
value
=
true
try
{
try
{
const
data
=
await
ConfigApi
.
getConfig
(
id
)
formData
.
value
=
await
ConfigApi
.
getConfig
(
id
)
// TODO 规范纠结点:因为用 reactive,所以需要使用 Object;可以替换的方案,1)把 reactive 改成 ref;
Object
.
assign
(
formData
,
data
)
}
finally
{
}
finally
{
formLoading
.
value
=
false
formLoading
.
value
=
false
}
}
...
@@ -95,7 +94,7 @@ const submitForm = async () => {
...
@@ -95,7 +94,7 @@ const submitForm = async () => {
// 提交请求
// 提交请求
formLoading
.
value
=
true
formLoading
.
value
=
true
try
{
try
{
const
data
=
formData
as
ConfigApi
.
ConfigVO
const
data
=
formData
.
value
as
ConfigApi
.
ConfigVO
if
(
formType
.
value
===
'create'
)
{
if
(
formType
.
value
===
'create'
)
{
await
ConfigApi
.
createConfig
(
data
)
await
ConfigApi
.
createConfig
(
data
)
message
.
success
(
t
(
'common.createSuccess'
))
message
.
success
(
t
(
'common.createSuccess'
))
...
@@ -104,6 +103,7 @@ const submitForm = async () => {
...
@@ -104,6 +103,7 @@ const submitForm = async () => {
message
.
success
(
t
(
'common.updateSuccess'
))
message
.
success
(
t
(
'common.updateSuccess'
))
}
}
modelVisible
.
value
=
false
modelVisible
.
value
=
false
// 发送操作成功的事件
emit
(
'success'
)
emit
(
'success'
)
}
finally
{
}
finally
{
formLoading
.
value
=
false
formLoading
.
value
=
false
...
@@ -112,7 +112,7 @@ const submitForm = async () => {
...
@@ -112,7 +112,7 @@ const submitForm = async () => {
/** 重置表单 */
/** 重置表单 */
const
resetForm
=
()
=>
{
const
resetForm
=
()
=>
{
Object
.
assign
(
formData
,
{
formData
.
value
=
{
id
:
undefined
,
id
:
undefined
,
category
:
''
,
category
:
''
,
name
:
''
,
name
:
''
,
...
@@ -120,7 +120,7 @@ const resetForm = () => {
...
@@ -120,7 +120,7 @@ const resetForm = () => {
value
:
''
,
value
:
''
,
visible
:
true
,
visible
:
true
,
remark
:
''
remark
:
''
}
)
}
formRef
.
value
?.
resetFields
()
formRef
.
value
?.
resetFields
()
}
}
</
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