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.
97 lines (94 loc) • 2.29 kB
JavaScript
import {
defineStore
} from 'pinia';
import {
store
} from '@/common/js/app.js'
import {
markRaw,
shallowReactive
} from 'vue';
class Log {
constructor() {
this.log = [];
this.max = 10000;
}
add(data) {
if (!this.log) {
this.log = markRaw([]);
}
this.log = [...this.log, ...data.log];
if (this.log.length > this.max) {
this.log = this.log.slice(this.log.length - this.max);
}
}
get() {
return this.log || [];
}
init(){
this.log = markRaw([]);
}
}
export const useController = defineStore({
id: 'topo-controller', // id必填,且需要唯一
state: () => {
return {
currentTopo: null,
logs: new Log(),
mode: 'info',
showAllNodes: false,
logCode: '',
breakPoints: {},
editable: true,
};
},
persist:{
enabled: true,
strategies:[
{
storage: sessionStorage,
paths: ['mode','showAllNodes','breakPoints']
}
],
},
actions: {
setBreakPoints(key){
const path = store.route.path;
this.breakPoints[path] = this.breakPoints[path]||{};
this.breakPoints[path][key]=this.breakPoints[path][key]==undefined?true:!this.breakPoints[path][key];
},
setMode(mode){
this.mode = mode;
},
setShowNodes(show=true){
this.showAllNodes = show;
},
getConfig() {
return this.$state
},
init(currentTopo) {
this.currentTopo = currentTopo;
},
setLogCode(code){
this.logCode = code;
this.logs.init();
},
initLog(code) {
console.log(code,'initLog>>>>')
if(this.logCode===code){
this.mode = 'test'
this.logs.init();
}
},
addLog(data) {
if(this.logCode===data.code){
this.logs.add(markRaw(data));
}
}
},
getters: {
getBreakPoints(state){
return state.breakPoints[store.route.path]||{};
}
}
});