【modify】使用ESLint格式化代码

This commit is contained in:
zer0Black
2023-03-01 09:33:58 +08:00
parent 694855ae8b
commit 63369b8b87
400 changed files with 42942 additions and 43132 deletions
+146 -149
View File
@@ -4,23 +4,23 @@ import { isURL } from '@/utils/validate'
import { ACCESS_TOKEN } from '@/store/mutation-types'
import onlineCommons from '@/components/onlineForm/onlineForm'
//
export function timeFix() {
export function timeFix () {
const time = new Date()
const hour = time.getHours()
return hour < 9 ? '早上好' : (hour <= 11 ? '上午好' : (hour <= 13 ? '中午好' : (hour < 20 ? '下午好' : '晚上好')))
}
export function welcome() {
export function welcome () {
const arr = ['休息一会儿吧', '准备吃什么呢?', '要不要打一把 DOTA', '我猜你可能累了']
let index = Math.floor((Math.random()*arr.length))
const index = Math.floor((Math.random() * arr.length))
return arr[index]
}
/**
* 触发 window.resize
*/
export function triggerWindowResizeEvent() {
let event = document.createEvent('HTMLEvents')
export function triggerWindowResizeEvent () {
const event = document.createEvent('HTMLEvents')
event.initEvent('resize', true, true)
event.eventType = 'message'
window.dispatchEvent(event)
@@ -31,18 +31,18 @@ export function triggerWindowResizeEvent() {
* @param obj
* @returns {*}
*/
export function filterObj(obj) {
if (!(typeof obj == 'object')) {
return;
export function filterObj (obj) {
if (!(typeof obj === 'object')) {
return
}
for ( let key in obj) {
if (obj.hasOwnProperty(key)
&& (obj[key] == null || obj[key] == undefined || obj[key] === '')) {
delete obj[key];
for (const key in obj) {
if (obj.hasOwnProperty(key) &&
(obj[key] == null || obj[key] == undefined || obj[key] === '')) {
delete obj[key]
}
}
return obj;
return obj
}
/**
@@ -51,130 +51,130 @@ export function filterObj(obj) {
* @param fmt
* @returns {*}
*/
export function formatDate(value, fmt) {
let regPos = /^\d+(\.\d+)?$/;
if(regPos.test(value)){
//如果是数字
let getDate = new Date(value);
let o = {
export function formatDate (value, fmt) {
const regPos = /^\d+(\.\d+)?$/
if (regPos.test(value)) {
// 如果是数字
const getDate = new Date(value)
const 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()
};
S: getDate.getMilliseconds()
}
if (/(y+)/.test(fmt)) {
fmt = fmt.replace(RegExp.$1, (getDate.getFullYear() + '').substr(4 - RegExp.$1.length))
}
for (let k in o) {
for (const 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);
return fmt
} else {
// TODO
value = value.trim()
return value.substr(0, fmt.length)
}
}
// 生成首页路由
export function generateIndexRouter(data) {
export function generateIndexRouter (data) {
const redirectPath = findFirstRoute(data)
let indexRouter = [{
path: '/',
name: 'dashboard',
//component: () => import('@/components/layouts/BasicLayout'),
component: resolve => require(['@/components/layouts/TabLayout'], resolve),
meta: { title: '首页' },
redirect: redirectPath,
children: [
...generateChildRouters(data)
]
},{
"path": "*", "redirect": "/404", "hidden": true
}]
return indexRouter;
const indexRouter = [{
path: '/',
name: 'dashboard',
// component: () => import('@/components/layouts/BasicLayout'),
component: resolve => require(['@/components/layouts/TabLayout'], resolve),
meta: { title: '首页' },
redirect: redirectPath,
children: [
...generateChildRouters(data)
]
}, {
path: '*', redirect: '/404', hidden: true
}]
return indexRouter
}
// 生成嵌套路由(子路由)
function generateChildRouters (data) {
const routers = [];
for (let item of data) {
let component = "";
if(item.component.indexOf("layouts")>=0){
component = "components/"+item.component;
}else{
component = "views/"+item.component;
function generateChildRouters (data) {
const routers = []
for (const 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 && item.meta.url.indexOf("{{") == 0)) {
item.meta.url = URL;
if (isURL(URL) || (item.meta.url && item.meta.url.indexOf('{{') == 0)) {
item.meta.url = URL
}
let componentPath
if(item.component=="modules/online/cgform/OnlCgformHeadList"){
if (item.component == 'modules/online/cgform/OnlCgformHeadList') {
componentPath = onlineCommons.OnlCgformHeadList
}else if(item.component=="modules/online/cgform/OnlCgformCopyList"){
} else if (item.component == 'modules/online/cgform/OnlCgformCopyList') {
componentPath = onlineCommons.OnlCgformCopyList
}else if(item.component=="modules/online/cgform/auto/OnlCgformAutoList"){
} else if (item.component == 'modules/online/cgform/auto/OnlCgformAutoList') {
componentPath = onlineCommons.OnlCgformAutoList
}else if(item.component=="modules/online/cgform/auto/OnlCgformTreeList"){
} else if (item.component == 'modules/online/cgform/auto/OnlCgformTreeList') {
componentPath = onlineCommons.OnlCgformTreeList
}else if(item.component=="modules/online/cgform/auto/erp/OnlCgformErpList"){
} else if (item.component == 'modules/online/cgform/auto/erp/OnlCgformErpList') {
componentPath = onlineCommons.OnlCgformErpList
}else if(item.component=="modules/online/cgform/auto/tab/OnlCgformTabList"){
} else if (item.component == 'modules/online/cgform/auto/tab/OnlCgformTabList') {
componentPath = onlineCommons.OnlCgformTabList
}else if(item.component=="modules/online/cgform/auto/innerTable/OnlCgformInnerTableList"){
} else if (item.component == 'modules/online/cgform/auto/innerTable/OnlCgformInnerTableList') {
componentPath = onlineCommons.OnlCgformInnerTableList
}else if(item.component=="modules/online/cgreport/OnlCgreportHeadList"){
} else if (item.component == 'modules/online/cgreport/OnlCgreportHeadList') {
componentPath = onlineCommons.OnlCgreportHeadList
}else if(item.component=="modules/online/cgreport/auto/OnlCgreportAutoList"){
} else if (item.component == 'modules/online/cgreport/auto/OnlCgreportAutoList') {
componentPath = onlineCommons.OnlCgreportAutoList
}else{
componentPath = resolve => require(['@/' + component+'.vue'], resolve)
} else {
componentPath = resolve => require(['@/' + component + '.vue'], resolve)
}
let menu = {
const menu = {
path: item.path,
name: item.name,
redirect:item.redirect,
redirect: item.redirect,
component: componentPath,
//component: resolve => require(['@/' + component+'.vue'], resolve),
hidden:item.hidden,
// component: resolve => require(['@/' + component+'.vue'], resolve),
hidden: item.hidden,
meta: {
title:item.meta.title ,
title: item.meta.title,
icon: item.meta.icon,
url:item.meta.url ,
permissionList:item.meta.permissionList,
keepAlive:item.meta.keepAlive,
/*update_begin author:wuxianquan date:20190908 for:赋值 */
internalOrExternal:item.meta.internalOrExternal,
/*update_end author:wuxianquan date:20190908 for:赋值 */
componentName:item.meta.componentName
url: item.meta.url,
permissionList: item.meta.permissionList,
keepAlive: item.meta.keepAlive,
/* update_begin author:wuxianquan date:20190908 for:赋值 */
internalOrExternal: item.meta.internalOrExternal,
/* update_end author:wuxianquan date:20190908 for:赋值 */
componentName: item.meta.componentName
}
}
if(item.alwaysShow){
menu.alwaysShow = true;
menu.redirect = menu.path;
if (item.alwaysShow) {
menu.alwaysShow = true
menu.redirect = menu.path
}
if (item.children && item.children.length > 0) {
menu.children = [...generateChildRouters( item.children)];
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-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菜单)------
// --update-end----author:scott---date:20190320------for:根据后台菜单配置,判断是否路由菜单字段,动态选择是否生成路由(为了支持参数URL菜单)------
}
return routers
}
@@ -184,7 +184,7 @@ function generateChildRouters (data) {
* @param obj 被克隆的对象
* @return 克隆后的对象
*/
export function cloneObject(obj) {
export function cloneObject (obj) {
return JSON.parse(JSON.stringify(obj))
}
@@ -198,18 +198,18 @@ export function cloneObject(obj) {
* @param2 最大值
* @return int 生成后的数字
*/
export function randomNumber() {
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)))
const [length] = arguments
// 生成指定长度的随机数字,首位一定不是 0
const 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
const [min, max] = arguments
return random(min, max)
} else {
return Number.NaN
@@ -222,12 +222,12 @@ export function randomNumber() {
* @param chats 可选字符串区间(只会生成传入的字符串中的字符)
* @return string 生成的字符串
*/
export function randomString(length, chats) {
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)
const num = randomNumber(0, chats.length - 1)
str += chats[num]
}
return str
@@ -237,8 +237,8 @@ export function randomString(length, chats) {
* 随机生成uuid
* @return string 生成的uuid
*/
export function randomUUID() {
let chats = '0123456789abcdef'
export function randomUUID () {
const chats = '0123456789abcdef'
return randomString(32, chats)
}
@@ -247,10 +247,10 @@ export function randomUUID() {
* @param string
* @returns {*}
*/
export function underLine2CamelCase(string){
return string.replace( /_([a-z])/g, function( all, letter ) {
return letter.toUpperCase();
});
export function underLine2CamelCase (string) {
return string.replace(/_([a-z])/g, function (all, letter) {
return letter.toUpperCase()
})
}
/**
@@ -258,11 +258,11 @@ export function underLine2CamelCase(string){
* @param bpmStatus
* @returns {*}
*/
export function showDealBtn(bpmStatus){
if(bpmStatus!="1"&&bpmStatus!="3"&&bpmStatus!="4"){
return true;
export function showDealBtn (bpmStatus) {
if (bpmStatus != '1' && bpmStatus != '3' && bpmStatus != '4') {
return true
}
return false;
return false
}
/**
@@ -270,13 +270,13 @@ export function showDealBtn(bpmStatus){
* @param css 要增强的css
* @param id style标签的id,可以用来清除旧样式
*/
export function cssExpand(css, id) {
let style = document.createElement('style')
style.type = "text/css"
export function cssExpand (css, id) {
const style = document.createElement('style')
style.type = 'text/css'
style.innerHTML = `@charset "UTF-8"; ${css}`
// 清除旧样式
if (id) {
let $style = document.getElementById(id)
const $style = document.getElementById(id)
if ($style != null) $style.outerHTML = ''
style.id = id
}
@@ -284,7 +284,6 @@ export function cssExpand(css, id) {
document.head.appendChild(style)
}
/** 用于js增强事件,运行JS代码,可以传参 */
// options 所需参数:
// 参数名 类型 说明
@@ -292,18 +291,17 @@ export function cssExpand(css, id) {
// event Object event对象
// jsCode String 待执行的js代码
// errorMessage String 执行出错后的提示(控制台)
export function jsExpand(options = {}) {
export function jsExpand (options = {}) {
// 绑定到window上的keyName
let windowKeyName = 'J_CLICK_EVENT_OPTIONS'
if (typeof window[windowKeyName] != 'object') {
const windowKeyName = 'J_CLICK_EVENT_OPTIONS'
if (typeof window[windowKeyName] !== 'object') {
window[windowKeyName] = {}
}
// 随机生成JS增强的执行id,防止冲突
let id = randomString(16, 'qwertyuioplkjhgfdsazxcvbnm'.toUpperCase())
const id = randomString(16, 'qwertyuioplkjhgfdsazxcvbnm'.toUpperCase())
// 封装按钮点击事件
let code = `
const code = `
(function (o_${id}) {
try {
(function (globalEvent, vm) {
@@ -322,13 +320,13 @@ export function jsExpand(options = {}) {
vm: options.vm,
event: options.event,
// 当执行完成时,无论如何都会调用的回调事件
done() {
done () {
// 执行完后删除新增的 script 标签不会撤销执行结果(已产生的结果不会被撤销)
script.outerHTML = ''
delete window[windowKeyName]['EVENT_' + id]
},
// 当js运行出错的时候调用的事件
error(e) {
error (e) {
console.group(`${options.errorMessage || '用户自定义JS增强代码运行出错'}${new Date()}`)
console.error(e)
console.groupEnd()
@@ -339,7 +337,6 @@ export function jsExpand(options = {}) {
document.body.appendChild(script)
}
/**
* 重复值验证工具方法
*
@@ -352,11 +349,11 @@ export function jsExpand(options = {}) {
* @param dataId 数据ID,可空
* @param callback
*/
export function validateDuplicateValue(tableName, fieldName, fieldVal, dataId, callback) {
export function validateDuplicateValue (tableName, fieldName, fieldVal, dataId, callback) {
if (fieldVal) {
let params = { tableName, fieldName, fieldVal, dataId }
const params = { tableName, fieldName, fieldVal, dataId }
api.duplicateCheck(params).then(res => {
res['success'] ? callback() : callback(res['message'])
res.success ? callback() : callback(res.message)
}).catch(err => {
callback(err.message || err)
})
@@ -375,11 +372,11 @@ export function validateDuplicateValue(tableName, fieldName, fieldVal, dataId, c
* @param value 被验证的值
* @param callback
*/
export function validateCheckRule(ruleCode, value, callback) {
export function validateCheckRule (ruleCode, value, callback) {
if (ruleCode && value) {
value = encodeURIComponent(value)
api.checkRuleByCode({ ruleCode, value }).then(res => {
res['success'] ? callback() : callback(res['message'])
res.success ? callback() : callback(res.message)
}).catch(err => {
callback(err.message || err)
})
@@ -395,8 +392,8 @@ export function validateCheckRule(ruleCode, value, callback) {
* @param key 可空,如果比较的是对象,可能存在地址不一样但值实际上是一样的情况,可以传此字段判断对象中唯一的字段,例如 id。不传则直接比较实际值
* @returns {boolean} 成功 push 返回 true,不处理返回 false
*/
export function pushIfNotExist(array, value, key) {
for (let item of array) {
export function pushIfNotExist (array, value, key) {
for (const item of array) {
if (key && (item[key] === value[key])) {
return false
} else if (item === value) {
@@ -425,7 +422,7 @@ export const failedSymbol = Symbol()
* @param promise 可传Promise对象或返回Promise对象的方法
* @returns {Promise<any>}
*/
export function alwaysResolve(promise) {
export function alwaysResolve (promise) {
return new Promise((resolve, reject) => {
let p = promise
if (typeof promise === 'function') {
@@ -454,10 +451,10 @@ export function alwaysResolve(promise) {
* @param delay 防抖的毫秒数
* @returns {Function}
*/
export function simpleDebounce(fn, delay = 100) {
export function simpleDebounce (fn, delay = 100) {
let timer = null
return function () {
let args = arguments
const args = arguments
if (timer) {
clearTimeout(timer)
}
@@ -474,8 +471,8 @@ export function simpleDebounce(fn, delay = 100) {
* @param replacer 替换后的内容
* @returns {String} 替换后的字符串
*/
export function replaceAll(text, checker, replacer) {
let lastText = text
export function replaceAll (text, checker, replacer) {
const lastText = text
text = text.replace(checker, replacer)
if (lastText !== text) {
return replaceAll(text, checker, replacer)
@@ -487,9 +484,9 @@ export function replaceAll(text, checker, replacer) {
* 获取事件冒泡路径,兼容 IE11EdgeChromeFirefoxSafari
* 目前使用的地方:JEditableTable Span模式
*/
export function getEventPath(event) {
let target = event.target
let path = (event.composedPath && event.composedPath()) || event.path
export function getEventPath (event) {
const target = event.target
const path = (event.composedPath && event.composedPath()) || event.path
if (path != null) {
return (path.indexOf(window) < 0) ? path.concat(window) : path
@@ -499,7 +496,7 @@ export function getEventPath(event) {
return [window]
}
let getParents = (node, memo) => {
const getParents = (node, memo) => {
memo = memo || []
const parentNode = node.parentNode
@@ -518,13 +515,13 @@ export function getEventPath(event) {
* @param name
* @returns {Vue | null|null|Vue}
*/
export function getVmParentByName(vm, name) {
let parent = vm.$parent
export function getVmParentByName (vm, name) {
const parent = vm.$parent
if (parent && parent.$options) {
if (parent.$options.name === name) {
return parent
} else {
let res = getVmParentByName(parent, name)
const res = getVmParentByName(parent, name)
if (res) {
return res
}
@@ -539,7 +536,7 @@ export function getVmParentByName(vm, name) {
* @param value 要处理的值
* @param def 默认值,如果value为(null | undefined)则返回的默认值,可不传,默认为''
*/
export function neverNull(value, def) {
export function neverNull (value, def) {
return value == null ? (neverNull(def, '')) : value
}
@@ -550,19 +547,19 @@ export function neverNull(value, def) {
* @param value 属性值
* @returns {string}
*/
export function removeArrayElement(array, prod, value) {
export function removeArrayElement (array, prod, value) {
let index = -1
for(let i = 0;i<array.length;i++){
if(array[i][prod] == value){
index = i;
break;
for (let i = 0; i < array.length; i++) {
if (array[i][prod] == value) {
index = i
break
}
}
if(index>=0){
array.splice(index, 1);
if (index >= 0) {
array.splice(index, 1)
}
}
export function findFirstRoute(data){
export function findFirstRoute (data) {
if (data[0]) {
if (data[0] && data[0].children && data[0].children.length > 0) {
return findFirstRoute(data[0].children)
@@ -575,7 +572,7 @@ export function findFirstRoute(data){
}
/** 判断是否是OAuth2APP环境 */
export function isOAuth2AppEnv() {
export function isOAuth2AppEnv () {
return /wxwork|dingtalk/i.test(navigator.userAgent)
}
@@ -586,7 +583,7 @@ export function isOAuth2AppEnv() {
* @param open 是否自动打开
* @returns {*}
*/
export function getReportPrintUrl(url, id, open) {
export function getReportPrintUrl (url, id, open) {
// URL支持{{ window.xxx }}占位符变量
url = url.replace(/{{([^}]+)?}}/g, (s1, s2) => eval(s2))
if (url.includes('?')) {