NormalTable.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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. // size: 'small',
  112. // bordered: false,
  113. scroll: { y: 650 },
  114. formConfig: {
  115. showAdvancedButton: true,
  116. // labelWidth: 100,
  117. labelAlign: 'left',
  118. labelCol: {
  119. xs: 24,
  120. sm: 24,
  121. md: 24,
  122. lg: 9,
  123. xl: 7,
  124. xxl: 5,
  125. },
  126. schemas: props.searchFormSchema as any[],
  127. },
  128. useSearchForm: props.searchFormSchema.length > 0 ? true : false,
  129. striped: true,
  130. actionColumn: {
  131. width: 180,
  132. },
  133. //自定义默认排序
  134. defSort: {
  135. column: 'createTime',
  136. order: 'desc',
  137. },
  138. beforeFetch: (params) => {
  139. return Object.assign(params, { column: 'createTime', ...searchParams });
  140. },
  141. },
  142. });
  143. //注册table数据
  144. const [registerTable, { reload, getForm }, { rowSelection, selectedRowKeys }] = tableContext;
  145. //报表或模板上传
  146. function handleUpload() {
  147. visibleUp.value = new Date().getTime();
  148. }
  149. function resetUpload() {
  150. resetTable.value = new Date().getTime();
  151. }
  152. /**
  153. * 新增事件
  154. */
  155. function handleAdd() {
  156. addOredit.value = 'add';
  157. for (let key in record) {
  158. delete record[key];
  159. }
  160. openModal(true);
  161. }
  162. //新增保存
  163. function saveOrUpdate(param) {
  164. console.log(param, '新增参数----------');
  165. emit('saveAdd', param);
  166. }
  167. /**
  168. * 编辑事件
  169. */
  170. function handleEdit(data) {
  171. addOredit.value = 'edit';
  172. reportLogHis.value = '';
  173. Object.assign(record, toRaw(data));
  174. let index = record.fileName.indexOf('.');
  175. fileType.value = record.fileName.substring(index + 1);
  176. editID.value = record.id;
  177. console.log(editID.value, '编辑文件ID');
  178. openModal(true, {
  179. record,
  180. });
  181. }
  182. //同步报表
  183. async function handleReport(data) {
  184. let res = await synReportFile({ id: data.id });
  185. if (res) {
  186. resetTable.value = new Date().getTime();
  187. }
  188. }
  189. /**
  190. * 删除事件
  191. */
  192. async function handleDelete(record) {
  193. await props.deleteById({ id: record.id }, reload);
  194. }
  195. // 历史记录
  196. function handleHisrecord(data) {
  197. addOredit.value = 'hisRecord';
  198. Object.assign(record, toRaw(data));
  199. reportId.value = record.id;
  200. console.log(reportId.value, '历史记录列表传参---00000000');
  201. openModal(true, {
  202. record,
  203. });
  204. }
  205. //下载文件
  206. function handleDownLoad(record) {
  207. console.log(record, '下载');
  208. props.downLoad({ id: record.id }).then((res) => {
  209. console.log(res, '文件下载成功');
  210. let filename = `${record.fileName}`;
  211. downFilePublic(res, filename);
  212. });
  213. }
  214. // 下载公用方法
  215. function downFilePublic(content, fileName) {
  216. const blob = new Blob([content], { type: 'application/xlsx;charset=UTF-8' }); // 构造一个blob对象来处理数据
  217. // 对于<a>标签,只有 Firefox 和 Chrome(内核) 支持 download 属性
  218. // IE10以上支持blob但是依然不支持download
  219. if ('download' in document.createElement('a')) {
  220. // 支持a标签download的浏览器
  221. const link = document.createElement('a'); // 创建a标签
  222. link.download = fileName; // a标签添加属性
  223. link.style.display = 'none';
  224. link.href = URL.createObjectURL(blob);
  225. document.body.appendChild(link);
  226. link.click(); // 执行下载
  227. URL.revokeObjectURL(link.href); // 释放url
  228. document.body.removeChild(link); // 释放标签
  229. } else {
  230. // 其他浏览器
  231. navigator.msSaveBlob(blob, fileName);
  232. }
  233. }
  234. watch(
  235. () => props.searchParam,
  236. (newS, oldS) => {
  237. searchParams.busKind = newS.busKind;
  238. searchParams.modelType = newS.modelType;
  239. searchParams.reportType = newS.reportType;
  240. },
  241. { immediate: true, deep: true }
  242. );
  243. defineExpose({
  244. doRequest,
  245. onExportXls,
  246. onImportXls,
  247. reload,
  248. getForm,
  249. });
  250. </script>
  251. <style scoped lang="less">
  252. @ventSpace: zxm;
  253. @vent-table-no-hover: #00bfff10;
  254. :deep(.@{ventSpace}-table-cell-row-hover) {
  255. background: #264d8833 !important;
  256. }
  257. :deep(.@{ventSpace}-table-row-selected) {
  258. background: #268bc522 !important;
  259. }
  260. :deep(.@{ventSpace}-table-tbody > tr > td) {
  261. background-color: #0dc3ff05;
  262. }
  263. :deep(.jeecg-basic-table-row__striped) {
  264. td {
  265. background-color: @vent-table-no-hover !important;
  266. }
  267. }
  268. :deep(.@{ventSpace}-select-dropdown) {
  269. .@{ventSpace}-select-item-option-selected,
  270. .@{ventSpace}-select-item-option-active {
  271. background-color: #ffffff33 !important;
  272. }
  273. .@{ventSpace}-select-item:hover {
  274. background-color: #ffffff33 !important;
  275. }
  276. }
  277. </style>