@lambo-design/shared 1.0.0-beta.27 → 1.0.0-beta.271

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 (211) hide show
  1. package/config/config.js +17 -2
  2. package/config/index.js +7 -2
  3. package/config/themes/atrovirens/atrovirens.css +578 -0
  4. package/config/themes/atrovirens/atrovirens.css.map +1 -0
  5. package/config/themes/atrovirens/atrovirens.less +673 -0
  6. package/config/themes/atrovirens/var.less +680 -0
  7. package/config/themes/blue/blue.css +578 -0
  8. package/config/themes/blue/blue.css.map +1 -0
  9. package/config/themes/blue/blue.less +675 -0
  10. package/config/themes/blue/var.less +683 -0
  11. package/config/themes/blue-white/blue-white.css +582 -0
  12. package/config/themes/blue-white/blue-white.css.map +1 -0
  13. package/config/themes/blue-white/blue-white.less +675 -0
  14. package/config/themes/blue-white/var.less +681 -0
  15. package/config/themes/blue-white-tight/blue-white-tight.css +579 -0
  16. package/config/themes/blue-white-tight/blue-white-tight.css.map +1 -0
  17. package/config/themes/blue-white-tight/blue-white-tight.less +676 -0
  18. package/config/themes/blue-white-tight/var.less +683 -0
  19. package/config/themes/cuiwei/cuiwei.css +578 -0
  20. package/config/themes/cuiwei/cuiwei.css.map +10 -0
  21. package/config/themes/cuiwei/cuiwei.less +673 -0
  22. package/config/themes/cuiwei/var.less +683 -0
  23. package/config/themes/danqing/danqing.css +578 -0
  24. package/config/themes/danqing/danqing.css.map +1 -0
  25. package/config/themes/danqing/danqing.less +673 -0
  26. package/config/themes/danqing/danqing.wxss +576 -0
  27. package/config/themes/danqing/var.less +684 -0
  28. package/config/themes/deep/deep.css +578 -0
  29. package/config/themes/deep/deep.css.map +1 -0
  30. package/config/themes/deep/deep.less +673 -0
  31. package/config/themes/deep/var.less +683 -0
  32. package/config/themes/default/default.css +393 -58
  33. package/config/themes/default/default.css.map +1 -1
  34. package/config/themes/default/default.less +371 -16
  35. package/config/themes/default/var.less +380 -11
  36. package/config/themes/eap/eap.css +578 -0
  37. package/config/themes/eap/eap.css.map +1 -0
  38. package/config/themes/eap/eap.less +676 -0
  39. package/config/themes/eap/var.less +683 -0
  40. package/config/themes/gold/gold.css +578 -0
  41. package/config/themes/gold/gold.css.map +1 -0
  42. package/config/themes/gold/gold.less +676 -0
  43. package/config/themes/gold/var.less +374 -5
  44. package/config/themes/index.js +20 -3
  45. package/config/themes/lime/lime.css +578 -0
  46. package/config/themes/lime/lime.css.map +1 -0
  47. package/config/themes/lime/lime.less +676 -0
  48. package/config/themes/lime/var.less +374 -5
  49. package/config/themes/orange/orange.css +343 -8
  50. package/config/themes/orange/orange.css.map +1 -1
  51. package/config/themes/orange/orange.less +356 -0
  52. package/config/themes/orange/var.less +375 -5
  53. package/config/themes/red/red.css +343 -8
  54. package/config/themes/red/red.css.map +1 -1
  55. package/config/themes/red/red.less +356 -0
  56. package/config/themes/red/var.less +374 -5
  57. package/config/themes/theme-atrovirens.js +563 -0
  58. package/config/themes/theme-blue.js +563 -0
  59. package/config/themes/theme-bw.js +567 -0
  60. package/config/themes/theme-bwt.js +564 -0
  61. package/config/themes/theme-cuiwei.js +564 -0
  62. package/config/themes/theme-danqing.js +567 -0
  63. package/config/themes/theme-deep.js +563 -0
  64. package/config/themes/theme-default.js +369 -59
  65. package/config/themes/theme-eap.js +563 -0
  66. package/config/themes/theme-gold.js +317 -7
  67. package/config/themes/theme-lime.js +317 -7
  68. package/config/themes/theme-orange.js +551 -28
  69. package/config/themes/theme-red.js +555 -33
  70. package/config/themes/theme-white.js +563 -0
  71. package/config/themes/white/var.less +683 -0
  72. package/config/themes/white/white.css +578 -0
  73. package/config/themes/white/white.css.map +1 -0
  74. package/config/themes/white/white.less +675 -0
  75. package/directives/module/print.js +1 -0
  76. package/directives/module/vue-print-nb/README.md +63 -0
  77. package/directives/module/vue-print-nb/print.js +94 -0
  78. package/directives/module/vue-print-nb/printarea.js +532 -0
  79. package/index.js +7 -1
  80. package/nstyles/common.less +197 -0
  81. package/nstyles/components/404.less +46 -0
  82. package/nstyles/components/button.less +34 -0
  83. package/nstyles/components/date-picker.less +37 -0
  84. package/nstyles/components/drawer.less +20 -0
  85. package/nstyles/components/dropdown.less +18 -0
  86. package/nstyles/components/excel-flow.less +72 -0
  87. package/nstyles/components/form.less +313 -0
  88. package/nstyles/components/index.less +23 -0
  89. package/nstyles/components/layout/collect.less +10 -0
  90. package/nstyles/components/layout/detail-view.less +107 -0
  91. package/nstyles/components/layout/full-screen.less +7 -0
  92. package/nstyles/components/layout/index.less +7 -0
  93. package/nstyles/components/layout/other-menu.less +142 -0
  94. package/nstyles/components/layout/page-view.less +101 -0
  95. package/nstyles/components/layout/sider-trigger.less +41 -0
  96. package/nstyles/components/layout/tags-nav.less +113 -0
  97. package/nstyles/components/modal.less +90 -0
  98. package/nstyles/components/n-button.less +131 -0
  99. package/nstyles/components/n-image-preview.less +131 -0
  100. package/nstyles/components/n-model/index.less +19 -0
  101. package/nstyles/components/n-model/report-index.less +43 -0
  102. package/nstyles/components/n-panel.less +41 -0
  103. package/nstyles/components/n-picker.less +37 -0
  104. package/nstyles/components/n-sign.less +17 -0
  105. package/nstyles/components/n-tooltip.less +10 -0
  106. package/nstyles/components/panel.less +31 -0
  107. package/nstyles/components/select.less +3 -0
  108. package/nstyles/components/sign.less +27 -0
  109. package/nstyles/components/table.less +315 -0
  110. package/nstyles/components/tree.less +159 -0
  111. package/nstyles/components/upload.less +164 -0
  112. package/nstyles/index.less +5 -0
  113. package/nstyles/reset.less +73 -0
  114. package/nstyles/third/ag.less +174 -0
  115. package/nstyles/third/icons/sort-desc.svg +1 -0
  116. package/nstyles/third/icons/sort-up.svg +1 -0
  117. package/nstyles/third/icons/sorting.svg +1 -0
  118. package/nstyles/third/index.less +11 -0
  119. package/nstyles/third/view-design.less +375 -0
  120. package/nstyles/variables/base.less +143 -0
  121. package/nstyles/variables/index.less +4 -0
  122. package/nstyles/variables/theme/default/button.less +7 -0
  123. package/nstyles/variables/theme/default/common.less +57 -0
  124. package/nstyles/variables/theme/default/index.less +7 -0
  125. package/nstyles/variables/theme/default/layout.less +40 -0
  126. package/nstyles/variables/theme/default/table.less +37 -0
  127. package/nstyles/variables/theme/default/tag.less +3 -0
  128. package/nstyles/variables/theme/default/upload.less +3 -0
  129. package/nstyles/variables/theme/index.less +13 -0
  130. package/nstyles/variables/theme/lsv/button.less +7 -0
  131. package/nstyles/variables/theme/lsv/common.less +39 -0
  132. package/nstyles/variables/theme/lsv/index.less +5 -0
  133. package/nstyles/variables/theme/lsv/layout.less +21 -0
  134. package/nstyles/variables/theme/lsv/table.less +20 -0
  135. package/nstyles/variables/theme/lsv/tag.less +3 -0
  136. package/nstyles/variables/theme/small/button.less +7 -0
  137. package/nstyles/variables/theme/small/common.less +39 -0
  138. package/nstyles/variables/theme/small/index.less +5 -0
  139. package/nstyles/variables/theme/small/layout.less +21 -0
  140. package/nstyles/variables/theme/small/table.less +17 -0
  141. package/nstyles/variables/theme/small/tag.less +3 -0
  142. package/package.json +28 -7
  143. package/plugin/index.js +12 -0
  144. package/plugin/module/date-format.js +30 -0
  145. package/plugin/module/loading.js +26 -0
  146. package/plugin/module/warn-handler.js +11 -0
  147. package/styles/image/inspur.png +0 -0
  148. package/styles/image/lan_navigator.png +0 -0
  149. package/styles/image/layout-header-bg-cuiwei.png +0 -0
  150. package/styles/image/lv_navigator.png +0 -0
  151. package/utils/ajax/content-type.js +30 -0
  152. package/utils/ajax/headers.js +11 -0
  153. package/utils/ajax/interceptors.js +12 -4
  154. package/utils/ajax/sseFetchUtil.js +118 -0
  155. package/utils/assist.js +155 -27
  156. package/utils/base64.js +126 -0
  157. package/utils/blob.js +47 -0
  158. package/utils/crypto/aes.js +23 -0
  159. package/utils/crypto/index.js +10 -0
  160. package/utils/crypto/rsa.js +23 -0
  161. package/utils/date.js +334 -305
  162. package/utils/dict/built-in-dict.js +20 -0
  163. package/utils/dict/index.js +191 -0
  164. package/utils/event.js +72 -0
  165. package/utils/excel.js +373 -241
  166. package/utils/file.js +19 -0
  167. package/utils/form/validate.js +29 -0
  168. package/utils/half-year.js +68 -0
  169. package/utils/index.js +37 -0
  170. package/utils/json.js +29 -0
  171. package/utils/lodop.js +5 -0
  172. package/utils/menu/index.js +292 -15
  173. package/utils/mime_type.js +67 -0
  174. package/utils/modelerUtil.js +4 -1
  175. package/utils/n/api.js +22 -0
  176. package/utils/n/date.js +57 -0
  177. package/utils/n/index.js +10 -0
  178. package/utils/n/is-type.js +176 -0
  179. package/utils/n/number.js +144 -0
  180. package/utils/n/permission-cache.js +11 -0
  181. package/utils/n/reuqest/axiosN.js +17 -0
  182. package/utils/n/reuqest/content-type.js +19 -0
  183. package/utils/n/reuqest/interceptors.js +95 -0
  184. package/utils/n/reuqest/url-params.js +12 -0
  185. package/utils/n/storage.js +51 -0
  186. package/utils/n/token.js +51 -0
  187. package/utils/n/user-cache.js +11 -0
  188. package/utils/n/user.js +34 -0
  189. package/utils/n/uuid.js +16 -0
  190. package/utils/n-generator-routers.js +208 -0
  191. package/utils/n-router.js +205 -0
  192. package/utils/n-theme.js +30 -0
  193. package/utils/number.js +72 -15
  194. package/utils/oss.js +57 -0
  195. package/utils/platform.js +807 -30
  196. package/utils/quarter.js +58 -0
  197. package/utils/storage.js +198 -0
  198. package/utils/style.js +24 -0
  199. package/utils/theme.js +98 -3
  200. package/utils/transfer-queue.js +7 -0
  201. package/utils/transform.js +205 -0
  202. package/utils/type.js +102 -0
  203. package/utils/util.js +795 -0
  204. package/utils/vForm.js +349 -0
  205. package/utils/validator.js +181 -0
  206. package/config/themes/gold/default.css +0 -243
  207. package/config/themes/gold/default.css.map +0 -1
  208. package/config/themes/gold/default.less +0 -320
  209. package/config/themes/lime/default.css +0 -243
  210. package/config/themes/lime/default.css.map +0 -1
  211. package/config/themes/lime/default.less +0 -320
