NormalTable.vue 7.1 KB

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