zhl-methods 1.0.3 → 1.0.5

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/index.css ADDED
@@ -0,0 +1,48 @@
1
+ /* 单行溢出省略号 */
2
+ .nowrap {
3
+ /*溢出部分隐藏*/
4
+ overflow: hidden;
5
+ /*禁止换行*/
6
+ white-space: nowrap;
7
+ /*显示省略号*/
8
+ text-overflow: ellipsis;
9
+ }
10
+ /* 三行溢出省略号 */
11
+ .manyWrap {
12
+ /* 必须结合的属性 ,将对象作为弹性伸缩盒子模型显示 。*/
13
+ display: -webkit-box;
14
+ /* 必须结合的属性 ,设置或检索伸缩盒对象的子元素的排列方式 。*/
15
+ -webkit-box-orient: vertical;
16
+ /*要显示的行数*/
17
+ -webkit-line-clamp: 3;
18
+ line-clamp: 3;
19
+ /* 溢出部分隐藏 */
20
+ overflow: hidden;
21
+ }
22
+ /*滚动条整体部分*/
23
+ .scrollbar ::-webkit-scrollbar {
24
+ width: 8px;
25
+ height: 6px;
26
+ }
27
+ /*滚动条的轨道*/
28
+ .scrollbar ::-webkit-scrollbar-track {
29
+ background-color: #ffffff;
30
+ }
31
+ /*滚动条里面的小方块,能向上向下移动*/
32
+ .scrollbar ::-webkit-scrollbar-thumb {
33
+ background-color: #bfbfbf;
34
+ border-radius: 5px;
35
+ border: 1px solid #f1f1f1;
36
+ box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3);
37
+ cursor: pointer;
38
+ }
39
+ .scrollbar ::-webkit-scrollbar-thumb:hover {
40
+ background-color: #a8a8a8;
41
+ }
42
+ .scrollbar ::-webkit-scrollbar-thumb:active {
43
+ background-color: #787878;
44
+ }
45
+ /*边角,即两个滚动条的交汇处*/
46
+ .scrollbar ::-webkit-scrollbar-corner {
47
+ background-color: #ffffff;
48
+ }
package/js/index.js CHANGED
@@ -13,6 +13,20 @@ export const isPhone = (value) => {
13
13
  }
14
14
  return false;
15
15
  };
16
+ /**
17
+ * 身份证号校验
18
+ * @example isIDCode('410781199909090000') => true
19
+ * @param value 要校验的数据
20
+ * @returns true false 是 否
21
+ */
22
+ export const isIDCode = (value) => {
23
+ if (typeof value == "string") {
24
+ return /^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/.test(
25
+ value
26
+ );
27
+ }
28
+ return false;
29
+ };
16
30
  /**
17
31
  * 对象转url参数
18
32
  * @example toUrlQuery({a:1}) => '?a=1'
@@ -31,7 +45,7 @@ export const toUrlQuery = (query) => {
31
45
  }
32
46
  };
33
47
  /**
34
- * 对象转url参数
48
+ * 将传入的数据转换成千位符
35
49
  * @example numberToPrice(1234.12) => '1,234.12'
36
50
  * @param {number} 要转换的数字
37
51
  * @returns {String} '1,234.12'
@@ -47,6 +61,17 @@ export const numberToPrice = (number) => {
47
61
  console.log(error, "numberToPrice");
48
62
  }
49
63
  };
64
+ /**
65
+ * 千位符格式转换数字
66
+ * @example moneyToNumber('123,456.789') => 123456.789
67
+ * @author zhl
68
+ * @date 2023/11/23
69
+ * @param data 要转换的数据
70
+ * @returns 转换完成的数据
71
+ */
72
+ export const priceToNumber = (data) => {
73
+ return Number(data.replace(/,/gi, ""));
74
+ };
50
75
  /**
51
76
  * 保留两位小数
52
77
  * @example setTwoDecimal(3.144) => '3.14'
@@ -71,7 +96,174 @@ export const setTwoDecimal = (number, isAdjust) => {
71
96
  * @param {max} 最大值
72
97
  * @returns {Number} 98
73
98
  */
74
-
75
99
  export const getRandomNumber = (min, max) => {
76
100
  return Math.floor(Math.random() * (max - min + 1)) + min;
77
101
  };
