project init

This commit is contained in:
zxy
2024-02-02 10:23:22 +08:00
commit dc7051417b
681 changed files with 142886 additions and 0 deletions

207
src/router/avue-router.js Normal file
View File

@@ -0,0 +1,207 @@
let RouterPlugin = function () {
this.$router = null;
this.$store = null;
};
RouterPlugin.install = function (vue, router, store, i18n) {
this.$router = router;
this.$store = store;
this.$vue = new vue({i18n});
// 这个的作用是 为了检查出网页链接,因为本项目用到了 iframe
function isURL(s) {
if (s.includes('html')) return true;
return /^http[s]?:\/\/.*/.test(s)
}
// 将参数处理为参数的形式拼接
function objToform(obj) {
let result = [];
Object.keys(obj).forEach(ele => {
result.push(`${ele}=${obj[ele]}`);
})
return result.join('&');
}
this.$router.$avueRouter = {
//全局配置
$website: this.$store.getters.website,
routerList: [],
group: '',
meta: {},
safe: this,
// 设置标题
setTitle: (title) => {
const defaultTitle = this.$vue.$t('title');
title = title ? `${title}-${defaultTitle}` : defaultTitle;
document.title = title;
},
closeTag: (value) => {
let tag = value || this.$store.getters.tag;
if (typeof value === 'string') {
tag = this.$store.getters.tagList.filter(ele => ele.value === value)[0]
}
this.$store.commit('DEL_TAG', tag)
},
generateTitle: (title, key) => {
if (!key) return title;
const hasKey = this.$vue.$te('route.' + key)
if (hasKey) {
// $t :this method from vue-i18n, inject in @/lang/index.js
const translatedTitle = this.$vue.$t('route.' + key)
return translatedTitle
}
return title
},
//处理路由
getPath: function (params) {
let {src} = params;
let result = src || '/';
if (isURL(src)) {
result = `/myiframe/urlPath?${objToform(params)}`;
}
return result;
},
//正则处理路由
vaildPath: function (list, path) {
let result = false;
list.forEach(ele => {
if (new RegExp("^" + ele + ".*", "g").test(path)) {
result = true
}
})
return result;
},
//设置路由值
getValue: function (route) {
let value = "";
if (route.query.src) {
value = route.query.src;
} else {
value = route.path;
}
return value;
},
//动态路由
// 路由是专门的一个接口获取
/**
* aMenu: 接受到的动态路由数据 menu的结构外层有父级path 里面有一个childen 记录页面的路由
* first: 为了区分外界 调用formatRoutes 和 当前文件调用 formatRoutes
*/
formatRoutes: function (aMenu = [], first) {
// window.console.log('aMenu')
// window.console.log(aMenu)
const aRouter = []
// 获取到全局配置中的 props
const propsConfig = this.$website.menu.props;
// 设置 props默认值 作用就是将字段设置成配置的
const propsDefault = {
label: propsConfig.label || 'name',
path: propsConfig.path || 'path',
icon: propsConfig.icon || 'icon',
children: propsConfig.children || 'children',
meta: propsConfig.meta || 'meta',
}
// 如果没有权限菜单就结束
if (aMenu.length === 0) return;
// 开始处理menu
for (let i = 0; i < aMenu.length; i++) {
// 取到当前要处理的一项
const oMenu = aMenu[i];
// 判断this.routerList中是否已经存在该path存在就跳出
if (this.routerList.includes(oMenu[propsDefault.path])) return;
// 这一块的赋值 也就是取到返回的值
let path = (() => {
if (first) {
// 将 '/index' 替换为 ''
return oMenu[propsDefault.path].replace('/index', '')
} else {
return oMenu[propsDefault.path]
}
})(),
//特殊处理组件 执行完这个 component 也就是精确到具体的文件了 views文件夹下面就是具体的页面代码
component = 'views' + oMenu.path,
name = oMenu[propsDefault.label],
icon = oMenu[propsDefault.icon],
children = oMenu[propsDefault.children],
meta = oMenu[propsDefault.meta] || {},
code = oMenu.code;
// meta中 keepalive 的处理
meta = Object.assign(meta, (function (code) {
// if (meta.keepAlive === true) {
// return {
// $keepAlive: true
// }
// }
return { $keepAlive: true, code }
})(code));
//是否有子路由
const isChild = children.length !== 0;
const oRouter = {
path: path,
component(resolve) {
// 判断是否为首路由
if (first) {
require(['../page/index'], resolve)
return
// 判断是否为多层路由
} else if (isChild && !first) {
require(['../page/index/layout'], resolve)
return
// 判断是否为最终的页面视图
} else {
require([`../${component}.vue`], resolve)
}
},
name: name,
icon: icon,
meta: meta,
redirect: (() => {
// 第一次进来但是没有子路由的 需要添加redirect
if (!isChild && first && !isURL(path)) return `${path}/index`
else return '';
})(),
// 整理子路由的route 配置
// 处理是否为一级路由
children: !isChild ? (() => {
if (first) {
// 这里的isURL判断因为这个网站有使用 iframe。所以需要判断是否为网页链接
if (!isURL(path)) oMenu[propsDefault.path] = `${path}/index`;
return [{
component(resolve) {
require([`../${component}.vue`], resolve)
},
icon: icon,
name: name,
meta: meta,
path: 'index'
}]
}
return [];
})() : (() => {
/**
* 这里是重点,当有子路由的时候 会再去执行 formatRoutes 方法,然后又会有一个新的 aMenu for循环。
* 最后返回的是一个数组 aRouter 这个数组就会作为 childen的值被 return
*/
return this.formatRoutes(children, false)
})()
}
aRouter.push(oRouter)
}
// for循环结束
// 这个first 卡的其实就是首路由
if (first) {
if (!this.routerList.includes(aRouter[0][propsDefault.path])) {
this.safe.$router.addRoutes(aRouter)
this.routerList.push(aRouter[0][propsDefault.path])
}
} else {
// 这里返回的是子组件
return aRouter
}
}
}
}
export default RouterPlugin;

