Commit d6843bc5 authored by rockyl's avatar rockyl

包管理修改

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