@bit-sun/business-component 1.0.17 → 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/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export { default as DataValidation } from './components/DataValidation';
2
2
  export { default as QueryMutipleInput } from './components/QueryMutipleInput';
3
+ export { default as CheckOneUser } from './utils/CheckOneUser';
package/dist/index.esm.js CHANGED
@@ -77,14 +77,14 @@ function _inherits(subClass, superClass) {
77
77
  throw new TypeError("Super expression must either be null or a function");
78
78
  }
79
79
 
80
- subClass.prototype = Object.create(superClass && superClass.prototype, {
81
- constructor: {
82
- value: subClass,
83
- writable: true,
84
- configurable: true
85
- }
86
- });
87
80
  Object.defineProperty(subClass, "prototype", {
81
+ value: Object.create(superClass && superClass.prototype, {
82
+ constructor: {
83
+ value: subClass,
84
+ writable: true,
85
+ configurable: true
86
+ }
87
+ }),
88
88
  writable: false
89
89
  });
90
90
  if (superClass) _setPrototypeOf(subClass, superClass);
@@ -196,6 +196,10 @@ function _slicedToArray(arr, i) {
196
196
  return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
197
197
  }
198
198
 
199
+ function _toArray(arr) {
200
+ return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest();
201
+ }
202
+
199
203
  function _toConsumableArray(arr) {
200
204
  return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
201
205
  }
@@ -2301,14 +2305,70 @@ function ToCDB(str) {
2301
2305
  return tmp;
2302
2306
  }
2303
2307
 
2308
+ /*
2309
+ * @Description:
2310
+ * @Author: rodchen
2311
+ * @Date: 2022-01-14 14:12:01
2312
+ * @LastEditTime: 2022-01-14 17:17:26
2313
+ * @LastEditors: rodchen
2314
+ */
2315
+ var index = (function (storageKeyString) {
2316
+ var seconds = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;
2317
+ var tipsCallFunction = arguments.length > 2 ? arguments[2] : undefined;
2318
+ if (typeof seconds !== 'number') throw new Error('seconds should be number');
2319
+ var cacheValue = getStorageVale(storageKeyString);
2320
+
2321
+ if (document.hidden !== undefined) {
2322
+ document.addEventListener('visibilitychange', function () {
2323
+ if (!document.hidden) {
2324
+ var currentValue = getStorageVale(storageKeyString);
2325
+
2326
+ if (currentValue !== cacheValue) {
2327
+ if (tipsCallFunction && typeof tipsCallFunction === 'function') {
2328
+ tipsCallFunction();
2329
+ } else {
2330
+ window.alert('检测新用户登录,当前页面会在2s之后刷新!');
2331
+ }
2332
+
2333
+ setTimeout(function () {
2334
+ window.location.reload();
2335
+ }, seconds * 1000);
2336
+ }
2337
+ }
2338
+ });
2339
+ }
2340
+ });
2341
+
2342
+ function getStorageVale(storageKeyString) {
2343
+ var _storageKeyString$spl = storageKeyString.split('.'),
2344
+ _storageKeyString$spl2 = _toArray(_storageKeyString$spl),
2345
+ localstorage = _storageKeyString$spl2[0],
2346
+ restKeyArrays = _storageKeyString$spl2.slice(1);
2347
+
2348
+ var localStorageInfo = window.localStorage.getItem(localstorage);
2349
+ if (!restKeyArrays.length) return localStorageInfo;
2350
+ var returnVal = JSON.parse(localStorageInfo || '{}');
2351
+
2352
+ for (var i = 0; i < restKeyArrays.length; i++) {
2353
+ returnVal = returnVal[restKeyArrays[i]];
2354
+ if (!returnVal) return '';
2355
+
2356
+ if (typeof returnVal === 'string') {
2357
+ return returnVal;
2358
+ }
2359
+ }
2360
+
2361
+ return "";
2362
+ }
2363
+
2304
2364
  /*
2305
2365
  * @Description:
2306
2366
  * @Author: rodchen
2307
2367
  * @Date: 2021-11-30 22:59:39
2308
- * @LastEditTime: 2021-12-29 17:43:01
2368
+ * @LastEditTime: 2022-01-14 16:10:27
2309
2369
  * @LastEditors: rodchen
2310
2370
  */
2311
2371
  var resposne = JSON.parse(localStorage.getItem('userInfo') || '{}');
2312
2372
  axios.defaults.headers.common['sso-sessionid'] = (resposne === null || resposne === void 0 ? void 0 : resposne.sessionId) || '';
