Commit 481aa828 authored by 姬鋆屾's avatar 姬鋆屾

tui

parent d261530c
...@@ -128,6 +128,10 @@ export default { ...@@ -128,6 +128,10 @@ export default {
.then(() => { .then(() => {
this.$message.success("已退出登录"); this.$message.success("已退出登录");
this.$store.commit("logout"); this.$store.commit("logout");
process.env.NODE_ENV == "development"
? this.$router.replace("/login")
: (window.location.href = this.portal);
return;
this.$router.replace("/login"); this.$router.replace("/login");
}); });
}, },
...@@ -135,7 +139,9 @@ export default { ...@@ -135,7 +139,9 @@ export default {
beforeDestroy() { beforeDestroy() {
console.log("beforeDestroy"); console.log("beforeDestroy");
}, },
mounted() {}, mounted() {
this.$forceUpdate(this.userData);
},
computed: { computed: {
group() { group() {
const relativeGroup = this.$store.state.group; const relativeGroup = this.$store.state.group;
......
import Vue from 'vue' import Vue from "vue";
import Vuex from 'vuex' import Vuex from "vuex";
import { normalCallPost } from './assets/utils'; import { normalCallPost } from "./assets/utils";
Vue.use(Vuex) Vue.use(Vuex);
let userData = {}; let userData = {};
let currentParentName = '' let currentParentName = "";
let headBar = [] let headBar = [];
let CurrentThirdArr = [] let CurrentThirdArr = [];
let ThirdPath = '' let ThirdPath = "";
let CurrentSecondPath = '' let CurrentSecondPath = "";
try { try {
userData = JSON.parse(window.sessionStorage.userData || '{}'); userData = JSON.parse(window.sessionStorage.userData || "{}");
currentParentName = window.sessionStorage.currentParentName || '' currentParentName = window.sessionStorage.currentParentName || "";
headBar = JSON.parse(window.sessionStorage.headBar || '{}') headBar = JSON.parse(window.sessionStorage.headBar || "{}");
CurrentThirdArr = JSON.parse(window.sessionStorage.CurrentThirdArr || '{}') CurrentThirdArr = JSON.parse(window.sessionStorage.CurrentThirdArr || "{}");
ThirdPath = window.sessionStorage.ThirdPath || '' ThirdPath = window.sessionStorage.ThirdPath || "";
CurrentSecondPath = window.sessionStorage.CurrentSecondPath || '' CurrentSecondPath = window.sessionStorage.CurrentSecondPath || "";
} catch (error) { } catch (error) {
console.log('未从session中获取到userData') console.log("未从session中获取到userData");
console.log('未从session中获取到currentParentName') console.log("未从session中获取到currentParentName");
console.log('未从session中获取到headBar') console.log("未从session中获取到headBar");
console.log('未从session中获取到CurrentThirdArr') console.log("未从session中获取到CurrentThirdArr");
console.log('未从session中获取到ThirdPath') console.log("未从session中获取到ThirdPath");
console.log('未从session中获取到CurrentSecondPath') console.log("未从session中获取到CurrentSecondPath");
} }
function convertTreeToList(root, array) { function convertTreeToList(root, array) {
if(!root || !root.length) return array; if (!root || !root.length) return array;
root.forEach(item=>{ root.forEach((item) => {
let data = JSON.parse(JSON.stringify(item)); let data = JSON.parse(JSON.stringify(item));
const url = data.url ? data.url : (item.childList[0] ? (item.childList[0].url || '') : ''); const url = data.url
? data.url
: item.childList[0]
? item.childList[0].url || ""
: "";
delete data.childList; delete data.childList;
array.push({ array.push({
name: data.name, name: data.name,
...@@ -39,20 +43,30 @@ function convertTreeToList(root, array) { ...@@ -39,20 +43,30 @@ function convertTreeToList(root, array) {
parentId: data.parentId, parentId: data.parentId,
icon: data.imgPath, icon: data.imgPath,
}); });
if(item.childList){ if (item.childList) {
convertTreeToList(item.childList, array); convertTreeToList(item.childList, array);
} }
}) });
return array; return array;
} }
function isPc() { function isPc() {
var userAgentInfo = navigator.userAgent; var userAgentInfo = navigator.userAgent;
var Agents = new Array("Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"); var Agents = new Array(
var flag = true; "Android",
for (var v = 0; v < Agents.length; v++) { "iPhone",
if (userAgentInfo.indexOf(Agents[v]) > 0) { flag = false; break; } "SymbianOS",
} "Windows Phone",
"iPad",
"iPod"
);
var flag = true;
for (var v = 0; v < Agents.length; v++) {
if (userAgentInfo.indexOf(Agents[v]) > 0) {
flag = false;
break;
}
}
return flag; return flag;
} }
...@@ -60,27 +74,28 @@ export default new Vuex.Store({ ...@@ -60,27 +74,28 @@ export default new Vuex.Store({
state: { state: {
isLogin: false, isLogin: false,
isMobile: !isPc(), isMobile: !isPc(),
userData,//用户数据 userData, //用户数据
group: '', group: "",
headBar, headBar,
currentParentName,//当前选择一级菜单 currentParentName, //当前选择一级菜单
CurrentSecondPath,//当前二级菜单路径 CurrentSecondPath, //当前二级菜单路径
CurrentThirdArr, CurrentThirdArr,
ThirdPath ThirdPath,
}, },
// 同步存储数据 // 同步存储数据
mutations: { mutations: {
setUserData(state, data) { setUserData(state, data) {
data.flat = convertTreeToList(data.barList, []); data.flat = convertTreeToList(data.barList, []);
state.userData = {};
state.userData = Object.assign({}, state.userData, data); state.userData = Object.assign({}, state.userData, data);
state.isLogin = true; state.isLogin = true;
window.sessionStorage.userData = JSON.stringify(data); window.sessionStorage.userData = JSON.stringify(data);
window.sessionStorage.token = data.token; window.sessionStorage.token = data.token;
}, },
// 头部导航栏数据 // 头部导航栏数据
setHeadBar(state,data){ setHeadBar(state, data) {
state.headBar = data state.headBar = data;
window.sessionStorage.headBar = JSON.stringify(data) window.sessionStorage.headBar = JSON.stringify(data);
}, },
logout(state) { logout(state) {
state.userData = {}; state.userData = {};
...@@ -91,44 +106,47 @@ export default new Vuex.Store({ ...@@ -91,44 +106,47 @@ export default new Vuex.Store({
// window.sessionStorage.currentParentName = '' // window.sessionStorage.currentParentName = ''
// window.sessionStorage.CurrentSecondPath = '' // window.sessionStorage.CurrentSecondPath = ''
// window.sessionStorage.CurrentThirdArr = '' // window.sessionStorage.CurrentThirdArr = ''
window.sessionStorage.clear() window.sessionStorage.clear();
}, },
setGroup(state, data) { setGroup(state, data) {
state.group = data; state.group = data;
}, },
// 当前以及导航名 // 当前以及导航名
setCurrentParentName(state,data){ setCurrentParentName(state, data) {
state.currentParentName = data state.currentParentName = data;
window.sessionStorage.currentParentName = data window.sessionStorage.currentParentName = data;
}, },
setCurrentSecondPath(state,data){ setCurrentSecondPath(state, data) {
state.CurrentSecondPath = data state.CurrentSecondPath = data;
window.sessionStorage.CurrentSecondPath = data window.sessionStorage.CurrentSecondPath = data;
}, },
// 当前三级导航栏 // 当前三级导航栏
setCurrentThirdArr(state,data){ setCurrentThirdArr(state, data) {
state.CurrentThirdArr = data state.CurrentThirdArr = data;
window.sessionStorage.CurrentThirdArr = JSON.stringify(data) window.sessionStorage.CurrentThirdArr = JSON.stringify(data);
}, },
// 当前三级导航栏路径 // 当前三级导航栏路径
setThirdPath(state,data){ setThirdPath(state, data) {
state.ThirdPath = data state.ThirdPath = data;
window.sessionStorage.ThirdPath = data window.sessionStorage.ThirdPath = data;
}, },
}, },
// 异步任务 // 异步任务
actions: { actions: {
login({commit}) { login({ commit }) {
normalCallPost('/login/index').then(({data})=>{ normalCallPost("/login/index")
commit('setUserData', data) .then(({ data }) => {
}).catch(error=>{ commit("setUserData", data);
})
}) .catch((error) => {});
}, },
logout({commit}) { logout({ commit }) {
normalCallPost('/login/logout').then(data=>{}).catch(error=>{}).then(()=>{ normalCallPost("/login/logout")
commit('logout') .then((data) => {})
}) .catch((error) => {})
} .then(() => {
} commit("logout");
}) });
},
},
});
...@@ -159,16 +159,16 @@ export default { ...@@ -159,16 +159,16 @@ export default {
this.$store.commit("setCurrentThirdArr", []); this.$store.commit("setCurrentThirdArr", []);
this.$store.commit("setCurrentSecondPath", ""); this.$store.commit("setCurrentSecondPath", "");
this.$store.commit("setThirdPath", ""); this.$store.commit("setThirdPath", "");
this.homeNum(); this.$nextTick(() => {
this.homeNum();
});
}, },
methods: { methods: {
tabChildren(name) { tabChildren(name) {
console.log("name:" + name);
this.$store.commit("setCurrentParentName", name); //存储选择路由 this.$store.commit("setCurrentParentName", name); //存储选择路由
let result = this.menu.find((item) => item.name === name); let result = this.menu.find((item) => item.name === name);
this.$store.commit("setHeadBar", result); this.$store.commit("setHeadBar", result);
console.log("result:", result);
if (result) { if (result) {
// 路由跳转 // 路由跳转
if (result.children.length > 0) { if (result.children.length > 0) {
...@@ -184,6 +184,7 @@ export default { ...@@ -184,6 +184,7 @@ export default {
} }
}, },
mapMenu(arr) { mapMenu(arr) {
console.log(arr);
if (arr.length === 0) return []; if (arr.length === 0) return [];
let result = arr.map((item) => { let result = arr.map((item) => {
const url = item.url const url = item.url
...@@ -203,12 +204,12 @@ export default { ...@@ -203,12 +204,12 @@ export default {
return result; return result;
}, },
// 查询统计数据 // 查询统计数据
homeNum() { async homeNum() {
this.$post("/login/index").then((res) => { await this.$post("/login/index").then((res) => {
const { code, data } = res; const { code, data } = res;
if (code == 1) { if (code == 1) {
this.homeStat = Object.assign({}, this.homeStat, data.homeStat); this.homeStat = Object.assign({}, this.homeStat, data.homeStat);
console.log(data, "####"); this.$store.commit("setUserData", data);
} }
}); });
}, },
......
...@@ -6,45 +6,54 @@ ...@@ -6,45 +6,54 @@
<script> <script>
export default { export default {
name: 'authentication', name: "authentication",
created () { created() {
this.login(); this.login();
}, },
methods: { methods: {
login() { async login() {
this.$post('/login/index').then(this.loginSuccess).catch(this.loginFail) await this.$post("/login/index")
.then(this.loginSuccess)
.catch(this.loginFail);
}, },
loginSuccess({data}) { loginSuccess({ data }) {
this.$store.commit('setUserData', data); this.$store.commit("setUserData", data);
this.$router.replace({ this.$router.replace({
path: this.redirect, path: this.redirect,
}); });
}, },
loginFail(error) { loginFail(error) {
this.$message.error(error.message || '请登录'); this.$message.error(error.message || "请登录");
console.log("href:"+process.env.VUE_APP_PORTAL_URL) console.log("href:" + process.env.VUE_APP_PORTAL_URL);
//window.location.href=process.env.VUE_APP_PORTAL_URL=='undefined'?'http://192.168.0.98:11072':process.env.VUE_APP_PORTAL_URL //window.location.href=process.env.VUE_APP_PORTAL_URL=='undefined'?'http://192.168.0.98:11072':process.env.VUE_APP_PORTAL_URL
console.log(process.env);
window.location.href=process.env.VUE_APP_PORTAL_URL process.env.NODE_ENV == "development"
/* this.$router.replace({ ? this.$router.replace({
path: "/login",
query: {
redirect: this.redirect,
},
})
: (window.location.href = process.env.VUE_APP_PORTAL_URL);
/* this.$router.replace({
path: '/login', path: '/login',
query: { query: {
redirect: this.redirect, redirect: this.redirect,
} }
});*/ });*/
} },
}, },
computed: { computed: {
isLogin() { isLogin() {
return this.$store.state.isLogin return this.$store.state.isLogin;
} },
}, },
data() { data() {
return { return {
redirect: this.$route.query.redirect, redirect: this.$route.query.redirect,
loading: true, loading: true,
} };
} },
} };
</script> </script>
...@@ -68,9 +68,9 @@ export default { ...@@ -68,9 +68,9 @@ export default {
: ""; : "";
}, },
methods: { methods: {
login() { async login() {
this.loading = true; this.loading = true;
this.$post("/login/login", this.form) await this.$post("/login/login", this.form)
.then(this.loginSuccess) .then(this.loginSuccess)
.catch(this.loginFail); .catch(this.loginFail);
}, },
......
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