NormalTable.vue 8.4 KB

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