@netang/quasar 0.1.94 → 0.1.96

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netang/quasar",
3
- "version": "0.1.94",
3
+ "version": "0.1.96",
4
4
  "description": "netang-quasar",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
package/utils/config.js CHANGED
@@ -11,12 +11,7 @@ import $n_get from 'lodash/get'
11
11
  // // 是否开启人民币分转元
12
12
  // priceCentToYuan: false,
13
13
  // // 上传器
14
- // uploader: {
15
- // upload: {
16
- // type: '',
17
- // domain: '',
18
- // },
19
- // },
14
+ // uploader: {},
20
15
  // },
21
16
 
22
17
  // 配置
package/utils/getFile.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import $n_isValidArray from '@netang/utils/isValidArray'
2
2
  import $n_isValidString from '@netang/utils/isValidString'
3
3
 
4
- import $n_config from './config'
4
+ import $n_uploader from './uploader'
5
5
 
6
6
  import useFileUrl from './useFileUrl'
7
7
 
@@ -27,11 +27,13 @@ export default function getFile(src) {
27
27
  const {
28
28
  type,
29
29
  domain,
30
- } = $n_config('uploader.upload')
30
+ } = $n_uploader.getUpload()
31
31
 
32
32
  switch (type) {
33
33
  // 七牛云
34
34
  case 'qiniu':
35
+ // minio
36
+ case 'minio':
35
37
  return useFileUrl(domain, src)
36
38
  }
37
39
  }
package/utils/getImage.js CHANGED
@@ -7,7 +7,7 @@ import $n_isValidString from '@netang/utils/isValidString'
7
7
  import $n_isNumeric from '@netang/utils/isNumeric'
8
8
  import $n_split from '@netang/utils/split'
9
9
 
10
- import $n_config from './config'
10
+ import $n_uploader from './uploader'
11
11
 
12
12
  import useFileUrl from './useFileUrl'
13
13
 
@@ -113,14 +113,16 @@ export default function getImage(src, options) {
113
113
  const {
114
114
  type,
115
115
  domain,
116
- } = $n_config('uploader.upload')
116
+ } = $n_uploader.getUpload()
117
117
 
118
118
  // 判断图片上传方式
