mirror of
https://github.com/jeecgboot/JeecgBoot.git
synced 2026-01-03 12:05:28 +08:00
JEECG-BOOT 2.0.2版本发布
This commit is contained in:
100
ant-design-vue-jeecg/src/utils/JEditableTableUtil.js
Normal file
100
ant-design-vue-jeecg/src/utils/JEditableTableUtil.js
Normal file
@ -0,0 +1,100 @@
|
||||
const FormTypes = {
|
||||
normal: 'normal',
|
||||
input: 'input',
|
||||
inputNumber: 'inputNumber',
|
||||
checkbox: 'checkbox',
|
||||
select: 'select',
|
||||
date: 'date',
|
||||
datetime: 'datetime',
|
||||
upload: 'upload',
|
||||
slot: 'slot',
|
||||
hidden: 'hidden'
|
||||
}
|
||||
const VALIDATE_NO_PASSED = Symbol()
|
||||
export { FormTypes, VALIDATE_NO_PASSED }
|
||||
|
||||
/**
|
||||
* 获取指定的 $refs 对象
|
||||
* 有时候可能会遇到组件未挂载到页面中的情况,导致无法获取 $refs 中的某个对象
|
||||
* 这个方法可以等待挂载完成之后再返回 $refs 的对象,避免报错
|
||||
* @author sunjianlei
|
||||
**/
|
||||
export function getRefPromise(vm, name) {
|
||||
return new Promise((resolve) => {
|
||||
(function next() {
|
||||
let ref = vm.$refs[name]
|
||||
if (ref) {
|
||||
resolve(ref)
|
||||
} else {
|
||||
setTimeout(() => {
|
||||
next()
|
||||
}, 10)
|
||||
}
|
||||
})()
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 一次性验证主表单和所有的次表单
|
||||
* @param form 主表单 form 对象
|
||||
* @param cases 接收一个数组,每项都是一个JEditableTable实例
|
||||
* @returns {Promise<any>}
|
||||
* @author sunjianlei
|
||||
*/
|
||||
export function validateFormAndTables(form, cases) {
|
||||
|
||||
if (!(form && typeof form.validateFields === 'function')) {
|
||||
throw `form 参数需要的是一个form对象,而传入的却是${typeof form}`
|
||||
}
|
||||
|
||||
let options = {}
|
||||
return new Promise((resolve, reject) => {
|
||||
// 验证主表表单
|
||||
form.validateFields((err, values) => {
|
||||
err ? reject({ error: VALIDATE_NO_PASSED }) : resolve(values)
|
||||
})
|
||||
}).then(values => {
|
||||
Object.assign(options, { formValue: values })
|
||||
// 验证所有子表的表单
|
||||
return validateTables(cases)
|
||||
}).then(all => {
|
||||
Object.assign(options, { tablesValue: all })
|
||||
return Promise.resolve(options)
|
||||
}).catch(error => {
|
||||
return Promise.reject(error)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证并获取一个或多个表格的所有值
|
||||
* @param cases 接收一个数组,每项都是一个JEditableTable实例
|
||||
* @author sunjianlei
|
||||
*/
|
||||
export function validateTables(cases) {
|
||||
if (!(cases instanceof Array)) {
|
||||
throw `'validateTables'函数的'cases'参数需要的是一个数组,而传入的却是${typeof cases}`
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
let tables = []
|
||||
let index = 0;
|
||||
(function next() {
|
||||
let vm = cases[index]
|
||||
vm.getAll(true).then(all => {
|
||||
tables[index] = all
|
||||
// 判断校验是否全部完成,完成返回成功,否则继续进行下一步校验
|
||||
if (++index === cases.length) {
|
||||
resolve(tables)
|
||||
} else (
|
||||
next()
|
||||
)
|
||||
}, error => {
|
||||
// 出现未验证通过的表单,不再进行下一步校验,直接返回失败并跳转到该表格
|
||||
if (error === VALIDATE_NO_PASSED) {
|
||||
reject({ error: VALIDATE_NO_PASSED, index })
|
||||
}
|
||||
reject(error)
|
||||
})
|
||||
})()
|
||||
})
|
||||
}
|
||||
19
ant-design-vue-jeecg/src/utils/auth.js
Normal file
19
ant-design-vue-jeecg/src/utils/auth.js
Normal file
@ -0,0 +1,19 @@
|
||||
/**
|
||||
* 弃用
|
||||
*/
|
||||
import { setStore, getStore, clearStore } from "@/utils/storage"
|
||||
|
||||
export const TokenKey = 'Access-Token'
|
||||
|
||||
export function getToken() {
|
||||
return getStore(TokenKey)
|
||||
}
|
||||
|
||||
export function setToken(token) {
|
||||
// key, token, timeout = 86400s
|
||||
return setStore(TokenKey, token, 86400)
|
||||
}
|
||||
|
||||
export function removeToken() {
|
||||
return clearStore(TokenKey)
|
||||
}
|
||||
176
ant-design-vue-jeecg/src/utils/authFilter.js
Normal file
176
ant-design-vue-jeecg/src/utils/authFilter.js
Normal file
@ -0,0 +1,176 @@
|
||||
|
||||
import { USER_AUTH,SYS_BUTTON_AUTH } from "@/store/mutation-types"
|
||||
|
||||
export function disabledAuthFilter(code,formData) {
|
||||
if(nodeDisabledAuth(code,formData)){
|
||||
return true;
|
||||
}else{
|
||||
return globalDisabledAuth(code);
|
||||
}
|
||||
}
|
||||
|
||||
function nodeDisabledAuth(code,formData){
|
||||
console.log("页面权限禁用--NODE--开始");
|
||||
var permissionList = [];
|
||||
try {
|
||||
var obj = formData;
|
||||
//console.log("页面权限禁用--NODE--开始",obj);
|
||||
if (obj) {
|
||||
let bpmList = obj.permissionList;
|
||||
for (var bpm of bpmList) {
|
||||
if(bpm.type == '2') {
|
||||
permissionList.push(bpm);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
//console.log("页面权限异常----", e);
|
||||
}
|
||||
if (permissionList === null || permissionList === "" || permissionList === undefined||permissionList.length<=0) {
|
||||
return false;
|
||||
}
|
||||
let permissions = [];
|
||||
for (var item of permissionList) {
|
||||
if(item.type == '2') {
|
||||
permissions.push(item.action);
|
||||
}
|
||||
}
|
||||
//console.log("页面权限----"+code);
|
||||
if (!permissions.includes(code)) {
|
||||
return false;
|
||||
}else{
|
||||
for (var item2 of permissionList) {
|
||||
if(code === item2.action){
|
||||
console.log("页面权限禁用--NODE--生效");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function globalDisabledAuth(code){
|
||||
console.log("页面禁用权限--Global--开始");
|
||||
|
||||
var permissionList = [];
|
||||
var allPermissionList = [];
|
||||
|
||||
//let authList = Vue.ls.get(USER_AUTH);
|
||||
let authList = JSON.parse(sessionStorage.getItem(USER_AUTH) || "[]");
|
||||
for (var auth of authList) {
|
||||
if(auth.type == '2') {
|
||||
permissionList.push(auth);
|
||||
}
|
||||
}
|
||||
//console.log("页面禁用权限--Global--",sessionStorage.getItem(SYS_BUTTON_AUTH));
|
||||
let allAuthList = JSON.parse(sessionStorage.getItem(SYS_BUTTON_AUTH) || "[]");
|
||||
for (var gauth of allAuthList) {
|
||||
if(gauth.type == '2') {
|
||||
allPermissionList.push(gauth);
|
||||
}
|
||||
}
|
||||
//设置全局配置是否有命中
|
||||
var gFlag = false;//禁用命中
|
||||
var invalidFlag = false;//无效命中
|
||||
if(allPermissionList != null && allPermissionList != "" && allPermissionList != undefined && allPermissionList.length > 0){
|
||||
for (var itemG of allPermissionList) {
|
||||
if(code === itemG.action){
|
||||
if(itemG.status == '0'){
|
||||
invalidFlag = true;
|
||||
break;
|
||||
}else{
|
||||
gFlag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(invalidFlag){
|
||||
return false;
|
||||
}
|
||||
if (permissionList === null || permissionList === "" || permissionList === undefined||permissionList.length<=0) {
|
||||
return gFlag;
|
||||
}
|
||||
let permissions = [];
|
||||
for (var item of permissionList) {
|
||||
if(item.type == '2') {
|
||||
permissions.push(item.action);
|
||||
}
|
||||
}
|
||||
//console.log("页面禁用权限----"+code);
|
||||
if (!permissions.includes(code)) {
|
||||
return gFlag;
|
||||
}else{
|
||||
for (var item2 of permissionList) {
|
||||
if(code === item2.action){
|
||||
console.log("页面权限解除禁用--Global--生效");
|
||||
gFlag = false;
|
||||
}
|
||||
}
|
||||
return gFlag;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
export function colAuthFilter(columns,pre) {
|
||||
var authList = getNoAuthCols(pre);
|
||||
const cols = columns.filter(item => {
|
||||
if (hasColoum(item,authList)) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
})
|
||||
return cols
|
||||
}
|
||||
|
||||
function hasColoum(item,authList){
|
||||
if (authList.includes(item.dataIndex)) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
//权限无效时不做控制,有效时控制,只能控制 显示不显示
|
||||
//根据授权码前缀获取未授权的列信息
|
||||
function getNoAuthCols(pre){
|
||||
var permissionList = [];
|
||||
var allPermissionList = [];
|
||||
|
||||
//let authList = Vue.ls.get(USER_AUTH);
|
||||
let authList = JSON.parse(sessionStorage.getItem(USER_AUTH) || "[]");
|
||||
for (var auth of authList) {
|
||||
//显示策略,有效状态
|
||||
if(auth.type == '1'&&startWith(auth.action,pre)) {
|
||||
permissionList.push(substrPre(auth.action,pre));
|
||||
}
|
||||
}
|
||||
//console.log("页面禁用权限--Global--",sessionStorage.getItem(SYS_BUTTON_AUTH));
|
||||
let allAuthList = JSON.parse(sessionStorage.getItem(SYS_BUTTON_AUTH) || "[]");
|
||||
for (var gauth of allAuthList) {
|
||||
//显示策略,有效状态
|
||||
if(gauth.type == '1'&&gauth.status == '1'&&startWith(gauth.action,pre)) {
|
||||
allPermissionList.push(substrPre(gauth.action,pre));
|
||||
}
|
||||
}
|
||||
const cols = allPermissionList.filter(item => {
|
||||
if (permissionList.includes(item)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
})
|
||||
return cols;
|
||||
}
|
||||
|
||||
function startWith(str,pre) {
|
||||
if (pre == null || pre == "" || str==null|| str==""|| str.length == 0 || pre.length > str.length)
|
||||
return false;
|
||||
if (str.substr(0, pre.length) == pre)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
function substrPre(str,pre) {
|
||||
return str.substr(pre.length);
|
||||
}
|
||||
37
ant-design-vue-jeecg/src/utils/axios.js
Normal file
37
ant-design-vue-jeecg/src/utils/axios.js
Normal file
@ -0,0 +1,37 @@
|
||||
const VueAxios = {
|
||||
vm: {},
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
install(Vue, router = {}, instance) {
|
||||
if (this.installed) {
|
||||
return;
|
||||
}
|
||||
this.installed = true;
|
||||
|
||||
if (!instance) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error('You have to install axios');
|
||||
return;
|
||||
}
|
||||
|
||||
Vue.axios = instance;
|
||||
|
||||
Object.defineProperties(Vue.prototype, {
|
||||
axios: {
|
||||
get: function get() {
|
||||
return instance;
|
||||
}
|
||||
},
|
||||
$http: {
|
||||
get: function get() {
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export {
|
||||
VueAxios,
|
||||
// eslint-disable-next-line no-undef
|
||||
//instance as axios
|
||||
}
|
||||
51
ant-design-vue-jeecg/src/utils/commonUploadFile.js
Normal file
51
ant-design-vue-jeecg/src/utils/commonUploadFile.js
Normal file
@ -0,0 +1,51 @@
|
||||
const getFileName=(path)=>{
|
||||
if(path.lastIndexOf("\\")>=0){
|
||||
let reg=new RegExp("\\\\","g");
|
||||
path = path.replace(reg,"/");
|
||||
}
|
||||
return path.substring(path.lastIndexOf("/")+1);
|
||||
}
|
||||
|
||||
const uidGenerator=()=>{
|
||||
return '-'+parseInt(Math.random()*10000+1,10);
|
||||
}
|
||||
|
||||
const getFilePaths=(uploadFiles)=>{
|
||||
let arr = [];
|
||||
if(!uploadFiles){
|
||||
return ""
|
||||
}
|
||||
for(var a=0;a<uploadFiles.length;a++){
|
||||
arr.push(uploadFiles[a].response.message)
|
||||
}
|
||||
if(arr && arr.length>0){
|
||||
return arr.join(",")
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
const getUploadFileList=(paths)=>{
|
||||
if(!paths){
|
||||
return [];
|
||||
}
|
||||
let fileList = [];
|
||||
let arr = paths.split(",")
|
||||
for(var a=0;a<arr.length;a++){
|
||||
if(!arr[a]){
|
||||
continue
|
||||
}else{
|
||||
fileList.push({
|
||||
uid:uidGenerator(),
|
||||
name:getFileName(arr[a]),
|
||||
status: 'done',
|
||||
url: window._CONFIG['domianURL']+"/sys/common/view/"+arr[a],
|
||||
response:{
|
||||
status:"history",
|
||||
message:arr[a]
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
return fileList;
|
||||
}
|
||||
export {getFilePaths,getUploadFileList}
|
||||
23
ant-design-vue-jeecg/src/utils/device.js
Normal file
23
ant-design-vue-jeecg/src/utils/device.js
Normal file
@ -0,0 +1,23 @@
|
||||
import enquireJs from 'enquire.js'
|
||||
|
||||
const enquireScreen = function (call) {
|
||||
// tablet
|
||||
const handler = {
|
||||
match: function () {
|
||||
call && call(0)
|
||||
},
|
||||
unmatch: function () {
|
||||
call && call(-1)
|
||||
}
|
||||
}
|
||||
// mobile
|
||||
const handler2 = {
|
||||
match: () => {
|
||||
call && call(1)
|
||||
}
|
||||
}
|
||||
enquireJs.register('screen and (max-width: 1087.99px)', handler)
|
||||
enquireJs.register('screen and (max-width: 767.99px)', handler2)
|
||||
}
|
||||
|
||||
export default enquireScreen
|
||||
5988
ant-design-vue-jeecg/src/utils/encryption/aesEncrypt.js
Normal file
5988
ant-design-vue-jeecg/src/utils/encryption/aesEncrypt.js
Normal file
File diff suppressed because it is too large
Load Diff
30
ant-design-vue-jeecg/src/utils/filter.js
Normal file
30
ant-design-vue-jeecg/src/utils/filter.js
Normal file
@ -0,0 +1,30 @@
|
||||
import Vue from "vue";
|
||||
import * as dayjs from "dayjs";
|
||||
|
||||
Vue.filter('NumberFormat', function (value) {
|
||||
if (!value) {
|
||||
return '0'
|
||||
}
|
||||
let intPartFormat = value.toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,') //将整数部分逢三一断
|
||||
return intPartFormat
|
||||
})
|
||||
|
||||
Vue.filter('dayjs', function(dataStr, pattern = 'YYYY-MM-DD HH:mm:ss') {
|
||||
return dayjs(dataStr).format(pattern)
|
||||
})
|
||||
|
||||
Vue.filter('moment', function(dataStr, pattern = 'YYYY-MM-DD HH:mm:ss') {
|
||||
return dayjs(dataStr).format(pattern)
|
||||
})
|
||||
|
||||
/** 字符串超长截取省略号显示 */
|
||||
Vue.filter('ellipsis', function (value, vlength = 25) {
|
||||
if(!value){
|
||||
return "";
|
||||
}
|
||||
console.log('vlength: '+ vlength);
|
||||
if (value.length > vlength) {
|
||||
return value.slice(0, vlength) + '...'
|
||||
}
|
||||
return value
|
||||
})
|
||||
116
ant-design-vue-jeecg/src/utils/hasPermission.js
Normal file
116
ant-design-vue-jeecg/src/utils/hasPermission.js
Normal file
@ -0,0 +1,116 @@
|
||||
import { USER_AUTH,SYS_BUTTON_AUTH } from "@/store/mutation-types"
|
||||
|
||||
const hasPermission = {
|
||||
install (Vue, options) {
|
||||
console.log(options);
|
||||
Vue.directive('has', {
|
||||
inserted: (el, binding, vnode)=>{
|
||||
console.log("页面权限控制----");
|
||||
//节点权限处理,如果命中则不进行全局权限处理
|
||||
if(!filterNodePermission(el, binding, vnode)){
|
||||
filterGlobalPermission(el, binding, vnode);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 全局权限控制
|
||||
*/
|
||||
export function filterNodePermission(el, binding, vnode) {
|
||||
console.log("页面权限--NODE--");
|
||||
|
||||
var permissionList = [];
|
||||
try {
|
||||
var obj = vnode.context.$props.formData;
|
||||
if (obj) {
|
||||
let bpmList = obj.permissionList;
|
||||
for (var bpm of bpmList) {
|
||||
if(bpm.type != '2') {
|
||||
permissionList.push(bpm);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
//console.log("页面权限异常----", e);
|
||||
}
|
||||
if (permissionList === null || permissionList === "" || permissionList === undefined||permissionList.length<=0) {
|
||||
//el.parentNode.removeChild(el)
|
||||
return false;
|
||||
}
|
||||
let permissions = [];
|
||||
for (var item of permissionList) {
|
||||
if(item.type != '2') {
|
||||
permissions.push(item.action);
|
||||
}
|
||||
}
|
||||
//console.log("页面权限----"+permissions);
|
||||
//console.log("页面权限----"+binding.value);
|
||||
if (!permissions.includes(binding.value)) {
|
||||
//el.parentNode.removeChild(el)
|
||||
return false;
|
||||
}else{
|
||||
for (var item2 of permissionList) {
|
||||
if(binding.value === item2.action){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 全局权限控制
|
||||
*/
|
||||
export function filterGlobalPermission(el, binding, vnode) {
|
||||
console.log("页面权限--Global--");
|
||||
|
||||
var permissionList = [];
|
||||
var allPermissionList = [];
|
||||
|
||||
//let authList = Vue.ls.get(USER_AUTH);
|
||||
let authList = JSON.parse(sessionStorage.getItem(USER_AUTH) || "[]");
|
||||
for (var auth of authList) {
|
||||
if(auth.type != '2') {
|
||||
permissionList.push(auth);
|
||||
}
|
||||
}
|
||||
//console.log("页面权限--Global--",sessionStorage.getItem(SYS_BUTTON_AUTH));
|
||||
let allAuthList = JSON.parse(sessionStorage.getItem(SYS_BUTTON_AUTH) || "[]");
|
||||
for (var gauth of allAuthList) {
|
||||
if(gauth.type != '2') {
|
||||
allPermissionList.push(gauth);
|
||||
}
|
||||
}
|
||||
//设置全局配置是否有命中
|
||||
var invalidFlag = false;//无效命中
|
||||
if(allPermissionList != null && allPermissionList != "" && allPermissionList != undefined && allPermissionList.length > 0){
|
||||
for (var itemG of allPermissionList) {
|
||||
if(binding.value === itemG.action){
|
||||
if(itemG.status == '0'){
|
||||
invalidFlag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(invalidFlag){
|
||||
return;
|
||||
}
|
||||
if (permissionList === null || permissionList === "" || permissionList === undefined||permissionList.length<=0) {
|
||||
el.parentNode.removeChild(el);
|
||||
return;
|
||||
}
|
||||
let permissions = [];
|
||||
for (var item of permissionList) {
|
||||
if(item.type != '2'){
|
||||
permissions.push(item.action);
|
||||
}
|
||||
}
|
||||
if (!permissions.includes(binding.value)) {
|
||||
el.parentNode.removeChild(el);
|
||||
}
|
||||
}
|
||||
|
||||
export default hasPermission;
|
||||
40
ant-design-vue-jeecg/src/utils/mixin.js
Normal file
40
ant-design-vue-jeecg/src/utils/mixin.js
Normal file
@ -0,0 +1,40 @@
|
||||
// import Vue from 'vue'
|
||||
import { mapState } from "vuex";
|
||||
|
||||
// const mixinsComputed = Vue.config.optionMergeStrategies.computed
|
||||
// const mixinsMethods = Vue.config.optionMergeStrategies.methods
|
||||
|
||||
const mixin = {
|
||||
computed: {
|
||||
...mapState({
|
||||
layoutMode: state => state.app.layout,
|
||||
navTheme: state => state.app.theme,
|
||||
primaryColor: state => state.app.color,
|
||||
colorWeak: state => state.app.weak,
|
||||
multipage: state => state.app.multipage,//多页签设置
|
||||
fixedHeader: state => state.app.fixedHeader,
|
||||
fixSiderbar: state => state.app.fixSiderbar,
|
||||
contentWidth: state => state.app.contentWidth,
|
||||
autoHideHeader: state => state.app.autoHideHeader,
|
||||
sidebarOpened: state => state.app.sidebar.opened
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const mixinDevice = {
|
||||
computed: {
|
||||
...mapState({
|
||||
device: state => state.app.device,
|
||||
})
|
||||
},
|
||||
methods: {
|
||||
isMobile () {
|
||||
return this.device === 'mobile'
|
||||
},
|
||||
isDesktop () {
|
||||
return this.device === 'desktop'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export { mixin, mixinDevice }
|
||||
8
ant-design-vue-jeecg/src/utils/permissions.js
Normal file
8
ant-design-vue-jeecg/src/utils/permissions.js
Normal file
@ -0,0 +1,8 @@
|
||||
export function actionToObject(json) {
|
||||
try {
|
||||
return JSON.parse(json)
|
||||
} catch (e) {
|
||||
console.log('err', e.message)
|
||||
}
|
||||
return []
|
||||
}
|
||||
106
ant-design-vue-jeecg/src/utils/request.js
Normal file
106
ant-design-vue-jeecg/src/utils/request.js
Normal file
@ -0,0 +1,106 @@
|
||||
import Vue from 'vue'
|
||||
import axios from 'axios'
|
||||
import store from '@/store'
|
||||
import { VueAxios } from './axios'
|
||||
import {Modal, notification} from 'ant-design-vue'
|
||||
import { ACCESS_TOKEN } from "@/store/mutation-types"
|
||||
|
||||
// 创建 axios 实例
|
||||
const service = axios.create({
|
||||
baseURL: '/jeecg-boot', // api base_url
|
||||
timeout: 6000 // 请求超时时间
|
||||
})
|
||||
|
||||
const err = (error) => {
|
||||
if (error.response) {
|
||||
let data = error.response.data
|
||||
const token = Vue.ls.get(ACCESS_TOKEN)
|
||||
console.log("------异常响应------",token)
|
||||
console.log("------异常响应------",error.response.status)
|
||||
switch (error.response.status) {
|
||||
case 403:
|
||||
notification.error({ message: '系统提示', description: '拒绝访问',duration: 4})
|
||||
break
|
||||
case 500:
|
||||
//notification.error({ message: '系统提示', description:'Token失效,请重新登录!',duration: 4})
|
||||
if(token && data.message=="Token失效,请重新登录"){
|
||||
// update-begin- --- author:scott ------ date:20190225 ---- for:Token失效采用弹框模式,不直接跳转----
|
||||
// store.dispatch('Logout').then(() => {
|
||||
// window.location.reload()
|
||||
// })
|
||||
Modal.error({
|
||||
title: '登录已过期',
|
||||
content: '很抱歉,登录已过期,请重新登录',
|
||||
okText: '重新登录',
|
||||
mask: false,
|
||||
onOk: () => {
|
||||
store.dispatch('Logout').then(() => {
|
||||
Vue.ls.remove(ACCESS_TOKEN)
|
||||
window.location.reload()
|
||||
})
|
||||
}
|
||||
})
|
||||
// update-end- --- author:scott ------ date:20190225 ---- for:Token失效采用弹框模式,不直接跳转----
|
||||
}
|
||||
break
|
||||
case 404:
|
||||
notification.error({ message: '系统提示', description:'很抱歉,资源未找到!',duration: 4})
|
||||
break
|
||||
case 504:
|
||||
notification.error({ message: '系统提示', description: '网络超时'})
|
||||
break
|
||||
case 401:
|
||||
notification.error({ message: '系统提示', description:'未授权,请重新登录',duration: 4})
|
||||
if (token) {
|
||||
store.dispatch('Logout').then(() => {
|
||||
setTimeout(() => {
|
||||
window.location.reload()
|
||||
}, 1500)
|
||||
})
|
||||
}
|
||||
break
|
||||
default:
|
||||
notification.error({
|
||||
message: '系统提示',
|
||||
description: data.message,
|
||||
duration: 4
|
||||
})
|
||||
break
|
||||
}
|
||||
}
|
||||
return Promise.reject(error)
|
||||
};
|
||||
|
||||
// request interceptor
|
||||
service.interceptors.request.use(config => {
|
||||
const token = Vue.ls.get(ACCESS_TOKEN)
|
||||
if (token) {
|
||||
config.headers[ 'X-Access-Token' ] = token // 让每个请求携带自定义 token 请根据实际情况自行修改
|
||||
}
|
||||
if(config.method=='get'){
|
||||
config.params = {
|
||||
_t: Date.parse(new Date())/1000,
|
||||
...config.params
|
||||
}
|
||||
}
|
||||
return config
|
||||
},(error) => {
|
||||
return Promise.reject(error)
|
||||
})
|
||||
|
||||
// response interceptor
|
||||
service.interceptors.response.use((response) => {
|
||||
return response.data
|
||||
}, err)
|
||||
|
||||
const installer = {
|
||||
vm: {},
|
||||
install (Vue, router = {}) {
|
||||
Vue.use(VueAxios, router, service)
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
installer as VueAxios,
|
||||
service as axios
|
||||
}
|
||||
78
ant-design-vue-jeecg/src/utils/storage.js
Normal file
78
ant-design-vue-jeecg/src/utils/storage.js
Normal file
@ -0,0 +1,78 @@
|
||||
/**
|
||||
* Set storage
|
||||
*
|
||||
* @param name
|
||||
* @param content
|
||||
* @param maxAge
|
||||
*/
|
||||
export const setStore = (name, content, maxAge = null) => {
|
||||
if (!global.window || !name) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof content !== 'string') {
|
||||
content = JSON.stringify(content)
|
||||
}
|
||||
|
||||
let storage = global.window.localStorage
|
||||
|
||||
storage.setItem(name, content)
|
||||
if (maxAge && !isNaN(parseInt(maxAge))) {
|
||||
let timeout = parseInt(new Date().getTime() / 1000)
|
||||
storage.setItem(`${name}_expire`, timeout + maxAge)
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get storage
|
||||
*
|
||||
* @param name
|
||||
* @returns {*}
|
||||
*/
|
||||
export const getStore = name => {
|
||||
if (!global.window || !name) {
|
||||
return;
|
||||
}
|
||||
|
||||
let content = window.localStorage.getItem(name)
|
||||
let _expire = window.localStorage.getItem(`${name}_expire`)
|
||||
|
||||
if (_expire) {
|
||||
let now = parseInt(new Date().getTime() / 1000)
|
||||
if (now > _expire) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
return JSON.parse(content)
|
||||
} catch (e) {
|
||||
return content
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Clear storage
|
||||
*
|
||||
* @param name
|
||||
*/
|
||||
export const clearStore = name => {
|
||||
if (!global.window || !name) {
|
||||
return;
|
||||
}
|
||||
|
||||
window.localStorage.removeItem(name)
|
||||
window.localStorage.removeItem(`${name}_expire`)
|
||||
};
|
||||
|
||||
/**
|
||||
* Clear all storage
|
||||
*/
|
||||
export const clearAll = () => {
|
||||
if (!global.window || !name) {
|
||||
return;
|
||||
}
|
||||
|
||||
window.localStorage.clear()
|
||||
}
|
||||
|
||||
235
ant-design-vue-jeecg/src/utils/util.js
Normal file
235
ant-design-vue-jeecg/src/utils/util.js
Normal file
@ -0,0 +1,235 @@
|
||||
import { isURL } from '@/utils/validate'
|
||||
|
||||
export function timeFix() {
|
||||
const time = new Date()
|
||||
const hour = time.getHours()
|
||||
return hour < 9 ? '早上好' : (hour <= 11 ? '上午好' : (hour <= 13 ? '中午好' : (hour < 20 ? '下午好' : '晚上好')))
|
||||
}
|
||||
|
||||
export function welcome() {
|
||||
const arr = ['休息一会儿吧', '准备吃什么呢?', '要不要打一把 DOTA', '我猜你可能累了']
|
||||
let index = Math.floor((Math.random()*arr.length))
|
||||
return arr[index]
|
||||
}
|
||||
|
||||
/**
|
||||
* 触发 window.resize
|
||||
*/
|
||||
export function triggerWindowResizeEvent() {
|
||||
let event = document.createEvent('HTMLEvents')
|
||||
event.initEvent('resize', true, true)
|
||||
event.eventType = 'message'
|
||||
window.dispatchEvent(event)
|
||||
}
|
||||
|
||||
/**
|
||||
* 过滤对象中为空的属性
|
||||
* @param obj
|
||||
* @returns {*}
|
||||
*/
|
||||
export function filterObj(obj) {
|
||||
if (!(typeof obj == 'object')) {
|
||||
return;
|
||||
}
|
||||
|
||||
for ( var key in obj) {
|
||||
if (obj.hasOwnProperty(key)
|
||||
&& (obj[key] == null || obj[key] == undefined || obj[key] === '')) {
|
||||
delete obj[key];
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* 时间格式化
|
||||
* @param value
|
||||
* @param fmt
|
||||
* @returns {*}
|
||||
*/
|
||||
export function formatDate(value, fmt) {
|
||||
var regPos = /^\d+(\.\d+)?$/;
|
||||
if(regPos.test(value)){
|
||||
//如果是数字
|
||||
let getDate = new Date(value);
|
||||
let o = {
|
||||
'M+': getDate.getMonth() + 1,
|
||||
'd+': getDate.getDate(),
|
||||
'h+': getDate.getHours(),
|
||||
'm+': getDate.getMinutes(),
|
||||
's+': getDate.getSeconds(),
|
||||
'q+': Math.floor((getDate.getMonth() + 3) / 3),
|
||||
'S': getDate.getMilliseconds()
|
||||
};
|
||||
if (/(y+)/.test(fmt)) {
|
||||
fmt = fmt.replace(RegExp.$1, (getDate.getFullYear() + '').substr(4 - RegExp.$1.length))
|
||||
}
|
||||
for (let k in o) {
|
||||
if (new RegExp('(' + k + ')').test(fmt)) {
|
||||
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length)))
|
||||
}
|
||||
}
|
||||
return fmt;
|
||||
}else{
|
||||
//TODO
|
||||
value = value.trim();
|
||||
return value.substr(0,fmt.length);
|
||||
}
|
||||
}
|
||||
|
||||
// 生成首页路由
|
||||
export function generateIndexRouter(data) {
|
||||
let indexRouter = [{
|
||||
path: '/',
|
||||
name: 'dashboard',
|
||||
//component: () => import('@/components/layouts/BasicLayout'),
|
||||
component: resolve => require(['@/components/layouts/TabLayout'], resolve),
|
||||
meta: { title: '首页' },
|
||||
redirect: '/dashboard/analysis',
|
||||
children: [
|
||||
...generateChildRouters(data)
|
||||
]
|
||||
},{
|
||||
"path": "*", "redirect": "/404", "hidden": true
|
||||
}]
|
||||
return indexRouter;
|
||||
}
|
||||
|
||||
// 生成嵌套路由(子路由)
|
||||
|
||||
function generateChildRouters (data) {
|
||||
const routers = [];
|
||||
for (var item of data) {
|
||||
let component = "";
|
||||
if(item.component.indexOf("layouts")>=0){
|
||||
component = "components/"+item.component;
|
||||
}else{
|
||||
component = "views/"+item.component;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line
|
||||
let URL = (item.meta.url|| '').replace(/{{([^}}]+)?}}/g, (s1, s2) => eval(s2)) // URL支持{{ window.xxx }}占位符变量
|
||||
if (isURL(URL)) {
|
||||
item.meta.url = URL;
|
||||
}
|
||||
|
||||
let menu = {
|
||||
path: item.path,
|
||||
name: item.name,
|
||||
redirect:item.redirect,
|
||||
component: resolve => require(['@/' + component+'.vue'], resolve),
|
||||
hidden:item.hidden,
|
||||
//component:()=> import(`@/views/${item.component}.vue`),
|
||||
meta: {
|
||||
title:item.meta.title ,
|
||||
icon: item.meta.icon,
|
||||
url:item.meta.url ,
|
||||
permissionList:item.meta.permissionList,
|
||||
keepAlive:item.meta.keepAlive
|
||||
}
|
||||
}
|
||||
if(item.alwaysShow){
|
||||
menu.alwaysShow = true;
|
||||
menu.redirect = menu.path;
|
||||
}
|
||||
if (item.children && item.children.length > 0) {
|
||||
menu.children = [...generateChildRouters( item.children)];
|
||||
}
|
||||
//--update-begin----author:scott---date:20190320------for:根据后台菜单配置,判断是否路由菜单字段,动态选择是否生成路由(为了支持参数URL菜单)------
|
||||
//判断是否生成路由
|
||||
if(item.route && item.route === '0'){
|
||||
//console.log(' 不生成路由 item.route: '+item.route);
|
||||
//console.log(' 不生成路由 item.path: '+item.path);
|
||||
}else{
|
||||
routers.push(menu);
|
||||
}
|
||||
//--update-end----author:scott---date:20190320------for:根据后台菜单配置,判断是否路由菜单字段,动态选择是否生成路由(为了支持参数URL菜单)------
|
||||
}
|
||||
return routers
|
||||
}
|
||||
|
||||
/**
|
||||
* 深度克隆对象、数组
|
||||
* @param obj 被克隆的对象
|
||||
* @return 克隆后的对象
|
||||
*/
|
||||
export function cloneObject(obj) {
|
||||
return JSON.parse(JSON.stringify(obj))
|
||||
}
|
||||
|
||||
/**
|
||||
* 随机生成数字
|
||||
*
|
||||
* 示例:生成长度为 12 的随机数:randomNumber(12)
|
||||
* 示例:生成 3~23 之间的随机数:randomNumber(3, 23)
|
||||
*
|
||||
* @param1 最小值 | 长度
|
||||
* @param2 最大值
|
||||
* @return int 生成后的数字
|
||||
*/
|
||||
export function randomNumber() {
|
||||
// 生成 最小值 到 最大值 区间的随机数
|
||||
const random = (min, max) => {
|
||||
return Math.floor(Math.random() * (max - min + 1) + min)
|
||||
}
|
||||
if (arguments.length === 1) {
|
||||
let [length] = arguments
|
||||
// 生成指定长度的随机数字,首位一定不是 0
|
||||
let nums = [...Array(length).keys()].map((i) => (i > 0 ? random(0, 9) : random(1, 9)))
|
||||
return parseInt(nums.join(''))
|
||||
} else if (arguments.length >= 2) {
|
||||
let [min, max] = arguments
|
||||
return random(min, max)
|
||||
} else {
|
||||
return Number.NaN
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 随机生成字符串
|
||||
* @param length 字符串的长度
|
||||
* @param chats 可选字符串区间(只会生成传入的字符串中的字符)
|
||||
* @return string 生成的字符串
|
||||
*/
|
||||
export function randomString(length, chats) {
|
||||
if (!length) length = 1
|
||||
if (!chats) chats = '0123456789qwertyuioplkjhgfdsazxcvbnm'
|
||||
let str = ''
|
||||
for (let i = 0; i < length; i++) {
|
||||
let num = randomNumber(0, chats.length - 1)
|
||||
str += chats[num]
|
||||
}
|
||||
return str
|
||||
}
|
||||
|
||||
/**
|
||||
* 随机生成uuid
|
||||
* @return string 生成的uuid
|
||||
*/
|
||||
export function randomUUID() {
|
||||
let chats = '0123456789abcdef'
|
||||
return randomString(32, chats)
|
||||
}
|
||||
|
||||
/**
|
||||
* 下划线转驼峰
|
||||
* @param string
|
||||
* @returns {*}
|
||||
*/
|
||||
export function underLine2CamelCase(string){
|
||||
return string.replace( /_([a-z])/g, function( all, letter ) {
|
||||
return letter.toUpperCase();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否显示办理按钮
|
||||
* @param bpmStatus
|
||||
* @returns {*}
|
||||
*/
|
||||
export function showDealBtn(bpmStatus){
|
||||
if(bpmStatus!="1"&&bpmStatus!="3"&&bpmStatus!="4"){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
31
ant-design-vue-jeecg/src/utils/validate.js
Normal file
31
ant-design-vue-jeecg/src/utils/validate.js
Normal file
@ -0,0 +1,31 @@
|
||||
/**
|
||||
* 邮箱
|
||||
* @param {*} s
|
||||
*/
|
||||
export function isEmail (s) {
|
||||
return /^([a-zA-Z0-9._-])+@([a-zA-Z0-9_-])+((.[a-zA-Z0-9_-]{2,3}){1,2})$/.test(s)
|
||||
}
|
||||
|
||||
/**
|
||||
* 手机号码
|
||||
* @param {*} s
|
||||
*/
|
||||
export function isMobile (s) {
|
||||
return /^1[0-9]{10}$/.test(s)
|
||||
}
|
||||
|
||||
/**
|
||||
* 电话号码
|
||||
* @param {*} s
|
||||
*/
|
||||
export function isPhone (s) {
|
||||
return /^([0-9]{3,4}-)?[0-9]{7,8}$/.test(s)
|
||||
}
|
||||
|
||||
/**
|
||||
* URL地址
|
||||
* @param {*} s
|
||||
*/
|
||||
export function isURL (s) {
|
||||
return /^http[s]?:\/\/.*/.test(s)
|
||||
}
|
||||
5
ant-design-vue-jeecg/src/utils/vueBus.js
Normal file
5
ant-design-vue-jeecg/src/utils/vueBus.js
Normal file
@ -0,0 +1,5 @@
|
||||
import Bus from 'vue';
|
||||
let install = function (Vue) {
|
||||
Vue.prototype.$bus = new Bus()
|
||||
}
|
||||
export default { install };
|
||||
Reference in New Issue
Block a user