Commit 4be75099 authored by rockyl's avatar rockyl

修改上传文件使用自己实现

增加上传指示器
parent 1ccf415c
...@@ -61,12 +61,27 @@ export async function pack(id) { ...@@ -61,12 +61,27 @@ export async function pack(id) {
} }
export async function importView(file) { export async function importView(file) {
return await fetchApi('/api/parsePSD', { const response = await fetchApi('/api/parsePSD', {
params: { params: {
file, file,
}, },
method: 'post', method: 'post',
contentType: 'form-data', contentType: 'form-data',
errMessage: 'Failed to import view', errMessage: 'Failed to import view',
}) });
response.__originFile = file;
return response;
}
export async function uploadFile(file) {
const response = await fetchApi('/api/uploadFile', {
params: {
file,
},
method: 'post',
contentType: 'form-data',
errMessage: 'Failed to upload file',
});
response.__originFile = file;
return response;
} }
...@@ -7,8 +7,8 @@ if (process.env.NODE_ENV === 'development') { ...@@ -7,8 +7,8 @@ if (process.env.NODE_ENV === 'development') {
//API_HOST = 'http://10.10.95.74:7777'; //API_HOST = 'http://10.10.95.74:7777';
//API_HOST = 'http://10.10.94.134:7777'; //API_HOST = 'http://10.10.94.134:7777';
//API_HOST = 'http://localhost:3002'; //API_HOST = 'http://localhost:3002';
//API_HOST = window.__data.apiHost; API_HOST = window.__data.apiHost;
API_HOST = ''; //API_HOST = '';
} else { } else {
API_HOST = window.__data.apiHost; API_HOST = window.__data.apiHost;
} }
...@@ -17,9 +17,6 @@ if (API_HOST[API_HOST.length - 1] === '/') { ...@@ -17,9 +17,6 @@ if (API_HOST[API_HOST.length - 1] === '/') {
API_HOST = API_HOST.substr(0, API_HOST.length - 1); API_HOST = API_HOST.substr(0, API_HOST.length - 1);
} }
export const UPLOAD_FILE_URL = API_HOST + '/api/uploadFile';
export const PARSE_BUNDLE_URL = API_HOST + '/api/parsePSD';
export const SSO_VERIFY_PAGE_URL = '/sso/logout'; export const SSO_VERIFY_PAGE_URL = '/sso/logout';
export const DOCK_POINT_OFFSET = 4; export const DOCK_POINT_OFFSET = 4;
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
"Import": "Import", "Import": "Import",
"Export": "Export", "Export": "Export",
"Upload": "Upload", "Upload": "Upload",
"Uploading": "Uploading",
"Edit": "Edit", "Edit": "Edit",
"EditEnv": "EditEnv", "EditEnv": "EditEnv",
"EditCustomModule": "EditCustomModule", "EditCustomModule": "EditCustomModule",
...@@ -119,10 +120,12 @@ ...@@ -119,10 +120,12 @@
"Divider node desc": "Divider node, exit will be executed in sequence", "Divider node desc": "Divider node, exit will be executed in sequence",
"Save this behavior before": "Save this behavior before?", "Save this behavior before": "Save this behavior before?",
"Failed to import view": "Failed to import view", "Failed to import view": "Failed to import view",
"Failed to upload file": "Failed to upload file",
"Single view": "Single view", "Single view": "Single view",
"Multi views": "Multi views", "Multi views": "Multi views",
"Import single": "Import single", "Import single": "Import single",
"Import multi": "Import multi", "Import multi": "Import multi",
"Import view success": "Import view success",
"menu": { "menu": {
"save": "Save", "save": "Save",
"details": "Details", "details": "Details",
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
"Import": "导入", "Import": "导入",
"Export": "导出", "Export": "导出",
"Upload": "上传", "Upload": "上传",
"Uploading": "上传中",
"Edit": "编辑", "Edit": "编辑",
"EditEnv": "编辑环境", "EditEnv": "编辑环境",
"EditCustomModule": "编辑自定义模块", "EditCustomModule": "编辑自定义模块",
...@@ -119,10 +120,12 @@ ...@@ -119,10 +120,12 @@
"Divider node desc": "分流节点,出口会按顺序一次执行", "Divider node desc": "分流节点,出口会按顺序一次执行",
"Save this behavior before": "是否先保存这个行为?", "Save this behavior before": "是否先保存这个行为?",
"Failed to import view": "导入视图失败", "Failed to import view": "导入视图失败",
"Failed to upload file": "上传文件失败",
"Single view": "单视图", "Single view": "单视图",
"Multi views": "多视图", "Multi views": "多视图",
"Import single": "导入单", "Import single": "导入单",
"Import multi": "导入多", "Import multi": "导入多",
"Import view success": "视图导入成功",
"menu": { "menu": {
"save": "保存", "save": "保存",
"details": "详情", "details": "详情",
......
...@@ -9,7 +9,8 @@ import generateUUID from "uuid/v4"; ...@@ -9,7 +9,8 @@ import generateUUID from "uuid/v4";
import {getCmpProps, flattenViews, getCmpByUUID} from '../../utils/common'; import {getCmpProps, flattenViews, getCmpByUUID} from '../../utils/common';
import {clonePureObj, saveAs} from "../../utils"; import {clonePureObj, saveAs} from "../../utils";
import {template} from "../../template"; import {template} from "../../template";
import {importView} from "../../api/project"; import {importView, uploadFile} from "../../api/project";
import events from "@/global-events";
const defaultOptions = { const defaultOptions = {
pageTitle: 'no title', pageTitle: 'no title',
...@@ -569,10 +570,37 @@ export const projectStore = { ...@@ -569,10 +570,37 @@ export const projectStore = {
saveAs(content, `view-${view.name}.zrv`); saveAs(content, `view-${view.name}.zrv`);
}); });
}, },
async uploadFiles({commit}, files) {
const failedList = [];
let ps = [];
for (let file of files) {
events.$emit('upload-indicator', true);
ps.push(
uploadFile(file).catch(e => {
}).finally(() => {
events.$emit('upload-indicator', false);
})
);
}
const result = await Promise.all(ps);
for (let item of result) {
const {url, __originFile} = item;
commit('addAsset', {url, file: __originFile});
}
/*for (let file of files) {
try {
const {url} = await uploadFile(file);
commit('addAsset', {url, file});
}catch (e) {
failedList.push(file);
}
events.$emit('upload-indicator', false);
}*/
return failedList;
},
async packProject({state}) { async packProject({state}) {
const result = await projectApi.pack(state.id); const result = await projectApi.pack(state.id);
console.log(result) console.log(result);
return result; return result;
} }
}, },
......
...@@ -25,6 +25,10 @@ ...@@ -25,6 +25,10 @@
} }
} }
.file-upload-indicator{
color: $--color-text-secondary;
}
.right-part { .right-part {
color: $--color-text-regular; color: $--color-text-regular;
line-height: 15px; line-height: 15px;
......
...@@ -109,11 +109,17 @@ export function readTextFile(file) { ...@@ -109,11 +109,17 @@ export function readTextFile(file) {
}) })
} }
export function selectFile(callback){ export function selectFile(callback, {accept, multiple} = {}) {
let input = document.createElement('input'); let input = document.createElement('input');
input.type = 'file'; input.type = 'file';
input.onchange = function(e){ input.onchange = function (e) {
callback(input.files); callback(input.files);
}; };
if (accept) {
input.accept = accept;
}
if (multiple) {
input.multiple = true;
}
input.click(); input.click();
} }
...@@ -23,18 +23,9 @@ ...@@ -23,18 +23,9 @@
<el-scrollbar class="assets-scrollbar" wrap-class="wrap-x-hidden" <el-scrollbar class="assets-scrollbar" wrap-class="wrap-x-hidden"
view-class="scrollbar-view"> view-class="scrollbar-view">
<div class="file-list"> <div class="file-list">
<el-upload <div class="file-uploader" @click="toUploadFile">
class="file-uploader"
:action="uploadFileUrl"
name="file"
:headers="uploadHeaders"
multiple
:show-file-list="false"
:on-success="uploadFileSuccess"
:on-error="uploadFileError"
>
<i class="el-icon-plus file-uploader-icon"></i> <i class="el-icon-plus file-uploader-icon"></i>
</el-upload> </div>
<file-item v-for="(asset, index) in assets" :data="asset" :key="index" @show-file-details="showFileDetails" <file-item v-for="(asset, index) in assets" :data="asset" :key="index" @show-file-details="showFileDetails"
@click="onItemClick(asset)"/> @click="onItemClick(asset)"/>
</div> </div>
...@@ -46,12 +37,12 @@ ...@@ -46,12 +37,12 @@
</template> </template>
<script> <script>
import {mapState, mapMutations} from 'vuex' import {mapState, mapMutations, mapActions} from 'vuex'
import Pane from "../../components/Pane"; import Pane from "../../components/Pane";
import FileItem from "./Assets/FileItem"; import FileItem from "./Assets/FileItem";
import AssetsShow from "./Assets/AssetsShow"; import AssetsShow from "./Assets/AssetsShow";
import {UPLOAD_FILE_URL} from "../../config";
import SplitPanes from 'splitpanes' import SplitPanes from 'splitpanes'
import {selectFile} from "../../utils";
export default { export default {
name: "Assets", name: "Assets",
...@@ -66,9 +57,6 @@ ...@@ -66,9 +57,6 @@
} }
}, },
computed: { computed: {
uploadFileUrl() {
return UPLOAD_FILE_URL;
},
...mapState({ ...mapState({
assets: state => state.project.data.assets assets: state => state.project.data.assets
}), }),
...@@ -77,27 +65,18 @@ ...@@ -77,27 +65,18 @@
this.currentItem = null; this.currentItem = null;
}, },
methods: { methods: {
toUploadFile() {
selectFile((files) => {
this.uploadFiles(files);
}, {multiple: true})
},
showFileDetails(file) { showFileDetails(file) {
this.$refs.assetsShow.show(file); this.$refs.assetsShow.show(file);
}, },
onItemClick(asset) { onItemClick(asset) {
this.currentItem = asset; this.currentItem = asset;
}, },
uploadFileSuccess(response, file) { deleteAll() {
if (response.success) {
//console.log('upload success', response, file);
this.addAsset({
url: response.url,
file,
})
} else {
this.uploadFileError();
}
},
uploadFileError() {
console.log('upload error')
},
deleteAll(){
this.$confirm(this.$t('Are you sure to delete all assets'), this.$t('Alert'), { this.$confirm(this.$t('Are you sure to delete all assets'), this.$t('Alert'), {
confirmButtonText: this.$t('Confirm'), confirmButtonText: this.$t('Confirm'),
cancelButtonText: this.$t('Cancel'), cancelButtonText: this.$t('Cancel'),
...@@ -108,9 +87,11 @@ ...@@ -108,9 +87,11 @@
}); });
}, },
...mapMutations([ ...mapMutations([
'addAsset',
'deleteAllAssets', 'deleteAllAssets',
]), ]),
...mapActions([
'uploadFiles',
]),
} }
} }
</script> </script>
......
<template> <template>
<div class="tool-bar"> <div class="tool-bar">
<sample-menu :data="menu" @click-menu="clickMenu"/> <sample-menu :data="menu" @click-menu="clickMenu"/>
<upload-indicator/>
<div style="flex: 1"></div>
<div class="right-part"> <div class="right-part">
<span> <span>
[{{project.name}}] [{{project.name}}]
...@@ -13,10 +15,11 @@ ...@@ -13,10 +15,11 @@
<script> <script>
import {mapState, mapActions, mapMutations} from 'vuex' import {mapState, mapActions, mapMutations} from 'vuex'
import SampleMenu from "../../components/SampleMenu"; import SampleMenu from "../../components/SampleMenu";
import UploadIndicator from "./ToolBar/UploadIndicator";
export default { export default {
name: "ToolBar", name: "ToolBar",
components: {SampleMenu}, components: {UploadIndicator, SampleMenu},
data() { data() {
return {} return {}
}, },
...@@ -24,7 +27,7 @@ ...@@ -24,7 +27,7 @@
...mapState([ ...mapState([
'project' 'project'
]), ]),
menu: function() { menu: function () {
const menuConfig = this.$t('menu'); const menuConfig = this.$t('menu');
let menu = {}; let menu = {};
for (let item of Object.keys(menuConfig)) { for (let item of Object.keys(menuConfig)) {
...@@ -43,7 +46,7 @@ ...@@ -43,7 +46,7 @@
clickMenu(menuItem) { clickMenu(menuItem) {
this.$emit('click-menu', menuItem); this.$emit('click-menu', menuItem);
}, },
editProjectName(){ editProjectName() {
this.$prompt(this.$t('Input project name'), this.$t('Rename project'), { this.$prompt(this.$t('Input project name'), this.$t('Rename project'), {
inputValue: this.project.name, inputValue: this.project.name,
confirmButtonText: this.$t('Confirm'), confirmButtonText: this.$t('Confirm'),
......
<template>
<div v-if="counting > 0" class="file-upload-indicator">
{{$t('Uploading')}}({{counting}})
<i class="el-icon-loading"></i>
</div>
</template>
<script>
import events from "../../../global-events";
export default {
name: "UploadIndicator",
data() {
return {
counting: 0,
}
},
mounted() {
events.$on('upload-indicator', this.onUploadIndicator);
},
destroyed() {
events.$off('upload-indicator', this.onUploadIndicator);
},
methods: {
onUploadIndicator(show) {
this.counting += show ? 1 : -1;
},
}
}
</script>
<style scoped>
</style>
\ No newline at end of file
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
@node-click="handleNodeClick" @node-click="handleNodeClick"
empty-text="" empty-text=""
:allow-drag="allowDrag" :allow-drag="allowDrag"
:allow-drop="allowDrop"
> >
<div slot-scope="{ node, data }" class="tree-node"> <div slot-scope="{ node, data }" class="tree-node">
<div class="node-name"> <div class="node-name">
...@@ -54,8 +55,8 @@ ...@@ -54,8 +55,8 @@
<script> <script>
import {mapState, mapMutations, mapActions} from 'vuex'; import {mapState, mapMutations, mapActions} from 'vuex';
import Pane from '../../components/Pane'; import Pane from '../../components/Pane';
import {PARSE_BUNDLE_URL} from '../../config';
import {selectFile} from "../../utils"; import {selectFile} from "../../utils";
import events from "../../global-events";
export default { export default {
name: 'Views', name: 'Views',
...@@ -72,9 +73,6 @@ ...@@ -72,9 +73,6 @@
}; };
}, },
computed: { computed: {
importFileUrl() {
return PARSE_BUNDLE_URL;
},
...mapState({ ...mapState({
views: state => state.project.data.views views: state => state.project.data.views
}) })
...@@ -83,6 +81,10 @@ ...@@ -83,6 +81,10 @@
allowDrag(draggingNode) { allowDrag(draggingNode) {
return draggingNode.parent.parent; return draggingNode.parent.parent;
}, },
allowDrop(draggingNode, dropNode, type) {
//console.log(dropNode.parent.parent, type);
return dropNode.parent.parent || type === 'inner';
},
/** /**
* 点击左侧视图列表 * 点击左侧视图列表
*/ */
...@@ -106,11 +108,16 @@ ...@@ -106,11 +108,16 @@
}); });
}, },
toImport(action) { toImport(action) {
selectFile(files => { selectFile(async files => {
this.importView({ events.$emit('upload-indicator', true);
try {
await this.importView({
file: files[0], file: files[0],
action, action,
}); });
} catch (e) {
}
events.$emit('upload-indicator', false);
}) })
}, },
onImportCommand(command) { onImportCommand(command) {
...@@ -148,36 +155,6 @@ ...@@ -148,36 +155,6 @@
break; break;
} }
}, },
uploadFileSuccess(response, file) {
if (response.success) {
console.log('upload success', response);
const {view, assets} = response.data;
switch (this.uploadAction) {
case 0: //单视图
view.name = file.name.substring(0, file.name.lastIndexOf('.'));
this.importView(view);
break;
case 1: //多视图
for (let subView of view) {
this.importView(subView);
}
break;
}
this.importAssets(assets);
} else {
this.uploadFileError();
}
},
uploadFileError() {
console.log('upload error');
this.$message({
message: this.$t('Upload view failed'),
type: 'error',
duration: 1000,
});
},
...mapMutations(['deleteNode', 'addNode']), ...mapMutations(['deleteNode', 'addNode']),
...mapActions(['exportView', 'importView']) ...mapActions(['exportView', 'importView'])
} }
......
<template> <template>
<el-dialog :title="$t('Behavior Editor')" :visible.sync="visible" :before-close="beforeClose" @opened="onOpened" <el-dialog :title="$t('Behavior Editor')" :visible.sync="visible" :before-close="beforeClose" @opened="onOpened"
:fullscreen="true" :fullscreen="true" :close-on-click-modal="false" :close-on-press-escape="false"
:append-to-body="true" :close-on-click-modal="false" custom-class="behavior-editor-dialog"> :append-to-body="true" custom-class="behavior-editor-dialog">
<behavior-editor v-if="editorReady" ref="behaviorEditor" class="full-size"></behavior-editor> <behavior-editor v-if="editorReady" ref="behaviorEditor" class="full-size"></behavior-editor>
<div slot="footer" class="dialog-footer"> <div slot="footer" class="dialog-footer">
<el-button size="mini" type="primary" @click="onSave">{{$t('Save')}}</el-button> <el-button size="mini" type="primary" @click="onSave">{{$t('Save')}}</el-button>
......
...@@ -33,11 +33,11 @@ ...@@ -33,11 +33,11 @@
type="success" icon="el-icon-document-copy" type="success" icon="el-icon-document-copy"
size="small" circle plain> size="small" circle plain>
</el-button> </el-button>
<el-button <!--<el-button
@click.native.prevent="onDeleteProject(scope.row)" @click.native.prevent="onDeleteProject(scope.row)"
type="danger" icon="el-icon-delete" type="danger" icon="el-icon-delete"
size="small" circle plain> size="small" circle plain>
</el-button> </el-button>-->
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
......
const serverHost = 'http://10.10.95.74:7777'; const serverHost = 'http://10.10.95.74:7777';
//const serverHost = 'http://beacon.duibadev.com.cn';
module.exports = { module.exports = {
publicPath: process.env.NODE_ENV === 'production' ? '//yun.duiba.com.cn/editor/zeroing/v1/' : '', publicPath: process.env.NODE_ENV === 'production' ? '//yun.duiba.com.cn/editor/zeroing/v1/' : '',
...@@ -20,7 +19,6 @@ module.exports = { ...@@ -20,7 +19,6 @@ module.exports = {
}, },
'/api': { '/api': {
target: serverHost, target: serverHost,
timeout: 60 * 1000,
}, },
} }
}, },
......
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