85
src/router/axios.js Normal file
View File

@@ -0,0 +1,85 @@
/**
* 全站http配置
*
* axios参数说明
* isSerialize是否开启form表单提交
* isToken是否需要token
*/
import 'nprogress/nprogress.css';
import website from '@/config/website';
import router from '@/router/router';
import store from '@/store/';
import {getToken} from '@/util/auth';
import {serialize} from '@/util/util';
import axios from 'axios';
import {Message} from 'element-ui';
import {Base64} from 'js-base64';
import NProgress from 'nprogress';
//默认超时时间
axios.defaults.timeout = 60000;
//返回其他状态码
axios.defaults.validateStatus = function(status) {
return status >= 200 && status <= 500;
};
//跨域请求允许保存cookie
axios.defaults.withCredentials = true;
// NProgress 配置
NProgress.configure({showSpinner: false});
// http request拦截
axios.interceptors.request.use(config => {
//开启 progress bar
NProgress.start();
const meta = (config.meta || {});
const isToken = meta.isToken === false;
config.headers['Authorization'] =
`Basic ${Base64.encode(`${website.clientId}:${website.clientSecret}`)}`;
if (getToken() && !isToken) {
//让每个请求携带token--['Authorization']为自定义key 请根据实际情况自行修改
config.headers['Jobslink-Auth'] = 'bearer ' + getToken()
}
// headers中配置serialize为true开启序列化
if (config.method === 'post' && meta.isSerialize === true) {
config.data = serialize(config.data);
}
return config
}, error => {return Promise.reject(error)});
// http response 拦截
axios.interceptors.response.use(
res => {
//关闭 progress bar
NProgress.done();
//获取状态码
const status = res.data.code || res.status;
const statusWhiteList = website.statusWhiteList || [];
const message = res.data.msg || res.data.error_description || '未知错误';
//如果在白名单里则自行catch逻辑处理
if (statusWhiteList.includes(status)) return Promise.reject(res);
//如果是401则跳转到登录页面
if (status === 401)
store.dispatch('FedLogOut').then(() => router.push({path: '/login'}));
// 如果请求为500统一处理
const err = new Error(message)
err.response = res
err.status = status
if (message.length > 100) {
Message({message: '系统繁忙', type: 'error'});
return Promise.reject(err)
}
// 如果请求为非200否者默认统一处理
if (status !== 200) {
Message({message: message, type: 'error'});
return Promise.reject(err, res)
}
return res;
},
error => {
NProgress.done();
if (error.message.includes('timeout')) {
Message({message: '请求超时', type: 'error'});
}
return Promise.reject(new Error(error), error);
});
export default axios;

59
src/router/page/index.js Normal file
View File

