Commit f05589e1 authored by rockyl's avatar rockyl

去掉压缩

parent d53c7757
......@@ -24,11 +24,8 @@ class ApiError extends Error {
}
}
export async function fetchApi(uri, {params, method = 'get', auth = true, judgeSuccess = true, contentType = 'json', errMessage} = {
method: 'get',
contentType: 'json'
}) {
let url = uri.startsWith('http') || uri.startsWith('//') ? uri : API_HOST + uri;
export async function fetchApi(uri, {host = '', params, method = 'get', auth = true, judgeSuccess = true, contentType = 'json', dataField = 'data', errMessage}) {
let url = host + (uri.startsWith('http') || uri.startsWith('//') ? uri : API_HOST + uri);
const options = {
method,
......@@ -77,7 +74,7 @@ export async function fetchApi(uri, {params, method = 'get', auth = true, judgeS
if (judgeSuccess) {
if (jsonObj.success) {
return jsonObj.data;
return jsonObj[dataField];
}
} else {
return jsonObj;
......
......@@ -63,7 +63,7 @@ export async function fetchHistory(id, currentPage, pageSize) {
}
export async function saveOne(project, remark) {
project.remark = remark
project.remark = remark;
return await fetchApi('/api/project/update', {
params: project,
method: 'post',
......
......@@ -6,7 +6,7 @@ export let API_HOST;
if (process.env.NODE_ENV === 'development') {
//API_HOST = '//10.10.95.74:7777';
//API_HOST = '//192.168.1.16:7777';
//API_HOST = '//10.10.93.88:7777';
//API_HOST = '//10.10.94.107:3000';
//API_HOST = '//192.168.0.105:7777';
//API_HOST = '//localhost:3002';
//API_HOST = window.__data.apiHost;
......
......@@ -23,5 +23,10 @@ export default new Router({
name: 'preview',
component: () => import('./views/Preview.vue')
},
{
path: '/diff',
name: 'diff',
component: () => import('./views/ProjectDiff.vue')
},
]
})
......@@ -7,7 +7,15 @@ import {editorApi, projectApi} from "../../api"
import path from "path"
import generateUUID from "uuid/v4"
import {flattenViews, getCmpByUUID, getCmpProps} from '../../utils/common'
import {assetScheme, clonePureObj, findProcess, getMockServeEnabled, saveAs, traverseViewNode} from "../../utils"
import {
assetScheme,
clonePureObj, deleteAssetsDepConfig,
deleteDesignConfig,
findProcess,
getMockServeEnabled,
saveAs,
traverseViewNode
} from "../../utils"
import {template} from "../../template"
import events from "@/global-events"
import {packImages} from "../../utils/sheet-pack"
......@@ -20,7 +28,6 @@ import {fetchApi} from "../../api/common"
import {toZeroing} from "psd-parse-web"
import {arrayFind} from "element-ui/src/utils/util";
const storeName = 'project';
const psStoreName = 'pack-history';
......@@ -47,47 +54,6 @@ const defaultOptions = {
const OPERATE_MAX_LENGTH = 200; // 撤销重做栈最大值
function getDefaultOptions() {
return clonePureObj(defaultOptions)
}
function setUUIDForAllChildren(node) {
if (node.children && node.children.length > 0) {
for (let i = 0; i < node.children.length; i++) {
node.children[i] = copyBaseRoot(node.children[i]);
setUUIDForAllChildren(node.children[i])
}
}
}
let copyNodeCatch = null;
function copyBaseRoot(node) {
let _node = JSON.parse(JSON.stringify(node));
let data;
if (_node.children && _node.children.length > 0) {
data = {
name: _node.name,
type: _node.type,
properties: _node.properties,
events: _node.events,
uuid: generateUUID(),
children: _node.children
};
} else {
data = {
name: _node.name,
type: _node.type,
properties: _node.properties,
events: _node.events,
uuid: generateUUID(),
};
}
return data
}
export const projectStore = {
modules: {
package: packageStore,
......@@ -378,8 +344,7 @@ export const projectStore = {
parentChildren.splice(index, 1);
},
copyNode(state, {node, parentNode,copyState}) {
copyNode(state, {node, parentNode, copyState}) {
let _node1 = node;
console.log(_node1)
copyNodeCatch =clonePureObj(_node1)
......@@ -501,9 +466,12 @@ export const projectStore = {
getters: {
project(state) {
const {id, name, creator, data} = state;
let newData = clonePureObj(data);
deleteDesignConfig(newData.processes);
deleteAssetsDepConfig(newData);
return {
id, name, creator,
data: JSON.stringify(data),
data: JSON.stringify(newData),
};
},
menuBadge: (state) => (key) => {
......@@ -621,7 +589,7 @@ export const projectStore = {
},
actions: {
async saveToLocal({getters, commit}) {
const {project} = getters;
const project = getters.project;
await db.set(storeName, {id: project.id, data: JSON.stringify(project)});
//localStorage.setItem('project-' + project.id, JSON.stringify(project));
......@@ -860,7 +828,7 @@ export const projectStore = {
await db.remove(psStoreName, id);
},
savePreview({state, rootState, getters}) {
const {project} = getters;
const project = getters.project;
const packages = state.package.packages;
/*const data = {
......@@ -870,7 +838,7 @@ export const projectStore = {
localStorage.setItem('preview-project-' + project.id, JSON.stringify(data));
localStorage.setItem('preview-ts', Date.now().toString());*/
preprocess(project, state.data, clonePureObj(packages));
preprocess(project, clonePureObj(packages));
},
addBehaviorDirect({state}, {behaviors, alias}) {
......@@ -960,3 +928,45 @@ export async function updateMock(mocks) {
db.set('mock', mock);
}
}
function getDefaultOptions() {
return clonePureObj(defaultOptions)
}
function setUUIDForAllChildren(node) {
if (node.children && node.children.length > 0) {
for (let i = 0; i < node.children.length; i++) {
node.children[i] = copyBaseRoot(node.children[i]);
setUUIDForAllChildren(node.children[i])
}
}
}
let copyNodeCatch = null;
function copyBaseRoot(node) {
let _node = JSON.parse(JSON.stringify(node));
let data;
if (_node.children && _node.children.length > 0) {
data = {
name: _node.name,
type: _node.type,
properties: _node.properties,
events: _node.events,
uuid: generateUUID(),
children: _node.children
};
} else {
data = {
name: _node.name,
type: _node.type,
properties: _node.properties,
events: _node.events,
uuid: generateUUID(),
};
}
return data
}
......@@ -93,6 +93,9 @@ export function guid() {
* @param parent
*/
export function traverseViewNode(nodes, callback, parent) {
if (!nodes) {
return;
}
for (let node of nodes) {
callback(node, parent);
if (node.children && node.children.length > 0) {
......@@ -400,3 +403,24 @@ export function getViewNodePath(node, sep = '/') {
export function timeFormat(time, format = 'YYYY-MM-DD HH:mm:ss') {
return moment(time).format(format)
}
export function deleteDesignConfig(processes) {
for (let process of processes) {
if (process.sub) {
for (let key in process.sub) {
let p = process.sub[key];
delete p.design['input'];
delete p.design['output'];
}
}
if (process.metas) {
deleteDesignConfig(process.metas);
}
}
}
export function deleteAssetsDepConfig(data) {
for (let asset of data.assets) {
delete asset['dep'];
}
}
......@@ -24,9 +24,9 @@ function getPackages(packages) {
}
}
export async function preprocess(project, data, packages) {
let newData = clonePureObj(data);
const codes = await divideCode(newData, {
export async function preprocess(project, packages) {
let data = JSON.parse(project.data);
const codes = await divideCode(data, {
debug: true,
getPackages: getPackages(packages),
dependencies: data.dependencies,
......@@ -50,7 +50,7 @@ export async function preprocess(project, data, packages) {
scripts.push(newScriptContent('var proxy_mode=true;'));
codesCache = codes;
const dataUrl = URL.createObjectURL(new Blob([JSON.stringify(newData)]));
const dataUrl = URL.createObjectURL(new Blob([JSON.stringify(data)]));
const {libraryScriptElMap, analyseResult} = await generateLibraryScriptEl(tpl, dependencies, getPackages(packages), '//yun.duiba.com.cn/editor/zeroing/libs/');
......@@ -65,7 +65,7 @@ export async function preprocess(project, data, packages) {
db.set(storeName, {
id: project.id,
data: newData,
data,
tpl,
});
localStorage.setItem('preview-ts', Date.now().toString());
......
<template>
<monaco-editor
class="script-editor"
ref="editor"
v-model="code"
language="json"
:options="monacoEditorOptions"
diff-editor
:original="originalCode"
/>
</template>
<script>
import MonacoEditor from "vue-monaco";
import {monacoEditorOptions} from "../utils";
//import old from './old.json'
//let originalCode = JSON.stringify(old, null, '\t');
let originalCode = `hello`;
console.log(originalCode);
export default {
name: "ProjectDiff",
components: {MonacoEditor},
data() {
return {
monacoEditorOptions,
code: '',
originalCode,
}
},
mounted() {
let editor = this.$refs.editor.getEditor();
editor.onDidUpdateDiff(()=>{
let m = editor.getLineChanges();
console.log(m);
})
}
}
</script>
<style scoped>
.script-editor{
width: 100%;
}
</style>
\ No newline at end of file
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