@bit-sun/business-component 1.0.14 → 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 +1 -0
- package/dist/index.esm.js +91 -11
- package/dist/index.js +92 -10
- package/dist/utils/CheckOneUser/index.d.ts +2 -0
- package/package.json +2 -1
- package/src/components/DataValidation/index.md +3 -1
- package/src/components/DataValidation/index.tsx +12 -2
- package/src/index.ts +3 -1
- package/src/utils/CheckOneUser/index.md +39 -0
- package/src/utils/CheckOneUser/index.ts +52 -0
package/dist/index.d.ts
CHANGED
package/dist/index.esm.js
CHANGED
|
@@ -3,6 +3,7 @@ import React, { createContext, useContext, useEffect, forwardRef, createElement,
|
|
|
3
3
|
import { message, Menu, Space, Dropdown, Tooltip, Button, Checkbox, Input, Modal } from 'antd';
|
|
4
4
|
import { DragDropContext, Droppable, Draggable } from 'react-beautiful-dnd';
|
|
5
5
|
import classNames from 'classnames';
|
|
6
|
+
import _ from 'loadsh';
|
|
6
7
|
import { useDebounceFn } from 'ahooks';
|
|
7
8
|
|
|
8
9
|
function ownKeys(object, enumerableOnly) {
|
|
@@ -76,14 +77,14 @@ function _inherits(subClass, superClass) {
|
|
|
76
77
|
throw new TypeError("Super expression must either be null or a function");
|
|
77
78
|
}
|
|
78
79
|
|
|
79
|
-
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
80
|
-
constructor: {
|
|
81
|
-
value: subClass,
|
|
82
|
-
writable: true,
|
|
83
|
-
configurable: true
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
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
|
+
}),
|
|
87
88
|
writable: false
|
|
88
89
|
});
|
|
89
90
|
if (superClass) _setPrototypeOf(subClass, superClass);
|
|
@@ -195,6 +196,10 @@ function _slicedToArray(arr, i) {
|
|
|
195
196
|
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
|
196
197
|
}
|
|
197
198
|
|
|
199
|
+
function _toArray(arr) {
|
|
200
|
+
return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest();
|
|
201
|
+
}
|
|
202
|
+
|
|
198
203
|
function _toConsumableArray(arr) {
|
|
199
204
|
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
|
200
205
|
}
|
|
@@ -1716,7 +1721,24 @@ var DataValidation = /*#__PURE__*/function (_React$Component) {
|
|
|
1716
1721
|
defaultRowHeight: 20,
|
|
1717
1722
|
defaultColWidth: 120,
|
|
1718
1723
|
config: {},
|
|
1719
|
-
celldata: data
|
|
1724
|
+
celldata: data && data.length !== 0 ? data : _.flattenDeep(Array.from({
|
|
1725
|
+
length: 100
|
|
1726
|
+
}).map(function (a, b) {
|
|
1727
|
+
return Array.from({
|
|
1728
|
+
length: 100
|
|
1729
|
+
}).map(function (c, d) {
|
|
1730
|
+
return {
|
|
1731
|
+
"r": b,
|
|
1732
|
+
"c": d,
|
|
1733
|
+
"v": {
|
|
1734
|
+
"ct": {
|
|
1735
|
+
"fa": "@",
|
|
1736
|
+
"t": "s"
|
|
1737
|
+
}
|
|
1738
|
+
}
|
|
1739
|
+
};
|
|
1740
|
+
});
|
|
1741
|
+
})),
|
|
1720
1742
|
scrollLeft: 0,
|
|
1721
1743
|
// "scrollTop": 315, //上下滚动条位置
|
|
1722
1744
|
luckysheet_select_save: [],
|
|
@@ -1876,7 +1898,9 @@ var DataValidation = /*#__PURE__*/function (_React$Component) {
|
|
|
1876
1898
|
updateData = _this$props.updateData,
|
|
1877
1899
|
columns = _this$props.columns;
|
|
1878
1900
|
|
|
1879
|
-
var resultData = _this.getData()
|
|
1901
|
+
var resultData = _this.getData().filter(function (d) {
|
|
1902
|
+
return _.compact(Object.values(d)).length;
|
|
1903
|
+
});
|
|
1880
1904
|
|
|
1881
1905
|
axios.post(validDataUrl, {
|
|
1882
1906
|
columns: columns,
|
|
@@ -2281,14 +2305,70 @@ function ToCDB(str) {
|
|
|
2281
2305
|
return tmp;
|
|
2282
2306
|
}
|
|
2283
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
|
+
|
|
2284
2364
|
/*
|
|
2285
2365
|
* @Description:
|
|
2286
2366
|
* @Author: rodchen
|
|
2287
2367
|
* @Date: 2021-11-30 22:59:39
|
|
2288
|
-
* @LastEditTime:
|
|
2368
|
+
* @LastEditTime: 2022-01-14 16:10:27
|
|
2289
2369
|
* @LastEditors: rodchen
|
|
2290
2370
|
*/
|
|
2291
2371
|
var resposne = JSON.parse(localStorage.getItem('userInfo') || '{}');
|
|
2292
2372
|
axios.defaults.headers.common['sso-sessionid'] = (resposne === null || resposne === void 0 ? void 0 : resposne.sessionId) || '';
|
|
2293
2373
|
|
|
2294
|
-
export { DataValidation, QueryMutipleInput };
|
|
2374
|
+
export { index as CheckOneUser, DataValidation, QueryMutipleInput };
|
package/dist/index.js
CHANGED
|
@@ -7,6 +7,7 @@ var React = require('react');
|
|
|
7
7
|
var antd = require('antd');
|
|
8
8
|
var reactBeautifulDnd = require('react-beautiful-dnd');
|
|
9
9
|
var classNames = require('classnames');
|
|
10
|
+
var _ = require('loadsh');
|
|
10
11
|
var ahooks = require('ahooks');
|
|
11
12
|
|
|
12
13
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
@@ -14,6 +15,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
14
15
|
var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
|
|
15
16
|
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
16
17
|
var classNames__default = /*#__PURE__*/_interopDefaultLegacy(classNames);
|
|
18
|
+
var ___default = /*#__PURE__*/_interopDefaultLegacy(_);
|
|
17
19
|
|
|
18
20
|
function ownKeys(object, enumerableOnly) {
|
|
19
21
|
var keys = Object.keys(object);
|
|
@@ -86,14 +88,14 @@ function _inherits(subClass, superClass) {
|
|
|
86
88
|
throw new TypeError("Super expression must either be null or a function");
|
|
87
89
|
}
|
|
88
90
|
|
|
89
|
-
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
90
|
-
constructor: {
|
|
91
|
-
value: subClass,
|
|
92
|
-
writable: true,
|
|
93
|
-
configurable: true
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
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
|
+
}),
|
|
97
99
|
writable: false
|
|
98
100
|
});
|
|
99
101
|
if (superClass) _setPrototypeOf(subClass, superClass);
|
|
@@ -205,6 +207,10 @@ function _slicedToArray(arr, i) {
|
|
|
205
207
|
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
|
206
208
|
}
|
|
207
209
|
|
|
210
|
+
function _toArray(arr) {
|
|
211
|
+
return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest();
|
|
212
|
+
}
|
|
213
|
+
|
|
208
214
|
function _toConsumableArray(arr) {
|
|
209
215
|
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
|
210
216
|
}
|
|
@@ -1726,7 +1732,24 @@ var DataValidation = /*#__PURE__*/function (_React$Component) {
|
|
|
1726
1732
|
defaultRowHeight: 20,
|
|
1727
1733
|
defaultColWidth: 120,
|
|
1728
1734
|
config: {},
|
|
1729
|
-
celldata: data
|
|
1735
|
+
celldata: data && data.length !== 0 ? data : ___default['default'].flattenDeep(Array.from({
|
|
1736
|
+
length: 100
|
|
1737
|
+
}).map(function (a, b) {
|
|
1738
|
+
return Array.from({
|
|
1739
|
+
length: 100
|
|
1740
|
+
}).map(function (c, d) {
|
|
1741
|
+
return {
|
|
1742
|
+
"r": b,
|
|
1743
|
+
"c": d,
|
|
1744
|
+
"v": {
|
|
1745
|
+
"ct": {
|
|
1746
|
+
"fa": "@",
|
|
1747
|
+
"t": "s"
|
|
1748
|
+
}
|
|
1749
|
+
}
|
|
1750
|
+
};
|
|
1751
|
+
});
|
|
1752
|
+
})),
|
|
1730
1753
|
scrollLeft: 0,
|
|
1731
1754
|
// "scrollTop": 315, //上下滚动条位置
|
|
1732
1755
|
luckysheet_select_save: [],
|
|
@@ -1886,7 +1909,9 @@ var DataValidation = /*#__PURE__*/function (_React$Component) {
|
|
|
1886
1909
|
updateData = _this$props.updateData,
|
|
1887
1910
|
columns = _this$props.columns;
|
|
1888
1911
|
|
|
1889
|
-
var resultData = _this.getData()
|
|
1912
|
+
var resultData = _this.getData().filter(function (d) {
|
|
1913
|
+
return ___default['default'].compact(Object.values(d)).length;
|
|
1914
|
+
});
|
|
1890
1915
|
|
|
1891
1916
|
axios__default['default'].post(validDataUrl, {
|
|
1892
1917
|
columns: columns,
|
|
@@ -2291,15 +2316,72 @@ function ToCDB(str) {
|
|
|
2291
2316
|
return tmp;
|
|
2292
2317
|
}
|
|
2293
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
|
+
|
|
2294
2375
|
/*
|
|
2295
2376
|
* @Description:
|
|
2296
2377
|
* @Author: rodchen
|
|
2297
2378
|
* @Date: 2021-11-30 22:59:39
|
|
2298
|
-
* @LastEditTime:
|
|
2379
|
+
* @LastEditTime: 2022-01-14 16:10:27
|
|
2299
2380
|
* @LastEditors: rodchen
|
|
2300
2381
|
*/
|
|
2301
2382
|
var resposne = JSON.parse(localStorage.getItem('userInfo') || '{}');
|
|
2302
2383
|
axios__default['default'].defaults.headers.common['sso-sessionid'] = (resposne === null || resposne === void 0 ? void 0 : resposne.sessionId) || '';
|
|
2303
2384
|
|
|
2385
|
+
exports.CheckOneUser = index;
|
|
2304
2386
|
exports.DataValidation = DataValidation;
|
|
2305
2387
|
exports.QueryMutipleInput = QueryMutipleInput;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bit-sun/business-component",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"start": "dumi dev",
|
|
6
6
|
"docs:build": "dumi build",
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"antd": "4.17.2",
|
|
32
32
|
"axios": "^0.24.0",
|
|
33
33
|
"classnames": "^2.3.1",
|
|
34
|
+
"loadsh": "^0.0.4",
|
|
34
35
|
"react": "^16.12.0",
|
|
35
36
|
"react-beautiful-dnd": "10.0.0"
|
|
36
37
|
},
|
|
@@ -23,7 +23,9 @@ export default () => {
|
|
|
23
23
|
return (
|
|
24
24
|
<div>
|
|
25
25
|
<DataValidation
|
|
26
|
-
columns={['skuCode', 'quantity', 'price']}
|
|
26
|
+
// columns={['skuCode', 'quantity', 'price']}
|
|
27
|
+
columns={["skuCode", "quantity", "price"]} // 需要哪些列展示,以及展示的顺序
|
|
28
|
+
validDataUrl="http://test.i-baby.net/wms-ops/recordDetailImport/check" // 校验的接口url
|
|
27
29
|
onRef={(ref) => {
|
|
28
30
|
dataValidationRef = ref;
|
|
29
31
|
}}
|
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
} from '@ant-design/icons';
|
|
28
28
|
import axios from 'axios';
|
|
29
29
|
import './index.less';
|
|
30
|
+
import _ from "loadsh"
|
|
30
31
|
|
|
31
32
|
const luckysheet = window.luckysheet;
|
|
32
33
|
|
|
@@ -209,7 +210,13 @@ class DataValidation extends React.Component {
|
|
|
209
210
|
defaultRowHeight: 20, //自定义行高
|
|
210
211
|
defaultColWidth: 120, //自定义列宽
|
|
211
212
|
config: {},
|
|
212
|
-
celldata:
|
|
213
|
+
celldata:
|
|
214
|
+
data && data.length !== 0 ? data : _.flattenDeep(Array.from({ length: 100 }).map((a, b) => Array.from({ length: 100 }).map((c, d) => ({
|
|
215
|
+
"r": b,
|
|
216
|
+
"c": d,
|
|
217
|
+
"v": { "ct": { "fa": "@", "t": "s" }, }
|
|
218
|
+
}))))
|
|
219
|
+
,
|
|
213
220
|
scrollLeft: 0, //左右滚动条位置
|
|
214
221
|
// "scrollTop": 315, //上下滚动条位置
|
|
215
222
|
luckysheet_select_save: [], //选中的区域
|
|
@@ -336,6 +343,7 @@ class DataValidation extends React.Component {
|
|
|
336
343
|
|
|
337
344
|
getValidateData = () => {
|
|
338
345
|
const { resultData } = this.state;
|
|
346
|
+
|
|
339
347
|
return {
|
|
340
348
|
successData: resultData
|
|
341
349
|
.filter((item) => item.flag)
|
|
@@ -366,7 +374,9 @@ class DataValidation extends React.Component {
|
|
|
366
374
|
|
|
367
375
|
resetData = () => {
|
|
368
376
|
const { validDataUrl, updateData, columns } = this.props;
|
|
369
|
-
const resultData = this.getData()
|
|
377
|
+
const resultData = this.getData().filter(d => {
|
|
378
|
+
return _.compact(Object.values(d)).length
|
|
379
|
+
})
|
|
370
380
|
|
|
371
381
|
axios
|
|
372
382
|
.post(validDataUrl, {
|
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:
|
|
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
|
+
}
|