| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586 |
- <template>
- <div class="box">
- <Prequalification />
- <div class="search-form">
- <QueryForm
- :is-show-tab="false"
- :ai-options="aiMainOptions"
- :manual-options="manualMainOptions"
- :location-options="locationOptions"
- @on-search="handleSearch"
- @on-reset="handleReset"
- @on-export="handleExport"
- />
- </div>
- <div class="table-list">
- <div v-if="showActionBar" class="action-bar">
- <span class="num-text">已选{{ chooseNum }}项</span>
- <el-button :class="isActiveCancelHide ? 'btn-active' : 'btn-normal'" @click="handleCancelHideAll"
- >全部生效</el-button
- >
- <el-button :class="isActiveHide ? 'btn-active' : 'btn-normal'" @click="handleHideAll">全部失效</el-button>
- <el-button
- v-if="hasDeletePermission()"
- :class="isActiveDelete ? 'btn-active' : 'btn-normal'"
- @click="handleDeleteAll"
- >删除</el-button
- >
- <el-button
- v-if="!cancelUrgentFlag"
- :class="isActiveUrgent ? 'btn-active' : 'btn-normal'"
- @click="handleUrgentAll"
- >标记加急</el-button
- >
- <el-button
- v-if="cancelUrgentFlag"
- :class="isActiveCancelUrgent ? 'btn-active' : 'btn-normal'"
- @click="handleCancelUrgentAll"
- >取消加急</el-button
- >
- <el-button v-if="hasPermisson()" :class="isActiveCopy ? 'btn-active' : 'btn-normal'" @click="handleCopyToShow"
- >复制到展示数据</el-button
- >
- <span class="close-btn" @click="handleSelectNone"></span>
- </div>
- <AlertTable
- ref="alertTableRef"
- class="table-bar"
- :is-show-tab="false"
- :table-data="tableData"
- :on-detail="handleDetail"
- :on-urgent="handleUrgent"
- :on-show="handleShow"
- :on-delete="handleDelete"
- @update:selection="handlePop"
- @update:time-sort="handleChangeTimeSort"
- />
- </div>
- <div class="pagination-box">
- <Pagination
- v-model:page="query.pageNumber"
- v-model:size="query.pageSize"
- :total="total"
- @update:page="handlePageChange"
- @update:size="handleSizeChange"
- />
- </div>
- <DetailDialog
- v-if="isDetailDialogShow"
- :has-been-chosen="detailRowChosen"
- :description="detailDescription"
- :image-paths="detailPictures"
- :video-paths="detailVideos"
- :has-previous="hasPreviousRow"
- :has-next="hasNextRow"
- @close="closeDetailDialog"
- @update:previous="handleChangePrevious"
- @update:next="handleChangeNext"
- @update:choose="handleChangeChoose"
- />
- </div>
- </template>
- <script setup lang="ts">
- import { ref, onMounted, onBeforeMount } from 'vue';
- import { ElMessage, ElMessageBox } from 'element-plus';
- import axios, { AxiosRequestConfig } from 'axios';
- import QueryForm from '../common/QueryForm.vue';
- import AlertTable, { DataSourceItem } from '../common/AlertTable.vue';
- import DetailDialog from '../common/DetailDialog.vue';
- import Pagination from '../common/Pagination.vue';
- import { useWorkLocation } from '../../hooks/useWorkLocation';
- import { useIssueMainType } from '../../hooks/useIssueMainType';
- import {
- TableQueryForm,
- getDefaultTableData,
- deleteDefaultTableData,
- copyToShowTableData,
- updateDefaultHide,
- updateDefaultHideAll,
- updateDefaultPriority,
- updateDefaultPriorityAll,
- } from '@/api/datamanagement/alert-default';
- import Prequalification from '../common/Prequalification.vue';
- import { useUserStore } from '@/store/modules/user';
- import { useGlobSetting } from '@/hooks/setting';
- import urlJoin from 'url-join';
- import { getHeaders } from '@/utils/http/axios';
- import { PERM_DATA } from '@/types/permission/constants';
- const userStore = useUserStore();
- const { locationOptions, getLocationOptions } = useWorkLocation();
- const { aiMainOptions, manualMainOptions, getAIMainOptions, getManualMainOptions } = useIssueMainType();
- const { urlPrefix } = useGlobSetting();
- const alertTableRef = ref<typeof AlertTable>();
- const tableData = ref<DataSourceItem[]>([]);
- const showActionBar = ref(false);
- const chooseNum = ref(0);
- const chooseRow = ref<DataSourceItem[]>([]); // 被选中的数据行
- const chooseId = ref<number[]>([]);
- const cancelUrgentFlag = ref(true); // true取消加急 / false全部加急
- const isActiveHide = ref(false);
- const isActiveCancelHide = ref(false);
- const isActiveDelete = ref(false);
- const isActiveUrgent = ref(false);
- const isActiveCancelUrgent = ref(false);
- const isActiveCopy = ref(false);
- // 详情
- const isDetailDialogShow = ref(false);
- const detailRowChosen = ref(false); // 当前行是否被选中
- const detailRow = ref(); // 当前行
- const detailCurRowIndex = ref(0); // 当前行index
- const detailPreviousRow = ref(); // 上一行
- const detailNextRow = ref(); // 下一行
- const hasPreviousRow = ref(false); // 是否有上一行
- const hasNextRow = ref(false); // 是否有下一行
- const detailDescription = ref('');
- const detailPictures = ref<string[]>([]);
- const detailVideos = ref<string[]>([]);
- // 分页
- const total = ref(0);
- const query = ref<TableQueryForm>({
- pageNumber: 1,
- pageSize: 10,
- queryParam: {},
- });
- // 查询
- const handleSearch = (queryForm) => {
- query.value = queryForm;
- getTableData();
- };
- // 重置
- const handleReset = (queryForm) => {
- query.value = queryForm;
- getTableData();
- };
- // 导出
- const handleExport = async (queryForm, workShop) => {
- const tempWorkShopIds = ref<number[]>([]);
- if (workShop.length === 0) {
- locationOptions.value.forEach((item) => {
- tempWorkShopIds.value.push(item.value);
- });
- } else {
- tempWorkShopIds.value = workShop;
- }
- try {
- const now = new Date();
- const year = now.getFullYear();
- const month = String(now.getMonth() + 1).padStart(2, '0');
- const day = String(now.getDate()).padStart(2, '0');
- const currentDate = `${year}${month}${day}`;
- const currentUrl = urlJoin(window.location.origin, window.location.pathname);
- const requestBody = {
- imageBaseUrl: currentUrl,
- queryDisplayIssueReq: {
- issueMainTypeList: queryForm.queryParam.issueMainTypeList,
- issueTypeList: queryForm.queryParam.issueTypeList,
- workspaceId: queryForm.queryParam.workspaceId,
- workshopIds: tempWorkShopIds.value,
- source: queryForm.queryParam.source,
- issueState: queryForm.queryParam.issueState,
- startTime: queryForm.queryParam.startTime,
- endTime: queryForm.queryParam.endTime,
- hide: queryForm.queryParam.hide,
- order: queryForm.queryParam.order,
- },
- };
- const config: AxiosRequestConfig = {
- headers: getHeaders(),
- responseType: 'blob',
- };
- const response = await axios.post(urlPrefix + '/admin/issueManage/exportIssueList', requestBody, config);
- const blob = new Blob([response.data], {
- type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
- });
- // 创建下载链接
- let downloadLink: HTMLAnchorElement | null = document.createElement('a');
- const url = window.URL.createObjectURL(blob);
- downloadLink.href = url;
- downloadLink.download = `安全违规问题数据统计表${currentDate}.xlsx`;
- downloadLink.click();
- // 移除下载链接
- window.URL.revokeObjectURL(url);
- downloadLink = null;
- } catch (error) {
- console.error('Error downloading file:', error);
- }
- };
- // 表格排序切换
- const handleChangeTimeSort = (curTimeSort) => {
- query.value.queryParam.order = curTimeSort;
- getTableData();
- };
- // 多选
- const handlePop = (selection) => {
- chooseRow.value = selection;
- chooseId.value = [];
- cancelUrgentFlag.value = true;
- selection.forEach((item) => {
- if (chooseId.value.indexOf(item.id) === -1) chooseId.value.push(item.id);
- if (item.priority === 0) cancelUrgentFlag.value = false;
- });
- chooseNum.value = selection.length;
- showActionBar.value = chooseNum.value > 0 ? true : false;
- };
- // 取消多选
- const handleSelectNone = () => {
- chooseId.value = [];
- chooseNum.value = 0;
- alertTableRef.value?.clearAll();
- showActionBar.value = false;
- };
- // 改变该行的选中状态
- const handleChangeChoose = (status) => {
- alertTableRef.value?.updateCurRowChosen(detailRow.value, !status);
- updateDetailDialog(detailRow.value);
- };
- // 全部隐藏
- const handleHideAll = () => {
- if (showActionBar.value) isActiveHide.value = !isActiveHide.value;
- const updateList = {
- ids: chooseId.value,
- hide: true,
- };
- updateDefaultHideAll(updateList).then(() => {
- handleSelectNone();
- getTableData();
- ElMessage({
- message: '操作成功',
- type: 'success',
- });
- setTimeout(function () {
- isActiveHide.value = !isActiveHide.value;
- }, 1000);
- });
- };
- // 取消隐藏
- const handleCancelHideAll = () => {
- if (showActionBar.value) isActiveCancelHide.value = !isActiveCancelHide.value;
- const updateList = {
- ids: chooseId.value,
- hide: false,
- };
- updateDefaultHideAll(updateList).then(() => {
- handleSelectNone();
- getTableData();
- ElMessage({
- message: '操作成功',
- type: 'success',
- });
- setTimeout(function () {
- isActiveCancelHide.value = !isActiveCancelHide.value;
- }, 1000);
- });
- };
- // 批量删除
- const handleDeleteAll = () => {
- if (showActionBar.value) isActiveDelete.value = !isActiveDelete.value;
- ElMessageBox.confirm('删除之后,数据无法恢复', '请确认是否删除数据', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning',
- customClass: 'deleteMessage',
- center: true,
- })
- .then(() => {
- deleteDefaultTableData(chooseId.value).then(() => {
- ElMessage({
- type: 'success',
- message: '删除成功',
- });
- getTableData();
- handleSelectNone();
- isActiveDelete.value = !isActiveDelete.value;
- });
- })
- .catch(() => {
- ElMessage({
- type: 'info',
- message: '取消删除',
- });
- isActiveDelete.value = !isActiveDelete.value;
- });
- };
- // 标记加急,设置priority = 1
- const handleUrgentAll = () => {
- if (showActionBar.value) isActiveUrgent.value = !isActiveUrgent.value;
- const updateList = {
- ids: chooseId.value,
- priority: 1,
- };
- updateDefaultPriorityAll(updateList).then(() => {
- handleSelectNone();
- getTableData();
- ElMessage({
- message: '已加急',
- type: 'success',
- });
- setTimeout(function () {
- isActiveUrgent.value = !isActiveUrgent.value;
- }, 1000);
- });
- };
- // 取消加急
- const handleCancelUrgentAll = () => {
- if (showActionBar.value) isActiveCancelUrgent.value = !isActiveCancelUrgent.value;
- const updateList = {
- ids: chooseId.value,
- priority: 0,
- };
- updateDefaultPriorityAll(updateList).then(() => {
- handleSelectNone();
- getTableData();
- ElMessage({
- message: '已取消加急',
- type: 'success',
- });
- setTimeout(function () {
- isActiveCancelUrgent.value = !isActiveCancelUrgent.value;
- }, 1000);
- });
- };
- // 复制到展示数据
- const handleCopyToShow = () => {
- if (showActionBar.value) isActiveCopy.value = !isActiveCopy.value;
- copyToShowTableData(chooseId.value).then(() => {
- ElMessage({
- message: '复制成功',
- type: 'success',
- });
- setTimeout(function () {
- isActiveCopy.value = !isActiveCopy.value;
- }, 1000);
- handleSelectNone();
- });
- };
- // 详情
- const closeDetailDialog = () => {
- isDetailDialogShow.value = false;
- };
- // 更新detailCurRowIndex、detailPreviousRow、detailNextRow、hasPreviousRow、hasNextRow
- const updateDetailDialog = (curRow) => {
- detailDescription.value = curRow.description;
- detailPictures.value = curRow.pictures;
- detailVideos.value = curRow.videos;
- detailCurRowIndex.value = tableData.value.findIndex((item) => item.id === curRow.id);
- detailPreviousRow.value = tableData.value[detailCurRowIndex.value - 1];
- detailNextRow.value = tableData.value[detailCurRowIndex.value + 1];
- if (detailPreviousRow.value) hasPreviousRow.value = true;
- else hasPreviousRow.value = false;
- if (detailNextRow.value) hasNextRow.value = true;
- else hasNextRow.value = false;
- if (chooseRow.value.findIndex((item) => item.id === curRow.id) !== -1) detailRowChosen.value = true;
- else detailRowChosen.value = false;
- };
- const handleDetail = (row) => {
- isDetailDialogShow.value = true;
- detailRow.value = row;
- updateDetailDialog(detailRow.value);
- };
- // 上一个
- const handleChangePrevious = () => {
- detailRow.value = detailPreviousRow.value;
- updateDetailDialog(detailRow.value);
- };
- // 下一个
- const handleChangeNext = () => {
- detailRow.value = detailNextRow.value;
- updateDetailDialog(detailRow.value);
- };
- // 单个加急priority=1/取消加急priority=0
- const handleUrgent = (row) => {
- const tempPriority = row.priority === 0 ? 1 : 0;
- const updateList = {
- id: row.id,
- priority: tempPriority,
- };
- updateDefaultPriority(updateList).then(() => {
- getTableData();
- });
- };
- // 单个显示hide=false/隐藏hide=true
- const handleShow = (row) => {
- const tempHide = row.isHide === false ? true : false;
- const updateList = {
- id: row.id,
- hide: tempHide,
- };
- updateDefaultHide(updateList).then(() => {
- getTableData();
- });
- };
- // 删除
- const handleDelete = (row) => {
- ElMessageBox.confirm('删除之后,数据无法恢复', '请确认是否删除数据', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning',
- customClass: 'deleteMessage',
- center: true,
- })
- .then(() => {
- deleteDefaultTableData([row.id]).then(() => {
- ElMessage({
- type: 'success',
- message: '删除成功',
- });
- getTableData();
- });
- })
- .catch(() => {
- ElMessage({
- type: 'info',
- message: '取消删除',
- });
- });
- };
- // 换页,重新获取表格
- const handlePageChange = (val) => {
- query.value.pageNumber = val;
- getTableData();
- };
- const handleSizeChange = (val) => {
- query.value.pageSize = val;
- getTableData();
- };
- const getTableData = () => {
- getDefaultTableData(query.value).then((res) => {
- console.log(res);
- tableData.value = res.records;
- total.value = res.totalRow;
- });
- };
- const hasDeletePermission = () => {
- return userStore.checkPermission(PERM_DATA.VIOLATION_DELETE);
- };
- const hasPermisson = () => {
- return (
- userStore.checkPermission(PERM_DATA.VIOLATION_FAKE_ADD) ||
- userStore.checkPermission(PERM_DATA.VIOLATION_FAKE_DELETE)
- );
- };
- onMounted(() => {
- getTableData();
- });
- onBeforeMount(() => {
- getAIMainOptions();
- getManualMainOptions();
- getLocationOptions();
- });
- </script>
- <style scoped lang="less">
- .box {
- display: flex;
- flex-direction: column;
- }
- .table-list {
- flex: 1;
- .action-bar {
- display: flex;
- align-items: center;
- position: absolute;
- min-width: calc(100vw - 266px);
- height: 50px;
- border-radius: 4px 4px 0px 0px;
- background-color: #ddefff;
- z-index: 10;
- .num-text {
- margin: 0 34px 0 25px;
- color: rgba(0, 0, 0, 0.85);
- font-weight: 500;
- }
- .btn-normal {
- color: #1890ff;
- background: transparent;
- border: 1px solid #1890ff;
- border-radius: 2px;
- }
- .btn-active {
- color: #ffffff;
- background-color: #1890ff;
- }
- .close-btn {
- margin-left: auto;
- margin-right: 20px;
- }
- .close-btn:before {
- content: '\2716';
- color: #000;
- cursor: pointer;
- }
- }
- .table-bar {
- position: relative;
- }
- }
- .pagination-box {
- height: 50px;
- margin-top: 10px;
- }
- </style>
- <style lang="less">
- .deleteMessage {
- padding: 20px 24px;
- box-shadow: 0px 12px 48px 16px rgba(0, 0, 0, 0.03), 0px 9px 28px 0px rgba(0, 0, 0, 0.05),
- 0px 6px 16px -8px rgba(0, 0, 0, 0.08);
- border-radius: 8px;
- .el-message-box__headerbtn {
- margin-top: 12px;
- margin-right: 12px;
- }
- .el-message-box__title {
- justify-content: start;
- color: rgba(0, 0, 0, 0.88);
- font-size: 16px;
- font-weight: 500;
- }
- .el-message-box__container {
- justify-content: start;
- margin-left: 23px;
- }
- .el-message-box__btns {
- display: block;
- float: right;
- }
- }
- </style>
|