Commit 52cfdaae46448e4a9ed8fedc5816e58c2aec08ca

Authored by xp.Huang
2 parents b007f48c 0f944fb9

Merge branch 'feat/product-object-model' into 'main_dev'

feat: 物模型新增批量删除功能

See merge request yunteng/thingskit-front!1106
@@ -65,3 +65,19 @@ export interface ImportModelOfMatterType { @@ -65,3 +65,19 @@ export interface ImportModelOfMatterType {
65 tkDeviceProfileId?: string; 65 tkDeviceProfileId?: string;
66 categoryId?: string; 66 categoryId?: string;
67 } 67 }
  68 +
  69 +export interface ModelOfMatterItemRecordType {
  70 + id: string;
  71 + creator: string;
  72 + createTime: string;
  73 + enabled: boolean;
  74 + tenantId: string;
  75 + functionType: string;
  76 + functionName: string;
  77 + identifier: string;
  78 + extensionDesc: any;
  79 + accessMode: string;
  80 + functionJson: FunctionJson;
  81 + status: number;
  82 + deviceProfileId: string;
  83 +}
@@ -2,6 +2,7 @@ import { BasicPageParams } from '../model/baseModel'; @@ -2,6 +2,7 @@ import { BasicPageParams } from '../model/baseModel';
2 import { 2 import {
3 GetModelTslParams, 3 GetModelTslParams,
4 ImportModelOfMatterType, 4 ImportModelOfMatterType,
  5 + ModelOfMatterItemRecordType,
5 ModelOfMatterParams, 6 ModelOfMatterParams,
6 } from './model/modelOfMatterModel'; 7 } from './model/modelOfMatterModel';
7 import { defHttp } from '/@/utils/http/axios'; 8 import { defHttp } from '/@/utils/http/axios';
@@ -36,7 +37,7 @@ export const getModelList = ( @@ -36,7 +37,7 @@ export const getModelList = (
36 id?: string; 37 id?: string;
37 } 38 }
38 ) => { 39 ) => {
39 - return defHttp.get({ 40 + return defHttp.get<ModelOfMatterItemRecordType[]>({
40 url: `${ModelOfMatter.LIST}`, 41 url: `${ModelOfMatter.LIST}`,
41 params, 42 params,
42 }); 43 });
@@ -68,21 +68,18 @@ @@ -68,21 +68,18 @@
68 <Button v-if="isShowBtn" class="!bg-gray-200" type="text" @click="handleReturn"> 68 <Button v-if="isShowBtn" class="!bg-gray-200" type="text" @click="handleReturn">
69 返回 69 返回
70 </Button> 70 </Button>
71 - <Authority :value="[ModelOfMatterPermission.DELETE, ModelCategoryPermission.DELETE]"> 71 + <Authority
  72 + v-if="isShowBtn"
  73 + :value="[ModelOfMatterPermission.DELETE, ModelCategoryPermission.DELETE]"
  74 + >
72 <Popconfirm 75 <Popconfirm
73 title="您确定要批量删除数据" 76 title="您确定要批量删除数据"
74 ok-text="确定" 77 ok-text="确定"
75 cancel-text="取消" 78 cancel-text="取消"
76 - @confirm="handleDeleteOrBatchDelete(null)" 79 + @confirm="handleDeleteOrBatchDelete()"
  80 + :disabled="getHasBatchDelete"
77 > 81 >
78 - <Button  
79 - style="display: none"  
80 - type="primary"  
81 - color="error"  
82 - :disabled="hasBatchDelete"  
83 - >  
84 - 批量删除  
85 - </Button> 82 + <Button type="primary" danger :disabled="getHasBatchDelete"> 批量删除 </Button>
86 </Popconfirm> 83 </Popconfirm>
87 </Authority> 84 </Authority>
88 </div> 85 </div>
@@ -120,11 +117,7 @@ @@ -120,11 +117,7 @@
120 /> 117 />
121 </template> 118 </template>
122 </BasicTable> 119 </BasicTable>
123 - <PhysicalModelModal  
124 - :record="$props.record"  
125 - @register="registerModal"  
126 - @success="handleSuccess"  
127 - /> 120 + <PhysicalModelModal :record="$props.record" @register="registerModal" @success="reload" />
128 <PhysicalModelTsl :record="$props.record" @register="registerModalTsl" /> 121 <PhysicalModelTsl :record="$props.record" @register="registerModalTsl" />
129 <SelectImport 122 <SelectImport
130 :record="$props.record" 123 :record="$props.record"
@@ -142,7 +135,6 @@ @@ -142,7 +135,6 @@
142 ModelCategoryPermission, 135 ModelCategoryPermission,
143 physicalColumn, 136 physicalColumn,
144 } from '../device.profile.data'; 137 } from '../device.profile.data';
145 - import { useBatchDelete } from '/@/hooks/web/useBatchDelete';  
146 import { Authority } from '/@/components/Authority'; 138 import { Authority } from '/@/components/Authority';
147 import PhysicalModelModal from './cpns/physical/PhysicalModelModal.vue'; 139 import PhysicalModelModal from './cpns/physical/PhysicalModelModal.vue';
148 import PhysicalModelTsl from './cpns/physical/PhysicalModelTsl.vue'; 140 import PhysicalModelTsl from './cpns/physical/PhysicalModelTsl.vue';
@@ -156,8 +148,11 @@ @@ -156,8 +148,11 @@
156 releaseModel, 148 releaseModel,
157 } from '/@/api/device/modelOfMatter'; 149 } from '/@/api/device/modelOfMatter';
158 import { OpenModelOfMatterModelParams, OpenModelMode } from './cpns/physical/types'; 150 import { OpenModelOfMatterModelParams, OpenModelMode } from './cpns/physical/types';
159 - import { ModelOfMatterParams } from '/@/api/device/model/modelOfMatterModel';  
160 - import { ref, unref } from 'vue'; 151 + import {
  152 + ModelOfMatterItemRecordType,
  153 + ModelOfMatterParams,
  154 + } from '/@/api/device/model/modelOfMatterModel';
  155 + import { computed, ref, unref } from 'vue';
