Commit 26881ed0 authored by rockyl's avatar rockyl

节点增加uuid字段

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