localizeText accepts 'earTH', 'defLAN', 'gloBAL' as default language
This commit is contained in:
parent
948e16cc91
commit
fa4bcb4fc6
20
unitool.js
20
unitool.js
@ -64,7 +64,8 @@ module.exports = {
|
|||||||
return (
|
return (
|
||||||
i18nText?.[my.langNow()] ||
|
i18nText?.[my.langNow()] ||
|
||||||
i18nText?.earTH ||
|
i18nText?.earTH ||
|
||||||
i18nText?.defauLT ||
|
i18nText?.defLAN ||
|
||||||
|
i18nText?.gloBAL ||
|
||||||
i18nText?.enUS ||
|
i18nText?.enUS ||
|
||||||
(['string', 'number', 'boolean'].includes(typeof i18nText) ? i18nText : '')
|
(['string', 'number', 'boolean'].includes(typeof i18nText) ? i18nText : '')
|
||||||
) // 必须检测是否标量值,如果直接返回 i18nText 可能返回{}等,导致依赖于返回空值的前端出错
|
) // 必须检测是否标量值,如果直接返回 i18nText 可能返回{}等,导致依赖于返回空值的前端出错
|
||||||
@ -314,7 +315,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
async pickupFile2Server ({
|
async pickupFile2Server ({
|
||||||
fileDragged,
|
fileDragged, // 形如 { filePath: "blob:http://localhost:8080/218e3007-f74b-440d-a2db-8f1d9aed746f", name: 'abc.txt', size: 2375, type: "text/plain", lastModified: 1732291306772 }
|
||||||
mediaType = 'image', // could be: image, video, array of supported extensions, anything else
|
mediaType = 'image', // could be: image, video, array of supported extensions, anything else
|
||||||
count = 1,
|
count = 1,
|
||||||
sizeType = ['original', 'compressed'],
|
sizeType = ['original', 'compressed'],
|
||||||
@ -328,6 +329,7 @@ module.exports = {
|
|||||||
|
|
||||||
let filePath, fileSize, filePicked
|
let filePath, fileSize, filePicked
|
||||||
if ('undefined' !== typeof fileDragged?.size) {
|
if ('undefined' !== typeof fileDragged?.size) {
|
||||||
|
// size 为 0 的时候也该要做这些处理
|
||||||
fileSize = fileDragged.size
|
fileSize = fileDragged.size
|
||||||
filePath = fileDragged.filePath
|
filePath = fileDragged.filePath
|
||||||
filePicked = fileDragged
|
filePicked = fileDragged
|
||||||
@ -416,7 +418,8 @@ module.exports = {
|
|||||||
formData[key] = JSON.stringify(formData[key])
|
formData[key] = JSON.stringify(formData[key])
|
||||||
}
|
}
|
||||||
// 在 Fileloader/fileloader.js 里,已经不再依赖 _passtoken,而且 header 在被 nginx 或 cloudflare (没搞清楚是谁干的)代理之后也被过滤掉了,因此不再使用这一句: header._passtoken = uni.getStorageSync('_passtoken')
|
// 在 Fileloader/fileloader.js 里,已经不再依赖 _passtoken,而且 header 在被 nginx 或 cloudflare (没搞清楚是谁干的)代理之后也被过滤掉了,因此不再使用这一句: header._passtoken = uni.getStorageSync('_passtoken')
|
||||||
formData['_passtoken'] = uni.getStorageSync('_passtoken') // 20230527 加回这一句,让后台可以根据验证用户来决定怎样处理文件。
|
formData._passtoken = uni.getStorageSync('_passtoken') // 20230527 加回这一句,让后台可以根据验证用户来决定怎样处理文件。
|
||||||
|
formData.filenameOriginal = fileName // 20241020 不知为何,通过拖拽的文件上传后,后台得到的 file.originalname 形如 "file-1729354713176" 而不是真正的原始文件名,也不包含后缀。为了保持一致,这里主动把真实的文件名(不管是拖拽还是点击的)发给后台来处理。
|
||||||
|
|
||||||
this.showLoading({ title: { zhCN: '上传中...', enUS: 'Uploading...' } })
|
this.showLoading({ title: { zhCN: '上传中...', enUS: 'Uploading...' } })
|
||||||
let [errorUpload, { data, statusCode } = {}] = await uni.uploadFile({ url: this.make_server_url(url), filePath, name, header, formData })
|
let [errorUpload, { data, statusCode } = {}] = await uni.uploadFile({ url: this.make_server_url(url), filePath, name, header, formData })
|
||||||
@ -428,11 +431,12 @@ module.exports = {
|
|||||||
// 不知为何,uni.uploadFile返回的 data 是字符串而不是对象
|
// 不知为何,uni.uploadFile返回的 data 是字符串而不是对象
|
||||||
try {
|
try {
|
||||||
data = JSON.parse(data)
|
data = JSON.parse(data)
|
||||||
if (fileDragged?.name) {
|
// 注释下面几句,改由后台来处理 filenameOriginal 以把正确的 data.originalname 返回给前端
|
||||||
// 20241020 不知为何,通过拖拽的文件上传后,得到的结果里 originalname 形如 "file-1729354713176" 而不是真正的原始文件名,也不包含后缀。为了保持一致,这里强行重新设置
|
// if (fileDragged?.name) {
|
||||||
data.originalnameSystem = data.originalname
|
// // 20241020 不知为何,通过拖拽的文件上传后,后台得到的 以及返回的 data.originalname 形如 "file-1729354713176" 而不是真正的原始文件名,也不包含后缀。为了保持一致,这里强行重新设置
|
||||||
data.originalname = fileDragged.name
|
// data.originalnameSystem = data.originalname
|
||||||
}
|
// data.originalname = fileDragged.name
|
||||||
|
// }
|
||||||
} catch (exp) {
|
} catch (exp) {
|
||||||
return {
|
return {
|
||||||
_state: 'BER_FAIL_RESPONSE_JSON_MALFORMED',
|
_state: 'BER_FAIL_RESPONSE_JSON_MALFORMED',
|
||||||
|
Loading…
Reference in New Issue
Block a user