NormalTable.vue 8.3 KB

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