Commit d6843bc5 authored by rockyl's avatar rockyl

包管理修改

parent acdb6949
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
import Vue from 'vue' import Vue from 'vue'
import Vuex from 'vuex' import Vuex from 'vuex'
import {envStore} from "./modules/env"; import {editorStore} from "./modules/editor";
import {projectsStore} from "./modules/projects"; import {projectsStore} from "./modules/projects";
import {projectStore} from "./modules/project"; import {projectStore} from "./modules/project";
import SaveToLocalPlugin from "./save-to-local-plugin"; import SaveToLocalPlugin from "./save-to-local-plugin";
...@@ -21,7 +21,7 @@ export default new Vuex.Store({ ...@@ -21,7 +21,7 @@ export default new Vuex.Store({
}, },
modules: { modules: {
env: envStore, editor: editorStore,
projects: projectsStore, projects: projectsStore,
project: projectStore, project: projectStore,
behavior: behaviorStore, behavior: behaviorStore,
......
...@@ -9,7 +9,7 @@ import i18n from "../../i18n"; ...@@ -9,7 +9,7 @@ import i18n from "../../i18n";
const storeKey = 'code-sync-serve-config'; const storeKey = 'code-sync-serve-config';
export const envStore = { export const editorStore = {
state: { state: {
initialized: false, initialized: false,
name: 'Zeroing Editor', name: 'Zeroing Editor',
...@@ -18,9 +18,6 @@ export const envStore = { ...@@ -18,9 +18,6 @@ export const envStore = {
builtin: ['blank'], builtin: ['blank'],
custom: [], custom: [],
}, },
processes: [],
scripts: [],
customs: [],
codeSyncServeConfig: { codeSyncServeConfig: {
ip: 'localhost', ip: 'localhost',
port: 7788, port: 7788,
...@@ -29,9 +26,6 @@ export const envStore = { ...@@ -29,9 +26,6 @@ export const envStore = {
mutations: { mutations: {
updateEnv(state, env) { updateEnv(state, env) {
Object.assign(state, env); Object.assign(state, env);
state.processes = parseItem(state.processes);
state.scripts = parseItem(state.scripts);
state.customs = parseItem(state.customs);
state.initialized = true; state.initialized = true;
...@@ -111,18 +105,3 @@ function groupProcesses(processes, filterFunc) { ...@@ -111,18 +105,3 @@ function groupProcesses(processes, filterFunc) {
}); });
return result; return result;
} }
function parseItem(list) {
let hasError, result = [];
for (let i = 0, li = list.length; i < li; i++) {
try {
result.push(JSON.parse(list[i].data));
} catch (e) {
hasError = true;
}
}
if (hasError) {
console.warn('parse env error');
}
return result;
}
import db from "../../utils/db-storage";
/**
* Created by rockyl on 2020-01-04.
*/
export const packagesStore = {
state: {},
actions: {
async loadPackages({state, commit}, id) {
let packages = await db.get('packages', id);
commit('updatePackages', packages);
},
},
};
...@@ -16,6 +16,7 @@ import {addBehavior, deleteProcessMeta, findProcess} from "./behavior"; ...@@ -16,6 +16,7 @@ import {addBehavior, deleteProcessMeta, findProcess} from "./behavior";
import db from "../../utils/db-storage"; import db from "../../utils/db-storage";
import {preprocess} from "../../views/Preview/preview-preprocess"; import {preprocess} from "../../views/Preview/preview-preprocess";
import {packagesStore} from "./packages";
const storeName = 'project'; const storeName = 'project';
...@@ -79,6 +80,9 @@ function copyBaseRoot(node) { ...@@ -79,6 +80,9 @@ function copyBaseRoot(node) {
} }
export const projectStore = { export const projectStore = {
modules: {
packages: packagesStore,
},
state: { state: {
id: '', id: '',
name: '', name: '',
...@@ -102,7 +106,6 @@ export const projectStore = { ...@@ -102,7 +106,6 @@ export const projectStore = {
dirty: false, dirty: false,
operateStack: [], operateStack: [],
stackIndex: 0, stackIndex: 0,
packages: {},
}, },
mutations: { mutations: {
setDirty(state, dirty = true) { setDirty(state, dirty = true) {
...@@ -110,6 +113,13 @@ export const projectStore = { ...@@ -110,6 +113,13 @@ export const projectStore = {
}, },
makeDirty() { makeDirty() {
},
updatePackages(state, packages) {
state.packages = packages ? JSON.parse(packages) : {
processes: [],
customs: [],
scripts: [],
};
}, },
updateProject(state, project) { updateProject(state, project) {
const {id, name, creator, data} = project; const {id, name, creator, data} = project;
...@@ -526,7 +536,8 @@ export const projectStore = { ...@@ -526,7 +536,8 @@ export const projectStore = {
//let json = localStorage.getItem('project-' + projectID); //let json = localStorage.getItem('project-' + projectID);
return !!json; return !!json;
}, },
async loadFromLocal({commit}, projectID) { async loadFromLocal({commit, dispatch}, projectID) {
await dispatch('loadPackages', projectID);
let json = await db.get(storeName, projectID); let json = await db.get(storeName, projectID);
//let json = localStorage.getItem('project-' + projectID); //let json = localStorage.getItem('project-' + projectID);
if (json) { if (json) {
...@@ -541,6 +552,7 @@ export const projectStore = { ...@@ -541,6 +552,7 @@ export const projectStore = {
commit('setDirty', false); commit('setDirty', false);
}, },
async loadFromRemote({commit, dispatch}, projectID) { async loadFromRemote({commit, dispatch}, projectID) {
await dispatch('loadPackages', projectID);
const project = await projectApi.fetchOne(projectID); const project = await projectApi.fetchOne(projectID);
if (project) { if (project) {
dispatch('deleteLocalVersion', projectID); dispatch('deleteLocalVersion', projectID);
...@@ -550,6 +562,7 @@ export const projectStore = { ...@@ -550,6 +562,7 @@ export const projectStore = {
} }
}, },
async loadFromDataUrl({commit, dispatch}, {project, dataUrl}) { async loadFromDataUrl({commit, dispatch}, {project, dataUrl}) {
await dispatch('loadPackages', project.id);
const projectData = await projectApi.fetchOneFromDataUrl(dataUrl); const projectData = await projectApi.fetchOneFromDataUrl(dataUrl);
if (projectData) { if (projectData) {
project.data = projectData; project.data = projectData;
...@@ -567,13 +580,11 @@ export const projectStore = { ...@@ -567,13 +580,11 @@ export const projectStore = {
const project = await projectApi.getData(projectID); const project = await projectApi.getData(projectID);
commit('updateProject', project); commit('updateProject', project);
}, },
async loadPackages({state, commit}) {
let packages = await db.get('packages', state.id);
},
async resolveDependencies({state}) { async resolveDependencies({state}) {
for (let key in state.data.dependencies) { for (let key in state.data.dependencies) {
let version = state.data.dependencies[key]; let version = state.data.dependencies[key];
} }
}, },
...@@ -718,7 +729,7 @@ export const projectStore = { ...@@ -718,7 +729,7 @@ export const projectStore = {
savePreview({state, rootState, getters}) { savePreview({state, rootState, getters}) {
const {project} = getters; const {project} = getters;
const {processes, scripts, customs} = rootState.env; const {processes, scripts, customs} = rootstate.editor;
/*const data = { /*const data = {
processes, scripts, customs, processes, scripts, customs,
data: state.data, data: state.data,
...@@ -806,3 +817,18 @@ export async function updateMock(mocks) { ...@@ -806,3 +817,18 @@ export async function updateMock(mocks) {
db.set('mock', mock); db.set('mock', mock);
} }
} }
function parseItem(list) {
let hasError, result = [];
for (let i = 0, li = list.length; i < li; i++) {
try {
result.push(JSON.parse(list[i].data));
} catch (e) {
hasError = true;
}
}
if (hasError) {
console.warn('parse env error');
}
return result;
}
...@@ -73,7 +73,7 @@ ...@@ -73,7 +73,7 @@
computed: { computed: {
...mapState({ ...mapState({
codeSyncServeConfig(state) { codeSyncServeConfig(state) {
return state.env.codeSyncServeConfig; return state.editor.codeSyncServeConfig;
}, },
}), }),
}, },
...@@ -309,6 +309,7 @@ ...@@ -309,6 +309,7 @@
}, 300); }, 300);
}, },
...mapActions([ ...mapActions([
'loadPackages',
'localVersionExist', 'localVersionExist',
'loadFromLocal', 'loadFromLocal',
'loadFromRemote', 'loadFromRemote',
......
...@@ -79,7 +79,7 @@ export default { ...@@ -79,7 +79,7 @@ export default {
...mapGetters(['activeComponent', 'activeComponentCopy', 'componentList']), ...mapGetters(['activeComponent', 'activeComponentCopy', 'componentList']),
...mapState({ ...mapState({
scripts(state){ scripts(state){
return state.env.scripts; return state.editor.scripts;
} }
}), }),
}, },
......
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
computed: { computed: {
...mapState({ ...mapState({
codeSyncServeConfig(state) { codeSyncServeConfig(state) {
return state.env.codeSyncServeConfig; return state.editor.codeSyncServeConfig;
} }
}) })
}, },
......
...@@ -68,8 +68,8 @@ ...@@ -68,8 +68,8 @@
computed: { computed: {
...mapState({ ...mapState({
customs(state) { customs(state) {
console.log(state.env.customs); console.log(state.editor.customs);
return state.env.customs; return state.editor.customs;
}, },
}), }),
...mapGetters([ ...mapGetters([
......
...@@ -63,7 +63,7 @@ ...@@ -63,7 +63,7 @@
edit() { edit() {
this.editData = clonePureObj(this.customs); this.editData = clonePureObj(this.customs);
this.customMetas.splice(0); this.customMetas.splice(0);
for (let meta of this.$store.state.env.customs) { for (let meta of this.$store.state.editor.customs) {
let data = this.editData.find(item => item.id === meta.id); let data = this.editData.find(item => item.id === meta.id);
this.customMetas.push({ this.customMetas.push({
id: meta.id, id: meta.id,
......
<template> <template>
<div class="home"> <div class="home">
<div class="editor-name" style="font-weight: bold">{{env.name}} <div class="editor-name" style="font-weight: bold">{{editor.name}}
<span class="editor-version">{{env.version}}</span> <span class="editor-version">{{editor.version}}</span>
</div> </div>
<main> <main>
<div class="project-list"> <div class="project-list">
...@@ -110,7 +110,7 @@ ...@@ -110,7 +110,7 @@
}, },
...mapState([ ...mapState([
'projects', 'projects',
'env', 'editor',
]), ]),
}, },
watch: { watch: {
......
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