zhl-methods 1.0.4 → 1.1.0

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/README.md CHANGED
@@ -46,20 +46,25 @@ isPhone(123)
46
46
 
47
47
  ##### 获取导航栏高度
48
48
 
49
+ - @example getNavBarHeight() => 100
49
50
  - @returns {number}
50
51
 
51
52
  ##### 弹窗二次确认
52
53
 
54
+ - @example showModal(query,callback)
53
55
  - @param {Function} callback
54
56
 
55
57
  ##### 获取当前环境
56
58
 
59
+ - @example getEnv()
57
60
  - @returns {string} release 线上 trial 测试 develop 开发
58
61
 
59
62
  ##### 获取 appId
60
63
 
64
+ - @example getAppId()
61
65
  - @returns {string}
62
66
 
63
67
  ##### 获取底部安全距离
64
68
 
69
+ - @example getSafeBottom()
65
70
  - @returns {string}
package/VERSION.md ADDED
@@ -0,0 +1,14 @@
1
+ # zhl-methods
2
+
3
+ 版本更新日志
4
+
5
+ #### 1.0.5
6
+
7
+ - 增加 css 文件
8
+ - 单/多行文本溢出省略号 nowrap/manyWrap
9
+ - 滚动条样式 scrollbar
10
+
11
+ ### 1.1.0
12
+
13
+ - 删除 wx 'requestApi' 方法 使用 'showModal' 代替
14
+ - 小程序 兼容 uin 和 wx 方法
package/index.css ADDED
@@ -0,0 +1,49 @@
1
+ /* npm publish 发布命令 */
2
+ /* 单行溢出省略号 */
3
+ .nowrap {
4
+ /*溢出部分隐藏*/
5
+ overflow: hidden;
6
+ /*禁止换行*/
7
+ white-space: nowrap;
8
+ /*显示省略号*/
9
+ text-overflow: ellipsis;
10
+ }
11
+ /* 三行溢出省略号 */
12
+ .manyWrap {
13
+ /* 必须结合的属性 ,将对象作为弹性伸缩盒子模型显示 。*/
14
+ display: -webkit-box;
15
+ /* 必须结合的属性 ,设置或检索伸缩盒对象的子元素的排列方式 。*/
16
+ -webkit-box-orient: vertical;
17
+ /*要显示的行数*/
18
+ -webkit-line-clamp: 3;
19
+ line-clamp: 3;
20
+ /* 溢出部分隐藏 */
21
+ overflow: hidden;
22
+ }
23
+ /*滚动条整体部分*/
24
+ .scrollbar ::-webkit-scrollbar {
25
+ width: 8px;
26
+ height: 6px;
27
+ }
28
+ /*滚动条的轨道*/
29
+ .scrollbar ::-webkit-scrollbar-track {
30
+ background-color: #ffffff;
31
+ }
32
+ /*滚动条里面的小方块,能向上向下移动*/
33
+ .scrollbar ::-webkit-scrollbar-thumb {
34
+ background-color: #bfbfbf;
35
+ border-radius: 5px;
36
+ border: 1px solid #f1f1f1;
37
+ box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3);
38
+ cursor: pointer;
39
+ }
40
+ .scrollbar ::-webkit-scrollbar-thumb:hover {
41
+ background-color: #a8a8a8;
42
+ }
43
+ .scrollbar ::-webkit-scrollbar-thumb:active {
44
+ background-color: #787878;
45
+ }
46
+ /*边角,即两个滚动条的交汇处*/
47
+ .scrollbar ::-webkit-scrollbar-corner {
48
+ background-color: #ffffff;
49
+ }
package/js/index.js CHANGED
@@ -218,3 +218,52 @@ export const downloadFile = (url, name) => {
218
218
  a.click();
219
219
  a.remove();
220
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,8 +1,6 @@
1
1
  {
2
2
  "name": "zhl-methods",
3
- "version": "1.0.4",
4
- "description": "",
5
- "main": "index.js",
3
+ "version": "1.1.0",
6
4
  "license": "ISC",
7
5
  "dependencies": {
8
6
  "vue": "^3.5.12"
package/wx/index.js CHANGED
@@ -1,9 +1,11 @@
1
+ const thit = uni ? uni : wx;
1
2
  /**
2
3
  * 获取导航栏高度
4
+ * @example getNavBarHeight() => 100
3
5
  * @returns {number}
4
6
  */
5
7
  export const getNavBarHeight = () => {
6
- let res = wx.getSystemInfoSync();
8
+ let res = thit.getSystemInfoSync();
7
9
  let nav = 48;
8
10
  if (res.system.indexOf("iOS") > -1) {
9
11
  nav = 44;
@@ -15,7 +17,7 @@ export const getNavBarHeight = () => {
15
17
  * @param {Function} callback
16
18
  */
17
19
  export const requestApi = (callback) => {
18
- wx.showModal({
20
+ thit.showModal({
19
21
  title: "确认该操作吗?",
20
22
  confirmText: "确认",
21
23
  cancelText: "取消",
@@ -32,7 +34,7 @@ export const requestApi = (callback) => {
32
34
  * @param {Function} callback
33
35
  */
34
36
  export const showModal = (query = {}, callback) => {
35
- wx.showModal({
37
+ thit.showModal({
36
38
  title: query.title ? query.title : "确认该操作吗?",
37
39
  content: query.content ? query.content : "",
38
40
  confirmText: "确认",
@@ -49,21 +51,21 @@ export const showModal = (query = {}, callback) => {
49
51
  * @returns {string} release线上 trial测试 develop开发
50
52
  */
51
53
  export const getEnv = () => {
52
- return wx.getAccountInfoSync().miniProgram.envVersion;
54
+ return thit.getAccountInfoSync().miniProgram.envVersion;
53
55
  };
54
56
  /**
55
57
  * 获取appId
56
58
  * @returns {string}
57
59
  */
58
60
  export const getAppId = () => {
59
- return wx.getAccountInfoSync().miniProgram.appId;
61
+ return thit.getAccountInfoSync().miniProgram.appId;
60
62
  };
61
63
  /**
62
64
  * 获取底部安全距离
63
65
  * @returns {string}
64
66
  */
65
67
  export const getSafeBottom = () => {
66
- let winInfo = wx.getWindowInfo();
68
+ let winInfo = thit.getWindowInfo();
67
69
  return winInfo.safeArea.bottom - winInfo.safeArea.height;
68
70
  };
69
71
  /**
@@ -71,13 +73,13 @@ export const getSafeBottom = () => {
71
73
  * @param {string|number} 要复制的数据
72
74
  */
73
75
  export const copyText = (val) => {
74
- wx.setClipboardData({
76
+ thit.setClipboardData({
75
77
  data: val,
76
78
  success: () => {
77
- wx.showToast({ title: "复制成功", icon: "none" });
79
+ thit.showToast({ title: "复制成功", icon: "none" });
78
80
  },
79
81
  fail: (res) => {
80
- wx.showToast({ title: "复制失败", icon: "none" });
82
+ thit.showToast({ title: "复制失败", icon: "none" });
81
83
  },
82
84
  });
83
85
  };