161 import { isObject } from '/@/utils/is'; 156 import { isObject } from '/@/utils/is';
162 import { useRole } from '/@/hooks/business/useRole'; 157 import { useRole } from '/@/hooks/business/useRole';
163 import { ExportModelCategory } from '/@/api/device/modelOfMatter'; 158 import { ExportModelCategory } from '/@/api/device/modelOfMatter';
@@ -177,50 +172,45 @@ @@ -177,50 +172,45 @@
177 const [registerModalTsl, { openModal: openModalTsl }] = useModal(); 172 const [registerModalTsl, { openModal: openModalTsl }] = useModal();
178 const [registerModalSelect, { openModal: openModalSelect }] = useModal(); 173 const [registerModalSelect, { openModal: openModalSelect }] = useModal();
179 174
180 - const [registerTable, { reload, setProps }] = useTable({  
181 - api: async (params: Record<'page' | 'pageSize', number>) => {  
182 - return await getModelList({  
183 - ...params,  
184 - id: props.record.id,  
185 - selectType: props.record.ifShowClass ? 'category' : undefined,  
186 - });  
187 - },  
188 - columns: props.record.ifShowClass  
189 - ? physicalColumn.filter((item) => item.dataIndex !== 'status')  
190 - : physicalColumn,  
191 - showIndexColumn: false,  
192 - clickToRowSelect: false,  
193 - showTableSetting: true,  
194 - bordered: true,  
195 - useSearchForm: true,  
196 - formConfig: {  
197 - schemas: modelOfMatterForm,  
198 - labelWidth: 120,  
199 - },  
200 - actionColumn: {  
201 - width: 200,  
202 - title: '操作',  
203 - dataIndex: 'action',  
204 - slots: { customRender: 'action' },  
205 - fixed: 'right',  
206 - },  
207 - });  
208 -  
209 - // 刷新  
210 - const handleSuccess = () => {  
211 - reload();  
212 - };  
213 - const { hasBatchDelete, handleDeleteOrBatchDelete, selectionOptions } = useBatchDelete(  
214 - props.record.ifShowClass && (unref(isPlatformAdmin) || unref(isSysadmin))  
215 - ? deleteModelCategory  
216 - : deleteModel,  
217 - handleSuccess,  
218 - setProps  
219 - ); 175 + const [registerTable, { reload, getSelectRowKeys, getRowSelection, clearSelectedRowKeys }] =
  176 + useTable({
  177 + api: async (params: Record<'page' | 'pageSize', number>) => {
  178 + return await getModelList({
  179 + ...params,
  180 + id: props.record.id,
  181 + selectType: props.record.ifShowClass ? 'category' : undefined,
  182 + });
  183 + },
  184 + columns: props.record.ifShowClass
  185 + ? physicalColumn.filter((item) => item.dataIndex !== 'status')
  186 + : physicalColumn,
  187 + showIndexColumn: false,
  188 + clickToRowSelect: false,
  189 + showTableSetting: true,
  190 + bordered: true,
  191 + useSearchForm: true,
  192 + rowKey: 'id',
  193 + formConfig: {
  194 + schemas: modelOfMatterForm,
  195 + labelWidth: 120,
  196 + },
  197 + actionColumn: {
  198 + width: 200,
  199 + title: '操作',
  200 + dataIndex: 'action',
  201 + slots: { customRender: 'action' },
  202 + fixed: 'right',
  203 + },
  204 + rowSelection: {
  205 + getCheckboxProps: (record: ModelOfMatterItemRecordType) => {
  206 + return {
  207 + disabled: record.status === 1,
  208 + };
  209 + },
  210 + },
  211 + });
220 212
221 - selectionOptions.rowSelection.getCheckboxProps = (record: Recordable) => {  
222 - return { disabled: record.status === 1 };  
223 - }; 213 + const getHasBatchDelete = computed(() => !getRowSelection().selectedRowKeys?.length);
224 214
225 const handleViewDetail = (record: ModelOfMatterParams) => { 215 const handleViewDetail = (record: ModelOfMatterParams) => {
226 if (record) { 216 if (record) {
@@ -245,6 +235,19 @@ @@ -245,6 +235,19 @@
245 } 235 }
246 }; 236 };
247 237
  238 + const handleDeleteOrBatchDelete = async (record?: ModelOfMatterItemRecordType) => {
  239 + const deleteFn =
  240 + props.record.ifShowClass && (unref(isPlatformAdmin) || unref(isSysadmin))
  241 + ? deleteModelCategory
  242 + : deleteModel;
  243 +
  244 + const ids = record ? [record.id] : getSelectRowKeys();
  245 + await deleteFn(ids);
  246 + createMessage.success('删除成功');
  247 + clearSelectedRowKeys();
  248 + reload();
  249 + };
  250 +
248 const handleOpenTsl = () => { 251 const handleOpenTsl = () => {
249 openModalTsl(true, { 252 openModalTsl(true, {
250 isUpdate: true, 253 isUpdate: true,