¶Ô±ÈÐÂÎļþ |
| | |
| | | <template> |
| | | <div> |
| | | <!--å¼ç¨è¡¨æ ¼--> |
| | | <BasicTable |
| | | @register="registerTable" |
| | | :rowSelection="rowSelection" |
| | | :expandedRowKeys="expandedRowKeys" |
| | | @expand="handleExpand" |
| | | @fetch-success="onFetchSuccess" |
| | | > |
| | | <!--ææ§½:tableæ é¢--> |
| | | <template #tableTitle> |
| | | <a-button type="primary" @click="handleCreate" preIcon="ant-design:plus-outlined"> æ°å¢</a-button> |
| | | <a-button type="primary" preIcon="ant-design:export-outlined" @click="onExportXls"> 导åº</a-button> |
| | | <j-upload-button type="primary" preIcon="ant-design:import-outlined" @click="onImportXls">导å
¥</j-upload-button> |
| | | |
| | | <a-dropdown v-if="selectedRowKeys.length > 0"> |
| | | <template #overlay> |
| | | <a-menu> |
| | | <a-menu-item key="1" @click="batchHandleDelete"> |
| | | <Icon icon="ant-design:delete-outlined" /> |
| | | å é¤ |
| | | </a-menu-item> |
| | | </a-menu> |
| | | </template> |
| | | <a-button |
| | | >æ¹éæä½ |
| | | <Icon icon="ant-design:down-outlined" /> |
| | | </a-button> |
| | | </a-dropdown> |
| | | </template> |
| | | <!--æä½æ --> |
| | | <template #action="{ record }"> |
| | | <TableAction :actions="getTableAction(record)" :dropDownActions="getDropDownAction(record)" /> |
| | | </template> |
| | | <!--åæ®µåæ¾ææ§½--> |
| | | <template #htmlSlot="{ text }"> |
| | | <div v-html="text"></div> |
| | | </template> |
| | | <!--çå¸åºåæ®µåæ¾ææ§½--> |
| | | <template #pcaSlot="{ text }"> |
| | | {{ getAreaTextByCode(text) }} |
| | | </template> |
| | | <template #fileSlot="{ text }"> |
| | | <span v-if="!text" style="font-size: 12px; font-style: italic">æ æä»¶</span> |
| | | <a-button v-else :ghost="true" type="primary" preIcon="ant-design:download-outlined" size="small" @click="downloadFile(text)">ä¸è½½</a-button> |
| | | </template> |
| | | </BasicTable> |
| | | <!--åå
¸å¼¹çª--> |
| | | <DryHerbTypeModal @register="registerModal" @success="handleSuccess" /> |
| | | </div> |
| | | </template> |
| | | |
| | | <script lang="ts" name="dry-dryHerbType" setup> |
| | | //tsè¯æ³ |
| | | import { ref, unref } from 'vue' |
| | | import { batchDeleteDryHerbType, deleteDryHerbType, getChildList, getChildListBatch, getExportUrl, getImportUrl, list } from './api/DryHerbType.api' |
| | | import DryHerbTypeModal from './components/DryHerbTypeModal.vue' |
| | | import { columns, searchFormSchema } from './dataDefine/DryHerbType.data' |
| | | import { useModal } from '/@/components/Modal' |
| | | import { BasicTable, TableAction } from '/@/components/Table' |
| | | import { useListPage } from '/@/hooks/system/useListPage' |
| | | import { downloadFile } from '/@/utils/common/renderUtils' |
| | | const expandedRowKeys = ref([]) |
| | | //åå
¸model |
| | | const [registerModal, { openModal }] = useModal() |
| | | //注åtableæ°æ® |
| | | const { prefixCls, tableContext, onExportXls, onImportXls } = useListPage({ |
| | | tableProps: { |
| | | api: list, |
| | | title: 'è¯æåç±»', |
| | | columns, |
| | | canResize: false, |
| | | formConfig: { |
| | | //labelWidth: 120, |
| | | schemas: searchFormSchema, |
| | | autoSubmitOnEnter: true, |
| | | showAdvancedButton: true, |
| | | fieldMapToNumber: [], |
| | | fieldMapToTime: [], |
| | | }, |
| | | actionColumn: { |
| | | width: 240, |
| | | fixed: 'right', |
| | | }, |
| | | }, |
| | | exportConfig: { |
| | | name: 'è¯æåç±»', |
| | | url: getExportUrl, |
| | | }, |
| | | importConfig: { |
| | | url: getImportUrl, |
| | | success: importSuccess, |
| | | }, |
| | | }) |
| | | |
| | | const [registerTable, { reload, collapseAll, updateTableDataRecord, findTableDataRecord, getDataSource }, { rowSelection, selectedRowKeys }] = |
| | | tableContext |
| | | |
| | | /** |
| | | * æ°å¢äºä»¶ |
| | | */ |
| | | function handleCreate() { |
| | | openModal(true, { |
| | | isUpdate: false, |
| | | }) |
| | | } |
| | | |
| | | /** |
| | | * ç¼è¾äºä»¶ |
| | | */ |
| | | async function handleEdit(record) { |
| | | openModal(true, { |
| | | record, |
| | | isUpdate: true, |
| | | }) |
| | | } |
| | | |
| | | /** |
| | | * 详æ
|
| | | */ |
| | | async function handleDetail(record) { |
| | | openModal(true, { |
| | | record, |
| | | isUpdate: true, |
| | | hideFooter: true, |
| | | }) |
| | | } |
| | | |
| | | /** |
| | | * å é¤äºä»¶ |
| | | */ |
| | | async function handleDelete(record) { |
| | | await deleteDryHerbType({ id: record.id }, importSuccess) |
| | | } |
| | | |
| | | /** |
| | | * æ¹éå é¤äºä»¶ |
| | | */ |
| | | async function batchHandleDelete() { |
| | | const ids = selectedRowKeys.value.filter((item) => !item.includes('loading')) |
| | | await batchDeleteDryHerbType({ id: ids }, importSuccess) |
| | | } |
| | | /** |
| | | * 导å
¥ |
| | | */ |
| | | function importSuccess() { |
| | | ;(selectedRowKeys.value = []) && reload() |
| | | } |
| | | /** |
| | | * æ·»å ä¸çº§ |
| | | */ |
| | | function handleAddSub(record) { |
| | | openModal(true, { |
| | | record, |
| | | isUpdate: false, |
| | | }) |
| | | } |
| | | /** |
| | | * æååè° |
| | | */ |
| | | async function handleSuccess({ isUpdate, values, expandedArr, changeParent }) { |
| | | if (isUpdate) { |
| | | if (changeParent) { |
| | | reload() |
| | | } else { |
| | | // ç¼è¾åè° |
| | | updateTableDataRecord(values.id, values) |
| | | } |
| | | } else { |
| | | if (!values['id'] || !values['pid']) { |
| | | //æ°å¢æ ¹èç¹ |
| | | reload() |
| | | } else { |
| | | //æ°å¢åé |
| | | expandedRowKeys.value = [] |
| | | for (let key of unref(expandedArr)) { |
| | | await expandTreeNode(key) |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ¥å£è¯·æ±æåååè° |
| | | */ |
| | | function onFetchSuccess(result) { |
| | | getDataByResult(result.items) && loadDataByExpandedRows() |
| | | } |
| | | /** |
| | | * æ ¹æ®å·²å±å¼çè¡æ¥è¯¢æ°æ®ï¼ç¨äºä¿ååå·æ°æ¶å¼æ¥å è½½åçº§çæ°æ®ï¼ |
| | | */ |
| | | async function loadDataByExpandedRows() { |
| | | if (unref(expandedRowKeys).length > 0) { |
| | | const res = await getChildListBatch({ parentIds: unref(expandedRowKeys).join(',') }) |
| | | if (res.success && res.result.records.length > 0) { |
| | | //å·²å±å¼çæ°æ®æ¹éåèç¹ |
| | | let records = res.result.records |
| | | const listMap = new Map() |
| | | for (let item of records) { |
| | | let pid = item['pid'] |
| | | if (unref(expandedRowKeys).includes(pid)) { |
| | | let mapList = listMap.get(pid) |
| | | if (mapList == null) { |
| | | mapList = [] |
| | | } |
| | | mapList.push(item) |
| | | listMap.set(pid, mapList) |
| | | } |
| | | } |
| | | let childrenMap = listMap |
| | | let fn = (list) => { |
| | | if (list) { |
| | | list.forEach((data) => { |
| | | if (unref(expandedRowKeys).includes(data.id)) { |
| | | data.children = getDataByResult(childrenMap.get(data.id)) |
| | | fn(data.children) |
| | | } |
| | | }) |
| | | } |
| | | } |
| | | fn(getDataSource()) |
| | | } |
| | | } |
| | | } |
| | | /** |
| | | * å¤çæ°æ®é |
| | | */ |
| | | function getDataByResult(result) { |
| | | if (result && result.length > 0) { |
| | | return result.map((item) => { |
| | | //夿æ¯å¦æ è®°äºå¸¦æåèç¹ |
| | | if (item['hasChild'] == '1') { |
| | | let loadChild = { id: item.id + '_loadChild', name: 'loading...', isLoading: true } |
| | | item.children = [loadChild] |
| | | } |
| | | return item |
| | | }) |
| | | } |
| | | } |
| | | /** |
| | | *æ èç¹å±å¼åå¹¶ |
| | | * */ |
| | | async function handleExpand(expanded, record) { |
| | | // 夿æ¯å¦æ¯å±å¼ç¶æï¼å±å¼ç¶æ(expanded)å¹¶ä¸åå¨åé(children)并䏿ªå è½½è¿(isLoading)ç就廿¥è¯¢åèç¹æ°æ® |
| | | if (expanded) { |
| | | expandedRowKeys.value.push(record.id) |
| | | if (record.children.length > 0 && !!record.children[0].isLoading) { |
| | | let result = await getChildList({ pid: record.id }) |
| | | result = result.records ? result.records : result |
| | | if (result && result.length > 0) { |
| | | record.children = getDataByResult(result) |
| | | } else { |
| | | record.children = null |
| | | record.hasChild = '0' |
| | | } |
| | | } |
| | | } else { |
| | | let keyIndex = expandedRowKeys.value.indexOf(record.id) |
| | | if (keyIndex >= 0) { |
| | | expandedRowKeys.value.splice(keyIndex, 1) |
| | | } |
| | | } |
| | | } |
| | | /** |
| | | *æä½è¡¨æ ¼åå¤çæ èç¹å±å¼åå¹¶ |
| | | * */ |
| | | async function expandTreeNode(key) { |
| | | let record = findTableDataRecord(key) |
| | | expandedRowKeys.value.push(key) |
| | | let result = await getChildList({ pid: key }) |
| | | if (result && result.length > 0) { |
| | | record.children = getDataByResult(result) |
| | | } else { |
| | | record.children = null |
| | | record.hasChild = '0' |
| | | } |
| | | updateTableDataRecord(key, record) |
| | | } |
| | | /** |
| | | * æä½æ |
| | | */ |
| | | function getTableAction(record) { |
| | | return [ |
| | | { |
| | | label: 'ç¼è¾', |
| | | onClick: handleEdit.bind(null, record), |
| | | }, |
| | | { |
| | | label: 'æ·»å ä¸çº§', |
| | | onClick: handleAddSub.bind(null, { pid: record.id }), |
| | | }, |
| | | ] |
| | | } |
| | | /** |
| | | * 䏿æä½æ |
| | | */ |
| | | function getDropDownAction(record) { |
| | | return [ |
| | | { |
| | | label: '详æ
', |
| | | onClick: handleDetail.bind(null, record), |
| | | }, |
| | | { |
| | | label: 'å é¤', |
| | | popConfirm: { |
| | | title: 'ç¡®å®å é¤å?', |
| | | confirm: handleDelete.bind(null, record), |
| | | }, |
| | | }, |
| | | ] |
| | | } |
| | | </script> |
| | | |
| | | <style scoped></style> |