119
119
  switch (type) {
120
120
 
121
121
  // 七牛云
122
122
  case 'qiniu':
123
-
123
+ // minio
124
+ case 'minio':
125
+
124
126
  const {
125
127
  compress,
126
128
  w,
package/utils/uploader.js CHANGED
@@ -45,8 +45,8 @@ import {
45
45
  FilE_NAME,
46
46
  // 上传状态
47
47
  UPLOAD_STATUS,
48
- // 上传器
49
- UPLOADERS,
48
+ // 上传至服务器
49
+ uploadServer,
50
50
  } from './useUploader'
51
51
 
52
52
  // 文件数量
@@ -114,12 +114,8 @@ function create(options) {
114
114
  /**
115
115
  * 上传配置
116
116
  */
117
- const configUpload = Object.assign(
118
- {
119
- type: 'local',
120
- },
121
- $n_config('uploader.upload')
122
- )
117
+ const configUpload = getUpload()
118
+
123
119
  const configLimit = Object.assign({
124
120
  maxSize: 100,
125
121
  exts: [],
@@ -871,23 +867,8 @@ function create(options) {
871
867
  /**
872
868
  * 上传
873
869
  */
874
- let _upload = null
875
870
  async function upload() {
876
871
  try {
877
- if (! _upload) {
878
- const run = $n_get(UPLOADERS, configUpload.type)
879
- if (run) {
880
- _upload = (await run()).default
881
- }
882
- if (! _upload) {
883
- // 错误提示
884
- $n_alert({
885
- message: '没有定义上传器',
886
- })
887
- return
888
- }
889
- }
890
-
891
872
  // 待上传文件列表
892
873
  const waitUploadFileLists = []
893
874
  for (const fileItem of uploadFileLists.value) {
@@ -900,12 +881,13 @@ function create(options) {
900
881
  return
901
882
  }
902
883
 
903
- // 上传
904
- await _upload({
905
- config: configUpload,
884
+ // 上传至服务器
885
+ await uploadServer({
886
+ fileType: FilE_TYPE[props.type],
887
+ configUpload,
906
888
  waitUploadFileLists,
907
- uploadFileLists,
908
- checkFileError,
889
+ // uploadFileLists,
890
+ // checkFileError,
909
891
  setFileSuccess,
910
892
  setFileFail,
911
893
  })
@@ -1614,12 +1596,29 @@ function create(options) {
1614
1596
  }
1615
1597
  }
1616
1598
 
1599
+ /**
1600
+ * 获取上传方式
1601
+ */
1602
+ export function getUpload(userConfig = null, defaultUpload = '') {
1603
+ const uploadConfig = $n_get((userConfig ? userConfig : configs.userConfig), 'uploader.upload', {})
1604
+ const type = defaultUpload ? defaultUpload : uploadConfig.default
1605
+ return Object.assign(
1606
+ {},
1607
+ $n_get(uploadConfig, type, {}),
1608
+ {
1609
+ type,
1610
+ }
1611
+ )
1612
+ }
1613
+
1617
1614
  /**
1618
1615
  * 上传器
1619
1616
  */
1620
1617
  const uploader = {
1621
1618
  // 创建对话框
1622
1619
  create,
1620
+ // 获取上传方式
1621
+ getUpload,
1623
1622
  }
1624
1623
 
1625
1624
  export default uploader
@@ -14,6 +14,7 @@ export default function useFileUrl(domain, src) {
14
14
  const {
15
15
  getFileUrl,
16
16
  } = configs
17
+
17
18
  if ($n_isFunction(getFileUrl)) {
18
19
  const res = getFileUrl(domain, src)
19
20
  if ($n_isValidString(res)) {
@@ -1,53 +1,303 @@
1
- /**
2
- * 文件类型映射
3
- */
4
- export const FilE_TYPE = {
5
- file: 1,
6
- image: 2,
7
- video: 3,
8
- audio: 4,
9
- }
10
-
11
- /**
12
- * 文件名称映射
13
- */
14
- export const FilE_NAME = {
15
- 1: '文件',
16
- 2: '图片',
17
- 3: '视频',
18
- 4: '音频',
19
- }
20
-
21
- /**
22
- * 上传状态
23
- */
24
- export const UPLOAD_STATUS = {
25
- // 等待上传中
26
- waiting: 1,
27
- // 检查 hash 中
28
- hashChecking: 2,
29
- // 检查 hash 完成
30
- hashChecked: 3,
31
- // 检查是否存在服务器中
32
- existChecking: 4,
33
- // 检查是否存在服务器完成
34
- existChecked: 5,
35
- // 上传中
36
- uploading: 6,
37
- // 上传完成
38
- success: 7,
39
- // 上传失败
40
- fail: 8,
41
- }
42
-
43
- /**
44
- * 上传器
45
- */
46
- export const UPLOADERS = {
47
- // 本地上传
48
- 'local': ()=>import('./uploader/local'),
49
- // 七牛云上传
50
- 'qiniu': ()=>import('./uploader/qiniu'),
51
- // 阿里云上传
52
- 'aliyun': ()=>import('./uploader/aliyun'),
53
- }
1
+ import $n_storage from '@netang/utils/storage'
2
+ import $n_isValidObject from '@netang/utils/isValidObject'
3
+ import $n_isValidString from '@netang/utils/isValidString'
4
+ import $n_http from '@netang/utils/http'
5
+ import $n_numberDeep from '@netang/utils/numberDeep'
6
+ import $n_json from '@netang/utils/json'
7
+
8
+ import { getUpload } from './uploader'
9
+
10
+ import $n_toast from './toast'
11
+ import $n_config from './config'
12
+
13
+ /**
14
+ * 文件类型映射
15
+ */
16
+ export const FilE_TYPE = {
17
+ file: 1,
18
+ image: 2,
19
+ video: 3,
20
+ audio: 4,
21
+ }
22
+
23
+ /**
24
+ * 文件名称映射
25
+ */
26
+ export const FilE_NAME = {
27
+ 1: '文件',
28
+ 2: '图片',
29
+ 3: '视频',
30
+ 4: '音频',
31
+ }
32
+
33
+ /**
34
+ * 上传状态
35
+ */
36
+ export const UPLOAD_STATUS = {
37
+ // 等待上传中
38
+ waiting: 1,
39
+ // 检查 hash 中
40
+ hashChecking: 2,
41
+ // 检查 hash 完成
42
+ hashChecked: 3,
43
+ // 检查是否存在服务器中
44
+ existChecking: 4,
45
+ // 检查是否存在服务器完成
46
+ existChecked: 5,
47
+ // 上传中
48
+ uploading: 6,
49
+ // 上传完成
50
+ success: 7,
51
+ // 上传失败
52
+ fail: 8,
53
+ }
54
+
55
+ /**
56
+ * 获取上传参数
57
+ */
58
+ export async function getUploadParams(type, bucket = 'public') {
59
+
60
+ // 缓存名
61
+ const cacheName = `upload_params_${type}_${bucket}`
62
+
63
+ // 获取缓存
64
+ const cache = $n_storage.get(cacheName)
65
+ if (cache !== null) {
66
+ return cache
67
+ }
68
+
69
+ // 请求数据
70
+ const { status, data } = await $n_http({
71
+ url: $n_config('apiFileUrl') + 'get_upload_params',
72
+ data: {
73
+ // 类型
74
+ type,
75
+ // 空间名称
76
+ bucket,
77
+ },
78
+ })
79
+
80
+ // 如果成功
81
+ if (! status || ! $n_isValidObject(data)) {
82
+ return false
83
+ }
84
+
85
+ // 【生产模式】
86
+ // --------------------------------------------------
87
+ // #ifdef IS_PRO
88
+ // 保存缓存(6 小时)
89
+ $n_storage.set(cacheName, data, 21600000)
90
+ // #endif
91
+ // --------------------------------------------------
92
+
93
+ return data
94
+ }
95
+
96
+ /**
97
+ * 删除上传参数缓存
98
+ */
99
+ export function deleteUploadParams(type, bucket = 'public') {
100
+ $n_storage.delete(`upload_params_${type}_${bucket}`)
101
+ }
102
+
103
+ /**
104
+ * 上传至服务器
105
+ */
106
+ export async function uploadServer(params) {
107
+
108
+ const {
109
+ fileType,
110
+ configUpload,
111
+ waitUploadFileLists,
112
+ // uploadFileLists,
113
+ // checkFileError,
114
+ setFileSuccess,
115
+ setFileFail,
116
+ } = params
117
+
118
+ // 获取上传参数
119
+ const uploadParams = await getUploadParams(configUpload.type)
120
+ if (uploadParams === false) {
121
+ for (const fileItem of waitUploadFileLists) {
122
+ setFileFail(fileItem, '上传失败')
123
+ }
124
+ $n_toast({
125
+ message: `获取[${configUpload.type}]上传参数失败`,
126
+ })
127
+ return
128
+ }
129
+
130
+ // 是否上传 minio 备份
131
+ // --------------------------------------------------
132
+ let backupParams = null
133
+ let backupConfig = null
134
+ if (configUpload.type !== 'minio') {
135
+ backupConfig = getUpload(null, 'minio')
136
+ // 如果同步
137
+ if (backupConfig.sync === true) {
138
+ backupParams = await getUploadParams(backupConfig.type)
139
+ if (backupParams === false) {
140
+ for (const fileItem of waitUploadFileLists) {
141
+ setFileFail(fileItem, '上传失败')
142
+ }
143
+ $n_toast({
144
+ message: `获取[${backupConfig.type}]上传参数失败`,
145
+ })
146
+ return
147
+ }
148
+ }
149
+ }
150
+ // --------------------------------------------------
151
+
152
+ // 批量上传
153
+ for (const fileItem of waitUploadFileLists) {
154
+ // 上传单个文件
155
+ await uploadFileItem(fileItem)
156
+ }
157
+
158
+ /**
159
+ * 上传单个文件
160
+ */
161
+ async function uploadFileItem(fileItem) {
162
+
163
+ // 设置文件状态
164
+ fileItem.status = UPLOAD_STATUS.uploading
165
+
166
+ // 上传文件
167
+ const upload = async function(configUpload, uploadParams, startPercent, halfPercent) {
168
+
169
+ const {
170
+ // 上传地址
171
+ url,
172
+ // 文件名
173
+ fileName,
174
+ // 键值名
175
+ keyName,
176
+ // 上传数据
177
+ data,
178
+ } = uploadParams
179
+
180
+ // 请求数据
181
+ const httpData = Object.assign({}, data)
182
+ // 文件
183
+ httpData[fileName] = fileItem.file
184
+ // 自定义文件 key
185
+ httpData[keyName] = fileItem.hash
186
+
187
+ const { status, data: res } = await $n_http({
188
+ // 上传地址
189
+ url,
190
+ // 数据
191
+ data: httpData,
192
+ // 关闭错误提醒
193
+ warn: false,
194
+ // 关闭检查结果 code
195
+ checkCode: false,
196
+ // 不包含头部鉴权认证
197
+ token: false,
198
+ // 开启上传
199
+ upload: true,
200
+ // 取消请求
201
+ onCancel(cancel) {
202
+ // 设置中断上传
203
+ fileItem.abort = function(msg) {
204
+ cancel($n_isValidString(msg) ? msg : '已取消')
205
+ }
206
+ },
207
+ // 监听上传进度
208
+ onUploadProgress(percent) {
209
+ // 设置上传进度
210
+ fileItem.progress = Math.round(startPercent + (halfPercent ? percent / 2 : percent))
211
+ },
212
+ })
213
+
214
+ // 如果请求失败
215
+ if (! status) {
216
+ // 设置文件上传失败
217
+ setFileFail(fileItem, res.msg)
218
+ // 删除上传参数缓存
219
+ deleteUploadParams(configUpload.type)
220
+ return false
221
+ }
222
+
223
+ return res
224
+ }
225
+ const resUpload = await upload(configUpload, uploadParams, 0, !! backupParams)
226
+ if (resUpload === false) {
227
+ return false
228
+ }
229
+
230
+ // 是否已备份
231
+ let is_backup = 0
232
+
233
+ // 上传至备份服务器
234
+ // --------------------------------------------------
235
+ if (backupParams) {
236
+ const res = await upload(backupConfig, backupParams, 50, true)
237
+ if (res === false) {
238
+ return false
239
+ }
240
+ is_backup = 1
241
+ }
242
+ // --------------------------------------------------
243
+
244
+ const {
245
+ title,
246
+ type,
247
+ hash,
248
+ ext,
249
+ size,
250
+ json,
251
+ } = fileItem
252
+
253
+ // 请求 - 上传文件至 cdn
254
+ const { status: statusCallback, data: resCallback } = await $n_http({
255
+ url: $n_config('apiFileUrl') + 'upload_callback',
256
+ data: {
257
+ // 类型
258
+ type: configUpload.type,
259
+ // 需上传的文件类型
260
+ file_type: fileType,
261
+ // 文件
262
+ file: {
263
+ // 标题
264
+ title: title || '',
265
+ // 类型
266
+ type,
267
+ // hash
268
+ hash,
269
+ // 后缀
270
+ ext,
271
+ // 文件大小
272
+ size,
273
+ // 文件 json
274
+ json,
275
+ // 是否已备份
276
+ is_backup,
277
+ },
278
+ // 结果
279
+ result: $n_isValidObject(resUpload) ? resUpload : {},
280
+ },
281
+ // 关闭错误提示
282
+ warn: false,
283
+ })
284
+
285
+ // 请求失败
286
+ if (! statusCallback || ! $n_isValidObject(resCallback)) {
287
+ // 设置文件上传失败
288
+ setFileFail(fileItem, resCallback.msg || '上传失败')
289
+ return false
290
+ }
291
+
292
+ // 格式化 json
293
+ const _json = $n_json.parse(resCallback.json)
294
+ Object.assign(fileItem, resCallback, {
295
+ json: $n_isValidObject(_json) ? $n_numberDeep(_json) : {},
296
+ })
297
+
298
+ // 设置文件上传成功
299
+ setFileSuccess(fileItem)
300
+
301
+ return true
302
+ }
303
+ }
@@ -1,6 +0,0 @@
1
- /**
2
- * 七牛云上传
3
- */
4
- export default async function () {
5
-
6
- }
@@ -1,8 +0,0 @@
1
- /**
2
- * 七牛云上传
3
- */
4
- export default async function () {
5
-
6
-
7
-
8
- }
@@ -1,320 +0,0 @@
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
- await uploadFileItem(fileItem, token)
69
- }
70
-
71
- /**
72
- * 上传单个文件
73
- */
74
- async function uploadFileItem(fileItem, token) {
75
-
76
- // 设置文件状态
77
- fileItem.status = UPLOAD_STATUS.uploading
78
-
79
- // 请求上传文件到七牛云
80
- const { status, data: resUpload } = await $n_http({
81
- // 上传地址
82
- url: 'https://upload.qiniup.com/',
83
- // 数据
84
- data: {
85
- // 七牛云上传 token
86
- token,
87
- // 文件
88
- file: fileItem.file,
89
- // 自定义文件 key
90
- key: fileItem.hash,
91
- },
92
- // 关闭错误提醒
93
- warn: false,
94
- // 关闭检查结果 code
95
- checkCode: false,
96
- // 不包含头部鉴权认证
97
- token: false,
98
- // 开启上传
99
- upload: true,
100
- // 取消请求
101
- onCancel(cancel) {
102
- // 设置中断上传
103
- fileItem.abort = function(msg) {
104
- cancel($n_isValidString(msg) ? msg : '已取消')
105
- }
106
- },
107
- // 监听上传进度
108
- onUploadProgress(percent) {
109
- // 设置上传进度
110
- fileItem.progress = percent
111
- },
112
- })
113
-
114
- // 如果请求失败
115
- if (! status) {
116
- // 设置文件上传失败
117
- setFileFail(fileItem, resUpload.msg)
118
- return
119
- }
120
-
121
- // 如果检查七牛回调成功
122
- const query = await checkQiniuCallback(resUpload, fileItem)
123
- if (! query) {
124
- return
125
- }
126
-
127
- // 请求 - 上传文件至 cdn
128
- const { status: statusCallback, data: resCallback } = await $n_http({
129
- url: $n_config('apiFileUrl') + 'upload_cdn_callback',
130
- data: query,
131
- // 关闭错误提示
132
- warn: false,
133
- })
134
-
135
- // 请求失败
136
- if (! statusCallback) {
137
- // 设置文件上传失败
138
- setFileFail(fileItem, resCallback.msg || '上传失败')
139
- return
140
- }
141
-
142
- // 设置文件上传成功
143
- setFileSuccess(fileItem)
144
- }
145
-
146
- /**
147
- * 检查七牛回调成功
148
- */
149
- function checkQiniuCallback(res, fileItem) {
150
-
151
- // 如果文件被删除
152
- if ($n_findIndex(uploadFileLists.value, { hash: fileItem.hash }) === -1) {
153
- // 设置文件上传失败
154
- setFileFail(fileItem, '上传失败')
155
- return false
156
- }
157
-
158
- // 返回示例
159
- // ------------------------------
160
- // format: "null"
161
- // width: null
162
- // height: null
163
- // key: "d038dce5892840636b2c1f6d241f33ad"
164
- // hash: "lrYGlELBAgN9OgKV_i5gbHOdZMvt"
165
- // orientation: null
166
- // size: 6620454
167
- // aduration: 57.258005
168
- // vwidth: 1280
169
- // vheight: 720
170
- // vrotate: null
171
- // vduration: 57.291992
172
-
173
- const {
174
- format,
175
- width,
176
- height,
177
- key,
178
- orientation,
179
- size,
180
- aduration,
181
- vwidth,
182
- vheight,
183
- vrotate,
184
- vduration,
185
- } = res
186
-
187
- const query = {
188
- // 标题
189
- title: fileItem.title,
190
- // 类型(1:文件,2:图片,3:视频,4:音频)
191
- type: 0,
192
- // hash
193
- hash: key,
194
- // 文件大小
195
- size,
196
- // 后缀
197
- ext: fileItem.ext,
198
- }
199
-
200
- // json 信息
201
- const json = {}
202
-
203
- // 【1】先判断是否为视频(有时长 && 有宽 && 有高 && 时长 > 0, 则为视频)
204
- if (vduration && vwidth && vheight) {
205
-
206
- // 类型(3:视频)
207
- query.type = 3
208
-
209
- // 视频旋转角度
210
- // vrotate: 无 ==> 1: 手机右横屏(宽高不变)
211
- // vrotate: 90 ==> 2: 手机垂直(宽高反转)
212
- // vrotate: 180 ==> 3: 手机左横屏(宽高不变)
213
- // vrotate: 270 ==> 4: 手机倒过来垂直(宽高反转)
214
- const rotates = {
215
- 90: 2,
216
- 180: 3,
217
- 270: 4,
218
- }
219
-
220
- // 设置 json 信息
221
- Object.assign(json, {
222
- w: vwidth,
223
- h: vheight,
224
- d: vduration,
225
- })
226
-
227
- if ($n_has(rotates, vrotate)) {
228
- json.o = rotates[vrotate]
229
- }
230
-
231
- // 【2】再判断是否为音频(有音频时长 && 无视频时长 && 音频时长 > 0, 则为音频)
232
- } else if (aduration && ! vduration) {
233
-
234
- // 类型(4:音频)
235
- query.type = 4
236
-
237
- // 设置 json 信息
238
- json.d = aduration
239
-
240
- // 【3】再判断是否为图片(有宽 && 有高 && 大小 < 20M, 为图片)
241
- } else if (width && height) {
242
-
243
- // 类型(2:图片)
244
- query.type = 2
245
-
246
- // 图片后缀名
247
- query.ext = format === 'jpeg' ? 'jpg' : format
248
-
249
- // 如果大小 < 20M, 则为可用图片
250
- if (size < 20971520) {
251
-
252
- // 设置 json 数据
253
- json.w = width
254
- json.h = height
255
-
256
- // 图片垂直角度
257
- const orientations = {
258
- // 【1】相机原始位置(宽高不变)
259
- // 'top-left': 1,
260
- // 【2】等于 1 的垂直镜像(几乎无用)(宽高不变)
261
- 'top-right': 2,
262
- // 【3】旋转 180度(宽高不变)
263
- 'bottom-right': 3,
264
- // 【4】等于 3 的垂直镜像(几乎无用)(宽高不变)
265
- 'bottom-left': 4,
266
- // 【5】等于 8 的水平镜像(几乎无用)(宽高反转)
267
- 'left-top': 5,
268
- // 【6】旋转 90 度(宽高反转)
269
- 'right-top': 6,
270
- // 【7】等于 8 的垂直镜像(几乎无用)(宽高反转)
271
- 'right-bottom': 7,
272
- // 【8】旋转 270 度(宽高反转)
273
- 'left-bottom': 8,
274
- }
275
- if (orientation && $n_isString(orientation)) {
276
- const key = $n_trim(orientation).toLowerCase()
277
- if ($n_has(orientations, key)) {
278
- json.o = orientations[key]
279
- }
280
- }
281
-
282
- // 否则为类型为文件
283
- } else {
284
- // 检查文件错误
285
- const errMsg = checkFileError(query)
286
- if (errMsg) {
287
- // 设置文件上传失败
288
- setFileFail(fileItem, errMsg)
289
- return false
290
- }
291
-
292
- // 类型(1:文件)
293
- query.type = 1
294
- }
295
-
296
- // 否则为类型为文件
297
- } else {
298
- // 类型(1:文件)
299
- query.type = 1
300
- }
301
-
302
- // 检查文件错误
303
- const errMsg = checkFileError(query)
304
- if (errMsg) {
305
- // 设置文件上传失败
306
- setFileFail(fileItem, errMsg)
307
- return false
308
- }
309
-
310
- // json 信息
311
- query.json = json
312
-
313
- // 设置文件
314
- Object.assign(fileItem, query)
315
-
316
- return Object.assign({}, query, {
317
- json: $n_isValidObject(json) ? JSON.stringify(json) : ''
318
- })
319
- }
320
- }