ls-pro-common 3.1.47 → 3.1.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.
Files changed (43) hide show
  1. package/dist/common.js +1 -1
  2. package/dist/common.min.js +1 -1
  3. package/es/components/InputTable.d.ts +2 -2
  4. package/es/components/InputTable.js +85 -32
  5. package/es/utils/cache.d.ts +28 -0
  6. package/es/utils/cache.js +63 -0
  7. package/es/utils/constant.d.ts +12 -0
  8. package/es/utils/constant.js +20 -0
  9. package/es/utils/cookie.d.ts +15 -0
  10. package/es/utils/cookie.js +36 -0
  11. package/es/utils/event.d.ts +16 -0
  12. package/es/utils/event.js +26 -0
  13. package/es/utils/index.d.ts +8 -179
  14. package/es/utils/index.js +12 -423
  15. package/es/utils/print.d.ts +24 -0
  16. package/es/utils/print.js +86 -0
  17. package/es/utils/project.d.ts +33 -0
  18. package/es/utils/project.js +66 -0
  19. package/es/utils/url.d.ts +26 -0
  20. package/es/utils/url.js +113 -0
  21. package/es/utils/user.d.ts +29 -0
  22. package/es/utils/user.js +25 -0
  23. package/lib/components/InputTable.d.ts +2 -2
  24. package/lib/components/InputTable.js +85 -32
  25. package/lib/utils/cache.d.ts +28 -0
  26. package/lib/utils/cache.js +63 -0
  27. package/lib/utils/constant.d.ts +12 -0
  28. package/lib/utils/constant.js +20 -0
  29. package/lib/utils/cookie.d.ts +15 -0
  30. package/lib/utils/cookie.js +36 -0
  31. package/lib/utils/event.d.ts +16 -0
  32. package/lib/utils/event.js +26 -0
  33. package/lib/utils/index.d.ts +8 -179
  34. package/lib/utils/index.js +12 -423
  35. package/lib/utils/print.d.ts +24 -0
  36. package/lib/utils/print.js +86 -0
  37. package/lib/utils/project.d.ts +33 -0
  38. package/lib/utils/project.js +66 -0
  39. package/lib/utils/url.d.ts +26 -0
  40. package/lib/utils/url.js +113 -0
  41. package/lib/utils/user.d.ts +29 -0
  42. package/lib/utils/user.js +25 -0
  43. package/package.json +1 -1