102
+ /**
103
+ * 检测数据格式
104
+ * @example isType({},object) => true
105
+ * @example isType({}) => object
106
+ * @author zhl
107
+ * @param data 要检测的数据
108
+ * @param type 类型 非必填
109
+ * @returns 不传type 返回数据的类型
110
+ * 传type 返回 true false
111
+ */
112
+ export const isType = (data, type) => {
113
+ if (type) {
114
+ return Object.prototype.toString.call(data) === type;
115
+ }
116
+ return Object.prototype.toString.call(data);
117
+ };
118
+ /**
119
+ * 时间戳转换成时间
120
+ * @example toTypeDate('1701139100',true) => 2023-11-28 10:38:20
121
+ * @author zhl
122
+ * @param date 要转换的数据 Date格式
123
+ * @param isSeconds 是否显示秒
124
+ * @returns 转换完成的数据
125
+ */
126
+ export const toTypeDate = (date, isSeconds) => {
127
+ if (date && typeof date == "number") {
128
+ String(date).length == 10
129
+ ? (date = new Date(date * 1000))
130
+ : (date = new Date(date));
131
+ } else {
132
+ date = new Date();
133
+ }
134
+ const year = date.getFullYear();
135
+ let month = date.getMonth() + 1;
136
+ let ri = date.getDate();
137
+ let hours = date.getHours();
138
+ let minutes = date.getMinutes();
139
+ let seconds = date.getSeconds();
140
+ if (month < 10) month = "0" + month;
141
+ if (ri < 10) ri = "0" + ri;
142
+ if (hours < 10) hours = "0" + hours;
143
+ if (minutes < 10) minutes = "0" + minutes;
144
+ if (seconds < 10) seconds = "0" + seconds;
145
+
146
+ return (
147
+ year +
148
+ "-" +
149
+ month +
150
+ "-" +
151
+ ri +
152
+ " " +
153
+ hours +
154
+ ":" +
155
+ minutes +
156
+ (isSeconds ? ":" + seconds : "")
157
+ );
158
+ };
159
+ /**
160
+ * 转换成整数
161
+ * @example toInt(123.123) => 123
162
+ * @param value 要转成整数的数据 字符串 数字
163
+ * @returns true false 是 否
164
+ */
165
+ export const toInt = (value) => {
166
+ if (typeof value == "number") {
167
+ return ~~value;
168
+ }
169
+ if (typeof value == "string") {
170
+ return parseInt(value, 10);
171
+ }
172
+ return 0;
173
+ };
174
+ /**
175
+ * 复制
176
+ * @example copyText(123) => Promise
177
+ * @param content 要复制的数据
178
+ * @returns Promise 复制成功 失败
179
+ */
180
+ export const copyText = (content) => {
181
+ return new Promise((resolve, reject) => {
182
+ try {
183
+ // 创建输入框元素
184
+ const input = document.createElement("input"); //不会保留文本格式
185
+ //如果要保留文本格式,比如保留换行符,或者多行文本,可以使用 textarea 标签,再配和模板字符串 ` `
186
+ //const input = document.createElement('textarea')
187
+ // 将想要复制的值
188
+ input.value = content;
189
+ // 页面底部追加输入框
190
+ document.body.appendChild(input);
191
+ // 选中输入框
192
+ input.select();
193
+ // 执行浏览器复制命令
194
+ document.execCommand("Copy");
195
+ // 弹出复制成功信息
196
+ //this.$message.success('复制成功');
197
+ // 复制后移除输入框
198
+ input.remove();
199
+ resolve(true);
200
+ } catch (err) {
201
+ reject(err);
202
+ }
203
+ });
204
+ };
205
+ /**
206
+ * 下载文件
207
+ * @example downloadFile('www.baidu.com','文件名称')
208
+ * @param url 要下载的文件 地址
209
+ * @param name 要下载的文件名称
210
+ * @returns 没有返回值
211
+ */
212
+ export const downloadFile = (url, name) => {
213
+ let a = document.createElement("a");
214
+ a.href = url;
215
+ a.download = name;
216
+ a.style.display = "none";
217
+ document.body.appendChild(a);
218
+ a.click();
219
+ a.remove();
220
+ };
221
+ /**
222
+ * 防抖
223
+ * @example debounce(() => {}, 250)
224
+ * @param fn 防抖的函数
225
+ * @param wait 防抖时间 毫秒
226
+ * @returns fn
227
+ */
228
+ export const debounce = (fn, wait = 250) => {
229
+ let timeout = null;
230
+ return function () {
231
+ let context = this;
232
+ let args = arguments;
233
+ if (timeout) clearTimeout(timeout);
234
+ let callNow = !timeout;
235
+ timeout = setTimeout(() => {
236
+ timeout = null;
237
+ }, wait);
238
+ if (callNow) fn.apply(context, args);
239
+ };
240
+ };
241
+ /**
242
+ * 节流
243
+ * @example throttle(()=>{})
244
+ * @param fn 节流的函数
245
+ * @param threshhold 节流时间
246
+ * @param scope this
247
+ * @returns 没有返回值
248
+ */
249
+ export const throttle = (fn, threshhold, scope) => {
250
+ threshhold || (threshhold = 250);
251
+ var last, timer;
252
+ return function () {
253
+ var context = scope || this;
254
+ var now = +new Date(),
255
+ args = arguments;
256
+ if (last && now < last + threshhold) {
257
+ // 如果在节流时间内,则取消之前的延迟调用
258
+ clearTimeout(timer);
259
+ // 设定一个新的延迟调用
260
+ timer = setTimeout(function () {
261
+ last = now;
262
+ fn.apply(context, args);
263
+ }, threshhold);
264
+ } else {
265
+ last = now;
266
+ fn.apply(context, args);
267
+ }
268
+ };
269
+ };
package/package.json CHANGED
@@ -1,7 +1,10 @@
1
1
  {
2
2
  "name": "zhl-methods",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "",
5
5
  "main": "index.js",
6
- "license": "ISC"
6
+ "license": "ISC",
7
+ "dependencies": {
8
+ "vue": "^3.5.12"
9
+ }
7
10
  }
package/vue3/index.js ADDED
@@ -0,0 +1,7 @@
1
+ import { getCurrentInstance } from "vue";
2
+
3
+ export function useEmitter() {
4
+ const internalInstance = getCurrentInstance();
5
+ const emitter = internalInstance.appContext.config.globalProperties.emitter;
6
+ return emitter;
7
+ }
package/wx/index.js CHANGED
@@ -1,3 +1,6 @@
1
+ if (!wx) {
2
+ wx = uni;
3
+ }
1
4
  /**
2
5
  * 获取导航栏高度
3
6
  * @returns {number}