NormalTable.vue 7.2 KB

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