@@ -0,0 +1,57 @@
1
+ import dayjs from 'dayjs'
2
+
3
+ export function str2Date(value) {
4
+ if (value) {
5
+ return dayjs(value, ['YYYYMMDDHHmmss', 'YYYYMMDDHHmm', 'YYYYMMDD', 'YYYYMM', 'YYYY']).toDate()
6
+ } else {
7
+ return null
8
+ }
9
+ }
10
+
11
+ export function formatDate(value) {
12
+ if (value && /^[0-9]+$/.test(value)) {
13
+ switch (value.length) {
14
+ case 14: {
15
+ return dayjs(value, ['YYYYMMDDHHmmss']).format('YYYY-MM-DD HH:mm:ss')
16
+ }
17
+ case 12: {
18
+ return dayjs(value, ['YYYYMMDDHHmmss']).format('YYYY-MM-DD HH:mm')
19
+ }
20
+ case 8: {
21
+ return dayjs(value, ['YYYYMMDD']).format('YYYY-MM-DD')
22
+ }
23
+ case 6: {
24
+ return dayjs(value, ['YYYYMM']).format('YYYY-MM')
25
+ }
26
+ case 4: {
27
+ return value.substring(0, 2) + '-' + value.substring(2, 2)
28
+ }
29
+ }
30
+ } else {
31
+ return value || '-'
32
+ }
33
+ }
34
+
35
+ export function formatDateChinese(value) {
36
+ if (value && /^[0-9]+$/.test(value)) {
37
+ switch (value.length) {
38
+ case 14: {
39
+ return dayjs(value, ['YYYYMMDDHHmmss']).format('YYYY年MM月DD日 HH:mm:ss')
40
+ }
41
+ case 12: {
42
+ return dayjs(value, ['YYYYMMDDHHmmss']).format('YYYY年MM月DD日 HH:mm')
43
+ }
44
+ case 8: {
45
+ return dayjs(value, ['YYYYMMDD']).format('YYYY年MM月DD日')
46
+ }
47
+ case 6: {
48
+ return dayjs(value, ['YYYYMM']).format('YYYY年MM月')
49
+ }
50
+ case 4: {
51
+ return value.substring(0, 2) + '年' + value.substring(2, 2) + '月'
52
+ }
53
+ }
54
+ } else {
55
+ return value || '-'
56
+ }
57
+ }
@@ -0,0 +1,10 @@
1
+ export * from './date'
2
+ export * from './is-type'
3
+ export * from './number'
4
+ export * from './permission-cache'
5
+ export * from './storage'
6
+ export * from './token'
7
+ export * from './user-cache'
8
+ export * from './user'
9
+ export * from './uuid'
10
+ export * from './reuqest/axiosN'
@@ -0,0 +1,176 @@
1
+ const toString = {}.toString;
2
+ const hasOwnProperty = Object.prototype.hasOwnProperty;
3
+ const PRECISION = 0.00001; // numbers less than this is considered as 0
4
+ const objectProto = Object.prototype;
5
+
6
+ export function isNull(value) {
7
+ return value === null;
8
+ }
9
+
10
+ export function isUndefined(value) {
11
+ return value === undefined;
12
+ }
13
+
14
+ export function isNil(value) {
15
+ return isNull(value) || isUndefined(value);
16
+ }
17
+
18
+ export function getType(value) {
19
+ return toString
20
+ .call(value)
21
+ .replace(/^\[object /, '')
22
+ .replace(/]$/, '');
23
+ }
24
+
25
+ export function isType(value, type) {
26
+ return toString.call(value) === `[object ${type}]`;
27
+ }
28
+
29
+ export function isPrototype(value) {
30
+ const Ctor = value && value.constructor;
31
+ const proto = (typeof Ctor === 'function' && Ctor.prototype) || objectProto;
32
+ return value === proto;
33
+ }
34
+
35
+ export function isBoolean(value) {
36
+ return isType(value, 'Boolean');
37
+ }
38
+
39
+ export function isNumber(value) {
40
+ return isType(value, 'Number');
41
+ }
42
+
43
+ export function isString(str) {
44
+ return isType(str, 'String');
45
+ }
46
+
47
+ export function isArray(value) {
48
+ return Array.isArray ? Array.isArray(value) : isType(value, 'Array');
49
+ }
50
+
51
+ export function isArrayLike(value) {
52
+ return value !== null && typeof value !== 'function' && Number.isFinite(value.length);
53
+ }
54
+
55
+ export function isObject(value) {
56
+ const type = typeof value;
57
+ return (value !== null && type === 'object') || type === 'function';
58
+ }
59
+
60
+ export function isObjectLike(value) {
61
+ return typeof value === 'object' && value !== null;
62
+ }
63
+
64
+ export function isPlainObject(value) {
65
+ if (!isObjectLike(value) || !isType(value, 'Object')) return false;
66
+ if (Object.getPrototypeOf(value) === null) return true;
67
+ let proto = value;
68
+ while (Object.getPrototypeOf(proto) !== null) {
69
+ proto = Object.getPrototypeOf(proto);
70
+ }
71
+ return Object.getPrototypeOf(value) === proto;
72
+ }
73
+
74
+ export function isFunction(value) {
75
+ return isType(value, 'Function');
76
+ }
77
+
78
+ export function isPromise(value) {
79
+ return value && typeof value.then === 'function';
80
+ }
81
+
82
+ export function isDate(value) {
83
+ return isType(value, 'Date');
84
+ }
85
+
86
+ export function isArguments(value) {
87
+ return isType(value, 'Arguments');
88
+ }
89
+
90
+ export function isRegExp(str) {
91
+ return isType(str, 'RegExp');
92
+ }
93
+
94
+ export function isError(value) {
95
+ return isType(value, 'Error');
96
+ }
97
+
98
+ export function isElement(o) {
99
+ return o instanceof Element || o instanceof HTMLDocument;
100
+ }
101
+
102
+ export function isEmpty(value) {
103
+ if (isNil(value)) return true;
104
+ if (isArrayLike(value)) return !value.length;
105
+ const type = getType(value);
106
+ if (['Map', 'Set'].includes(type)) return !value.size;
107
+ if (isPrototype(value)) return !Object.keys(value).length;
108
+ for (const key in value) {
109
+ if (hasOwnProperty.call(value, key)) return false;
110
+ }
111
+ return true;
112
+ }
113
+
114
+ export function isEqual(value, other) {
115
+ if (value === other) return true;
116
+ if (!value || !other) return false;
117
+ if (isString(value) || isString(other)) return false;
118
+ if (isArrayLike(value) || isArrayLike(other)) {
119
+ if (value.length !== other.length) return false;
120
+ let rst = true;
121
+ for (let i = 0; i < value.length; i++) {
122
+ rst = isEqual(value[i], other[i]);
123
+ if (!rst) break;
124
+ }
125
+ return rst;
126
+ }
127
+ if (isObjectLike(value) || isObjectLike(other)) {
128
+ const valueKeys = Object.keys(value);
129
+ const otherKeys = Object.keys(other);
130
+ if (valueKeys.length !== otherKeys.length) return false;
131
+ let rst = true;
132
+ for (let i = 0; i < valueKeys.length; i++) {
133
+ rst = isEqual(value[valueKeys[i]], other[valueKeys[i]]);
134
+ if (!rst) break;
135
+ }
136
+ return rst;
137
+ }
138
+ return false;
139
+ }
140
+
141
+ export function isEven(num) {
142
+ return isNumber(num) && num % 2 === 0;
143
+ }
144
+
145
+ export function isOdd(num) {
146
+ return isNumber(num) && num % 2 !== 0;
147
+ }
148
+
149
+ export function isFinite(value) {
150
+ return isNumber(value) && Number.isFinite(value);
151
+ }
152
+
153
+ export function isInteger(num) {
154
+ return Number.isInteger ? Number.isInteger(num) : isNumber(num) && num % 1 === 0;
155
+ }
156
+
157
+ export function isDecimal(num) {
158
+ return isNumber(num) && num % 1 !== 0;
159
+ }
160
+
161
+ export function isNegative(num) {
162
+ return isNumber(num) && num < 0;
163
+ }
164
+
165
+ export function isPositive(num) {
166
+ return isNumber(num) && num > 0;
167
+ }
168
+
169
+ export function isNumberEqual(a, b, precision = PRECISION) {
170
+ return Math.abs(a - b) < precision;
171
+ }
172
+
173
+ export function isEqualWith(value, other, fn) {
174
+ if (!isFunction(fn)) return isEqual(value, other);
175
+ return fn(value, other);
176
+ }
@@ -0,0 +1,144 @@
1
+ import _ from 'lodash'
2
+
3
+ // 数字每三位加逗号
4
+ export function toThousands(numStr) {
5
+ let result = ''
6
+ numStr = (numStr || 0).toString()
7
+ while (numStr.length > 3) {
8
+ result = ',' + numStr.slice(-3) + result
9
+ numStr = numStr.slice(0, numStr.length - 3)
10
+ }
11
+ if (numStr) {
12
+ result = numStr + result
13
+ }
14
+ return result
15
+ }
16
+
17
+ /**
18
+ * 数字金额转为汉字
19
+ */
20
+ export function toChies(numStr) {
21
+ const len = numStr.length //统计出长度
22
+ const chin_list = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'] //所有的数值对应的汉字
23
+ const chin_lisp = ['仟', '佰', '拾', '亿', '仟', '佰', '拾', '万', '仟', '佰', '拾'] //进制
24
+
25
+ let numbers = []
26
+ let hanStr = []
27
+ let result = ''
28
+
29
+ for (let i = 0; i < len; i++) {
30
+ numbers.push(parseInt(numStr[i])) //输入的数据按下标存进去 存进去的只是数字
31
+ hanStr[i] = chin_list[numbers[i]] //是根据我们输入的输入的数字,对应着我们的chin_list这个数组
32
+ } //123['壹','佰','贰','拾','叁']
33
+
34
+ for (let i = len - 1, j = 1; i > 0; i--) {
35
+ //i =2 1 //倒序 为了添加进制,方便我们去观看
36
+ hanStr.splice(i, 0, chin_lisp[chin_lisp.length - j++]) //j=2
37
+ }
38
+
39
+ result = hanStr.join('')
40
+ if (len >= 1) {
41
+ result += '元整'
42
+ }
43
+ return result
44
+ }
45
+
46
+ export function numToDX(numStr) {
47
+ if (!/^(0|[1-9]\d*)(\.\d+)?$/.test(numStr)) return '数据非法'
48
+ let unit = '千百拾亿千百拾万千百拾元角分',
49
+ str = ''
50
+ numStr += '00'
51
+ let p = numStr.indexOf('.')
52
+ if (p >= 0) numStr = numStr.substring(0, p) + numStr.substr(p + 1, 2)
53
+ unit = unit.substr(unit.length - numStr.length)
54
+ for (let i = 0; i < numStr.length; i++)
55
+ str += '零壹贰叁肆伍陆柒捌玖'.charAt(parseInt(numStr.charAt(i))) + unit.charAt(i)
56
+ return str
57
+ .replace(/零(千|百|拾|角)/g, '零')
58
+ .replace(/(零)+/g, '零')
59
+ .replace(/零(万|亿|元)/g, '$1')
60
+ .replace(/(亿)万|壹(拾)/g, '$1$2')
61
+ .replace(/^元零?|零分/g, '')
62
+ .replace(/元$/g, '元整')
63
+ }
64
+
65
+ export function formatDecimal(num, decimal = 2) {
66
+ num = num.toString()
67
+ let index = num.indexOf('.')
68
+ if (index !== -1) {
69
+ num = num.substring(0, decimal + index + 1)
70
+ } else {
71
+ num = num.substring(0)
72
+ }
73
+ return parseFloat(num).toFixed(decimal)
74
+ }
75
+
76
+ /**
77
+ * 保留指定位数的小数,对最后一位进行四舍五入
78
+ */
79
+ export function round(number, precision = 2) {
80
+ if (typeof number === 'number') {
81
+ // 指数表示法表示的数字 幂指数为-7以后 +number不转换为数字 只好用正则匹配了
82
+ const reg = /([0-9])+e([-0-9]+)/
83
+ const result = reg.exec(number + '') || []
84
+ if (result.length > 2) {
85
+ const num = result[1]
86
+ const e = result[2]
87
+ return Math.round(parseInt(+num + 'e' + (+e + precision))) / Math.pow(10, precision)
88
+ }
89
+ return Math.round(parseInt(+number + 'e' + precision)) / Math.pow(10, precision)
90
+ }
91
+ return number
92
+ }
93
+
94
+ /**
95
+ * 保留指定位数的小数,对最后一位进行四舍五入,并返回字符串
96
+ */
97
+ export function toFixed(num, precision = 2) {
98
+ const number = parseFloat(num + '')
99
+ if (!isNaN(number) && (number || number === 0)) {
100
+ return round(number, precision).toFixed(precision)
101
+ }
102
+
103
+ return num
104
+ }
105
+
106
+ /**
107
+ * 数字转中文
108
+ */
109
+ export const numToChineseNumerals = (num) => {
110
+ if (isNaN(num)) {
111
+ throw 'numToChineseNumerals: 数据非法'
112
+ }
113
+ num = Number(num)
114
+ return numToChineseNumeralsFormat(num).replace(/^零/, '').replace(/^一十/, '十')
115
+ }
116
+ const chineseNumeralList = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九']
117
+ const orderOfMagnitudeList = ['', '十', '百', '千']
118
+ function numToChineseNumeralsFormat(num) {
119
+ if (num === 0) {
120
+ return ''
121
+ }
122
+ const power = Math.floor(Math.log10(num))
123
+ const y = Math.floor(power / 8)
124
+ const x = Math.floor((power % 8) / 4)
125
+ let n1 = Math.floor(num / Math.pow(10, 4 * x + 8 * y))
126
+ let n2 = num % Math.pow(10, 4 * x + 8 * y)
127
+ let str = _(String(n1).padStart(4, '0'))
128
+ .split('')
129
+ .map(
130
+ (num, index) =>
131
+ chineseNumeralList[num] + (num === '0' ? '' : orderOfMagnitudeList[3 - index]),
132
+ )
133
+ .uniq()
134
+ .value()
135
+ .join('')
136
+ .replace(/零$/, '')
137
+ for (let i = 0; i < x; i++) {
138
+ str += '万'
139
+ }
140
+ for (let i = 0; i < y; i++) {
141
+ str += '亿'
142
+ }
143
+ return str + numToChineseNumeralsFormat(n2)
144
+ }
@@ -0,0 +1,11 @@
1
+ import { getSessionStorage, setSessionStorage, removeSessionStorage } from './storage';
2
+ const PERMISSION_KEY = 'ibp-sc-permission';
3
+ export function getPermissionCache() {
4
+ return getSessionStorage(PERMISSION_KEY);
5
+ }
6
+ export function setPermissionCache(data) {
7
+ setSessionStorage(PERMISSION_KEY, data);
8
+ }
9
+ export function clearPermissionCache() {
10
+ removeSessionStorage(PERMISSION_KEY);
11
+ }
@@ -0,0 +1,17 @@
1
+ import axios from 'axios';
2
+ import { requestInterceptors, responseInterceptors, inspectorError } from './interceptors';
3
+ import { CONTENT_TYPE, setContentType } from './content-type';
4
+ export * from './url-params';
5
+ export * from './content-type';
6
+ export { responseInterceptors };
7
+ const instance = axios.create({ timeout: 5 * 60 * 1000 });
8
+ instance.interceptors.request.use(requestInterceptors, inspectorError);
9
+ instance.interceptors.response.use(responseInterceptors, inspectorError);
10
+ instance.formPost = function (url, data, config) {
11
+ const headers = (config === null || config === void 0 ? void 0 : config.headers) || {};
12
+ setContentType(headers, CONTENT_TYPE.form);
13
+ return instance.post(url, data, Object.assign(Object.assign({}, config), { headers }));
14
+ };
15
+ export { instance as axiosN };
16
+
17
+ export default instance;
@@ -0,0 +1,19 @@
1
+ const contentTypeKey = 'Content-Type';
2
+ export function getContentType(config) {
3
+ let type = (config === null || config === void 0 ? void 0 : config[contentTypeKey]) || (config === null || config === void 0 ? void 0 : config['content-type']) || '';
4
+ const suffixIdx = type.indexOf(';');
5
+ if (suffixIdx !== -1) {
6
+ type = type.substring(0, suffixIdx);
7
+ }
8
+ return type;
9
+ }
10
+ export function setContentType(headers, type) {
11
+ headers[contentTypeKey] = type;
12
+ }
13
+ export const CONTENT_TYPE = {
14
+ form: 'application/x-www-form-urlencoded',
15
+ multiForm: 'multipart/form-data',
16
+ body: 'application/json',
17
+ os: 'application/octet-stream',
18
+ json: 'application/json',
19
+ };
@@ -0,0 +1,95 @@
1
+ import qs from 'qs';
2
+ import { getUrlParams } from './url-params';
3
+ import { CONTENT_TYPE, getContentType } from './content-type';
4
+ // import cacheRules from './cache-rules'
5
+ import { getToken } from '../token';
6
+ import { config } from '../../../config/config';
7
+ const SUCCESS_CODE = 1;
8
+ const NO_SESSION_CODE = 10106;
9
+ let timer = null;
10
+ function _debounce(callback) {
11
+ if (timer) {
12
+ clearTimeout(timer);
13
+ }
14
+ let callNow = !timer;
15
+ timer = setTimeout(() => {
16
+ timer = null;
17
+ }, 1000 * 20);
18
+ callNow && callback();
19
+ }
20
+ // 请求的拦截器,处理Content-Type以及加入token
21
+ export function requestInterceptors(config) {
22
+ let token = getToken();
23
+ if (token) {
24
+ config.headers.token = token;
25
+ }
26
+ // 以下拷自lambo-design
27
+ const params = getUrlParams();
28
+ // sso_token认证
29
+ if (params.hasOwnProperty('sso_token') || sessionStorage.getItem('sso_token')) {
30
+ config.params = Object.assign({
31
+ sso_token: params.sso_token || sessionStorage.getItem('sso_token'),
32
+ sso_id: params.sso_id,
33
+ }, config.params);
34
+ }
35
+ const contentType = getContentType(config.headers);
36
+ if (config.method === 'post') {
37
+ // form 表单方式提交
38
+ if (contentType === CONTENT_TYPE.form) {
39
+ config.data = qs.stringify(config.data);
40
+ }
41
+ }
42
+ else if (config.method === 'get') {
43
+ // 暂时不要这个逻辑
44
+ // for (let rule of cacheRules) {
45
+ // if (rule.test(config.url)) {
46
+ // return config
47
+ // }
48
+ // }
49
+ // if (config.url.indexOf('?') === -1) {
50
+ // config.url = config.url + '?t=' + new Date().getTime()
51
+ // } else {
52
+ // config.url = config.url + '&t=' + new Date().getTime()
53
+ // }
54
+ }
55
+ return config;
56
+ }
57
+ export function responseInterceptors(response) {
58
+ let data = response.data;
59
+ // 下载文件返回格式不是json
60
+ const contentType = getContentType(response.headers);
61
+ if (contentType !== CONTENT_TYPE.json) {
62
+ return data;
63
+ }
64
+ if (typeof response.data === 'string') {
65
+ data = JSON.parse(response.data);
66
+ }
67
+ const code = data.code;
68
+ switch (code) {
69
+ case SUCCESS_CODE: {
70
+ return data;
71
+ }
72
+ case NO_SESSION_CODE: {
73
+ _debounce(function () {
74
+ window.sessionNotValidHandler && window.sessionNotValidHandler();
75
+ });
76
+ break;
77
+ }
78
+ default: {
79
+ let msg = data.message || data.msg || config.errorMessage;
80
+ window.apiErrorHandler && window.apiErrorHandler(msg);
81
+ }
82
+ }
83
+ return Promise.reject(data);
84
+ }
85
+ export function inspectorError(error) {
86
+ var _a;
87
+ if ((error === null || error === void 0 ? void 0 : error.code) === 'ECONNABORTED') {
88
+ // 超时
89
+ window.apiErrorHandler && window.apiErrorHandler('请求超时,请稍后再试');
90
+ }
91
+ else if (((_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.status) !== 200) {
92
+ window.apiErrorHandler && window.apiErrorHandler('请求出错了');
93
+ }
94
+ return Promise.reject(error);
95
+ }
@@ -0,0 +1,12 @@
1
+ export function getUrlParams() {
2
+ const url = location.search; //获取url中"?"符后的字串
3
+ const theRequest = new Object();
4
+ if (url.indexOf('?') != -1) {
5
+ const str = url.substr(1);
6
+ let strs = str.split('&');
7
+ for (let i = 0; i < strs.length; i++) {
8
+ theRequest[strs[i].split('=')[0]] = unescape(strs[i].split('=')[1]);
9
+ }
10
+ }
11
+ return theRequest;
12
+ }
@@ -0,0 +1,51 @@
1
+ // ============ SessionStorage ============
2
+ export const getSessionStorage = (key) => {
3
+ const value = sessionStorage.getItem(key)
4
+ if (value) {
5
+ try {
6
+ return JSON.parse(value)
7
+ } catch (error) {
8
+ return value
9
+ }
10
+ }
11
+ return value
12
+ }
13
+
14
+ export const setSessionStorage = (key, value) => {
15
+ if (typeof value !== 'string') {
16
+ value = JSON.stringify(value)
17
+ }
18
+ sessionStorage.setItem(key, value)
19
+ }
20
+
21
+ export const removeSessionStorage = (key) => {
22
+ return sessionStorage.removeItem(key)
23
+ }
24
+
25
+ export function clearSessionStorage() {
26
+ sessionStorage.clear()
27
+ }
28
+
29
+ // ============ LocalStorage ============
30
+ export const getLocalStorage = (key) => {
31
+ const value = localStorage.getItem(key)
32
+ if (value) {
33
+ try {
34
+ return JSON.parse(value)
35
+ } catch (error) {
36
+ return value
37
+ }
38
+ }
39
+ return value
40
+ }
41
+
42
+ export const setLocalStorage = (key, value) => {
43
+ if (typeof value !== 'string') {
44
+ value = JSON.stringify(value)
45
+ }
46
+ localStorage.setItem(key, value)
47
+ }
48
+
49
+ export const removeLocalStorage = (key) => {
50
+ return localStorage.removeItem(key)
51
+ }
@@ -0,0 +1,51 @@
1
+ import { getLocalStorage, getSessionStorage, setLocalStorage } from './storage';
2
+ const TOKEN_KEY = 'v8-token';
3
+ const TOKEN_KEY_IBP = 'lambo-token';
4
+ // 要从门户跳转过来,sessionStorage不能带token过来,改成localStorage
5
+ export function setToken(token) {
6
+ setLocalStorage(TOKEN_KEY, token);
7
+ Cookie.set('TOKEN_KEY', token, 1);
8
+ }
9
+ export function getToken() {
10
+ let token = getSessionStorage(TOKEN_KEY_IBP);
11
+ if (!token) {
12
+ token = Cookie.get('lambo-sso-key');
13
+ }
14
+ if (!token) {
15
+ token = Cookie.get('TOKEN_KEY');
16
+ }
17
+ if (!token) {
18
+ token = getLocalStorage(TOKEN_KEY);
19
+ }
20
+ return token || false;
21
+ }
22
+ const Cookie = {
23
+ set: function (key, value, exdays) {
24
+ //校验Key, key中不能有等号【=】
25
+ if (key.indexOf('=') !== -1) {
26
+ throw new Error('Cookie不支持key中使用等号【=】, key:' + key);
27
+ }
28
+ let exdate = new Date(); // 获取时间
29
+ exdate.setTime(exdate.getTime() + 24 * 60 * 60 * 1000 * exdays); // 保存的天数
30
+ // 字符串拼接cookie
31
+ // eslint-disable-next-line camelcase
32
+ window.document.cookie = key + '=' + value + ';path=/;expires=' + exdate.toGMTString();
33
+ },
34
+ get: function (key) {
35
+ if (document.cookie.length > 0) {
36
+ // 这里显示的格式需要切割一下自己可输出看下
37
+ var arr = document.cookie.split('; ');
38
+ for (let i = 0; i < arr.length; i++) {
39
+ let arr2 = arr[i].split('='); // 再次切割
40
+ // 判断查找相对应的值
41
+ if (arr2[0] === key) {
42
+ var value = arr2[1];
43
+ for (let j = 2; j < arr2.length; j++) {
44
+ value += '=' + arr2[j];
45
+ }
46
+ return value;
47
+ }
48
+ }
49
+ }
50
+ },
51
+ };
@@ -0,0 +1,11 @@
1
+ import { getLocalStorage, removeLocalStorage, setLocalStorage } from './storage';
2
+ const USER_INFO_KEY = 'userInfo';
3
+ export function getUserInfoCache() {
4
+ return getLocalStorage(USER_INFO_KEY);
5
+ }
6
+ export function setUserInfoCache(data) {
7
+ setLocalStorage(USER_INFO_KEY, data);
8
+ }
9
+ export function clearUserInfoCache() {
10
+ removeLocalStorage(USER_INFO_KEY);
11
+ }