2313
2373
 
2314
- export { DataValidation, QueryMutipleInput };
2374
+ export { index as CheckOneUser, DataValidation, QueryMutipleInput };
package/dist/index.js CHANGED
@@ -88,14 +88,14 @@ function _inherits(subClass, superClass) {
88
88
  throw new TypeError("Super expression must either be null or a function");
89
89
  }
90
90
 
91
- subClass.prototype = Object.create(superClass && superClass.prototype, {
92
- constructor: {
93
- value: subClass,
94
- writable: true,
95
- configurable: true
96
- }
97
- });
98
91
  Object.defineProperty(subClass, "prototype", {
92
+ value: Object.create(superClass && superClass.prototype, {
93
+ constructor: {
94
+ value: subClass,
95
+ writable: true,
96
+ configurable: true
97
+ }
98
+ }),
99
99
  writable: false
100
100
  });
101
101
  if (superClass) _setPrototypeOf(subClass, superClass);
@@ -207,6 +207,10 @@ function _slicedToArray(arr, i) {
207
207
  return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
208
208
  }
209
209
 
210
+ function _toArray(arr) {
211
+ return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest();
212
+ }
213
+
210
214
  function _toConsumableArray(arr) {
211
215
  return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
212
216
  }
@@ -2312,15 +2316,72 @@ function ToCDB(str) {
2312
2316
  return tmp;
2313
2317
  }
2314
2318
 
2319
+ /*
2320
+ * @Description:
2321
+ * @Author: rodchen
2322
+ * @Date: 2022-01-14 14:12:01
2323
+ * @LastEditTime: 2022-01-14 17:17:26
2324
+ * @LastEditors: rodchen
2325
+ */
2326
+ var index = (function (storageKeyString) {
2327
+ var seconds = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;
2328
+ var tipsCallFunction = arguments.length > 2 ? arguments[2] : undefined;
2329
+ if (typeof seconds !== 'number') throw new Error('seconds should be number');
2330
+ var cacheValue = getStorageVale(storageKeyString);
2331
+
2332
+ if (document.hidden !== undefined) {
2333
+ document.addEventListener('visibilitychange', function () {
2334
+ if (!document.hidden) {
2335
+ var currentValue = getStorageVale(storageKeyString);
2336
+
2337
+ if (currentValue !== cacheValue) {
2338
+ if (tipsCallFunction && typeof tipsCallFunction === 'function') {
2339
+ tipsCallFunction();
2340
+ } else {
2341
+ window.alert('检测新用户登录,当前页面会在2s之后刷新!');
2342
+ }
2343
+
2344
+ setTimeout(function () {
2345
+ window.location.reload();
2346
+ }, seconds * 1000);
2347
+ }
2348
+ }
2349
+ });
2350
+ }
2351
+ });
2352
+
2353
+ function getStorageVale(storageKeyString) {
2354
+ var _storageKeyString$spl = storageKeyString.split('.'),
2355
+ _storageKeyString$spl2 = _toArray(_storageKeyString$spl),
2356
+ localstorage = _storageKeyString$spl2[0],
2357
+ restKeyArrays = _storageKeyString$spl2.slice(1);
2358
+
2359
+ var localStorageInfo = window.localStorage.getItem(localstorage);
2360
+ if (!restKeyArrays.length) return localStorageInfo;
2361
+ var returnVal = JSON.parse(localStorageInfo || '{}');
2362
+
2363
+ for (var i = 0; i < restKeyArrays.length; i++) {
2364
+ returnVal = returnVal[restKeyArrays[i]];
2365
+ if (!returnVal) return '';
2366
+
2367
+ if (typeof returnVal === 'string') {
2368
+ return returnVal;
2369
+ }
2370
+ }
2371
+
2372
+ return "";
2373
+ }
2374
+
2315
2375
  /*
2316
2376
  * @Description:
2317
2377
  * @Author: rodchen
2318
2378
  * @Date: 2021-11-30 22:59:39
2319
- * @LastEditTime: 2021-12-29 17:43:01
2379
+ * @LastEditTime: 2022-01-14 16:10:27
2320
2380
  * @LastEditors: rodchen
2321
2381
  */
2322
2382
  var resposne = JSON.parse(localStorage.getItem('userInfo') || '{}');
2323
2383
  axios__default['default'].defaults.headers.common['sso-sessionid'] = (resposne === null || resposne === void 0 ? void 0 : resposne.sessionId) || '';
