@netang/quasar 0.0.100 → 0.0.102

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 (164) hide show
  1. package/.editorconfig +12 -0
  2. package/LICENSE +21 -21
  3. package/README.md +11 -11
  4. package/_docs/docs/.vuepress/client.js +8 -8
  5. package/_docs/docs/.vuepress/config.js +40 -40
  6. package/_docs/docs/.vuepress/configs/index.js +2 -2
  7. package/_docs/docs/.vuepress/configs/navbar/index.js +1 -1
  8. package/_docs/docs/.vuepress/configs/navbar/zh.js +16 -16
  9. package/_docs/docs/.vuepress/configs/sidebar/index.js +1 -1
  10. package/_docs/docs/.vuepress/configs/sidebar/zh.js +75 -75
  11. package/_docs/docs/.vuepress/public/css/index.css +3 -3
  12. package/_docs/docs/.vuepress/styles/index.scss +3 -3
  13. package/_docs/docs/components/column-title.md +25 -25
  14. package/_docs/docs/components/data.md +66 -66
  15. package/_docs/docs/components/dialog.md +59 -59
  16. package/_docs/docs/components/dragger.md +26 -26
  17. package/_docs/docs/components/editor-code.md +16 -16
  18. package/_docs/docs/components/empty.md +13 -13
  19. package/_docs/docs/components/field-date.md +16 -16
  20. package/_docs/docs/components/field-text.md +57 -57
  21. package/_docs/docs/components/field-tree.md +21 -21
  22. package/_docs/docs/components/img.md +25 -25
  23. package/_docs/docs/components/input-number.md +21 -21
  24. package/_docs/docs/components/list-menu-item.md +21 -21
  25. package/_docs/docs/components/list-menu.md +21 -21
  26. package/_docs/docs/components/power-page.md +21 -21
  27. package/_docs/docs/components/price.md +21 -21
  28. package/_docs/docs/components/render.md +12 -12
  29. package/_docs/docs/components/search-item.md +10 -10
  30. package/_docs/docs/components/search.md +12 -12
  31. package/_docs/docs/components/select.md +11 -11
  32. package/_docs/docs/components/splitter.md +15 -15
  33. package/_docs/docs/components/table-column-fixed.md +20 -20
  34. package/_docs/docs/components/table-pagination.md +20 -20
  35. package/_docs/docs/components/table-splitter.md +20 -20
  36. package/_docs/docs/components/table-summary.md +20 -20
  37. package/_docs/docs/components/table.md +25 -25
  38. package/_docs/docs/components/thumbnail.md +18 -18
  39. package/_docs/docs/components/toolbar.md +9 -9
  40. package/_docs/docs/components/uploader-query.md +19 -19
  41. package/_docs/docs/components/uploader.md +16 -16
  42. package/_docs/docs/components/value-format.md +26 -26
  43. package/_docs/docs/index.md +1 -1
  44. package/_docs/docs/utils/alert.md +26 -26
  45. package/_docs/docs/utils/area.md +112 -112
  46. package/_docs/docs/utils/arr.md +80 -80
  47. package/_docs/docs/utils/auth.md +101 -101
  48. package/_docs/docs/utils/bus.md +18 -18
  49. package/_docs/docs/utils/confirm.md +31 -31
  50. package/_docs/docs/utils/copy.md +22 -22
  51. package/_docs/docs/utils/dialog.md +98 -98
  52. package/_docs/docs/utils/dict.md +50 -50
  53. package/_docs/docs/utils/dictOptions.md +27 -27
  54. package/_docs/docs/utils/form.md +33 -33
  55. package/_docs/docs/utils/getData.md +60 -60
  56. package/_docs/docs/utils/getFile.md +21 -21
  57. package/_docs/docs/utils/getImage.md +33 -33
  58. package/_docs/docs/utils/getTime.md +51 -51
  59. package/_docs/docs/utils/index.md +1 -1
  60. package/_docs/docs/utils/loading.md +18 -18
  61. package/_docs/docs/utils/notify.md +29 -29
  62. package/_docs/docs/utils/power.md +353 -353
  63. package/_docs/docs/utils/previewImage.md +11 -11
  64. package/_docs/docs/utils/price.md +45 -45
  65. package/_docs/docs/utils/rule.md +30 -30
  66. package/_docs/docs/utils/ruleValid.md +31 -31
  67. package/_docs/docs/utils/symbols.md +30 -30
  68. package/_docs/docs/utils/table.md +194 -194
  69. package/_docs/docs/utils/timestamp.md +27 -27
  70. package/_docs/docs/utils/toast.md +27 -27
  71. package/_docs/docs/utils/tree.md +174 -174
  72. package/_docs/docs/utils/uploader.md +29 -29
  73. package/_docs/package.json +11 -11
  74. package/components/column-title/index.vue +37 -37
  75. package/components/data/index.vue +20 -20
  76. package/components/dialog/index.vue +372 -372
  77. package/components/dragger/index.vue +203 -203
  78. package/components/drawer/index.vue +303 -303
  79. package/components/editor-code/index.vue +289 -289
  80. package/components/empty/index.vue +71 -71
  81. package/components/field-date/index.vue +850 -850
  82. package/components/field-date/methods.js +100 -100
  83. package/components/field-table/index.vue +1222 -1195
  84. package/components/field-text/index.vue +165 -165
  85. package/components/field-tree/index.vue +739 -659
  86. package/components/img/index.vue +202 -202
  87. package/components/input-number/index.vue +546 -546
  88. package/components/list-menu/index.vue +149 -149
  89. package/components/list-menu-item/index.vue +79 -79
  90. package/components/power-page/index.vue +92 -92
  91. package/components/price/index.vue +188 -188
  92. package/components/private/components/index.js +11 -11
  93. package/components/private/components/move-to-tree/index.vue +154 -154
  94. package/components/private/edit-power-data/index.vue +816 -816
  95. package/components/private/table-visible-columns-button/index.vue +109 -109
  96. package/components/render/index.vue +150 -150
  97. package/components/search/index.vue +222 -222
  98. package/components/search-item/index.vue +210 -210
  99. package/components/select/index.vue +177 -177
  100. package/components/splitter/index.vue +415 -415
  101. package/components/table/index.vue +456 -456
  102. package/components/table-column-fixed/index.vue +112 -112
  103. package/components/table-pagination/index.vue +192 -192
  104. package/components/table-splitter/index.vue +360 -360
  105. package/components/table-summary/index.vue +110 -110
  106. package/components/thumbnail/index.vue +72 -72
  107. package/components/toolbar/container.vue +31 -31
  108. package/components/toolbar/index.vue +136 -136
  109. package/components/uploader/index.vue +158 -158
  110. package/components/uploader-query/index.vue +758 -758
  111. package/components/value-format/index.vue +274 -274
  112. package/configs/area3.js +1 -1
  113. package/docs/css/index.css +3 -3
  114. package/package.json +24 -24
  115. package/sass/common.scss +174 -174
  116. package/sass/index.scss +14 -14
  117. package/sass/line.scss +39 -39
  118. package/sass/quasar/btn.scss +46 -46
  119. package/sass/quasar/common.scss +3 -3
  120. package/sass/quasar/dialog.scss +7 -7
  121. package/sass/quasar/drawer.scss +6 -6
  122. package/sass/quasar/field.scss +243 -243
  123. package/sass/quasar/loading.scss +6 -6
  124. package/sass/quasar/menu.scss +8 -8
  125. package/sass/quasar/table.scss +150 -150
  126. package/sass/quasar/toolbar.scss +22 -22
  127. package/store/index.js +29 -29
  128. package/utils/$auth.js +127 -127
  129. package/utils/$form.js +56 -56
  130. package/utils/$power.js +1215 -1215
  131. package/utils/$rule.js +13 -13
  132. package/utils/$ruleValid.js +10 -10
  133. package/utils/$table.js +999 -999
  134. package/utils/$tree.js +713 -713
  135. package/utils/alert.js +12 -12
  136. package/utils/area.js +400 -400
  137. package/utils/arr.js +51 -51
  138. package/utils/bus.js +6 -6
  139. package/utils/config.js +52 -52
  140. package/utils/confirm.js +11 -11
  141. package/utils/copy.js +30 -30
  142. package/utils/dialog.js +36 -36
  143. package/utils/dict.js +21 -21
  144. package/utils/dictOptions.js +28 -28
  145. package/utils/getData.js +73 -73
  146. package/utils/getFile.js +40 -40
  147. package/utils/getImage.js +153 -153
  148. package/utils/getTime.js +106 -106
  149. package/utils/index.js +61 -61
  150. package/utils/loading.js +15 -15
  151. package/utils/notify.js +13 -13
  152. package/utils/previewImage.js +10 -10
  153. package/utils/price.js +18 -18
  154. package/utils/symbols.js +18 -18
  155. package/utils/timestamp.js +18 -18
  156. package/utils/toast.js +13 -13
  157. package/utils/uploader/aliyun.js +6 -6
  158. package/utils/uploader/local.js +8 -8
  159. package/utils/uploader/qiniu.js +321 -321
  160. package/utils/uploader.js +1059 -1059
  161. package/utils/useAuth.js +30 -30
  162. package/utils/useRouter.js +47 -47
  163. package/utils/useSearch.js +496 -496
  164. package/utils/useUploader.js +53 -53
