Commit d64a4c0f authored by rockyl's avatar rockyl

无效路由处理

parent 46b9ebf1
No preview for this file type
...@@ -8,11 +8,46 @@ const data = { ...@@ -8,11 +8,46 @@ const data = {
"name": "view1", "name": "view1",
"children": [ "children": [
{ {
"name": "label" name: 'node1',
type: 'node',
properties: {
x: 0,
y: 0,
width: 0,
height: 0,
rotation: 0,
scaleX: 1,
scaleY: 1,
alpha: 1,
visible: true,
}
}, },
{ {
"name": "image" name: 'node2',
} type: 'label',
properties: {
text: '',
color: 'black',
size: 12,
align: 'left',
}
},
{
"name": "node3",
type: 'image',
properties: {
source: '',
}
},
{
"name": "node4",
type: 'rect',
properties: {
fillColor: 'white',
strokeColor: 'black',
strokeWidth: 1,
}
},
] ]
}, },
{ {
...@@ -22,10 +57,12 @@ const data = { ...@@ -22,10 +57,12 @@ const data = {
"assets": [ "assets": [
{ {
"name": "bg.jpg", "name": "bg.jpg",
uuid:"a1",
"url": "/bg.jpg" "url": "/bg.jpg"
}, },
{ {
"name": "btn-join.png", "name": "btn-join.png",
uuid:"a2",
"url": "/btn-join.png" "url": "/btn-join.png"
} }
] ]
...@@ -46,4 +83,4 @@ const resp = { ...@@ -46,4 +83,4 @@ const resp = {
module.exports = function(){ module.exports = function(){
return resp; return resp;
} };
<template> <template>
<div id="app" class="theme-light"> <div id="app" class="theme-light">
<router-view/> <router-view/>
<div class="invalid-route" v-if="invalidRoute">
<p>无效的页面 {{cd}}秒后跳转</p>
</div>
</div> </div>
</template> </template>
<script> <script>
import events from './global-events'
export default { export default {
name: "App", name: "App",
data() {
return {
cd: 5,
}
},
computed: {
invalidRoute() {
return !this.$route.matched || this.$route.matched.length === 0;
}
},
watch: {
$route: {
handler: function(val, oldVal){
this.dealInvalidRoute();
},
deep: true
}
},
mounted() { mounted() {
this.dealInvalidRoute();
}, },
methods: { methods: {
dealInvalidRoute(){
if (this.invalidRoute) {
this.cd = 5;
this.startCD();
}
},
startCD() {
this.timer = setInterval(() => {
if (this.cd <= 0) {
clearInterval(this.timer);
this.$router.push({name: 'home'});
return;
}
this.cd--;
}, 1000)
}
}, },
} }
</script> </script>
<style> <style>
.invalid-route {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
</style> </style>
...@@ -24,7 +24,10 @@ class ApiError extends Error { ...@@ -24,7 +24,10 @@ class ApiError extends Error {
} }
} }
export async function fetchApi(uri, {params, method, contentType, errMessage} = {method: 'get', contentType: 'form'}) { export async function fetchApi(uri, {params, method = 'get', contentType = 'json', errMessage} = {
method: 'get',
contentType: 'json'
}) {
let url = API_HOST + uri; let url = API_HOST + uri;
const options = { const options = {
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
import {fetchApi} from "./common"; import {fetchApi} from "./common";
export async function fetchEnv() { export async function fetchEnv() {
return await fetchApi('/api/project/env', { return await fetchApi('/api/editor/info', {
errMessage: 'Failed to fetch env', errMessage: 'Failed to fetch env',
}) })
} }
...@@ -16,7 +16,6 @@ export async function createOne(project) { ...@@ -16,7 +16,6 @@ export async function createOne(project) {
return await fetchApi('/api/project/create', { return await fetchApi('/api/project/create', {
params: project, params: project,
method: 'post', method: 'post',
contentType: 'json',
errMessage: 'Failed to create project', errMessage: 'Failed to create project',
}) })
} }
...@@ -25,7 +24,6 @@ export async function duplicateOne(project) { ...@@ -25,7 +24,6 @@ export async function duplicateOne(project) {
return await fetchApi('/api/project/duplicate', { return await fetchApi('/api/project/duplicate', {
params: project, params: project,
method: 'post', method: 'post',
contentType: 'json',
errMessage: 'Failed to duplicate project', errMessage: 'Failed to duplicate project',
}) })
} }
...@@ -33,13 +31,13 @@ export async function duplicateOne(project) { ...@@ -33,13 +31,13 @@ export async function duplicateOne(project) {
export async function deleteOne(id) { export async function deleteOne(id) {
return await fetchApi('/api/project/delete', { return await fetchApi('/api/project/delete', {
params: {id}, params: {id},
method: 'delete', method: 'post',
errMessage: 'Failed to delete project', errMessage: 'Failed to delete project',
}) })
} }
export async function getData(id) { export async function getData(id) {
return await fetchApi('/api/project/data', { return await fetchApi('/api/project/query/data', {
params: {id}, params: {id},
method: 'get', method: 'get',
errMessage: 'Failed to get project', errMessage: 'Failed to get project',
...@@ -50,7 +48,6 @@ export async function updateOne(project) { ...@@ -50,7 +48,6 @@ export async function updateOne(project) {
return await fetchApi('/api/project/update', { return await fetchApi('/api/project/update', {
params: project, params: project,
method: 'post', method: 'post',
contentType: 'json',
errMessage: 'Failed to save project', errMessage: 'Failed to save project',
}) })
} }
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
* Created by rockyl on 2019-09-19. * Created by rockyl on 2019-09-19.
*/ */
//export const API_HOST = 'http://10.10.94.31:7777'; export const API_HOST = 'http://10.10.94.31:7777';
export const API_HOST = 'http://localhost:3002'; //export const API_HOST = 'http://localhost:3002';
export const ASSETS_BASE = 'http://0.0.0.0:4002/assets'; export const ASSETS_BASE = 'http://0.0.0.0:4002/assets';
//文件类型图标 t表示展示缩略图 //文件类型图标 t表示展示缩略图
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
"Data mapping": "Data mapping", "Data mapping": "Data mapping",
"Template": "Template", "Template": "Template",
"Preparing": "Preparing…", "Preparing": "Preparing…",
"Deleting": "Deleting…",
"Create project": "Create project", "Create project": "Create project",
"Creating project": "Creating project…", "Creating project": "Creating project…",
"Create project success": "Create project success", "Create project success": "Create project success",
......
...@@ -22,16 +22,19 @@ export const projectStore = { ...@@ -22,16 +22,19 @@ export const projectStore = {
state.name = name; state.name = name;
state.creator = creator; state.creator = creator;
const localData = state.data; if(data){
const {views, assets, dataMapping} = JSON.parse(data); const localData = state.data;
if(!localData.views || localData.views.length === 0){ const {views, assets, dataMapping} = JSON.parse(data);
localData.views = views || []; if(!localData.views || localData.views.length === 0){
} localData.views = views || [];
if(!localData.assets || localData.assets.length === 0){ }
localData.assets = assets || []; if(!localData.assets || localData.assets.length === 0){
} localData.assets = assets || [];
if(!localData.dataMapping || localData.dataMapping.length === 0){ }
localData.dataMapping = dataMapping || []; if(!localData.dataMapping || localData.dataMapping.length === 0){
localData.dataMapping = dataMapping || [];
};
} }
}, },
}, },
......
...@@ -10,8 +10,18 @@ export const projectsStore = { ...@@ -10,8 +10,18 @@ export const projectsStore = {
state.splice(0); state.splice(0);
state.push(...projects); state.push(...projects);
}, },
addProject(state, project){ addProject(state, project) {
state.push(project); state.unshift(project);
},
deleteProject(state, projectID) {
for (let i = 0, li = state.length; i < li; i++) {
const item = state[i];
if (item.id === projectID) {
state.splice(i, 1);
break;
}
}
}, },
}, },
actions: { actions: {
...@@ -29,5 +39,10 @@ export const projectsStore = { ...@@ -29,5 +39,10 @@ export const projectsStore = {
commit('addProject', project); commit('addProject', project);
return project; return project;
}, },
async deleteProject({commit}, projectID) {
await projectApi.deleteOne(projectID);
commit('deleteProject', projectID);
return projectID;
},
}, },
}; };
\ No newline at end of file
...@@ -48,7 +48,11 @@ ...@@ -48,7 +48,11 @@
}, },
mounted() { mounted() {
const {projectID} = this.$route.params; const {projectID} = this.$route.params;
playWaiting(this.updateProject(projectID), this.$t('Preparing')).catch(e => {}); if(projectID){
playWaiting(this.updateProject(projectID), this.$t('Preparing')).catch(e => {});
}else{
this.$router.push({name: 'home'})
}
}, },
methods: { methods: {
getSize(id, side) { getSize(id, side) {
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
size="small" circle plain> size="small" circle plain>
</el-button> </el-button>
<el-button <el-button
@click.native.prevent="deleteProject(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>
...@@ -94,8 +94,17 @@ ...@@ -94,8 +94,17 @@
selectProject(row, event) { selectProject(row, event) {
this.editProject(row.id); this.editProject(row.id);
}, },
async deleteProject(row, event) { async onDeleteProject(project, event) {
this.deleteAlert(row); this.$confirm(this.$t('This action will permanently delete project', {projectName: project.name}), this.$t('Alert'), {
confirmButtonText: this.$t('Confirm'),
cancelButtonText: this.$t('Cancel'),
type: 'warning'
}).then(
()=>{
playWaiting(this.deleteProject(project.id), this.$t('Deleting')).catch(e => {});
},
()=>{}
)
}, },
onCreateProject(projectID) { onCreateProject(projectID) {
this.editProject(projectID); this.editProject(projectID);
...@@ -106,16 +115,10 @@ ...@@ -106,16 +115,10 @@
editProject(projectID) { editProject(projectID) {
this.$router.push({name: 'editor', params: {projectID}}); this.$router.push({name: 'editor', params: {projectID}});
}, },
deleteAlert(project) {
return this.$confirm(this.$t('This action will permanently delete project', {projectName: project.name}), this.$t('Alert'), {
confirmButtonText: this.$t('Confirm'),
cancelButtonText: this.$t('Cancel'),
type: 'warning'
})
},
...mapActions([ ...mapActions([
'updateProjects', 'updateProjects',
'updateEnv', 'updateEnv',
'deleteProject'
]), ]),
}, },
} }
......
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