NormalTable.vue 8.8 KB

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