Default.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  1. <template>
  2. <div class="box">
  3. <Prequalification />
  4. <div class="search-form">
  5. <QueryForm
  6. :is-show-tab="false"
  7. :ai-options="aiMainOptions"
  8. :manual-options="manualMainOptions"
  9. :location-options="locationOptions"
  10. @on-search="handleSearch"
  11. @on-reset="handleReset"
  12. @on-export="handleExport"
  13. />
  14. </div>
  15. <div class="table-list">
  16. <div v-if="showActionBar" class="action-bar">
  17. <span class="num-text">已选{{ chooseNum }}项</span>
  18. <el-button :class="isActiveCancelHide ? 'btn-active' : 'btn-normal'" @click="handleCancelHideAll"
  19. >全部生效</el-button
  20. >
  21. <el-button :class="isActiveHide ? 'btn-active' : 'btn-normal'" @click="handleHideAll">全部失效</el-button>
  22. <el-button
  23. v-if="hasDeletePermission()"
  24. :class="isActiveDelete ? 'btn-active' : 'btn-normal'"
  25. @click="handleDeleteAll"
  26. >删除</el-button
  27. >
  28. <el-button
  29. v-if="!cancelUrgentFlag"
  30. :class="isActiveUrgent ? 'btn-active' : 'btn-normal'"
  31. @click="handleUrgentAll"
  32. >标记加急</el-button
  33. >
  34. <el-button
  35. v-if="cancelUrgentFlag"
  36. :class="isActiveCancelUrgent ? 'btn-active' : 'btn-normal'"
  37. @click="handleCancelUrgentAll"
  38. >取消加急</el-button
  39. >
  40. <el-button v-if="hasPermisson()" :class="isActiveCopy ? 'btn-active' : 'btn-normal'" @click="handleCopyToShow"
  41. >复制到展示数据</el-button
  42. >
  43. <span class="close-btn" @click="handleSelectNone"></span>
  44. </div>
  45. <AlertTable
  46. ref="alertTableRef"
  47. class="table-bar"
  48. :is-show-tab="false"
  49. :table-data="tableData"
  50. :on-detail="handleDetail"
  51. :on-urgent="handleUrgent"
  52. :on-show="handleShow"
  53. :on-delete="handleDelete"
  54. @update:selection="handlePop"
  55. @update:time-sort="handleChangeTimeSort"
  56. />
  57. </div>
  58. <div class="pagination-box">
  59. <Pagination
  60. v-model:page="query.pageNumber"
  61. v-model:size="query.pageSize"
  62. :total="total"
  63. @update:page="handlePageChange"
  64. @update:size="handleSizeChange"
  65. />
  66. </div>
  67. <DetailDialog
  68. v-if="isDetailDialogShow"
  69. :has-been-chosen="detailRowChosen"
  70. :description="detailDescription"
  71. :image-paths="detailPictures"
  72. :video-paths="detailVideos"
  73. :has-previous="hasPreviousRow"
  74. :has-next="hasNextRow"
  75. @close="closeDetailDialog"
  76. @update:previous="handleChangePrevious"
  77. @update:next="handleChangeNext"
  78. @update:choose="handleChangeChoose"
  79. />
  80. </div>
  81. </template>
  82. <script setup lang="ts">
  83. import { ref, onMounted, onBeforeMount } from 'vue';
  84. import { ElMessage, ElMessageBox } from 'element-plus';
  85. import axios, { AxiosRequestConfig } from 'axios';
  86. import QueryForm from '../common/QueryForm.vue';
  87. import AlertTable, { DataSourceItem } from '../common/AlertTable.vue';
  88. import DetailDialog from '../common/DetailDialog.vue';
  89. import Pagination from '../common/Pagination.vue';
  90. import { useWorkLocation } from '../../hooks/useWorkLocation';
  91. import { useIssueMainType } from '../../hooks/useIssueMainType';
  92. import {
  93. TableQueryForm,
  94. getDefaultTableData,
  95. deleteDefaultTableData,
  96. copyToShowTableData,
  97. updateDefaultHide,
  98. updateDefaultHideAll,
  99. updateDefaultPriority,
  100. updateDefaultPriorityAll,
  101. } from '@/api/datamanagement/alert-default';
  102. import Prequalification from '../common/Prequalification.vue';
  103. import { useUserStore } from '@/store/modules/user';
  104. import { useGlobSetting } from '@/hooks/setting';
  105. import urlJoin from 'url-join';
  106. import { getHeaders } from '@/utils/http/axios';
  107. import { PERM_DATA } from '@/types/permission/constants';
  108. const userStore = useUserStore();
  109. const { locationOptions, getLocationOptions } = useWorkLocation();
  110. const { aiMainOptions, manualMainOptions, getAIMainOptions, getManualMainOptions } = useIssueMainType();
  111. const { urlPrefix } = useGlobSetting();
  112. const alertTableRef = ref<typeof AlertTable>();
  113. const tableData = ref<DataSourceItem[]>([]);
  114. const showActionBar = ref(false);
  115. const chooseNum = ref(0);
  116. const chooseRow = ref<DataSourceItem[]>([]); // 被选中的数据行
  117. const chooseId = ref<number[]>([]);
  118. const cancelUrgentFlag = ref(true); // true取消加急 / false全部加急
  119. const isActiveHide = ref(false);
  120. const isActiveCancelHide = ref(false);
  121. const isActiveDelete = ref(false);
  122. const isActiveUrgent = ref(false);
  123. const isActiveCancelUrgent = ref(false);
  124. const isActiveCopy = ref(false);
  125. // 详情
  126. const isDetailDialogShow = ref(false);
  127. const detailRowChosen = ref(false); // 当前行是否被选中
  128. const detailRow = ref(); // 当前行
  129. const detailCurRowIndex = ref(0); // 当前行index
  130. const detailPreviousRow = ref(); // 上一行
  131. const detailNextRow = ref(); // 下一行
  132. const hasPreviousRow = ref(false); // 是否有上一行
  133. const hasNextRow = ref(false); // 是否有下一行
  134. const detailDescription = ref('');
  135. const detailPictures = ref<string[]>([]);
  136. const detailVideos = ref<string[]>([]);
  137. // 分页
  138. const total = ref(0);
  139. const query = ref<TableQueryForm>({
  140. pageNumber: 1,
  141. pageSize: 10,
  142. queryParam: {},
  143. });
  144. // 查询
  145. const handleSearch = (queryForm) => {
  146. query.value = queryForm;
  147. getTableData();
  148. };
  149. // 重置
  150. const handleReset = (queryForm) => {
  151. query.value = queryForm;
  152. getTableData();
  153. };
  154. // 导出
  155. const handleExport = async (queryForm, workShop) => {
  156. const tempWorkShopIds = ref<number[]>([]);
  157. if (workShop.length === 0) {
  158. locationOptions.value.forEach((item) => {
  159. tempWorkShopIds.value.push(item.value);
  160. });
  161. } else {
  162. tempWorkShopIds.value = workShop;
  163. }
  164. try {
  165. const now = new Date();
  166. const year = now.getFullYear();
  167. const month = String(now.getMonth() + 1).padStart(2, '0');
  168. const day = String(now.getDate()).padStart(2, '0');
  169. const currentDate = `${year}${month}${day}`;
  170. const currentUrl = urlJoin(window.location.origin, window.location.pathname);
  171. const requestBody = {
  172. imageBaseUrl: currentUrl,
  173. queryDisplayIssueReq: {
  174. issueMainTypeList: queryForm.queryParam.issueMainTypeList,
  175. issueTypeList: queryForm.queryParam.issueTypeList,
  176. workspaceId: queryForm.queryParam.workspaceId,
  177. workshopIds: tempWorkShopIds.value,
  178. source: queryForm.queryParam.source,
  179. issueState: queryForm.queryParam.issueState,
  180. startTime: queryForm.queryParam.startTime,
  181. endTime: queryForm.queryParam.endTime,
  182. hide: queryForm.queryParam.hide,
  183. order: queryForm.queryParam.order,
  184. },
  185. };
  186. const config: AxiosRequestConfig = {
  187. headers: getHeaders(),
  188. responseType: 'blob',
  189. };
  190. const response = await axios.post(urlPrefix + '/admin/issueManage/exportIssueList', requestBody, config);
  191. const blob = new Blob([response.data], {
  192. type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
  193. });
  194. // 创建下载链接
  195. let downloadLink: HTMLAnchorElement | null = document.createElement('a');
  196. const url = window.URL.createObjectURL(blob);
  197. downloadLink.href = url;
  198. downloadLink.download = `安全违规问题数据统计表${currentDate}.xlsx`;
  199. downloadLink.click();
  200. // 移除下载链接
  201. window.URL.revokeObjectURL(url);
  202. downloadLink = null;
  203. } catch (error) {
  204. console.error('Error downloading file:', error);
  205. }
  206. };
  207. // 表格排序切换
  208. const handleChangeTimeSort = (curTimeSort) => {
  209. query.value.queryParam.order = curTimeSort;
  210. getTableData();
  211. };
  212. // 多选
  213. const handlePop = (selection) => {
  214. chooseRow.value = selection;
  215. chooseId.value = [];
  216. cancelUrgentFlag.value = true;
  217. selection.forEach((item) => {
  218. if (chooseId.value.indexOf(item.id) === -1) chooseId.value.push(item.id);
  219. if (item.priority === 0) cancelUrgentFlag.value = false;
  220. });
  221. chooseNum.value = selection.length;
  222. showActionBar.value = chooseNum.value > 0 ? true : false;
  223. };
  224. // 取消多选
  225. const handleSelectNone = () => {
  226. chooseId.value = [];
  227. chooseNum.value = 0;
  228. alertTableRef.value?.clearAll();
  229. showActionBar.value = false;
  230. };
  231. // 改变该行的选中状态
  232. const handleChangeChoose = (status) => {
  233. alertTableRef.value?.updateCurRowChosen(detailRow.value, !status);
  234. updateDetailDialog(detailRow.value);
  235. };
  236. // 全部隐藏
  237. const handleHideAll = () => {
  238. if (showActionBar.value) isActiveHide.value = !isActiveHide.value;
  239. const updateList = {
  240. ids: chooseId.value,
  241. hide: true,
  242. };
  243. updateDefaultHideAll(updateList).then(() => {
  244. handleSelectNone();
  245. getTableData();
  246. ElMessage({
  247. message: '操作成功',
  248. type: 'success',
  249. });
  250. setTimeout(function () {
  251. isActiveHide.value = !isActiveHide.value;
  252. }, 1000);
  253. });
  254. };
  255. // 取消隐藏
  256. const handleCancelHideAll = () => {
  257. if (showActionBar.value) isActiveCancelHide.value = !isActiveCancelHide.value;
  258. const updateList = {
  259. ids: chooseId.value,
  260. hide: false,
  261. };
  262. updateDefaultHideAll(updateList).then(() => {
  263. handleSelectNone();
  264. getTableData();
  265. ElMessage({
  266. message: '操作成功',
  267. type: 'success',
  268. });
  269. setTimeout(function () {
  270. isActiveCancelHide.value = !isActiveCancelHide.value;
  271. }, 1000);
  272. });
  273. };
  274. // 批量删除
  275. const handleDeleteAll = () => {
  276. if (showActionBar.value) isActiveDelete.value = !isActiveDelete.value;
  277. ElMessageBox.confirm('删除之后,数据无法恢复', '请确认是否删除数据', {
  278. confirmButtonText: '确定',
  279. cancelButtonText: '取消',
  280. type: 'warning',
  281. customClass: 'deleteMessage',
  282. center: true,
  283. })
  284. .then(() => {
  285. deleteDefaultTableData(chooseId.value).then(() => {
  286. ElMessage({
  287. type: 'success',
  288. message: '删除成功',
  289. });
  290. getTableData();
  291. handleSelectNone();
  292. isActiveDelete.value = !isActiveDelete.value;
  293. });
  294. })
  295. .catch(() => {
  296. ElMessage({
  297. type: 'info',
  298. message: '取消删除',
  299. });
  300. isActiveDelete.value = !isActiveDelete.value;
  301. });
  302. };
  303. // 标记加急,设置priority = 1
  304. const handleUrgentAll = () => {
  305. if (showActionBar.value) isActiveUrgent.value = !isActiveUrgent.value;
  306. const updateList = {
  307. ids: chooseId.value,
  308. priority: 1,
  309. };
  310. updateDefaultPriorityAll(updateList).then(() => {
  311. handleSelectNone();
  312. getTableData();
  313. ElMessage({
  314. message: '已加急',
  315. type: 'success',
  316. });
  317. setTimeout(function () {
  318. isActiveUrgent.value = !isActiveUrgent.value;
  319. }, 1000);
  320. });
  321. };
  322. // 取消加急
  323. const handleCancelUrgentAll = () => {
  324. if (showActionBar.value) isActiveCancelUrgent.value = !isActiveCancelUrgent.value;
  325. const updateList = {
  326. ids: chooseId.value,
  327. priority: 0,
  328. };
  329. updateDefaultPriorityAll(updateList).then(() => {
  330. handleSelectNone();
  331. getTableData();
  332. ElMessage({
  333. message: '已取消加急',
  334. type: 'success',
  335. });
  336. setTimeout(function () {
  337. isActiveCancelUrgent.value = !isActiveCancelUrgent.value;
  338. }, 1000);
  339. });
  340. };
  341. // 复制到展示数据
  342. const handleCopyToShow = () => {
  343. if (showActionBar.value) isActiveCopy.value = !isActiveCopy.value;
  344. copyToShowTableData(chooseId.value).then(() => {
  345. ElMessage({
  346. message: '复制成功',
  347. type: 'success',
  348. });
  349. setTimeout(function () {
  350. isActiveCopy.value = !isActiveCopy.value;
  351. }, 1000);
  352. handleSelectNone();
  353. });
  354. };
  355. // 详情
  356. const closeDetailDialog = () => {
  357. isDetailDialogShow.value = false;
  358. };
  359. // 更新detailCurRowIndex、detailPreviousRow、detailNextRow、hasPreviousRow、hasNextRow
  360. const updateDetailDialog = (curRow) => {
  361. detailDescription.value = curRow.description;
  362. detailPictures.value = curRow.pictures;
  363. detailVideos.value = curRow.videos;
  364. detailCurRowIndex.value = tableData.value.findIndex((item) => item.id === curRow.id);
  365. detailPreviousRow.value = tableData.value[detailCurRowIndex.value - 1];
  366. detailNextRow.value = tableData.value[detailCurRowIndex.value + 1];
  367. if (detailPreviousRow.value) hasPreviousRow.value = true;
  368. else hasPreviousRow.value = false;
  369. if (detailNextRow.value) hasNextRow.value = true;
  370. else hasNextRow.value = false;
  371. if (chooseRow.value.findIndex((item) => item.id === curRow.id) !== -1) detailRowChosen.value = true;
  372. else detailRowChosen.value = false;
  373. };
  374. const handleDetail = (row) => {
  375. isDetailDialogShow.value = true;
  376. detailRow.value = row;
  377. updateDetailDialog(detailRow.value);
  378. };
  379. // 上一个
  380. const handleChangePrevious = () => {
  381. detailRow.value = detailPreviousRow.value;
  382. updateDetailDialog(detailRow.value);
  383. };
  384. // 下一个
  385. const handleChangeNext = () => {
  386. detailRow.value = detailNextRow.value;
  387. updateDetailDialog(detailRow.value);
  388. };
  389. // 单个加急priority=1/取消加急priority=0
  390. const handleUrgent = (row) => {
  391. const tempPriority = row.priority === 0 ? 1 : 0;
  392. const updateList = {
  393. id: row.id,
  394. priority: tempPriority,
  395. };
  396. updateDefaultPriority(updateList).then(() => {
  397. getTableData();
  398. });
  399. };
  400. // 单个显示hide=false/隐藏hide=true
  401. const handleShow = (row) => {
  402. const tempHide = row.isHide === false ? true : false;
  403. const updateList = {
  404. id: row.id,
  405. hide: tempHide,
  406. };
  407. updateDefaultHide(updateList).then(() => {
  408. getTableData();
  409. });
  410. };
  411. // 删除
  412. const handleDelete = (row) => {
  413. ElMessageBox.confirm('删除之后,数据无法恢复', '请确认是否删除数据', {
  414. confirmButtonText: '确定',
  415. cancelButtonText: '取消',
  416. type: 'warning',
  417. customClass: 'deleteMessage',
  418. center: true,
  419. })
  420. .then(() => {
  421. deleteDefaultTableData([row.id]).then(() => {
  422. ElMessage({
  423. type: 'success',
  424. message: '删除成功',
  425. });
  426. getTableData();
  427. });
  428. })
  429. .catch(() => {
  430. ElMessage({
  431. type: 'info',
  432. message: '取消删除',
  433. });
  434. });
  435. };
  436. // 换页,重新获取表格
  437. const handlePageChange = (val) => {
  438. query.value.pageNumber = val;
  439. getTableData();
  440. };
  441. const handleSizeChange = (val) => {
  442. query.value.pageSize = val;
  443. getTableData();
  444. };
  445. const getTableData = () => {
  446. getDefaultTableData(query.value).then((res) => {
  447. console.log(res);
  448. tableData.value = res.records;
  449. total.value = res.totalRow;
  450. });
  451. };
  452. const hasDeletePermission = () => {
  453. return userStore.checkPermission(PERM_DATA.VIOLATION_DELETE);
  454. };
  455. const hasPermisson = () => {
  456. return (
  457. userStore.checkPermission(PERM_DATA.VIOLATION_FAKE_ADD) ||
  458. userStore.checkPermission(PERM_DATA.VIOLATION_FAKE_DELETE)
  459. );
  460. };
  461. onMounted(() => {
  462. getTableData();
  463. });
  464. onBeforeMount(() => {
  465. getAIMainOptions();
  466. getManualMainOptions();
  467. getLocationOptions();
  468. });
  469. </script>
  470. <style scoped lang="less">
  471. .box {
  472. display: flex;
  473. flex-direction: column;
  474. }
  475. .table-list {
  476. flex: 1;
  477. .action-bar {
  478. display: flex;
  479. align-items: center;
  480. position: absolute;
  481. min-width: calc(100vw - 266px);
  482. height: 50px;
  483. border-radius: 4px 4px 0px 0px;
  484. background-color: #ddefff;
  485. z-index: 10;
  486. .num-text {
  487. margin: 0 34px 0 25px;
  488. color: rgba(0, 0, 0, 0.85);
  489. font-weight: 500;
  490. }
  491. .btn-normal {
  492. color: #1890ff;
  493. background: transparent;
  494. border: 1px solid #1890ff;
  495. border-radius: 2px;
  496. }
  497. .btn-active {
  498. color: #ffffff;
  499. background-color: #1890ff;
  500. }
  501. .close-btn {
  502. margin-left: auto;
  503. margin-right: 20px;
  504. }
  505. .close-btn:before {
  506. content: '\2716';
  507. color: #000;
  508. cursor: pointer;
  509. }
  510. }
  511. .table-bar {
  512. position: relative;
  513. }
  514. }
  515. .pagination-box {
  516. height: 50px;
  517. margin-top: 10px;
  518. }
  519. </style>
  520. <style lang="less">
  521. .deleteMessage {
  522. padding: 20px 24px;
  523. box-shadow: 0px 12px 48px 16px rgba(0, 0, 0, 0.03), 0px 9px 28px 0px rgba(0, 0, 0, 0.05),
  524. 0px 6px 16px -8px rgba(0, 0, 0, 0.08);
  525. border-radius: 8px;
  526. .el-message-box__headerbtn {
  527. margin-top: 12px;
  528. margin-right: 12px;
  529. }
  530. .el-message-box__title {
  531. justify-content: start;
  532. color: rgba(0, 0, 0, 0.88);
  533. font-size: 16px;
  534. font-weight: 500;
  535. }
  536. .el-message-box__container {
  537. justify-content: start;
  538. margin-left: 23px;
  539. }
  540. .el-message-box__btns {
  541. display: block;
  542. float: right;
  543. }
  544. }
  545. </style>