diff --git a/package.json b/package.json index 39247c2..86b1ed9 100644 --- a/package.json +++ b/package.json @@ -16,11 +16,13 @@ "emittery": "^0.8.1", "file-saver": "2.0.5", "js-cookie": "^3.0.5", + "nprogress": "0.2.0", "less": "^4.1.3", "less-loader": "^11.1.3", "lodash.debounce": "^4.0.8", "logt": "^1.4.1", "vue": "^2.6.14", + "vuex": "3.6.0", "vue-router": "^3.1.3" }, "devDependencies": { diff --git a/public/css/largeScreenStyle.css b/public/css/largeScreenStyle.css index 70d9409..72c64fd 100644 --- a/public/css/largeScreenStyle.css +++ b/public/css/largeScreenStyle.css @@ -165,8 +165,7 @@ table{ width: 45%; text-align: center; } -.head-title-weather{ - width: 55%; +.head-title-weather{ display: flex; align-items: center; } diff --git a/src/api/dept/index.js b/src/api/dept/index.js index 75f4b50..0bd7c82 100644 --- a/src/api/dept/index.js +++ b/src/api/dept/index.js @@ -2,9 +2,9 @@ import request from '@/utils/request' // 查询流程表单列表 -const list=()=> { +const list=(roleId)=> { return request({ - url: 'bgscreen/dept/list', + url: 'bgscreen/dept/list?roleId='+(roleId||1), method: 'get' }) } diff --git a/src/api/login/index.js b/src/api/login/index.js new file mode 100644 index 0000000..e6835aa --- /dev/null +++ b/src/api/login/index.js @@ -0,0 +1,47 @@ +import request from '@/utils/request' + +// 登录方法 +function login(username, password, code, uuid) { + const data = { + username, + password, + code, + uuid + } + return request({ + url: '/login', + headers: { + isToken: false + }, + method: 'post', + data: data + }) +} + + +// 获取用户详细信息 +function getInfo() { + return request({ + url: '/getInfo', + method: 'get' + }) + } + +// 退出方法 +function logout() { + return request({ + url: '/logout', + method: 'post' + }) + } + +export { + login, + logout, + getInfo +} +export default { + login, + logout, + getInfo +} \ No newline at end of file diff --git a/src/assets/images/profile.png b/src/assets/images/profile.png new file mode 100644 index 0000000..8e5b56e Binary files /dev/null and b/src/assets/images/profile.png differ diff --git a/src/assets/images/profile1.png b/src/assets/images/profile1.png new file mode 100644 index 0000000..b08edec Binary files /dev/null and b/src/assets/images/profile1.png differ diff --git a/src/components/header.vue b/src/components/header.vue index 51ad6b2..54bf878 100644 --- a/src/components/header.vue +++ b/src/components/header.vue @@ -1,259 +1,318 @@ - \ No newline at end of file +} \ No newline at end of file diff --git a/src/main.js b/src/main.js index b411d44..0f9ef81 100644 --- a/src/main.js +++ b/src/main.js @@ -1,11 +1,14 @@ import Vue from 'vue' import App from './App.vue' +import store from './store' import router from './router' +import './permission' import './pages/init.js' Vue.config.productionTip = false new Vue({ router, + store, render: h => h(App) }).$mount('#app') diff --git a/src/pages/style/index.less b/src/pages/style/index.less index 7322c67..d2042b4 100644 --- a/src/pages/style/index.less +++ b/src/pages/style/index.less @@ -131,4 +131,17 @@ } } } +} +.el-message-box{ + background-color: rgba(1, 169, 255,0.5); + border: solid 1px rgba(1, 169, 255,1); +} +.el-message-box__title{ + color: #000; +} +.el-message-box__btns{ + text-align: center; +} +.el-message-box__content{ + color: #fff; } \ No newline at end of file diff --git a/src/permission.js b/src/permission.js new file mode 100644 index 0000000..1e7f593 --- /dev/null +++ b/src/permission.js @@ -0,0 +1,57 @@ +import router from './router' +import store from './store' +import { Message } from 'element-ui' +import NProgress from 'nprogress' +import 'nprogress/nprogress.css' +import { getToken } from '@/utils/auth' +import { isRelogin } from '@/utils/request' + +NProgress.configure({ showSpinner: false }) + +const whiteList = [] + +router.beforeEach((to, from, next) => { + NProgress.start() + if (getToken()) { + to.meta.title && store.dispatch('settings/setTitle', to.meta.title) + /* has token*/ + if (to.path === '/login') { + next({ path: '/' }) + NProgress.done() + } else { + if (store.getters.roles.length === 0) { + isRelogin.show = true + // 判断当前用户是否已拉取完user_info信息 + store.dispatch('GetInfo').then(() => { + isRelogin.show = false + next(); + }).catch(err => { + store.dispatch('LogOut').then(() => { + Message.error(err) + next({ path: '/' }) + }) + }) + } else { + next() + } + } + } else { + // 没有token + if (whiteList.indexOf(to.path) !== -1) { + // 在免登录白名单,直接进入 + next() + } else { + //next(`/login?redirect=#/index`) // 否则全部重定向到登录页 + let base="/"; + if(location.host.indexOf("localhost")>=0){ + base="/jhapp/" + } + location.href=base+"#/login?redirect=/jhbs/#/"; + NProgress.done() + } + } +}) + +router.afterEach(() => { + NProgress.done() +}) diff --git a/src/store/getters.js b/src/store/getters.js new file mode 100644 index 0000000..e73b3b7 --- /dev/null +++ b/src/store/getters.js @@ -0,0 +1,13 @@ +const getters = { + token: state => state.user.token, + avatar: state => state.user.avatar, + userId: state => state.user.userId, + name: state => state.user.name, + dept:state=>state.user.dept, + introduction: state => state.user.introduction, + roles: state => state.user.roles, + nickName:state=>state.user.nickName, + roleId:state=>state.user.roleId, + permissions: state => state.user.permissions, +} +export default getters diff --git a/src/store/index.js b/src/store/index.js new file mode 100644 index 0000000..3ca1427 --- /dev/null +++ b/src/store/index.js @@ -0,0 +1,17 @@ +import Vue from 'vue' +import Vuex from 'vuex' +import user from './modules/user' +import getters from './getters' + +Vue.use(Vuex) + +const store = new Vuex.Store({ + modules: { + user + }, + getters + }) + + export default store + + \ No newline at end of file diff --git a/src/store/modules/user.js b/src/store/modules/user.js new file mode 100644 index 0000000..3cee5c7 --- /dev/null +++ b/src/store/modules/user.js @@ -0,0 +1,118 @@ +import { login, logout, getInfo } from '@/api/login' +import { getToken, setToken, removeToken } from '@/utils/auth' + + +const user = { + state: { + token: getToken(), + userId:'', + name: '', + nickName:'', + roleId:0, + avatar: '', + dept:null, + roles: [], + permissions: [] + }, + + mutations: { + SET_TOKEN: (state, token) => { + state.token = token + }, + SET_USER_ID: (state, id) => { + state.userId = id + }, + SET_NAME: (state, name) => { + state.name = name + }, + SET_NICKNAME: (state, nickName) => { + state.nickName = nickName + }, + SET_ROLEID: (state, roleId) => { + state.roleId = roleId + }, + SET_AVATAR: (state, avatar) => { + state.avatar = avatar + }, + SET_ROLES: (state, roles) => { + state.roles = roles + }, + SET_PERMISSIONS: (state, permissions) => { + state.permissions = permissions + }, + SET_DEPT: (state, dept) => { + state.dept = dept + } + }, + + actions: { + // 登录 + Login({ commit }, userInfo) { + const username = userInfo.username.trim() + const password = userInfo.password + const code = userInfo.code + const uuid = userInfo.uuid + return new Promise((resolve, reject) => { + login(username, password, code, uuid).then(res => { + setToken(res.token) + commit('SET_TOKEN', res.token) + resolve() + }).catch(error => { + reject(error) + }) + }) + }, + + // 获取用户信息 + GetInfo({ commit, state }) { + return new Promise(async (resolve, reject) => { + let res=await getInfo() + const user = res.user + const avatar = (user.avatar == "" || user.avatar == null) ? require("@/assets/images/profile.png") : process.env.VUE_APP_BASE_API + user.avatar; + if (res.roles && res.roles.length > 0) { // 验证返回的roles是否是一个非空数组 + commit('SET_ROLES', res.roles) + commit('SET_PERMISSIONS', res.permissions) + } else { + commit('SET_ROLES', ['ROLE_DEFAULT']) + } + commit('SET_USER_ID', user.userId) + commit('SET_NAME', user.userName) + commit('SET_NICKNAME', user.nickName) + commit('SET_ROLEID', res.roleId) + commit("SET_DEPT",user.dept); + commit('SET_AVATAR', avatar) + resolve(res) + }).catch(error => { + reject(error) + }) + }, + + // 退出系统 + LogOut({ commit, state }) { + return new Promise((resolve, reject) => { + logout(state.token).then(() => { + commit('SET_TOKEN', '') + commit("SET_DEPT",null); + commit('SET_ROLES', []) + commit('SET_PERMISSIONS', []) + removeToken() + resolve() + }).catch(error => { + reject(error) + }) + }) + }, + + // 前端 登出 + FedLogOut({ commit }) { + return new Promise(resolve => { + commit('SET_TOKEN', '') + removeToken() + resolve() + }) + } + } + } + + export default user + \ No newline at end of file diff --git a/src/utils/request.js b/src/utils/request.js index b73bbbe..ea075e7 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -51,7 +51,6 @@ service.interceptors.request.use(config => { const interval = 1000; // 间隔时间(ms),小于此时间视为重复提交 if (s_data === requestObj.data && requestObj.time - s_time < interval && s_url === requestObj.url) { const message = '数据正在处理,请勿重复提交'; - //console.warn(`[${s_url}]: ` + message+",",config,s_url) console.warn("--->",s_data,requestObj.data,s_url) return Promise.reject(new Error(message)) } else { @@ -81,7 +80,7 @@ service.interceptors.response.use(res => { MessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', { confirmButtonText: '重新登录', cancelButtonText: '取消', type: 'warning' }).then(() => { isRelogin.show = false; if(location.href.indexOf("localhost")>=0){ - //location.href = `/#/login?redirect=${encodeURIComponent("http://localhost:3000/jhbs/")}`; + //location.href = `/#/login?redirect=${encodeURIComponent("/jhbs/")}`; location.href=`http://localhost/#/login?redirect=${encodeURI('http://localhost:3000/jhbs/')}` }else{ location.href = `/#/login?redirect=${encodeURIComponent("/jhbs/")}`; diff --git a/vue.config.js b/vue.config.js index 5272f8a..1dd7088 100644 --- a/vue.config.js +++ b/vue.config.js @@ -1,7 +1,7 @@ const { defineConfig } = require('@vue/cli-service') module.exports = defineConfig({ transpileDependencies: true, - publicPath :'./' , + publicPath :'/jhbs' , productionSourceMap:false, devServer: { host: '0.0.0.0', @@ -15,6 +15,13 @@ module.exports = defineConfig({ '^/jhapi/profile':'/' } }, + '/jhapp':{ + target: `http://62.234.3.186/`, + changeOrigin: true, + pathRewrite: { + '^/jhapp':'/' + } + }, '/cesium':{ target: `http://62.234.3.186/cesium/`, changeOrigin: true, diff --git a/yarn.lock b/yarn.lock index 29ac13d..a11cc65 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4450,6 +4450,11 @@ npm-run-path@^4.0.1: dependencies: path-key "^3.0.0" +nprogress@0.2.0: + version "0.2.0" + resolved "https://registry.npmmirror.com/nprogress/-/nprogress-0.2.0.tgz#cb8f34c53213d895723fcbab907e9422adbcafb1" + integrity sha512-I19aIingLgR1fmhftnbWWO3dXc0hSxqHQHQb3H8m+K3TnEn/iSeTZZOyvKXWqQESMwuUVnatlCnZdLBZZt2VSA== + nth-check@^2.0.1: version "2.1.1" resolved "https://registry.npmmirror.com/nth-check/-/nth-check-2.1.1.tgz" @@ -6001,6 +6006,11 @@ vue@^2.6.14: "@vue/compiler-sfc" "2.7.14" csstype "^3.1.0" +vuex@3.6.0: + version "3.6.0" + resolved "https://registry.npmmirror.com/vuex/-/vuex-3.6.0.tgz#95efa56a58f7607c135b053350833a09e01aa813" + integrity sha512-W74OO2vCJPs9/YjNjW8lLbj+jzT24waTo2KShI8jLvJW8OaIkgb3wuAMA7D+ZiUxDOx3ubwSZTaJBip9G8a3aQ== + watchpack@^2.4.0: version "2.4.0" resolved "https://registry.npmmirror.com/watchpack/-/watchpack-2.4.0.tgz"