diff --git a/src/assets/img/login-bg-1.jpg b/src/assets/img/login-bg-1.jpg new file mode 100644 index 0000000..88cf3bb Binary files /dev/null and b/src/assets/img/login-bg-1.jpg differ diff --git a/src/components/page/Login.vue b/src/components/page/Login.vue index 8908ed0..23d52e5 100644 --- a/src/components/page/Login.vue +++ b/src/components/page/Login.vue @@ -1,339 +1,354 @@ \ No newline at end of file diff --git a/src/router/index.js b/src/router/index.js index d26ead8..13f88ca 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -1,19 +1,19 @@ import Vue from 'vue'; import Router from 'vue-router'; import axios from 'axios' -import {getPermission} from '../utils/api' +import { getPermission } from '../utils/api' //解决编程式路由往同一地址跳转时会报错的情况 const originalPush = Router.prototype.push; const originalReplace = Router.prototype.replace; //push -Router.prototype.push = function push(location, onResolve, onReject) { +Router.prototype.push = function push (location, onResolve, onReject) { if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject); return originalPush.call(this, location).catch(err => err); }; //replace -Router.prototype.replace = function push(location, onResolve, onReject) { +Router.prototype.replace = function push (location, onResolve, onReject) { if (onResolve || onReject) return originalReplace.call(this, location, onResolve, onReject); return originalReplace.call(this, location).catch(err => err); @@ -23,7 +23,7 @@ const Home = () => import('../components/common/Home.vue') // 首页 const HomePage = () => import('../components/page/HomePage.vue') // 个人中心 -const Dashboard = () => import('../components/page/Dashboard.vue') +const Dashboard = () => import('../components/page/Dashboard.vue') // 工作台 const Workbench = () => import('../components/page/Workbench.vue') // 人力资源管理 @@ -74,267 +74,268 @@ const noticeDesign = () => import('../components/common/noticeDesign.vue') // 404页面,随便写了个 const notFind = () => import('../components/page/404.vue') // 重载路由,用于权限更新后的重载 -import {resetRouter} from './resetRouter' +import { resetRouter } from './resetRouter' Vue.use(Router); export const constantRouterMap = [ // 默认路由,不需要权限 - { - path: '/', - redirect: '/beforeLogin', - }, - { - path: '/beforeLogin', - component: () => import('../components/page/beforeLogin.vue'), - meta: { title: '智慧管理平台' } - }, - { - path: '/login', - component: () => import('../components/page/Login.vue'), - meta: { title: '登录' } - }, - { - path: '/bind-phone', - component: () => import('../components/page/phoneBind.vue'), - meta: { title: '绑定手机' } - } + { + path: '/', + redirect: '/login', + }, + { + path: '/beforeLogin', + component: () => import('../components/page/beforeLogin.vue'), + meta: { title: '智慧管理平台' } + }, + { + path: '/login', + component: () => import('../components/page/Login.vue'), + meta: { title: '登录' } + }, + { + path: '/bind-phone', + component: () => import('../components/page/phoneBind.vue'), + meta: { title: '绑定手机' } + } ] let router = new Router({ - mode: 'hash', -    base: process.env.BASE_URL, - routes: [] + mode: 'hash', + base: process.env.BASE_URL, + routes: [] }); -export default router +export default router router.addRoutes(constantRouterMap) -function createdRouter(item,val) {// 处理成路由接受对象的方法 - if(item.menuOrNot===1){ - let len,com,obj - // 匹配路由名称对应的component - switch (item.name) { - case '待办事项': com = Dashboard - break; - case '工作台': com = Workbench - break; - case '人力资源管理系统': com = WorkbenchManpower - break; - case '客户资源管理系统': com = WorkbenchClient - break; - case '工作台客户信息': com = WorkbenchClientmessage - break; - case '担保业务管理系统': com = WorkbenchGuarantee - break; - case '后台管理': com = Background - break; - case '客户资源后台管理系统': com = Customer - break; - case '后台客户信息': com = AddCustomer - break; - case '人力资源后台管理系统': com = backgroundManpower - break; - case '担保业务后台管理系统': com = backgroundGuarantee - break; - case '系统管理': com = SystemManagement - break; - case '保后业务管理系统': com = afterLoan - break; - default:console.log('未匹配到文件地址'); - break; - } - // 每个路由对应的数据形式 - obj = { - path:item.menuUrl, - component:com, - meta:{title:item.name,btn:[]}, - children:[] +function createdRouter (item, val) {// 处理成路由接受对象的方法 + if (item.menuOrNot === 1) { + let len, com, obj + // 匹配路由名称对应的component + switch (item.name) { + case '待办事项': com = Dashboard + break; + case '工作台': com = Workbench + break; + case '人力资源管理系统': com = WorkbenchManpower + break; + case '客户资源管理系统': com = WorkbenchClient + break; + case '工作台客户信息': com = WorkbenchClientmessage + break; + case '担保业务管理系统': com = WorkbenchGuarantee + break; + case '后台管理': com = Background + break; + case '客户资源后台管理系统': com = Customer + break; + case '后台客户信息': com = AddCustomer + break; + case '人力资源后台管理系统': com = backgroundManpower + break; + case '担保业务后台管理系统': com = backgroundGuarantee + break; + case '系统管理': com = SystemManagement + break; + case '保后业务管理系统': com = afterLoan + break; + default: console.log('未匹配到文件地址'); + break; + } + // 每个路由对应的数据形式 + obj = { + path: item.menuUrl, + component: com, + meta: { title: item.name, btn: [] }, + children: [] + } + // 判断是否为主路由文件,进行递归匹配 + if (item.children && item.children.length !== 0) { + len = item.children.length + for (let i = 0; i < len; i++) { + obj.meta.btn.push(item.children[i].name)// 权限判断,把非主路由name作为鉴权信息 + if (item.children[i].menuOrNot !== 0) { + // 是页面的话,生成新的obj,赛进父级 + obj.children.push(createdRouter(item.children[i])) } - // 判断是否为主路由文件,进行递归匹配 - if(item.children&&item.children.length!==0){ - len = item.children.length - for(let i=0;i{ - if(res.success){ - sessionStorage.setItem('getRouter','true') - let permissions = { - path: '/', - component: Home, - meta: { title: '' }, - children: [ - { - path: '/homePage', - component: HomePage, - meta: { title: '首页' ,btn:[]} - }, - { - path: '/workbench', - component: () => import('../components/page/Workbench.vue'), - meta: { title: '工作台' ,btn:[]}, - children: [ - { - path: '/workbench-manpower', - component: WorkbenchManpower, - meta: { title: '人力资源管理',btn:[] } - }, - { - path: '/workbench-client-message', - component: WorkbenchClientmessage, - meta: { title: '工作台客户信息', btn:[]} - } - ] - }, - ] - }, - len = res.data.length, - homeMenu = [] - // console.log(res.data,'路由处理,工作台和非工作台路由匹配') + return obj + } else return +} +router.beforeEach(function (to, from, next) { + if (to.path == '/login') { + sessionStorage.removeItem('token') + } + if (sessionStorage.getItem('token')) { + if (!sessionStorage.getItem('success')) {// 记录路由是否处理过 + getPermission().then(res => { + if (res.success) { + sessionStorage.setItem('getRouter', 'true') + let permissions = { + path: '/', + component: Home, + meta: { title: '' }, + children: [ + { + path: '/homePage', + component: HomePage, + meta: { title: '首页', btn: [] } + }, + { + path: '/workbench', + component: () => import('../components/page/Workbench.vue'), + meta: { title: '工作台', btn: [] }, + children: [ + { + path: '/workbench-manpower', + component: WorkbenchManpower, + meta: { title: '人力资源管理', btn: [] } + }, + { + path: '/workbench-client-message', + component: WorkbenchClientmessage, + meta: { title: '工作台客户信息', btn: [] } + } + ] + }, + ] + }, + len = res.data.length, + homeMenu = [] + // console.log(res.data,'路由处理,工作台和非工作台路由匹配') - // 此处为主路由页面的操作,通过对应的 createdRouter 函数进行路由数据处理,文件地址分配 - for(let i=0;i{ - console.log(err,'路由处理出错') - let errPage = { - path: '*', - redirect: '/login' - } - router.addRoutes([errPage]) - }) + // 此处为主路由页面的操作,通过对应的 createdRouter 函数进行路由数据处理,文件地址分配 + for (let i = 0; i < len; i++) { + //匹配非工作台的路由 + if (res.data[i].name !== '客户资源管理系统' && res.data[i].name !== '担保业务管理系统' && res.data[i].name !== '保后业务管理系统') { + permissions.children.push(createdRouter(res.data[i])) + homeMenu.push(res.data[i].name) + } else { + permissions.children[1].meta.btn.push(res.data[i].name) + permissions.children[1].children.push(createdRouter(res.data[i])) + } + } + // 记录主页顶部大按钮的值(路由主页面权限) + router.app.$options.store.commit("homeMenuData", { homeMenu: homeMenu }); + let errPage = [ + { + path: '*', + redirect: '/404' + }, + { + path: '/404', + component: notFind, + meta: { title: '找不到页面', btn: [] } + } + ] + router.addRoutes([permissions]) + router.addRoutes(errPage) + sessionStorage.setItem('routerData', JSON.stringify([permissions])) + // 处理过路由否 + sessionStorage.setItem('success', true) } - }else{ - if (to.path !== '/login'&&to.path !=="/beforeLogin"&&to.path !=='/bind-phone') { - next({ path: '/login', - query:{redirect:to.path} - }) + }).catch(err => { + console.log(err, '路由处理出错') + let errPage = { + path: '*', + redirect: '/login' } + router.addRoutes([errPage]) + }) + } + } else { + if (to.path !== '/login' && to.path !== "/beforeLogin" && to.path !== '/bind-phone') { + next({ + path: '/login', + query: { redirect: to.path } + }) } - // 根据路由元信息设置文档标题 - window.document.title = to.meta.title || '智慧管理' - next() + } + // 根据路由元信息设置文档标题 + window.document.title = to.meta.title || '智慧管理' + next() }) \ No newline at end of file diff --git a/src/utils/api.js b/src/utils/api.js index ddc59b1..6c4bcf3 100644 --- a/src/utils/api.js +++ b/src/utils/api.js @@ -1,4 +1,4 @@ -import {get,post,put,del,Url} from './http'; +import { get, post, put, del, Url } from './http'; let host = Url; export const login = p => post('/apiHrmsAuth/hrms/auth/userlogin/login', p); export const phoneCode = p => get('/apiHrmsAuth/hrms/auth/userlogin/sendCode', p); @@ -94,7 +94,7 @@ export const personnelSelection = p => get('/api-guarantee/al-collection-statist export const annualStatisticsDeleted = p => post(`/api-guarantee/al-collection-statistics/annualStatisticsDeleted?year=${p}`); export const annualStatisticsListExport = p => `${host}/api-guarantee/al-collection-statistics/annualStatisticsListExport?year=${p}` export const importInsurance = `${host}/api-guarantee/al-insurance-list/importInsurance`; -export const exportFailure = p=> `${host}/api-guarantee/al-insurance-list/exportFailure?exportCode=${p}`; +export const exportFailure = p => `${host}/api-guarantee/al-insurance-list/exportFailure?exportCode=${p}`; @@ -108,7 +108,7 @@ export const collectionListDetail = p => get('/api-guarantee/al-collection/overd export const modifyReimbursement = p => get('/api-guarantee/al-reimbursement/modifyReimbursement', p);// 查清收组人员 export const collectionHisList = p => post('/api-guarantee/al-collection/collection/list', p); export const updateCollection = p => post('/api-guarantee/al-collection/updateCollection', p);// 编辑催收记录 -export const delCollection = p => post('/api-guarantee/al-collection/delCollection?id='+p);// 删除催收记录 +export const delCollection = p => post('/api-guarantee/al-collection/delCollection?id=' + p);// 删除催收记录 export const collectionHisListDetail = p => get('/api-guarantee/al-collection/examine/detail', p); export const excelInsurance = `${host}/api-guarantee/al-insurance-list/excelExport`; diff --git a/src/utils/http.js b/src/utils/http.js index ffac35a..a4b76ad 100644 --- a/src/utils/http.js +++ b/src/utils/http.js @@ -3,11 +3,12 @@ import axios from 'axios'; // import store from '../store/index' import { Message } from 'element-ui' import router from '../router/index' - + // 服务器的切换 // export const Url = 'https://test.feifanhitech.com'// 测试服务器地址 -export const Url = 'https://www.feifanhitech.com';// 非凡(正式服) -// export const Url = 'http://192.168.31.137:8080';//陈赓 +// export const Url = 'https://www.feifanhitech.com';// 非凡(正式服) +// export const Url = 'http://192.168.31.51:8089';//陈赓 +export const Url = 'http://10.0.0.40:8089'; axios.defaults.baseURL = Url; const baseurl = Url // 请求超时时间 @@ -17,145 +18,145 @@ axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded // 请求拦截器 axios.interceptors.request.use(config => { - if (sessionStorage.getItem('token')) { - config.headers.token = `${sessionStorage.getItem('token')}`; - } - return config; + if (sessionStorage.getItem('token')) { + config.headers.token = `${sessionStorage.getItem('token')}`; + } + return config; }, err => { - return Promise.reject(err); + return Promise.reject(err); }) // 响应拦截器 axios.interceptors.response.use( - response => { - if (response.data.code === 10000) { - return Promise.resolve(response); - } else - if(response.data.code === 401){ + response => { + if (response.data.code === 10000) { + return Promise.resolve(response); + } else + if (response.data.code === 401) { + Message.error('登录过期,请重新登录!'); + // 清除token + sessionStorage.removeItem('token'); + localStorage.removeItem('token') + // 跳转登录页面,并将要浏览的页面fullPath传过去,登录成功后跳转需要访问的页面 + setTimeout(() => { + router.replace({ + path: '/login', + query: { + redirect: router.currentRoute.fullPath + } + }); + }, 1000); + } else { + if (response.data.message) { + Message.error(response.data.message); + } + return Promise.reject(response) + // return Promise.reject(response); + } + }, + // 服务器状态码不是200的情况 + error => { + if (error.response) { + if (error.response.status) { + switch (error.response.status) { + // 401: 未登录 + // 未登录则跳转登录页面,并携带当前页面的路径 + // 在登录成功后返回当前页面,这一步需要在登录页操作。 + case 403: + router.replace({ + path: '/login', + query: { redirect: router.currentRoute.fullPath } + }); + break; + // 403 token过期 + // 登录过期对用户进行提示 + // 清除本地token和清空vuex中token对象 + // 跳转登录页面 + case 401: Message.error('登录过期,请重新登录!'); // 清除token sessionStorage.removeItem('token'); localStorage.removeItem('token') + // store.commit('loginSuccess', null); // 跳转登录页面,并将要浏览的页面fullPath传过去,登录成功后跳转需要访问的页面 setTimeout(() => { - router.replace({ - path: '/login', - query: { - redirect: router.currentRoute.fullPath - } - }); - }, 1000); - }else{ - if(response.data.message){ - Message.error(response.data.message); - } - return Promise.reject(response) - // return Promise.reject(response); - } - }, - // 服务器状态码不是200的情况 - error => { - if(error.response){ - if (error.response.status) { - switch (error.response.status) { - // 401: 未登录 - // 未登录则跳转登录页面,并携带当前页面的路径 - // 在登录成功后返回当前页面,这一步需要在登录页操作。 - case 403: - router.replace({ - path: '/login', - query: { redirect: router.currentRoute.fullPath } - }); - break; - // 403 token过期 - // 登录过期对用户进行提示 - // 清除本地token和清空vuex中token对象 - // 跳转登录页面 - case 401: - Message.error('登录过期,请重新登录!'); - // 清除token - sessionStorage.removeItem('token'); - localStorage.removeItem('token') - // store.commit('loginSuccess', null); - // 跳转登录页面,并将要浏览的页面fullPath传过去,登录成功后跳转需要访问的页面 - setTimeout(() => { - router.replace({ - path: '/login', - query: { - redirect: router.currentRoute.fullPath - } - }); - }, 1000); - break; - // 404请求不存在 - case 404: - Message.error('网络请求不存在!'); - break; - // 404请求不存在 - case 500: - Message.error('网络请求出错!'); - break; - // 其他错误,直接抛出错误提示 - default: - Message.error(error.response.errmessage); + router.replace({ + path: '/login', + query: { + redirect: router.currentRoute.fullPath } - return Promise.reject(error.response); - } + }); + }, 1000); + break; + // 404请求不存在 + case 404: + Message.error('网络请求不存在!'); + break; + // 404请求不存在 + case 500: + Message.error('网络请求出错!'); + break; + // 其他错误,直接抛出错误提示 + default: + Message.error(error.response.errmessage); } + return Promise.reject(error.response); + } } + } ); /** get方法,对应get请求---sb封装,本身axios就是封装的promis **/ -export function get(url, params){ - return new Promise((resolve, reject) =>{ - axios.get(url, { - params: params - }) - .then(res => { - resolve(res.data); - }) - .catch(err => { - reject(err.data) - }) - }); +export function get (url, params) { + return new Promise((resolve, reject) => { + axios.get(url, { + params: params + }) + .then(res => { + resolve(res.data); + }) + .catch(err => { + reject(err.data) + }) + }); } /** post方法,对应post请求 **/ -export function post(url, params) { - return new Promise((resolve, reject) => { - axios.post(url,params) - .then(res => { - resolve(res.data); - }) - .catch(err => { - reject(err.data) - }) - }); +export function post (url, params) { + return new Promise((resolve, reject) => { + axios.post(url, params) + .then(res => { + resolve(res.data); + }) + .catch(err => { + reject(err.data) + }) + }); } /** delete方法,对应delete请求 **/ - export function del(url, params){ - return new Promise((resolve, reject) =>{ - axios.delete(url, { - data: params - }) - .then(res => { - resolve(res.data); - }) - .catch(err => { - reject(err.data) - }) - }); +export function del (url, params) { + return new Promise((resolve, reject) => { + axios.delete(url, { + data: params + }) + .then(res => { + resolve(res.data); + }) + .catch(err => { + reject(err.data) + }) + }); } /** put修改 **/ -export function put(url, params){ - return new Promise((resolve, reject) =>{ - axios.put(url, params) - .then(res => { - resolve(res.data); - }) - .catch(err => { - reject(err.data) - }) - }); +export function put (url, params) { + return new Promise((resolve, reject) => { + axios.put(url, params) + .then(res => { + resolve(res.data); + }) + .catch(err => { + reject(err.data) + }) + }); } \ No newline at end of file