|
|
@@ -1,17 +1,17 @@
|
|
|
<template>
|
|
|
<div class="page_switch_tabs">
|
|
|
<!-- 参数配置 -->
|
|
|
- <div class="tab_item" :class="{ active: isParamPage }" @click="goParam(flowKey)">
|
|
|
+ <div class="tab_item" :class="{ active: isParamPage }" @click="goParam">
|
|
|
<span>参数配置</span>
|
|
|
</div>
|
|
|
|
|
|
<!-- 控制页面 -->
|
|
|
- <div class="tab_item" :class="{ active: isControlPage }" @click="goControl(flowKey)">
|
|
|
+ <div class="tab_item" :class="{ active: isControlPage }" @click="goControl">
|
|
|
<span>控制页面</span>
|
|
|
</div>
|
|
|
|
|
|
- <!-- 组态页面(可能有多个:下拉选择) -->
|
|
|
- <el-dropdown trigger="click" @command="onPickConfig" v-if="configList.length > 1">
|
|
|
+ <!-- 组态页面 -->
|
|
|
+ <el-dropdown trigger="click" @command="goConfig" v-if="configList.length > 1">
|
|
|
<div class="tab_item" :class="{ active: isConfiguratePage }">
|
|
|
<span>组态页面</span>
|
|
|
<i class="el-icon-arrow-down" style="font-size:12px"></i>
|
|
|
@@ -24,154 +24,66 @@
|
|
|
</el-dropdown-menu>
|
|
|
</template>
|
|
|
</el-dropdown>
|
|
|
- <div v-else class="tab_item" :class="{ active: isConfiguratePage }" @click="goConfig(flowKey)">
|
|
|
+ <div v-else class="tab_item" :class="{ active: isConfiguratePage }" @click="goConfig()">
|
|
|
<span>组态页面</span>
|
|
|
</div>
|
|
|
|
|
|
- <!-- 装饰性滑块 -->
|
|
|
+ <!-- 滑块 -->
|
|
|
<div class="tab_slider" :style="sliderStyle"></div>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script setup>
|
|
|
-import { computed } from 'vue';
|
|
|
-import { useRouter, useRoute } from 'vue-router';
|
|
|
-//TODO: 数据库新增一张路由映射表,而不是在代码里写死
|
|
|
-/**
|
|
|
- * ① 以 flowKey 为核心的注册表
|
|
|
- * 同一 flowKey 下,收口 control / param / configurates(1~n)
|
|
|
- */
|
|
|
-const FLOW_REGISTRY = {
|
|
|
- reaction: {
|
|
|
- label: '反应分离',
|
|
|
- control: '/controlPage/flowSelect/reaction',
|
|
|
- param: '/controlPage/paramConfiguration/reaction',
|
|
|
- configurates: [
|
|
|
- { label: '反应分离1', code: 'Na2SO4_FY', path: '/configuratePage/Na2SO4_FY' },
|
|
|
- { label: '反应分离2', code: 'Na2SO4_FYFL2', path: '/configuratePage/Na2SO4_FYFL2' },
|
|
|
- ],
|
|
|
- },
|
|
|
- flatBeltFiltration: {
|
|
|
- label: '24平真空过滤',
|
|
|
- control: '/controlPage/flowSelect/flatBeltFiltration',
|
|
|
- param: '/controlPage/paramConfiguration/flatBeltFiltration',
|
|
|
- configurates: [
|
|
|
- { label: '24平真空过滤', code: 'Na2SO4_24PDSGL', path: '/configuratePage/Na2SO4_24PDSGL' },
|
|
|
- ],
|
|
|
- },
|
|
|
- G1Decomposition: {
|
|
|
- label: 'G1分解',
|
|
|
- control: '/controlPage/flowSelect/G1Decomposition',
|
|
|
- param: '/controlPage/paramConfiguration/G1Decomposition',
|
|
|
- configurates: [
|
|
|
- { label: 'G1分解1', code: 'Na2SO4_G1FJ', path: '/configuratePage/Na2SO4_G1FJ' },
|
|
|
- { label: 'G1分解2', code: 'Na2SO4_G1FJ2', path: '/configuratePage/Na2SO4_G1FJ2' },
|
|
|
- ],
|
|
|
- },
|
|
|
- G3Decomposition: {
|
|
|
- label: 'G3分解',
|
|
|
- control: '/controlPage/flowSelect/G3Decomposition',
|
|
|
- param: '/controlPage/paramConfiguration/G3Decomposition',
|
|
|
- configurates: [
|
|
|
- { label: 'G3分解1', code: 'Na2SO4_G3FJ', path: '/configuratePage/Na2SO4_G3FJ' },
|
|
|
- { label: 'G3分解2', code: 'Na2SO4_G3FJ2', path: '/configuratePage/Na2SO4_G3FJ2' },
|
|
|
- ],
|
|
|
- },
|
|
|
-};
|
|
|
+import { computed } from 'vue'
|
|
|
+import { useRouter, useRoute } from 'vue-router'
|
|
|
+import { useFlowStore } from '@/store/modules/useFlowStore'
|
|
|
+import { FLOW_REGISTRY } from '@/utils/flowRouter/flowRegistry'
|
|
|
|
|
|
-// 反查:config code -> flowKey
|
|
|
-const CONFIG_CODE_TO_FLOW_KEY = Object.entries(FLOW_REGISTRY).reduce((m, [fk, v]) => {
|
|
|
- v.configurates.forEach(c => (m[c.code] = fk));
|
|
|
- return m;
|
|
|
-}, {});
|
|
|
+const router = useRouter()
|
|
|
+const route = useRoute()
|
|
|
+const flowStore = useFlowStore()
|
|
|
|
|
|
-const router = useRouter();
|
|
|
-const route = useRoute();
|
|
|
+// 当前 flowKey
|
|
|
+const flowKey = computed(() => flowStore.flowKey)
|
|
|
|
|
|
-/**
|
|
|
- * ② 从任意路由解析 flowKey + 当前页类型
|
|
|
- * - 控制页:/controlPage/flowSelect/:flowKey
|
|
|
- * - 参数页:/controlPage/paramConfiguration/:flowKey
|
|
|
- * - 组态页:/configuratePage/:configCode -> 反查出 flowKey
|
|
|
- */
|
|
|
-const flowKey = computed(() => {
|
|
|
- const segs = route.path.split('/').filter(Boolean);
|
|
|
- console.log(segs);
|
|
|
- if (route.path.startsWith('/controlPage/flowSelect/')) {
|
|
|
- return segs[2]; // .../flowSelect/:flowKey
|
|
|
- }
|
|
|
- if (route.path.startsWith('/controlPage/paramConfiguration/')) {
|
|
|
- return segs[2]; // .../paramConfiguration/:flowKey
|
|
|
- }
|
|
|
- if (route.path.startsWith('/configuratePage/')) {
|
|
|
- const code = segs[1]; // .../configuratePage/:code
|
|
|
- return CONFIG_CODE_TO_FLOW_KEY[code];
|
|
|
- }
|
|
|
- console.warn(`未知路由:${route.path}`);
|
|
|
- return undefined;
|
|
|
-});
|
|
|
-
|
|
|
-const isControlPage = computed(() => route.path.startsWith('/controlPage/flowSelect/'));
|
|
|
-const isParamPage = computed(() => route.path.startsWith('/controlPage/paramConfiguration/'));
|
|
|
-const isConfiguratePage = computed(() => route.path.startsWith('/configuratePage/'));
|
|
|
-
|
|
|
-const activeIndex = computed(() => {
|
|
|
- if (isParamPage.value) return 0;
|
|
|
- if (isControlPage.value) return 1;
|
|
|
- return 2; // 组态页
|
|
|
-});
|
|
|
+// 当前 flow 下的组态候选
|
|
|
+const configList = computed(() => FLOW_REGISTRY[flowKey.value]?.configurates ?? [])
|
|
|
|
|
|
-// 当前 flow 的组态候选
|
|
|
-const configList = computed(() => {
|
|
|
- const fk = flowKey.value;
|
|
|
- if (!fk) return [];
|
|
|
- return FLOW_REGISTRY[fk]?.configurates ?? [];
|
|
|
-});
|
|
|
+// 当前页面类型
|
|
|
+const isControlPage = computed(() => route.path.startsWith('/controlPage/flowSelect/'))
|
|
|
+const isParamPage = computed(() => route.path.startsWith('/controlPage/paramConfiguration/'))
|
|
|
+const isConfiguratePage = computed(() => route.path.startsWith('/configuratePage/'))
|
|
|
|
|
|
-// ③ 最近使用的组态 code(每个 flowKey 记一次)
|
|
|
-const getLastConfigCode = (fk) => localStorage.getItem(`last_config_code_${fk}`) || '';
|
|
|
-const setLastConfigCode = (fk, code) => localStorage.setItem(`last_config_code_${fk}`, code);
|
|
|
-
|
|
|
-const getDefaultConfig = (fk) => {
|
|
|
- const list = FLOW_REGISTRY[fk]?.configurates || [];
|
|
|
- if (!list.length) return undefined;
|
|
|
- const hit = list.find(x => x.code === getLastConfigCode(fk));
|
|
|
- return hit || list[0];
|
|
|
-};
|
|
|
-
|
|
|
-// ④ 跳转函数(任意页 → 其余两类)
|
|
|
-const goControl = (fk) => {
|
|
|
- const path = FLOW_REGISTRY[fk]?.control;
|
|
|
- if (path) router.push(path);
|
|
|
-};
|
|
|
-
|
|
|
-const goParam = (fk) => {
|
|
|
- console.log(fk);
|
|
|
- const path = FLOW_REGISTRY[fk]?.param;
|
|
|
- console.log(path);
|
|
|
- if (path) router.push(path);
|
|
|
-};
|
|
|
-
|
|
|
-const goConfig = (fk, code) => {
|
|
|
- const list = FLOW_REGISTRY[fk]?.configurates || [];
|
|
|
- if (!list.length) return;
|
|
|
- const target = code ? list.find(x => x.code === code) : getDefaultConfig(fk);
|
|
|
+// 滑块位置
|
|
|
+const activeIndex = computed(() => (isParamPage.value ? 0 : isControlPage.value ? 1 : 2))
|
|
|
+const sliderStyle = computed(() => ({
|
|
|
+ transform: `translateX(${activeIndex.value * 100}%)`
|
|
|
+}))
|
|
|
+
|
|
|
+// 跳转函数(同时更新 store + router)
|
|
|
+const goControl = () => {
|
|
|
+ const path = FLOW_REGISTRY[flowKey.value]?.control
|
|
|
+ if (path) {
|
|
|
+ flowStore.setFlowKey(flowKey.value)
|
|
|
+ router.push(path)
|
|
|
+ }
|
|
|
+}
|
|
|
+const goParam = () => {
|
|
|
+ const path = FLOW_REGISTRY[flowKey.value]?.param
|
|
|
+ if (path) {
|
|
|
+ flowStore.setFlowKey(flowKey.value)
|
|
|
+ router.push(path)
|
|
|
+ }
|
|
|
+}
|
|
|
+const goConfig = (code) => {
|
|
|
+ const list = FLOW_REGISTRY[flowKey.value]?.configurates || []
|
|
|
+ if (!list.length) return
|
|
|
+ const target = code ? list.find(x => x.code === code) : list[0]
|
|
|
if (target) {
|
|
|
- setLastConfigCode(fk, target.code);
|
|
|
- router.push(target.path);
|
|
|
+ flowStore.setFlowKey(flowKey.value)
|
|
|
+ router.push(target.path)
|
|
|
}
|
|
|
-};
|
|
|
-
|
|
|
-// 下拉选择具体组态
|
|
|
-const onPickConfig = (code) => {
|
|
|
- if (!flowKey.value) return;
|
|
|
- goConfig(flowKey.value, code);
|
|
|
-};
|
|
|
-
|
|
|
-// ⑤ 滑块样式(3个 Tab)
|
|
|
-const sliderStyle = computed(() => ({
|
|
|
- transform: `translateX(${activeIndex.value * 100}%)`,
|
|
|
-}));
|
|
|
+}
|
|
|
</script>
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
@@ -197,7 +109,6 @@ const sliderStyle = computed(() => ({
|
|
|
transition: color .3s ease;
|
|
|
display: flex;
|
|
|
align-items: center;
|
|
|
- // gap: 8px;
|
|
|
|
|
|
&:hover {
|
|
|
color: #e2e8f0;
|
|
|
@@ -207,10 +118,6 @@ const sliderStyle = computed(() => ({
|
|
|
color: #fff;
|
|
|
font-weight: 500;
|
|
|
}
|
|
|
-
|
|
|
- i {
|
|
|
- font-size: 15px;
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
.tab_slider {
|
|
|
@@ -218,11 +125,9 @@ const sliderStyle = computed(() => ({
|
|
|
top: 3px;
|
|
|
left: 3px;
|
|
|
width: calc(33.333% - 3px);
|
|
|
- /* 由 50% 改为三等分 */
|
|
|
height: calc(100% - 6px);
|
|
|
background-color: #0ea5e9;
|
|
|
border-radius: 6px;
|
|
|
transition: transform .3s cubic-bezier(0.34, 1.56, 0.64, 1);
|
|
|
- box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
|
|
}
|
|
|
</style>
|