1. 优化配置管理的 loading 设置

This commit is contained in:
YunaiV 2023-03-09 21:45:39 +08:00
parent 74846a11bd
commit d24d9e690a
3 changed files with 20 additions and 11 deletions

View File

@ -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

View File

@ -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>

View File

@ -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使 Object1 reactive ref // TODO reactive使 Object1 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')