fix: #310 keep loading animation bug is related to cytoscape undefined bug. And cytoscape node position remembering feature is not actually finished correctly yet before. Now remembering feature is done.
This commit is contained in:
@@ -1,11 +1,33 @@
|
||||
import { el } from 'date-fns/locale';
|
||||
import { defineStore } from 'pinia';
|
||||
|
||||
import { SAVE_KEY_NAME } from '@/constants/constants.js';
|
||||
|
||||
// nodePositions 結構 {
|
||||
// graphId: [{
|
||||
// id,
|
||||
// position: {
|
||||
// x,
|
||||
// y,
|
||||
// }
|
||||
// }]
|
||||
// }
|
||||
interface Position {
|
||||
x: number;
|
||||
y: number;
|
||||
}
|
||||
|
||||
interface Node {
|
||||
id: string;
|
||||
position: Position;
|
||||
}
|
||||
|
||||
interface NodePositions {
|
||||
[graphId: string]: Node[];
|
||||
}
|
||||
|
||||
export default defineStore('useCytoscapeStore', {
|
||||
state: () => ({
|
||||
nodePositions: {},
|
||||
nodePositions: {} as NodePositions,
|
||||
currentGraphId: "",
|
||||
}),
|
||||
actions: {
|
||||
@@ -14,16 +36,23 @@ export default defineStore('useCytoscapeStore', {
|
||||
* @param {string} id
|
||||
* @param {object} position {x, y} position有兩個值,x與y
|
||||
*/
|
||||
saveNodePosition(nodeId, position) {
|
||||
saveNodePosition(nodeId: string, position: NodePosition) {
|
||||
// 若是資訊曾經存在這張圖於localStorage中
|
||||
if (localStorage.getItem(SAVE_KEY_NAME) && JSON.parse(localStorage.getItem(SAVE_KEY_NAME))[this.currentGraphId]) {
|
||||
console.log('saveNodePosition ---- this.nodePositions[this.currentGraphId]',this.nodePositions[this.currentGraphId] );
|
||||
const nodeToSave = this.nodePositions[this.currentGraphId].find(node => node.id === nodeId);
|
||||
if(nodeToSave) {
|
||||
nodeToSave.position = position;
|
||||
} else {
|
||||
console.log('aaaa this.nodePositions[this.currentGraphId]',this.nodePositions[this.currentGraphId] );
|
||||
this.nodePositions[this.currentGraphId].push({id: nodeId, position: position});
|
||||
}
|
||||
} else {
|
||||
this.nodePositions[this.currentGraphId] = [];
|
||||
this.nodePositions[this.currentGraphId].push({id: nodeId, position: position});
|
||||
localStorage.setItem(SAVE_KEY_NAME, JSON.stringify(this.nodePositions));
|
||||
}
|
||||
console.log('', );
|
||||
this.savePositionsToStorage();
|
||||
},
|
||||
/**
|
||||
@@ -40,9 +69,9 @@ export default defineStore('useCytoscapeStore', {
|
||||
savePositionsToStorage() {
|
||||
localStorage.setItem(SAVE_KEY_NAME, JSON.stringify(this.nodePositions));
|
||||
},
|
||||
setCurrentGraphId(currentGraphId) {
|
||||
setCurrentGraphId(currentGraphId: string) {
|
||||
this.currentGraphId = currentGraphId;
|
||||
this.nodePositions[currentGraphId] = [];
|
||||
this.nodePositions = {[this.currentGraphId]: []};
|
||||
},
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user