dlsjs 1.0.5 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dlsjs.cjs.js +2 -0
- package/dist/dlsjs.cjs.js.map +1 -0
- package/dist/dlsjs.es.js +8326 -0
- package/dist/dlsjs.es.js.map +1 -0
- package/dist/dlsjs.umd.js +2 -0
- package/dist/dlsjs.umd.js.map +1 -0
- package/package.json +9 -5
- package/src/Browser/Dom.js +0 -127
- package/src/Browser/File.js +0 -174
- package/src/Browser/Local.js +0 -61
- package/src/Browser/Nav.js +0 -208
- package/src/Browser/Screen.js +0 -175
- package/src/Browser/Timer.js +0 -99
- package/src/ES/Chain.js +0 -62
- package/src/ES/Const.js +0 -24
- package/src/ES/Judgment.js +0 -184
- package/src/ES/QRW.js +0 -287
- package/src/ES/Singleton.js +0 -73
- package/src/ES/Trans.js +0 -390
- package/src/ES/Tree.js +0 -916
- package/src/Instance/transCore.js +0 -108
- package/src/Instance/transFunc.js +0 -84
- package/src/Instance/transRule.js +0 -32
- package/src/index.js +0 -19
package/src/Browser/Screen.js
DELETED
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 切换全屏状态
|
|
3
|
-
* 如果当前处于全屏模式则退出,否则进入全屏模式
|
|
4
|
-
* 时间复杂度O(1):直接调用浏览器API,无循环操作
|
|
5
|
-
*
|
|
6
|
-
* @param {HTMLElement} [element=document.documentElement] - 要设置为全屏的元素,默认为整个文档
|
|
7
|
-
* @returns {boolean} 操作是否成功执行
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* // 切换整个文档的全屏状态
|
|
11
|
-
* toggleFullscreen();
|
|
12
|
-
*
|
|
13
|
-
* // 切换指定元素的全屏状态
|
|
14
|
-
* toggleFullscreen(document.getElementById('myElement'));
|
|
15
|
-
*/
|
|
16
|
-
export function toggleFullscreen(element = document.documentElement) {
|
|
17
|
-
if (!element || !(element instanceof HTMLElement)) {
|
|
18
|
-
console.warn('dlsjs: toggleFullscreen 参数必须是有效的HTML元素');
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (isFullscreenActive()) {
|
|
23
|
-
return exitFullscreen();
|
|
24
|
-
} else {
|
|
25
|
-
return requestFullscreen(element);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* 请求进入全屏模式
|
|
31
|
-
* 时间复杂度O(1):直接调用浏览器API,无循环操作
|
|
32
|
-
*
|
|
33
|
-
* @param {HTMLElement} element - 要设置为全屏的元素
|
|
34
|
-
* @returns {boolean} 操作是否成功发起
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* requestFullscreen(document.getElementById('myElement'));
|
|
38
|
-
*/
|
|
39
|
-
export function requestFullscreen(element) {
|
|
40
|
-
if (!element || !(element instanceof HTMLElement)) {
|
|
41
|
-
console.warn('dlsjs: requestFullscreen 参数必须是有效的HTML元素');
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
try {
|
|
46
|
-
// 处理不同浏览器的全屏API
|
|
47
|
-
const requestMethod =
|
|
48
|
-
element.requestFullscreen ||
|
|
49
|
-
element.webkitRequestFullscreen ||
|
|
50
|
-
element.mozRequestFullScreen ||
|
|
51
|
-
element.msRequestFullscreen;
|
|
52
|
-
|
|
53
|
-
if (requestMethod) {
|
|
54
|
-
requestMethod.call(element);
|
|
55
|
-
return true;
|
|
56
|
-
} else {
|
|
57
|
-
console.warn('dlsjs: 当前浏览器不支持全屏API');
|
|
58
|
-
return false;
|
|
59
|
-
}
|
|
60
|
-
} catch (error) {
|
|
61
|
-
console.error('dlsjs: 全屏请求失败:', error);
|
|
62
|
-
return false;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* 退出全屏模式
|
|
68
|
-
* 时间复杂度O(1):直接调用浏览器API,无循环操作
|
|
69
|
-
*
|
|
70
|
-
* @returns {boolean} 操作是否成功发起
|
|
71
|
-
*
|
|
72
|
-
* @example
|
|
73
|
-
* exitFullscreen();
|
|
74
|
-
*/
|
|
75
|
-
export function exitFullscreen() {
|
|
76
|
-
try {
|
|
77
|
-
// 处理不同浏览器的退出全屏API
|
|
78
|
-
const exitMethod =
|
|
79
|
-
document.exitFullscreen ||
|
|
80
|
-
document.webkitExitFullscreen ||
|
|
81
|
-
document.mozCancelFullScreen ||
|
|
82
|
-
document.msExitFullscreen;
|
|
83
|
-
|
|
84
|
-
if (exitMethod) {
|
|
85
|
-
exitMethod.call(document);
|
|
86
|
-
return true;
|
|
87
|
-
} else {
|
|
88
|
-
console.warn('dlsjs: 当前浏览器不支持退出全屏API');
|
|
89
|
-
return false;
|
|
90
|
-
}
|
|
91
|
-
} catch (error) {
|
|
92
|
-
console.error('dlsjs: 退出全屏失败:', error);
|
|
93
|
-
return false;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* 检查当前是否处于全屏模式
|
|
99
|
-
* 时间复杂度O(1):直接访问浏览器属性,无循环操作
|
|
100
|
-
*
|
|
101
|
-
* @returns {boolean} 当前是否处于全屏模式
|
|
102
|
-
*
|
|
103
|
-
* @example
|
|
104
|
-
* if (isFullscreenActive()) {
|
|
105
|
-
* console.log('当前处于全屏模式');
|
|
106
|
-
* }
|
|
107
|
-
*/
|
|
108
|
-
export function isFullscreenActive() {
|
|
109
|
-
return !!(
|
|
110
|
-
document.fullscreenElement ||
|
|
111
|
-
document.webkitFullscreenElement ||
|
|
112
|
-
document.mozFullScreenElement ||
|
|
113
|
-
document.msFullscreenElement
|
|
114
|
-
);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* 获取当前全屏元素
|
|
119
|
-
* 时间复杂度O(1):直接访问浏览器属性,无循环操作
|
|
120
|
-
*
|
|
121
|
-
* @returns {HTMLElement|null} 当前全屏元素,如果没有则返回null
|
|
122
|
-
*
|
|
123
|
-
* @example
|
|
124
|
-
* const fullscreenElement = getFullscreenElement();
|
|
125
|
-
*/
|
|
126
|
-
export function getFullscreenElement() {
|
|
127
|
-
return (
|
|
128
|
-
document.fullscreenElement ||
|
|
129
|
-
document.webkitFullscreenElement ||
|
|
130
|
-
document.mozFullScreenElement ||
|
|
131
|
-
document.msFullscreenElement ||
|
|
132
|
-
null
|
|
133
|
-
);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* 添加全屏状态变化监听器
|
|
138
|
-
* 时间复杂度O(1):直接添加事件监听器,无循环操作
|
|
139
|
-
*
|
|
140
|
-
* @param {Function} callback - 状态变化时的回调函数
|
|
141
|
-
* @returns {Function} 移除监听器的函数
|
|
142
|
-
*
|
|
143
|
-
* @example
|
|
144
|
-
* const removeListener = addFullscreenChangeListener(() => {
|
|
145
|
-
* console.log('全屏状态发生变化');
|
|
146
|
-
* });
|
|
147
|
-
*
|
|
148
|
-
* // 稍后移除监听器
|
|
149
|
-
* removeListener();
|
|
150
|
-
*/
|
|
151
|
-
export function addFullscreenChangeListener(callback) {
|
|
152
|
-
if (typeof callback !== 'function') {
|
|
153
|
-
console.warn('dlsjs: addFullscreenChangeListener 参数必须是函数');
|
|
154
|
-
return () => {};
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
const eventName =
|
|
158
|
-
'fullscreenchange' in document ? 'fullscreenchange' :
|
|
159
|
-
'webkitfullscreenchange' in document ? 'webkitfullscreenchange' :
|
|
160
|
-
'mozfullscreenchange' in document ? 'mozfullscreenchange' :
|
|
161
|
-
'MSFullscreenChange' in document ? 'MSFullscreenChange' : null;
|
|
162
|
-
|
|
163
|
-
if (!eventName) {
|
|
164
|
-
console.warn('dlsjs: 当前浏览器不支持全屏变化事件');
|
|
165
|
-
return () => {};
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
const handler = () => callback(isFullscreenActive());
|
|
169
|
-
document.addEventListener(eventName, handler);
|
|
170
|
-
|
|
171
|
-
// 返回移除监听器的函数
|
|
172
|
-
return () => {
|
|
173
|
-
document.removeEventListener(eventName, handler);
|
|
174
|
-
};
|
|
175
|
-
}
|
package/src/Browser/Timer.js
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 等待一个结果为真的情况执行
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
export function waitValue (valueGetter, timeout = 10000, freq = 100) {
|
|
6
|
-
return new Promise((resolve,reject) => {
|
|
7
|
-
let count = 0
|
|
8
|
-
let timerId = setInterval(() => {
|
|
9
|
-
if(count*freq > timeout) {
|
|
10
|
-
clearInterval(timerId)
|
|
11
|
-
reject('等待超时')
|
|
12
|
-
}
|
|
13
|
-
if(valueGetter()) {
|
|
14
|
-
clearInterval(timerId)
|
|
15
|
-
resolve(valueGetter())
|
|
16
|
-
}
|
|
17
|
-
count++
|
|
18
|
-
}, freq)
|
|
19
|
-
})
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* 等待固定毫秒数
|
|
24
|
-
* @param ms
|
|
25
|
-
*/
|
|
26
|
-
export async function waitMS (ms) {
|
|
27
|
-
return new Promise(resolve => {
|
|
28
|
-
setTimeout(resolve, ms)
|
|
29
|
-
})
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* 一个变化代理,如果一段时间内反复横跳,则取最后,相当于节流防抖的赋值代理版本。
|
|
34
|
-
* 应用场景:解决loading状态在多处频繁变化
|
|
35
|
-
*/
|
|
36
|
-
export function lazyChange (obj, timeout = 100) {
|
|
37
|
-
let timer = null
|
|
38
|
-
const handler = {
|
|
39
|
-
set: (target, key, value) => {
|
|
40
|
-
if(!timer) target[key] = value
|
|
41
|
-
else clearTimeout(timer)
|
|
42
|
-
timer = setTimeout(() => {target[key] = value}, timeout)
|
|
43
|
-
return true
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return new Proxy(obj, handler)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* async防抖函数,接收一个async函数,返回节流的async函数
|
|
51
|
-
* 先执行一次,timeout毫秒内在发生调用则忽视,timeout后才可继续调用
|
|
52
|
-
*/
|
|
53
|
-
export function throttleAsync(func, timeout = 100) {
|
|
54
|
-
let lastTime = 0
|
|
55
|
-
return async function(...args) {
|
|
56
|
-
const now = Date.now()
|
|
57
|
-
if(now - lastTime < timeout) {
|
|
58
|
-
return
|
|
59
|
-
}
|
|
60
|
-
lastTime = now
|
|
61
|
-
return await func(...args)
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* 接收一个async函数,返回新的async函数
|
|
67
|
-
* 至少freq毫秒后触发该函数,freq内再次触发,取消前一次触发,直到freq毫秒内没有触发,正式执行这个函数
|
|
68
|
-
*/
|
|
69
|
-
export function debounceAsync(func, wait = 100) {
|
|
70
|
-
let timer = null
|
|
71
|
-
return function(...args) {
|
|
72
|
-
if(timer) clearTimeout(timer)
|
|
73
|
-
timer = setTimeout(() => {
|
|
74
|
-
func(...args)
|
|
75
|
-
}, wait)
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* 轮询工具
|
|
81
|
-
*/
|
|
82
|
-
export class Poll {
|
|
83
|
-
constructor() {
|
|
84
|
-
this.timer = null
|
|
85
|
-
this.func = () => {}
|
|
86
|
-
this.freq = 1000
|
|
87
|
-
}
|
|
88
|
-
init() {
|
|
89
|
-
if(this.timer) return
|
|
90
|
-
this.func()
|
|
91
|
-
this.timer = setInterval(() => {
|
|
92
|
-
this.func()
|
|
93
|
-
},this.freq)
|
|
94
|
-
}
|
|
95
|
-
destroy() {
|
|
96
|
-
clearInterval(this.timer)
|
|
97
|
-
this.timer = null
|
|
98
|
-
}
|
|
99
|
-
}
|
package/src/ES/Chain.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import * as r from 'ramda'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 代理函数执行
|
|
5
|
-
* @type {{get: ((function(*, *, *): (function(): *))|*)}}
|
|
6
|
-
*/
|
|
7
|
-
const handler = {
|
|
8
|
-
get: function (target, p, receiver) {
|
|
9
|
-
if (!r.isNil(target[p])) {
|
|
10
|
-
// 使用本身方法
|
|
11
|
-
if (r.is(Function, target[p])) {
|
|
12
|
-
return (...arg) => {
|
|
13
|
-
let result = target[p].call(target, ...arg)
|
|
14
|
-
return pack(result)
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
// 使用本身属性
|
|
18
|
-
else {
|
|
19
|
-
return pack(target[p])
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
// 使用ramda方法
|
|
23
|
-
if (r[p] instanceof Function) {
|
|
24
|
-
let func;
|
|
25
|
-
if (r[p].length > 1) {
|
|
26
|
-
const paramList = new Array(r[p].length - 1).fill(r.__)
|
|
27
|
-
func = r[p](...paramList, target)
|
|
28
|
-
} else {
|
|
29
|
-
func = () => r[p](target)
|
|
30
|
-
}
|
|
31
|
-
return (...args) => {
|
|
32
|
-
let result = func(...args)
|
|
33
|
-
return pack(result)
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return target[p]
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* 数据是否为数组或者对象
|
|
42
|
-
*/
|
|
43
|
-
function isAO(data) {
|
|
44
|
-
return ['[object Object]', '[object Array]'].includes(Object.prototype.toString.call(data))
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* 如果是对象或数组则包装成proxy
|
|
49
|
-
*/
|
|
50
|
-
function pack(data) {
|
|
51
|
-
if (isAO(data)) {
|
|
52
|
-
return new Proxy(data, handler)
|
|
53
|
-
} else {
|
|
54
|
-
return data
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export function Chain(data) {
|
|
59
|
-
return pack(data)
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export default Chain
|
package/src/ES/Const.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import {treeFind} from "./Tree";
|
|
2
|
-
|
|
3
|
-
export const ENLetters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
|
4
|
-
|
|
5
|
-
export class DLS {
|
|
6
|
-
constructor() {
|
|
7
|
-
this.treeFind = treeFind
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function generateRandomId() {
|
|
12
|
-
const chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
|
|
13
|
-
let result = '';
|
|
14
|
-
|
|
15
|
-
// 使用Web Crypto API获取安全的随机值
|
|
16
|
-
const randomValues = new Uint8Array(8);
|
|
17
|
-
crypto.getRandomValues(randomValues);
|
|
18
|
-
|
|
19
|
-
for (let i = 0; i < 8; i++) {
|
|
20
|
-
result += chars[randomValues[i] % chars.length];
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return result;
|
|
24
|
-
}
|
package/src/ES/Judgment.js
DELETED
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
import {isEmpty, isNil, type} from 'ramda'
|
|
2
|
-
import {RW} from "./QRW";
|
|
3
|
-
/**
|
|
4
|
-
* 区间判断
|
|
5
|
-
* @param value
|
|
6
|
-
* @param range
|
|
7
|
-
* @return {boolean|void|*}
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* isRangeIn(55,'[50,60]')
|
|
11
|
-
* 中括号开区间,小括号闭区间,大括号枚举匹配,直接填入数值判断等于
|
|
12
|
-
*/
|
|
13
|
-
export const isRangeIn = function (value, range) {
|
|
14
|
-
if(typeof range === 'number') range = range.toString()
|
|
15
|
-
if(!range) return false // range为空时默认错误
|
|
16
|
-
if(!value && value !== 0) return false // value为空时默认错误
|
|
17
|
-
if(!isNaN(value)) value = Number(value) // value不为number时强转一下
|
|
18
|
-
else {
|
|
19
|
-
console.error('isRangeIn first param "value" is NaN')
|
|
20
|
-
return false
|
|
21
|
-
}
|
|
22
|
-
let isContainMin = false
|
|
23
|
-
let isContainMax = false
|
|
24
|
-
let isGTMin = false
|
|
25
|
-
let isLTMax = false
|
|
26
|
-
// 纯数字时相等为真
|
|
27
|
-
if(!isNaN(Number(range))) return value === Number(range)
|
|
28
|
-
// 花括弧时,包含为真
|
|
29
|
-
if(range.includes('{') && range.includes('}')) {
|
|
30
|
-
let arrString = range.replace(/\{|}/g,'')
|
|
31
|
-
let arr = arrString.split(',').map(item => {
|
|
32
|
-
return Number(item)
|
|
33
|
-
})
|
|
34
|
-
return arr.includes(value)
|
|
35
|
-
}
|
|
36
|
-
// 位运算+幂运算(判断第几位是1)
|
|
37
|
-
if(range.includes('&pow')) {
|
|
38
|
-
let string = range.replace(/(&pow)/g,'')
|
|
39
|
-
return !!(value&Math.pow(2,Number(string) - 1))
|
|
40
|
-
}
|
|
41
|
-
// 位运算(与)
|
|
42
|
-
if(range.includes('&')) {
|
|
43
|
-
let string = range.replace(/(&)/g,'')
|
|
44
|
-
return !!(value&Number(string))
|
|
45
|
-
}
|
|
46
|
-
// 开闭区间,运算
|
|
47
|
-
let rangeArr = range.split(',')
|
|
48
|
-
if(rangeArr[0].includes('[')) isContainMin = true
|
|
49
|
-
if(rangeArr[1].includes(']')) isContainMax = true
|
|
50
|
-
let min = rangeArr[0].replace(/\[|]|\(|\)/g,'') || -Infinity
|
|
51
|
-
let max = rangeArr[1].replace(/\[|]|\(|\)/g,'') || Infinity
|
|
52
|
-
if(isContainMin) {
|
|
53
|
-
isGTMin = value >= min
|
|
54
|
-
}else {
|
|
55
|
-
isGTMin = value > min
|
|
56
|
-
}
|
|
57
|
-
if(isContainMax) {
|
|
58
|
-
isLTMax = value <= max
|
|
59
|
-
|
|
60
|
-
}else {
|
|
61
|
-
isLTMax = value < max
|
|
62
|
-
}
|
|
63
|
-
return isLTMax && isGTMin
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* 判断一个对象是否符合要求
|
|
68
|
-
* @param {{key,value,condition,prop,eval,enum,dateFormat,must,should,matchFuncName}} config
|
|
69
|
-
* @param {{}} data
|
|
70
|
-
* @param {{}} [myFuncMap]
|
|
71
|
-
* @return {boolean|*}
|
|
72
|
-
*/
|
|
73
|
-
export function matchRules(config, data) {
|
|
74
|
-
if(config.must) {
|
|
75
|
-
return checkMust(config.must, data)
|
|
76
|
-
}
|
|
77
|
-
if(config.should) {
|
|
78
|
-
return checkShould(config.should, data)
|
|
79
|
-
}
|
|
80
|
-
if(config.condition) {
|
|
81
|
-
let left = config.left
|
|
82
|
-
let right = config.right
|
|
83
|
-
if(config.leftKey) {
|
|
84
|
-
left = RW(data)[config.leftKey]
|
|
85
|
-
}
|
|
86
|
-
if(config.rightKey) {
|
|
87
|
-
right = RW(data)[config.rightKey]
|
|
88
|
-
}
|
|
89
|
-
if(config.condition === 'eq') {
|
|
90
|
-
return left === right
|
|
91
|
-
}
|
|
92
|
-
if(config.condition === 'ne') {
|
|
93
|
-
return left !== right
|
|
94
|
-
}
|
|
95
|
-
if(config.condition === 'lt') {
|
|
96
|
-
return left < right
|
|
97
|
-
}
|
|
98
|
-
if(config.condition === 'le') {
|
|
99
|
-
return left <= right
|
|
100
|
-
}
|
|
101
|
-
if(config.condition === 'gt') {
|
|
102
|
-
return left > right
|
|
103
|
-
}
|
|
104
|
-
if(config.condition === 'ge') {
|
|
105
|
-
return left >= right
|
|
106
|
-
}
|
|
107
|
-
if(config.condition === 'in') {
|
|
108
|
-
if(['String', 'Array'].includes(type(right))) {
|
|
109
|
-
return right?.includes(left)
|
|
110
|
-
}else {
|
|
111
|
-
console.error(`${right} is not String|Array`)
|
|
112
|
-
return false
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
if(config.condition === 'nin') {
|
|
116
|
-
if(['String', 'Array'].includes(type(right))) {
|
|
117
|
-
return !right?.includes(left)
|
|
118
|
-
}else {
|
|
119
|
-
console.error(`${right} is not String|Array`)
|
|
120
|
-
return false
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
if(config.condition === 'has') {
|
|
124
|
-
if(['String', 'Array'].includes(type(left))) {
|
|
125
|
-
return left?.includes(right)
|
|
126
|
-
}else {
|
|
127
|
-
console.error(`${left} is not String|Array`)
|
|
128
|
-
return false
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
if(config.condition === 'nhas') {
|
|
132
|
-
if(['String', 'Array'].includes(type(left))) {
|
|
133
|
-
return !left?.includes(right)
|
|
134
|
-
}else {
|
|
135
|
-
console.error(`${left} is not String|Array`)
|
|
136
|
-
return false
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
if(config.condition === 'notNull') {
|
|
140
|
-
return !isNil(left) && !isEmpty(left)
|
|
141
|
-
}
|
|
142
|
-
if(config.condition === 'isNull') {
|
|
143
|
-
return isNil(left) || isEmpty(left)
|
|
144
|
-
}
|
|
145
|
-
if(config.condition === 'any') {
|
|
146
|
-
return true
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
return true
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* 通用条件判断must
|
|
154
|
-
*/
|
|
155
|
-
export function checkMust(must, row) {
|
|
156
|
-
let result = []
|
|
157
|
-
for(let item of must) {
|
|
158
|
-
result.push(matchRules(item, row))
|
|
159
|
-
}
|
|
160
|
-
return !result.includes(false)
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* 通用条件判断should
|
|
165
|
-
*/
|
|
166
|
-
export function checkShould(should, row) {
|
|
167
|
-
let result = []
|
|
168
|
-
for(let item of should) {
|
|
169
|
-
result.push(matchRules(item, row))
|
|
170
|
-
}
|
|
171
|
-
return result.includes(true)
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* 类型判断
|
|
176
|
-
*/
|
|
177
|
-
export function isType(type, target) {
|
|
178
|
-
let typeList = type.split(',')
|
|
179
|
-
let result = []
|
|
180
|
-
for(let type of typeList) {
|
|
181
|
-
result.push(Object.prototype.toString.call(target) === `[object ${type}]`)
|
|
182
|
-
}
|
|
183
|
-
return result.includes(true)
|
|
184
|
-
}
|