NormalTable.vue 8.1 KB

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