NormalTable.vue 6.7 KB

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