@@ -0,0 +1,59 @@
import Layout from '@/page/index/'
export default [
{
path: '/login',
name: '登录页',
component: () =>
import(/* webpackChunkName: "page" */ '@/page/login/index'),
meta: {keepAlive: true, isTab: false, isAuth: false}
},
{
path: '/reg',
name: '企业注册',
component: () =>
import(/* webpackChunkName: "views" */ '@/page/login/userRegister'),
meta: {keepAlive: true, isTab: false, isAuth: false}
},
{
path: '/lock',
name: '锁屏页',
component: () => import(/* webpackChunkName: "page" */ '@/page/lock/index'),
meta: {keepAlive: true, isTab: false, isAuth: false}
},
{
path: '/404',
component: () =>
import(/* webpackChunkName: "page" */ '@/components/error-page/404'),
name: '404',
meta: {keepAlive: true, isTab: false, isAuth: true}
},
{
path: '/403',
component: () =>
import(/* webpackChunkName: "page" */ '@/components/error-page/403'),
name: '403',
meta: {keepAlive: true, isTab: false, isAuth: false}
},
{
path: '/500',
component: () =>
import(/* webpackChunkName: "page" */ '@/components/error-page/500'),
name: '500',
meta: {keepAlive: true, isTab: false, isAuth: false}
},
{path: '/', name: '主页', redirect: '/wel'}, {
path: '/myiframe',
component: Layout,
redirect: '/myiframe',
children: [{
path: ':routerPath',
name: 'iframe',
component: () =>
import(/* webpackChunkName: "page" */ '@/components/iframe/main'),
props: true
}]
},
{path: '*', redirect: '/404'}
]

48
src/router/router.js Normal file
View File

@@ -0,0 +1,48 @@
/**
* 全站路由配置
*
* meta参数说明
* keepAlive是否缓冲页面
* isTab是否加入到tag导航
* isAuth是否需要授权
*/
import Vue from 'vue';
import VueRouter from 'vue-router';
import PageRouter from './page/' // 页面路由
import ViewsRouter from './views/' // 页面路由
import AvueRouter from './avue-router'; //封装的路由控制方法
import i18n from '@/lang' // Internationalization 国际化 多语言
import Store from '../store/'; // vuex
Vue.use(VueRouter)
//创建路由
export const createRouter = () => new VueRouter({
// https://router.vuejs.org/zh/guide/advanced/scroll-behavior.html#%E5%BC%82%E6%AD%A5%E6%BB%9A%E5%8A%A8
// 这个方法 是控制滚动条
// 如果 retuen falsy || {} ,则不发生滚动
scrollBehavior (to, from, savedPosition) {
// savedPosition 这个参数当且仅当导航 (通过浏览器的 前进/后退 按钮触发) 时才可用 效果和 router.go() 或 router.back()
if (savedPosition) {
// 返回savedPosition 其实就是 当用户点击 返回的话,保持之前游览的高度
return savedPosition
} else {
if (from.meta.keepAlive) {
from.meta.savedPosition = document.body.scrollTop
}
return {
x: 0,
y: to.meta.savedPosition || 0
}
}
},
routes: [...PageRouter, ...ViewsRouter]
})
const Router = createRouter() // 获得 route 实例
AvueRouter.install(Vue, Router, Store, i18n); // 初始化和注册 AvueRouter
Router.$avueRouter.formatRoutes(Store.state.user.menuAll, true); // 动态路由核心方法
Router.addRoutes([...PageRouter, ...ViewsRouter]);
export function resetRouter () { // 重置路由 比如用于身份验证失败,需要重新登录时 先清空当前的路有权限
const newRouter = createRouter()
Router.matcher = newRouter.matcher // reset router
AvueRouter.install(Vue, Router, Store, i18n);
}
export default Router

248
src/router/views/index.js Normal file
View File

