DataTable.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <script lang="ts" setup>
  2. /**
  3. * @Name: Table.vue
  4. * @Description: 市场店铺表格
  5. * @Author: Cheney
  6. */
  7. import { Download, InfoFilled, Refresh } from '@element-plus/icons-vue';
  8. import { usePagination } from '/@/utils/usePagination';
  9. import { useTableData } from '/@/utils/useTableData';
  10. import { OnlineMerchandiseColumns } from '/@/views/store-manage/Columns';
  11. import DataTableSlot from './DataTableSlot.vue';
  12. import * as api from '../api';
  13. import { ElMessage } from 'element-plus';
  14. import { uesDownloadFile } from '/@/utils/useDownload';
  15. interface Parameter {
  16. country: string,
  17. shop: string,
  18. region: string,
  19. delivery: string,
  20. status: string,
  21. asin: string,
  22. sku: string,
  23. platformId: string,
  24. }
  25. const queryParameter: Parameter | undefined = inject('query-parameter');
  26. const { tableOptions, handlePageChange } = usePagination(fetchList);
  27. const gridRef = ref();
  28. const gridOptions: any = reactive({
  29. id: 'online-merchandise-table',
  30. keepSource: true,
  31. size: 'small',
  32. border: false,
  33. round: true,
  34. stripe: true,
  35. currentRowHighLight: true,
  36. height: '100%',
  37. customConfig: {
  38. storage: {
  39. visible: true
  40. }
  41. },
  42. toolbarConfig: {
  43. size: 'large',
  44. // custom: true,
  45. slots: {
  46. tools: 'toolbar_tools'
  47. }
  48. },
  49. rowConfig: {
  50. isHover: true
  51. },
  52. columnConfig: {
  53. resizable: true
  54. },
  55. pagerConfig: {
  56. total: tableOptions.value.total,
  57. page: tableOptions.value.page,
  58. limit: tableOptions.value.limit
  59. },
  60. loading: false,
  61. loadingConfig: {
  62. icon: 'vxe-icon-indicator roll',
  63. text: '正在拼命加载中...'
  64. },
  65. columns: '',
  66. data: ''
  67. });
  68. onBeforeMount(() => {
  69. gridOptions.pagerConfig.limit = 20;
  70. })
  71. onMounted(() => {
  72. fetchList();
  73. });
  74. async function fetchList(isQuery = false) {
  75. if (isQuery) {
  76. gridOptions.pagerConfig.page = 1;
  77. }
  78. gridOptions.data = [];
  79. gridOptions.columns = [];
  80. const query = {
  81. asin: queryParameter?.asin,
  82. sku: queryParameter?.sku,
  83. country_code: queryParameter?.country,
  84. shop_id: queryParameter?.shop,
  85. region: queryParameter?.region,
  86. delivery: queryParameter?.delivery,
  87. status: queryParameter?.status,
  88. platform_number: queryParameter?.platformId,
  89. };
  90. await useTableData(api.getTableData, query, gridOptions);
  91. if (gridOptions && gridOptions.data?.length) await gridRef.value.loadColumn(OnlineMerchandiseColumns);
  92. gridOptions.showHeader = Boolean(gridOptions.data?.length);
  93. }
  94. function handleRefresh() {
  95. fetchList();
  96. }
  97. async function handleDownload() {
  98. gridOptions.loading = true;
  99. try {
  100. await uesDownloadFile({
  101. apiMethod: api.exportData,
  102. queryParams: {
  103. asin: queryParameter?.asin,
  104. sku: queryParameter?.sku,
  105. country_code: queryParameter?.country,
  106. shop_id: queryParameter?.shop,
  107. region: queryParameter?.region,
  108. delivery: queryParameter?.delivery,
  109. status: queryParameter?.status,
  110. platform_number: queryParameter?.platformId,
  111. },
  112. fileName: '在线商品数据.xlsx',
  113. successMessage: () => ElMessage.success('数据导出成功!'),
  114. errorMessage: () => ElMessage.error('数据导出失败,请重试!'),
  115. });
  116. } finally {
  117. gridOptions.loading = false;
  118. }
  119. }
  120. defineExpose({ fetchList });
  121. </script>
  122. <template>
  123. <vxe-grid ref="gridRef" v-bind="gridOptions">
  124. <!-- 工具栏右侧 -->
  125. <template #toolbar_tools>
  126. <el-button circle class="toolbar-btn" @click="handleRefresh">
  127. <el-icon>
  128. <Refresh />
  129. </el-icon>
  130. </el-button>
  131. <el-button circle class="toolbar-btn" @click="handleDownload">
  132. <el-icon>
  133. <Download />
  134. </el-icon>
  135. </el-button>
  136. </template>
  137. <template #pager>
  138. <vxe-pager
  139. v-model:currentPage="gridOptions.pagerConfig.page"
  140. v-model:pageSize="gridOptions.pagerConfig.limit"
  141. :total="gridOptions.pagerConfig.total"
  142. class="mt-1.5"
  143. @page-change="handlePageChange"
  144. />
  145. </template>
  146. <template #empty>
  147. <el-empty description="暂无数据" />
  148. </template>
  149. <!-- 自定义列插槽 -->
  150. <template v-for="col in OnlineMerchandiseColumns" #[`${col.field}`]="{ row }">
  151. <DataTableSlot :key="row.id" :field="col.field" :row="row" />
  152. </template>
  153. </vxe-grid>
  154. </template>
  155. <style scoped>
  156. .toolbar-btn {
  157. width: 34px;
  158. height: 34px;
  159. font-size: 18px
  160. }
  161. :deep(.custom-el-input .el-select__wrapper) {
  162. border-radius: 20px;
  163. }
  164. </style>