NormalTable.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. <template>
  2. <div>
  3. <BasicTable @register="registerTable">
  4. <template #action="{ record }">
  5. <!-- <TableAction :actions="getActions(record)" :dropDownActions="getDropDownAction(record)" /> -->
  6. <a class="table-action-link" @click="handleEdit(record)">编辑</a>
  7. <a-popconfirm
  8. title="确定删除?"
  9. @confirm="handleDelete(record)"
  10. >
  11. <a class="table-action-link">删除</a>
  12. </a-popconfirm>
  13. <a class="table-action-link" @click="handleDownLoad(record)">下载</a>
  14. </template>
  15. <template #bodyCell="{ column, record }">
  16. <slot name="filterCell" v-bind="{ column, record }"></slot>
  17. </template>
  18. </BasicTable>
  19. <DeviceModal :editID="editID" :fileType="fileType" @register="registerModal" />
  20. </div>
  21. </template>
  22. <script lang="ts" name="system-user" setup>
  23. //ts语法
  24. import { ref, provide, reactive, toRaw, defineExpose, } from 'vue';
  25. import { BasicTable, TableAction } from '/@/components/Table';
  26. import { useModal } from '/@/components/Modal';
  27. import DeviceModal from './DeviceModal.vue';
  28. import { getTableHeaderColumns } from '/@/hooks/web/useWebColumns';
  29. import { useListPage } from '/@/hooks/system/useListPage';
  30. const props = defineProps({
  31. //各矿参数
  32. selfParam: {
  33. type: Object,
  34. default: () => {
  35. return {}
  36. }
  37. },
  38. //查询参数
  39. searchParam: {
  40. type: String,
  41. default: '',
  42. },
  43. //菜单树传递参数
  44. nodeParam: {
  45. type: Object,
  46. default: () => {
  47. return {};
  48. },
  49. },
  50. columnsType: {
  51. type: String,
  52. // required: true,
  53. },
  54. columns: {
  55. type: Array,
  56. // required: true,
  57. default: () => [],
  58. },
  59. list: {
  60. type: Function,
  61. required: true,
  62. },
  63. //下载文件接口
  64. downLoad: {
  65. type: Function,
  66. required: true,
  67. },
  68. deleteById: {
  69. type: Function,
  70. required: true,
  71. },
  72. pointList: {
  73. type: Function,
  74. // required: true,
  75. },
  76. designScope: {
  77. type: String,
  78. },
  79. title: {
  80. type: String,
  81. },
  82. });
  83. let fileType = ref(''); //文件类型
  84. let editID = ref(0); //文件ID
  85. const isUpdate = ref(false);
  86. const record = reactive({});
  87. provide('formData', record);
  88. const [registerModal, { openModal, closeModal }] = useModal();
  89. const columnList = getTableHeaderColumns(props.columnsType);
  90. console.log('aaa', columnList);
  91. // 列表页面公共参数、方法
  92. const { tableContext, doRequest } = useListPage({
  93. designScope: props.designScope,
  94. tableProps: {
  95. title: props.title,
  96. api: props.list,
  97. columns: props.columns.length > 0 ? (props.columns as any[]) : columnList,
  98. // size: 'small',
  99. bordered: false,
  100. // formConfig: {
  101. // // labelWidth: 100,
  102. // labelAlign: 'left',
  103. // labelCol: {
  104. // xs: 24,
  105. // sm: 24,
  106. // md: 24,
  107. // lg: 9,
  108. // xl: 7,
  109. // xxl: 5,
  110. // },
  111. // schemas: props.searchFormSchema as any[],
  112. // },
  113. striped: true,
  114. showIndexColumn: true, //是否显示序列号
  115. actionColumn: {
  116. width: 280,
  117. },
  118. useSearchForm: false, //不使用查询条件
  119. // pagination: false, //不使用分页组件
  120. beforeFetch: (params) => {
  121. params.parentId = props.nodeParam.id ? props.nodeParam.id : '';
  122. params.selectFlag = props.nodeParam.id ? false : true;
  123. params.likeFileName = props.searchParam ? props.searchParam : '';
  124. params.bpmStatus = props.selfParam.bpmStatus ? props.selfParam.bpmStatus : ''
  125. params.sysOrgCode = props.selfParam.sysOrgCode ? props.selfParam.sysOrgCode : ''
  126. // return Object.assign({ column: '111', order: 'd11' }, params);
  127. // return Object.assign({ parentId: '', selectFlag: true, likeFileName: '' }, params);
  128. },
  129. },
  130. });
  131. //注册table数据
  132. const [registerTable, { reload }, { selectedRowKeys }] = tableContext;
  133. /**
  134. * 编辑事件
  135. */
  136. function handleEdit(data) {
  137. isUpdate.value = true;
  138. Object.assign(record, toRaw(data));
  139. console.log(record, '编辑');
  140. let index = record.fileSuffix.indexOf('.');
  141. fileType.value = record.fileSuffix.substring(index + 1);
  142. editID.value = record.id;
  143. console.log(fileType, '文件格式');
  144. console.log(editID.value, '编辑文件ID');
  145. openModal(true, {
  146. record,
  147. });
  148. }
  149. /**
  150. * 删除事件
  151. */
  152. async function handleDelete(record) {
  153. await props.deleteById({ id: record.id }, reload);
  154. }
  155. //下载文件
  156. function handleDownLoad(record) {
  157. console.log(record, '下载');
  158. props.downLoad({ id: record.id }).then((res) => {
  159. console.log('11111');
  160. console.log(res, '文件下载成功');
  161. let filename = `${record.fileName}`;
  162. downFilePublic(res, filename);
  163. });
  164. }
  165. // 下载公用方法
  166. function downFilePublic(content, fileName) {
  167. const blob = new Blob([content], { type: 'application/xlsx;charset=UTF-8' }); // 构造一个blob对象来处理数据
  168. // 对于<a>标签,只有 Firefox 和 Chrome(内核) 支持 download 属性
  169. // IE10以上支持blob但是依然不支持download
  170. if ('download' in document.createElement('a')) {
  171. // 支持a标签download的浏览器
  172. const link = document.createElement('a'); // 创建a标签
  173. link.download = fileName; // a标签添加属性
  174. link.style.display = 'none';
  175. link.href = URL.createObjectURL(blob);
  176. document.body.appendChild(link);
  177. link.click(); // 执行下载
  178. URL.revokeObjectURL(link.href); // 释放url
  179. document.body.removeChild(link); // 释放标签
  180. } else {
  181. // 其他浏览器
  182. navigator.msSaveBlob(blob, fileName);
  183. }
  184. }
  185. // /**
  186. // * 操作列定义
  187. // * @param record
  188. // */
  189. // function getActions(record) {
  190. // return [
  191. // {
  192. // label: '详情',
  193. // onClick: handleEdit.bind(null, record),
  194. // },
  195. // {
  196. // label: '编辑',
  197. // onClick: handleEdit.bind(null, record),
  198. // },
  199. // {
  200. // label: '删除',
  201. // popConfirm: {
  202. // title: '是否确认删除',
  203. // confirm: handleDelete.bind(null, record),
  204. // },
  205. // },
  206. // {
  207. // label: '下载',
  208. // onClick: handleDownLoad.bind(null, record),
  209. // },
  210. // // {
  211. // // label: '审批',
  212. // // onClick: handleEdit.bind(null, record),
  213. // // },
  214. // // {
  215. // // label: '查看',
  216. // // onClick: handleDetail.bind(null, record),
  217. // // },
  218. // ];
  219. // }
  220. /**
  221. * 下拉操作栏
  222. */
  223. function getDropDownAction(record) {
  224. return [
  225. // {
  226. // label: '删除',
  227. // popConfirm: {
  228. // title: '是否确认删除',
  229. // confirm: handleDelete.bind(null, record),
  230. // },
  231. // },
  232. // {
  233. // label: '查看',
  234. // onClick: handleDetail.bind(null, record),
  235. // },
  236. ];
  237. }
  238. defineExpose({
  239. doRequest,
  240. });
  241. </script>
  242. <style scoped lang="less">
  243. // @ventSpace: zxm;
  244. // @vent-table-no-hover: rgba(43, 135, 255, 0.1);
  245. // @vent-table-hover: rgba(53, 147, 255, 0.2);
  246. // :deep(.zxm-table-row) {
  247. // td {
  248. // background-color: @vent-table-hover !important;
  249. // }
  250. // }
  251. // :deep(.jeecg-basic-table-row__striped) {
  252. // td {
  253. // background-color: @vent-table-no-hover !important;
  254. // }
  255. // }
  256. // ::v-deep .zxm-table-title {
  257. // display: none;
  258. // }
  259. // ::v-deep .zxm-table-thead > tr > th {
  260. // border-top: 0px !important;
  261. // border-left: 0px !important;
  262. // border-right: 0px !important;
  263. // border-bottom: 1px solid #268bc1 !important;
  264. // color: #3beff9 !important;
  265. // }
  266. // ::v-deep .zxm-table-tbody > tr > td {
  267. // border: none;
  268. // }
  269. // ::v-deep .zxm-table-thead {
  270. // background: linear-gradient(to bottom, transparent, rgba(53, 147, 255, 0.5)) !important;
  271. // }
  272. @ventSpace: zxm;
  273. @vent-table-no-hover: #00bfff10;
  274. :deep(.@{ventSpace}-table-cell-row-hover) {
  275. background: #264d8833 !important;
  276. }
  277. :deep(.@{ventSpace}-table-row-selected) {
  278. background: #268bc522 !important;
  279. }
  280. :deep(.@{ventSpace}-table-tbody > tr > td) {
  281. background-color: #0dc3ff05;
  282. }
  283. :deep(.jeecg-basic-table-row__striped) {
  284. td {
  285. background-color: @vent-table-no-hover !important;
  286. }
  287. }
  288. ::v-deep .zxm-table-title {
  289. display: none;
  290. }</style>