NormalTable.vue 7.4 KB

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