Default.vue 16 KB

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