@@ -14,7 +14,7 @@ export declare type InputTableProps = ProFormItemProps<InputProps> & {
14
14
  /** @name 是否支持多选 */
15
15
  multiple?: boolean;
16
16
  /** @name 表单项name, 跟 form.item 的 name一致 */
17
- name: string;
17
+ name?: string;
18
18
  /** @name 返回的值字段,表格中valueField配置的字段时返回给name */
19
19
  valueField: string;
20
20
  /** @name 返回输入框显示的字段,textField字段值返回给textName */
@@ -74,7 +74,7 @@ declare const InputTable: React.ForwardRefExoticComponent<{
74
74
  /** @name 是否支持多选 */
75
75
  multiple?: boolean | undefined;
76
76
  /** @name 表单项name, 跟 form.item 的 name一致 */
77
- name: string;
77
+ name?: string | undefined;
78
78
  /** @name 返回的值字段,表格中valueField配置的字段时返回给name */
79
79
  valueField: string;
80
80
  /** @name 返回输入框显示的字段,textField字段值返回给textName */
@@ -1,3 +1,5 @@
1
+ import "antd/es/form/style";
2
+ import _Form from "antd/es/form";
1
3
  import "antd/es/input/style";
2
4
  import _Input from "antd/es/input";
3
5
  import "antd/es/popover/style";
@@ -11,7 +13,7 @@ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
11
13
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
12
14
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
13
15
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
14
- var _excluded = ["columns", "url", "textName", "name", "tableConfig", "tableHeight", "tableWidth", "readonly", "multiple", "valueField", "labelWidth", "textField", "onSelectChange", "beforeLoad", "afterLoad", "isV2", "allowClear", "keepSelect", "fieldProps", "searchField", "fillMap", "loadOnShow", "triggerCheck", "getPopupContainer", "placement", "arrowPointAtCenter", "rowKey", "method", "changeOnSelect", "record"],
16
+ var _excluded = ["columns", "url", "textName", "name", "tableConfig", "tableHeight", "tableWidth", "readonly", "multiple", "valueField", "labelWidth", "textField", "onSelectChange", "beforeLoad", "afterLoad", "isV2", "allowClear", "keepSelect", "fieldProps", "searchField", "fillMap", "loadOnShow", "triggerCheck", "getPopupContainer", "placement", "arrowPointAtCenter", "method", "changeOnSelect", "rowKey", "record", "id"],
15
17
  _excluded2 = ["current", "pageSize"];
16
18
  import _regeneratorRuntime from "@babel/runtime/regenerator";
17
19
  import React, { useRef, useState, useEffect, useContext, useMemo, useImperativeHandle } from 'react';
@@ -43,7 +45,7 @@ var InputTable = /*#__PURE__*/React.forwardRef(function (prop, ref) {
43
45
  var columns = prop.columns,
44
46
  url = prop.url,
45
47
  textName = prop.textName,
46
- name = prop.name,
48
+ itemName = prop.name,
47
49
  tableConfig = prop.tableConfig,
48
50
  _prop$tableHeight = prop.tableHeight,
49
51
  tableHeight = _prop$tableHeight === void 0 ? 400 : _prop$tableHeight,
@@ -80,12 +82,13 @@ var InputTable = /*#__PURE__*/React.forwardRef(function (prop, ref) {
80
82
  placement = _prop$placement === void 0 ? 'bottom' : _prop$placement,
81
83
  _prop$arrowPointAtCen = prop.arrowPointAtCenter,
82
84
  arrowPointAtCenter = _prop$arrowPointAtCen === void 0 ? true : _prop$arrowPointAtCen,
83
- rowKey = prop.rowKey,
84
85
  _prop$method = prop.method,
85
86
  method = _prop$method === void 0 ? 'GET' : _prop$method,
86
87
  _prop$changeOnSelect = prop.changeOnSelect,
87
88
  changeOnSelect = _prop$changeOnSelect === void 0 ? true : _prop$changeOnSelect,
89
+ rowKey = prop.rowKey,
88
90
  record = prop.record,
91
+ id = prop.id,
89
92
  rest = _objectWithoutProperties(prop, _excluded);
90
93
  if (!valueField && isDev) {
91
94
  console.error('valueField 属性必须设置');
@@ -93,10 +96,21 @@ var InputTable = /*#__PURE__*/React.forwardRef(function (prop, ref) {
93
96
  if (!url && isDev) {
94
97
  console.error('url 属性必须设置');
95
98
  }
99
+ var tableKey = (tableConfig === null || tableConfig === void 0 ? void 0 : tableConfig.rowKey) || valueField || 'id';
100
+ // 处理表单name, 如果不传入通过id来处理。在表格中,自动会添加Id
101
+ var name = useMemo(function () {
102
+ if (itemName) return itemName;
103
+ if (id) {
104
+ if (id.includes('_')) {
105
+ return id.slice(id.indexOf('_') + 1);
106
+ }
107
+ return id;
108
+ }
109
+ return '';
110
+ }, [itemName, id]);
96
111
  if (!name && isDev) {
97
112
  console.error('name 属性必须设置');
98
113
  }
99
- var tableKey = (tableConfig === null || tableConfig === void 0 ? void 0 : tableConfig.rowKey) || valueField || 'id';
100
114
  //显示输入框绑定的name,如果不设置textName,设置为$name__text
101
115
  var textNameProp = useMemo(function () {
102
116
  return textName ? textName : name + '__text';
@@ -120,6 +134,11 @@ var InputTable = /*#__PURE__*/React.forwardRef(function (prop, ref) {
120
134
  if (col) return col.searchField || col.dataIndex;
121
135
  return textField || valueField;
122
136
  }, [columns, searchField, valueField, textField]);
137
+ /**
138
+ * 获取表单值
139
+ *
140
+ * @returns
141
+ */
123
142
  var getFormValue = function getFormValue() {
124
143
  var _formRef$current2, _formRef$current2$get;
125
144
  if (rowKey) {
@@ -128,20 +147,31 @@ var InputTable = /*#__PURE__*/React.forwardRef(function (prop, ref) {
128
147
  }
129
148
  return formRef === null || formRef === void 0 ? void 0 : (_formRef$current2 = formRef.current) === null || _formRef$current2 === void 0 ? void 0 : (_formRef$current2$get = _formRef$current2.getFieldsValue) === null || _formRef$current2$get === void 0 ? void 0 : _formRef$current2$get.call(_formRef$current2);
130
149
  };
150
+ /**
151
+ * 设置表单值
152
+ *
153
+ * @param formValue
154
+ */
131
155
  var setFormValue = function setFormValue(formValue) {
132
- var _prop$onChange;
133
- (_prop$onChange = prop.onChange) === null || _prop$onChange === void 0 ? void 0 : _prop$onChange.call(prop, formValue[name]);
134
156
  if (rowKey) {
135
- var _formRef$current3, _formRef$current3$set;
157
+ var _formRef$current3, _formRef$current3$set, _prop$onChange;
136
158
  formRef === null || formRef === void 0 ? void 0 : (_formRef$current3 = formRef.current) === null || _formRef$current3 === void 0 ? void 0 : (_formRef$current3$set = _formRef$current3.setFieldsValue) === null || _formRef$current3$set === void 0 ? void 0 : _formRef$current3$set.call(_formRef$current3, _defineProperty({}, rowKey, formValue));
159
+ (_prop$onChange = prop.onChange) === null || _prop$onChange === void 0 ? void 0 : _prop$onChange.call(prop, formValue[textNameProp]);
137
160
  } else {
138
- var _formRef$current4, _formRef$current4$set;
161
+ var _prop$onChange2, _formRef$current4, _formRef$current4$set;
162
+ (_prop$onChange2 = prop.onChange) === null || _prop$onChange2 === void 0 ? void 0 : _prop$onChange2.call(prop, formValue[name]);
139
163
  formRef === null || formRef === void 0 ? void 0 : (_formRef$current4 = formRef.current) === null || _formRef$current4 === void 0 ? void 0 : (_formRef$current4$set = _formRef$current4.setFieldsValue) === null || _formRef$current4$set === void 0 ? void 0 : _formRef$current4$set.call(_formRef$current4, formValue);
140
164
  }
141
165
  };
166
+ /**
167
+ * 加载面板数据
168
+ *
169
+ * @param param
170
+ * @returns
171
+ */
142
172
  var loadData = /*#__PURE__*/function () {
143
173
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(param) {
144
- var current, pageSize, restParams, _selectRowRef$current, _rows, data, _tableRef$current2, _tableRef$current2$cl, _param, result, rows, formValue, val, _selectRowRef$current2, arr, pageSelectedRows;
174
+ var current, pageSize, restParams, _selectRowRef$current, _rows, data, _tableRef$current2, _tableRef$current2$cl, beforeParam, result, rows, formValue, val, _selectRowRef$current2, arr, pageSelectedRows;
145
175
  return _regeneratorRuntime.wrap(function _callee$(_context) {
146
176
  while (1) switch (_context.prev = _context.next) {
147
177
  case 0:
@@ -157,10 +187,10 @@ var InputTable = /*#__PURE__*/React.forwardRef(function (prop, ref) {
157
187
  return o[tableKey];
158
188
  })));
159
189
  setSelectedKeys(Array.from(new Set(selectedKeys)));
160
- setTimeout(function () {
190
+ requestIdleCallback(function () {
161
191
  var _tableRef$current, _tableRef$current$rel;
162
192
  (_tableRef$current = tableRef.current) === null || _tableRef$current === void 0 ? void 0 : (_tableRef$current$rel = _tableRef$current.reload) === null || _tableRef$current$rel === void 0 ? void 0 : _tableRef$current$rel.call(_tableRef$current);
163
- }, 0);
193
+ });
164
194
  return _context.abrupt("return", {
165
195
  data: _rows,
166
196
  total: _rows.length,
@@ -191,9 +221,9 @@ var InputTable = /*#__PURE__*/React.forwardRef(function (prop, ref) {
191
221
  _context.next = 16;
192
222
  return beforeLoad(data);
193
223
  case 16:
194
- _param = _context.sent;
195
- if (typeof _param !== 'boolean' && _param !== undefined) {
196
- data = _param;
224
+ beforeParam = _context.sent;
225
+ if (typeof beforeParam !== 'boolean' && beforeParam !== undefined) {
226
+ data = beforeParam;
197
227
  }
198
228
  case 18:
199
229
  if (!(method !== 'GET')) {
@@ -254,6 +284,13 @@ var InputTable = /*#__PURE__*/React.forwardRef(function (prop, ref) {
254
284
  return _ref.apply(this, arguments);
255
285
  };
256
286
  }();
287
+ /**
288
+ * 如果初始有值时,调用此方法初始化名称
289
+ *
290
+ * @param val
291
+ * @param updateTxt
292
+ * @returns
293
+ */
257
294
  var initName = function initName(val) {
258
295
  var updateTxt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
259
296
  if (!val) return;
@@ -310,6 +347,7 @@ var InputTable = /*#__PURE__*/React.forwardRef(function (prop, ref) {
310
347
  initName(val, false);
311
348
  }
312
349
  }
350
+ // eslint-disable-next-line react-hooks/exhaustive-deps
313
351
  }, [rowKey]);
314
352
  // 处理返回数据
315
353
  var handleValue = function handleValue(row) {
@@ -433,6 +471,19 @@ var InputTable = /*#__PURE__*/React.forwardRef(function (prop, ref) {
433
471
  (_tableRef$current5 = tableRef.current) === null || _tableRef$current5 === void 0 ? void 0 : (_tableRef$current5$re = _tableRef$current5.reload) === null || _tableRef$current5$re === void 0 ? void 0 : _tableRef$current5$re.call(_tableRef$current5);
434
472
  }
435
473
  }, [visible, loadOnShow]);
474
+ // 处理有值时,可清空
475
+ useEffect(function () {
476
+ if (rest.disabled || (fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.disabled)) return;
477
+ try {
478
+ var el = inputRef.current.input.parentNode;
479
+ if (!el) return;
480
+ if (text) {
481
+ el.classList.add('ant-input-has-value');
482
+ } else {
483
+ el.classList.remove('ant-input-has-value');
484
+ }
485
+ } catch (e) {}
486
+ }, [text, rest, fieldProps]);
436
487
  var tableDom = /*#__PURE__*/React.createElement(ProTable, _extends({
437
488
  className: "ls-input-table",
438
489
  columns: columns,
@@ -549,31 +600,33 @@ var InputTable = /*#__PURE__*/React.forwardRef(function (prop, ref) {
549
600
  readOnly: readonly,
550
601
  allowClear: allowClear,
551
602
  ref: inputRef
552
- }, rest.label ? {} : {
553
- value: text
554
603
  }, fieldProps));
555
- // 处理有值时,可清空
556
- useEffect(function () {
557
- if (rest.disabled || (fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.disabled)) return;
558
- try {
559
- var el = inputRef.current.input.parentNode;
560
- if (!el) return;
561
- if (text) {
562
- el.classList.add('ant-input-has-value');
563
- } else {
564
- el.classList.remove('ant-input-has-value');
565
- }
566
- } catch (e) {}
567
- }, [text, rest, fieldProps]);
604
+ // 是否在编辑表格下面使用,如果是,则需要使用 rowKey 和 id 来设置 name
605
+ var isEditable = rowKey && id && id.includes('_');
568
606
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
569
607
  style: {
570
608
  display: 'none'
571
609
  }
572
610
  }, /*#__PURE__*/React.createElement(ProFormText, {
573
- name: name
574
- })), /*#__PURE__*/React.createElement(ProFormText, _extends({
611
+ name: isEditable ? [rowKey, name] : name
612
+ })), rest.label ?
613
+ /*#__PURE__*/
614
+ // 在ProForm中直接使用
615
+ React.createElement(ProFormText, _extends({
616
+ name: textNameProp
617
+ }, rest), InputDom) : isEditable ?
618
+ /*#__PURE__*/
619
+ // 在EditableTable中使用
620
+ React.createElement(_Form.Item, _extends({
621
+ name: [rowKey, textNameProp]
622
+ }, rest, {
623
+ noStyle: true
624
+ }), InputDom) :
625
+ /*#__PURE__*/
626
+ // 在 ProTable 的查询面板中使用
627
+ React.createElement(_Form.Item, _extends({
575
628
  name: textNameProp
576
- }, rest, rest.label ? {} : {
629
+ }, rest, {
577
630
  noStyle: true
578
631
  }), InputDom));
579
632
  });
@@ -0,0 +1,28 @@
1
+ /**
2
+ * 设置本地缓存
3
+ *
4
+ * @param {String} key 关键字
5
+ * @param {Object} data 值
6
+ * @param {Boolean} session 保存到 sessionStorage 还是 localStorage,默认 localStorage
7
+ */
8
+ export declare const setCache: (key: string, data: any, session?: boolean) => void;
9
+ /**
10
+ * 读取本地缓存
11
+ *
12
+ * @param {String} key 关键字
13
+ * @param {boolean} session 从 sessionStorage 取数还是从 localStorage 中取数 默认从 localStorage
14
+ * @returns 关键字对应的值
15
+ */
16
+ export declare const getCache: any;
17
+ /**
18
+ * 读取本地缓存,优先从sessionStorage 取,取不到时再从 localStorage取
19
+ *
20
+ * @param key
21
+ * @returns
22
+ */
23
+ export declare const getCacheSessionFirst: (key: string) => any;
24
+ /**
25
+ * @param key 关键字,不传清除所有
26
+ * @param session 是否session storage , 默认 localStorage
27
+ */
28
+ export declare const clearCache: (key?: string | undefined, session?: boolean) => void;
@@ -0,0 +1,63 @@
1
+ import _typeof from "@babel/runtime/helpers/esm/typeof";
2
+ /**
3
+ * 设置本地缓存
4
+ *
5
+ * @param {String} key 关键字
6
+ * @param {Object} data 值
7
+ * @param {Boolean} session 保存到 sessionStorage 还是 localStorage,默认 localStorage
8
+ */
9
+ export var setCache = function setCache(key, data) {
10
+ var session = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
11
+ if (_typeof(data) === 'object') {
12
+ data = JSON.stringify(data);
13
+ }
14
+ if (session) {
15
+ sessionStorage.setItem(key, data);
16
+ } else {
17
+ localStorage.setItem(key, data);
18
+ }
19
+ };
20
+ /**
21
+ * 读取本地缓存
22
+ *
23
+ * @param {String} key 关键字
24
+ * @param {boolean} session 从 sessionStorage 取数还是从 localStorage 中取数 默认从 localStorage
25
+ * @returns 关键字对应的值
26
+ */
27
+ export var getCache = function getCache(key) {
28
+ var session = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
29
+ var data = session ? sessionStorage.getItem(key) : localStorage.getItem(key);
30
+ if (data && (data.startsWith('{') || data.startsWith('['))) {
31
+ data = JSON.parse(data);
32
+ }
33
+ return data;
34
+ };
35
+ /**
36
+ * 读取本地缓存,优先从sessionStorage 取,取不到时再从 localStorage取
37
+ *
38
+ * @param key
39
+ * @returns
40
+ */
41
+ export var getCacheSessionFirst = function getCacheSessionFirst(key) {
42
+ return getCache(key, true) || getCache(key);
43
+ };
44
+ /**
45
+ * @param key 关键字,不传清除所有
46
+ * @param session 是否session storage , 默认 localStorage
47
+ */
48
+ export var clearCache = function clearCache(key) {
49
+ var session = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
50
+ if (key) {
51
+ if (session) {
52
+ sessionStorage.removeItem(key);
53
+ } else {
54
+ localStorage.removeItem(key);
55
+ }
56
+ } else {
57
+ if (session) {
58
+ sessionStorage.clear();
59
+ } else {
60
+ localStorage.clear();
61
+ }
62
+ }
63
+ };
@@ -0,0 +1,12 @@
1
+ /** @name 状态列表 */
2
+ export declare const statusList: {
3
+ value: number;
4
+ text: string;
5
+ label: string;
6
+ }[];
7
+ /** @name 是否列表 */
8
+ export declare const yesnoList: {
9
+ value: number;
10
+ text: string;
11
+ label: string;
12
+ }[];
@@ -0,0 +1,20 @@
1
+ /** @name 状态列表 */
2
+ export var statusList = [{
3
+ value: 1,
4
+ text: '启用',
5
+ label: '1→启用'
6
+ }, {
7
+ value: 0,
8
+ text: '禁用',
9
+ label: '0→禁用'
10
+ }];
11
+ /** @name 是否列表 */
12
+ export var yesnoList = [{
13
+ value: 1,
14
+ text: '是',
15
+ label: '1→是'
16
+ }, {
17
+ value: 0,
18
+ text: '否',
19
+ label: '0→否'
20
+ }];
@@ -0,0 +1,15 @@
1
+ /**
2
+ * 获取Cookie
3
+ *
4
+ * @param {String} name Cookie名
5
+ * @returns
6
+ */
7
+ export declare const getCookie: (name: string) => string | null;
8
+ /**
9
+ * 设置Cookie
10
+ *
11
+ * @param {any} key Cookie名称
12
+ * @param {any} value Cookie 值
13
+ * @param {Number} day 有效天数 默认1天,
14
+ */
15
+ export declare const setCookie: (key: string, value: string | number, day?: number, sameSite?: boolean) => void;
@@ -0,0 +1,36 @@
1
+ /**
2
+ * 获取Cookie
3
+ *
4
+ * @param {String} name Cookie名
5
+ * @returns
6
+ */
7
+ export var getCookie = function getCookie(name) {
8
+ var arr;
9
+ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)');
10
+ if (arr = document.cookie.match(reg)) return arr[2];else return null;
11
+ };
12
+ /**
13
+ * 设置Cookie
14
+ *
15
+ * @param {any} key Cookie名称
16
+ * @param {any} value Cookie 值
17
+ * @param {Number} day 有效天数 默认1天,
18
+ */
19
+ export var setCookie = function setCookie(key, value) {
20
+ var day = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
21
+ var sameSite = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
22
+ if (day !== 0) {
23
+ var d = new Date(Date.now() + day * 24 * 60 * 60 * 1000);
24
+ if (sameSite) {
25
+ document.cookie = "".concat(key, "=").concat(value, ";expires=").concat(d.toUTCString(), ";path=/;sameSite=None;secure=true");
26
+ } else {
27
+ document.cookie = "".concat(key, "=").concat(value, ";expires=").concat(d.toUTCString(), ";path=/");
28
+ }
29
+ } else {
30
+ if (sameSite) {
31
+ document.cookie = key + '=' + value + ';path=/;sameSite=None;secure=true';
32
+ } else {
33
+ document.cookie = key + '=' + value + ';path=/';
34
+ }
35
+ }
36
+ };
@@ -0,0 +1,16 @@
1
+ /**
2
+ * 绑定事件
3
+ *
4
+ * @param eventName 事件名
5
+ * @param fn 调用函数
6
+ * @param el 源对象,默认为window
7
+ */
8
+ export declare const on: (eventName: string, fn: Function, el: any | undefined) => void;
9
+ /**
10
+ * 解绑事件
11
+ *
12
+ * @param eventName 事件名
13
+ * @param fn 调用函数
14
+ * @param el 源对象,默认为window
15
+ */
16
+ export declare const off: (eventName: string, fn: Function, el: any | undefined) => void;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * 绑定事件
3
+ *
4
+ * @param eventName 事件名
5
+ * @param fn 调用函数
6
+ * @param el 源对象,默认为window
7
+ */
8
+ export var on = function on(eventName, fn, el) {
9
+ if (!el) {
10
+ el = window;
11
+ }
12
+ el.addEventListener(eventName, fn);
13
+ };
14
+ /**
15
+ * 解绑事件
16
+ *
17
+ * @param eventName 事件名
18
+ * @param fn 调用函数
19
+ * @param el 源对象,默认为window
20
+ */
21
+ export var off = function off(eventName, fn, el) {
22
+ if (!el) {
23
+ el = window;
24
+ }
25
+ el.removeEventListener(eventName, fn);
26
+ };