@melt-js/tpl-vue2-admin-ele 0.0.0-stage → 1.0.2

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 (115) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +68 -3
  3. package/hel_dist/entry.js +37 -0
  4. package/hel_dist/favicon.ico +0 -0
  5. package/hel_dist/hel-meta.json +127 -0
  6. package/hel_dist/hel_userChunk_1.js +1 -0
  7. package/hel_dist/index.html +1 -0
  8. package/hel_dist/static/css/chunk-017edab0.c58e968f.css +1 -0
  9. package/hel_dist/static/css/chunk-5eaa4e8c.fdc15fc9.css +1 -0
  10. package/hel_dist/static/css/chunk-67ce6001.3f0a3a92.css +1 -0
  11. package/hel_dist/static/css/chunk-6d379bf5.f23be7e7.css +1 -0
  12. package/hel_dist/static/css/chunk-718db1ae.6eddafbb.css +1 -0
  13. package/hel_dist/static/css/chunk-7ba44fd1.85e72a0e.css +1 -0
  14. package/hel_dist/static/css/chunk-de514d9e.00a6d6a6.css +1 -0
  15. package/hel_dist/static/css/chunk-elementUI.5646d24e.css +1 -0
  16. package/hel_dist/static/fonts/element-icons.535877f5.woff +0 -0
  17. package/hel_dist/static/fonts/element-icons.732389de.ttf +0 -0
  18. package/hel_dist/static/img/404.a57b6f31.png +0 -0
  19. package/hel_dist/static/img/404_cloud.0f4bc32b.png +0 -0
  20. package/hel_dist/static/img/logo.82b9c7a5.png +0 -0
  21. package/hel_dist/static/js/app.4c22465f.js +1 -0
  22. package/hel_dist/static/js/chunk-017edab0.362048d2.js +1 -0
  23. package/hel_dist/static/js/chunk-2d0c8bf7.70b29a00.js +1 -0
  24. package/hel_dist/static/js/chunk-2d0cfaef.084b1334.js +1 -0
  25. package/hel_dist/static/js/chunk-2d0d0f79.d7d27267.js +1 -0
  26. package/hel_dist/static/js/chunk-2d0e4b0c.3835385f.js +1 -0
  27. package/hel_dist/static/js/chunk-2d0e4e1f.0c68ea9c.js +1 -0
  28. package/hel_dist/static/js/chunk-2d0e944c.5d7311c9.js +1 -0
  29. package/hel_dist/static/js/chunk-2d2104c6.b1e1cf15.js +1 -0
  30. package/hel_dist/static/js/chunk-2d226cab.f4b20d3f.js +1 -0
  31. package/hel_dist/static/js/chunk-2d229205.b6def72f.js +1 -0
  32. package/hel_dist/static/js/chunk-5eaa4e8c.62e343d1.js +1 -0
  33. package/hel_dist/static/js/chunk-67ce6001.c7dec55f.js +1 -0
  34. package/hel_dist/static/js/chunk-6d379bf5.3d4baab7.js +1 -0
  35. package/hel_dist/static/js/chunk-718db1ae.a79def1c.js +1 -0
  36. package/hel_dist/static/js/chunk-7ba44fd1.b80386b8.js +33 -0
  37. package/hel_dist/static/js/chunk-de514d9e.96bc330f.js +1 -0
  38. package/hel_dist/static/js/chunk-elementUI.f4fd50f4.js +9 -0
  39. package/hel_dist/static/js/chunk-libs.8a568f76.js +17 -0
  40. package/hel_proxy/entry.js +37 -0
  41. package/hel_proxy_es/entry.js +28 -0
  42. package/package.json +95 -4
  43. package/scripts/check.js +13 -0
  44. package/scripts/meta.js +19 -0
  45. package/scripts/prepublishOnly.js +26 -0
  46. package/src/App.vue +11 -0
  47. package/src/api/table.js +9 -0
  48. package/src/api/user.js +24 -0
  49. package/src/assets/404_images/404.png +0 -0
  50. package/src/assets/404_images/404_cloud.png +0 -0
  51. package/src/components/Breadcrumb/index.vue +78 -0
  52. package/src/components/Hamburger/index.vue +44 -0
  53. package/src/components/SvgIcon/index.vue +62 -0
  54. package/src/components/index.js +2 -0
  55. package/src/configs/subApp.js +9 -0
  56. package/src/entrance/libProperties.js +10 -0
  57. package/src/entrance/libTypes.ts +24 -0
  58. package/src/icons/index.js +9 -0
  59. package/src/icons/svg/dashboard.svg +1 -0
  60. package/src/icons/svg/example.svg +1 -0
  61. package/src/icons/svg/eye-open.svg +1 -0
  62. package/src/icons/svg/eye.svg +1 -0
  63. package/src/icons/svg/form.svg +1 -0
  64. package/src/icons/svg/link.svg +1 -0
  65. package/src/icons/svg/nested.svg +1 -0
  66. package/src/icons/svg/password.svg +1 -0
  67. package/src/icons/svg/table.svg +1 -0
  68. package/src/icons/svg/tree.svg +1 -0
  69. package/src/icons/svg/user.svg +1 -0
  70. package/src/icons/svgo.config.js +9 -0
  71. package/src/layout/components/AppMain.vue +40 -0
  72. package/src/layout/components/Navbar.vue +139 -0
  73. package/src/layout/components/Sidebar/FixiOSBug.js +26 -0
  74. package/src/layout/components/Sidebar/Item.vue +41 -0
  75. package/src/layout/components/Sidebar/Link.vue +43 -0
  76. package/src/layout/components/Sidebar/Logo.vue +82 -0
  77. package/src/layout/components/Sidebar/SidebarItem.vue +95 -0
  78. package/src/layout/components/Sidebar/index.vue +56 -0
  79. package/src/layout/components/index.js +3 -0
  80. package/src/layout/index.vue +93 -0
  81. package/src/layout/mixin/ResizeHandler.js +45 -0
  82. package/src/loadApp.js +43 -0
  83. package/src/main.js +13 -0
  84. package/src/permission.js +64 -0
  85. package/src/router/index.js +181 -0
  86. package/src/settings.js +16 -0
  87. package/src/store/getters.js +8 -0
  88. package/src/store/index.js +19 -0
  89. package/src/store/modules/app.js +48 -0
  90. package/src/store/modules/settings.js +32 -0
  91. package/src/store/modules/user.js +97 -0
  92. package/src/styles/element-ui.scss +49 -0
  93. package/src/styles/index.scss +65 -0
  94. package/src/styles/mixin.scss +28 -0
  95. package/src/styles/sidebar.scss +226 -0
  96. package/src/styles/transition.scss +48 -0
  97. package/src/styles/variables.scss +25 -0
  98. package/src/utils/auth.js +15 -0
  99. package/src/utils/get-page-title.js +10 -0
  100. package/src/utils/index.js +117 -0
  101. package/src/utils/request.js +85 -0
  102. package/src/utils/validate.js +20 -0
  103. package/src/views/404.vue +228 -0
  104. package/src/views/dashboard/index.vue +37 -0
  105. package/src/views/form/index.vue +85 -0
  106. package/src/views/login/index.vue +237 -0
  107. package/src/views/nested/menu1/index.vue +7 -0
  108. package/src/views/nested/menu1/menu1-1/index.vue +7 -0
  109. package/src/views/nested/menu1/menu1-2/index.vue +7 -0
  110. package/src/views/nested/menu1/menu1-2/menu1-2-1/index.vue +5 -0
  111. package/src/views/nested/menu1/menu1-2/menu1-2-2/index.vue +5 -0
  112. package/src/views/nested/menu1/menu1-3/index.vue +5 -0
  113. package/src/views/nested/menu2/index.vue +5 -0
  114. package/src/views/table/index.vue +79 -0
  115. package/src/views/tree/index.vue +78 -0
