@94ai/nf-search-form 3.2.48 → 3.2.49

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/package/tools.ts DELETED
@@ -1,177 +0,0 @@
1
- /**
2
- * 创建唯一的字符串
3
- * @return {string} ojgdvbvaua40
4
- */
5
- export function createUniqueString(randomLength = 36) {
6
- return Number(Math.random().toString().substr(3, randomLength) + Date.now()).toString(36)
7
- }
8
-
9
- export function debounce(func, wait, immediate) {
10
- let timeout, args, context, timestamp, result
11
-
12
- const later = function() {
13
- // 据上一次触发时间间隔
14
- const last = +new Date() - timestamp
15
-
16
- // 上次被包装函数被调用时间间隔last小于设定时间间隔wait
17
- if (last < wait && last > 0) {
18
- timeout = setTimeout(later, wait - last)
19
- } else {
20
- timeout = null
21
- // 如果设定为immediate===true,因为开始边界已经调用过了此处无需调用
22
- if (!immediate) {
23
- result = func.apply(context, args)
24
- if (!timeout) context = args = null
25
- }
26
- }
27
- }
28
-
29
- return function(...args) {
30
- // @ts-ignore
31
- context = this
32
- timestamp = +new Date()
33
- const callNow = immediate && !timeout
34
- // 如果延时不存在,重新设定延时
35
- if (!timeout) timeout = setTimeout(later, wait)
36
- if (callNow) {
37
- result = func.apply(context, args)
38
- // @ts-ignore
39
- context = args = null
40
- }
41
-
42
- return result
43
- }
44
- }
45
- export const on = (function() {
46
- // @ts-ignore
47
- if (document.addEventListener) {
48
- return function(event, handler, element = window) {
49
- if (element && event && handler) {
50
- element.addEventListener(event, handler, false)
51
- }
52
- }
53
- } else {
54
- return function(event, handler, element = window) {
55
- if (element && event && handler) {
56
- // @ts-ignore
57
- element.attachEvent('on' + event, handler)
58
- }
59
- }
60
- }
61
- })()
62
-
63
- export function deepClone(source) {
64
- if (!source && typeof source !== 'object') {
65
- throw new Error('error arguments shallowClone')
66
- }
67
- const targetObj: Record<string, any> | Record<string, any>[] = source.constructor === Array ? [] : {}
68
- Object.keys(source).forEach((keys) => {
69
- if (source[keys] && typeof source[keys] === 'object') {
70
- targetObj[keys] = source[keys].constructor === Array ? [] : {}
71
- targetObj[keys] = deepClone(source[keys])
72
- } else {
73
- targetObj[keys] = source[keys]
74
- }
75
- })
76
- return targetObj
77
- }
78
-
79
- /**
80
- * 移除事件监听
81
- */
82
- export const off = (function() {
83
- // @ts-ignore
84
- if (document.removeEventListener) {
85
- return function(event, handler, element = window) {
86
- if (element && event) {
87
- element.removeEventListener(event, handler, false)
88
- }
89
- }
90
- } else {
91
- return function(event, handler, element = window) {
92
- if (element && event) {
93
- // @ts-ignore
94
- element.detachEvent('on' + event, handler)
95
- }
96
- }
97
- }
98
- })()
99
-
100
-
101
- /**
102
- * elementui日期时间范围 快捷选项
103
- */
104
- export const pickerOptionsRange = {
105
- shortcuts: [
106
- {
107
- text: '今天',
108
- onClick(picker) {
109
- const end = new Date()
110
- const start = new Date(new Date().toDateString())
111
- start.setTime(start.getTime())
112
- picker.$emit('pick', [start, end])
113
- }
114
- },
115
- {
116
- text: '最近一周',
117
- onClick(picker) {
118
- const end = new Date()
119
- const start = new Date()
120
- start.setTime(end.getTime() - 3600 * 1000 * 24 * 7)
121
- picker.$emit('pick', [start, end])
122
- }
123
- },
124
- {
125
- text: '最近一个月',
126
- onClick(picker) {
127
- const end = new Date()
128
- const start = new Date()
129
- start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
130
- picker.$emit('pick', [start, end])
131
- }
132
- },
133
- {
134
- text: '最近三个月',
135
- onClick(picker) {
136
- const end = new Date()
137
- const start = new Date()
138
- start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
139
- picker.$emit('pick', [start, end])
140
- }
141
- }
142
- ]
143
- }
144
-
145
- /**
146
- * elementui月份范围 快捷选项
147
- */
148
- export const pickerOptionsRangeMonth = {
149
- shortcuts: [
150
- {
151
- text: '今年至今',
152
- onClick(picker) {
153
- const end = new Date()
154
- const start = new Date(new Date().getFullYear(), 0)
155
- picker.$emit('pick', [start, end])
156
- }
157
- },
158
- {
159
- text: '最近半年',
160
- onClick(picker) {
161
- const end = new Date()
162
- const start = new Date()
163
- start.setMonth(start.getMonth() - 6)
164
- picker.$emit('pick', [start, end])
165
- }
166
- },
167
- {
168
- text: '最近一年',
169
- onClick(picker) {
170
- const end = new Date()
171
- const start = new Date()
172
- start.setMonth(start.getMonth() - 12)
173
- picker.$emit('pick', [start, end])
174
- }
175
- }
176
- ]
177
- }