@@ -0,0 +1,248 @@
import Layout from '@/page/index/'
export default [
// 没有引用website里的firstPage
{
path: '/wel',
component: Layout,
redirect: '/wel/index',
children: [{
path: 'index',
name: '首页',
meta: {i18n: 'dashboard',code: "wel"},
component: () =>
import(/* webpackChunkName: "views" */ '@/views/wel/index')
}]
},
{
path: '/test',
component: Layout,
redirect: '/test/index',
children: [{
path: 'index',
name: '测试页',
meta: {i18n: 'test'},
component: () =>
import(/* webpackChunkName: "views" */ '@/views/util/test')
}]
},
{
path: '/dict-horizontal',
component: Layout,
redirect: '/dict-horizontal/index',
children: [{
path: 'index',
name: '字典管理',
meta: {i18n: 'dict'},
component: () => import(
/* webpackChunkName: "views" */ '@/views/util/demo/dict-horizontal')
}]
},
{
path: '/dict-vertical',
component: Layout,
redirect: '/dict-vertical/index',
children: [{
path: 'index',
name: '字典管理',
meta: {i18n: 'dict'},
component: () => import(
/* webpackChunkName: "views" */ '@/views/util/demo/dict-vertical')
}]
},
{
path: '/info',
component: Layout,
redirect: '/info/index',
children: [{
path: 'index',
name: '个人信息',
meta: {i18n: 'info'},
component: () =>
import(/* webpackChunkName: "views" */ '@/views/system/userinfo')
}]
},
{
path: '/manage',
component: Layout,
children: [
{
path: 'mission/zpView/:missionNo',
name: '招聘情况',
props: true,
meta: {
i18n: 'mission',
isTab: false,
},
component: () => import(
/* webpackChunkName: "views" */ '@/views/manage/mission/zpView')
},
]
},
{
path: '/work/process/leave',
component: Layout,
redirect: '/work/process/leave/form',
children: [
{
path: 'form/:processDefinitionId',
name: '请假流程',
meta: {i18n: 'work'},
component: () => import(
/* webpackChunkName: "views" */ '@/views/work/process/leave/form')
},
{
path: 'handle/:taskId/:processInstanceId/:businessId',
name: '处理请假流程',
meta: {i18n: 'work'},
component: () => import(
/* webpackChunkName: "views" */ '@/views/work/process/leave/handle')
},
{
path: 'detail/:processInstanceId/:businessId',
name: '请假流程详情',
meta: {i18n: 'work'},
component: () => import(
/* webpackChunkName: "views" */ '@/views/work/process/leave/detail')
}
]
},
{
path: '/tenant/news',
component: Layout,
redirect: '/tenant/news/index',
children: [{
path: 'index',
name: '客户消息',
meta: {i18n: 'news',code:'news'},
component: () =>
import(/* webpackChunkName: "views" */ '@/views/tenant/news/index')
}]
},
{
path: '/tenant/account',
component: Layout,
redirect: 'tenant/account/index',
children: [{
path: 'index',
name: '账户安全',
meta: {i18n: 'accountsafe', code: 'accountsafe'},
component: () =>
import(/* webpackChunkName: "views" */ '@/views/tenant/account/index')
}]
},
// {
// path: '/tenant/set',
// component: Layout,
// redirect: 'tenant/set/index',
// children: [{
// path: 'index',
// name: '设置',
// meta: { i18n: 'set' },
// component: () =>
// import(/* webpackChunkName: "views" */ '@/views/tenant/set/index')
// }]
// },
// {
// path: '/tenant/company',
// component: Layout,
// redirect: 'tenant/company/index',
// children: [{
// path: 'index',
// name: '公司主页',
// meta: { i18n: 'companyindex' },
// component: () =>
// import(/* webpackChunkName: "views" */
// '@/views/tenant/company/index')
// }]
// },
{
path: '/news',
name: '文章管理',
component: Layout,
meta: {
i18n: 'index',
isTab: false,
},
children: [
{
path: 'index/:type/:id',
name: '添加/修改文章',
meta: {
i18n: 'index',
isTab: false,
},
props: true,
component: () => import(
/* webpackChunkName: "views" */ '@/views/manage/jlhome/news/addNews')
}
]
},
{
path: '/article',
name: '文章管理',
component: Layout,
meta: {
i18n: 'index',
isTab: false,
},
children: [
{
path: 'index/:type/:id',
name: '添加/修改文章article',
meta: {
i18n: 'index',
isTab: false,
},
props: true,
component: () => import(
/* webpackChunkName: "views" */ '@/views/manage/jlhome/article/allArticle/addNews')
}
]
},
{
path: '/recommend',
name: '推荐管理',
component: Layout,
meta: {
i18n: 'index',
isTab: false,
},
children: [
{
path: 'index/:type/:id',
name: '管理内容',
meta: {
i18n: 'index',
isTab: false,
},
props: true,
component: () => import(
/* webpackChunkName: "views" */ '@/views/manage/recommend/manageContent/contentManage')
}
]
},
{
path: '/allContent',
name: '全部内容',
component: Layout,
meta: {
i18n: 'index',
isTab: false,
},
children: [
{
path: 'index/:type/:id',
name: '添加/修改内容',
meta: {
i18n: 'index',
isTab: false,
},
props: true,
component: () => import(
/* webpackChunkName: "views" */ '@/views/manage/content/allContent/addContent')
}
]
},
]