Commit 26881ed0 authored by rockyl's avatar rockyl

节点增加uuid字段

parent 10674cff
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
*/ */
import Vue from "vue"; import Vue from "vue";
import { projectApi } from "../../api"; import {projectApi} from "../../api";
import { compoleteComponentData } from '../../utils/compoleteCmpData'; import {compoleteComponentData} from '../../utils/compoleteCmpData';
import path from "path"; import path from "path";
import generateUUID from "uuid/v4"; import generateUUID from "uuid/v4";
...@@ -27,14 +27,14 @@ export const projectStore = { ...@@ -27,14 +27,14 @@ export const projectStore = {
state.dirty = dirty; state.dirty = dirty;
}, },
updateProject(state, project) { updateProject(state, project) {
const { id, name, creator, data } = project; const {id, name, creator, data} = project;
state.id = id; state.id = id;
state.name = name; state.name = name;
state.creator = creator; state.creator = creator;
const localData = state.data; const localData = state.data;
if (data) { if (data) {
const { views, assets, dataMapping } = JSON.parse(data); const {views, assets, dataMapping} = JSON.parse(data);
if (!localData.views || localData.views.length === 0) { if (!localData.views || localData.views.length === 0) {
Vue.set(localData, 'views', views || []); Vue.set(localData, 'views', views || []);
} }
...@@ -44,7 +44,7 @@ export const projectStore = { ...@@ -44,7 +44,7 @@ export const projectStore = {
if (!localData.dataMapping || localData.dataMapping.length === 0) { if (!localData.dataMapping || localData.dataMapping.length === 0) {
Vue.set(localData, 'dataMapping', dataMapping || []); Vue.set(localData, 'dataMapping', dataMapping || []);
} }
}else{ } else {
Vue.set(localData, 'views', []); Vue.set(localData, 'views', []);
Vue.set(localData, 'assets', []); Vue.set(localData, 'assets', []);
Vue.set(localData, 'dataMapping', []); Vue.set(localData, 'dataMapping', []);
...@@ -53,8 +53,8 @@ export const projectStore = { ...@@ -53,8 +53,8 @@ export const projectStore = {
}, },
/** /**
* 激活组件 * 激活组件
* @param {*} state * @param {*} state
* @param {*} id * @param {*} id
*/ */
activeComponent(state, item) { activeComponent(state, item) {
// todo drag // todo drag
...@@ -70,13 +70,14 @@ export const projectStore = { ...@@ -70,13 +70,14 @@ export const projectStore = {
// state.activeIdList = [id]; // state.activeIdList = [id];
console.log('mutations activeComponent', state); console.log('mutations activeComponent', state);
}, },
modifyProject(state, ) { modifyProject(state,) {
}, },
addNode(state, { node, name, type }) { addNode(state, {node, name, type}) {
const child = { const child = {
name, name,
type, type,
uuid: generateUUID(),
}; };
if (node) { if (node) {
if (!node.children) { if (!node.children) {
...@@ -87,12 +88,12 @@ export const projectStore = { ...@@ -87,12 +88,12 @@ export const projectStore = {
state.data.views.push(child); state.data.views.push(child);
} }
}, },
deleteNode(state, { node, parentNode }) { deleteNode(state, {node, parentNode}) {
const index = parentNode.children.indexOf(node); const index = parentNode.children.indexOf(node);
parentNode.children.splice(index, 1); parentNode.children.splice(index, 1);
}, },
addAsset(state, { url, file }) { addAsset(state, {url, file}) {
const ext = path.extname(file.name); const ext = path.extname(file.name);
state.data.assets.push({ state.data.assets.push({
name: path.basename(file.name, ext), name: path.basename(file.name, ext),
...@@ -102,7 +103,7 @@ export const projectStore = { ...@@ -102,7 +103,7 @@ export const projectStore = {
}) })
}, },
deleteAsset(state, uuid) { deleteAsset(state, uuid) {
const { assets } = state.data; const {assets} = state.data;
for (let i = 0, li = assets.length; i < li; i++) { for (let i = 0, li = assets.length; i < li; i++) {
const asset = state.data.assets[i]; const asset = state.data.assets[i];
if (asset.uuid === uuid) { if (asset.uuid === uuid) {
...@@ -136,7 +137,7 @@ export const projectStore = { ...@@ -136,7 +137,7 @@ export const projectStore = {
}, },
getters: { getters: {
project(state) { project(state) {
const { id, name, creator, data } = state; const {id, name, creator, data} = state;
return { return {
id, name, creator, id, name, creator,
data: JSON.stringify(data), data: JSON.stringify(data),
...@@ -179,17 +180,17 @@ export const projectStore = { ...@@ -179,17 +180,17 @@ export const projectStore = {
} }
}, },
actions: { actions: {
saveToLocal({ getters, commit }) { saveToLocal({getters, commit}) {
const { project } = getters; const {project} = getters;
localStorage.setItem('project-' + project.id, JSON.stringify(project)); localStorage.setItem('project-' + project.id, JSON.stringify(project));
commit('setDirty', true); commit('setDirty', true);
}, },
localVersionExist({ commit }, projectID) { localVersionExist({commit}, projectID) {
let json = localStorage.getItem('project-' + projectID); let json = localStorage.getItem('project-' + projectID);
return !!json; return !!json;
}, },
loadFromLocal({ commit }, projectID) { loadFromLocal({commit}, projectID) {
let json = localStorage.getItem('project-' + projectID); let json = localStorage.getItem('project-' + projectID);
if (json) { if (json) {
const project = JSON.parse(json); const project = JSON.parse(json);
...@@ -197,11 +198,11 @@ export const projectStore = { ...@@ -197,11 +198,11 @@ export const projectStore = {
commit('setDirty', true); commit('setDirty', true);
} }
}, },
deleteLocalVersion({ state, commit }, projectID) { deleteLocalVersion({state, commit}, projectID) {
localStorage.removeItem('project-' + projectID); localStorage.removeItem('project-' + projectID);
commit('setDirty', false); commit('setDirty', false);
}, },
async loadFromRemote({ commit, dispatch }, projectID) { async loadFromRemote({commit, dispatch}, projectID) {
const project = await projectApi.fetchOne(projectID); const project = await projectApi.fetchOne(projectID);
if (project) { if (project) {
dispatch('deleteLocalVersion', projectID); dispatch('deleteLocalVersion', projectID);
...@@ -210,20 +211,20 @@ export const projectStore = { ...@@ -210,20 +211,20 @@ export const projectStore = {
throw new Error('Project does not exist') throw new Error('Project does not exist')
} }
}, },
async saveToRemote({ state, dispatch, getters }) { async saveToRemote({state, dispatch, getters}) {
await projectApi.saveOne(getters.project); await projectApi.saveOne(getters.project);
dispatch('deleteLocalVersion', state.id); dispatch('deleteLocalVersion', state.id);
}, },
async updateProject({ commit }, projectID) { async updateProject({commit}, projectID) {
const project = await projectApi.getData(projectID); const project = await projectApi.getData(projectID);
commit('updateProject', project); commit('updateProject', project);
}, },
/** /**
* 选中节点 * 选中节点
* @param {*} param0 * @param {*} param0
* @param {*} data * @param {*} data
*/ */
activeComponent({ commit }, data) { activeComponent({commit}, data) {
console.log('actions activeComponent', data); console.log('actions activeComponent', data);
commit('activeComponent', data); commit('activeComponent', data);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment