NormalHisTable.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <template>
  2. <div>
  3. <BasicTable @register="registerTable" :rowSelection="rowSelection">
  4. <template #action="{ record }">
  5. <a class="table-action-link" @click="handleEdit(record)">预览</a>
  6. <a class="table-action-link" @click="handleDownLoad(record)">下载</a>
  7. <slot name="action" v-bind="{ record }"></slot>
  8. </template>
  9. <template #bodyCell="{ column, record }">
  10. <slot name="filterCell" v-bind="{ column, record }"></slot>
  11. </template>
  12. </BasicTable>
  13. <DeviceModal :editID="editID" :reportLogHis="reportLogHis" :fileType="fileType" @register="registerModal" :addOredit="addOredit" />
  14. </div>
  15. </template>
  16. <script lang="ts" setup>
  17. //ts语法
  18. import { ref, reactive, toRaw, defineExpose, watch } from 'vue';
  19. import { BasicTable } from '/@/components/Table';
  20. import { useModal } from '/@/components/Modal';
  21. import DeviceModal from './DeviceModal.vue';
  22. import { getTableHeaderColumns } from '/@/hooks/web/useWebColumns';
  23. import { useListPage } from '/@/hooks/system/useListPage';
  24. const props = defineProps({
  25. columns: {
  26. type: Array,
  27. // required: true,
  28. default: () => [],
  29. },
  30. list: {
  31. type: Function,
  32. required: true,
  33. },
  34. //历史记录下载文件接口
  35. downLoad: {
  36. type: Function,
  37. required: true,
  38. },
  39. designScope: {
  40. type: String,
  41. },
  42. title: {
  43. type: String,
  44. },
  45. reportIds: {
  46. type: String,
  47. default: '',
  48. },
  49. });
  50. //区分打开编辑或新增弹窗
  51. let addOredit = ref('');
  52. //文件ID
  53. let editID = ref(0);
  54. let fileType = ref(''); //文件类型
  55. let reportLogHis = ref(''); //是否为报表记录编辑
  56. const record = reactive({});
  57. const [registerModal, { openModal, closeModal }] = useModal();
  58. const columnList = getTableHeaderColumns('');
  59. // 列表页面公共参数、方法
  60. const { prefixCls, tableContext, onExportXls, onImportXls, doRequest } = useListPage({
  61. designScope: props.designScope,
  62. tableProps: {
  63. title: props.title,
  64. api: props.list,
  65. columns: props.columns.length > 0 ? (props.columns as any[]) : columnList,
  66. showTableSetting: false,
  67. showIndexColumn: true,
  68. // size: 'small',
  69. // bordered: false,
  70. formConfig: {
  71. showAdvancedButton: true,
  72. // labelWidth: 100,
  73. labelAlign: 'left',
  74. labelCol: {
  75. xs: 24,
  76. sm: 24,
  77. md: 24,
  78. lg: 9,
  79. xl: 7,
  80. xxl: 5,
  81. },
  82. schemas: [],
  83. },
  84. useSearchForm: false,
  85. striped: true,
  86. actionColumn: {
  87. width: 180,
  88. },
  89. beforeFetch: (params) => {
  90. return Object.assign(params, { column: 'createTime', reportId: props.reportIds });
  91. },
  92. },
  93. });
  94. //注册table数据
  95. const [registerTable, { reload, getForm }, { rowSelection, selectedRowKeys }] = tableContext;
  96. /**
  97. * 编辑事件
  98. */
  99. function handleEdit(data) {
  100. addOredit.value = 'edit';
  101. reportLogHis.value = 'reportLog';
  102. Object.assign(record, toRaw(data));
  103. let index = record.fileName.indexOf('.');
  104. fileType.value = record.fileName.substring(index + 1);
  105. editID.value = record.id;
  106. console.log(editID.value, '报表历史记录ID');
  107. openModal(true, {
  108. record,
  109. });
  110. }
  111. //下载文件
  112. function handleDownLoad(record) {
  113. console.log(record, '下载');
  114. props.downLoad({ id: record.id }).then((res) => {
  115. console.log(res, '报表历史记录下载');
  116. let filename = `${record.fileName}`;
  117. downFilePublic(res, filename);
  118. });
  119. }
  120. // 下载公用方法
  121. function downFilePublic(content, fileName) {
  122. const blob = new Blob([content], { type: 'application/xlsx;charset=UTF-8' }); // 构造一个blob对象来处理数据
  123. // 对于<a>标签,只有 Firefox 和 Chrome(内核) 支持 download 属性
  124. // IE10以上支持blob但是依然不支持download
  125. if ('download' in document.createElement('a')) {
  126. // 支持a标签download的浏览器
  127. const link = document.createElement('a'); // 创建a标签
  128. link.download = fileName; // a标签添加属性
  129. link.style.display = 'none';
  130. link.href = URL.createObjectURL(blob);
  131. document.body.appendChild(link);
  132. link.click(); // 执行下载
  133. URL.revokeObjectURL(link.href); // 释放url
  134. document.body.removeChild(link); // 释放标签
  135. } else {
  136. // 其他浏览器
  137. navigator.msSaveBlob(blob, fileName);
  138. }
  139. }
  140. defineExpose({
  141. doRequest,
  142. onExportXls,
  143. onImportXls,
  144. reload,
  145. getForm,
  146. });
  147. </script>
  148. <style scoped lang="less">
  149. @ventSpace: zxm;
  150. @vent-table-no-hover: #00bfff10;
  151. :deep(.@{ventSpace}-table-cell-row-hover) {
  152. background: #264d8833 !important;
  153. }
  154. :deep(.@{ventSpace}-table-row-selected) {
  155. background: #268bc522 !important;
  156. }
  157. :deep(.@{ventSpace}-table-tbody > tr > td) {
  158. background-color: #0dc3ff05;
  159. }
  160. :deep(.jeecg-basic-table-row__striped) {
  161. td {
  162. background-color: @vent-table-no-hover !important;
  163. }
  164. }
  165. :deep(.@{ventSpace}-select-dropdown) {
  166. .@{ventSpace}-select-item-option-selected,
  167. .@{ventSpace}-select-item-option-active {
  168. background-color: #ffffff33 !important;
  169. }
  170. .@{ventSpace}-select-item:hover {
  171. background-color: #ffffff33 !important;
  172. }
  173. }
  174. </style>