@netang/quasar 0.0.102 → 0.0.103
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +11 -11
- package/_docs/docs/.vuepress/client.js +8 -8
- package/_docs/docs/.vuepress/config.js +40 -40
- package/_docs/docs/.vuepress/configs/index.js +2 -2
- package/_docs/docs/.vuepress/configs/navbar/index.js +1 -1
- package/_docs/docs/.vuepress/configs/navbar/zh.js +16 -16
- package/_docs/docs/.vuepress/configs/sidebar/index.js +1 -1
- package/_docs/docs/.vuepress/configs/sidebar/zh.js +75 -75
- package/_docs/docs/.vuepress/public/css/index.css +3 -3
- package/_docs/docs/.vuepress/styles/index.scss +3 -3
- package/_docs/docs/components/column-title.md +25 -25
- package/_docs/docs/components/data.md +66 -66
- package/_docs/docs/components/dialog.md +59 -59
- package/_docs/docs/components/dragger.md +26 -26
- package/_docs/docs/components/editor-code.md +16 -16
- package/_docs/docs/components/empty.md +13 -13
- package/_docs/docs/components/field-date.md +16 -16
- package/_docs/docs/components/field-text.md +57 -57
- package/_docs/docs/components/field-tree.md +14 -14
- package/_docs/docs/components/img.md +25 -25
- package/_docs/docs/components/input-number.md +21 -21
- package/_docs/docs/components/list-menu-item.md +21 -21
- package/_docs/docs/components/list-menu.md +21 -21
- package/_docs/docs/components/power-page.md +21 -21
- package/_docs/docs/components/price.md +21 -21
- package/_docs/docs/components/render.md +12 -12
- package/_docs/docs/components/search-item.md +10 -10
- package/_docs/docs/components/search.md +12 -12
- package/_docs/docs/components/select.md +11 -11
- package/_docs/docs/components/splitter.md +15 -15
- package/_docs/docs/components/table-column-fixed.md +20 -20
- package/_docs/docs/components/table-pagination.md +20 -20
- package/_docs/docs/components/table-splitter.md +20 -20
- package/_docs/docs/components/table-summary.md +20 -20
- package/_docs/docs/components/table.md +25 -25
- package/_docs/docs/components/thumbnail.md +18 -18
- package/_docs/docs/components/toolbar.md +9 -9
- package/_docs/docs/components/uploader-query.md +19 -19
- package/_docs/docs/components/uploader.md +16 -16
- package/_docs/docs/components/value-format.md +26 -26
- package/_docs/docs/index.md +1 -1
- package/_docs/docs/utils/alert.md +26 -26
- package/_docs/docs/utils/area.md +112 -112
- package/_docs/docs/utils/arr.md +80 -80
- package/_docs/docs/utils/auth.md +101 -101
- package/_docs/docs/utils/bus.md +18 -18
- package/_docs/docs/utils/confirm.md +31 -31
- package/_docs/docs/utils/copy.md +22 -22
- package/_docs/docs/utils/dialog.md +98 -98
- package/_docs/docs/utils/dict.md +50 -50
- package/_docs/docs/utils/dictOptions.md +27 -27
- package/_docs/docs/utils/form.md +33 -33
- package/_docs/docs/utils/getData.md +60 -60
- package/_docs/docs/utils/getFile.md +21 -21
- package/_docs/docs/utils/getImage.md +33 -33
- package/_docs/docs/utils/getTime.md +51 -51
- package/_docs/docs/utils/index.md +1 -1
- package/_docs/docs/utils/loading.md +18 -18
- package/_docs/docs/utils/notify.md +29 -29
- package/_docs/docs/utils/power.md +353 -353
- package/_docs/docs/utils/previewImage.md +11 -11
- package/_docs/docs/utils/price.md +45 -45
- package/_docs/docs/utils/rule.md +30 -30
- package/_docs/docs/utils/ruleValid.md +31 -31
- package/_docs/docs/utils/symbols.md +30 -30
- package/_docs/docs/utils/table.md +194 -194
- package/_docs/docs/utils/timestamp.md +27 -27
- package/_docs/docs/utils/toast.md +27 -27
- package/_docs/docs/utils/tree.md +174 -174
- package/_docs/docs/utils/uploader.md +29 -29
- package/_docs/package.json +11 -11
- package/components/column-title/index.vue +37 -37
- package/components/data/index.vue +20 -20
- package/components/dialog/index.vue +372 -372
- package/components/dragger/index.vue +203 -203
- package/components/drawer/index.vue +303 -303
- package/components/editor-code/index.vue +289 -289
- package/components/empty/index.vue +71 -71
- package/components/field-date/index.vue +850 -850
- package/components/field-date/methods.js +100 -100
- package/components/field-table/index.vue +1222 -1222
- package/components/field-text/index.vue +165 -165
- package/components/field-tree/index.vue +103 -81
- package/components/img/index.vue +202 -202
- package/components/input-number/index.vue +546 -546
- package/components/list-menu/index.vue +149 -149
- package/components/list-menu-item/index.vue +79 -79
- package/components/power-page/index.vue +92 -92
- package/components/price/index.vue +188 -188
- package/components/private/components/index.js +11 -11
- package/components/private/components/move-to-tree/index.vue +154 -154
- package/components/private/edit-power-data/index.vue +816 -816
- package/components/private/table-visible-columns-button/index.vue +109 -109
- package/components/render/index.vue +150 -150
- package/components/search/index.vue +222 -222
- package/components/search-item/index.vue +210 -210
- package/components/splitter/index.vue +415 -415
- package/components/table/index.vue +456 -456
- package/components/table-column-fixed/index.vue +112 -112
- package/components/table-pagination/index.vue +192 -192
- package/components/table-splitter/index.vue +360 -360
- package/components/table-summary/index.vue +110 -110
- package/components/thumbnail/index.vue +72 -72
- package/components/toolbar/container.vue +31 -31
- package/components/toolbar/index.vue +136 -136
- package/components/uploader/index.vue +158 -158
- package/components/uploader-query/index.vue +758 -758
- package/components/value-format/index.vue +274 -274
- package/configs/area3.js +1 -1
- package/docs/css/index.css +3 -3
- package/package.json +1 -1
- package/sass/common.scss +174 -174
- package/sass/index.scss +14 -14
- package/sass/line.scss +39 -39
- package/sass/quasar/btn.scss +46 -46
- package/sass/quasar/common.scss +3 -3
- package/sass/quasar/dialog.scss +7 -7
- package/sass/quasar/drawer.scss +6 -6
- package/sass/quasar/field.scss +243 -243
- package/sass/quasar/loading.scss +6 -6
- package/sass/quasar/menu.scss +8 -8
- package/sass/quasar/table.scss +150 -150
- package/sass/quasar/toolbar.scss +22 -22
- package/store/index.js +29 -29
- package/utils/$auth.js +127 -127
- package/utils/$form.js +56 -56
- package/utils/$power.js +1215 -1215
- package/utils/$rule.js +13 -13
- package/utils/$ruleValid.js +10 -10
- package/utils/$table.js +999 -999
- package/utils/$tree.js +713 -713
- package/utils/alert.js +12 -12
- package/utils/area.js +400 -400
- package/utils/arr.js +51 -51
- package/utils/bus.js +6 -6
- package/utils/config.js +52 -52
- package/utils/confirm.js +11 -11
- package/utils/copy.js +30 -30
- package/utils/dialog.js +36 -36
- package/utils/dict.js +21 -21
- package/utils/dictOptions.js +28 -28
- package/utils/getData.js +73 -73
- package/utils/getFile.js +40 -40
- package/utils/getImage.js +153 -153
- package/utils/getTime.js +106 -106
- package/utils/index.js +61 -61
- package/utils/loading.js +15 -15
- package/utils/notify.js +13 -13
- package/utils/previewImage.js +10 -10
- package/utils/price.js +18 -18
- package/utils/symbols.js +18 -18
- package/utils/timestamp.js +18 -18
- package/utils/toast.js +13 -13
- package/utils/uploader/aliyun.js +6 -6
- package/utils/uploader/local.js +8 -8
- package/utils/uploader/qiniu.js +321 -321
- package/utils/uploader.js +1059 -1059
- package/utils/useAuth.js +30 -30
- package/utils/useRouter.js +47 -47
- package/utils/useSearch.js +0 -6
- package/utils/useUploader.js +53 -53
package/utils/getFile.js
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
import $n_isValidArray from '@netang/utils/isValidArray'
|
|
2
|
-
import $n_isValidString from '@netang/utils/isValidString'
|
|
3
|
-
import $n_slash from '@netang/utils/slash'
|
|
4
|
-
|
|
5
|
-
import $n_config from './config'
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* 获取文件
|
|
9
|
-
*/
|
|
10
|
-
export default function getFile(src) {
|
|
11
|
-
|
|
12
|
-
if (src) {
|
|
13
|
-
|
|
14
|
-
// 如果为数组, 则获取第一个
|
|
15
|
-
if ($n_isValidArray(src)) {
|
|
16
|
-
src = src[0]
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
if ($n_isValidString(src)) {
|
|
20
|
-
|
|
21
|
-
// http(s):// 或 data: 或 blob: 开头的地址
|
|
22
|
-
if (/^(http(s)?:\/\/|data:|blob:)/i.test(src)) {
|
|
23
|
-
return src
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const {
|
|
27
|
-
type,
|
|
28
|
-
domain,
|
|
29
|
-
} = $n_config('uploader.upload')
|
|
30
|
-
|
|
31
|
-
switch (type) {
|
|
32
|
-
// 七牛云
|
|
33
|
-
case 'qiniu':
|
|
34
|
-
return $n_slash(domain, 'end', true) + src
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return ''
|
|
40
|
-
}
|
|
1
|
+
import $n_isValidArray from '@netang/utils/isValidArray'
|
|
2
|
+
import $n_isValidString from '@netang/utils/isValidString'
|
|
3
|
+
import $n_slash from '@netang/utils/slash'
|
|
4
|
+
|
|
5
|
+
import $n_config from './config'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 获取文件
|
|
9
|
+
*/
|
|
10
|
+
export default function getFile(src) {
|
|
11
|
+
|
|
12
|
+
if (src) {
|
|
13
|
+
|
|
14
|
+
// 如果为数组, 则获取第一个
|
|
15
|
+
if ($n_isValidArray(src)) {
|
|
16
|
+
src = src[0]
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if ($n_isValidString(src)) {
|
|
20
|
+
|
|
21
|
+
// http(s):// 或 data: 或 blob: 开头的地址
|
|
22
|
+
if (/^(http(s)?:\/\/|data:|blob:)/i.test(src)) {
|
|
23
|
+
return src
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const {
|
|
27
|
+
type,
|
|
28
|
+
domain,
|
|
29
|
+
} = $n_config('uploader.upload')
|
|
30
|
+
|
|
31
|
+
switch (type) {
|
|
32
|
+
// 七牛云
|
|
33
|
+
case 'qiniu':
|
|
34
|
+
return $n_slash(domain, 'end', true) + src
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return ''
|
|
40
|
+
}
|
package/utils/getImage.js
CHANGED
|
@@ -1,153 +1,153 @@
|
|
|
1
|
-
import $n_has from 'lodash/has'
|
|
2
|
-
import $n_isString from 'lodash/isString'
|
|
3
|
-
|
|
4
|
-
import $n_isValidArray from '@netang/utils/isValidArray'
|
|
5
|
-
import $n_isValidObject from '@netang/utils/isValidObject'
|
|
6
|
-
import $n_isValidString from '@netang/utils/isValidString'
|
|
7
|
-
import $n_isNumeric from '@netang/utils/isNumeric'
|
|
8
|
-
import $n_slash from '@netang/utils/slash'
|
|
9
|
-
|
|
10
|
-
import $n_config from './config'
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* 获取图片
|
|
14
|
-
*/
|
|
15
|
-
export default function getImage(src, options) {
|
|
16
|
-
|
|
17
|
-
if (src) {
|
|
18
|
-
|
|
19
|
-
// 如果为数组, 则获取第一个
|
|
20
|
-
if ($n_isValidArray(src)) {
|
|
21
|
-
src = src[0]
|
|
22
|
-
|
|
23
|
-
// 如果为对象
|
|
24
|
-
} else if ($n_isValidObject(src)) {
|
|
25
|
-
|
|
26
|
-
if ($n_has(src, 'options')) {
|
|
27
|
-
options = src.options
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if ($n_has(src, 'img')) {
|
|
31
|
-
src = src.img
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if ($n_isValidString(src)) {
|
|
36
|
-
|
|
37
|
-
// http(s):// 或 data: 或 blob: 开头的地址
|
|
38
|
-
if (/^(http(s)?:\/\/|data:|blob:)/i.test(src)) {
|
|
39
|
-
return src
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// 如果为对象定义的规格
|
|
43
|
-
if ($n_isValidObject(options)) {
|
|
44
|
-
|
|
45
|
-
// 是否自动缩放
|
|
46
|
-
// --------------------------------------------------
|
|
47
|
-
// 如果有定义 w
|
|
48
|
-
if ($n_has(options, 'w')) {
|
|
49
|
-
|
|
50
|
-
let {
|
|
51
|
-
w,
|
|
52
|
-
maxWidth,
|
|
53
|
-
zoom,
|
|
54
|
-
} = options
|
|
55
|
-
|
|
56
|
-
// 先设为 0
|
|
57
|
-
options.w = 0
|
|
58
|
-
|
|
59
|
-
// 如果开启缩放 && 有宽度
|
|
60
|
-
if (zoom && w) {
|
|
61
|
-
|
|
62
|
-
if (! $n_isNumeric(w) && $n_isString(w)) {
|
|
63
|
-
w = w.replace('px', '')
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if ($n_isNumeric(w)) {
|
|
67
|
-
w = Number(w)
|
|
68
|
-
if (w > 0) {
|
|
69
|
-
|
|
70
|
-
// 获取设备像素比
|
|
71
|
-
/* #if IS_WEB */
|
|
72
|
-
const devicePixelRatio = window.devicePixelRatio || 1
|
|
73
|
-
if (devicePixelRatio > 2) {
|
|
74
|
-
w *= 2
|
|
75
|
-
}
|
|
76
|
-
/* #endif */
|
|
77
|
-
|
|
78
|
-
if (w > 10) {
|
|
79
|
-
w = Math.floor(w / 10) * 10
|
|
80
|
-
} else {
|
|
81
|
-
w = Math.floor(w)
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// 如果有最大宽度
|
|
85
|
-
if (maxWidth && maxWidth > w) {
|
|
86
|
-
w = maxWidth
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
options.w = w
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
// --------------------------------------------------
|
|
95
|
-
|
|
96
|
-
const {
|
|
97
|
-
type,
|
|
98
|
-
domain,
|
|
99
|
-
} = $n_config('uploader.upload')
|
|
100
|
-
|
|
101
|
-
// 判断图片上传方式
|
|
102
|
-
switch (type) {
|
|
103
|
-
|
|
104
|
-
// 七牛云
|
|
105
|
-
case 'qiniu':
|
|
106
|
-
|
|
107
|
-
const {
|
|
108
|
-
w,
|
|
109
|
-
h,
|
|
110
|
-
q,
|
|
111
|
-
format,
|
|
112
|
-
} = Object.assign({
|
|
113
|
-
// 宽
|
|
114
|
-
w: 0,
|
|
115
|
-
// 高
|
|
116
|
-
h: 0,
|
|
117
|
-
// 质量
|
|
118
|
-
q: 75,
|
|
119
|
-
// 格式
|
|
120
|
-
format: 'webp',
|
|
121
|
-
}, options)
|
|
122
|
-
|
|
123
|
-
// 裁剪图片方式
|
|
124
|
-
src += '?imageView2/2'
|
|
125
|
-
|
|
126
|
-
// 质量
|
|
127
|
-
if (q) {
|
|
128
|
-
src += '/q/' + q
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// 宽
|
|
132
|
-
if (w) {
|
|
133
|
-
src += '/w/' + w
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// 高
|
|
137
|
-
if (h) {
|
|
138
|
-
src += '/h/' + h
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// 格式
|
|
142
|
-
if (format) {
|
|
143
|
-
src += '/format/' + format
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
return $n_slash(domain, 'end', true) + src
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
return ''
|
|
153
|
-
}
|
|
1
|
+
import $n_has from 'lodash/has'
|
|
2
|
+
import $n_isString from 'lodash/isString'
|
|
3
|
+
|
|
4
|
+
import $n_isValidArray from '@netang/utils/isValidArray'
|
|
5
|
+
import $n_isValidObject from '@netang/utils/isValidObject'
|
|
6
|
+
import $n_isValidString from '@netang/utils/isValidString'
|
|
7
|
+
import $n_isNumeric from '@netang/utils/isNumeric'
|
|
8
|
+
import $n_slash from '@netang/utils/slash'
|
|
9
|
+
|
|
10
|
+
import $n_config from './config'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 获取图片
|
|
14
|
+
*/
|
|
15
|
+
export default function getImage(src, options) {
|
|
16
|
+
|
|
17
|
+
if (src) {
|
|
18
|
+
|
|
19
|
+
// 如果为数组, 则获取第一个
|
|
20
|
+
if ($n_isValidArray(src)) {
|
|
21
|
+
src = src[0]
|
|
22
|
+
|
|
23
|
+
// 如果为对象
|
|
24
|
+
} else if ($n_isValidObject(src)) {
|
|
25
|
+
|
|
26
|
+
if ($n_has(src, 'options')) {
|
|
27
|
+
options = src.options
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if ($n_has(src, 'img')) {
|
|
31
|
+
src = src.img
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if ($n_isValidString(src)) {
|
|
36
|
+
|
|
37
|
+
// http(s):// 或 data: 或 blob: 开头的地址
|
|
38
|
+
if (/^(http(s)?:\/\/|data:|blob:)/i.test(src)) {
|
|
39
|
+
return src
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// 如果为对象定义的规格
|
|
43
|
+
if ($n_isValidObject(options)) {
|
|
44
|
+
|
|
45
|
+
// 是否自动缩放
|
|
46
|
+
// --------------------------------------------------
|
|
47
|
+
// 如果有定义 w
|
|
48
|
+
if ($n_has(options, 'w')) {
|
|
49
|
+
|
|
50
|
+
let {
|
|
51
|
+
w,
|
|
52
|
+
maxWidth,
|
|
53
|
+
zoom,
|
|
54
|
+
} = options
|
|
55
|
+
|
|
56
|
+
// 先设为 0
|
|
57
|
+
options.w = 0
|
|
58
|
+
|
|
59
|
+
// 如果开启缩放 && 有宽度
|
|
60
|
+
if (zoom && w) {
|
|
61
|
+
|
|
62
|
+
if (! $n_isNumeric(w) && $n_isString(w)) {
|
|
63
|
+
w = w.replace('px', '')
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if ($n_isNumeric(w)) {
|
|
67
|
+
w = Number(w)
|
|
68
|
+
if (w > 0) {
|
|
69
|
+
|
|
70
|
+
// 获取设备像素比
|
|
71
|
+
/* #if IS_WEB */
|
|
72
|
+
const devicePixelRatio = window.devicePixelRatio || 1
|
|
73
|
+
if (devicePixelRatio > 2) {
|
|
74
|
+
w *= 2
|
|
75
|
+
}
|
|
76
|
+
/* #endif */
|
|
77
|
+
|
|
78
|
+
if (w > 10) {
|
|
79
|
+
w = Math.floor(w / 10) * 10
|
|
80
|
+
} else {
|
|
81
|
+
w = Math.floor(w)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// 如果有最大宽度
|
|
85
|
+
if (maxWidth && maxWidth > w) {
|
|
86
|
+
w = maxWidth
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
options.w = w
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
// --------------------------------------------------
|
|
95
|
+
|
|
96
|
+
const {
|
|
97
|
+
type,
|
|
98
|
+
domain,
|
|
99
|
+
} = $n_config('uploader.upload')
|
|
100
|
+
|
|
101
|
+
// 判断图片上传方式
|
|
102
|
+
switch (type) {
|
|
103
|
+
|
|
104
|
+
// 七牛云
|
|
105
|
+
case 'qiniu':
|
|
106
|
+
|
|
107
|
+
const {
|
|
108
|
+
w,
|
|
109
|
+
h,
|
|
110
|
+
q,
|
|
111
|
+
format,
|
|
112
|
+
} = Object.assign({
|
|
113
|
+
// 宽
|
|
114
|
+
w: 0,
|
|
115
|
+
// 高
|
|
116
|
+
h: 0,
|
|
117
|
+
// 质量
|
|
118
|
+
q: 75,
|
|
119
|
+
// 格式
|
|
120
|
+
format: 'webp',
|
|
121
|
+
}, options)
|
|
122
|
+
|
|
123
|
+
// 裁剪图片方式
|
|
124
|
+
src += '?imageView2/2'
|
|
125
|
+
|
|
126
|
+
// 质量
|
|
127
|
+
if (q) {
|
|
128
|
+
src += '/q/' + q
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// 宽
|
|
132
|
+
if (w) {
|
|
133
|
+
src += '/w/' + w
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// 高
|
|
137
|
+
if (h) {
|
|
138
|
+
src += '/h/' + h
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// 格式
|
|
142
|
+
if (format) {
|
|
143
|
+
src += '/format/' + format
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return $n_slash(domain, 'end', true) + src
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return ''
|
|
153
|
+
}
|
package/utils/getTime.js
CHANGED
|
@@ -1,106 +1,106 @@
|
|
|
1
|
-
import $n_isValidString from '@netang/utils/isValidString'
|
|
2
|
-
import $n_toDate from '@netang/utils/toDate'
|
|
3
|
-
import $n_indexOf from '@netang/utils/indexOf'
|
|
4
|
-
|
|
5
|
-
import $n_timestamp from './timestamp'
|
|
6
|
-
|
|
7
|
-
import { date as quasarDate } from 'quasar'
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* 获取时间
|
|
11
|
-
*/
|
|
12
|
-
export default function getTime(time, options, defaultValue = '') {
|
|
13
|
-
|
|
14
|
-
if (! time) {
|
|
15
|
-
return $n_isValidString(options) ? options : defaultValue
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
let {
|
|
19
|
-
hideCurrentYear,
|
|
20
|
-
showSecond,
|
|
21
|
-
format,
|
|
22
|
-
calendar,
|
|
23
|
-
showCalendarToday,
|
|
24
|
-
showCalendarTime,
|
|
25
|
-
|
|
26
|
-
} = Object.assign({
|
|
27
|
-
// 默认格式化
|
|
28
|
-
format: 'MM-DD HH:mm',
|
|
29
|
-
// 是否显示秒
|
|
30
|
-
showSecond: false,
|
|
31
|
-
// 是否隐藏当前年份
|
|
32
|
-
hideCurrentYear: false,
|
|
33
|
-
// 是否显示日历格式
|
|
34
|
-
calendar: false,
|
|
35
|
-
// 是否显示日历今天
|
|
36
|
-
showCalendarToday: false,
|
|
37
|
-
// 是否显示日历时间
|
|
38
|
-
showCalendarTime: false,
|
|
39
|
-
}, options)
|
|
40
|
-
|
|
41
|
-
// 传入时间
|
|
42
|
-
const date = $n_toDate(time)
|
|
43
|
-
|
|
44
|
-
// 当前时间
|
|
45
|
-
const now = $n_toDate($n_timestamp())
|
|
46
|
-
|
|
47
|
-
// 如果是自然化时间
|
|
48
|
-
// 如果是今天, 则显示时分秒
|
|
49
|
-
// 如果是昨天, 则显示昨天
|
|
50
|
-
// 如果是本周, 则显示星期几
|
|
51
|
-
// 如果是本年, 则显示某月某日
|
|
52
|
-
// 如果是非本年, 则显示某年某月某日
|
|
53
|
-
if (calendar) {
|
|
54
|
-
|
|
55
|
-
// 当前时间
|
|
56
|
-
let time = ''
|
|
57
|
-
|
|
58
|
-
// 如果是今年
|
|
59
|
-
if (quasarDate.formatDate(date, 'YYYY') === quasarDate.formatDate(now, 'YYYY')) {
|
|
60
|
-
|
|
61
|
-
// 如果是今天
|
|
62
|
-
const resDay = quasarDate.formatDate(date, 'YYYY-MM-DD')
|
|
63
|
-
if (resDay === quasarDate.formatDate(now, 'YYYY-MM-DD')) {
|
|
64
|
-
return showCalendarToday ? '今天' : quasarDate.formatDate(date, 'HH:mm' + (showSecond ? ':ss' : ''))
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// 判断是否是昨天
|
|
68
|
-
if (resDay === quasarDate.formatDate(quasarDate.subtractFromDate(now, { days: 1 }), 'YYYY-MM-DD')) {
|
|
69
|
-
time = '昨天'
|
|
70
|
-
|
|
71
|
-
// 是否为本周(判断日期在本年是第几周 如果相同, 则是本周)
|
|
72
|
-
} else if (quasarDate.formatDate(date, 'YYYY w') === quasarDate.formatDate(now, 'YYYY w')) {
|
|
73
|
-
time = quasarDate.formatDate(date, 'dddd')
|
|
74
|
-
|
|
75
|
-
// 否则显示某月某日
|
|
76
|
-
} else {
|
|
77
|
-
time = quasarDate.formatDate(date, 'MM月DD日')
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// 否则显示某年某月某日
|
|
81
|
-
} else {
|
|
82
|
-
time = quasarDate.formatDate(date, 'YYYY年MM月DD日')
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// 是否显示日历时间
|
|
86
|
-
if (showCalendarTime) {
|
|
87
|
-
return time + ' ' + quasarDate.formatDate(date, 'HH:mm' + (showSecond ? ':ss' : ''))
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// 否则仅显示日期
|
|
91
|
-
return time
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// 如果是今年是否显示
|
|
95
|
-
if (
|
|
96
|
-
$n_indexOf(format, 'YYYY') === -1
|
|
97
|
-
&& (
|
|
98
|
-
! hideCurrentYear
|
|
99
|
-
|| quasarDate.formatDate(date, 'YYYY') !== quasarDate.formatDate(now, 'YYYY')
|
|
100
|
-
)
|
|
101
|
-
) {
|
|
102
|
-
format = 'YYYY-' + format
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
return quasarDate.formatDate(date, format + (showSecond ? ':ss' : ''))
|
|
106
|
-
}
|
|
1
|
+
import $n_isValidString from '@netang/utils/isValidString'
|
|
2
|
+
import $n_toDate from '@netang/utils/toDate'
|
|
3
|
+
import $n_indexOf from '@netang/utils/indexOf'
|
|
4
|
+
|
|
5
|
+
import $n_timestamp from './timestamp'
|
|
6
|
+
|
|
7
|
+
import { date as quasarDate } from 'quasar'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 获取时间
|
|
11
|
+
*/
|
|
12
|
+
export default function getTime(time, options, defaultValue = '') {
|
|
13
|
+
|
|
14
|
+
if (! time) {
|
|
15
|
+
return $n_isValidString(options) ? options : defaultValue
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
let {
|
|
19
|
+
hideCurrentYear,
|
|
20
|
+
showSecond,
|
|
21
|
+
format,
|
|
22
|
+
calendar,
|
|
23
|
+
showCalendarToday,
|
|
24
|
+
showCalendarTime,
|
|
25
|
+
|
|
26
|
+
} = Object.assign({
|
|
27
|
+
// 默认格式化
|
|
28
|
+
format: 'MM-DD HH:mm',
|
|
29
|
+
// 是否显示秒
|
|
30
|
+
showSecond: false,
|
|
31
|
+
// 是否隐藏当前年份
|
|
32
|
+
hideCurrentYear: false,
|
|
33
|
+
// 是否显示日历格式
|
|
34
|
+
calendar: false,
|
|
35
|
+
// 是否显示日历今天
|
|
36
|
+
showCalendarToday: false,
|
|
37
|
+
// 是否显示日历时间
|
|
38
|
+
showCalendarTime: false,
|
|
39
|
+
}, options)
|
|
40
|
+
|
|
41
|
+
// 传入时间
|
|
42
|
+
const date = $n_toDate(time)
|
|
43
|
+
|
|
44
|
+
// 当前时间
|
|
45
|
+
const now = $n_toDate($n_timestamp())
|
|
46
|
+
|
|
47
|
+
// 如果是自然化时间
|
|
48
|
+
// 如果是今天, 则显示时分秒
|
|
49
|
+
// 如果是昨天, 则显示昨天
|
|
50
|
+
// 如果是本周, 则显示星期几
|
|
51
|
+
// 如果是本年, 则显示某月某日
|
|
52
|
+
// 如果是非本年, 则显示某年某月某日
|
|
53
|
+
if (calendar) {
|
|
54
|
+
|
|
55
|
+
// 当前时间
|
|
56
|
+
let time = ''
|
|
57
|
+
|
|
58
|
+
// 如果是今年
|
|
59
|
+
if (quasarDate.formatDate(date, 'YYYY') === quasarDate.formatDate(now, 'YYYY')) {
|
|
60
|
+
|
|
61
|
+
// 如果是今天
|
|
62
|
+
const resDay = quasarDate.formatDate(date, 'YYYY-MM-DD')
|
|
63
|
+
if (resDay === quasarDate.formatDate(now, 'YYYY-MM-DD')) {
|
|
64
|
+
return showCalendarToday ? '今天' : quasarDate.formatDate(date, 'HH:mm' + (showSecond ? ':ss' : ''))
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// 判断是否是昨天
|
|
68
|
+
if (resDay === quasarDate.formatDate(quasarDate.subtractFromDate(now, { days: 1 }), 'YYYY-MM-DD')) {
|
|
69
|
+
time = '昨天'
|
|
70
|
+
|
|
71
|
+
// 是否为本周(判断日期在本年是第几周 如果相同, 则是本周)
|
|
72
|
+
} else if (quasarDate.formatDate(date, 'YYYY w') === quasarDate.formatDate(now, 'YYYY w')) {
|
|
73
|
+
time = quasarDate.formatDate(date, 'dddd')
|
|
74
|
+
|
|
75
|
+
// 否则显示某月某日
|
|
76
|
+
} else {
|
|
77
|
+
time = quasarDate.formatDate(date, 'MM月DD日')
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// 否则显示某年某月某日
|
|
81
|
+
} else {
|
|
82
|
+
time = quasarDate.formatDate(date, 'YYYY年MM月DD日')
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// 是否显示日历时间
|
|
86
|
+
if (showCalendarTime) {
|
|
87
|
+
return time + ' ' + quasarDate.formatDate(date, 'HH:mm' + (showSecond ? ':ss' : ''))
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// 否则仅显示日期
|
|
91
|
+
return time
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// 如果是今年是否显示
|
|
95
|
+
if (
|
|
96
|
+
$n_indexOf(format, 'YYYY') === -1
|
|
97
|
+
&& (
|
|
98
|
+
! hideCurrentYear
|
|
99
|
+
|| quasarDate.formatDate(date, 'YYYY') !== quasarDate.formatDate(now, 'YYYY')
|
|
100
|
+
)
|
|
101
|
+
) {
|
|
102
|
+
format = 'YYYY-' + format
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return quasarDate.formatDate(date, format + (showSecond ? ':ss' : ''))
|
|
106
|
+
}
|