jeecg-boot 1.1 稳定版本发布

This commit is contained in:
zhangdaihao
2019-04-14 16:20:04 +08:00
parent c0b489a0e7
commit cd327c4895
375 changed files with 48784 additions and 7523 deletions

View File

@ -0,0 +1,97 @@
const FormTypes = {
normal: 'normal',
input: 'input',
inputNumber: 'inputNumber',
checkbox: 'checkbox',
select: 'select',
date: 'date',
datetime: 'datetime'
}
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)
})
})()
})
}

View File

@ -33,5 +33,5 @@ const VueAxios = {
export {
VueAxios,
// eslint-disable-next-line no-undef
// instance as axios
//instance as axios
}

View File

@ -15,4 +15,16 @@ Vue.filter('dayjs', function(dataStr, pattern = 'YYYY-MM-DD HH:mm:ss') {
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
})

View File

@ -3,10 +3,11 @@ const hasPermission = {
console.log(options);
Vue.directive('has', {
inserted: (el, binding, vnode)=>{
//console.log("页面权限----",el);
console.log("页面权限----",el);
let permissionList = vnode.context.$route.meta.permissionList;
if (permissionList === null || permissionList === "" || permissionList === undefined) {
el.parentNode.removeChild(el)
return
}
let permissions = [];
for (var item of permissionList) {

View File

@ -11,6 +11,7 @@ const mixin = {
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,

View File

@ -23,7 +23,7 @@ const err = (error) => {
break
case 500:
//notification.error({ message: '系统提示', description:'Token失效请重新登录!',duration: 4})
if(data.message=="Token失效请重新登录"){
if(token && data.message=="Token失效请重新登录"){
// update-begin- --- author:scott ------ date:20190225 ---- for:Token失效采用弹框模式不直接跳转----
// store.dispatch('Logout').then(() => {
// window.location.reload()
@ -35,6 +35,7 @@ const err = (error) => {
mask: false,
onOk: () => {
store.dispatch('Logout').then(() => {
Vue.ls.remove(ACCESS_TOKEN)
window.location.reload()
})
}
@ -76,6 +77,12 @@ service.interceptors.request.use(config => {
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)

View File

@ -1,3 +1,4 @@
import { isURL } from '@/utils/validate'
export function timeFix() {
const time = new Date()
@ -33,7 +34,7 @@ export function filterObj(obj) {
for ( var key in obj) {
if (obj.hasOwnProperty(key)
&& (obj[key] == null || obj[key] == undefined || obj[key] == '')) {
&& (obj[key] == null || obj[key] == undefined || obj[key] === '')) {
delete obj[key];
}
}
@ -105,6 +106,13 @@ function generateChildRouters (data) {
}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,
@ -125,7 +133,94 @@ function generateChildRouters (data) {
if (item.children && item.children.length > 0) {
menu.children = [...generateChildRouters( item.children)];
}
routers.push(menu);
//--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))
}
/**
* 随机生成数字
* @param min 最小值
* @param max 最大值
* @return int 生成后的数字
*/
export function randomNumber(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min)
}
/**
* 随机生成字符串
* @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)
}
/**
* 【顶部导航栏模式】
* @date 2019-04-08
* 顶部导航栏滚动条位置滚动到选中的菜单处
* @param doc document 对象
*/
export function topNavScrollToSelectItem(doc) {
let scrollWidth = doc.getElementById('top-nav-scroll-width')
if (scrollWidth == null) return
let menu = scrollWidth.getElementsByClassName('ant-menu')[0]
if (menu) {
let menuItems = menu.getElementsByTagName('li')
for (let item of menuItems) {
let index1 = item.className.indexOf('ant-menu-item-selected') !== -1
let index2 = item.className.indexOf('ant-menu-submenu-selected') !== -1
if (index1 || index2) {
// scrollLeft = 选中项left - 选中项width - (第一个隐藏的div的宽度)
let scrollLeft = (item.offsetLeft - item.offsetWidth - (index1 ? 100 : 60))
let scrollView = doc.getElementById('top-nav-scroll-view')
// scrollTo() 方法存在兼容性问题
if (typeof scrollView.scrollTo === 'function') {
scrollView.scrollTo({
left: scrollLeft,
behavior: 'smooth'
})
} else {
scrollView.scrollLeft = scrollLeft
}
break
}
}
}
}

View 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)
}