code init

This commit is contained in:
chenxiaoxi
2021-05-25 18:06:45 +08:00
parent 02698d6dab
commit f54a8d4fa1
1367 changed files with 540755 additions and 21713 deletions
+450
View File
@@ -0,0 +1,450 @@
/**
* @description: axios二次封装
* @author: chenxiaoxi
* @date: 2018-09-04 11:29:34
*/
import axios from 'axios'
import router from '@/router'
import store from '@/store'
import {Message} from 'element-ui'
export const CancelToken = axios.CancelToken
// import 'element-ui/lib/theme-chalk/index.css'
const _axios = axios.create({
baseURL: '/'
})
/**
* @description: FormData
* @author: xx
* @date: 2018-08-14 16:57:48
*/
let formData = (data) => {
let _formData = new FormData()
for (let i in data) {
_formData.append(i, data[i])
}
return _formData
}
_axios.defaults.timeout = 60000
_axios.defaults.headers['Content-type'] = 'application/json'
window._axiosPromiseArr = []
/**
* @description: axios请求拦截器
* liuyan
*/
_axios.interceptors.request.use(
config => {
// 记录接口请求
// config.cancelToken = new axios.CancelToken(cancel => {
// // window._axiosPromiseArr.push({ cancel })
// })
return config
},
error => {
return Promise.reject(error.response)
})
/**
* @description: axios响应拦截器
* liuyan
*/
_axios.interceptors.response.use(
res => {
return res
},
error => {
// 登录超时
if (error.response.data.path === '/a/login' && store.state.isTimeOut === false) {
for (let key in store.state) {
if (key !== 'isTimeOut' && key !== 'laws_urm' && key !== 'laws_prm') {
store.state[key] = ''
}
}
Message.warning('登录超时,请重新登录')
router.push('/login')
store.state.isTimeOut = true
}
})
function api () {
return store.getters.getTypeFlag === 'CloudRepository' ? '/busApi/' : '/api/'
}
export default {
_axios,
/**
* @description: post方法
* @config: {
* _this : this (vue原型)
* loading: data中定义的 loading('字符串格式 例如data定义的myloading config:{ _this: this, loading: 'myloading' }')
* }
* @author: xx
* @date: 2018-08-14 16:59:56
*/
post (url, param, config, thenFun, exeFun) {
var _formData = formData(param)
// 参数包含this
let _this = config._this || false
// 参数包含loading
let loading = config.loading || false
// 是否显示操作提示
let showTips = config.showTips === undefined ? true : config.showTips
if (_this) {
_this[loading] = true
}
_axios.post(api() + url + '?' + new Date().getTime(), _formData).then(res => {
if (_this && loading) { _this[loading] = false }
if (res.data.ok !== undefined && showTips) {
let type = res.data.ok ? 'success' : 'warning'
if (_this) {
if (res.data.message !== '') {
_this.$message[type](res.data.message)
}
}
}
thenFun.call(this, res.data)
}).catch(err => {
if (_this && loading) {
_this[loading] = false
// _this.$Notice.error({
// title: '错误',
// desc: '网络连接错误'
// })
}
exeFun.call(this, err)
})
},
/**
* @description: post方法(json格式提交)
* @config: {
* _this : this (vue原型)
* loading: data中定义的 loading('字符串格式 例如data定义的myloading config:{ _this: this, loading: 'myloading' }')
* }
* @author: xx
* @date: 2018-08-14 16:59:56
*/
postData (url, param, config, thenFun, exeFun) {
// 参数包含this
let _this = config._this || false
// 参数包含loading
let loading = config.loading || false
// 是否显示操作提示
let showTips = config.showTips === undefined ? true : config.showTips
if (_this) {
_this[loading] = true
}
_axios.post(api() + url + '?' + new Date().getTime(), param).then(res => {
if (_this && loading) { _this[loading] = false }
if (res.data.ok !== undefined && showTips) {
let type = res.data.ok ? 'success' : 'warning'
if (_this && res.data.message !== '') {
_this.$message[type](res.data.message)
}
}
thenFun.call(this, res.data)
}).catch(err => {
if (_this && loading) {
_this[loading] = false
// _this.$Notice.error({
// title: '错误',
// desc: '网络连接错误'
// })
}
exeFun.call(this, err)
})
},
/**
* @description: $get方法(使用post方法获取数据)
* @config: {
* _this : this (vue原型)
* loading: data中定义的 loading('字符串格式 例如data定义的myloading config:{ _this: this, loading: 'myloading' }')
* }
* @author: xx
* @date: 2018-08-14 16:59:56
*/
$get (url, param, config, thenFun, exeFun) {
var _formData = formData(param)
// 参数包含this
let _this = config._this || false
// 参数包含loading
let loading = config.loading || false
if (_this) {
_this[loading] = true
}
_axios.post(api() + url + '?' + new Date().getTime(), _formData).then(res => {
if (_this && loading) { _this[loading] = false }
thenFun.call(this, res.data)
}).catch(err => {
if (_this && loading) {
_this[loading] = false
// _this.$Notice.error({
// title: '错误',
// desc: '网络连接错误'
// })
}
exeFun.call(this, err)
})
},
/**
* @description: get方法
* @config: {
* _this : this (vue原型)
* loading: data中定义的 loading('字符串格式 例如data定义的myloading config:{ _this: this, loading: 'myloading' }')
* }
* @author: xx
* @date: 2018-08-14 16:59:56
*/
get (url, param, config, thenFun, exeFun) {
// 参数包含this
let _this = config._this || false
// 参数包含loading
let loading = config.loading || false
if (_this) {
_this[loading] = true
}
_axios.get(api() + url + '?_t=' + new Date().getTime(), { params: param, cancelToken: config.cancelToken }).then(res => {
if (_this && loading) { _this[loading] = false }
// 返回data对象
if (res.ok !== undefined) {
if (res.ok) {
thenFun.call(this, res.data)
}
} else {
// 返回data数组
thenFun.call(this, res.data)
}
}).catch(err => {
if (_this && loading) {
_this[loading] = false
}
if (exeFun) {
exeFun.call(this, err)
}
})
},
/**
* @description: put方法
* @author: chenxiaoxi
* @date: 2018-09-06 13:28:37
*/
put (url, param, config, thenFun, exeFun) {
var _formData = formData(param)
// 参数包含this
let _this = config._this || false
// 参数包含loading
let loading = config.loading || false
if (_this) {
_this[loading] = true
}
_axios.put(api() + url, _formData).then(res => {
if (_this && loading) { _this[loading] = false }
thenFun.call(this, res.data)
}).catch(err => {
if (_this && loading) {
_this[loading] = false
}
exeFun.call(this, err)
})
},
/**
* @description: put方法(json提交)
* @author: chenxiaoxi
* @date: 2018-09-06 13:28:37
*/
putData (url, param, config, thenFun, exeFun) {
// 参数包含this
let _this = config._this || false
// 参数包含loading
let loading = config.loading || false
if (_this) {
_this[loading] = true
}
_axios.put(api() + url + '?' + new Date().getTime(), param).then(res => {
if (_this && loading) { _this[loading] = false }
if (res.data.ok !== undefined) {
let type = res.data.ok ? 'success' : 'warning'
if (_this && res.data.message !== '') {
_this.$message[type](res.data.message)
}
}
thenFun.call(this, res.data)
}).catch(err => {
if (_this && loading) {
_this[loading] = false
// _this.$Notice.error({
// title: '错误',
// desc: '网络连接错误'
// })
}
exeFun.call(this, err)
})
},
/**
* @description: delete方法
* @author: chenxiaoxi
* @date: 2018-09-14 09:55:30
*/
delete (url, param, config, thenFun, exeFun) {
// 参数包含this
let _this = config._this || false
// 参数包含loading
let loading = config.loading || false
if (_this) {
_this[loading] = true
}
_axios.delete(api() + url + '?' + new Date().getTime(), {
params: param
}).then(res => {
if (_this && loading) { _this[loading] = false }
if (res.data.ok !== undefined) {
let type = res.data.ok ? 'success' : 'warning'
if (_this) { if (res.data.message !== '') { _this.$message[type](res.data.message) } }
thenFun.call(this, res.data)
}
}).catch(err => {
if (_this && loading) {
_this[loading] = false
// _this.$Notice.error({
// title: '错误',
// desc: '网络连接错误'
// })
}
exeFun.call(this, err)
})
},
/**
* @description: delete方法(字符串)
* @author: chenxiaoxi
* @date: 2018-09-29 16:21:41
*/
deleteStr (url, param, config, thenFun, exeFun) {
// 参数包含this
let _this = config._this || false
// 参数包含loading
let loading = config.loading || false
if (_this) {
_this[loading] = true
}
_axios.delete(api() + url + '?' + new Date().getTime()).then(res => {
if (_this && loading) { _this[loading] = false }
if (res.data.ok !== undefined) {
let type = res.data.ok ? 'success' : 'warning'
if (_this) { if (res.data.message !== '') { _this.$message[type](res.data.message) } }
thenFun.call(this, res.data)
}
}).catch(err => {
if (_this && loading) {
_this[loading] = false
// _this.$Notice.error({
// title: '错误',
// desc: '网络连接错误'
// })
}
exeFun.call(this, err)
})
},
/**
* @description: 自定义请求类型
* @params: type为请求类型
* @author: chenxiaoxi
* @date: 2018-09-25 14:51:19
*/
ajax (type, url, param, config, thenFun, exeFun) {
// 参数包含this
let _this = config._this || false
// 参数包含loading
let loading = config.loading || false
if (_this) {
_this[loading] = true
}
_axios[type](api() + url + '?' + new Date().getTime(), param).then(res => {
if (_this && loading) { _this[loading] = false }
if (res.data.ok !== undefined) {
let type = res.data.ok ? 'success' : 'warning'
if (_this) { if (res.data.message !== '') { _this.$message[type](res.data.message) } }
if (res.data.ok) {
thenFun.call(this, res.data)
}
}
}).catch(err => {
if (_this && loading) {
_this[loading] = false
// _this.$Notice.error({
// title: '错误',
// desc: '网络连接错误'
// })
}
exeFun.call(this, err)
})
},
/**
* @description: 请求云端动态get方法
* @config: {
* _this : this (vue原型)
* loading: data中定义的 loading('字符串格式 例如data定义的myloading config:{ _this: this, loading: 'myloading' }')
* }
* @author: xx
* @date: 2018-08-14 16:59:56
*/
getMsgDynamicInfo (url, param, config, thenFun, exeFun) {
// 参数包含this
let _this = config._this || false
// 参数包含loading
let loading = config.loading || false
if (_this) {
_this[loading] = true
}
_axios.get('/busApi/' + url + '?' + new Date().getTime(), { params: param }).then(res => {
if (_this && loading) { _this[loading] = false }
// 返回data对象
if (res.ok !== undefined) {
if (res.ok) {
thenFun.call(this, res.data)
}
} else {
// 返回data数组
thenFun.call(this, res.data)
}
}).catch(err => {
if (_this && loading) {
_this[loading] = false
// _this.$Notice.error({
// title: '错误',
// desc: '网络连接错误'
// })
}
exeFun.call(this, err)
})
},
start (param, config, thenFun, exeFun) {
// 参数包含this
let _this = config._this || false
// 参数包含loading
let loading = config.loading || false
if (_this) {
_this[loading] = true
}
_axios.get(`/bat-wkflow/activiti_define_start?id=11`, {}).then(res => {
if (_this && loading) { _this[loading] = false }
// 返回data对象
if (res.ok !== undefined) {
if (res.ok) {
thenFun.call(this, res.data)
}
} else {
// 返回data数组
thenFun.call(this, res.data)
}
}).catch(err => {
if (_this && loading) {
_this[loading] = false
}
exeFun.call(this, err)
})
}
}
+62
View File
@@ -0,0 +1,62 @@
import axios from 'axios'
import router from '@/router'
import store from '@/store'
import {Message} from 'element-ui'
// import 'element-ui/lib/theme-chalk/index.css'
/**
* @description: FormData
* @author: xx
* @date: 2018-08-14 16:57:48
*/
let formData = (data) => {
let _formData = new FormData()
for (let i in data) {
_formData.append(i, data[i])
}
return _formData
}
const service = axios.create({
baseURL: '/'
})
service.defaults.timeout = 99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
service.defaults.headers['Content-type'] = 'application/json'
/**
* @description: axios请求拦截器
* liuyan
*/
service.interceptors.request.use(
config => {
if (config.params) {
// 解决IE请求不刷新
config.params._t = new Date().getTime()
}
return config
},
error => {
return Promise.reject(error.response)
})
/**
* @description: axios响应拦截器
* liuyan
*/
service.interceptors.response.use(
res => {
return res.data
},
error => {
// 登录超时
if (error.response.data.path === '/a/login' && store.state.isTimeOut === false) {
for (let key in store.state) {
if (key !== 'isTimeOut' && key !== 'laws_urm' && key !== 'laws_prm') {
store.state[key] = ''
}
}
Message.warning('登录超时,请重新登录')
router.push('/login')
store.state.isTimeOut = true
}
})
export default service
+10
View File
@@ -0,0 +1,10 @@
/**
* @author liuyan
* @Description: Base64加密 + 反转
*/
export default (item) => {
let Base64 = require('js-base64').Base64
let password = Base64.encode(item)
let code = password.split('').reverse().join('')
return code
}
+59
View File
@@ -0,0 +1,59 @@
/**
* @description: 按钮级权限
* @author: liuyan
*/
import Vue from 'vue'
import store from '@/store'
const btnPermission = Vue.directive('btnPermission', {
bind (el, binding, vnode) {
// 获取按钮权限
let btnPermission = binding.value
// 没有这个权限则移除
if (!Vue.prototype.$_has(btnPermission)) {
Vue.nextTick(() => {
el.parentNode.removeChild(el)
})
}
}
})
const tableBtnPermission = Vue.directive('tableBtnPermission', {
bind (el, binding, vnode) {
// 获取按钮权限
let btnPermission = binding.value
console.log(el, binding, vnode)
function handler(event) {
console.log(event)
event.stopImmediatePropagation()
return false
}
el.addEventListener('click', handler, true)
// 没有这个权限则移除
// if (!Vue.prototype.$_has(btnPermission)) {
// Vue.nextTick(() => {
// el.parentNode.removeChild(el)
// })
// }
}
})
// 权限检查方法
Vue.prototype.$_has = function (value) {
let has = false
let menuList = store.getters.getMenuList
if (menuList === '') {
return false
} else {
menuList.map((menu) => {
if (menu.id === value || value === undefined || value === '') {
has = true
}
})
}
return has
}
export {
btnPermission
}
+56
View File
@@ -0,0 +1,56 @@
/**
* @file: index.
* @intro: 时间格式化工具类.
*
/**
* 时间格式化函数
* 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符,
* 年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字)
*
* @param {Date||number} date Date对象或者时间戳
* @param {string} fmt 格式化字符串
* ("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
* ("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18
* @returns {string} 格式化后的字符串
*/
import moment from 'moment'
export default (date, fmt) => {
// 如果是时间戳的话那么转换成Date类型
if (typeof date === 'number') {
date = new Date(date)
} else if (typeof date === 'string') {
date = new Date(parseInt(date))
}
let o = {
// 月份
'M+': date.getMonth() + 1,
// 日
'd+': date.getDate(),
// 小时
'h+': date.getHours(),
// 分
'm+': date.getMinutes(),
// 秒
's+': date.getSeconds(),
// 季度
'q+': Math.floor((date.getMonth() + 3) / 3),
// 毫秒
'S': date.getMilliseconds()
}
if (/(y+)/.test(fmt)) { fmt = fmt.replace(RegExp.$1, (date.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
}
export const dateFormat = (str, format = 'YYYY-MM-DD') => {
if (moment(str).isValid()) {
return moment(str).format(format)
} else {
return str
}
}
+4
View File
@@ -0,0 +1,4 @@
// 将在各处使用该事件中心
// 组件通过它来通信
import Vue from 'vue'
export default new Vue()
+26
View File
@@ -0,0 +1,26 @@
let userId = ''
let modifyTimeStamp = 0
let globalVariable = {
modifyTimeStamp: 0
}
// setInterval(() => {
// console.log('global : userId', userId)
// console.log('global : modifyTimeStamp', modifyTimeStamp)
// }, 1000)
export const printData = function() {
console.log('global : userId', userId)
console.log('global : modifyTimeStamp', modifyTimeStamp)
}
export const setData = (userId2, modifyTimeStamp2) => {
userId = userId2
modifyTimeStamp = modifyTimeStamp2
}
// export default {
// userId,
// modifyTimeStamp,
// printData,
// setData
// }
export default globalVariable
+17
View File
@@ -0,0 +1,17 @@
/**
* @description: 判断是否含有指定权限
* @author: chenxiaoxi
* @date: 2019/01/17 15:42:32
*/
import store from '@/store'
export default (permissionId) => {
let flag = false
const MENULIST = store.getters.getMenuList
MENULIST.map((permissionItem) => {
if (permissionItem.id === permissionId) {
flag = true
}
})
return flag
}
+39
View File
@@ -0,0 +1,39 @@
/**
* 自定义插件
* liuyan
*/
import base64 from './base64'
import dateFormat from './date'
import hasPermission from './hasPermission'
// 表单验证
import verify from './verify'
const install = function (Vue) {
if (install.installed) return
install.installed = true
Object.defineProperties(Vue.prototype, {
// 封装全局加密
$base64: {
get () {
return base64
}
},
$dateFormat: {
get () {
return dateFormat
}
},
verify: {
get () {
return verify
}
},
$hasPermission: {
get () {
return hasPermission
}
}
})
}
export default {
install
}
+502
View File
@@ -0,0 +1,502 @@
/**
* @description: 通用正则验证方法
* @author: chenxiaoxi
* @date: 2018-09-04 11:29:05
*/
export const specialCharacterReg = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~@#¥……&*()——|{} %【】\\s‘;:”“'。,、?]")
export const asteriskReg = new RegExp('\\*')
export default {
// 验证Email
checkEmails (rule, value, callback) {
if (value === null || value === '') {
return callback(new Error('不能为空'))
}
let pattern = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/
if (!pattern.test(value)) {
return callback(new Error('邮箱格式不正确'))
} else {
callback()
}
},
/**
* 验证字母、数字、.、-的正则
* 应用于标准编号、条款号等
* */
validateStandardItem (rule, value, callback) {
// return callback()
let testval = /^[A-Za-z0-9/ ,.-\\-()()]+$/
if (value && !value.match(testval)) {
return callback(new Error('只能为(字母、数字、.、-)'))
} else {
callback()
}
},
/**
* 验证字母、数字、.、-的正则且不能重复
* 应用于标准编号、条款号等
* */
validateStandardItemNoRepeat(rule, value, callback) {
// let testval = /^[A-Za-z0-9/ ,.-\\-()]+$/
// if (value && !value.match(testval)) {
// return callback(new Error('只能为(字母、数字、.、-'))
// } else
if (value.indexOf(',') > -1) {
const val = value.split(',')
const valList = []
const repeatList = []
let flag = true
val.map(item => {
if (!valList.includes(item)) {
valList.push(item)
} else {
repeatList.push(item)
flag = false
}
})
if (flag) {
callback()
} else {
return callback(new Error(`数据 ${repeatList.join(',')} 重复,请重新输入`))
}
} else {
callback()
}
},
// 验证动态内容
validateContent (rule, value, callback) {
if (value === '') {
return callback(new Error('动态内容不能为空且不能全为空格'))
} else {
callback()
}
},
// 验证手机号码
checkMobilePhone (rule, value, callback) {
if (!value) {
// return callback(new Error('手机号码不能为空'))
return callback()
}
let tel = /^1([358][0-9]|4[579]|66|7[0135678]|9[89])[0-9]{8}$/
if (!value.match(tel)) {
return callback(new Error('手机格式不正确'))
} else {
callback()
}
},
// 验证手机号码2
checkMobilePhone2 (rule, value, callback) {
let tel = /^1([358][0-9]|4[579]|66|7[0135678]|9[89])[0-9]{8}$/
if (value === '') {
callback()
} else if (!value.match(tel)) {
return callback(new Error('手机格式不正确'))
}
callback()
},
// 验证办公电话
checkOfficePhone (rule, value, callback) {
let tel2 = /^[0-9\-\\(\\)()x]+$/
if (value === null || value === '') {
callback()
} else if (!tel2.test(value)) {
return callback(new Error('办公电话格式不正确'))
} else {
callback()
}
},
// 验证个人中心传真
checkFaxAddress (rule, value, callback) {
let tel = /^\d{1,100}$/
if (value === null || value === '') {
callback()
} else if (!value.match(tel)) {
return callback(new Error('输入上限为100,且必须为数字'))
} else {
callback()
}
},
checkOnlyNumber (rule, value, callback) {
let tel = /^\d{1,2}$/
if (value === null || value === '') {
callback()
} else if (!value.match(tel)) {
return callback(new Error('仅能输入不大于两位的数字'))
} else {
callback()
}
},
// 验证特殊字符(非必填)
checkSpecialCharacter (rule, value, callback) {
if (value === '') {
callback()
} else {
let pattern = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~@#¥……&*()——|{} %【】\\s‘;:”“'。,、?]") // eslint-disable-line
setTimeout(() => {
if (pattern.test(value) === true) {
return callback(new Error('不能包含特殊字符'))
} else {
callback()
}
})
}
},
// 验证url
checkUrl (rule, value, callback) {
if (value === '') {
callback()
} else {
let pattern = new RegExp(/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?/i) // eslint-disable-line
if (!pattern.test(value)) {
return callback(new Error('链接网址格式错误'))
} else {
callback()
}
}
callback()
},
// 验证特殊字符无长度限制(必填)
checkSpecialCharacter2 (rule, value, callback) {
let pattern = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\]<>/?~@#¥……&*()——|{} %【】\\s‘;:”“'。,、?]") // eslint-disable-line
setTimeout(() => {
if (pattern.test(value) === true) {
return callback(new Error('不能包含特殊字符'))
} else {
callback()
}
})
},
// 车型项目库 项目名称校验使用 提示词不同 能输入 中英文 数字 横线(-) 下划线(_) 括号
checkSpecialCharacterProduct (rule, value, callback) {
let pattern = new RegExp("[`~!@#$^&*=|{}':;',\\[\\]<>/?~@#¥……&*|{} %【】\\s‘;:”“'。,、?]") // eslint-disable-line
setTimeout(() => {
if (pattern.test(value) === true) {
return callback(new Error('能输入中英文、数字、横线(-)、下划线(_)、括号'))
} else {
callback()
}
})
},
// 验证标准法规属性管理字符长度与非空
checkCharacter (rule, value, callback) {
if (value === '') {
return callback(new Error('选项不能为空'))
} else {
let pattern = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~@#¥……&*()——|{} %【】\\s‘;:”“'。,、?]") // eslint-disable-line
setTimeout(() => {
if (pattern.test(value) === true) {
return callback(new Error('不能包含特殊字符'))
}
callback()
})
}
},
// 验证标准法规属性管理字符长度与非空
checkCharacter2 (rule, value, callback) {
if (value === '') {
return callback(new Error('描述不能为空'))
} else {
let pattern = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~@#¥……&*()——|{} % \\s【】‘;:”“'。,、?]") // eslint-disable-line
setTimeout(() => {
if (pattern.test(value) === true) {
return callback(new Error('不能包含特殊字符'))
}
callback()
})
}
},
// 验证动态信息管理动态标题
checkInformation (rule, value, callback) {
if (value === '') {
return callback(new Error('动态标题不能为空'))
} else {
let pattern = new RegExp("[`~!@#$^&*=|{}':;',\\[\\].<>/?~@#¥……&*——|{}%【】‘;:”“'。,、?]") // eslint-disable-line
setTimeout(() => {
if (pattern.test(value) === true) {
return callback(new Error('不能包含特殊字符'))
}
callback()
})
}
},
// 验证动态信息管理动态标题
checkInformationTestItemStand (rule, value, callback) {
if (value === '') {
return callback(new Error('动态标题不能为空'))
} else {
let pattern = new RegExp("[`~!@#$^&*=|{}':;',\\[\\]<>?~@#¥……&*——|{}%【】‘;:”“'。,、?]") // eslint-disable-line
setTimeout(() => {
if (pattern.test(value) === true) {
return callback(new Error('不能包含特殊字符'))
}
callback()
})
}
},
// 验证账号
checkUsername (nullTips, errTips) {
return (rule, value, callback) => {
if (!value) {
return callback(new Error(nullTips || '不能为空'))
}
let pattern = /\w{3,15}$/
setTimeout(() => {
if (pattern.test(value) === false) {
return callback(new Error(errTips || '只能由3-15位的数字、字母组成'))
} else {
callback()
}
}, 1000)
}
},
validateStandardNum (rule, value, callback) {
let testval = /^\d+(\.\d+)*$/
let pattern1 = /\w{1,100}$/
let pattern2 = /\w{0,100}$/ // 验证代替标准号,和被代替标准号,因为非必填项,所以长度可能是0
if (rule.field === 'standNumber') {
if (!value) {
return callback(new Error('标准编号不能为空'))
} else if (!value.match(testval)) {
return callback(new Error('1到100字符数字,支持“数字.数字”'))
} else if (!value.match(pattern1) && rule.field === 'standNumber') {
return callback(new Error('1到100字符数字,支持“数字.数字”'))
} else {
callback()
}
} else {
if (value) {
if (!value.match(testval)) {
return callback(new Error('100以内字符,支持“数字.数字”'))
} else if (!value.match(pattern2) && rule.field !== 'standNumber') {
return callback(new Error('100以内字符,支持“数字.数字”'))
} else {
callback()
}
} else {
callback()
}
}
},
// 验证排序序号 0-100
validateStandarOrder (rule, value, callback) {
if (!value) {
return callback(new Error('排序序号不能为空'))
}
let pattern = /^\+?[0-9]*$/
setTimeout(() => {
if (!pattern.test(value)) {
return callback(new Error('请输入100以内的非负整数'))
} else if (value > 100) {
return callback(new Error('请输入100以内的非负整数'))
} else {
callback()
}
})
},
/**
* 验证不为0的正整数正则
* */
validStandNumInCompile2 (rule, value, callback) {
// let pattern = /^\d+$/
let pattern = /^[1-9]\d*$/
setTimeout(() => {
if (!pattern.test(value)) {
return callback(new Error('仅能输入正整数'))
} else {
callback()
}
})
},
validStandNumInCompile3 (rule, value, callback) {
let pattern = /^\d+$/
setTimeout(() => {
if (!pattern.test(value)) {
return callback(new Error('仅能输入正整数'))
} else if (value > 4000) {
return callback(new Error('最大长度不能超过4000'))
} else {
callback()
}
})
},
valiateEnName (rule, value, callback) {
let reg = /[\u4E00-\u9FA5\uF900-\uFA2D'"‘’”“]/
if (value === '' || value == null) {
callback()
} else {
if (value.match(reg)) {
return callback(new Error('英文名称不能输入中文及引号'))
} else {
/* let pattern = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~@#¥……&*()——|{} %【】‘;:”“'。,、?]") // eslint-disable-line
setTimeout(() => {
if (pattern.test(value) === true) {
return callback(new Error('不能包含特殊字符'))
} else {
callback()
}
}) */
callback()
}
}
},
remakeY (rule, value, callback) {
let reg = /[‘’”“'"]/g
if (value === '' || value == null) {
callback()
} else {
if (value.match(reg)) {
return callback(new Error('不能输入引号'))
} else {
callback()
}
}
},
remakeBD (rule, value, callback) {
let reg = /[‘’”“']/g
if (value === '' || value == null) {
callback()
} else {
if (value.match(reg)) {
return callback(new Error('不能输入引号'))
} else {
callback()
}
}
},
valiateName (rule, value, callback) {
let reg = /[^\u4E00-\u9FA5‘’”“'"]/g
if (value === '' || value == null) {
callback()
} else {
if (value.match(reg)) {
return callback(new Error('中文名称不能输入英文及引号'))
} else {
/* let pattern = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~@#¥……&*()——|{} %【】‘;:”“'。,、?]") // eslint-disable-line
setTimeout(() => {
if (pattern.test(value) === true) {
return callback(new Error('不能包含特殊字符'))
} else {
callback()
}
}) */
callback()
}
}
},
// 验证年份
valiateStandYear (rule, value, callback) {
let reg = /^\d{4}$/
if (value.match(reg)) {
callback()
} else {
return callback(new Error('输入正确的年份'))
}
},
// 验证特殊字符,但不包括半角分号(非必填) gaoyan
checkSpecialCharacterOftags (rule, value, callback) {
if (value === '') {
callback()
} else {
let pattern = new RegExp("[`~!@#$^&*=|{}':',\\[\\].<>/?~@#¥……&*——|{}%【】‘:”“'。,、?]") // eslint-disable-line
setTimeout(() => {
if (pattern.test(value) === true) {
return callback(new Error('不能包含特殊字符'))
}
callback()
})
}
},
// syt 系统账户验证
checkUsername2 (rule, value, callback) {
let reg = /^(?=.*[a-zA-Z])/
if (value === '' || value == null) {
return callback(new Error('系统账号不能为空'))
} else {
if (!value.match(reg)) {
return callback(new Error('至少包含1个字母'))
} else {
let pattern = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~@#¥……&*()——|{} %【】‘;:”“'。,、?]") // eslint-disable-line
setTimeout(() => {
if (pattern.test(value) === true) {
return callback(new Error('不能包含特殊字符'))
} else {
callback()
}
})
}
}
},
// 验证企业标准台账标准编号,仅能输入英文,数字,点,/,-
validStandNumInCompile (rule, value, callback) {
if (value === '') {
callback()
} else {
let pattern = /^[a-zA-Z0-9//]*$/
setTimeout(() => {
if (!value.match(pattern)) {
return callback(new Error('仅能输入英文,数字,/'))
}
callback()
})
}
},
valiCategory (rule, value, callback) {
if (value != null && value.length > 20) {
return callback(new Error('多选择项不能超过20个'))
} else {
callback()
}
},
// 验证输入数字和英文
testItemCode (rule, value, callback) {
let reg = /^[0-9a-zA-Z]+$/
if (value !== '' && !value.match(reg)) {
return callback(new Error('只能输入字母、数字'))
} else {
callback()
}
},
validUrl (rule, value, callback) {
let reg = /(^((https|ftp|http|file):\/\/)|www\.)*([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.,?'\\+&%$#=~_-]+))*$/gm
if (!value.match(reg)) {
return callback(new Error('请输入正确的网址'))
} else {
callback()
}
},
valiApply (rule, value, callback) {
if (value != null && value.length > 100) {
return callback(new Error('多选择项不能超过100个'))
} else {
callback()
}
},
validFieldOracle (rule, value, callback) {
if (value === '') {
callback()
} else {
let pattern = /^[A-Z_]+$/
setTimeout(() => {
if (!value.match(pattern)) {
return callback(new Error('仅能包含大写英文,下划线'))
}
callback()
})
}
},
// 验证编码
validateCode (rule, value, callback) {
if (value === '') {
callback()
} else {
let pattern = /^[A-Z0-9]*$/
setTimeout(() => {
if (!value.match(pattern)) {
return callback(new Error('仅能包含大写英文,数字'))
}
callback()
})
}
},
}