logic-helper
Version:
This template should help get you started developing with Vue 3 in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.
76 lines (74 loc) • 1.8 kB
JavaScript
/**
* App.vue中初始化
*/
import {
markRaw,
watchEffect,
toRaw,
computed
} from 'vue';
import {
useTopo
} from '@/store/topo/index.js';
import {
useStorage
} from '@/store/storage/index.js';
import {
useController
} from '@/store/controller/index.js';
import {
useDirectory
} from '@/store/directory/index.js';
import router from '@/router/index.js';
import {
useRoute
} from 'vue-router';
import {
handler
} from '@/utils/eventHandler.js';
import ws from '@/ws/index.js';
/**
* 逻辑中介者
*/
class Mediator {
storage = null;
topo = null;
router = null;
route = null;
model = null;
controller = null;
setModel(model){
this.model = model;
}
init() {
//App.vue 初始化
this.storage = useStorage();
this.dir = useDirectory();
this.storage.init();
this.topo = useTopo();
this.controller = useController();
this.router = router;
this.route = this.route || useRoute();
this.handler = handler;
this.ws = ws;
this.init = () => Promise.resolve(this);
watchEffect(() => {
const { file, name } = store.route.params;
if (file) {
const topos = this.storage.findToposByGroup(file.replace(/-/g,'/'));
topos.forEach(item => {
if (item.config.name == name) {
this.storage.focus(item.config.id);
if(this.storage.currentTopo){
this.topo.init(this.storage.currentTopo);
}
}
})
}
}, {
immediate: true
})
return this;
}
}
export const store = new Mediator();