@@ -0,0 +1,32 @@
1
+ import defaultSettings from '@/settings'
2
+
3
+ const { showSettings, fixedHeader, sidebarLogo } = defaultSettings
4
+
5
+ const state = {
6
+ showSettings: showSettings,
7
+ fixedHeader: fixedHeader,
8
+ sidebarLogo: sidebarLogo
9
+ }
10
+
11
+ const mutations = {
12
+ CHANGE_SETTING: (state, { key, value }) => {
13
+ // eslint-disable-next-line no-prototype-builtins
14
+ if (state.hasOwnProperty(key)) {
15
+ state[key] = value
16
+ }
17
+ }
18
+ }
19
+
20
+ const actions = {
21
+ changeSetting({ commit }, data) {
22
+ commit('CHANGE_SETTING', data)
23
+ }
24
+ }
25
+
26
+ export default {
27
+ namespaced: true,
28
+ state,
29
+ mutations,
30
+ actions
31
+ }
32
+
@@ -0,0 +1,97 @@
1
+ import { login, logout, getInfo } from '@/api/user'
2
+ import { getToken, setToken, removeToken } from '@/utils/auth'
3
+ import { resetRouter } from '@/router'
4
+
5
+ const getDefaultState = () => {
6
+ return {
7
+ token: getToken(),
8
+ name: '',
9
+ avatar: ''
10
+ }
11
+ }
12
+
13
+ const state = getDefaultState()
14
+
15
+ const mutations = {
16
+ RESET_STATE: (state) => {
17
+ Object.assign(state, getDefaultState())
18
+ },
19
+ SET_TOKEN: (state, token) => {
20
+ state.token = token
21
+ },
22
+ SET_NAME: (state, name) => {
23
+ state.name = name
24
+ },
25
+ SET_AVATAR: (state, avatar) => {
26
+ state.avatar = avatar
27
+ }
28
+ }
29
+
30
+ const actions = {
31
+ // user login
32
+ login({ commit }, userInfo) {
33
+ const { username, password } = userInfo
34
+ return new Promise((resolve, reject) => {
35
+ login({ username: username.trim(), password: password }).then(response => {
36
+ const { data } = response
37
+ commit('SET_TOKEN', data.token)
38
+ setToken(data.token)
39
+ resolve()
40
+ }).catch(error => {
41
+ reject(error)
42
+ })
43
+ })
44
+ },
45
+
46
+ // get user info
47
+ getInfo({ commit, state }) {
48
+ return new Promise((resolve, reject) => {
49
+ getInfo(state.token).then(response => {
50
+ const { data } = response
51
+
52
+ if (!data) {
53
+ return reject('Verification failed, please Login again.')
54
+ }
55
+
56
+ const { name, avatar } = data
57
+
58
+ commit('SET_NAME', name)
59
+ commit('SET_AVATAR', avatar)
60
+ resolve(data)
61
+ }).catch(error => {
62
+ reject(error)
63
+ })
64
+ })
65
+ },
66
+
67
+ // user logout
68
+ logout({ commit, state }) {
69
+ return new Promise((resolve, reject) => {
70
+ logout(state.token).then(() => {
71
+ removeToken() // must remove token first
72
+ resetRouter()
73
+ commit('RESET_STATE')
74
+ resolve()
75
+ }).catch(error => {
76
+ reject(error)
77
+ })
78
+ })
79
+ },
80
+
81
+ // remove token
82
+ resetToken({ commit }) {
83
+ return new Promise(resolve => {
84
+ removeToken() // must remove token first
85
+ commit('RESET_STATE')
86
+ resolve()
87
+ })
88
+ }
89
+ }
90
+
91
+ export default {
92
+ namespaced: true,
93
+ state,
94
+ mutations,
95
+ actions
96
+ }
97
+
@@ -0,0 +1,49 @@
1
+ // cover some element-ui styles
2
+
3
+ .el-breadcrumb__inner,
4
+ .el-breadcrumb__inner a {
5
+ font-weight: 400 !important;
6
+ }
7
+
8
+ .el-upload {
9
+ input[type="file"] {
10
+ display: none !important;
11
+ }
12
+ }
13
+
14
+ .el-upload__input {
15
+ display: none;
16
+ }
17
+
18
+
19
+ // to fixed https://github.com/ElemeFE/element/issues/2461
20
+ .el-dialog {
21
+ transform: none;
22
+ left: 0;
23
+ position: relative;
24
+ margin: 0 auto;
25
+ }
26
+
27
+ // refine element ui upload
28
+ .upload-container {
29
+ .el-upload {
30
+ width: 100%;
31
+
32
+ .el-upload-dragger {
33
+ width: 100%;
34
+ height: 200px;
35
+ }
36
+ }
37
+ }
38
+
39
+ // dropdown
40
+ .el-dropdown-menu {
41
+ a {
42
+ display: block
43
+ }
44
+ }
45
+
46
+ // to fix el-date-picker css style
47
+ .el-range-separator {
48
+ box-sizing: content-box;
49
+ }
@@ -0,0 +1,65 @@
1
+ @import './variables.scss';
2
+ @import './mixin.scss';
3
+ @import './transition.scss';
4
+ @import './element-ui.scss';
5
+ @import './sidebar.scss';
6
+
7
+ body {
8
+ height: 100%;
9
+ -moz-osx-font-smoothing: grayscale;
10
+ -webkit-font-smoothing: antialiased;
11
+ text-rendering: optimizeLegibility;
12
+ font-family: Helvetica Neue, Helvetica, PingFang SC, Hiragino Sans GB, Microsoft YaHei, Arial, sans-serif;
13
+ }
14
+
15
+ label {
16
+ font-weight: 700;
17
+ }
18
+
19
+ html {
20
+ height: 100%;
21
+ box-sizing: border-box;
22
+ }
23
+
24
+ #app {
25
+ height: 100%;
26
+ }
27
+
28
+ *,
29
+ *:before,
30
+ *:after {
31
+ box-sizing: inherit;
32
+ }
33
+
34
+ a:focus,
35
+ a:active {
36
+ outline: none;
37
+ }
38
+
39
+ a,
40
+ a:focus,
41
+ a:hover {
42
+ cursor: pointer;
43
+ color: inherit;
44
+ text-decoration: none;
45
+ }
46
+
47
+ div:focus {
48
+ outline: none;
49
+ }
50
+
51
+ .clearfix {
52
+ &:after {
53
+ visibility: hidden;
54
+ display: block;
55
+ font-size: 0;
56
+ content: " ";
57
+ clear: both;
58
+ height: 0;
59
+ }
60
+ }
61
+
62
+ // main-container global css
63
+ .app-container {
64
+ padding: 20px;
65
+ }
@@ -0,0 +1,28 @@
1
+ @mixin clearfix {
2
+ &:after {
3
+ content: "";
4
+ display: table;
5
+ clear: both;
6
+ }
7
+ }
8
+
9
+ @mixin scrollBar {
10
+ &::-webkit-scrollbar-track-piece {
11
+ background: #d3dce6;
12
+ }
13
+
14
+ &::-webkit-scrollbar {
15
+ width: 6px;
16
+ }
17
+
18
+ &::-webkit-scrollbar-thumb {
19
+ background: #99a9bf;
20
+ border-radius: 20px;
21
+ }
22
+ }
23
+
24
+ @mixin relative {
25
+ position: relative;
26
+ width: 100%;
27
+ height: 100%;
28
+ }
@@ -0,0 +1,226 @@
1
+ #app {
2
+
3
+ .main-container {
4
+ min-height: 100%;
5
+ transition: margin-left .28s;
6
+ margin-left: $sideBarWidth;
7
+ position: relative;
8
+ }
9
+
10
+ .sidebar-container {
11
+ transition: width 0.28s;
12
+ width: $sideBarWidth !important;
13
+ background-color: $menuBg;
14
+ height: 100%;
15
+ position: fixed;
16
+ font-size: 0px;
17
+ top: 0;
18
+ bottom: 0;
19
+ left: 0;
20
+ z-index: 1001;
21
+ overflow: hidden;
22
+
23
+ // reset element-ui css
24
+ .horizontal-collapse-transition {
25
+ transition: 0s width ease-in-out, 0s padding-left ease-in-out, 0s padding-right ease-in-out;
26
+ }
27
+
28
+ .scrollbar-wrapper {
29
+ overflow-x: hidden !important;
30
+ }
31
+
32
+ .el-scrollbar__bar.is-vertical {
33
+ right: 0px;
34
+ }
35
+
36
+ .el-scrollbar {
37
+ height: 100%;
38
+ }
39
+
40
+ &.has-logo {
41
+ .el-scrollbar {
42
+ height: calc(100% - 50px);
43
+ }
44
+ }
45
+
46
+ .is-horizontal {
47
+ display: none;
48
+ }
49
+
50
+ a {
51
+ display: inline-block;
52
+ width: 100%;
53
+ overflow: hidden;
54
+ }
55
+
56
+ .svg-icon {
57
+ margin-right: 16px;
58
+ }
59
+
60
+ .sub-el-icon {
61
+ margin-right: 12px;
62
+ margin-left: -2px;
63
+ }
64
+
65
+ .el-menu {
66
+ border: none;
67
+ height: 100%;
68
+ width: 100% !important;
69
+ }
70
+
71
+ // menu hover
72
+ .submenu-title-noDropdown,
73
+ .el-submenu__title {
74
+ &:hover {
75
+ background-color: $menuHover !important;
76
+ }
77
+ }
78
+
79
+ .is-active>.el-submenu__title {
80
+ color: $subMenuActiveText !important;
81
+ }
82
+
83
+ & .nest-menu .el-submenu>.el-submenu__title,
84
+ & .el-submenu .el-menu-item {
85
+ min-width: $sideBarWidth !important;
86
+ background-color: $subMenuBg !important;
87
+
88
+ &:hover {
89
+ background-color: $subMenuHover !important;
90
+ }
91
+ }
92
+ }
93
+
94
+ .hideSidebar {
95
+ .sidebar-container {
96
+ width: 54px !important;
97
+ }
98
+
99
+ .main-container {
100
+ margin-left: 54px;
101
+ }
102
+
103
+ .submenu-title-noDropdown {
104
+ padding: 0 !important;
105
+ position: relative;
106
+
107
+ .el-tooltip {
108
+ padding: 0 !important;
109
+
110
+ .svg-icon {
111
+ margin-left: 20px;
112
+ }
113
+
114
+ .sub-el-icon {
115
+ margin-left: 19px;
116
+ }
117
+ }
118
+ }
119
+
120
+ .el-submenu {
121
+ overflow: hidden;
122
+
123
+ &>.el-submenu__title {
124
+ padding: 0 !important;
125
+
126
+ .svg-icon {
127
+ margin-left: 20px;
128
+ }
129
+
130
+ .sub-el-icon {
131
+ margin-left: 19px;
132
+ }
133
+
134
+ .el-submenu__icon-arrow {
135
+ display: none;
136
+ }
137
+ }
138
+ }
139
+
140
+ .el-menu--collapse {
141
+ .el-submenu {
142
+ &>.el-submenu__title {
143
+ &>span {
144
+ height: 0;
145
+ width: 0;
146
+ overflow: hidden;
147
+ visibility: hidden;
148
+ display: inline-block;
149
+ }
150
+ }
151
+ }
152
+ }
153
+ }
154
+
155
+ .el-menu--collapse .el-menu .el-submenu {
156
+ min-width: $sideBarWidth !important;
157
+ }
158
+
159
+ // mobile responsive
160
+ .mobile {
161
+ .main-container {
162
+ margin-left: 0px;
163
+ }
164
+
165
+ .sidebar-container {
166
+ transition: transform .28s;
167
+ width: $sideBarWidth !important;
168
+ }
169
+
170
+ &.hideSidebar {
171
+ .sidebar-container {
172
+ pointer-events: none;
173
+ transition-duration: 0.3s;
174
+ transform: translate3d(-$sideBarWidth, 0, 0);
175
+ }
176
+ }
177
+ }
178
+
179
+ .withoutAnimation {
180
+
181
+ .main-container,
182
+ .sidebar-container {
183
+ transition: none;
184
+ }
185
+ }
186
+ }
187
+
188
+ // when menu collapsed
189
+ .el-menu--vertical {
190
+ &>.el-menu {
191
+ .svg-icon {
192
+ margin-right: 16px;
193
+ }
194
+ .sub-el-icon {
195
+ margin-right: 12px;
196
+ margin-left: -2px;
197
+ }
198
+ }
199
+
200
+ .nest-menu .el-submenu>.el-submenu__title,
201
+ .el-menu-item {
202
+ &:hover {
203
+ // you can use $subMenuHover
204
+ background-color: $menuHover !important;
205
+ }
206
+ }
207
+
208
+ // the scroll bar appears when the subMenu is too long
209
+ >.el-menu--popup {
210
+ max-height: 100vh;
211
+ overflow-y: auto;
212
+
213
+ &::-webkit-scrollbar-track-piece {
214
+ background: #d3dce6;
215
+ }
216
+
217
+ &::-webkit-scrollbar {
218
+ width: 6px;
219
+ }
220
+
221
+ &::-webkit-scrollbar-thumb {
222
+ background: #99a9bf;
223
+ border-radius: 20px;
224
+ }
225
+ }
226
+ }
@@ -0,0 +1,48 @@
1
+ // global transition css
2
+
3
+ /* fade */
4
+ .fade-enter-active,
5
+ .fade-leave-active {
6
+ transition: opacity 0.28s;
7
+ }
8
+
9
+ .fade-enter,
10
+ .fade-leave-active {
11
+ opacity: 0;
12
+ }
13
+
14
+ /* fade-transform */
15
+ .fade-transform-leave-active,
16
+ .fade-transform-enter-active {
17
+ transition: all .5s;
18
+ }
19
+
20
+ .fade-transform-enter {
21
+ opacity: 0;
22
+ transform: translateX(-30px);
23
+ }
24
+
25
+ .fade-transform-leave-to {
26
+ opacity: 0;
27
+ transform: translateX(30px);
28
+ }
29
+
30
+ /* breadcrumb transition */
31
+ .breadcrumb-enter-active,
32
+ .breadcrumb-leave-active {
33
+ transition: all .5s;
34
+ }
35
+
36
+ .breadcrumb-enter,
37
+ .breadcrumb-leave-active {
38
+ opacity: 0;
39
+ transform: translateX(20px);
40
+ }
41
+
42
+ .breadcrumb-move {
43
+ transition: all .5s;
44
+ }
45
+
46
+ .breadcrumb-leave-active {
47
+ position: absolute;
48
+ }
@@ -0,0 +1,25 @@
1
+ // sidebar
2
+ $menuText:#bfcbd9;
3
+ $menuActiveText:#409EFF;
4
+ $subMenuActiveText:#f4f4f5; //https://github.com/ElemeFE/element/issues/12951
5
+
6
+ $menuBg:#304156;
7
+ $menuHover:#263445;
8
+
9
+ $subMenuBg:#1f2d3d;
10
+ $subMenuHover:#001528;
11
+
12
+ $sideBarWidth: 210px;
13
+
14
+ // the :export directive is the magic sauce for webpack
15
+ // https://www.bluematador.com/blog/how-to-share-variables-between-js-and-sass
16
+ :export {
17
+ menuText: $menuText;
18
+ menuActiveText: $menuActiveText;
19
+ subMenuActiveText: $subMenuActiveText;
20
+ menuBg: $menuBg;
21
+ menuHover: $menuHover;
22
+ subMenuBg: $subMenuBg;
23
+ subMenuHover: $subMenuHover;
24
+ sideBarWidth: $sideBarWidth;
25
+ }
@@ -0,0 +1,15 @@
1
+ import Cookies from 'js-cookie'
2
+
3
+ const TokenKey = 'vue_admin_template_token'
4
+
5
+ export function getToken() {
6
+ return Cookies.get(TokenKey)
7
+ }
8
+
9
+ export function setToken(token) {
10
+ return Cookies.set(TokenKey, token)
11
+ }
12
+
13
+ export function removeToken() {
14
+ return Cookies.remove(TokenKey)
15
+ }
@@ -0,0 +1,10 @@
1
+ import defaultSettings from '@/settings'
2
+
3
+ const title = defaultSettings.title || 'Vue Admin Template'
4
+
5
+ export default function getPageTitle(pageTitle) {
6
+ if (pageTitle) {
7
+ return `${pageTitle} - ${title}`
8
+ }
9
+ return `${title}`
10
+ }
@@ -0,0 +1,117 @@
1
+ /**
2
+ * Created by PanJiaChen on 16/11/18.
3
+ */
4
+
5
+ /**
6
+ * Parse the time to string
7
+ * @param {(Object|string|number)} time
8
+ * @param {string} cFormat
9
+ * @returns {string | null}
10
+ */
11
+ export function parseTime(time, cFormat) {
12
+ if (arguments.length === 0 || !time) {
13
+ return null
14
+ }
15
+ const format = cFormat || '{y}-{m}-{d} {h}:{i}:{s}'
16
+ let date
17
+ if (typeof time === 'object') {
18
+ date = time
19
+ } else {
20
+ if ((typeof time === 'string')) {
21
+ if ((/^[0-9]+$/.test(time))) {
22
+ // support "1548221490638"
23
+ time = parseInt(time)
24
+ } else {
25
+ // support safari
26
+ // https://stackoverflow.com/questions/4310953/invalid-date-in-safari
27
+ time = time.replace(new RegExp(/-/gm), '/')
28
+ }
29
+ }
30
+
31
+ if ((typeof time === 'number') && (time.toString().length === 10)) {
32
+ time = time * 1000
33
+ }
34
+ date = new Date(time)
35
+ }
36
+ const formatObj = {
37
+ y: date.getFullYear(),
38
+ m: date.getMonth() + 1,
39
+ d: date.getDate(),
40
+ h: date.getHours(),
41
+ i: date.getMinutes(),
42
+ s: date.getSeconds(),
43
+ a: date.getDay()
44
+ }
45
+ const time_str = format.replace(/{([ymdhisa])+}/g, (result, key) => {
46
+ const value = formatObj[key]
47
+ // Note: getDay() returns 0 on Sunday
48
+ if (key === 'a') { return ['日', '一', '二', '三', '四', '五', '六'][value ] }
49
+ return value.toString().padStart(2, '0')
50
+ })
51
+ return time_str
52
+ }
53
+
54
+ /**
55
+ * @param {number} time
56
+ * @param {string} option
57
+ * @returns {string}
58
+ */
59
+ export function formatTime(time, option) {
60
+ if (('' + time).length === 10) {
61
+ time = parseInt(time) * 1000
62
+ } else {
63
+ time = +time
64
+ }
65
+ const d = new Date(time)
66
+ const now = Date.now()
67
+
68
+ const diff = (now - d) / 1000
69
+
70
+ if (diff < 30) {
71
+ return '刚刚'
72
+ } else if (diff < 3600) {
73
+ // less 1 hour
74
+ return Math.ceil(diff / 60) + '分钟前'
75
+ } else if (diff < 3600 * 24) {
76
+ return Math.ceil(diff / 3600) + '小时前'
77
+ } else if (diff < 3600 * 24 * 2) {
78
+ return '1天前'
79
+ }
80
+ if (option) {
81
+ return parseTime(time, option)
82
+ } else {
83
+ return (
84
+ d.getMonth() +
85
+ 1 +
86
+ '月' +
87
+ d.getDate() +
88
+ '日' +
89
+ d.getHours() +
90
+ '时' +
91
+ d.getMinutes() +
92
+ '分'
93
+ )
94
+ }
95
+ }
96
+
97
+ /**
98
+ * @param {string} url
99
+ * @returns {Object}
100
+ */
101
+ export function param2Obj(url) {
102
+ const search = decodeURIComponent(url.split('?')[1]).replace(/\+/g, ' ')
103
+ if (!search) {
104
+ return {}
105
+ }
106
+ const obj = {}
107
+ const searchArr = search.split('&')
108
+ searchArr.forEach(v => {
109
+ const index = v.indexOf('=')
110
+ if (index !== -1) {
111
+ const name = v.substring(0, index)
112
+ const val = v.substring(index + 1, v.length)
113
+ obj[name] = val
114
+ }
115
+ })
116
+ return obj
117
+ }