NormalTable.vue 7.5 KB

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