wangjuncheng
2025-05-19 f5688d9765782bbb97b3abb8ee99fe7b9834a149
src/store/simulation.js
@@ -1,9 +1,13 @@
// stores/ui.js
import { defineStore } from 'pinia'
import { ref } from 'vue'
import { createSimData } from '@/api/trApi'
export const useSimStore = defineStore('ui', () => {
    // 所有UI状态
export const useSimStore = defineStore('simulation', () => {
    // 隐患点列表
    const DeviceShowSwitch = ref(true)
    const DangerShowSwitch = ref(true)
    const DangerPoint = ref([])
    const navigationShow = ref(true)
    const leftShow = ref(false)
    const rightShow = ref(false)
@@ -24,8 +28,18 @@
    const showLayerTree = ref(true)
    const showDangerAssess = ref(false)
    const schemCard = ref([])
    const backToHome = ref(false)
    const selectedScheme = ref(null)
    const rainFalls = ref()
    const setSelectedScheme = (scheme) => {
        selectedScheme.value = scheme
        rainFalls.value = JSON.parse(scheme.data).rainfalls
        console.log(rainFalls.value, 'shceme')
    }
    const clearSelectedScheme = () => {
        selectedScheme.value = null
    }
    // 初始化方法
    const init = () => {
        navigationShow.value = true
        leftShow.value = false
@@ -37,6 +51,7 @@
        locationShow.value = false
        tableShow.value = false
        flowShow.value = false
        backToHome.value = false
        rightRiverShow.value = false
        showPreview.value = false
        deviceShow.value = false
@@ -44,31 +59,25 @@
        showDangerAssess.value = false
        schemCard.value = []
    }
    // 方案相关
    const setSchemCard = (data) => {
        schemCard.value = data
        console.log(schemCard,'aaaaaaaaaaaaaa');
    }
    // 添加单个方案数据
    const addSchemCardItem = (item) => {
        schemCard.value.push(item)
    const addSchemCard = (item) => {
        schemCard.value.unshift(item)
    }
    // 删除指定方案数据
    const removeSchemCardItem = (id) => {
        schemCard.value = schemCard.value.filter(item => item.id !== id)
    }
    // 更新指定方案数据
    const updateSchemCardItem = (id, newData) => {
        const index = schemCard.value.findIndex(item => item.id === id)
        if (index !== -1) {
            schemCard.value[index] = { ...schemCard.value[index], ...newData }
        }
    }
    const startYHGL = () => {
        init()
@@ -84,13 +93,17 @@
    const startMNFZ = () => {
        init()
        leftShow.value = true
        rightRiverShow.value = true
        // rightRiverShow.value = true
    }
    const startMNPG = () => {
        init()
        showResultAssess.value = true
        showDangerAssess.value = true
        // showResultAssess.value = true
        // showDangerAssess.value = true
    }
    const setBackToHome = (value) => {
        backToHome.value = value
    }
    // 导航点击
@@ -110,7 +123,9 @@
                break
        }
    }
    return {
        // UI 状态
        navigationShow,
        leftShow,
        rightShow,
@@ -130,16 +145,31 @@
        showResultAssess,
        showLayerTree,
        showDangerAssess,
        handleNavClick,
        schemCard,
        backToHome,
        rainFalls,
        DangerPoint,
        DeviceShowSwitch,
        DangerShowSwitch,
        // 方案相关方法
        setSchemCard,
        addSchemCard,
        removeSchemCardItem,
        updateSchemCardItem,
        setBackToHome,
        // ✅ 暴露 selectedScheme 及其方法
        selectedScheme,          // 响应式引用
        setSelectedScheme,      // 方法
        clearSelectedScheme,    // 方法
        // 控制逻辑
        init,
        startYHGL,
        startZHJC,
        startMNFZ,
        startMNPG,
        schemCard,
        setSchemCard,
        addSchemCardItem,
        removeSchemCardItem,
        updateSchemCardItem,
        handleNavClick,
    }
})