Commit 2754da66541500e9a85f169e226d2514c57d500c

Authored by xp.Huang
2 parents 3e974a40 7a5eb630

Merge branch 'fix/DEFECT-1775' into 'main_dev'

fix:产品物模型导入添加注释和excel模板

See merge request yunteng/thingskit-front!1035
... ... @@ -24,6 +24,7 @@ enum ModelOfMatter {
24 24 CATEGORY_EXPORT = '/things_model/categoryGetExport',
25 25
26 26 IMPORT_CSV = '/things_model/csvImport',
  27 + EXCEL_EXPORT = '/things_model/downloadTemplate',
27 28 }
28 29
29 30 export const getModelList = (
... ... @@ -169,3 +170,13 @@ export const importCsvDeviceProfileId = (params: {
169 170 params: params.file,
170 171 });
171 172 };
  173 +
  174 +/**
  175 + * 物模型excel导出模板
  176 + */
  177 +export const excelExport = () => {
  178 + return defHttp.get({
  179 + url: `${ModelOfMatter.EXCEL_EXPORT}`,
  180 + responseType: 'blob',
  181 + });
  182 +};
... ...
... ... @@ -97,7 +97,6 @@
97 97 // 状态->编辑
98 98 const handleSwitch = async (e: any, record: any) => {
99 99 switchLoading.value = true;
100   - console.log(e, record);
101 100 await deviceProfileCategory({ ...record, status: e });
102 101 switchLoading.value = false;
103 102 createMessage.success('操作成功');
... ... @@ -185,7 +184,6 @@
185 184 </template>
186 185 </BasicTable>
187 186 <classModal @register="registerModal" @handleReload="handleReload" />
188   - <!-- <physicalModel @register="registerDetailDrawer" :record /> -->
189 187 <BasicDrawer title="物模型" @register="registerDetailDrawer" width="60%" destroy-on-close>
190 188 <PhysicalModelManagementStep :record="registerDetailRecord" />
191 189 </BasicDrawer>
... ...
... ... @@ -10,9 +10,9 @@
10 10 :showOkBtn="false"
11 11 >
12 12 <div class="w-full h-full" ref="loadingRef">
13   - <!-- <div class="flex justify-end">
14   - <Button @click="handleTemplateDownload" type="link">EXCEL模板下载</Button>
15   - </div> -->
  13 + <div class="flex justify-end">
  14 + <Button @click="handleTemplateDownload" type="link">excel模板下载</Button>
  15 + </div>
16 16 <div class="flex justify-evenly items-center h-50 !w-full">
17 17 <Upload
18 18 accept=".json,"
... ... @@ -21,7 +21,10 @@
21 21 class="flex justify-center items-center"
22 22 >
23 23 <div class="flex flex-col justify-center items-center">
24   - <img :src="JSONImage" alt="avatar" class="w-20 h-20" />
  24 + <Tooltip>
  25 + <template #title>使用从物模型TSL导出的JSON进行导入</template>
  26 + <img :src="JSONImage" alt="avatar" class="w-20 h-20" />
  27 + </Tooltip>
25 28 </div>
26 29 </Upload>
27 30 <Upload
... ... @@ -31,7 +34,10 @@
31 34 class="flex justify-center items-center"
32 35 >
33 36 <div class="flex flex-col justify-center items-center">
34   - <img :src="CSVImage" alt="avatar" class="w-20 h-20" />
  37 + <Tooltip>
  38 + <template #title>请使用excel模板编辑之后在进行导入</template>
  39 + <img :src="CSVImage" alt="avatar" class="w-20 h-20" />
  40 + </Tooltip>
35 41 </div>
36 42 </Upload>
37 43 </div>
... ... @@ -40,7 +46,7 @@
40 46 </template>
41 47 <script lang="ts" setup>
42 48 import { ref, unref } from 'vue';
43   - import { Upload } from 'ant-design-vue';
  49 + import { Upload, Tooltip, Button } from 'ant-design-vue';
44 50 import { BasicModal, useModalInner } from '/@/components/Modal';
45 51 import { DeviceRecord } from '/@/api/device/model/deviceModel';
46 52 import { useMessage } from '/@/hooks/web/useMessage';
... ... @@ -50,6 +56,7 @@
50 56 importModelCategory,
51 57 importModelOfMatter,
52 58 importCsvDeviceProfileId,
  59 + excelExport,
53 60 } from '/@/api/device/modelOfMatter';
54 61 // import XLSX, { CellObject } from 'xlsx';
55 62 import { useLoading } from '/@/components/Loading';
... ... @@ -162,6 +169,7 @@
162 169 });
163 170 flag && createMessage.info(flag?.message);
164 171 } catch (msg) {
  172 + // eslint-disable-next-line no-console
165 173 console.log(msg, 'msg');
166 174 } finally {
167 175 closeLoading();
... ... @@ -170,23 +178,23 @@
170 178 }
171 179 };
172 180
173   - // const downloadFile = (data: string, fileName: string, type: string, ext: string) => {
174   - // const blob = new Blob([data], { type: type });
175   - // const objectURL = URL.createObjectURL(blob);
176   - // const element = document.createElement('a');
177   - // element.href = objectURL;
178   - // element.download = `${fileName}.${ext}`;
179   - // element.style.display = 'none';
180   - // document.body.appendChild(element);
181   - // element.click();
182   - // element.remove();
183   - // URL.revokeObjectURL(objectURL);
184   - // };
  181 + const downloadFile = (data: Blob, fileName: string, ext: string) => {
  182 + const objectURL = URL.createObjectURL(data);
  183 + const element = document.createElement('a');
  184 + element.href = objectURL;
  185 + element.download = `${fileName}.${ext}`;
  186 + element.style.display = 'none';
  187 + document.body.appendChild(element);
  188 + element.click();
  189 + element.remove();
  190 + URL.revokeObjectURL(objectURL);
  191 + };
