|
|
@@ -13,7 +13,7 @@
|
|
|
<span class="fx-corner fx-corner--br"></span>
|
|
|
</div>
|
|
|
|
|
|
- <!-- 页面标题:与 HR 首页同款(光翼 + 六边形辉光边框),查询范围挂在标题右侧 -->
|
|
|
+ <!-- 页面标题:与 HR 首页同款(光翼 + 六边形辉光边框);查询档位已迁到下方检索行 -->
|
|
|
<header class="overview-title" aria-label="企业运营看板">
|
|
|
<div class="overview-title__wing overview-title__wing--left">
|
|
|
<i></i><i></i><i></i>
|
|
|
@@ -29,20 +29,6 @@
|
|
|
<div class="overview-title__wing overview-title__wing--right">
|
|
|
<i></i><i></i><i></i>
|
|
|
</div>
|
|
|
- <div class="scope">
|
|
|
- <span class="label">查询范围:</span>
|
|
|
- <div class="seg">
|
|
|
- <button
|
|
|
- v-for="item in scopeOptions"
|
|
|
- :key="item.value"
|
|
|
- type="button"
|
|
|
- :class="{ on: scope === item.value }"
|
|
|
- @click="changeScope(item.value)"
|
|
|
- >
|
|
|
- {{ item.label }}
|
|
|
- </button>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
<!-- 全屏按钮:HR 同款(纯图标),全屏对象是页面根元素而不是整个系统页面 -->
|
|
|
<button
|
|
|
type="button"
|
|
|
@@ -53,6 +39,19 @@
|
|
|
<i :class="isBoardFullscreen ? 'el-icon-copy-document' : 'el-icon-full-screen'"></i>
|
|
|
</button>
|
|
|
</header>
|
|
|
+
|
|
|
+ <!-- 检索行:公司/集团 → 部门 → 查询档位 → 自定义区间 → 刷新 -->
|
|
|
+ <board-filters
|
|
|
+ :value="filters"
|
|
|
+ :company-options="companyOptions"
|
|
|
+ :dept-options="deptOptions"
|
|
|
+ :refreshing="refreshing"
|
|
|
+ :fallback-hint="fallbackHintVisible"
|
|
|
+ :board-fullscreen="isBoardFullscreen"
|
|
|
+ @change="handleFilterChange"
|
|
|
+ @refresh="loadHome(true)"
|
|
|
+ />
|
|
|
+
|
|
|
<kpi-cards
|
|
|
:kpis="kpis"
|
|
|
:scope="scope"
|
|
|
@@ -91,25 +90,56 @@
|
|
|
|
|
|
<script>
|
|
|
import { getDashboardHome } from '@/api/eos/dashboard';
|
|
|
+ import { listOrganizations } from '@/api/system/organization';
|
|
|
+ import { getCurrentUser } from '@/utils/token-util';
|
|
|
+ import boardFilters from './components/boardFilters.vue';
|
|
|
import kpiCards from './components/kpiCards.vue';
|
|
|
import trendCharts from './components/trendCharts.vue';
|
|
|
import revenueDonut from './components/revenueDonut.vue';
|
|
|
import riskAlertCard from './components/riskAlertCard.vue';
|
|
|
import summaryCards from './components/summaryCards.vue';
|
|
|
+ import {
|
|
|
+ buildOrgIndex,
|
|
|
+ departmentOptions,
|
|
|
+ resolveDefaultSelection,
|
|
|
+ buildOrgFilterParams,
|
|
|
+ hasValue
|
|
|
+ } from './org-index';
|
|
|
|
|
|
// M01 下钻明细弹窗按需加载:只有用户点开时才拉这一份 chunk,首页首屏包体不因此膨胀
|
|
|
const revenueDetailDialog = () => import('./components/revenueDetailDialog.vue');
|
|
|
|
|
|
export default {
|
|
|
- components: { kpiCards, trendCharts, revenueDonut, riskAlertCard, summaryCards, revenueDetailDialog },
|
|
|
+ components: {
|
|
|
+ boardFilters,
|
|
|
+ kpiCards,
|
|
|
+ trendCharts,
|
|
|
+ revenueDonut,
|
|
|
+ riskAlertCard,
|
|
|
+ summaryCards,
|
|
|
+ revenueDetailDialog
|
|
|
+ },
|
|
|
+ // 三处明细弹窗(M01 / M17~M20)要跟首页卡片同口径:弹窗由卡片组件挂载,故用 provide 下发。
|
|
|
+ // filters 对象本身不整体替换(只改字段),注入方每次读取拿到的都是最新筛选
|
|
|
+ provide() {
|
|
|
+ return { eosBoardFilters: this.filters };
|
|
|
+ },
|
|
|
data() {
|
|
|
return {
|
|
|
- scope: 'MONTH',
|
|
|
- scopeOptions: [
|
|
|
- { value: 'YEAR', label: '年度' },
|
|
|
- { value: 'QUARTER', label: '本季度' },
|
|
|
- { value: 'MONTH', label: '本月(默认)' }
|
|
|
- ],
|
|
|
+ // 唯一筛选源:档位 + 组织维度 + 自定义区间(空值保持 undefined,绝不下发空串)
|
|
|
+ filters: {
|
|
|
+ scope: 'MONTH',
|
|
|
+ companyId: undefined,
|
|
|
+ deptId: undefined,
|
|
|
+ startDate: undefined,
|
|
|
+ endDate: undefined
|
|
|
+ },
|
|
|
+ // 组织树内存索引(一次性拉全量,切公司不额外发组织请求)
|
|
|
+ orgIndex: null,
|
|
|
+ // 默认本部门解析失败(按全部部门出数时给弱提示)
|
|
|
+ orgUnmatched: false,
|
|
|
+ // 已解析过默认值的登录组织 id:顶栏组织未真的变化时不重复查询
|
|
|
+ resolvedGroupId: null,
|
|
|
loading: false,
|
|
|
scopeRangeText: '',
|
|
|
dataTime: '',
|
|
|
@@ -124,12 +154,39 @@
|
|
|
// 预警卡刷新中:驱动刷新按钮旋转与置灰
|
|
|
refreshing: false,
|
|
|
// M01 下钻明细弹窗:v-if 控制挂载,配合异步组件实现按需加载
|
|
|
- revenueDetailVisible: false
|
|
|
+ revenueDetailVisible: false,
|
|
|
+ // 请求序号:并发响应只让最新那一次落地(旧响应直接丢弃,不写数据与 loading)
|
|
|
+ loadSeq: 0
|
|
|
};
|
|
|
},
|
|
|
- computed: {},
|
|
|
+ computed: {
|
|
|
+ // 档位对外仍以 scope 暴露,卡片组件的 props 契约不变
|
|
|
+ scope() {
|
|
|
+ return this.filters.scope || 'MONTH';
|
|
|
+ },
|
|
|
+ // 公司/集团下拉选项(集团 + 公司,停用项已过滤)
|
|
|
+ companyOptions() {
|
|
|
+ return this.orgIndex ? this.orgIndex.companies : [];
|
|
|
+ },
|
|
|
+ // 部门下拉选项:所选公司子树里的部门/工厂(内存级联,不发请求)
|
|
|
+ deptOptions() {
|
|
|
+ return departmentOptions(this.orgIndex, this.filters.companyId);
|
|
|
+ },
|
|
|
+ // 弱提示只在「默认本部门没解析到」且用户尚未自行选择组织时出现
|
|
|
+ fallbackHintVisible() {
|
|
|
+ return (
|
|
|
+ this.orgUnmatched && !hasValue(this.filters.companyId) && !hasValue(this.filters.deptId)
|
|
|
+ );
|
|
|
+ }
|
|
|
+ },
|
|
|
+ watch: {
|
|
|
+ // 顶栏切换组织后跟随:重跑默认值解析并重查(info 变化但组织未变时由 resolvedGroupId 拦住)
|
|
|
+ '$store.state.user.info'() {
|
|
|
+ this.handleLoginOrgChange();
|
|
|
+ }
|
|
|
+ },
|
|
|
mounted() {
|
|
|
- this.loadHome();
|
|
|
+ this.initBoard();
|
|
|
// 全屏状态同步:用户按 ESC 退出时按钮图标要跟着变
|
|
|
this.onFullscreenChange = this.handleBoardFullscreenChange;
|
|
|
document.addEventListener('fullscreenchange', this.onFullscreenChange);
|
|
|
@@ -140,6 +197,76 @@
|
|
|
document.removeEventListener('webkitfullscreenchange', this.onFullscreenChange);
|
|
|
},
|
|
|
methods: {
|
|
|
+ /**
|
|
|
+ * 首屏:先拉组织树 → 解析默认本部门 → 只发 1 次看板请求
|
|
|
+ * 组织树失败不阻断(initOrgIndex 内部兜底为全部部门)
|
|
|
+ */
|
|
|
+ async initBoard() {
|
|
|
+ await this.initOrgIndex();
|
|
|
+ this.applyDefaultFilters();
|
|
|
+ await this.loadHome();
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 组织树:一次性拉全量后建内存索引
|
|
|
+ * 失败处理:console.warn 后按全部部门出数,页面不阻断、不白屏
|
|
|
+ */
|
|
|
+ async initOrgIndex() {
|
|
|
+ try {
|
|
|
+ const list = await listOrganizations();
|
|
|
+ this.orgIndex = buildOrgIndex(list);
|
|
|
+ console.info('[eos-dashboard] 组织树加载完成', {
|
|
|
+ 节点数: this.orgIndex.total,
|
|
|
+ 公司数: this.orgIndex.companies.length
|
|
|
+ });
|
|
|
+ } catch (e) {
|
|
|
+ this.orgIndex = null;
|
|
|
+ console.warn('[eos-dashboard] 组织树加载失败,按全部部门出数', {
|
|
|
+ error: e && e.message
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 登录组织 id:拿不到就当没有(退到全部部门),不抛错打断首屏
|
|
|
+ readCurrentGroupId() {
|
|
|
+ try {
|
|
|
+ const user = getCurrentUser() || {};
|
|
|
+ return user.currentGroupId;
|
|
|
+ } catch (e) {
|
|
|
+ console.warn('[eos-dashboard] 读取登录组织失败', { error: e && e.message });
|
|
|
+ return undefined;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 默认值:本部门 + 其所属公司;解析不到本部门退到公司一级;连公司也没有则全部部门
|
|
|
+ * 只改 companyId / deptId,用户已选的档位与自定义区间保持不动
|
|
|
+ */
|
|
|
+ applyDefaultFilters() {
|
|
|
+ const currentGroupId = this.readCurrentGroupId();
|
|
|
+ const resolved = resolveDefaultSelection(this.orgIndex, currentGroupId);
|
|
|
+ this.orgUnmatched = !resolved.matched;
|
|
|
+ this.resolvedGroupId = hasValue(currentGroupId) ? currentGroupId : null;
|
|
|
+ this.filters.companyId = resolved.companyId;
|
|
|
+ this.filters.deptId = resolved.deptId;
|
|
|
+ console.info('[eos-dashboard] 默认筛选解析', {
|
|
|
+ currentGroupId: hasValue(currentGroupId) ? currentGroupId : '',
|
|
|
+ companyId: hasValue(resolved.companyId) ? resolved.companyId : '',
|
|
|
+ deptId: hasValue(resolved.deptId) ? resolved.deptId : '',
|
|
|
+ matched: resolved.matched
|
|
|
+ });
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 首页请求体:{ scope, companyId, deptId, startDate, endDate }
|
|
|
+ * companyId / deptId 为空时键不出现(undefined 不参与 JSON 序列化);区间两端都有值才带
|
|
|
+ */
|
|
|
+ buildQuery() {
|
|
|
+ const f = this.filters || {};
|
|
|
+ const query = { scope: f.scope || 'MONTH' };
|
|
|
+ Object.assign(query, buildOrgFilterParams(f));
|
|
|
+ if (hasValue(f.startDate) && hasValue(f.endDate)) {
|
|
|
+ query.startDate = f.startDate;
|
|
|
+ query.endDate = f.endDate;
|
|
|
+ }
|
|
|
+ return query;
|
|
|
+ },
|
|
|
getBoardFullscreenElement() {
|
|
|
return document.fullscreenElement || document.webkitFullscreenElement || null;
|
|
|
},
|
|
|
@@ -172,34 +299,78 @@
|
|
|
});
|
|
|
},
|
|
|
async loadHome(silent) {
|
|
|
+ // 请求序号:并发时旧响应回来直接丢弃,既不写数据也不动 loading / refreshing
|
|
|
+ const seq = (this.loadSeq += 1);
|
|
|
if (!silent) {
|
|
|
this.loading = true;
|
|
|
}
|
|
|
// 刷新按钮点击走 silent 分支,这里同步按钮的旋转/置灰状态
|
|
|
this.refreshing = true;
|
|
|
- const scope = this.scope;
|
|
|
+ const query = this.buildQuery();
|
|
|
const startedAt = Date.now();
|
|
|
- console.info('[eos-dashboard] 加载看板', { scope, 上次区间: this.scopeRangeText });
|
|
|
+ console.info('[eos-dashboard] 加载看板', Object.assign({}, query, { 上次区间: this.scopeRangeText }));
|
|
|
try {
|
|
|
- const data = await getDashboardHome(scope);
|
|
|
+ const data = await getDashboardHome(query);
|
|
|
+ if (seq !== this.loadSeq) {
|
|
|
+ console.info('[eos-dashboard] 丢弃过期响应', { seq, 最新序号: this.loadSeq });
|
|
|
+ return;
|
|
|
+ }
|
|
|
this.applyData(data);
|
|
|
if (silent) {
|
|
|
this.$message.success(`预警数据已刷新(${((Date.now() - startedAt) / 1000).toFixed(1)}s)`);
|
|
|
}
|
|
|
console.info('[eos-dashboard] 加载完成', {
|
|
|
- scope,
|
|
|
+ scope: query.scope,
|
|
|
区间: this.scopeRangeText,
|
|
|
耗时: Date.now() - startedAt
|
|
|
});
|
|
|
} catch (e) {
|
|
|
+ if (seq !== this.loadSeq) {
|
|
|
+ console.info('[eos-dashboard] 丢弃过期失败响应', { seq, 最新序号: this.loadSeq });
|
|
|
+ return;
|
|
|
+ }
|
|
|
this.applyData(null);
|
|
|
- console.error('[eos-dashboard] 加载失败', { scope, error: e });
|
|
|
+ console.error('[eos-dashboard] 加载失败', { scope: query.scope, error: e });
|
|
|
this.$message.error(`看板数据加载失败:${this.errorText(e)}`);
|
|
|
} finally {
|
|
|
- this.loading = false;
|
|
|
- this.refreshing = false;
|
|
|
+ // 序号不一致说明已有更新的请求在跑,loading / refreshing 交给它收尾
|
|
|
+ if (seq === this.loadSeq) {
|
|
|
+ this.loading = false;
|
|
|
+ this.refreshing = false;
|
|
|
+ }
|
|
|
}
|
|
|
},
|
|
|
+ /**
|
|
|
+ * 检索行变化 → 落库到 filters → 只发 1 次查询
|
|
|
+ * 切公司时 boardFilters 已在同一份载荷里清空 deptId,这里一次性写入,不会二次查询
|
|
|
+ */
|
|
|
+ handleFilterChange(next) {
|
|
|
+ const merged = {
|
|
|
+ scope: (next && next.scope) || 'MONTH',
|
|
|
+ companyId: next ? next.companyId : undefined,
|
|
|
+ deptId: next ? next.deptId : undefined,
|
|
|
+ startDate: next ? next.startDate : undefined,
|
|
|
+ endDate: next ? next.endDate : undefined
|
|
|
+ };
|
|
|
+ Object.keys(merged).forEach((key) => {
|
|
|
+ this.filters[key] = merged[key];
|
|
|
+ });
|
|
|
+ console.info('[eos-dashboard] 筛选条件变化', this.buildQuery());
|
|
|
+ this.loadHome();
|
|
|
+ },
|
|
|
+ // 顶栏切换组织($store.state.user.info 变化)→ 重解析默认值并重查
|
|
|
+ async handleLoginOrgChange() {
|
|
|
+ const currentGroupId = this.readCurrentGroupId();
|
|
|
+ if (String(currentGroupId) === String(this.resolvedGroupId)) {
|
|
|
+ // 首屏 info 填充 / 角色切换等并未改变登录组织:不重复查询
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ console.info('[eos-dashboard] 登录组织变化,重解析默认筛选', {
|
|
|
+ currentGroupId: hasValue(currentGroupId) ? currentGroupId : ''
|
|
|
+ });
|
|
|
+ this.applyDefaultFilters();
|
|
|
+ await this.loadHome();
|
|
|
+ },
|
|
|
// 后端业务提示为中文,axios 自身异常(Network Error 等)统一替换为中文兜底
|
|
|
errorText(e) {
|
|
|
const message = e && e.message;
|
|
|
@@ -218,16 +389,8 @@
|
|
|
},
|
|
|
// M01 卡片点击 → 打开明细弹窗(其余 5 张卡仍走原有菜单下钻)
|
|
|
openRevenueDetail() {
|
|
|
- console.info('[eos-dashboard] 打开 M01 营业收入下钻明细', { scope: this.scope });
|
|
|
+ console.info('[eos-dashboard] 打开 M01 营业收入下钻明细', this.buildQuery());
|
|
|
this.revenueDetailVisible = true;
|
|
|
- },
|
|
|
- changeScope(scope) {
|
|
|
- if (this.scope === scope || this.loading) {
|
|
|
- return;
|
|
|
- }
|
|
|
- console.info('[eos-dashboard] 切换查询档位', { from: this.scope, to: scope });
|
|
|
- this.scope = scope;
|
|
|
- this.loadHome();
|
|
|
}
|
|
|
}
|
|
|
};
|