PhysicalModelManagementStep.vue
7.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
<template>
<div class="p-style">
<BasicTable
:rowSelection="{ type: 'checkbox' }"
class="bg-gray-100 dark:bg-dark-900"
:clickToRowSelect="false"
@register="registerTable"
>
<template #toolbar>
<div class="flex-auto">
<div class="mb-2">
<Alert type="info" show-icon>
<template #message>
<span v-if="!isShowBtn">
当前展示的是已发布到线上的功能定义,如需修改,请点击
<span
@click="handleEditPhysicalModel"
class="cursor-pointer text-blue-400"
size="small"
>
"编辑物模型"
</span>
</span>
<span v-if="isShowBtn"> 您正在编辑的是草稿,需点击发布后,物模型才会正式生效. </span>
</template>
</Alert>
</div>
<div class="flex justify-between items-end">
<div class="flex gap-2">
<Authority :value="ModelOfMatterPermission.CREATE">
<Button v-if="isShowBtn" type="primary" @click="handleCreateOrEdit()">
新增物模型
</Button>
</Authority>
<Button type="primary" @click="handleOpenTsl"> 物模型TSL </Button>
<Upload v-if="isShowBtn" :show-upload-list="false" :customRequest="handleImportModel">
<Button type="primary"> 导入物模型 </Button>
</Upload>
</div>
<div class="flex gap-2">
<Authority :value="ModelOfMatterPermission.RELEASE">
<Popconfirm
title="是否需要发布上线?"
ok-text="确定"
cancel-text="取消"
@confirm="handleEmit"
>
<Button v-if="isShowBtn" type="primary" :loading="releaseLoading">
发布上线
</Button>
</Popconfirm>
</Authority>
<Button v-if="isShowBtn" class="!bg-gray-200" type="text" @click="handleReturn">
返回
</Button>
<Authority :value="ModelOfMatterPermission.DELETE">
<Popconfirm
title="您确定要批量删除数据"
ok-text="确定"
cancel-text="取消"
@confirm="handleDeleteOrBatchDelete(null)"
>
<Button
style="display: none"
type="primary"
color="error"
:disabled="hasBatchDelete"
>
批量删除
</Button>
</Popconfirm>
</Authority>
</div>
</div>
</div>
</template>
<template #action="{ record }">
<TableAction
:actions="[
{
label: '查看',
icon: 'ant-design:eye-outlined',
onClick: handleViewDetail.bind(null, record),
ifShow: isShowBtn ? false : true,
},
{
label: '编辑',
icon: 'clarity:note-edit-line',
auth: ModelOfMatterPermission.UPDATE,
onClick: handleCreateOrEdit.bind(null, record),
ifShow: !isShowBtn ? false : true,
},
{
label: '删除',
icon: 'ant-design:delete-outlined',
auth: ModelOfMatterPermission.DELETE,
color: 'error',
ifShow: !isShowBtn ? false : true,
popConfirm: {
title: '是否确认删除',
confirm: handleDeleteOrBatchDelete.bind(null, record),
},
},
]"
/>
</template>
</BasicTable>
<PhysicalModelModal
:record="$props.record"
@register="registerModal"
@success="handleSuccess"
/>
<PhysicalModelTsl :record="$props.record" @register="registerModalTsl" />
</div>
</template>
<script lang="ts" setup>
import { BasicTable, useTable, TableAction } from '/@/components/Table';
import { useModal } from '/@/components/Modal';
import {
modelOfMatterForm,
ModelOfMatterPermission,
physicalColumn,
} from '../device.profile.data';
import { useBatchDelete } from '/@/hooks/web/useBatchDelete';
import { Authority } from '/@/components/Authority';
import PhysicalModelModal from './cpns/physical/PhysicalModelModal.vue';
import PhysicalModelTsl from './cpns/physical/PhysicalModelTsl.vue';
import { Popconfirm, Button, Alert, Upload } from 'ant-design-vue';
import { useMessage } from '/@/hooks/web/useMessage';
import { DeviceRecord } from '/@/api/device/model/deviceModel';
import {
deleteModel,
getModelList,
importModelOfMatter,
releaseModel,
} from '/@/api/device/modelOfMatter';
import { OpenModelOfMatterModelParams, OpenModelMode } from './cpns/physical/types';
import { ModelOfMatterParams } from '/@/api/device/model/modelOfMatterModel';
import { ref } from 'vue';
defineEmits(['register']);
const props = defineProps<{
record: DeviceRecord;
}>();
const { createMessage } = useMessage();
const isShowBtn = ref(false);
const [registerModal, { openModal }] = useModal();
const [registerModalTsl, { openModal: openModalTsl }] = useModal();
const [registerTable, { reload, setProps }] = useTable({
api: async (params: Record<'page' | 'pageSize', number>) => {
return await getModelList({ ...params, deviceProfileId: props.record.id });
},
columns: physicalColumn,
showIndexColumn: false,
clickToRowSelect: false,
showTableSetting: true,
bordered: true,
useSearchForm: true,
formConfig: {
schemas: modelOfMatterForm,
labelWidth: 120,
},
actionColumn: {
width: 200,
title: '操作',
dataIndex: 'action',
slots: { customRender: 'action' },
fixed: 'right',
},
});
// 刷新
const handleSuccess = () => {
reload();
};
const { hasBatchDelete, handleDeleteOrBatchDelete, selectionOptions } = useBatchDelete(
deleteModel,
handleSuccess,
setProps
);
selectionOptions.rowSelection.getCheckboxProps = (record: Recordable) => {
return { disabled: record.status === 1 };
};
const handleViewDetail = (record: ModelOfMatterParams) => {
if (record) {
openModal(true, {
record,
mode: OpenModelMode.VIEW,
} as OpenModelOfMatterModelParams);
}
};
// 新增或编辑
const handleCreateOrEdit = (record?: ModelOfMatterParams) => {
if (record) {
openModal(true, {
mode: OpenModelMode.UPDATE,
record,
} as OpenModelOfMatterModelParams);
} else {
openModal(true, {
mode: OpenModelMode.CREATE,
} as OpenModelOfMatterModelParams);
}
};
const handleOpenTsl = () => {
openModalTsl(true, {
isUpdate: true,
});
};
const handleEditPhysicalModel = () => (isShowBtn.value = true);
const handleReturn = () => (isShowBtn.value = false);
const releaseLoading = ref(false);
const handleEmit = async () => {
try {
releaseLoading.value = true;
await releaseModel(props.record.id);
handleReturn();
createMessage.success('发布成功');
reload();
} catch (error) {
} finally {
releaseLoading.value = false;
}
};
const handleImportModel = async (data: { file: File }) => {
const fileReader = new FileReader();
fileReader.onload = () => {
console.log(fileReader.result);
importModelOfMatter({ tkDeviceProfileId: props.record.id });
};
fileReader.readAsText(data.file, 'utf-8');
};
defineExpose({});
</script>
<style lang="less" scoped>
@import url('./common/PhysicalModelManagementStep.less');
:deep(.ant-table-body) {
height: auto !important;
}
</style>