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