@jiangood/springboot-admin-starter 0.0.1

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 (213) hide show
  1. package/config/config.js +10 -0
  2. package/config/config.local.js +10 -0
  3. package/config/defaultConfig.js +35 -0
  4. package/config/plugins/forms.js +44 -0
  5. package/config/plugins/routes.js +82 -0
  6. package/package.json +41 -0
  7. package/src/.npmignore +6 -0
  8. package/src/app.js +0 -0
  9. package/src/asserts/login_bg.jpg +0 -0
  10. package/src/asserts/welcome.png +0 -0
  11. package/src/components/InstanceInfo.jsx +138 -0
  12. package/src/components/InstanceStatusInfo.jsx +79 -0
  13. package/src/components/StreamLog.jsx +27 -0
  14. package/src/components/flow/BpmnUtils.js +85 -0
  15. package/src/components/flow/customTranslate/customTranslate.js +19 -0
  16. package/src/components/flow/customTranslate/translations.js +79 -0
  17. package/src/components/flow/design/contextPad.js +50 -0
  18. package/src/components/flow/design/form/ConditionForm.jsx +316 -0
  19. package/src/components/flow/design/form/ServiceTaskForm.jsx +55 -0
  20. package/src/components/flow/design/form/TimerEventDefinitionForm.jsx +62 -0
  21. package/src/components/flow/design/form/UserTaskForm.jsx +211 -0
  22. package/src/components/flow/design/palette.js +39 -0
  23. package/src/components/monitor/AllDefinition.jsx +46 -0
  24. package/src/components/monitor/AllInstance.jsx +76 -0
  25. package/src/forms/demoForm.jsx +16 -0
  26. package/src/framework/components/ButtonList.d.ts +9 -0
  27. package/src/framework/components/ButtonList.jsx +91 -0
  28. package/src/framework/components/DownloadFileButton.d.ts +11 -0
  29. package/src/framework/components/DownloadFileButton.jsx +33 -0
  30. package/src/framework/components/Echarts/index.d.ts +10 -0
  31. package/src/framework/components/Echarts/index.jsx +49 -0
  32. package/src/framework/components/EditTable/index.d.ts +11 -0
  33. package/src/framework/components/EditTable/index.jsx +85 -0
  34. package/src/framework/components/EditTable/index.less +29 -0
  35. package/src/framework/components/Ellipsis.jsx +39 -0
  36. package/src/framework/components/Ellipsis.less +8 -0
  37. package/src/framework/components/FieldRemoteTree.jsx +20 -0
  38. package/src/framework/components/Gap/index.d.ts +10 -0
  39. package/src/framework/components/Gap/index.jsx +15 -0
  40. package/src/framework/components/Gap/index.less +3 -0
  41. package/src/framework/components/HasPerm.jsx +18 -0
  42. package/src/framework/components/ImageView.d.ts +12 -0
  43. package/src/framework/components/ImageView.jsx +64 -0
  44. package/src/framework/components/LinkButton.d.ts +14 -0
  45. package/src/framework/components/LinkButton.jsx +13 -0
  46. package/src/framework/components/MsgBox.jsx +180 -0
  47. package/src/framework/components/NamedIcon.tsx +15 -0
  48. package/src/framework/components/OrgTree.jsx +60 -0
  49. package/src/framework/components/Page/index.d.ts +10 -0
  50. package/src/framework/components/Page/index.jsx +30 -0
  51. package/src/framework/components/Page/index.less +10 -0
  52. package/src/framework/components/PageLoading.jsx +31 -0
  53. package/src/framework/components/Panel/index.d.ts +11 -0
  54. package/src/framework/components/Panel/index.jsx +24 -0
  55. package/src/framework/components/Panel/index.less +0 -0
  56. package/src/framework/components/ProModal/index.tsx +66 -0
  57. package/src/framework/components/ProTable/components/ToolBar/index.jsx +124 -0
  58. package/src/framework/components/ProTable/components/ToolBar/index.less +53 -0
  59. package/src/framework/components/ProTable/index.d.ts +38 -0
  60. package/src/framework/components/ProTable/index.jsx +258 -0
  61. package/src/framework/components/ProTable/index.less +3 -0
  62. package/src/framework/components/ProTable/utils/index.js +43 -0
  63. package/src/framework/components/RoleTree.jsx +53 -0
  64. package/src/framework/components/ValueType/index.jsx +34 -0
  65. package/src/framework/components/ValueType/registry.jsx +38 -0
  66. package/src/framework/components/field/FieldAutoTime/index.tsx +46 -0
  67. package/src/framework/components/field/FieldBoolean/index.tsx +92 -0
  68. package/src/framework/components/field/FieldEditTable/index.d.ts +13 -0
  69. package/src/framework/components/field/FieldEditTable/index.jsx +103 -0
  70. package/src/framework/components/field/FieldEditTable/index.less +29 -0
  71. package/src/framework/components/field/FieldEditor.jsx +48 -0
  72. package/src/framework/components/field/FieldFileBase64/index.d.ts +15 -0
  73. package/src/framework/components/field/FieldFileBase64/index.jsx +23 -0
  74. package/src/framework/components/field/FieldImageBase64/index.d.ts +15 -0
  75. package/src/framework/components/field/FieldImageBase64/index.jsx +22 -0
  76. package/src/framework/components/field/FieldInput.jsx +13 -0
  77. package/src/framework/components/field/FieldOrgTree/index.tsx +45 -0
  78. package/src/framework/components/field/FieldPassword.jsx +11 -0
  79. package/src/framework/components/field/FieldProps.ts +19 -0
  80. package/src/framework/components/field/FieldRemoteTreeCascader.jsx +75 -0
  81. package/src/framework/components/field/FieldRemoteTreeCheckable.jsx +81 -0
  82. package/src/framework/components/field/FieldRemoteTreeMultipleSelect.jsx +100 -0
  83. package/src/framework/components/field/FieldRemoteTreeSelect.jsx +82 -0
  84. package/src/framework/components/field/FieldSelectPosition/index.tsx +85 -0
  85. package/src/framework/components/field/FieldTree.jsx +45 -0
  86. package/src/framework/components/field/dict/index.tsx +110 -0
  87. package/src/framework/components/field/flat-multiple-select/index.d.ts +4 -0
  88. package/src/framework/components/field/flat-multiple-select/index.jsx +116 -0
  89. package/src/framework/components/field/flat-multiple-select/index.less +12 -0
  90. package/src/framework/components/field/flat-select/index.d.ts +4 -0
  91. package/src/framework/components/field/flat-select/index.jsx +107 -0
  92. package/src/framework/components/field/flat-select/index.less +12 -0
  93. package/src/framework/components/field/index.js +33 -0
  94. package/src/framework/components/field/input-number-percent/index.d.ts +11 -0
  95. package/src/framework/components/field/input-number-percent/index.jsx +28 -0
  96. package/src/framework/components/field/select/FieldSelect/index.d.ts +39 -0
  97. package/src/framework/components/field/select/FieldSelect/index.jsx +156 -0
  98. package/src/framework/components/field/select/FieldTableSelect/index.d.ts +29 -0
  99. package/src/framework/components/field/select/FieldTableSelect/index.jsx +155 -0
  100. package/src/framework/components/field/select/index.jsx +2 -0
  101. package/src/framework/components/field/switch-y-n/index.d.ts +11 -0
  102. package/src/framework/components/field/switch-y-n/index.jsx +31 -0
  103. package/src/framework/components/field/text/index.tsx +7 -0
  104. package/src/framework/components/field/time/DatePickerString.tsx +37 -0
  105. package/src/framework/components/field/time/DateTimePickerString.tsx +42 -0
  106. package/src/framework/components/field/time/FieldDateRange.d.ts +9 -0
  107. package/src/framework/components/field/time/FieldDateRange.jsx +49 -0
  108. package/src/framework/components/field/time/HHmmPickerString.tsx +42 -0
  109. package/src/framework/components/field/time/MonthPickerString.tsx +45 -0
  110. package/src/framework/components/field/time/TimePickerTool.ts +14 -0
  111. package/src/framework/components/field/time/YearPickerString.tsx +41 -0
  112. package/src/framework/components/field/time/YearQuarterString.tsx +38 -0
  113. package/src/framework/components/field/time/index.tsx +7 -0
  114. package/src/framework/components/field/upload/FieldUploadCropImage/index.d.ts +22 -0
  115. package/src/framework/components/field/upload/FieldUploadCropImage/index.jsx +11 -0
  116. package/src/framework/components/field/upload/FieldUploadFile.d.ts +35 -0
  117. package/src/framework/components/field/upload/FieldUploadFile.jsx +145 -0
  118. package/src/framework/components/field/upload/FieldUploadImage.d.ts +7 -0
  119. package/src/framework/components/field/upload/FieldUploadImage.jsx +16 -0
  120. package/src/framework/components/field/upload/index.jsx +3 -0
  121. package/src/framework/components/index.js +25 -0
  122. package/src/framework/components/system.jsx +29 -0
  123. package/src/framework/components/view/ViewBoolean.jsx +15 -0
  124. package/src/framework/components/view/ViewBooleanEnableDisable.jsx +16 -0
  125. package/src/framework/components/view/ViewEllipsis.d.ts +11 -0
  126. package/src/framework/components/view/ViewEllipsis.jsx +30 -0
  127. package/src/framework/components/view/ViewFile.d.ts +10 -0
  128. package/src/framework/components/view/ViewFile.jsx +50 -0
  129. package/src/framework/components/view/ViewFileButton.d.ts +10 -0
  130. package/src/framework/components/view/ViewFileButton.jsx +0 -0
  131. package/src/framework/components/view/ViewImage.d.ts +9 -0
  132. package/src/framework/components/view/ViewImage.jsx +61 -0
  133. package/src/framework/components/view/ViewPassword.jsx +24 -0
  134. package/src/framework/components/view/ViewRange/index.d.ts +16 -0
  135. package/src/framework/components/view/ViewRange/index.jsx +20 -0
  136. package/src/framework/components/view/ViewText.jsx +9 -0
  137. package/src/framework/components/view/index.js +12 -0
  138. package/src/framework/index.js +3 -0
  139. package/src/framework/system/FormRegistry.js +58 -0
  140. package/src/framework/system/dict.js +88 -0
  141. package/src/framework/system/http.jsx +290 -0
  142. package/src/framework/system/index.js +13 -0
  143. package/src/framework/system/page.js +109 -0
  144. package/src/framework/system/permission.js +44 -0
  145. package/src/framework/system/sys.js +60 -0
  146. package/src/framework/system/theme.js +17 -0
  147. package/src/framework/utils/arr.js +118 -0
  148. package/src/framework/utils/browser.js +24 -0
  149. package/src/framework/utils/color.js +269 -0
  150. package/src/framework/utils/date.js +173 -0
  151. package/src/framework/utils/debounce.js +33 -0
  152. package/src/framework/utils/dom.js +16 -0
  153. package/src/framework/utils/eventBus.js +70 -0
  154. package/src/framework/utils/html.js +13 -0
  155. package/src/framework/utils/index.js +17 -0
  156. package/src/framework/utils/obj.js +72 -0
  157. package/src/framework/utils/storage.js +37 -0
  158. package/src/framework/utils/str.js +297 -0
  159. package/src/framework/utils/tree.js +175 -0
  160. package/src/framework/utils/uid.js +76 -0
  161. package/src/framework/utils/url.js +84 -0
  162. package/src/framework/utils/validate.js +9 -0
  163. package/src/index.js +2 -0
  164. package/src/layouts/PageRender.d.ts +22 -0
  165. package/src/layouts/PageRender.jsx +90 -0
  166. package/src/layouts/admin/HeaderRight.jsx +104 -0
  167. package/src/layouts/admin/TabPageRender.jsx +158 -0
  168. package/src/layouts/admin/index.jsx +174 -0
  169. package/src/layouts/admin/index.less +64 -0
  170. package/src/layouts/index.jsx +163 -0
  171. package/src/layouts/index.less +45 -0
  172. package/src/loading.jsx +18 -0
  173. package/src/pages/404.jsx +13 -0
  174. package/src/pages/about.jsx +14 -0
  175. package/src/pages/api/accessLog/index.jsx +108 -0
  176. package/src/pages/api/accountResource/index.jsx +149 -0
  177. package/src/pages/api/doc.jsx +135 -0
  178. package/src/pages/api/index.jsx +163 -0
  179. package/src/pages/api/resource.jsx +18 -0
  180. package/src/pages/flowable/design/index.css +7 -0
  181. package/src/pages/flowable/design/index.jsx +297 -0
  182. package/src/pages/flowable/index.jsx +128 -0
  183. package/src/pages/flowable/instance/view.jsx +13 -0
  184. package/src/pages/flowable/monitor.jsx +106 -0
  185. package/src/pages/flowable/task/form.jsx +99 -0
  186. package/src/pages/flowable/task/index.jsx +200 -0
  187. package/src/pages/flowable/test/form.jsx +31 -0
  188. package/src/pages/flowable/test/index.jsx +54 -0
  189. package/src/pages/index.jsx +25 -0
  190. package/src/pages/job/index.jsx +239 -0
  191. package/src/pages/job/logList.jsx +100 -0
  192. package/src/pages/job/status.jsx +84 -0
  193. package/src/pages/login.jsx +144 -0
  194. package/src/pages/login.less +53 -0
  195. package/src/pages/system/config/index.jsx +136 -0
  196. package/src/pages/system/dict/Dict.jsx +73 -0
  197. package/src/pages/system/dict/DictItem.jsx +177 -0
  198. package/src/pages/system/dict/index.jsx +25 -0
  199. package/src/pages/system/file/index.jsx +152 -0
  200. package/src/pages/system/log/index.jsx +78 -0
  201. package/src/pages/system/org/index.jsx +263 -0
  202. package/src/pages/system/role/index.jsx +314 -0
  203. package/src/pages/system/role/perm.jsx +111 -0
  204. package/src/pages/system/sysManual/index.jsx +127 -0
  205. package/src/pages/system/user/UserPerm.jsx +132 -0
  206. package/src/pages/system/user/index.jsx +261 -0
  207. package/src/pages/test.jsx +16 -0
  208. package/src/pages/ureport/index.jsx +43 -0
  209. package/src/pages/userCenter/ChangePassword.jsx +64 -0
  210. package/src/pages/userCenter/index.jsx +90 -0
  211. package/src/pages/userCenter/manual.jsx +63 -0
  212. package/src/pages/userCenter/message.jsx +105 -0
  213. package/src/style/global.less +51 -0
