From f9eb1a419834f97a3ab0124b132de4f977b1973b Mon Sep 17 00:00:00 2001 From: Ben Lin <maobin001@msn.com> Date: 星期六, 28 十二月 2024 21:00:56 +0800 Subject: [PATCH] 通用导入Excel更新 --- src/views/tigerprojects/mes/smt/smttable/index.vue | 302 +++++++++++++++++++++++++------------------------ 1 files changed, 153 insertions(+), 149 deletions(-) diff --git a/src/views/tigerprojects/mes/smt/smttable/index.vue b/src/views/tigerprojects/mes/smt/smttable/index.vue index 2928305..702567f 100644 --- a/src/views/tigerprojects/mes/smt/smttable/index.vue +++ b/src/views/tigerprojects/mes/smt/smttable/index.vue @@ -2,27 +2,36 @@ <div> <BasicTable @register="registerTable"> <template #toolbar> - <a-button color="primary" @click="addTool"> 娣诲姞 </a-button> - <a-button ghost color="primary" @click="aoaToExcel"> 瀵煎嚭 </a-button> - <a-button ghost color="primary" @click="ExcelToaoa"> 瀵煎叆 </a-button> + <a-button color="primary" @click="addTool" preIcon="add_02|svg"> 鏂板 </a-button> + <a-button ghost color="success" @click="aoaToExcel" preIcon="excel-export|svg"> + 瀵煎嚭 + </a-button> + <a-button ghost color="success" @click="ExcelToaoa" preIcon="excel-import|svg"> + 瀵煎叆 + </a-button> </template> <template #action="{ record }"> - <TableAction :actions="[ - { - icon: 'clarity:note-edit-line', - tooltip: '淇敼', - onClick: handleEdit.bind(null, record), - }, - { - icon: 'ant-design:delete-outlined', - tooltip: '鍒犻櫎', - popConfirm: { - title: '鏄惁纭鍒犻櫎?', - placement: 'left', - confirm: handleDelete.bind(null, record), - }, - }, - ]" /> + <TableAction + :actions="[ + { + icon: 'clarity:note-edit-line', + tooltip: '淇敼', + onClick: handleEdit.bind(null, record), + name: '' + }, + { + icon: 'ant-design:delete-outlined', + tooltip: '鍒犻櫎', + color: 'error', + popConfirm: { + title: '鏄惁纭鍒犻櫎?', + placement: 'left', + confirm: handleDelete.bind(null, record), + }, + name: '' + }, + ]" + /> </template> </BasicTable> <Loading :loading="compState.loading" :tip="compState.tip" /> @@ -32,141 +41,136 @@ </div> </template> <script lang="ts" setup> -import { reactive, unref } from 'vue'; -import { aoaToSheetXlsx } from '/@/components/Excel'; -import { BasicTable, useTable, TableAction } from '/@/components/Table'; -import SmttableDrawer from './SmttableDrawer.vue'; -import SmttableModal from './SmttableModal.vue'; -import { useDrawer } from '/@/components/Drawer'; -import { columns, searchFormSchema } from './smttbale.data'; -import { getSmttableListByPage, DeleteSmttable } from '/@/api/tigerapi/mes/smt/smttable'; -import { useGo } from '/@/hooks/web/usePage'; -import { Loading } from '/@/components/Loading'; -import { useMessage } from '/@/hooks/web/useMessage'; -import { useI18n } from '/@/hooks/web/useI18n'; -import { useModal } from '/@/components/Modal'; + import { reactive, unref } from 'vue'; + import { aoaToSheetXlsx } from '/@/components/Excel'; + import { BasicTable, useTable, TableAction } from '/@/components/Table'; + import SmttableDrawer from './SmttableDrawer.vue'; + import SmttableModal from './SmttableModal.vue'; + import { useDrawer } from '/@/components/Drawer'; + import { columns, searchFormSchema } from './smttbale.data'; + import { getSmttableListByPage, DeleteSmttable } from '/@/api/tigerapi/mes/smt/smttable'; + import { useGo } from '/@/hooks/web/usePage'; + import { Loading } from '/@/components/Loading'; + import { useMessage } from '/@/hooks/web/useMessage'; + import { useI18n } from '/@/hooks/web/useI18n'; + import { useModal } from '/@/components/Modal'; -const { t } = useI18n(); -const { createMessage } = useMessage(); -const [registerDrawer, { openDrawer }] = useDrawer(); -const go = useGo(); + const { t } = useI18n(); + const { createMessage } = useMessage(); + const [registerDrawer, { openDrawer }] = useDrawer(); + const go = useGo(); -const compState = reactive({ - absolute: false, - loading: false, - tip: '鍔犺浇涓�...', -}); -const [registerSmttable, { openModal: openSmttableModal }] = useModal(); -const [registerTable, { getForm, getPaginationRef, reload }] = useTable({ - title: '宸ュ崟鏂欑珯琛�', - api: getSmttableListByPage, - columns, - formConfig: { - labelWidth: 120, - schemas: searchFormSchema, - }, - actionColumn: { - width: 120, - title: '鎿嶄綔', - dataIndex: 'action', - slots: { customRender: 'action' }, - fixed: 'right', //undefined, - }, - ellipsis: true, - useSearchForm: true, - showTableSetting: false, - bordered: true, - showIndexColumn: false, -}); -let arr: any[] = []; -//瀵煎嚭 -function aoaToExcel() { - const totals = getPaginationRef().total - if (totals < 30000) { - arr = []; - compState.loading = true; - const col = getForm().getFieldsValue() - getSmttableListByPage(col).then((res) => { - res.items.forEach(element => { - - arr.push({ - '鍏宠仈宸ュ崟鍙�': element.WORK_ORDER, - '浜у搧缂栫爜': element.PROD_CODE, - '鐗╂枡缂栫爜': element.ITEM_CODE, - '鏇夸唬鏂�': element.SUBITEM_CODE, - '鍗曚綅': element.UNIT, - '鍗曚綅鐢ㄩ噺': element.UNIT_QTY, - '浜х嚎缂栫爜': element.LINE_CODE, - '璐寸墖鏈虹紪鐮�': element.SMT_CODE, - '閽㈢綉缂栫爜': element.SMT_STENCIL, - '绔欎綅鍙�': element.SLOT_NO, - '璐寸墖浣嶇疆': element.LOCATION, - '椋炶揪缂栫爜': element.FEEDER_CODE, - '椋炶揪绫诲瀷': element.FEEDER_TYPE, - '鍔犲伐闈�': element.PCB_SURFACE, - '涓婃枡椤哄簭': element.LOAD_SEQ, - '鍒涘缓浜�': element.CREATE_USER, - '鍒涘缓鏃堕棿': element.CREATE_TIME, + const compState = reactive({ + absolute: false, + loading: false, + tip: '鍔犺浇涓�...', + }); + const [registerSmttable, { openModal: openSmttableModal }] = useModal(); + const [registerTable, { getForm, getPaginationRef, reload }] = useTable({ + title: '宸ュ崟鏂欑珯琛�', + api: getSmttableListByPage, + columns, + formConfig: { + labelWidth: 120, + schemas: searchFormSchema, + }, + actionColumn: { + width: 120, + title: '鎿嶄綔', + dataIndex: 'action', + slots: { customRender: 'action' }, + fixed: 'right', //undefined, + }, + ellipsis: true, + useSearchForm: true, + showTableSetting: true, + bordered: true, + showIndexColumn: false, + }); + let arr: any[] = []; + //瀵煎嚭 + function aoaToExcel() { + const totals = getPaginationRef().total; + if (totals < 30000) { + arr = []; + compState.loading = true; + const col = getForm().getFieldsValue(); + getSmttableListByPage(col).then((res) => { + res.items.forEach((element) => { + arr.push({ + 鍏宠仈宸ュ崟鍙�: element.WORK_ORDER, + 浜у搧缂栫爜: element.PROD_CODE, + 鐗╂枡缂栫爜: element.ITEM_CODE, + 鏇夸唬鏂�: element.SUBITEM_CODE, + 鍗曚綅: element.UNIT, + 鍗曚綅鐢ㄩ噺: element.UNIT_QTY, + 浜х嚎缂栫爜: element.LINE_CODE, + 璐寸墖鏈虹紪鐮�: element.SMT_CODE, + 閽㈢綉缂栫爜: element.SMT_STENCIL, + 绔欎綅鍙�: element.SLOT_NO, + 璐寸墖浣嶇疆: element.LOCATION, + 椋炶揪缂栫爜: element.FEEDER_CODE, + 椋炶揪绫诲瀷: element.FEEDER_TYPE, + 鍔犲伐闈�: element.PCB_SURFACE, + 涓婃枡椤哄簭: element.LOAD_SEQ, + 鍒涘缓浜�: element.CREATE_USER, + 鍒涘缓鏃堕棿: element.CREATE_TIME, + }); }); - }); - const arrHeader = columns.map((column) => column.title); - const arrData = arr.map((item) => { - return Object.keys(item).map((key) => item[key]); - }); - // 淇濊瘉data椤哄簭涓巋eader涓�鑷� - if (arr.length < 30000) { - aoaToSheetXlsx({ - data: arrData, - header: arrHeader, - filename: '宸ュ崟鏂欑珯琛ㄤ俊鎭�.xlsx', + const arrHeader = columns.map((column) => column.title); + const arrData = arr.map((item) => { + return Object.keys(item).map((key) => item[key]); }); - } else { - createMessage.error(t('瀵煎嚭鏁版嵁涓嶈兘瓒呰繃涓変竾鏉★紝濡傞渶瑕佹洿澶氱殑璇疯仈绯荤鐞嗗憳')); - } + // 淇濊瘉data椤哄簭涓巋eader涓�鑷� + if (arr.length < 30000) { + aoaToSheetXlsx({ + data: arrData, + header: arrHeader, + filename: '宸ュ崟鏂欑珯琛ㄤ俊鎭�.xlsx', + }); + } else { + createMessage.error(t('瀵煎嚭鏁版嵁涓嶈兘瓒呰繃涓変竾鏉★紝濡傞渶瑕佹洿澶氱殑璇疯仈绯荤鐞嗗憳')); + } - compState.loading = false; - - }) - - } else { - createMessage.error(t('瀵煎嚭鏁版嵁涓嶈兘瓒呰繃涓変竾鏉★紝濡傞渶瑕佹洿澶氱殑璇疯仈绯荤鐞嗗憳')); - } - - -} -//瀵煎叆 -function ExcelToaoa() { - openSmttableModal(true, { - data: 'content', - info: 'Info', - }); -} -//娣诲姞 -function addTool() { - openDrawer(true, { - isUpdate: false, - }); -} -//缂栬緫 -function handleEdit(record: any) { - openDrawer(true, { - isUpdate: true, - record - }); -} -function handleSuccess() { - reload(); -} -//鍒犻櫎 -function handleDelete(record: any) { - const apiAction = DeleteSmttable(record.ID); - apiAction.then((action) => { - if (action.IsSuccessed) { - createMessage.success(t('宸插垹闄�')); - reload(); + compState.loading = false; + }); } else { - createMessage.success(t('鍒犻櫎鎿嶄綔澶辫触')); + createMessage.error(t('瀵煎嚭鏁版嵁涓嶈兘瓒呰繃涓変竾鏉★紝濡傞渶瑕佹洿澶氱殑璇疯仈绯荤鐞嗗憳')); } - }); -} + } + //瀵煎叆 + function ExcelToaoa() { + openSmttableModal(true, { + data: 'content', + info: 'Info', + }); + } + //娣诲姞 + function addTool() { + openDrawer(true, { + isUpdate: false, + }); + } + //缂栬緫 + function handleEdit(record: any) { + openDrawer(true, { + isUpdate: true, + record, + }); + } + function handleSuccess() { + reload(); + } + //鍒犻櫎 + function handleDelete(record: any) { + const apiAction = DeleteSmttable(record.ID); + apiAction.then((action) => { + if (action.IsSuccessed) { + createMessage.success(t('宸插垹闄�')); + reload(); + } else { + createMessage.success(t('鍒犻櫎鎿嶄綔澶辫触')); + } + }); + } </script> -- Gitblit v1.9.3