复制产品模型已实现
This commit is contained in:
parent
f349409516
commit
328e4b2c2f
@ -517,7 +517,7 @@ export const postThingModelInfoFindByPlatformProductIdAsync = <ThrowOnError exte
|
||||
};
|
||||
|
||||
/**
|
||||
* 根据数据ID复制已存在物模型信息
|
||||
* 复制已存在产品设备物模型信息
|
||||
*/
|
||||
export const postThingModelInfoCopyAnotherThingModelAsync = <ThrowOnError extends boolean = false>(options?: Options<PostThingModelInfoCopyAnotherThingModelAsyncData, ThrowOnError>) => {
|
||||
return (options?.client ?? client).post<PostThingModelInfoCopyAnotherThingModelAsyncResponse, PostThingModelInfoCopyAnotherThingModelAsyncError, ThrowOnError>({
|
||||
@ -537,7 +537,7 @@ export const postThingModelInfoCopyStandardThingModel = <ThrowOnError extends bo
|
||||
};
|
||||
|
||||
/**
|
||||
* 分页查询设备信息
|
||||
* 分页查询物模型信息
|
||||
*/
|
||||
export const postThingModelInfoPageAsync = <ThrowOnError extends boolean = false>(options?: Options<PostThingModelInfoPageAsyncData, ThrowOnError>) => {
|
||||
return (options?.client ?? client).post<PostThingModelInfoPageAsyncResponse, PostThingModelInfoPageAsyncError, ThrowOnError>({
|
||||
|
||||
@ -11,6 +11,7 @@ import { message as Message, Modal, Tag } from 'ant-design-vue';
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import {
|
||||
postThingModelInfoCopyAnotherThingModelAsync,
|
||||
postThingModelInfoCopyStandardThingModel,
|
||||
postThingModelInfoCreateAsync,
|
||||
postThingModelInfoDeleteAsync,
|
||||
@ -22,6 +23,7 @@ import { $t } from '#/locales';
|
||||
|
||||
import {
|
||||
addThingModelFormSchema,
|
||||
copyThingModelFormSchema,
|
||||
editThingModelFormSchema,
|
||||
querySchema,
|
||||
tableSchema,
|
||||
@ -83,6 +85,8 @@ const gridOptions: VxeGridProps<any> = {
|
||||
...formValues,
|
||||
},
|
||||
});
|
||||
// 更新数据状态,检查是否有数据
|
||||
hasData.value = data?.items && data.items.length > 0;
|
||||
return data;
|
||||
},
|
||||
},
|
||||
@ -93,6 +97,10 @@ const [Grid, gridApi] = useVbenVxeGrid({ formOptions, gridOptions });
|
||||
|
||||
const editRow: Record<string, any> = ref({});
|
||||
|
||||
// 跟踪数据状态,用于控制按钮显示
|
||||
const hasData = ref(true);
|
||||
|
||||
|
||||
const [ThingModelModal, thingModelModalApi] = useVbenModal({
|
||||
draggable: true,
|
||||
footer: true,
|
||||
@ -115,6 +123,20 @@ const [ThingModelModal, thingModelModalApi] = useVbenModal({
|
||||
},
|
||||
});
|
||||
|
||||
const [CopyModal, copyModalApi] = useVbenModal({
|
||||
draggable: true,
|
||||
footer: true,
|
||||
showCancelButton: true,
|
||||
showConfirmButton: true,
|
||||
onConfirm: submitCopy,
|
||||
onBeforeClose: () => {
|
||||
return true;
|
||||
},
|
||||
onCancel: () => {
|
||||
copyModalApi.close();
|
||||
},
|
||||
});
|
||||
|
||||
const [AddForm, addFormApi] = useVbenForm({
|
||||
collapsed: false,
|
||||
commonConfig: {
|
||||
@ -145,6 +167,21 @@ const [EditForm, editFormApi] = useVbenForm({
|
||||
wrapperClass: 'grid-cols-2',
|
||||
});
|
||||
|
||||
const [CopyForm, copyFormApi] = useVbenForm({
|
||||
collapsed: false,
|
||||
commonConfig: {
|
||||
labelWidth: 110,
|
||||
componentProps: {
|
||||
class: 'w-4/5',
|
||||
},
|
||||
},
|
||||
layout: 'horizontal',
|
||||
schema: copyThingModelFormSchema.value,
|
||||
showCollapseButton: false,
|
||||
showDefaultActions: false,
|
||||
wrapperClass: 'grid-cols-2',
|
||||
});
|
||||
|
||||
// 监听props变化,自动设置筛选条件
|
||||
watch(
|
||||
() => [props.visible, props.productId, props.ioTPlatform],
|
||||
@ -235,6 +272,41 @@ const openAddModal = async () => {
|
||||
thingModelModalApi.open();
|
||||
};
|
||||
|
||||
// 打开复制已有模型模态框
|
||||
const openCopyAnotherThingModelModal = async () => {
|
||||
copyModalApi.open();
|
||||
};
|
||||
|
||||
// 复制提交逻辑
|
||||
async function submitCopy() {
|
||||
const { valid } = await copyFormApi.validate();
|
||||
if (!valid) return;
|
||||
|
||||
const formValues = await copyFormApi.getValues();
|
||||
|
||||
try {
|
||||
const resp = await postThingModelInfoCopyAnotherThingModelAsync({
|
||||
body: {
|
||||
ioTPlatform: Number.parseInt(props.ioTPlatform) as 1 | 2,
|
||||
ioTPlatformProductId: props.productId,
|
||||
sourceProductId: formValues.sourceProductId,
|
||||
filedType: formValues.filedType,
|
||||
},
|
||||
});
|
||||
|
||||
if (resp.data) {
|
||||
Message.success('复制模型成功');
|
||||
copyModalApi.close();
|
||||
gridApi.reload();
|
||||
} else {
|
||||
Message.error('复制模型失败');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('复制模型失败:', error);
|
||||
Message.error('复制模型失败');
|
||||
}
|
||||
}
|
||||
|
||||
// 删除函数
|
||||
async function onDel(record: any) {
|
||||
try {
|
||||
@ -279,6 +351,7 @@ function closeModal() {
|
||||
emit('update:visible', false);
|
||||
emit('close');
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@ -303,6 +376,14 @@ function closeModal() {
|
||||
onClick: copyStandardThingModel,
|
||||
auth: ['AbpIdentity.Users.Create'],
|
||||
},
|
||||
{
|
||||
label: '复制已有模型',
|
||||
type: 'default',
|
||||
icon: 'ant-design:copy-outlined',
|
||||
onClick: openCopyAnotherThingModelModal,
|
||||
auth: ['AbpIdentity.Users.Create'],
|
||||
ifShow: !hasData,
|
||||
},
|
||||
]" />
|
||||
</template>
|
||||
|
||||
@ -343,4 +424,9 @@ function closeModal() {
|
||||
<component :is="editRow.id ? EditForm : AddForm" />
|
||||
</ThingModelModal>
|
||||
</Modal>
|
||||
|
||||
<!-- 复制已有模型模态框 -->
|
||||
<CopyModal title="复制已有模型" class="w-[600px]">
|
||||
<CopyForm />
|
||||
</CopyModal>
|
||||
</template>
|
||||
|
||||
@ -4,7 +4,7 @@ import { z } from '@vben/common-ui';
|
||||
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
import { getCommonGetSelectList } from '#/api-client';
|
||||
import { getCommonGetSelectList, postOneNetProductListAsync } from '#/api-client';
|
||||
import { $t } from '#/locales';
|
||||
|
||||
export const querySchema = computed(() => [
|
||||
@ -360,3 +360,82 @@ export const editThingModelFormSchema = computed(() => [
|
||||
},
|
||||
},
|
||||
]);
|
||||
|
||||
// 复制已有模型表单schema
|
||||
export const copyThingModelFormSchema = computed(() => [
|
||||
{
|
||||
component: 'ApiSelect',
|
||||
fieldName: 'sourceProductId',
|
||||
label: '选择要复制的产品',
|
||||
rules: z.preprocess(
|
||||
(v) => (v == null ? '' : v),
|
||||
z.string().min(1, '请选择要复制的产品'),
|
||||
),
|
||||
componentProps: {
|
||||
api: postOneNetProductListAsync,
|
||||
params: {
|
||||
query: {
|
||||
input: {
|
||||
pageIndex: 1,
|
||||
pageSize: 1000,
|
||||
},
|
||||
},
|
||||
},
|
||||
labelField: 'productName',
|
||||
valueField: 'ioTPlatformProductId',
|
||||
optionsPropName: 'items',
|
||||
immediate: true,
|
||||
allowClear: true,
|
||||
placeholder: '请选择产品',
|
||||
afterFetch: (res: any) => {
|
||||
// 确保返回的是数组格式
|
||||
if (Array.isArray(res)) {
|
||||
return res;
|
||||
}
|
||||
if (res && Array.isArray(res.items)) {
|
||||
return res.items;
|
||||
}
|
||||
if (res && Array.isArray(res.data)) {
|
||||
return res.data;
|
||||
}
|
||||
return [];
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
component: 'ApiSelect',
|
||||
fieldName: 'filedType',
|
||||
label: '选择物模型类型',
|
||||
rules: z.preprocess(
|
||||
(v) => (v == null ? '' : v),
|
||||
z.string().min(1, '请选择物模型类型'),
|
||||
),
|
||||
componentProps: {
|
||||
api: getCommonGetSelectList,
|
||||
params: {
|
||||
query: {
|
||||
typeName: 'DataDictionaryTypeConst',
|
||||
},
|
||||
},
|
||||
labelField: 'value',
|
||||
valueField: 'key',
|
||||
optionsPropName: 'options',
|
||||
immediate: true,
|
||||
allowClear: true,
|
||||
placeholder: '请选择物模型类型',
|
||||
afterFetch: (res: any) => {
|
||||
// 确保返回的是数组格式
|
||||
if (Array.isArray(res)) {
|
||||
return res;
|
||||
}
|
||||
if (res && Array.isArray(res.items)) {
|
||||
return res.items;
|
||||
}
|
||||
if (res && Array.isArray(res.data)) {
|
||||
return res.data;
|
||||
}
|
||||
return [];
|
||||
},
|
||||
},
|
||||
},
|
||||
]);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user