diff --git a/src/views/workbench/index.vue b/src/views/workbench/index.vue index 32c1d6b..ea63bac 100644 --- a/src/views/workbench/index.vue +++ b/src/views/workbench/index.vue @@ -76,7 +76,7 @@ @@ -90,6 +90,7 @@ import * as echarts from 'echarts' import resize from '@/views/dashboard/mixins/resize' import { getHomeOverview, getHomeTodoWarning, getHomeTrendLatest } from '@/api/analysis/home' +import { listHazardLedger } from '@/api/hazard/ledger' export default { name: 'Workbench', @@ -101,7 +102,9 @@ export default { overview: {}, warning: {}, trendList: [], - latestReports: [] + latestReports: [], + // 最新上报接口不含 canApprove;用隐患待办列表补齐 id→canApprove。null 表示未就绪/加载失败,此时退回「仅按状态」判断 + approveMap: null } }, computed: { @@ -150,6 +153,7 @@ export default { const trend = (trendRes && trendRes.data) || {} this.trendList = Array.isArray(trend.trend7d) ? trend.trend7d : [] this.latestReports = Array.isArray(trend.latestReports) ? trend.latestReports : [] + this.loadApproveMap() this.$nextTick(this.renderChart) }) .catch(() => { @@ -157,12 +161,35 @@ export default { this.warning = {} this.trendList = [] this.latestReports = [] + this.approveMap = null this.$modal.msgError('工作台数据加载失败,请检查后端服务和登录状态') }) .finally(() => { this.loading = false }) }, + // 最新上报接口未返回 canApprove,改用隐患待办列表(与台账同一数据源,按创建时间倒序)建立 id→canApprove 映射,用于收敛「审核」入口 + loadApproveMap() { + return listHazardLedger({ pageNum: 1, pageSize: 30 }) + .then(response => { + const page = response.data || response + const rows = page.list || page.rows || page.records || [] + if (!rows.length) { + this.approveMap = null + return + } + const map = {} + rows.forEach(item => { + if (item && item.id !== undefined && item.id !== null) { + map[String(item.id)] = item.canApprove === true || String(item.canApprove) === 'true' + } + }) + this.approveMap = map + }) + .catch(() => { + this.approveMap = null + }) + }, renderChart() { const el = this.$refs.trendChart if (!el) return @@ -209,10 +236,17 @@ export default { if (row.route) this.$router.push(row.route) }, isReviewing(row) { - // 最新上报数据未含 canApprove,这里按状态收敛:仅“审核中”才显示审核入口。 + // 仅「审核中」状态 const value = String(row.status || '').toLowerCase() return value === 'reviewing' || value === '1' || /审核中|待审核/.test(row.statusName || '') }, + // 最新上报需要「审核中 且 当前用户可审批」才显示审核入口;canApprove 由 approveMap 补齐 + canAudit(row) { + if (!this.isReviewing(row)) return false + if (!this.approveMap) return true + const key = row.id === undefined || row.id === null ? '' : String(row.id) + return this.approveMap[key] === true + }, goAudit(row) { if (row.id === undefined || row.id === null) { this.$modal.msgWarning('该记录缺少主键,无法进入审核')