@@ -0,0 +1,70 @@
1
+ /**
2
+ * 事件总线
3
+ * forked form https://github.com/scottcorgan/tiny-emitter
4
+ */
5
+
6
+ export class EventBus {
7
+ constructor () {
8
+ this.__stack = {}
9
+ }
10
+
11
+ on (name, callback, ctx) {
12
+ (this.__stack[ name ] || (this.__stack[ name ] = [])).push({
13
+ fn: callback,
14
+ ctx
15
+ })
16
+
17
+ return this // chainable
18
+ }
19
+
20
+ once (name, callback, ctx) {
21
+ const listener = (...args) => {
22
+ this.off(name, listener)
23
+ callback.apply(ctx, args)
24
+ }
25
+
26
+ listener.__callback = callback
27
+ return this.on(name, listener, ctx) // chainable
28
+ }
29
+
30
+ emit (name) {
31
+ const list = this.__stack[ name ]
32
+
33
+ if (list !== void 0) {
34
+ const params = [].slice.call(arguments, 1)
35
+ list.forEach(entry => {
36
+ entry.fn.apply(entry.ctx, params)
37
+ })
38
+ }
39
+
40
+ return this // chainable
41
+ }
42
+
43
+ off (name, callback) {
44
+ const list = this.__stack[ name ]
45
+
46
+ if (list === void 0) {
47
+ return this // chainable
48
+ }
49
+
50
+ if (callback === void 0) {
51
+ delete this.__stack[ name ]
52
+ return this // chainable
53
+ }
54
+
55
+ const liveEvents = list.filter(
56
+ entry => entry.fn !== callback && entry.fn.__callback !== callback
57
+ )
58
+
59
+ if (liveEvents.length !== 0) {
60
+ this.__stack[ name ] = liveEvents
61
+ }
62
+ else {
63
+ delete this.__stack[ name ]
64
+ }
65
+
66
+ return this // chainable
67
+ }
68
+ }
69
+
70
+ export const eventBus = new EventBus()
@@ -0,0 +1,13 @@
1
+
2
+ export function getIframeCommonProps() {
3
+
4
+ return {
5
+ width: '100%',
6
+ frameBorder: 0,
7
+ marginHeight: 0,
8
+ marginWidth: 0
9
+ }
10
+ }
11
+
12
+
13
+
@@ -0,0 +1,17 @@
1
+ export * from "./date";
2
+ export * from "./arr";
3
+ export * from "./html";
4
+ export * from "./url"
5
+ export * from "./str"
6
+ export * from "./eventBus";
7
+ export * from "./color"
8
+ export * from "./debounce";
9
+ export * from "./dom"
10
+ export * from "./uid";
11
+ export * from './validate'
12
+
13
+ export * from "./str"
14
+ export * from "./tree";
15
+ export * from './storage'
16
+ export * from './browser'
17
+ export * from './obj'
@@ -0,0 +1,72 @@
1
+ /**
2
+ * 于安全地获取深度嵌套的对象属性的值
3
+ * 如果属性链中的任何一级为 undefined 或 null,get 函数会返回一个默认值,而不是抛出错误。
4
+ *
5
+ * const obj = { 'a': [{ 'b': { 'c': 3 } }] };
6
+ *
7
+ * const value = get(obj, 'a[0].b.c');
8
+ *
9
+ * @param obj
10
+ * @param path
11
+ * @param defaultValue
12
+ */
13
+ export function get(obj, path, defaultValue = undefined){
14
+
15
+ const pathArray = Array.isArray(path) ? path : path.split('.');
16
+ let result = obj;
17
+
18
+ // 遍历路径
19
+ for (const segment of pathArray) {
20
+ if (result == null) {
21
+ return defaultValue;
22
+ }
23
+
24
+ // 尝试访问属性
25
+ result = result[segment];
26
+ }
27
+
28
+ // 如果结果还是 null 或 undefined,则返回默认值
29
+ return result != null ? result : defaultValue;
30
+
31
+ }
32
+
33
+
34
+ export class ObjUtil {
35
+
36
+ /**
37
+ * 复制对象属性
38
+ * 如果目标对象的属性存在才复制
39
+ * @param source
40
+ * @param target
41
+ */
42
+ static copyPropertyIfPresent(source, target){
43
+ if (!source || !target || typeof source !== 'object' || typeof target !== 'object') {
44
+ return;
45
+ }
46
+
47
+ const keys = Object.keys(target)
48
+ for (let key of keys) {
49
+ if(Object.hasOwn(source,key)){
50
+ let value = source[key];
51
+ target[key] = value
52
+ }
53
+ }
54
+ }
55
+
56
+
57
+ static copyProperty(source, target){
58
+ if (!source || !target || typeof source !== 'object' || typeof target !== 'object') {
59
+ return;
60
+ }
61
+
62
+ const keys = Object.keys(target)
63
+ for (let key of keys) {
64
+ let value = source[key];
65
+ if(value !== undefined){
66
+ target[key] = value
67
+ }
68
+
69
+ }
70
+ }
71
+
72
+ }
@@ -0,0 +1,37 @@
1
+ import {DateUtil} from "./date";
2
+
3
+
4
+ const ENCRYPT = false;
5
+
6
+ export const StorageUtil = {
7
+
8
+
9
+ get(key, defaultValue = null) {
10
+ let v = localStorage.getItem(key);
11
+ if (v == null) {
12
+ v = defaultValue;
13
+ }else {
14
+ const item = JSON.parse(v);
15
+ v = item.data
16
+ }
17
+
18
+
19
+ return v
20
+ },
21
+
22
+ set(key, value) {
23
+ if(value == null){
24
+ localStorage.removeItem(key)
25
+ }
26
+ const item = {
27
+ createTime: DateUtil.now(),
28
+ data: value
29
+ }
30
+ const dataStr = JSON.stringify(item)
31
+ localStorage.setItem(key, dataStr)
32
+ }
33
+
34
+ }
35
+
36
+
37
+
@@ -0,0 +1,297 @@
1
+ export const StrUtil = {
2
+
3
+
4
+
5
+ removePrefix(str, ch){
6
+ if(str != null && str.startsWith(ch)){
7
+ return str.substring(ch.length)
8
+ }
9
+
10
+ return str;
11
+ },
12
+ removeSuffix(str, ch){
13
+ if(str != null && str.endsWith(ch)){
14
+ return str.substring(0,str.length - ch.length)
15
+ }
16
+
17
+ return str;
18
+ },
19
+
20
+ random(length){
21
+ const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
22
+ let result = '';
23
+ for (let i = 0; i < length; i++) {
24
+ result += characters.charAt(Math.floor(Math.random() * characters.length));
25
+ }
26
+ return result;
27
+
28
+ },
29
+
30
+ nullText(key){
31
+ return (key || '') + "未定义"
32
+ },
33
+
34
+
35
+ /**
36
+ * 包含
37
+ * @param subStr
38
+ * @returns {boolean}
39
+ */
40
+ contains(str, subStr) {
41
+ if (!str) {
42
+ return false
43
+ }
44
+ return str.includes(subStr);
45
+ },
46
+
47
+
48
+ /**
49
+ * 判断字符串出现的个数
50
+ * @param subStr
51
+ */
52
+ count(str, subStr) {
53
+ if (str == null || str.length == 0) {
54
+ return 0;
55
+ }
56
+ let count = 0;
57
+ let index = 0;
58
+
59
+ while (true) {
60
+ index = str.indexOf(subStr, index);
61
+ if (index === -1) {
62
+ break;
63
+ }
64
+ count++;
65
+ index += subStr.length;
66
+ }
67
+
68
+ return count;
69
+ },
70
+
71
+
72
+ /**
73
+ * 将字符串的首字母转换为大写
74
+ */
75
+ capitalize(str) {
76
+ if (str == null) {
77
+ return str
78
+ }
79
+ return str.charAt(0).toUpperCase() + str.slice(1);
80
+ },
81
+
82
+ /**
83
+ * 颠倒字符串的顺序
84
+ * @param str
85
+ * @returns {*}
86
+ */
87
+ reverse(str) {
88
+ if (str == null) {
89
+ return str;
90
+ }
91
+ return str.split('').reverse().join('');
92
+ },
93
+
94
+ /**
95
+ * 截取字符串, 如果不包含,则原样返回
96
+ * @param source
97
+ * @param str
98
+ * @returns {string|null}
99
+ */
100
+ subAfter(source, str) {
101
+ if (source == null) {
102
+ return source;
103
+ }
104
+ const index = source.indexOf(str)
105
+ return index === -1 ? source : source.substring(index + 1);
106
+ },
107
+
108
+ subAfterLast(source, str) {
109
+ if (source == null) {
110
+ return source;
111
+ }
112
+ const index = source.lastIndexOf(str)
113
+ return index === -1 ? source : source.substring(index + 1);
114
+ },
115
+
116
+ subBefore(s, sub) {
117
+ if (s == null) {
118
+ return s;
119
+ }
120
+ const index = s.indexOf(sub)
121
+ return index === -1 ? s : s.substring(0, index);
122
+ },
123
+
124
+ /**
125
+ * 混淆
126
+ * @param str
127
+ * @returns {*}
128
+ */
129
+ obfuscateString(str) {
130
+ if (str == null) {
131
+ return str
132
+ }
133
+ return str.split('').map(char => char + 1).join('');
134
+ },
135
+
136
+
137
+ /**
138
+ * 补零
139
+ * @param input 输入字符串说数字等
140
+ * @param totalLen 总长度,不狗
141
+ * @param padChar
142
+ * @returns {string}
143
+ */
144
+ pad(input, totalLen, padChar = '0') {
145
+ if (input == null) {
146
+ return padChar.repeat(totalLen)
147
+ }
148
+ var str = String(input);
149
+ var zerosNeeded = totalLen - str.length;
150
+ if (zerosNeeded > 0) {
151
+ str = padChar.repeat(zerosNeeded) + str;
152
+ }
153
+ return str;
154
+ },
155
+
156
+
157
+ /**
158
+ * 加密
159
+ * @param str
160
+ * @returns {string}
161
+ */
162
+ encrypt(str) {
163
+ if (str == null) {
164
+ return str
165
+ }
166
+ let encrypted = '';
167
+ for (let i = 0; i < str.length; i++) {
168
+ let charCode = str.charCodeAt(i);
169
+ charCode += 1;
170
+ encrypted += ('00' + charCode.toString(16)).slice(-4); // 转换为四位的十六进制表示
171
+ }
172
+ return encrypted;
173
+ },
174
+
175
+
176
+ decrypt(hexString) {
177
+ if (hexString == null) {
178
+ return hexString;
179
+ }
180
+ let decrypted = '';
181
+ for (let i = 0; i < hexString.length; i += 4) {
182
+ let hexCharCode = hexString.substr(i, 4);
183
+ let charCode = parseInt(hexCharCode, 16); // 将十六进制转换为十进制
184
+ charCode -= 1
185
+ decrypted += String.fromCharCode(charCode);
186
+ }
187
+ return decrypted;
188
+ },
189
+
190
+
191
+ /**
192
+ * 类似String.length, 区别在与中文字符占2位宽
193
+ * 获取字符串长度,英文字符 长度1,中文字符长度2
194
+ * @param {*} str
195
+ */
196
+ getWidth(str) {
197
+ if (str == null || str.length === 0) {
198
+ return 0
199
+ }
200
+ return str.split('').reduce((pre, cur) => {
201
+ const charCode = cur.charCodeAt(0);
202
+ if (charCode >= 0 && charCode <= 128) {
203
+ return pre + 1;
204
+ }
205
+ return pre + 2;
206
+ }, 0);
207
+ },
208
+
209
+ cutByWidth(str, maxWidth) {
210
+ let showLength = 0;
211
+ return str.split('').reduce((pre, cur) => {
212
+ const charCode = cur.charCodeAt(0);
213
+ if (charCode >= 0 && charCode <= 128) {
214
+ showLength += 1;
215
+ } else {
216
+ showLength += 2;
217
+ }
218
+ if (showLength <= maxWidth) {
219
+ return pre + cur;
220
+ }
221
+ return pre;
222
+ }, '');
223
+ },
224
+
225
+
226
+ /**
227
+ *
228
+ * @param str
229
+ * @param len 字符长度,注:中文字符算2
230
+ * @constructor
231
+ */
232
+ ellipsis(str, len, suffix = '...') {
233
+ if (str == null) {
234
+ return str;
235
+ }
236
+ if (!this.isStr(str)) {
237
+ return str;
238
+ }
239
+
240
+ // 快速判断2倍
241
+ if (str.length * 2 < len) {
242
+ return str
243
+ }
244
+
245
+ const fullLength = this.getWidth(str);
246
+ let isTooLong = fullLength > len;
247
+
248
+ if (!isTooLong) {
249
+ return str;
250
+ }
251
+
252
+ return this.cutByWidth(str, len) + suffix;
253
+ },
254
+
255
+ isStr(value) {
256
+ return typeof value === "string"
257
+ },
258
+
259
+
260
+ // 转驼峰
261
+ toCamelCase(str, firstLower = true) {
262
+ let result = str.replace(/\_(\w)/g, function (all, letter) {
263
+ return letter.toUpperCase();
264
+ });
265
+
266
+ if (firstLower) {
267
+ result = result.substring(0, 1).toLowerCase() + result.substring(1);
268
+ }
269
+
270
+ return result;
271
+ },
272
+
273
+ toUnderlineCase(name) {
274
+ if (name == null) {
275
+ return null;
276
+ }
277
+ let result = name.replace(/([A-Z])/g, '_$1').toLowerCase();
278
+ if (result.startsWith('_')) {
279
+ result = result.substring(1);
280
+ }
281
+ return result;
282
+ },
283
+
284
+ equalsIgnoreCase(a, b) {
285
+ if (a != null && b != null) {
286
+ if (a === b) {
287
+ return true;
288
+ }
289
+
290
+ if (a.toLowerCase() === b.toLowerCase()) {
291
+ return true;
292
+ }
293
+ }
294
+
295
+ return false;
296
+ }
297
+ }
@@ -0,0 +1,175 @@
1
+ // 数据结构 - tree
2
+
3
+ // 为方便起见,默认 3个字段 id, pid, children
4
+
5
+
6
+ import {ArrUtil} from "./arr";
7
+
8
+
9
+ function treeToList(tree, level = 1, result = []) {
10
+ for (const node of tree) {
11
+ const newNode = {...node, level: level};
12
+ result.push(newNode);
13
+
14
+ if (node.children && node.children.length > 0) {
15
+ treeToList(node.children, level + 1, result);
16
+ }
17
+ }
18
+
19
+ return result;
20
+ }
21
+
22
+
23
+ export const TreeUtil = {
24
+ treeToList,
25
+
26
+ /**
27
+ *
28
+ * @param tree
29
+ * @param level -1所有
30
+ */
31
+ findKeysByLevel(tree, level) {
32
+ const list = this.treeToList(tree)
33
+ if (level === -1) {
34
+ return list.filter(t => t.level === level).map(t => t.id)
35
+ }
36
+ return list.filter(t => t.level === level).map(t => t.id)
37
+ },
38
+
39
+ /**
40
+ * 将数组转换为树
41
+ * @param list
42
+ * @param idKey
43
+ * @param pidKey
44
+ * @returns {*[]}
45
+ */
46
+ buildTree(list, idKey = 'id', pidKey = 'pid') {
47
+ const map = {};
48
+ for (let i = 0; i < list.length; i++) {
49
+ const node = list[i];
50
+ let id = node[idKey];
51
+ map[id] = node;
52
+ }
53
+
54
+ const root = [];
55
+ for (let i = 0; i < list.length; i++) {
56
+ const node = list[i];
57
+ let pid = node[pidKey];
58
+ let parent = map[pid]
59
+ if (parent) {
60
+ if (parent.children == null) {
61
+ parent.children = []
62
+ }
63
+ parent.children.push(node)
64
+ } else {
65
+ root.push(node)
66
+ }
67
+ }
68
+
69
+ return root;
70
+ },
71
+
72
+
73
+ // 遍历树节点
74
+ walk(tree, callback) {
75
+ // 遍历当前层级的节点
76
+ for (let i = 0; i < tree.length; i++) {
77
+ const node = tree[i];
78
+ callback(node); // 执行回调函数
79
+
80
+ // 遍历子节点
81
+ if (node.children && node.children.length > 0) {
82
+ this.walk(node.children, callback);
83
+ }
84
+ }
85
+ },
86
+
87
+ findByKey(key, list, keyName = "id") {
88
+ for (let item of list) {
89
+ if (item[keyName] === key) {
90
+ return item;
91
+ }
92
+ if (item.children && item.children.length) {
93
+ const rs = this.findByKey(key, item.children, keyName)
94
+ if (rs) {
95
+ return rs;
96
+ }
97
+ }
98
+ }
99
+ },
100
+
101
+
102
+ findByKeyList(treeData, keyList) {
103
+ const itemList = [];
104
+ this.traverseTree(treeData, (item) => {
105
+ const key = item.key || item.id;
106
+
107
+ if (ArrUtil.contains(keyList, key)) {
108
+ itemList.push(item);
109
+ }
110
+ })
111
+
112
+ return itemList;
113
+ },
114
+ // id, pid
115
+ getSimpleList(treeNodeList) {
116
+ const buffer = [];
117
+
118
+ if (treeNodeList != null) {
119
+ treeNodeList.forEach((t) => {
120
+ buffer.push(t);
121
+ TreeUtil.getChild(t, buffer);
122
+ });
123
+ }
124
+ return buffer;
125
+ }
126
+
127
+ , getChild(treeNode, buffer) {
128
+ if (treeNode.children != null && treeNode.children.length > 0) {
129
+ treeNode.children.forEach((c) => {
130
+ buffer.push(c);
131
+ TreeUtil.getChild(c, buffer);
132
+ });
133
+ }
134
+ return buffer;
135
+ }
136
+
137
+ , getKeyList(tree, value) {
138
+ const list = TreeUtil.getSimpleList(tree);
139
+
140
+ const map = {};
141
+ list.forEach((t) => {
142
+ map[t.key || t.id] = t;
143
+ });
144
+
145
+ const t = map[value];
146
+ if (t == null) {
147
+ return [];
148
+ }
149
+
150
+ const keys = [t.key || t.id];
151
+ let parent = map[t.parentKey || t.pid];
152
+ while (parent != null) {
153
+ keys.push(parent.key || t.id);
154
+ parent = map[parent.parentKey || t.pid];
155
+ }
156
+
157
+ return keys.reverse();
158
+ },
159
+
160
+
161
+ }
162
+
163
+
164
+
165
+
166
+
167
+
168
+
169
+
170
+
171
+
172
+
173
+
174
+
175
+