NormalTable.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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" :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. const emit = defineEmits(['saveAdd']);
  74. const record = reactive({});
  75. const [registerModal, { openModal, closeModal }] = useModal();
  76. const columnList = getTableHeaderColumns('');
  77. // 列表页面公共参数、方法
  78. const { prefixCls, tableContext, onExportXls, onImportXls, doRequest } = useListPage({
  79. designScope: props.designScope,
  80. tableProps: {
  81. title: props.title,
  82. api: props.list,
  83. columns: props.columns.length > 0 ? (props.columns as any[]) : columnList,
  84. showTableSetting: false,
  85. // size: 'small',
  86. // bordered: false,
  87. formConfig: {
  88. showAdvancedButton: true,
  89. // labelWidth: 100,
  90. labelAlign: 'left',
  91. labelCol: {
  92. xs: 24,
  93. sm: 24,
  94. md: 24,
  95. lg: 9,
  96. xl: 7,
  97. xxl: 5,
  98. },
  99. schemas: props.searchFormSchema as any[],
  100. },
  101. useSearchForm: props.searchFormSchema.length > 0 ? true : false,
  102. striped: true,
  103. actionColumn: {
  104. width: 180,
  105. },
  106. beforeFetch: (params) => {
  107. return Object.assign(params, { column: 'createTime',});
  108. },
  109. },
  110. });
  111. //注册table数据
  112. const [registerTable, { reload, getForm }, { rowSelection, selectedRowKeys }] = tableContext;
  113. /**
  114. * 新增事件
  115. */
  116. function handleAdd() {
  117. addOredit.value='add'
  118. for (let key in record) {
  119. delete record[key];
  120. }
  121. openModal(true);
  122. }
  123. //新增保存
  124. function saveOrUpdate(param){
  125. console.log(param,'新增参数----------')
  126. emit('saveAdd',param)
  127. }
  128. /**
  129. * 编辑事件
  130. */
  131. function handleEdit(data) {
  132. addOredit.value='edit'
  133. reportLogHis.value=''
  134. Object.assign(record, toRaw(data));
  135. let index = record.fileName.indexOf('.');
  136. fileType.value = record.fileName.substring(index + 1);
  137. editID.value = record.id;
  138. console.log(editID.value, '编辑文件ID');
  139. openModal(true, {
  140. record,
  141. });
  142. }
  143. /**
  144. * 删除事件
  145. */
  146. async function handleDelete(record) {
  147. await props.deleteById({ id: record.id }, reload);
  148. }
  149. // 历史记录
  150. function handleHisrecord(data){
  151. addOredit.value='hisRecord'
  152. Object.assign(record, toRaw(data));
  153. openModal(true, {
  154. record,
  155. });
  156. }
  157. //下载文件
  158. function handleDownLoad(record) {
  159. console.log(record, '下载');
  160. props.downLoad({ id: record.id }).then((res) => {
  161. console.log(res, '文件下载成功');
  162. let filename = `${record.fileName}`;
  163. downFilePublic(res, filename);
  164. });
  165. }
  166. // 下载公用方法
  167. function downFilePublic(content, fileName) {
  168. const blob = new Blob([content], { type: 'application/xlsx;charset=UTF-8' }); // 构造一个blob对象来处理数据
  169. // 对于<a>标签,只有 Firefox 和 Chrome(内核) 支持 download 属性
  170. // IE10以上支持blob但是依然不支持download
  171. if ('download' in document.createElement('a')) {
  172. // 支持a标签download的浏览器
  173. const link = document.createElement('a'); // 创建a标签
  174. link.download = fileName; // a标签添加属性
  175. link.style.display = 'none';
  176. link.href = URL.createObjectURL(blob);
  177. document.body.appendChild(link);
  178. link.click(); // 执行下载
  179. URL.revokeObjectURL(link.href); // 释放url
  180. document.body.removeChild(link); // 释放标签
  181. } else {
  182. // 其他浏览器
  183. navigator.msSaveBlob(blob, fileName);
  184. }
  185. }
  186. defineExpose({
  187. doRequest, onExportXls, onImportXls, reload, getForm
  188. });
  189. </script>
  190. <style scoped lang="less">
  191. @ventSpace: zxm;
  192. @vent-table-no-hover: #00bfff10;
  193. :deep(.@{ventSpace}-table-cell-row-hover) {
  194. background: #264d8833 !important;
  195. }
  196. :deep(.@{ventSpace}-table-row-selected) {
  197. background: #268bc522 !important;
  198. }
  199. :deep(.@{ventSpace}-table-tbody > tr > td) {
  200. background-color: #0dc3ff05;
  201. }
  202. :deep(.jeecg-basic-table-row__striped) {
  203. td {
  204. background-color: @vent-table-no-hover !important;
  205. }
  206. }
  207. :deep(.@{ventSpace}-select-dropdown) {
  208. .@{ventSpace}-select-item-option-selected,
  209. .@{ventSpace}-select-item-option-active {
  210. background-color: #ffffff33 !important;
  211. }
  212. .@{ventSpace}-select-item:hover {
  213. background-color: #ffffff33 !important;
  214. }
  215. }
  216. </style>