@@ -1,321 +1,321 @@
1
- import $n_has from 'lodash/has'
2
- import $n_isString from 'lodash/isString'
3
- import $n_findIndex from 'lodash/findIndex'
4
- import $n_trim from 'lodash/trim'
5
-
6
- import $n_isValidObject from '@netang/utils/isValidObject'
7
- import $n_isValidString from '@netang/utils/isValidString'
8
- import $n_http from '@netang/utils/http'
9
-
10
- import $n_toast from '../toast'
11
- import $n_config from '../config'
12
-
13
- import {
14
- UPLOAD_STATUS,
15
- } from '../useUploader'
16
-
17
- /**
18
- * 获取七牛云上传 token
19
- */
20
- async function getQiniuToken(bucket = 'public') {
21
-
22
- // 请求数据
23
- const { status, data } = await $n_http({
24
- url: $n_config('apiFileUrl') + 'get_qiniu_token',
25
- data: {
26
- bucket,
27
- },
28
-
29
- // 【生产模式】
30
- // --------------------------------------------------
31
- // #ifdef IS_PRO
32
- // 开启缓存
33
- cache: 'qiniu_token_' + bucket,
34
- // 缓存时间(6 小时)
35
- cacheTime: 21600000,
36
- // #endif
37
- // --------------------------------------------------
38
- })
39
-
40
- // 如果成功
41
- if (! status) {
42
- return false
43
- }
44
-
45
- return data
46
- }
47
-
48
- /**
49
- * 七牛云上传
50
- */
51
- export default async function ({ waitUploadFileLists, uploadFileLists, checkFileError, setFileSuccess, setFileFail }) {
52
-
53
- // 获取七牛云上传 token
54
- const token = await getQiniuToken()
55
- if (! token) {
56
- for (const fileItem of waitUploadFileLists) {
57
- setFileFail(fileItem, '上传失败')
58
- }
59
- $n_toast({
60
- message: '获取上传参数失败',
61
- })
62
- return
63
- }
64
-
65
- // 批量上传
66
- for (const fileItem of waitUploadFileLists) {
67
- // 上传单个文件
68
- uploadFileItem(fileItem, token)
69
- .finally()
70
- }
71
-
72
- /**
73
- * 上传单个文件
74
- */
75
- async function uploadFileItem(fileItem, token) {
76
-
77
- // 设置文件状态
78
- fileItem.status = UPLOAD_STATUS.uploading
79
-
80
- // 请求上传文件到七牛云
81
- const { status, data: resUpload } = await $n_http({
82
- // 上传地址
83
- url: 'https://upload.qiniup.com/',
84
- // 数据
85
- data: {
86
- // 七牛云上传 token
87
- token,
88
- // 文件
89
- file: fileItem.file,
90
- // 自定义文件 key
91
- key: fileItem.hash,
92
- },
93
- // 关闭错误提醒
94
- warn: false,
95
- // 关闭检查结果 code
96
- checkCode: false,
97
- // 不包含头部鉴权认证
98
- token: false,
99
- // 开启上传
100
- upload: true,
101
- // 取消请求
102
- onCancel(cancel) {
103
- // 设置中断上传
104
- fileItem.abort = function(msg) {
105
- cancel($n_isValidString(msg) ? msg : '已取消')
106
- }
107
- },
108
- // 监听上传进度
109
- onUploadProgress(percent) {
110
- // 设置上传进度
111
- fileItem.progress = percent
112
- },
113
- })
114
-
115
- // 如果请求失败
116
- if (! status) {
117
- // 设置文件上传失败
118
- setFileFail(fileItem, resUpload.msg)
119
- return
120
- }
121
-
122
- // 如果检查七牛回调成功
123
- const query = await checkQiniuCallback(resUpload, fileItem)
124
- if (! query) {
125
- return
126
- }
127
-
128
- // 请求 - 上传文件至 cdn
129
- const { status: statusCallback, data: resCallback } = await $n_http({
130
- url: $n_config('apiFileUrl') + 'upload_cdn_callback',
131
- data: query,
132
- // 关闭错误提示
133
- warn: false,
134
- })
135
-
136
- // 请求失败
137
- if (! statusCallback) {
138
- // 设置文件上传失败
139
- setFileFail(fileItem, resCallback.msg || '上传失败')
140
- return
141
- }
142
-
143
- // 设置文件上传成功
144
- setFileSuccess(fileItem)
145
- }
146
-
147
- /**
148
- * 检查七牛回调成功
149
- */
150
- function checkQiniuCallback(res, fileItem) {
151
-
152
- // 如果文件被删除
153
- if ($n_findIndex(uploadFileLists.value, { hash: fileItem.hash }) === -1) {
154
- // 设置文件上传失败
155
- setFileFail(fileItem, '上传失败')
156
- return false
157
- }
158
-
159
- // 返回示例
160
- // ------------------------------
161
- // format: "null"
162
- // width: null
163
- // height: null
164
- // key: "d038dce5892840636b2c1f6d241f33ad"
165
- // hash: "lrYGlELBAgN9OgKV_i5gbHOdZMvt"
166
- // orientation: null
167
- // size: 6620454
168
- // aduration: 57.258005
169
- // vwidth: 1280
170
- // vheight: 720
171
- // vrotate: null
172
- // vduration: 57.291992
173
-
174
- const {
175
- format,
176
- width,
177
- height,
178
- key,
179
- orientation,
180
- size,
181
- aduration,
182
- vwidth,
183
- vheight,
184
- vrotate,
185
- vduration,
186
- } = res
187
-
188
- const query = {
189
- // 标题
190
- title: fileItem.title,
191
- // 类型(1:文件,2:图片,3:视频,4:音频)
192
- type: 0,
193
- // hash
194
- hash: key,
195
- // 文件大小
196
- size,
197
- // 后缀
198
- ext: fileItem.ext,
199
- }
200
-
201
- // json 信息
202
- const json = {}
203
-
204
- // 【1】先判断是否为视频(有时长 && 有宽 && 有高 && 时长 > 0, 则为视频)
205
- if (vduration && vwidth && vheight) {
206
-
207
- // 类型(3:视频)
208
- query.type = 3
209
-
210
- // 视频旋转角度
211
- // vrotate: 无 ==> 1: 手机右横屏(宽高不变)
212
- // vrotate: 90 ==> 2: 手机垂直(宽高反转)
213
- // vrotate: 180 ==> 3: 手机左横屏(宽高不变)
214
- // vrotate: 270 ==> 4: 手机倒过来垂直(宽高反转)
215
- const rotates = {
216
- 90: 2,
217
- 180: 3,
218
- 270: 4,
219
- }
220
-
221
- // 设置 json 信息
222
- Object.assign(json, {
223
- w: vwidth,
224
- h: vheight,
225
- d: vduration,
226
- })
227
-
228
- if ($n_has(rotates, vrotate)) {
229
- json.o = rotates[vrotate]
230
- }
231
-
232
- // 【2】再判断是否为音频(有音频时长 && 无视频时长 && 音频时长 > 0, 则为音频)
233
- } else if (aduration && ! vduration) {
234
-
235
- // 类型(4:音频)
236
- query.type = 4
237
-
238
- // 设置 json 信息
239
- json.d = aduration
240
-
241
- // 【3】再判断是否为图片(有宽 && 有高 && 大小 < 20M, 为图片)
242
- } else if (width && height) {
243
-
244
- // 类型(2:图片)
245
- query.type = 2
246
-
247
- // 图片后缀名
248
- query.ext = format === 'jpeg' ? 'jpg' : format
249
-
250
- // 如果大小 < 20M, 则为可用图片
251
- if (size < 20971520) {
252
-
253
- // 设置 json 数据
254
- json.w = width
255
- json.h = height
256
-
257
- // 图片垂直角度
258
- const orientations = {
259
- // 【1】相机原始位置(宽高不变)
260
- // 'top-left': 1,
261
- // 【2】等于 1 的垂直镜像(几乎无用)(宽高不变)
262
- 'top-right': 2,
263
- // 【3】旋转 180度(宽高不变)
264
- 'bottom-right': 3,
265
- // 【4】等于 3 的垂直镜像(几乎无用)(宽高不变)
266
- 'bottom-left': 4,
267
- // 【5】等于 8 的水平镜像(几乎无用)(宽高反转)
268
- 'left-top': 5,
269
- // 【6】旋转 90 度(宽高反转)
270
- 'right-top': 6,
271
- // 【7】等于 8 的垂直镜像(几乎无用)(宽高反转)
272
- 'right-bottom': 7,
273
- // 【8】旋转 270 度(宽高反转)
274
- 'left-bottom': 8,
275
- }
276
- if (orientation && $n_isString(orientation)) {
277
- const key = $n_trim(orientation).toLowerCase()
278
- if ($n_has(orientations, key)) {
279
- json.o = orientations[key]
280
- }
281
- }
282
-
283
- // 否则为类型为文件
284
- } else {
285
- // 检查文件错误
286
- const errMsg = checkFileError(query)
287
- if (errMsg) {
288
- // 设置文件上传失败
289
- setFileFail(fileItem, errMsg)
290
- return false
291
- }
292
-
293
- // 类型(1:文件)
294
- query.type = 1
295
- }
296
-
297
- // 否则为类型为文件
298
- } else {
299
- // 类型(1:文件)
300
- query.type = 1
301
- }
302
-
303
- // 检查文件错误
304
- const errMsg = checkFileError(query)
305
- if (errMsg) {
306
- // 设置文件上传失败
307
- setFileFail(fileItem, errMsg)
308
- return false
309
- }
310
-
311
- // json 信息
312
- query.json = json
313
-
314
- // 设置文件
315
- Object.assign(fileItem, query)
316
-
317
- return Object.assign({}, query, {
318
- json: $n_isValidObject(json) ? JSON.stringify(json) : ''
319
- })
320
- }
321
- }
1
+ import $n_has from 'lodash/has'
2
+ import $n_isString from 'lodash/isString'
3
+ import $n_findIndex from 'lodash/findIndex'
4
+ import $n_trim from 'lodash/trim'
5
+
6
+ import $n_isValidObject from '@netang/utils/isValidObject'
7
+ import $n_isValidString from '@netang/utils/isValidString'
8
+ import $n_http from '@netang/utils/http'
9
+
10
+ import $n_toast from '../toast'
11
+ import $n_config from '../config'
12
+
13
+ import {
14
+ UPLOAD_STATUS,
15
+ } from '../useUploader'
16
+
17
+ /**
18
+ * 获取七牛云上传 token
19
+ */
20
+ async function getQiniuToken(bucket = 'public') {
21
+
22
+ // 请求数据
23
+ const { status, data } = await $n_http({
24
+ url: $n_config('apiFileUrl') + 'get_qiniu_token',
25
+ data: {
26
+ bucket,
27
+ },
28
+
29
+ // 【生产模式】
30
+ // --------------------------------------------------
31
+ // #ifdef IS_PRO
32
+ // 开启缓存
33
+ cache: 'qiniu_token_' + bucket,
34
+ // 缓存时间(6 小时)
35
+ cacheTime: 21600000,
36
+ // #endif
37
+ // --------------------------------------------------
38
+ })
39
+
40
+ // 如果成功
41
+ if (! status) {
42
+ return false
43
+ }
44
+
45
+ return data
46
+ }
47
+
48
+ /**
49
+ * 七牛云上传
50
+ */
51
+ export default async function ({ waitUploadFileLists, uploadFileLists, checkFileError, setFileSuccess, setFileFail }) {
52
+
53
+ // 获取七牛云上传 token
54
+ const token = await getQiniuToken()
55
+ if (! token) {
56
+ for (const fileItem of waitUploadFileLists) {
57
+ setFileFail(fileItem, '上传失败')
58
+ }
59
+ $n_toast({
60
+ message: '获取上传参数失败',
61
+ })
62
+ return
63
+ }
64
+
65
+ // 批量上传
66
+ for (const fileItem of waitUploadFileLists) {
67
+ // 上传单个文件
68
+ uploadFileItem(fileItem, token)
69
+ .finally()
70
+ }
71
+
72
+ /**
73
+ * 上传单个文件
74
+ */
75
+ async function uploadFileItem(fileItem, token) {
76
+
77
+ // 设置文件状态
78
+ fileItem.status = UPLOAD_STATUS.uploading
79
+
80
+ // 请求上传文件到七牛云
81
+ const { status, data: resUpload } = await $n_http({
82
+ // 上传地址
83
+ url: 'https://upload.qiniup.com/',
84
+ // 数据
85
+ data: {
86
+ // 七牛云上传 token
87
+ token,
88
+ // 文件
89
+ file: fileItem.file,
90
+ // 自定义文件 key
91
+ key: fileItem.hash,
92
+ },
93
+ // 关闭错误提醒
94
+ warn: false,
95
+ // 关闭检查结果 code
96
+ checkCode: false,
97
+ // 不包含头部鉴权认证
98
+ token: false,
99
+ // 开启上传
100
+ upload: true,
101
+ // 取消请求
102
+ onCancel(cancel) {
103
+ // 设置中断上传
104
+ fileItem.abort = function(msg) {
105
+ cancel($n_isValidString(msg) ? msg : '已取消')
106
+ }
107
+ },
108
+ // 监听上传进度
109
+ onUploadProgress(percent) {
110
+ // 设置上传进度
111
+ fileItem.progress = percent
112
+ },
113
+ })
114
+
115
+ // 如果请求失败
116
+ if (! status) {
117
+ // 设置文件上传失败
118
+ setFileFail(fileItem, resUpload.msg)
119
+ return
120
+ }
121
+
122
+ // 如果检查七牛回调成功
123
+ const query = await checkQiniuCallback(resUpload, fileItem)
124
+ if (! query) {
125
+ return
126
+ }
127
+
128
+ // 请求 - 上传文件至 cdn
129
+ const { status: statusCallback, data: resCallback } = await $n_http({
130
+ url: $n_config('apiFileUrl') + 'upload_cdn_callback',
131
+ data: query,
132
+ // 关闭错误提示
133
+ warn: false,
134
+ })
135
+
136
+ // 请求失败
137
+ if (! statusCallback) {
138
+ // 设置文件上传失败
139
+ setFileFail(fileItem, resCallback.msg || '上传失败')
140
+ return
141
+ }
142
+
143
+ // 设置文件上传成功
144
+ setFileSuccess(fileItem)
145
+ }
146
+
147
+ /**
148
+ * 检查七牛回调成功
149
+ */
150
+ function checkQiniuCallback(res, fileItem) {
151
+
152
+ // 如果文件被删除
153
+ if ($n_findIndex(uploadFileLists.value, { hash: fileItem.hash }) === -1) {
154
+ // 设置文件上传失败
155
+ setFileFail(fileItem, '上传失败')
156
+ return false
157
+ }
158
+
159
+ // 返回示例
160
+ // ------------------------------
161
+ // format: "null"
162
+ // width: null
163
+ // height: null
164
+ // key: "d038dce5892840636b2c1f6d241f33ad"
165
+ // hash: "lrYGlELBAgN9OgKV_i5gbHOdZMvt"
166
+ // orientation: null
167
+ // size: 6620454
168
+ // aduration: 57.258005
169
+ // vwidth: 1280
170
+ // vheight: 720
171
+ // vrotate: null
172
+ // vduration: 57.291992
173
+
174
+ const {
175
+ format,
176
+ width,
177
+ height,
178
+ key,
179
+ orientation,
180
+ size,
181
+ aduration,
182
+ vwidth,
183
+ vheight,
184
+ vrotate,
185
+ vduration,
186
+ } = res
187
+
188
+ const query = {
189
+ // 标题
190
+ title: fileItem.title,
191
+ // 类型(1:文件,2:图片,3:视频,4:音频)
192
+ type: 0,
193
+ // hash
194
+ hash: key,
195
+ // 文件大小
196
+ size,
197
+ // 后缀
198
+ ext: fileItem.ext,
199
+ }
200
+
201
+ // json 信息
202
+ const json = {}
203
+
204
+ // 【1】先判断是否为视频(有时长 && 有宽 && 有高 && 时长 > 0, 则为视频)
205
+ if (vduration && vwidth && vheight) {
206
+
207
+ // 类型(3:视频)
208
+ query.type = 3
209
+
210
+ // 视频旋转角度
211
+ // vrotate: 无 ==> 1: 手机右横屏(宽高不变)
212
+ // vrotate: 90 ==> 2: 手机垂直(宽高反转)
213
+ // vrotate: 180 ==> 3: 手机左横屏(宽高不变)
214
+ // vrotate: 270 ==> 4: 手机倒过来垂直(宽高反转)
215
+ const rotates = {
216
+ 90: 2,
217
+ 180: 3,
218
+ 270: 4,
219
+ }
220
+
221
+ // 设置 json 信息
222
+ Object.assign(json, {
223
+ w: vwidth,
224
+ h: vheight,
225
+ d: vduration,
226
+ })
227
+
228
+ if ($n_has(rotates, vrotate)) {
229
+ json.o = rotates[vrotate]
230
+ }
231
+
232
+ // 【2】再判断是否为音频(有音频时长 && 无视频时长 && 音频时长 > 0, 则为音频)
233
+ } else if (aduration && ! vduration) {
234
+
235
+ // 类型(4:音频)
236
+ query.type = 4
237
+
238
+ // 设置 json 信息
239
+ json.d = aduration
240
+
241
+ // 【3】再判断是否为图片(有宽 && 有高 && 大小 < 20M, 为图片)
242
+ } else if (width && height) {
243
+
244
+ // 类型(2:图片)
245
+ query.type = 2
246
+
247
+ // 图片后缀名
248
+ query.ext = format === 'jpeg' ? 'jpg' : format
249
+
250
+ // 如果大小 < 20M, 则为可用图片
251
+ if (size < 20971520) {
252
+
253
+ // 设置 json 数据
254
+ json.w = width
255
+ json.h = height
256
+
257
+ // 图片垂直角度
258
+ const orientations = {
259
+ // 【1】相机原始位置(宽高不变)
260
+ // 'top-left': 1,
261
+ // 【2】等于 1 的垂直镜像(几乎无用)(宽高不变)
262
+ 'top-right': 2,
263
+ // 【3】旋转 180度(宽高不变)
264
+ 'bottom-right': 3,
265
+ // 【4】等于 3 的垂直镜像(几乎无用)(宽高不变)
266
+ 'bottom-left': 4,
267
+ // 【5】等于 8 的水平镜像(几乎无用)(宽高反转)
268
+ 'left-top': 5,
269
+ // 【6】旋转 90 度(宽高反转)
270
+ 'right-top': 6,
271
+ // 【7】等于 8 的垂直镜像(几乎无用)(宽高反转)
272
+ 'right-bottom': 7,
273
+ // 【8】旋转 270 度(宽高反转)
274
+ 'left-bottom': 8,
275
+ }
276
+ if (orientation && $n_isString(orientation)) {
277
+ const key = $n_trim(orientation).toLowerCase()
278
+ if ($n_has(orientations, key)) {
279
+ json.o = orientations[key]
280
+ }
281
+ }
282
+
283
+ // 否则为类型为文件
284
+ } else {
285
+ // 检查文件错误
286
+ const errMsg = checkFileError(query)
287
+ if (errMsg) {
288
+ // 设置文件上传失败
289
+ setFileFail(fileItem, errMsg)
290
+ return false
291
+ }
292
+
293
+ // 类型(1:文件)
294
+ query.type = 1
295
+ }
296
+
297
+ // 否则为类型为文件
298
+ } else {
299
+ // 类型(1:文件)
300
+ query.type = 1
301
+ }
302
+
303
+ // 检查文件错误
304
+ const errMsg = checkFileError(query)
305
+ if (errMsg) {
306
+ // 设置文件上传失败
307
+ setFileFail(fileItem, errMsg)
308
+ return false
309
+ }
310
+
311
+ // json 信息
312
+ query.json = json
313
+
314
+ // 设置文件
315
+ Object.assign(fileItem, query)
316
+
317
+ return Object.assign({}, query, {
318
+ json: $n_isValidObject(json) ? JSON.stringify(json) : ''
319
+ })
320
+ }
321
+ }