@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,60 @@
1
+ import {StorageUtil, UrlUtil} from "../utils";
2
+
3
+ const SITE_INFO_KEY = "siteInfo"
4
+ const LOGIN_INFO_KEY = "loginInfo"
5
+ const DICT_INFO_KEY = "dictInfo"
6
+ export const SysUtil = {
7
+
8
+
9
+
10
+ /**
11
+ * 服务器端的地址, 以 /结尾
12
+ * @returns {string}
13
+ */
14
+ getServerUrl() {
15
+ return "/"
16
+ },
17
+
18
+ /**
19
+ * 将服务url加载最前
20
+ * @param url
21
+ * @returns {*}
22
+ */
23
+ wrapServerUrl(url) {
24
+ const serverUrl = SysUtil.getServerUrl()
25
+ return UrlUtil.join(serverUrl, url)
26
+ },
27
+
28
+
29
+ getHeaders() {
30
+ const headers = {}
31
+ return headers;
32
+ },
33
+
34
+ setSiteInfo(data) {
35
+ return StorageUtil.set(SITE_INFO_KEY, data)
36
+ },
37
+
38
+ getSiteInfo() {
39
+ return StorageUtil.get(SITE_INFO_KEY) || {}
40
+ },
41
+
42
+ setLoginInfo(data) {
43
+ return StorageUtil.set(LOGIN_INFO_KEY, data)
44
+ },
45
+
46
+ getLoginInfo() {
47
+ return StorageUtil.get(LOGIN_INFO_KEY) || {}
48
+ },
49
+
50
+
51
+ setDictInfo(data) {
52
+ return StorageUtil.set(DICT_INFO_KEY, data)
53
+ },
54
+
55
+ getDictInfo() {
56
+ return StorageUtil.get(DICT_INFO_KEY)
57
+ }
58
+ }
59
+
60
+
@@ -0,0 +1,17 @@
1
+ export const theme = {
2
+ "primary-color": "#1961AC",
3
+ "success-color": "#52c41a",
4
+ "warning-color": "#faad14",
5
+ "error-color": "#ff4d4f",
6
+ "background-color":"#f5f5f5",
7
+
8
+
9
+ "primary-color-hover":"#4990CD",
10
+ "primary-color-click":"#124B93"
11
+ }
12
+
13
+
14
+
15
+
16
+
17
+
@@ -0,0 +1,118 @@
1
+ export const ArrUtil = {
2
+
3
+ contains(arr, item) {
4
+ return arr.indexOf(item) !== -1;
5
+ },
6
+ containsAny(arr, ...items) {
7
+ for (let item of items) {
8
+ if (this.contains(item)) {
9
+ return true
10
+ }
11
+ }
12
+ return false;
13
+ },
14
+
15
+ add(arr, item) {
16
+ arr.push(item)
17
+ },
18
+
19
+ addAt(arr, index, item) {
20
+ arr.splice(index, 0, item);
21
+ },
22
+
23
+ /**
24
+ * 将一个数组追加到尾
25
+ * @param index
26
+ * @param item
27
+ */
28
+ addAll(arr, items) {
29
+ for (let i = 0; i < items.length; i++) {
30
+ arr.push(items[i])
31
+ }
32
+ },
33
+
34
+ removeAt(arr, index) {
35
+ arr.splice(index, 1)
36
+ },
37
+
38
+ remove(arr, item) {
39
+ const index = arr.indexOf(item);
40
+ if (index !== -1) {
41
+ this.removeAt(arr, index)
42
+ }
43
+ },
44
+
45
+ /**
46
+ * 清空
47
+ */
48
+ clear(arr) {
49
+ arr.length = 0
50
+ },
51
+
52
+ /**
53
+ * 截取数组
54
+ * @param fromIndex low endpoint (inclusive) of the subList toIndex
55
+ * @param toIndex high endpoint (exclusive) of the subList
56
+ */
57
+ sub(arr, fromIndex, toIndex) {
58
+ return arr.slice(fromIndex, toIndex);
59
+ },
60
+
61
+ swap(arr, item1, item2) {
62
+ const index1 = arr.indexOf(item1);
63
+ const index2 = arr.indexOf(item2);
64
+
65
+ arr[index1] = item2;
66
+ arr[index2] = item1;
67
+ },
68
+
69
+ insert(arr, index, item) {
70
+ arr.splice(index, 0, item);
71
+ },
72
+
73
+ pushIfNotExist(arr, item) {
74
+ const index = arr.indexOf(item);
75
+ if (index == -1) {
76
+ arr.push(item);
77
+ }
78
+ },
79
+
80
+ pushAll(arr, newArr) {
81
+ for (let i = 0; i < newArr.length; i++) {
82
+ arr.push(newArr[i]);
83
+ }
84
+ },
85
+
86
+ /**
87
+ * 获取对象数组中某一属性值最大的对象
88
+ * @param arr
89
+ */
90
+ maxBy(arr, key) {
91
+ if (arr == null || arr.length === 0) {
92
+ return undefined;
93
+ }
94
+
95
+ let maxElement;
96
+ let maxValue = -Infinity;
97
+
98
+ for (const element of arr) {
99
+ const value = element[key];
100
+ if (value > maxValue) {
101
+ maxValue = value;
102
+ maxElement = element;
103
+ }
104
+ }
105
+
106
+ return maxElement;
107
+ },
108
+
109
+ /**
110
+ * 数组去重
111
+ * @param arr
112
+ * @returns {any[]}
113
+ */
114
+ unique(arr) {
115
+ return [...new Set(arr)]
116
+ }
117
+
118
+ }
@@ -0,0 +1,24 @@
1
+ export function isMobileDevice() {
2
+ const userAgent = navigator.userAgent || navigator.vendor || window.opera;
3
+
4
+ // Windows Phone must come first because its UA also contains "Android"
5
+ if (/windows phone/i.test(userAgent)) {
6
+ return true;
7
+ }
8
+
9
+ // Android devices
10
+ if (/android/i.test(userAgent)) {
11
+ return true;
12
+ }
13
+
14
+ // iOS devices
15
+ if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) {
16
+ return true;
17
+ }
18
+ return false;
19
+ }
20
+
21
+ export function getWebsocketBaseUrl() {
22
+ const protocol = location.protocol === 'http:' ? 'ws:' : 'wss:'
23
+ return protocol + "//" + location.host
24
+ }
@@ -0,0 +1,269 @@
1
+ /**
2
+ * forked form https://github.com/quasarframework/quasar
3
+ */
4
+
5
+
6
+ const reRGBA = /^rgb(a)?\((\d{1,3}),(\d{1,3}),(\d{1,3}),?([01]?\.?\d*?)?\)$/
7
+
8
+ export function rgbToHex ({ r, g, b, a }) {
9
+ const alpha = a !== void 0
10
+
11
+ r = Math.round(r)
12
+ g = Math.round(g)
13
+ b = Math.round(b)
14
+
15
+ if (
16
+ r > 255
17
+ || g > 255
18
+ || b > 255
19
+ || (alpha && a > 100)
20
+ ) {
21
+ throw new TypeError('Expected 3 numbers below 256 (and optionally one below 100)')
22
+ }
23
+
24
+ a = alpha
25
+ ? (Math.round(255 * a / 100) | 1 << 8).toString(16).slice(1)
26
+ : ''
27
+
28
+ return '#' + ((b | g << 8 | r << 16) | 1 << 24).toString(16).slice(1) + a
29
+ }
30
+
31
+ export function rgbToString ({ r, g, b, a }) {
32
+ return `rgb${ a !== void 0 ? 'a' : '' }(${ r },${ g },${ b }${ a !== void 0 ? ',' + (a / 100) : '' })`
33
+ }
34
+
35
+ export function hexToRgb (hex) {
36
+ if (typeof hex !== 'string') {
37
+ throw new TypeError('Expected a string')
38
+ }
39
+
40
+ hex = hex.replace(/^#/, '')
41
+
42
+ if (hex.length === 3) {
43
+ hex = hex[ 0 ] + hex[ 0 ] + hex[ 1 ] + hex[ 1 ] + hex[ 2 ] + hex[ 2 ]
44
+ }
45
+ else if (hex.length === 4) {
46
+ hex = hex[ 0 ] + hex[ 0 ] + hex[ 1 ] + hex[ 1 ] + hex[ 2 ] + hex[ 2 ] + hex[ 3 ] + hex[ 3 ]
47
+ }
48
+
49
+ const num = parseInt(hex, 16)
50
+
51
+ return hex.length > 6
52
+ ? { r: num >> 24 & 255, g: num >> 16 & 255, b: num >> 8 & 255, a: Math.round((num & 255) / 2.55) }
53
+ : { r: num >> 16, g: num >> 8 & 255, b: num & 255 }
54
+ }
55
+
56
+ export function hsvToRgb ({ h, s, v, a }) {
57
+ let r, g, b
58
+ s = s / 100
59
+ v = v / 100
60
+
61
+ h = h / 360
62
+ const
63
+ i = Math.floor(h * 6),
64
+ f = h * 6 - i,
65
+ p = v * (1 - s),
66
+ q = v * (1 - f * s),
67
+ t = v * (1 - (1 - f) * s)
68
+
69
+ switch (i % 6) {
70
+ case 0:
71
+ r = v
72
+ g = t
73
+ b = p
74
+ break
75
+ case 1:
76
+ r = q
77
+ g = v
78
+ b = p
79
+ break
80
+ case 2:
81
+ r = p
82
+ g = v
83
+ b = t
84
+ break
85
+ case 3:
86
+ r = p
87
+ g = q
88
+ b = v
89
+ break
90
+ case 4:
91
+ r = t
92
+ g = p
93
+ b = v
94
+ break
95
+ case 5:
96
+ r = v
97
+ g = p
98
+ b = q
99
+ break
100
+ }
101
+
102
+ return {
103
+ r: Math.round(r * 255),
104
+ g: Math.round(g * 255),
105
+ b: Math.round(b * 255),
106
+ a
107
+ }
108
+ }
109
+
110
+ export function rgbToHsv ({ r, g, b, a }) {
111
+ const
112
+ max = Math.max(r, g, b),
113
+ min = Math.min(r, g, b),
114
+ d = max - min,
115
+ s = (max === 0 ? 0 : d / max),
116
+ v = max / 255
117
+ let h
118
+
119
+ switch (max) {
120
+ case min:
121
+ h = 0
122
+ break
123
+ case r:
124
+ h = (g - b) + d * (g < b ? 6 : 0)
125
+ h /= 6 * d
126
+ break
127
+ case g:
128
+ h = (b - r) + d * 2
129
+ h /= 6 * d
130
+ break
131
+ case b:
132
+ h = (r - g) + d * 4
133
+ h /= 6 * d
134
+ break
135
+ }
136
+
137
+ return {
138
+ h: Math.round(h * 360),
139
+ s: Math.round(s * 100),
140
+ v: Math.round(v * 100),
141
+ a
142
+ }
143
+ }
144
+
145
+ export function textToRgb (str) {
146
+ if (typeof str !== 'string') {
147
+ throw new TypeError('Expected a string')
148
+ }
149
+
150
+ const color = str.replace(/ /g, '')
151
+
152
+ const m = reRGBA.exec(color)
153
+
154
+ if (m === null) {
155
+ return hexToRgb(color)
156
+ }
157
+
158
+ const rgb = {
159
+ r: Math.min(255, parseInt(m[ 2 ], 10)),
160
+ g: Math.min(255, parseInt(m[ 3 ], 10)),
161
+ b: Math.min(255, parseInt(m[ 4 ], 10))
162
+ }
163
+
164
+ if (m[ 1 ]) {
165
+ const alpha = parseFloat(m[ 5 ])
166
+ rgb.a = Math.min(1, isNaN(alpha) === true ? 1 : alpha) * 100
167
+ }
168
+
169
+ return rgb
170
+ }
171
+
172
+ /* works as darken if percent < 0 */
173
+ export function lighten (color, percent) {
174
+ if (typeof color !== 'string') {
175
+ throw new TypeError('Expected a string as color')
176
+ }
177
+ if (typeof percent !== 'number') {
178
+ throw new TypeError('Expected a numeric percent')
179
+ }
180
+
181
+ const rgb = textToRgb(color),
182
+ t = percent < 0 ? 0 : 255,
183
+ p = Math.abs(percent) / 100,
184
+ R = rgb.r,
185
+ G = rgb.g,
186
+ B = rgb.b
187
+
188
+ return '#' + (
189
+ 0x1000000 + (Math.round((t - R) * p) + R) * 0x10000
190
+ + (Math.round((t - G) * p) + G) * 0x100
191
+ + (Math.round((t - B) * p) + B)
192
+ ).toString(16).slice(1)
193
+ }
194
+
195
+ export function luminosity (color) {
196
+ if (typeof color !== 'string' && (!color || color.r === void 0)) {
197
+ throw new TypeError('Expected a string or a {r, g, b} object as color')
198
+ }
199
+
200
+ const
201
+ rgb = typeof color === 'string' ? textToRgb(color) : color,
202
+ r = rgb.r / 255,
203
+ g = rgb.g / 255,
204
+ b = rgb.b / 255,
205
+ R = r <= 0.03928 ? r / 12.92 : Math.pow((r + 0.055) / 1.055, 2.4),
206
+ G = g <= 0.03928 ? g / 12.92 : Math.pow((g + 0.055) / 1.055, 2.4),
207
+ B = b <= 0.03928 ? b / 12.92 : Math.pow((b + 0.055) / 1.055, 2.4)
208
+ return 0.2126 * R + 0.7152 * G + 0.0722 * B
209
+ }
210
+
211
+ export function brightness (color) {
212
+ if (typeof color !== 'string' && (!color || color.r === void 0)) {
213
+ throw new TypeError('Expected a string or a {r, g, b} object as color')
214
+ }
215
+
216
+ const rgb = typeof color === 'string'
217
+ ? textToRgb(color)
218
+ : color
219
+
220
+ return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1000
221
+ }
222
+
223
+ export function blend (fgColor, bgColor) {
224
+ if (typeof fgColor !== 'string' && (!fgColor || fgColor.r === void 0)) {
225
+ throw new TypeError('Expected a string or a {r, g, b[, a]} object as fgColor')
226
+ }
227
+
228
+ if (typeof bgColor !== 'string' && (!bgColor || bgColor.r === void 0)) {
229
+ throw new TypeError('Expected a string or a {r, g, b[, a]} object as bgColor')
230
+ }
231
+
232
+ const
233
+ rgb1 = typeof fgColor === 'string' ? textToRgb(fgColor) : fgColor,
234
+ r1 = rgb1.r / 255,
235
+ g1 = rgb1.g / 255,
236
+ b1 = rgb1.b / 255,
237
+ a1 = rgb1.a !== void 0 ? rgb1.a / 100 : 1,
238
+ rgb2 = typeof bgColor === 'string' ? textToRgb(bgColor) : bgColor,
239
+ r2 = rgb2.r / 255,
240
+ g2 = rgb2.g / 255,
241
+ b2 = rgb2.b / 255,
242
+ a2 = rgb2.a !== void 0 ? rgb2.a / 100 : 1,
243
+ a = a1 + a2 * (1 - a1),
244
+ r = Math.round(((r1 * a1 + r2 * a2 * (1 - a1)) / a) * 255),
245
+ g = Math.round(((g1 * a1 + g2 * a2 * (1 - a1)) / a) * 255),
246
+ b = Math.round(((b1 * a1 + b2 * a2 * (1 - a1)) / a) * 255)
247
+
248
+ const ret = { r, g, b, a: Math.round(a * 100) }
249
+ return typeof fgColor === 'string'
250
+ ? rgbToHex(ret)
251
+ : ret
252
+ }
253
+
254
+ export function changeAlpha (color, offset) {
255
+ if (typeof color !== 'string') {
256
+ throw new TypeError('Expected a string as color')
257
+ }
258
+
259
+ if (offset === void 0 || offset < -1 || offset > 1) {
260
+ throw new TypeError('Expected offset to be between -1 and 1')
261
+ }
262
+
263
+ const { r, g, b, a } = textToRgb(color)
264
+ const alpha = a !== void 0 ? a / 100 : 0
265
+
266
+ return rgbToHex({
267
+ r, g, b, a: Math.round(Math.min(1, Math.max(0, alpha + offset)) * 100)
268
+ })
269
+ }
@@ -0,0 +1,173 @@
1
+ import {StrUtil} from "./str";
2
+
3
+
4
+ export const DateUtil = {
5
+
6
+ year(date) {
7
+ return date.getFullYear();
8
+ },
9
+
10
+ /**
11
+ * 获取月份, 自动补0
12
+ * @param date
13
+ * @returns {*}
14
+ */
15
+ month(date) {
16
+ const n = date.getMonth() + 1; // (注意月份从0开始,所以要加1)
17
+ return StrUtil.pad(n, 2)
18
+ },
19
+
20
+ /**
21
+ * 获取日期,
22
+ * @param date
23
+ */
24
+ date(date) {
25
+ return StrUtil.pad(date.getDate(), 2)
26
+ },
27
+
28
+ /**
29
+ * 小时, 24进制
30
+ * @param date
31
+ * @returns {string}
32
+ */
33
+ hour(date) {
34
+ return StrUtil.pad(date.getHours(), 2);
35
+ },
36
+
37
+ minute(date) {
38
+ return StrUtil.pad(date.getMinutes(), 2);
39
+ },
40
+
41
+ second(date) {
42
+ return StrUtil.pad(date.getSeconds(), 2);
43
+ },
44
+
45
+ formatDate(d) {
46
+ return this.year(d) + '-' + this.month(d) + "-" + this.date(d)
47
+ },
48
+
49
+ formatTime(d) {
50
+ return this.hour(d) + ':' + this.minute(d) + ":" + this.second(d)
51
+ },
52
+
53
+ formatDateTime(d) {
54
+ return this.formatDate(d) + " " + this.formatTime(d)
55
+ },
56
+
57
+ /**
58
+ *
59
+ * @param d
60
+ * @returns {string} 2020年1月30日
61
+ */
62
+ formatDateCn(d) {
63
+ return this.year(d) + '年' + (d.getMonth() + 1) + '月' + d.getDate() + '日'
64
+ },
65
+
66
+ /***
67
+ 当前时间, 如 2022-01-23 11:59:59
68
+ */
69
+ now() {
70
+ return this.formatDateTime(new Date());
71
+ },
72
+
73
+ /**
74
+ * 当前日期 ,如 2022-01-23
75
+ *
76
+ */
77
+ today() {
78
+ return this.formatDate(new Date());
79
+ },
80
+
81
+ thisYear() {
82
+ return this.year(new Date())
83
+ },
84
+
85
+ thisMonth() {
86
+ return this.month(new Date())
87
+ },
88
+
89
+
90
+ /**
91
+ * 显示友好时间, 如 2小时前, 1周前
92
+ * @param pastDate 日期, 支持Date, String, Number
93
+ */
94
+ friendlyTime(pastDate) {
95
+ if (pastDate == null) {
96
+ return
97
+ }
98
+ if (!(pastDate instanceof Date)) {
99
+ pastDate = new Date(pastDate)
100
+ }
101
+
102
+ const currentDate = new Date();
103
+ let elapsedMilliseconds = currentDate - pastDate;
104
+ const suffix = elapsedMilliseconds > 0 ? "前" : "后";
105
+ elapsedMilliseconds = Math.abs(elapsedMilliseconds)
106
+
107
+ // 计算年、月、日、小时、分钟和秒的差值
108
+ const elapsedYears = Math.floor(elapsedMilliseconds / (1000 * 60 * 60 * 24 * 365));
109
+ const elapsedMonths = Math.floor(elapsedMilliseconds / (1000 * 60 * 60 * 24 * 30));
110
+ const elapsedDays = Math.floor(elapsedMilliseconds / (1000 * 60 * 60 * 24));
111
+ const elapsedHours = Math.floor(elapsedMilliseconds / (1000 * 60 * 60));
112
+ const elapsedMinutes = Math.floor(elapsedMilliseconds / (1000 * 60));
113
+ const elapsedSeconds = Math.floor(elapsedMilliseconds / 1000);
114
+
115
+ // 根据差值选择友好的格式
116
+ if (elapsedYears >= 1) {
117
+ return `${elapsedYears} 年${suffix}`;
118
+ }
119
+ if (elapsedMonths >= 1) {
120
+ return `${elapsedMonths} 个月${suffix}`;
121
+ }
122
+ if (elapsedDays >= 7) {
123
+ const weeks = Math.floor(elapsedDays / 7);
124
+ return `${weeks} 周${suffix}`;
125
+ }
126
+ if (elapsedDays >= 1) {
127
+ const days = elapsedDays;
128
+ return `${days} 天${suffix}`;
129
+ }
130
+ if (elapsedHours >= 1) {
131
+ return `${elapsedHours} 小时${suffix}`;
132
+ }
133
+ if (elapsedMinutes >= 1) {
134
+ return `${elapsedMinutes} 分钟${suffix}`;
135
+ }
136
+ return `${elapsedSeconds} 秒${suffix}`;
137
+ },
138
+
139
+ /**
140
+ * 总共耗时, 如 3分5秒
141
+ * @param time 数字 (Date.getTime)
142
+ * @returns {string|null}
143
+ */
144
+ friendlyTotalTime(time) {
145
+ if (time == null || time === '-') {
146
+ return null
147
+ }
148
+ let seconds = time / 1000;
149
+
150
+ seconds = Math.floor(seconds)
151
+
152
+ if (seconds < 60) {
153
+ return seconds + '秒';
154
+ }
155
+
156
+ let min = seconds / 60;
157
+ seconds = seconds % 60;
158
+
159
+ min = Math.floor(min);
160
+ seconds = Math.floor(seconds)
161
+
162
+ return min + '分' + seconds + '秒'
163
+ },
164
+
165
+ beginOfMonth(){
166
+ const d = new Date();
167
+ d.setMonth(0)
168
+ d.setDate(1)
169
+ return this.formatDate(d)
170
+ }
171
+
172
+
173
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * 防抖
3
+ *
4
+ * forked form https://github.com/quasarframework/quasar
5
+ */
6
+ export function debounce(fn, wait = 250, immediate) {
7
+ let timer = null
8
+
9
+ function debounced(/* ...args */) {
10
+ const args = arguments
11
+
12
+ const later = () => {
13
+ timer = null
14
+ if (immediate !== true) {
15
+ fn.apply(this, args)
16
+ }
17
+ }
18
+
19
+ if (timer !== null) {
20
+ clearTimeout(timer)
21
+ } else if (immediate === true) {
22
+ fn.apply(this, args)
23
+ }
24
+
25
+ timer = setTimeout(later, wait)
26
+ }
27
+
28
+ debounced.cancel = () => {
29
+ timer !== null && clearTimeout(timer)
30
+ }
31
+
32
+ return debounced
33
+ }
@@ -0,0 +1,16 @@
1
+ export function offset (el) {
2
+ if (el === window) {
3
+ return { top: 0, left: 0 }
4
+ }
5
+ const { top, left } = el.getBoundingClientRect()
6
+ return { top, left }
7
+ }
8
+ export function height (el) {
9
+ return el === window
10
+ ? window.innerHeight
11
+ : el.getBoundingClientRect().height
12
+ }export function width (el) {
13
+ return el === window
14
+ ? window.innerWidth
15
+ : el.getBoundingClientRect().width
16
+ }