2324
2384
 
2385
+ exports.CheckOneUser = index;
2325
2386
  exports.DataValidation = DataValidation;
2326
2387
  exports.QueryMutipleInput = QueryMutipleInput;
@@ -0,0 +1,2 @@
1
+ declare const _default: (storageKeyString: string, seconds?: number, tipsCallFunction?: (() => {}) | undefined) => void;
2
+ export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bit-sun/business-component",
3
- "version": "1.0.17",
3
+ "version": "1.1.0",
4
4
  "scripts": {
5
5
  "start": "dumi dev",
6
6
  "docs:build": "dumi build",
package/src/index.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  * @Description:
3
3
  * @Author: rodchen
4
4
  * @Date: 2021-11-30 22:59:39
5
- * @LastEditTime: 2021-12-29 17:43:01
5
+ * @LastEditTime: 2022-01-14 16:10:27
6
6
  * @LastEditors: rodchen
7
7
  */
8
8
 
@@ -14,3 +14,5 @@ axios.defaults.headers.common['sso-sessionid'] = resposne?.sessionId || '';
14
14
 
15
15
  export { default as DataValidation } from './components/DataValidation';
16
16
  export { default as QueryMutipleInput } from './components/QueryMutipleInput';
17
+ export { default as CheckOneUser } from './utils/CheckOneUser';
18
+
@@ -0,0 +1,39 @@
1
+ ---
2
+ nav:
3
+ title: '工具方法'
4
+ order: 2
5
+ group:
6
+ title: 方法
7
+ order: 0
8
+ title: 确保单用户登录
9
+ order: 1
10
+ ---
11
+
12
+ ## CheckOneUser
13
+
14
+ Demo:
15
+
16
+ ```tsx
17
+ import React, { useRef } from 'react';
18
+ import { message } from 'antd';
19
+
20
+ import { CheckOneUser } from '../../index';
21
+
22
+ CheckOneUser('userInfo.a.information.name', 3, () => {
23
+ message.warning('检测新用户登录,当前页面会在3s之后刷新!');
24
+ })
25
+
26
+ export default () => {
27
+
28
+ const handleOnChange = (value) => {
29
+ console.log(value);
30
+ };
31
+
32
+ return (
33
+ <div>
34
+ </div>
35
+ );
36
+ };
37
+ ```
38
+
39
+ More skills for writing demo: https://d.umijs.org/guide/demo-principle
@@ -0,0 +1,52 @@
1
+ /*
2
+ * @Description:
3
+ * @Author: rodchen
4
+ * @Date: 2022-01-14 14:12:01
5
+ * @LastEditTime: 2022-01-14 17:17:26
6
+ * @LastEditors: rodchen
7
+ */
8
+ export default (storageKeyString: string, seconds: number = 2, tipsCallFunction?: () =>{}) => {
9
+ if (typeof seconds !== 'number' ) throw new Error('seconds should be number');
10
+
11
+ let cacheValue = getStorageVale(storageKeyString);
12
+
13
+ if (document.hidden !== undefined) {
14
+ document.addEventListener('visibilitychange', () => {
15
+ if (!document.hidden) {
16
+ let currentValue = getStorageVale(storageKeyString);
17
+ if (currentValue !== cacheValue) {
18
+ if (tipsCallFunction && typeof tipsCallFunction === 'function') {
19
+ tipsCallFunction();
20
+ } else {
21
+ window.alert('检测新用户登录,当前页面会在2s之后刷新!');
22
+ }
23
+
24
+ setTimeout(() => {
25
+ window.location.reload();
26
+ }, seconds * 1000)
27
+ }
28
+ }
29
+ })
30
+ }
31
+ }
32
+
33
+ function getStorageVale (storageKeyString: string) {
34
+ var [localstorage, ...restKeyArrays] = storageKeyString.split('.');
35
+ let localStorageInfo = window.localStorage.getItem(localstorage)
36
+
37
+ if (!restKeyArrays.length) return localStorageInfo;
38
+
39
+ let returnVal = JSON.parse(localStorageInfo || '{}');
40
+
41
+ for(let i = 0; i < restKeyArrays.length; i++ ) {
42
+ returnVal = returnVal[restKeyArrays[i]]
43
+
44
+ if (!returnVal) return '';
45
+
46
+ if (typeof returnVal === 'string') {
47
+ return returnVal
48
+ }
49
+ }
50
+
51
+ return ""
52
+ }