修改模态框对象类型.

This commit is contained in:
lijiahang
2023-09-25 14:36:13 +08:00
parent e1fafbe135
commit 09610b3c82
29 changed files with 1450 additions and 2658 deletions

View File

@@ -60,7 +60,7 @@
</script>
<script lang="ts" setup>
import { reactive, ref } from 'vue';
import { ref } from 'vue';
import useLoading from '@/hooks/loading';
import useVisible from '@/hooks/visible';
import formRules from '../types/form.rules';
@@ -74,7 +74,7 @@
const title = ref<string>();
const isAddHandle = ref<boolean>(true);
const defaultForm = (): HostIdentityUpdateRequest & Record<string, any> => {
const defaultForm = (): HostIdentityUpdateRequest => {
return {
id: undefined,
name: undefined,
@@ -86,7 +86,7 @@
};
const formRef = ref();
const formModel = reactive<HostIdentityUpdateRequest & Record<string, any>>(defaultForm());
const formModel = ref<HostIdentityUpdateRequest>({});
const emits = defineEmits(['added', 'updated']);
@@ -108,11 +108,7 @@
// 渲染表单
const renderForm = (record: any) => {
Object.keys(formModel).forEach(k => {
if (record.hasOwnProperty(k)) {
formModel[k] = record[k];
}
});
formModel.value = Object.assign({}, record);
};
defineExpose({ openAdd, openUpdate });
@@ -127,17 +123,17 @@
return false;
}
if (isAddHandle.value) {
if (!formModel.password && !formModel.keyId) {
if (!formModel.value.password && !formModel.value.keyId) {
Message.error('创建时密码和秘钥不能同时为空');
return false;
}
// 新增
await createHostIdentity(formModel);
await createHostIdentity(formModel.value);
Message.success('创建成功');
emits('added');
} else {
// 修改
await updateHostIdentity(formModel);
await updateHostIdentity(formModel.value);
Message.success('修改成功');
emits('updated');
}

View File

@@ -7,7 +7,10 @@
@reset="fetchTableData">
<!-- id -->
<a-form-item field="id" label="id" label-col-flex="50px">
<a-input-number v-model="formModel.id" placeholder="请输入id" allow-clear />
<a-input-number v-model="formModel.id"
placeholder="请输入id"
allow-clear
hide-button />
</a-form-item>
<!-- 名称 -->
<a-form-item field="name" label="名称" label-col-flex="50px">
@@ -53,7 +56,7 @@
:loading="loading"
:columns="columns"
:data="tableRenderData"
:pagination="pagination as PaginationProps"
:pagination="pagination"
@page-change="(page) => fetchTableData(page, pagination.pageSize)"
@page-size-change="(size) => fetchTableData(pagination.current, size)"
:bordered="false">
@@ -138,7 +141,7 @@
const emits = defineEmits(['openAdd', 'openUpdate', 'openKeyView']);
const cacheStore = useCacheStore();
const pagination = reactive(defaultPagination());
const pagination = reactive(defaultPagination()) as PaginationProps;
const formModel = reactive<HostIdentityQueryRequest>({
id: undefined,
@@ -148,7 +151,9 @@
});
// 删除当前行
const deleteRow = async ({ id }: { id: number }) => {
const deleteRow = async ({ id }: {
id: number
}) => {
try {
setLoading(true);
// 调用删除接口