185 192
186 193 // 模板下载
187   - // const handleTemplateDownload = () => {
188   -
189   - // };
  194 + const handleTemplateDownload = async () => {
  195 + const res = await excelExport();
  196 + downloadFile(res, '物模型属性导入模板', 'xls');
  197 + };
190 198
191 199 const handleCancel = () => {
192 200 closeModal();
... ...
... ... @@ -75,35 +75,6 @@ export const columnsDrawer: BasicColumn[] = [
75 75 },
76 76 ellipsis: true,
77 77 },
78   - // {
79   - // title: '事件类型',
80   - // dataIndex: 'eventType',
81   - // customRender({ text }) {
82   - // return h(
83   - // Tag,
84   - // {
85   - // color: EventTypeColor[text as EventType],
86   - // },
87   - // () => EventTypeName[text as EventType]
88   - // );
89   - // },
90   - // ellipsis: true,
91   - // },
92   - // {
93   - // title: '状态',
94   - // dataIndex: 'status',
95   - // width: 100,
96   - // customRender: (value: Record<'text', number>) => {
97   - // const { text } = value;
98   - // return h(
99   - // Tag,
100   - // {
101   - // color: text ? 'green' : 'red',
102   - // },
103   - // () => (text ? '已发布' : '待发布')
104   - // );
105   - // },
106   - // },
107 78 ];
108 79
109 80 export const searchFormSchema: FormSchema[] = [
... ... @@ -121,7 +92,6 @@ export const searchFormSchema: FormSchema[] = [
121 92 labelField: 'itemText',
122 93 valueField: 'itemValue',
123 94 placeholder: '请选择领域',
124   - // getPopupContainer: () => document.body,
125 95 };
126 96 },
127 97 },
... ...
... ... @@ -186,7 +186,9 @@
186 186 selectType: props.record.ifShowClass ? 'category' : undefined,
187 187 });
188 188 },
189   - columns: physicalColumn,
  189 + columns: props.record.ifShowClass
  190 + ? physicalColumn.filter((item) => item.dataIndex !== 'status')
  191 + : physicalColumn,
190 192 showIndexColumn: false,
191 193 clickToRowSelect: false,
192 194 showTableSetting: true,
... ...