1. 修复 DictTag 对 boolean 的 false 处理不展示

2. vue 重构:增加配置管理的 form 表单
This commit is contained in:
YunaiV 2023-03-08 22:51:07 +08:00
parent 4c47ca9166
commit 64b249e743
5 changed files with 147 additions and 173 deletions

View File

@ -34,7 +34,7 @@ export default defineComponent({
return null
}
//
if (!props.value && props.value !== 0) {
if (props.value === undefined) {
return null
}
getDictObj(props.type, props.value.toString())

View File

@ -55,7 +55,7 @@ export const getBoolDictOptions = (dictType: string) => {
dictOptions.forEach((dict: DictDataType) => {
dictOption.push({
...dict,
value: dict.value + '' === 'true' ? true : false
value: dict.value + '' === 'true'
})
})
return dictOption

View File

@ -0,0 +1,122 @@
<template>
<XModal :title="modelTitle" :loading="modelLoading" v-model="modelVisible">
<el-form ref="formRef" :model="form" :rules="rules" label-width="80px">
<el-form-item label="参数分类" prop="category">
<el-input v-model="form.category" placeholder="请输入参数分类" />
</el-form-item>
<el-form-item label="参数名称" prop="name">
<el-input v-model="form.name" placeholder="请输入参数名称" />
</el-form-item>
<el-form-item label="参数键名" prop="key">
<el-input v-model="form.key" placeholder="请输入参数键名" />
</el-form-item>
<el-form-item label="参数键值" prop="value">
<el-input v-model="form.value" placeholder="请输入参数键值" />
</el-form-item>
<el-form-item label="是否可见" prop="visible">
<!-- TODO 芋艿改成组件 -->
<el-radio-group v-model="form.visible">
<el-radio :key="true" :label="true"></el-radio>
<el-radio :key="false" :label="false"></el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="备注" prop="remark">
<el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
</el-form-item>
</el-form>
<template #footer>
<div class="dialog-footer">
<el-button type="primary" @click="submitForm"> </el-button>
<el-button @click="modelLoading = false"> </el-button>
</div>
</template>
</XModal>
</template>
<script setup lang="ts">
// import type { FormExpose } from '@/components/Form'
import * as PostApi from '@/api/system/post'
const { t } = useI18n() //
const message = useMessage() //
const modelVisible = ref(false) //
const modelTitle = ref('') //
const modelLoading = ref(false) // Loading
const actionType = ref('') // create - update -
const actionLoading = ref(false) // Loading
const formRef = ref() // Ref
const form = reactive({
id: undefined,
category: undefined,
name: undefined,
key: undefined,
value: undefined,
visible: true,
remark: undefined
})
const rules = reactive({
category: [{ required: true, message: '参数分类不能为空', trigger: 'blur' }],
name: [{ required: true, message: '参数名称不能为空', trigger: 'blur' }],
key: [{ required: true, message: '参数键名不能为空', trigger: 'blur' }],
value: [{ required: true, message: '参数键值不能为空', trigger: 'blur' }],
visible: [{ required: true, message: '是否可见不能为空', trigger: 'blur' }]
})
// const formRef = ref<FormExpose>() // Ref
/** 打开弹窗 */
const openModal = async (type: string, id?: number) => {
modelVisible.value = true
modelLoading.value = true
modelTitle.value = t('action.' + type)
actionType.value = type
//
resetForm()
if (id) {
// const res = await PostApi.getPostApi(id)
// if (type === 'update') {
// unref(formRef)?.setValues(res)
// } else if (type === 'detail') {
// detailData.value = res
// }
}
modelLoading.value = false
}
defineExpose({ openModal }) // openModal
/** 提交表单 */
const emit = defineEmits(['success']) // success
const submitForm = async () => {
//
const elForm = unref(formRef)?.getElFormRef()
if (!elForm) return
const valid = await elForm.validate()
if (!valid) return
//
actionLoading.value = true
try {
const data = unref(formRef)?.formModel as PostApi.PostVO
if (actionType.value === 'create') {
await PostApi.createPostApi(data)
message.success(t('common.createSuccess'))
} else {
await PostApi.updatePostApi(data)
message.success(t('common.updateSuccess'))
}
modelVisible.value = false
emit('success')
} finally {
actionLoading.value = false
}
}
/** 重置表单 */
const resetForm = () => {
form.id = undefined
form.category = undefined
form.name = undefined
form.key = undefined
form.value = undefined
form.visible = true
form.remark = undefined
formRef.value.resetFields()
}
</script>

View File

@ -26,12 +26,16 @@
@keyup.enter="handleQuery"
/>
</el-form-item>
<!-- <el-form-item label="系统内置" prop="type">-->
<!-- <el-select v-model="queryParams.type" placeholder="系统内置" clearable>-->
<!-- <el-option v-for="dict in this.getDictDatas(DICT_TYPE.INFRA_CONFIG_TYPE)" :key="parseInt(dict.value)"-->
<!-- :label="dict.label" :value="parseInt(dict.value)"/>-->
<!-- </el-select>-->
<!-- </el-form-item>-->
<el-form-item label="系统内置" prop="type">
<el-select v-model="queryParams.type" placeholder="请选择系统内置" clearable>
<el-option
v-for="dict in getDictOptions(DICT_TYPE.INFRA_CONFIG_TYPE)"
:key="parseInt(dict.value)"
:label="dict.label"
:value="parseInt(dict.value)"
/>
</el-select>
</el-form-item>
<!-- TODO时间无法设置 -->
<el-form-item label="创建时间" prop="createTime">
<el-date-picker
@ -92,7 +96,6 @@
<el-table-column label="参数键值" align="center" prop="value" />
<el-table-column label="是否可见" align="center" prop="visible">
<template #default="scope">
<!-- TODO 芋艿这里 false 会不展示实现略有问题 -->
<dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="scope.row.visible" />
</template>
</el-table-column>
@ -116,7 +119,7 @@
link
type="primary"
icon="el-icon-edit"
@click="handleUpdate(scope.row)"
@click="openModal('update', scope.row.id)"
v-hasPermi="['infra:config:update']"
>
修改
@ -134,10 +137,15 @@
</el-table-column>
</el-table>
</content-wrap>
<!-- 表单弹窗添加/修改 -->
<!-- TODO 芋艿可以改成 form -->
<config-form ref="modalRef" @success="getList" />
</template>
<script setup lang="ts" name="Config">
import * as ConfigApi from '@/api/infra/config'
import { DICT_TYPE } from '@/utils/dict'
import ConfigForm from './form.vue'
import { DICT_TYPE, getDictOptions } from '@/utils/dict'
import dayjs from 'dayjs'
const showSearch = ref(true) //
@ -178,6 +186,12 @@ const resetQuery = () => {
handleQuery()
}
/** 添加/修改操作 */
const modalRef = ref()
const openModal = (type: string, id?: number) => {
modalRef.value.openModal(type, id)
}
// ========== ==========
onMounted(() => {
getList()

View File

@ -1,162 +0,0 @@
<template>
<ContentWrap>
<!-- 列表 -->
<XTable @register="registerTable">
<template #toolbar_buttons>
<!-- 操作新增 -->
<XButton
type="primary"
preIcon="ep:zoom-in"
:title="t('action.add')"
v-hasPermi="['infra:config:create']"
@click="handleCreate()"
/>
<!-- 操作导出 -->
<XButton
type="warning"
preIcon="ep:download"
:title="t('action.export')"
v-hasPermi="['infra:config:export']"
@click="exportList('配置.xls')"
/>
</template>
<template #visible_default="{ row }">
<span>{{ row.visible ? '是' : '否' }} </span>
</template>
<template #actionbtns_default="{ row }">
<!-- 操作修改 -->
<XTextButton
preIcon="ep:edit"
:title="t('action.edit')"
v-hasPermi="['infra:config:update']"
@click="handleUpdate(row.id)"
/>
<!-- 操作详情 -->
<XTextButton
preIcon="ep:view"
:title="t('action.detail')"
v-hasPermi="['infra:config:query']"
@click="handleDetail(row.id)"
/>
<!-- 操作删除 -->
<XTextButton
preIcon="ep:delete"
:title="t('action.del')"
v-hasPermi="['infra:config:delete']"
@click="deleteData(row.id)"
/>
</template>
</XTable>
</ContentWrap>
<XModal v-model="dialogVisible" :title="dialogTitle">
<!-- 对话框(添加 / 修改) -->
<Form
v-if="['create', 'update'].includes(actionType)"
:schema="allSchemas.formSchema"
:rules="rules"
ref="formRef"
/>
<!-- 对话框(详情) -->
<Descriptions
v-if="actionType === 'detail'"
:schema="allSchemas.detailSchema"
:data="detailData"
>
<template #visible="{ row }">
<span>{{ row.visible ? '是' : '否' }} </span>
</template>
</Descriptions>
<!-- 操作按钮 -->
<template #footer>
<!-- 按钮保存 -->
<XButton
v-if="['create', 'update'].includes(actionType)"
type="primary"
:title="t('action.save')"
:loading="actionLoading"
@click="submitForm()"
/>
<!-- 按钮关闭 -->
<XButton :loading="actionLoading" :title="t('dialog.close')" @click="dialogVisible = false" />
</template>
</XModal>
</template>
<script setup lang="ts" name="Config">
import type { FormExpose } from '@/components/Form'
// import
import * as ConfigApi from '@/api/infra/config'
import { rules, allSchemas } from './config.data'
const { t } = useI18n() //
const message = useMessage() //
//
const [registerTable, { reload, deleteData, exportList }] = useXTable({
allSchemas: allSchemas,
getListApi: ConfigApi.getConfigPage,
deleteApi: ConfigApi.deleteConfigApi,
exportListApi: ConfigApi.exportConfigApi
})
// ========== CRUD ==========
const actionLoading = ref(false) //
const actionType = ref('') //
const dialogVisible = ref(false) //
const dialogTitle = ref('edit') //
const formRef = ref<FormExpose>() // Ref
const detailData = ref() // Ref
//
const setDialogTile = (type: string) => {
dialogTitle.value = t('action.' + type)
actionType.value = type
dialogVisible.value = true
}
//
const handleCreate = () => {
setDialogTile('create')
}
//
const handleUpdate = async (rowId: number) => {
setDialogTile('update')
//
const res = await ConfigApi.getConfigApi(rowId)
unref(formRef)?.setValues(res)
}
//
const handleDetail = async (rowId: number) => {
setDialogTile('detail')
const res = await ConfigApi.getConfigApi(rowId)
detailData.value = res
}
//
const submitForm = async () => {
const elForm = unref(formRef)?.getElFormRef()
if (!elForm) return
elForm.validate(async (valid) => {
if (valid) {
actionLoading.value = true
//
try {
const data = unref(formRef)?.formModel as ConfigApi.ConfigVO
if (actionType.value === 'create') {
await ConfigApi.createConfigApi(data)
message.success(t('common.createSuccess'))
} else {
await ConfigApi.updateConfigApi(data)
message.success(t('common.updateSuccess'))
}
dialogVisible.value = false
} finally {
actionLoading.value = false
//
await reload()
}
}
})
}
</script>