NormalHisTable.vue 5.2 KB

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