20251128API:selectAllWithTableName/selectAll/selectTaskHasCreated提前缓存
This commit is contained in:
@@ -131,7 +131,7 @@
|
||||
<script type="text/javascript" src="/static/js/sockjs.min.js"></script>
|
||||
<script>
|
||||
// 平台名称配置
|
||||
const myname = '天津市林草资源专项调查管理平台 v20251126beta';
|
||||
const myname = '天津市林草资源专项调查管理平台 v20251006';
|
||||
document.getElementsByTagName('title')[0].innerText = myname;
|
||||
|
||||
// 页面加载完成后隐藏加载动画
|
||||
|
||||
61
src/App.vue
61
src/App.vue
@@ -1,12 +1,71 @@
|
||||
<template>
|
||||
<div id="app">
|
||||
<router-view/>
|
||||
|
||||
<!-- 全局数据初始化失败提示对话框 -->
|
||||
<el-dialog
|
||||
title="数据初始化失败"
|
||||
:visible.sync="initErrorVisible"
|
||||
:close-on-click-modal="false"
|
||||
:close-on-press-escape="false"
|
||||
:show-close="false"
|
||||
width="400px"
|
||||
>
|
||||
<div style="text-align: center; padding: 20px 0;">
|
||||
<i class="el-icon-warning" style="font-size: 48px; color: #E6A23C; margin-bottom: 16px;"></i>
|
||||
<p style="font-size: 16px; color: #606266; margin-bottom: 20px;">{{ initErrorMessage }}</p>
|
||||
</div>
|
||||
<div slot="footer" style="text-align: center;">
|
||||
<el-button type="primary" @click="retryInit" :loading="retrying">重试</el-button>
|
||||
<el-button @click="goToLogin">返回登录</el-button>
|
||||
</div>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'App'
|
||||
name: 'App',
|
||||
data() {
|
||||
return {
|
||||
retrying: false
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
initErrorVisible: {
|
||||
get() {
|
||||
return !!this.$store.state.initError
|
||||
},
|
||||
set(value) {
|
||||
if (!value) {
|
||||
this.$store.commit('clearInitError')
|
||||
}
|
||||
}
|
||||
},
|
||||
initErrorMessage() {
|
||||
return this.$store.state.initError || '数据初始化失败,请重试'
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
async retryInit() {
|
||||
this.retrying = true
|
||||
this.$store.commit('clearInitError')
|
||||
const result = await this.$store.dispatch('initTaskData')
|
||||
this.retrying = false
|
||||
|
||||
if (result.success) {
|
||||
// 初始化成功,刷新当前路由
|
||||
this.$router.go(0)
|
||||
} else {
|
||||
// 初始化失败,显示错误
|
||||
this.$store.commit('setInitError', result.error)
|
||||
}
|
||||
},
|
||||
goToLogin() {
|
||||
this.$store.commit('clearInitError')
|
||||
this.$router.push({ path: '/login' })
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -554,7 +554,7 @@
|
||||
overflow-y: scroll;
|
||||
height: calc(100% - 70px);
|
||||
|
||||
padding: 20px 24px;
|
||||
padding: 8px 8px;
|
||||
width: 420px;
|
||||
box-shadow: 0 15px 35px rgba(76, 175, 80, 0.14), inset 0 1px 0 rgba(255, 255, 255, 0.6);
|
||||
backdrop-filter: blur(4px);
|
||||
|
||||
@@ -135,6 +135,7 @@ ul {
|
||||
float: right;
|
||||
text-align: left;
|
||||
font-size: 15px;
|
||||
font-weight: bold !important;
|
||||
border-left: 0px solid #000;
|
||||
z-index: 999;
|
||||
margin-right: 0px;
|
||||
@@ -157,6 +158,7 @@ ul {
|
||||
width: 140px;
|
||||
text-align: center;
|
||||
color: #2E7D32 !important;
|
||||
font-weight: bold !important;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
@@ -447,6 +449,29 @@ el-aside.tac.el-menu-item,
|
||||
border-radius: 0 0 14px 14px !important;
|
||||
}
|
||||
|
||||
/* el-scrollbar 最大宽度设置,超出部分隐藏 */
|
||||
.el-scrollbar {
|
||||
max-width: 480px !important;
|
||||
overflow-x: hidden !important;
|
||||
overflow-y: auto !important;
|
||||
}
|
||||
|
||||
.el-scrollbar__wrap {
|
||||
max-width: 480px !important;
|
||||
overflow-x: hidden !important;
|
||||
overflow-y: auto !important;
|
||||
}
|
||||
|
||||
.el-scrollbar__view {
|
||||
max-width: 480px !important;
|
||||
overflow-x: hidden !important;
|
||||
}
|
||||
|
||||
/* 隐藏横向滚动条 */
|
||||
.el-scrollbar__bar.is-horizontal {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.el-input__inner {
|
||||
height: 35px !important;
|
||||
}
|
||||
@@ -549,6 +574,7 @@ el-aside.tac.el-menu-item,
|
||||
.container .topbar-wrap .topbar-title {
|
||||
margin-right: 0px;
|
||||
height: 70px;
|
||||
font-weight: bold !important;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -770,32 +770,22 @@ export default {
|
||||
|
||||
this.wTaskOptions = [];
|
||||
let that = this;
|
||||
request({
|
||||
url: "/task/selectTaskHasCreated",
|
||||
method: "get",
|
||||
}).then(function (response) {
|
||||
if (response.data.success == true) {
|
||||
var jsondata = JSON.parse(response.data.data);
|
||||
var options = jsondata.data;
|
||||
for (var i = 0; i < options.length; i++) {
|
||||
that.reportoptions.push({
|
||||
value: options[i].id,
|
||||
label: options[i].taskName,
|
||||
});
|
||||
that.taskoptions.push({
|
||||
value: options[i].id,
|
||||
label: options[i].taskName,
|
||||
});
|
||||
that.wTaskOptions.push({
|
||||
value: options[i].id,
|
||||
label: options[i].taskName,
|
||||
});
|
||||
}
|
||||
} else if (response.data.status == "401") {
|
||||
that.$alert(response.data.message);
|
||||
that.$router.push({ path: "/login" });
|
||||
}
|
||||
});
|
||||
// 从 store 获取数据
|
||||
const taskData = that.$store.state.taskData.selectTaskHasCreated || [];
|
||||
for (var i = 0; i < taskData.length; i++) {
|
||||
that.reportoptions.push({
|
||||
value: taskData[i].id,
|
||||
label: taskData[i].taskName,
|
||||
});
|
||||
that.taskoptions.push({
|
||||
value: taskData[i].id,
|
||||
label: taskData[i].taskName,
|
||||
});
|
||||
that.wTaskOptions.push({
|
||||
value: taskData[i].id,
|
||||
label: taskData[i].taskName,
|
||||
});
|
||||
}
|
||||
},
|
||||
getWarningTables() {
|
||||
if (this.warningform.task != "") {
|
||||
|
||||
@@ -363,24 +363,14 @@ export default {
|
||||
getTasks () {
|
||||
this.taskoptions = []
|
||||
let that = this
|
||||
request({
|
||||
url: '/task/selectTaskHasCreated',
|
||||
method: 'get'
|
||||
}).then(function (response) {
|
||||
if (response.data.success === true) {
|
||||
var jsondata = JSON.parse(response.data.data)
|
||||
var options = jsondata.data
|
||||
for (var i = 0; i < options.length; i++) {
|
||||
that.taskoptions.push({
|
||||
value: options[i].id,
|
||||
label: options[i].taskName
|
||||
})
|
||||
}
|
||||
} else if (response.data.status === '401') {
|
||||
that.$alert(response.data.message)
|
||||
that.$router.push({path: '/login'})
|
||||
}
|
||||
})
|
||||
// 从 store 获取数据
|
||||
const taskData = that.$store.state.taskData.selectTaskHasCreated || []
|
||||
for (var i = 0; i < taskData.length; i++) {
|
||||
that.taskoptions.push({
|
||||
value: taskData[i].id,
|
||||
label: taskData[i].taskName
|
||||
})
|
||||
}
|
||||
},
|
||||
getTables () {
|
||||
if (this.task === '') {
|
||||
|
||||
@@ -551,8 +551,8 @@ export default {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 400px;
|
||||
margin-bottom: 20px;
|
||||
height: 270px;
|
||||
margin-bottom: 0px;
|
||||
width: 100%;
|
||||
overflow: visible;
|
||||
}
|
||||
@@ -564,7 +564,7 @@ export default {
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
max-width: 100%;
|
||||
min-height: 400px;
|
||||
height: 270px;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
@@ -633,16 +633,17 @@ export default {
|
||||
|
||||
.thumbnail-nav {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
gap: 8px;
|
||||
justify-content: center;
|
||||
flex-wrap: wrap;
|
||||
padding: 10px 0;
|
||||
padding: 4px 0;
|
||||
height: 60px;
|
||||
border-top: 1px solid rgba(129, 199, 132, 0.3);
|
||||
}
|
||||
|
||||
.thumbnail-item {
|
||||
width: 80px;
|
||||
height: 80px;
|
||||
width: 72px;
|
||||
height: 48px;
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
border: 2px solid transparent;
|
||||
|
||||
@@ -129,6 +129,7 @@ export default {
|
||||
}
|
||||
|
||||
.topbar-title .el-menu--horizontal > .el-menu-item {
|
||||
font-weight: bold !important;
|
||||
height: 50px;
|
||||
line-height: 70px;
|
||||
width: 114px;
|
||||
|
||||
@@ -523,24 +523,14 @@ export default {
|
||||
getTasks1() {
|
||||
this.stattaskoptions = [];
|
||||
let that = this;
|
||||
request({
|
||||
url: "/task/selectTaskHasCreated",
|
||||
method: "get",
|
||||
}).then(function (response) {
|
||||
if (response.data.success == true) {
|
||||
var jsondata = JSON.parse(response.data.data);
|
||||
var options = jsondata.data;
|
||||
for (var i = 0; i < options.length; i++) {
|
||||
that.stattaskoptions.push({
|
||||
value: options[i].id,
|
||||
label: options[i].taskName,
|
||||
});
|
||||
}
|
||||
} else if (response.data.status == "401") {
|
||||
that.$alert(response.data.message);
|
||||
that.$router.push({ path: "/login" });
|
||||
}
|
||||
});
|
||||
// 从 store 获取数据
|
||||
const taskData = that.$store.state.taskData.selectTaskHasCreated || [];
|
||||
for (var i = 0; i < taskData.length; i++) {
|
||||
that.stattaskoptions.push({
|
||||
value: taskData[i].id,
|
||||
label: taskData[i].taskName,
|
||||
});
|
||||
}
|
||||
},
|
||||
getTables1() {
|
||||
if (this.stattask === "") {
|
||||
|
||||
@@ -1476,37 +1476,24 @@ export default {
|
||||
});
|
||||
this.map.addOverlay(this.trackLayerOverLay);
|
||||
},
|
||||
// 初始化任务清单
|
||||
// 初始化任务清单 - 从 store 获取数据
|
||||
initList() {
|
||||
that.routelist = [];
|
||||
that.routelist2 = [];
|
||||
// 连接后台测试:
|
||||
request({
|
||||
url: "/task/selectAllWithTableName",
|
||||
method: "get",
|
||||
})
|
||||
.then(function (response) {
|
||||
if (response.data.status == "401") {
|
||||
that.$alert(response.data.message);
|
||||
that.$router.push({ path: "/login" });
|
||||
} else {
|
||||
// 把数据装入下拉菜单中
|
||||
for (let i = 0; i < response.data.data.length; i++) {
|
||||
let newData = {
|
||||
value: response.data.data[i].databaseName,
|
||||
label: response.data.data[i].taskName,
|
||||
id: response.data.data[i].id,
|
||||
tableNames: response.data.data[i].tableNames,
|
||||
};
|
||||
that.routelist.push(newData);
|
||||
that.list.push(newData);
|
||||
that.routelist2.push(newData);
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch(function (err) {
|
||||
console.log(err);
|
||||
});
|
||||
// 从 store 获取数据
|
||||
const taskData = that.$store.state.taskData.selectAllWithTableName || [];
|
||||
// 把数据装入下拉菜单中
|
||||
for (let i = 0; i < taskData.length; i++) {
|
||||
let newData = {
|
||||
value: taskData[i].databaseName,
|
||||
label: taskData[i].taskName,
|
||||
id: taskData[i].id,
|
||||
tableNames: taskData[i].tableNames,
|
||||
};
|
||||
that.routelist.push(newData);
|
||||
that.list.push(newData);
|
||||
that.routelist2.push(newData);
|
||||
}
|
||||
},
|
||||
// 左侧面板收缩动画
|
||||
collapse() {
|
||||
@@ -4785,20 +4772,11 @@ export default {
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
api
|
||||
.getAllTask()
|
||||
.then((res) => {
|
||||
if (res.data.status == "401") {
|
||||
that.$alert(response.data.message);
|
||||
that.$router.push({ path: "/login" });
|
||||
}
|
||||
that.taskList = JSON.parse(res.data).data;
|
||||
if (that.taskList.length) that.listQuery.taskId = that.taskList[0].id;
|
||||
that.chooseTask(that.listQuery.taskId);
|
||||
})
|
||||
.catch((error) => {
|
||||
this.$message.error(error);
|
||||
});
|
||||
// 从 store 获取数据
|
||||
const taskData = this.$store.state.taskData.selectAll || [];
|
||||
that.taskList = taskData;
|
||||
if (that.taskList.length) that.listQuery.taskId = that.taskList[0].id;
|
||||
that.chooseTask(that.listQuery.taskId);
|
||||
},
|
||||
watch: {
|
||||
activeItem: {
|
||||
|
||||
@@ -792,25 +792,12 @@ export default {
|
||||
// },
|
||||
init() {
|
||||
let that = this;
|
||||
// 请求任务列表
|
||||
that.tasksData = [];
|
||||
that.srcTaskOptions = [];
|
||||
that.destTaskOptions = [];
|
||||
request({
|
||||
url: "/task/selectTaskHasCreated",
|
||||
method: "get",
|
||||
}).then(function (response) {
|
||||
if (response.data.success == true) {
|
||||
var jsondata = JSON.parse(response.data.data);
|
||||
that.tasksData = jsondata.data;
|
||||
that.filteredData = [...that.tasksData]; // 初始化过滤数据
|
||||
that.srcTaskOptions = jsondata.data;
|
||||
that.destTaskOptions = jsondata.data;
|
||||
} else if (response.data.status == "401") {
|
||||
that.$alert(response.data.message);
|
||||
that.$router.push({ path: "/login" });
|
||||
}
|
||||
});
|
||||
// 从 store 获取数据
|
||||
const taskData = that.$store.state.taskData.selectTaskHasCreated || [];
|
||||
that.tasksData = taskData;
|
||||
that.filteredData = [...that.tasksData]; // 初始化过滤数据
|
||||
that.srcTaskOptions = taskData;
|
||||
that.destTaskOptions = taskData;
|
||||
},
|
||||
beforeTpkUpload(file) {
|
||||
if (file.type != "tpk") {
|
||||
|
||||
@@ -765,27 +765,19 @@ export default {
|
||||
} else {
|
||||
let geojsonObject = result.data.data;
|
||||
this.drawgridLayer(geojsonObject, flag, isRedraw);
|
||||
request({
|
||||
url: "/task/selectAllWithTableName",
|
||||
method: "get",
|
||||
}).then((response) => {
|
||||
if (response.data.status == "401") {
|
||||
this.$alert(response.data.message);
|
||||
this.$router.push({ path: "/login" });
|
||||
} else {
|
||||
// 把数据装入查看表的下拉菜单中
|
||||
let temp = response.data.data;
|
||||
let current = temp.find((item) => {
|
||||
return item.id == this.taskId;
|
||||
});
|
||||
this.taskValue = {
|
||||
value: current.databaseName,
|
||||
label: current.taskName,
|
||||
id: current.id,
|
||||
tableNames: current.tableNames,
|
||||
};
|
||||
}
|
||||
// 从 store 获取数据
|
||||
const taskData = this.$store.state.taskData.selectAllWithTableName || [];
|
||||
let current = taskData.find((item) => {
|
||||
return item.id == this.taskId;
|
||||
});
|
||||
if (current) {
|
||||
this.taskValue = {
|
||||
value: current.databaseName,
|
||||
label: current.taskName,
|
||||
id: current.id,
|
||||
tableNames: current.tableNames,
|
||||
};
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
|
||||
@@ -370,34 +370,24 @@ export default {
|
||||
},
|
||||
init() {
|
||||
let that = this;
|
||||
// 请求任务列表
|
||||
request({
|
||||
url: "/task/selectTaskHasCreated",
|
||||
method: "get",
|
||||
}).then(function (response) {
|
||||
if (response.data.success == true) {
|
||||
var jsondata = JSON.parse(response.data.data);
|
||||
that.tasksData = jsondata.data;
|
||||
//0表示需要分配
|
||||
for (var i = 0; i < that.tasksData.length; i++) {
|
||||
if (that.tasksData[i].isAllocationOptional == 0) {
|
||||
that.tasksData[i].isAllocationOptional = true;
|
||||
} else {
|
||||
that.tasksData[i].isAllocationOptional = false;
|
||||
}
|
||||
if (that.tasksData[i].allocated == "true") {
|
||||
that.tasksData[i].allocated = true;
|
||||
} else {
|
||||
that.tasksData[i].allocated = false;
|
||||
}
|
||||
}
|
||||
// 应用当前筛选和搜索
|
||||
that.applyFilter();
|
||||
} else if (response.data.status == "401") {
|
||||
that.$alert(response.data.message);
|
||||
that.$router.push({ path: "/login" });
|
||||
// 从 store 获取数据
|
||||
const taskData = that.$store.state.taskData.selectTaskHasCreated || [];
|
||||
that.tasksData = taskData;
|
||||
//0表示需要分配
|
||||
for (var i = 0; i < that.tasksData.length; i++) {
|
||||
if (that.tasksData[i].isAllocationOptional == 0) {
|
||||
that.tasksData[i].isAllocationOptional = true;
|
||||
} else {
|
||||
that.tasksData[i].isAllocationOptional = false;
|
||||
}
|
||||
});
|
||||
if (that.tasksData[i].allocated == "true") {
|
||||
that.tasksData[i].allocated = true;
|
||||
} else {
|
||||
that.tasksData[i].allocated = false;
|
||||
}
|
||||
}
|
||||
// 应用当前筛选和搜索
|
||||
that.applyFilter();
|
||||
request({
|
||||
url: "/user/all_worker",
|
||||
method: "get",
|
||||
|
||||
@@ -295,37 +295,28 @@ export default {
|
||||
}
|
||||
},
|
||||
|
||||
//读取数据库 初始化xml
|
||||
//读取数据库 初始化xml - 从 store 获取数据
|
||||
init() {
|
||||
let that = this;
|
||||
request({
|
||||
url: "/task/selectAll",
|
||||
method: "get",
|
||||
}).then(function (response) {
|
||||
if (response.data.success == true) {
|
||||
var jsondata = JSON.parse(response.data.data);
|
||||
that.xmlData = jsondata.data;
|
||||
that.filteredData = [...that.xmlData]; // 初始化过滤数据
|
||||
for (var i = 0; i < that.xmlData.length; i++) {
|
||||
if (that.xmlData[i].hasCreateTables == 1) {
|
||||
that.xmlData[i].hasCreateTables = true;
|
||||
} else {
|
||||
that.xmlData[i].hasCreateTables = false;
|
||||
}
|
||||
if (
|
||||
that.xmlData[i].isReviewerRestricted == 1 ||
|
||||
that.xmlData[i].isReviewerRestricted == true
|
||||
) {
|
||||
that.xmlData[i].isReviewerRestricted = true;
|
||||
} else {
|
||||
that.xmlData[i].isReviewerRestricted = false;
|
||||
}
|
||||
}
|
||||
} else if (response.data.status == "401") {
|
||||
that.$alert(response.data.message);
|
||||
that.$router.push({ path: "/login" });
|
||||
// 从 store 获取数据
|
||||
const taskData = that.$store.state.taskData.selectAll || [];
|
||||
that.xmlData = taskData;
|
||||
that.filteredData = [...that.xmlData]; // 初始化过滤数据
|
||||
for (var i = 0; i < that.xmlData.length; i++) {
|
||||
if (that.xmlData[i].hasCreateTables == 1) {
|
||||
that.xmlData[i].hasCreateTables = true;
|
||||
} else {
|
||||
that.xmlData[i].hasCreateTables = false;
|
||||
}
|
||||
});
|
||||
if (
|
||||
that.xmlData[i].isReviewerRestricted == 1 ||
|
||||
that.xmlData[i].isReviewerRestricted == true
|
||||
) {
|
||||
that.xmlData[i].isReviewerRestricted = true;
|
||||
} else {
|
||||
that.xmlData[i].isReviewerRestricted = false;
|
||||
}
|
||||
}
|
||||
},
|
||||
// 修改方法参数,从index改为id
|
||||
changeRestricted(id, val) {
|
||||
|
||||
@@ -72,14 +72,33 @@
|
||||
</div>
|
||||
</el-form>
|
||||
<span style="position: fixed; bottom: 10px; left: 10px; color: lightgray"
|
||||
>v20251113beta</span
|
||||
>v20251006</span
|
||||
>
|
||||
|
||||
<!-- 数据初始化失败提示对话框 -->
|
||||
<el-dialog
|
||||
title="数据初始化失败"
|
||||
:visible.sync="initErrorVisible"
|
||||
:close-on-click-modal="false"
|
||||
:close-on-press-escape="false"
|
||||
:show-close="false"
|
||||
width="400px"
|
||||
>
|
||||
<div style="text-align: center; padding: 20px 0;">
|
||||
<i class="el-icon-warning" style="font-size: 48px; color: #E6A23C; margin-bottom: 16px;"></i>
|
||||
<p style="font-size: 16px; color: #606266; margin-bottom: 20px;">{{ initErrorMessage }}</p>
|
||||
</div>
|
||||
<div slot="footer" style="text-align: center;">
|
||||
<el-button type="primary" @click="retryInit" :loading="loading">重试</el-button>
|
||||
</div>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { ajax as request } from "@/request.js";
|
||||
import md5 from "js-md5";
|
||||
import { store } from "@/components/vuex/store.js";
|
||||
export default {
|
||||
name: "login",
|
||||
data() {
|
||||
@@ -107,6 +126,8 @@ export default {
|
||||
},
|
||||
loading: false,
|
||||
pwdType: "password",
|
||||
initErrorVisible: false,
|
||||
initErrorMessage: "",
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
@@ -138,23 +159,8 @@ export default {
|
||||
sessionStorage.setItem("access-user", response.data.data.role);
|
||||
sessionStorage.setItem("access-id", response.data.data.id);
|
||||
|
||||
if (
|
||||
sessionStorage.getItem("access-user") == "Admin" ||
|
||||
sessionStorage.getItem("access-user") == "SuperAdmin" ||
|
||||
sessionStorage.getItem("access-user") == "Leader"
|
||||
) {
|
||||
that.loading = false;
|
||||
that.$router.push({ path: "/view" });
|
||||
} else if (sessionStorage.getItem("access-user") == "Operator") {
|
||||
that.loading = false;
|
||||
that.$router.push({ path: "/main" });
|
||||
} else {
|
||||
that.$notify.error({
|
||||
title: "提示",
|
||||
message: "用户不可登录该系统!",
|
||||
});
|
||||
that.loading = false;
|
||||
}
|
||||
// 初始化任务数据
|
||||
that.initTaskData();
|
||||
} else if (response.data.status == "204") {
|
||||
that
|
||||
.$confirm("用户信息不完善,是否去完善信息?", "提示", {
|
||||
@@ -190,6 +196,41 @@ export default {
|
||||
toRegister() {
|
||||
this.$router.push({ path: "/register" });
|
||||
},
|
||||
// 初始化任务数据
|
||||
async initTaskData() {
|
||||
let that = this;
|
||||
const result = await store.dispatch('initTaskData');
|
||||
|
||||
if (result.success) {
|
||||
// 初始化成功,根据用户角色跳转
|
||||
that.loading = false;
|
||||
if (
|
||||
sessionStorage.getItem("access-user") == "Admin" ||
|
||||
sessionStorage.getItem("access-user") == "SuperAdmin" ||
|
||||
sessionStorage.getItem("access-user") == "Leader"
|
||||
) {
|
||||
that.$router.push({ path: "/view" });
|
||||
} else if (sessionStorage.getItem("access-user") == "Operator") {
|
||||
that.$router.push({ path: "/main" });
|
||||
} else {
|
||||
that.$notify.error({
|
||||
title: "提示",
|
||||
message: "用户不可登录该系统!",
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// 初始化失败,显示错误提示
|
||||
that.loading = false;
|
||||
that.initErrorMessage = result.error || "数据初始化失败,请重试";
|
||||
that.initErrorVisible = true;
|
||||
}
|
||||
},
|
||||
// 重试初始化
|
||||
retryInit() {
|
||||
this.initErrorVisible = false;
|
||||
this.loading = true;
|
||||
this.initTaskData();
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import Vue from 'vue'
|
||||
import Vuex from 'vuex'
|
||||
import { ajax as request } from "@/request.js";
|
||||
Vue.use(Vuex)
|
||||
|
||||
export const store = new Vuex.Store({
|
||||
@@ -15,7 +16,17 @@ export const store = new Vuex.Store({
|
||||
LocalLocation: {
|
||||
currentPosition: '',
|
||||
currentLocation: ''
|
||||
}
|
||||
},
|
||||
// 登录后初始化的任务数据
|
||||
taskData: {
|
||||
selectAllWithTableName: [], // /api/task/selectAllWithTableName 的数据
|
||||
selectAll: [], // /api/task/selectAll/ 的数据
|
||||
selectTaskHasCreated: [] // /api/task/selectTaskHasCreated 的数据
|
||||
},
|
||||
// 初始化状态
|
||||
taskDataInitialized: false,
|
||||
taskDataInitializing: false,
|
||||
initError: null // 初始化错误信息
|
||||
},
|
||||
mutations: {
|
||||
updateDrawtool(state, drawtool) {
|
||||
@@ -63,6 +74,28 @@ export const store = new Vuex.Store({
|
||||
},
|
||||
updatePosition(state, position) {
|
||||
state.LocalLocation.currentPosition = position
|
||||
},
|
||||
// 设置任务数据
|
||||
setTaskDataSelectAllWithTableName(state, data) {
|
||||
state.taskData.selectAllWithTableName = data
|
||||
},
|
||||
setTaskDataSelectAll(state, data) {
|
||||
state.taskData.selectAll = data
|
||||
},
|
||||
setTaskDataSelectTaskHasCreated(state, data) {
|
||||
state.taskData.selectTaskHasCreated = data
|
||||
},
|
||||
setTaskDataInitialized(state, value) {
|
||||
state.taskDataInitialized = value
|
||||
},
|
||||
setTaskDataInitializing(state, value) {
|
||||
state.taskDataInitializing = value
|
||||
},
|
||||
setInitError(state, error) {
|
||||
state.initError = error
|
||||
},
|
||||
clearInitError(state) {
|
||||
state.initError = null
|
||||
}
|
||||
|
||||
},
|
||||
@@ -87,6 +120,70 @@ export const store = new Vuex.Store({
|
||||
},
|
||||
updatePosition({ commit, state }, obj) {
|
||||
commit("updatePosition", obj.position)
|
||||
},
|
||||
// 初始化任务数据
|
||||
async initTaskData({ commit, state }) {
|
||||
commit('setTaskDataInitializing', true)
|
||||
commit('setTaskDataInitialized', false)
|
||||
|
||||
try {
|
||||
// 调用3个接口
|
||||
const [response1, response2, response3] = await Promise.all([
|
||||
request({
|
||||
url: "/task/selectAllWithTableName",
|
||||
method: "get",
|
||||
}),
|
||||
request({
|
||||
url: "/task/selectAll/",
|
||||
method: "get",
|
||||
}),
|
||||
request({
|
||||
url: "/task/selectTaskHasCreated",
|
||||
method: "get",
|
||||
})
|
||||
])
|
||||
|
||||
// 检查是否有401错误
|
||||
if (response1.data.status == "401" || response2.data.status == "401" || response3.data.status == "401") {
|
||||
throw new Error("认证失败,请重新登录")
|
||||
}
|
||||
|
||||
// 处理第一个接口的数据
|
||||
let data1 = response1.data.data || []
|
||||
commit('setTaskDataSelectAllWithTableName', data1)
|
||||
|
||||
// 处理第二个接口的数据
|
||||
let data2 = []
|
||||
if (response2.data.success == true && response2.data.data) {
|
||||
try {
|
||||
const parsed = JSON.parse(response2.data.data)
|
||||
data2 = parsed.data || []
|
||||
} catch (e) {
|
||||
data2 = response2.data.data || []
|
||||
}
|
||||
}
|
||||
commit('setTaskDataSelectAll', data2)
|
||||
|
||||
// 处理第三个接口的数据
|
||||
let data3 = []
|
||||
if (response3.data.success == true && response3.data.data) {
|
||||
try {
|
||||
const parsed = JSON.parse(response3.data.data)
|
||||
data3 = parsed.data || []
|
||||
} catch (e) {
|
||||
data3 = response3.data.data || []
|
||||
}
|
||||
}
|
||||
commit('setTaskDataSelectTaskHasCreated', data3)
|
||||
|
||||
commit('setTaskDataInitialized', true)
|
||||
commit('setTaskDataInitializing', false)
|
||||
return { success: true }
|
||||
} catch (error) {
|
||||
commit('setTaskDataInitialized', false)
|
||||
commit('setTaskDataInitializing', false)
|
||||
return { success: false, error: error.message || '初始化失败,请重试' }
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import Vue from 'vue'
|
||||
import VueRouter from 'vue-router'
|
||||
import { store } from '@/components/vuex/store'
|
||||
const Home = () => import('@/components/Home')
|
||||
const ViewTask = () => import('@/components/Supervision/ViewTask')
|
||||
const statPage = () => import('@/components/Statistic/statPage')
|
||||
@@ -148,21 +149,73 @@ const routes = [
|
||||
const router = new VueRouter({
|
||||
routes
|
||||
})
|
||||
router.beforeEach((to, from, next) => {
|
||||
router.beforeEach(async (to, from, next) => {
|
||||
if (to.path.startsWith('/login')) {
|
||||
window.sessionStorage.removeItem('access-user')
|
||||
window.sessionStorage.removeItem('access-id')
|
||||
// 清除初始化状态
|
||||
store.commit('setTaskDataInitialized', false)
|
||||
store.commit('clearInitError')
|
||||
next()
|
||||
} else if (to.path.startsWith('/register') || to.path.startsWith('/modifypassword') || to.path.startsWith('/forgetpassword') || to.path.startsWith('/addinfo')) {
|
||||
window.sessionStorage.removeItem('access-user')
|
||||
window.sessionStorage.removeItem('access-id')
|
||||
// 清除初始化状态
|
||||
store.commit('setTaskDataInitialized', false)
|
||||
store.commit('clearInitError')
|
||||
next()
|
||||
} else {
|
||||
let user = window.sessionStorage.getItem('access-user') === '' ? false : window.sessionStorage.getItem('access-user')
|
||||
if (!user) {
|
||||
next({ path: '/login' })
|
||||
} else {
|
||||
next()
|
||||
// 检查数据是否已初始化
|
||||
const isInitialized = store.state.taskDataInitialized
|
||||
const isInitializing = store.state.taskDataInitializing
|
||||
|
||||
// 如果数据未初始化且不在初始化中,则进行初始化
|
||||
if (!isInitialized && !isInitializing) {
|
||||
try {
|
||||
const result = await store.dispatch('initTaskData')
|
||||
if (result.success) {
|
||||
// 初始化成功,继续路由
|
||||
next()
|
||||
} else {
|
||||
// 初始化失败,显示错误提示并阻止路由
|
||||
store.commit('setInitError', result.error)
|
||||
// 阻止路由跳转,显示错误对话框
|
||||
next(false)
|
||||
}
|
||||
} catch (error) {
|
||||
// 初始化异常
|
||||
store.commit('setInitError', error.message || '初始化失败,请重试')
|
||||
next(false)
|
||||
}
|
||||
} else if (isInitializing) {
|
||||
// 正在初始化中,等待完成(最多等待5秒)
|
||||
let waited = 0
|
||||
const maxWait = 5000
|
||||
const checkInterval = setInterval(() => {
|
||||
waited += 100
|
||||
if (!store.state.taskDataInitializing || waited >= maxWait) {
|
||||
clearInterval(checkInterval)
|
||||
if (store.state.taskDataInitialized) {
|
||||
next()
|
||||
} else {
|
||||
if (waited >= maxWait) {
|
||||
store.commit('setTaskDataInitializing', false)
|
||||
store.commit('setInitError', '初始化超时,请重试')
|
||||
} else {
|
||||
store.commit('setInitError', '初始化失败,请重试')
|
||||
}
|
||||
next(false)
|
||||
}
|
||||
}
|
||||
}, 100)
|
||||
} else {
|
||||
// 已初始化,继续路由
|
||||
next()
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user