You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
92 lines
2.4 KiB
92 lines
2.4 KiB
/**
|
|
* Created by jiachenpan on 16/11/18.
|
|
*/
|
|
import store from '../store'
|
|
|
|
export function isvalidUsername(str) {
|
|
const valid_map = ['admin', 'editor']
|
|
return valid_map.indexOf(str.trim()) >= 0
|
|
}
|
|
|
|
/* 合法uri*/
|
|
export function validateURL(textval) {
|
|
const urlregex = /^(https?|ftp):\/\/([a-zA-Z0-9.-]+(:[a-zA-Z0-9.&%$-]+)*@)*((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}|([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(:[0-9]+)*(\/($|[a-zA-Z0-9.,?'\\+&%$#=~_-]+))*$/
|
|
return urlregex.test(textval)
|
|
}
|
|
|
|
/* 小写字母*/
|
|
export function validateLowerCase(str) {
|
|
const reg = /^[a-z]+$/
|
|
return reg.test(str)
|
|
}
|
|
|
|
/* 大写字母*/
|
|
export function validateUpperCase(str) {
|
|
const reg = /^[A-Z]+$/
|
|
return reg.test(str)
|
|
}
|
|
|
|
/* 大小写字母*/
|
|
export function validatAlphabets(str) {
|
|
const reg = /^[A-Za-z]+$/
|
|
return reg.test(str)
|
|
}
|
|
|
|
export function isExternal(path) {
|
|
return /^(http?:|mailto:|tel:)/.test(path)
|
|
}
|
|
|
|
/* 手机号 */
|
|
export function validatorPhone(str) {
|
|
const reg = /^1[3|4|5|7|8][0-9]\d{8}$/
|
|
return reg.test(str)
|
|
}
|
|
|
|
export default {
|
|
/**
|
|
* 判断该用户是否拥有该按钮权限
|
|
* @param permission 按钮权限代码
|
|
* @returns {boolean}
|
|
*/
|
|
hasPerm(permission) {
|
|
return !!store.getters.permissions.filter(permissionCode => permissionCode === permission)[0]
|
|
},
|
|
/**
|
|
* 判断当前用户是否拥有该角色权限
|
|
* @param roleCode 权限代码
|
|
* @returns {boolean}
|
|
*/
|
|
hasRole(roleCode) {
|
|
const cordList = []
|
|
store.getters.roles.forEach(item => cordList.push(item.roleCode))
|
|
return cordList.includes(roleCode)
|
|
},
|
|
/**
|
|
* 判断当前用户是否不拥有该角色权限
|
|
* @param roleCode 权限代码
|
|
* @returns {boolean}
|
|
*/
|
|
notHasRole(roleCode) {
|
|
return !this.hasRole(roleCode)
|
|
},
|
|
/**
|
|
* 判断当前用户所属科室是否在给定范围内
|
|
* @param departmentIds
|
|
* @returns {boolean}
|
|
*/
|
|
hasDepartmentId(departmentIds) {
|
|
if (departmentIds instanceof Array) {
|
|
return !!departmentIds.filter(departmentId => departmentId === store.getters.departmentId)[0]
|
|
} else {
|
|
return departmentIds === store.getters.departmentId
|
|
}
|
|
},
|
|
/**
|
|
* 判断当前用户所属科室是否不在给定范围内
|
|
* @param departmentIds
|
|
* @returns {boolean}
|
|
*/
|
|
notHasDepartmentId(departmentIds) {
|
|
return !this.hasDepartmentId(departmentIds)
|
|
}
|
|
}
|
|
|