1. 优化配置管理的 loading 设置
This commit is contained in:
parent
74846a11bd
commit
d24d9e690a
@ -1,7 +1,7 @@
|
|||||||
import request from '@/config/axios'
|
import request from '@/config/axios'
|
||||||
|
|
||||||
export interface ConfigVO {
|
export interface ConfigVO {
|
||||||
id: number
|
id: number | undefined
|
||||||
category: string
|
category: string
|
||||||
name: string
|
name: string
|
||||||
key: string
|
key: string
|
||||||
|
@ -86,7 +86,7 @@ const dialogStyle = computed(() => {
|
|||||||
<ElScrollbar :style="dialogStyle" v-if="scroll">
|
<ElScrollbar :style="dialogStyle" v-if="scroll">
|
||||||
<slot></slot>
|
<slot></slot>
|
||||||
</ElScrollbar>
|
</ElScrollbar>
|
||||||
<!-- 情况一:如果 scroll 为 false,说明关闭滚动条滚动条 -->
|
<!-- 情况二:如果 scroll 为 false,说明关闭滚动条滚动条 -->
|
||||||
<slot v-else></slot>
|
<slot v-else></slot>
|
||||||
|
|
||||||
<template v-if="slots.footer" #footer>
|
<template v-if="slots.footer" #footer>
|
||||||
|
@ -1,6 +1,12 @@
|
|||||||
<template>
|
<template>
|
||||||
<Dialog :title="modelTitle" v-model="modelVisible" :loading="modelLoading">
|
<Dialog :title="modelTitle" v-model="modelVisible">
|
||||||
<el-form ref="ruleFormRef" :model="formData" :rules="formRules" label-width="80px">
|
<el-form
|
||||||
|
ref="ruleFormRef"
|
||||||
|
:model="formData"
|
||||||
|
:rules="formRules"
|
||||||
|
label-width="80px"
|
||||||
|
v-loading="formLoading"
|
||||||
|
>
|
||||||
<el-form-item label="参数分类" prop="category">
|
<el-form-item label="参数分类" prop="category">
|
||||||
<el-input v-model="formData.category" placeholder="请输入参数分类" />
|
<el-input v-model="formData.category" placeholder="请输入参数分类" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
@ -42,9 +48,9 @@ const message = useMessage() // 消息弹窗
|
|||||||
|
|
||||||
const modelVisible = ref(false) // 弹窗的是否展示
|
const modelVisible = ref(false) // 弹窗的是否展示
|
||||||
const modelTitle = ref('') // 弹窗的标题
|
const modelTitle = ref('') // 弹窗的标题
|
||||||
const modelLoading = ref(false) // 弹窗的 Loading 加载
|
const formLoading = ref(false) // 表单的数据 Loading 加载
|
||||||
const formType = ref('') // 表单的类型:create - 新增;update - 修改
|
const formType = ref('') // 表单的类型:create - 新增;update - 修改
|
||||||
const formLoading = ref(false) // 操作按钮的 Loading 加载
|
const submitLoading = ref(false) // 操作按钮的 Loading 加载:避免重复提交
|
||||||
// let formRef = ref() // 表单的 Ref
|
// let formRef = ref() // 表单的 Ref
|
||||||
const formData = reactive({
|
const formData = reactive({
|
||||||
id: undefined,
|
id: undefined,
|
||||||
@ -62,7 +68,7 @@ const formRules = reactive({
|
|||||||
value: [{ required: true, message: '参数键值不能为空', trigger: 'blur' }],
|
value: [{ required: true, message: '参数键值不能为空', trigger: 'blur' }],
|
||||||
visible: [{ required: true, message: '是否可见不能为空', trigger: 'blur' }]
|
visible: [{ required: true, message: '是否可见不能为空', trigger: 'blur' }]
|
||||||
})
|
})
|
||||||
const ruleFormRef = ref<FormInstance>() // 表单 Ref
|
let ruleFormRef = ref<FormInstance>() // 表单 Ref
|
||||||
|
|
||||||
const { proxy } = getCurrentInstance() as any
|
const { proxy } = getCurrentInstance() as any
|
||||||
|
|
||||||
@ -74,13 +80,13 @@ const openModal = async (type: string, id?: number) => {
|
|||||||
resetForm()
|
resetForm()
|
||||||
// 修改时,设置数据
|
// 修改时,设置数据
|
||||||
if (id) {
|
if (id) {
|
||||||
modelLoading.value = true
|
formLoading.value = true
|
||||||
try {
|
try {
|
||||||
const data = await ConfigApi.getConfig(id)
|
const data = await ConfigApi.getConfig(id)
|
||||||
// TODO 规范纠结点:因为用 reactive,所以需要使用 Object;可以替换的方案,1)把 reactive 改成 ref;
|
// TODO 规范纠结点:因为用 reactive,所以需要使用 Object;可以替换的方案,1)把 reactive 改成 ref;
|
||||||
Object.assign(formData, data)
|
Object.assign(formData, data)
|
||||||
} finally {
|
} finally {
|
||||||
modelLoading.value = false
|
formLoading.value = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -95,7 +101,7 @@ const submitForm = async () => {
|
|||||||
const valid = await formRef.validate()
|
const valid = await formRef.validate()
|
||||||
if (!valid) return
|
if (!valid) return
|
||||||
// 提交请求
|
// 提交请求
|
||||||
formLoading.value = true
|
submitLoading.value = true
|
||||||
try {
|
try {
|
||||||
const data = formData as ConfigApi.ConfigVO
|
const data = formData as ConfigApi.ConfigVO
|
||||||
if (formType.value === 'create') {
|
if (formType.value === 'create') {
|
||||||
@ -108,7 +114,7 @@ const submitForm = async () => {
|
|||||||
modelVisible.value = false
|
modelVisible.value = false
|
||||||
emit('success')
|
emit('success')
|
||||||
} finally {
|
} finally {
|
||||||
formLoading.value = false
|
submitLoading.value = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,6 +127,9 @@ const resetForm = () => {
|
|||||||
formData.value = ''
|
formData.value = ''
|
||||||
formData.visible = true
|
formData.visible = true
|
||||||
formData.remark = ''
|
formData.remark = ''
|
||||||
|
// 重置表单
|
||||||
|
console.log(ruleFormRef)
|
||||||
|
console.log(ruleFormRef.value)
|
||||||
// proxy.$refs['ruleFormRef'].resetFields()
|
// proxy.$refs['ruleFormRef'].resetFields()
|
||||||
// setTimeout(() => {
|
// setTimeout(() => {
|
||||||
// console.log(ruleFormRef.value, 'formRef.value')
|
// console.log(ruleFormRef.value, 'formRef.value')
|
||||||
|
Loading…
Reference in New Issue
Block a user