use wo.envar.clientInfo.* instead of uni.getSystemInfoSync()
This commit is contained in:
parent
3da2705fe2
commit
5fc9b3ef1c
38
unitool.js
38
unitool.js
@ -74,7 +74,7 @@ export default {
|
|||||||
wo?.pagesJson?.globalStyle?.navigationBarTitleText ||
|
wo?.pagesJson?.globalStyle?.navigationBarTitleText ||
|
||||||
''
|
''
|
||||||
|
|
||||||
if (uni.getSystemInfoSync().deviceType === 'pc') {
|
if (wo.envar.clientInfo.deviceType === 'pc') {
|
||||||
uni.setNavigationBarTitle({ title: windowTitle + (navibarTitle ? ` - ${navibarTitle}` : '') })
|
uni.setNavigationBarTitle({ title: windowTitle + (navibarTitle ? ` - ${navibarTitle}` : '') })
|
||||||
} else {
|
} else {
|
||||||
uni.setNavigationBarTitle({ title: navibarTitle })
|
uni.setNavigationBarTitle({ title: navibarTitle })
|
||||||
@ -84,7 +84,7 @@ export default {
|
|||||||
//// 设置窗口标题栏 document.title
|
//// 设置窗口标题栏 document.title
|
||||||
//// navibarTitle 也会被用于浏览器的标签标题,可用 document.title 去覆盖。必须放在 setNavigationBarTitle 之后。
|
//// navibarTitle 也会被用于浏览器的标签标题,可用 document.title 去覆盖。必须放在 setNavigationBarTitle 之后。
|
||||||
//// 但这个方案,在电脑上,还是会显示 navibarTitle 在浏览器窗口顶栏,不知为何。
|
//// 但这个方案,在电脑上,还是会显示 navibarTitle 在浏览器窗口顶栏,不知为何。
|
||||||
if (uni.getSystemInfoSync().deviceType === 'phone' && /MicroMessenger/i.test(globalThis.window?.navigator?.userAgent)) {
|
if (wo.envar.clientInfo.deviceType === 'phone' && /MicroMessenger/i.test(globalThis.window?.navigator?.userAgent)) {
|
||||||
//// 微信浏览器里,本身就显示了标题栏,和自有的导航栏形成功能重叠和混淆。
|
//// 微信浏览器里,本身就显示了标题栏,和自有的导航栏形成功能重叠和混淆。
|
||||||
//// 设置标题栏为空或覆盖
|
//// 设置标题栏为空或覆盖
|
||||||
document.title = windowTitle
|
document.title = windowTitle
|
||||||
@ -93,7 +93,7 @@ export default {
|
|||||||
}
|
}
|
||||||
//#endif
|
//#endif
|
||||||
|
|
||||||
if (uni.getSystemInfoSync().deviceType === 'pc') {
|
if (wo.envar.clientInfo.deviceType === 'pc') {
|
||||||
uni.hideTabBar()
|
uni.hideTabBar()
|
||||||
} else {
|
} else {
|
||||||
// 必须要在有 tab 的页面里 setTabBarItem 才有效果
|
// 必须要在有 tab 的页面里 setTabBarItem 才有效果
|
||||||
@ -167,8 +167,7 @@ export default {
|
|||||||
const thisRoute = getCurrentPages()?.pop?.()?.route || 'VueApp' // 立刻保存 route,因为在调用后台后,可能已切换到了其他页面。
|
const thisRoute = getCurrentPages()?.pop?.()?.route || 'VueApp' // 立刻保存 route,因为在调用后台后,可能已切换到了其他页面。
|
||||||
const startTime = new Date().toJSON()
|
const startTime = new Date().toJSON()
|
||||||
let url = undefined
|
let url = undefined
|
||||||
let { uniPlatform, deviceType, osName } = uni.getSystemInfoSync()
|
apiWhat._clientInfo = globalThis.wo?.envar?.clientInfo
|
||||||
apiWhat._clientInfo = { uniPlatform, deviceType, osName, url: globalThis.location?.href }
|
|
||||||
apiWhat._passtoken = uni.getStorageSync('_passtoken')
|
apiWhat._passtoken = uni.getStorageSync('_passtoken')
|
||||||
let result = {}
|
let result = {}
|
||||||
if (baseType === 'UNICLOUD_OBJECT') {
|
if (baseType === 'UNICLOUD_OBJECT') {
|
||||||
@ -269,14 +268,14 @@ export default {
|
|||||||
let filePath
|
let filePath
|
||||||
if (mediaType === 'image') {
|
if (mediaType === 'image') {
|
||||||
let [errorChoose, { tempFilePaths, tempFiles } = {}] = await uni.chooseImage({ count, sizeType, sourceType })
|
let [errorChoose, { tempFilePaths, tempFiles } = {}] = await uni.chooseImage({ count, sizeType, sourceType })
|
||||||
filePath = tempFilePaths[0]
|
filePath = tempFilePaths?.[0]
|
||||||
} else if (mediaType === 'video') {
|
} else if (mediaType === 'video') {
|
||||||
let [errorChoose, { tempFilePath }] = await uni.chooseVideo({ sourceType })
|
let [errorChoose, { tempFilePath }] = await uni.chooseVideo({ sourceType })
|
||||||
filePath = tempFilePath
|
filePath = tempFilePath
|
||||||
} else {
|
} else {
|
||||||
// #ifdef H5
|
// #ifdef H5
|
||||||
let [errorChoose, { tempFilePaths, tempFiles } = {}] = await uni.chooseFile({ count, type: 'all' })
|
let [errorChoose, { tempFilePaths, tempFiles } = {}] = await uni.chooseFile({ count, type: 'all' })
|
||||||
filePath = tempFilePaths[0]
|
filePath = tempFilePaths?.[0]
|
||||||
// #endif
|
// #endif
|
||||||
// #ifndef H5
|
// #ifndef H5
|
||||||
return { _state: 'UNKNOWN_MEDIATYPE' }
|
return { _state: 'UNKNOWN_MEDIATYPE' }
|
||||||
@ -291,11 +290,11 @@ export default {
|
|||||||
// 在 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 加回这一句,让后台可以根据验证用户来决定怎样处理文件。
|
||||||
|
|
||||||
uni.showLoading()
|
this.showLoading()
|
||||||
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 })
|
||||||
// 后台 Multer 处理 req.file = { destination, filename, originalname, path, mimetype, size }, 其中 path 包括了 destination 和 filename 的文件相对路径。
|
// 后台 Multer 处理 req.file = { destination, filename, originalname, path, mimetype, size }, 其中 path 包括了 destination 和 filename 的文件相对路径。
|
||||||
// url 指向的后台方法进一步处理后,通过 uni.uploadFile 存在 data 里返回结果: { ...file, cid?, ipfsUrl?, baseUrl? }
|
// url 指向的后台方法进一步处理后,通过 uni.uploadFile 存在 data 里返回结果: { ...file, cid?, ipfsUrl?, baseUrl? }
|
||||||
uni.hideLoading()
|
this.hideLoading()
|
||||||
|
|
||||||
if (typeof data === 'string') {
|
if (typeof data === 'string') {
|
||||||
// 不知为何,uni.uploadFile返回的 data 是字符串而不是对象
|
// 不知为何,uni.uploadFile返回的 data 是字符串而不是对象
|
||||||
@ -323,9 +322,7 @@ export default {
|
|||||||
// return { _state: 'USER_OFFLINE', errMsg: 'offline user cannot upload files' }
|
// return { _state: 'USER_OFFLINE', errMsg: 'offline user cannot upload files' }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
let filePath,
|
let filePath, cloudPath
|
||||||
cloudPath,
|
|
||||||
osName = uni.getSystemInfoSync().osName
|
|
||||||
if (mediaType === 'image') {
|
if (mediaType === 'image') {
|
||||||
let [errorChoose, { tempFilePaths, tempFiles } = {}] = await uni.chooseImage({ count, sizeType, sourceType })
|
let [errorChoose, { tempFilePaths, tempFiles } = {}] = await uni.chooseImage({ count, sizeType, sourceType })
|
||||||
// uni.showModal({ title: 'tempFilePaths[0]=' + tempFilePaths[0] })
|
// uni.showModal({ title: 'tempFilePaths[0]=' + tempFilePaths[0] })
|
||||||
@ -333,20 +330,20 @@ export default {
|
|||||||
// #ifndef H5
|
// #ifndef H5
|
||||||
// let [errorGetImageInfo, { path, width, height, orientation, type }] = await uni.getImageInfo({ src: filePath })
|
// let [errorGetImageInfo, { path, width, height, orientation, type }] = await uni.getImageInfo({ src: filePath })
|
||||||
// cloudPath = path // 完整路径,包含后缀名。形如 file:///var/mobile/Containers/Data/Application/55A76332-44F5-4D5F-A9F6-3F857D584883/Documents/Pandora/apps/D064A425A8BEC13F9D8F741B98B37BC5/doc/uniapp_temp_1598593902955/compressed/1598593925815.png
|
// cloudPath = path // 完整路径,包含后缀名。形如 file:///var/mobile/Containers/Data/Application/55A76332-44F5-4D5F-A9F6-3F857D584883/Documents/Pandora/apps/D064A425A8BEC13F9D8F741B98B37BC5/doc/uniapp_temp_1598593902955/compressed/1598593925815.png
|
||||||
cloudPath = `APP_${osName}__${filePath}` // 在 iOS 上是 "_doc/uniapp_temp_1598593902955/compressed/1598593925815.png", 有时还包含从 file:/// 开始的完整路径名
|
cloudPath = `APP__${filePath}` // 在 iOS 上是 "_doc/uniapp_temp_1598593902955/compressed/1598593925815.png", 有时还包含从 file:/// 开始的完整路径名
|
||||||
// #endif
|
// #endif
|
||||||
// #ifdef H5
|
// #ifdef H5
|
||||||
cloudPath = `H5_${osName}_${this.parse_ua_to_browser()}__${tempFiles[0].name}` // name is available in H5 only. 只包含文件名和后缀名,不包含路径。
|
cloudPath = `H5__${tempFiles[0].name}` // name is available in H5 only. 只包含文件名和后缀名,不包含路径。
|
||||||
// #endif
|
// #endif
|
||||||
} else if (mediaType === 'video') {
|
} else if (mediaType === 'video') {
|
||||||
let [errorChoose, { tempFilePath, tempFile, duration, size, width, height, name }] = await uni.chooseVideo({ sourceType, maxDuration })
|
let [errorChoose, { tempFilePath, tempFile, duration, size, width, height, name }] = await uni.chooseVideo({ sourceType, maxDuration })
|
||||||
// uni.showModal({ title: 'tempFilePath=' + tempFilePath })
|
// uni.showModal({ title: 'tempFilePath=' + tempFilePath })
|
||||||
filePath = tempFilePath // 在 iOS 上形如 "file:///var/mobile/Containers/Data/Application/55A76332-44F5-4D5F-A9F6-3F857D584883/Documents/Pandora/apps/26B43CD2F587D37FC6799108434A6F84/doc/uniapp_temp_1598596171580/gallery/IMG_3082.MOV"
|
filePath = tempFilePath // 在 iOS 上形如 "file:///var/mobile/Containers/Data/Application/55A76332-44F5-4D5F-A9F6-3F857D584883/Documents/Pandora/apps/26B43CD2F587D37FC6799108434A6F84/doc/uniapp_temp_1598596171580/gallery/IMG_3082.MOV"
|
||||||
// #ifndef H5
|
// #ifndef H5
|
||||||
cloudPath = `APP_${osName}_dur${duration}__${filePath}`
|
cloudPath = `APP__dur${duration}__${filePath}`
|
||||||
// #endif
|
// #endif
|
||||||
// #ifdef H5
|
// #ifdef H5
|
||||||
cloudPath = `H5_${osName}_${this.parse_ua_to_browser()}_dur${duration}__${name}` // tempFile and name are H5 only
|
cloudPath = `H5__dur${duration}__${name}` // tempFile and name are H5 only
|
||||||
// #endif
|
// #endif
|
||||||
// iOS 上测试,filePath 为 *.MOV,而阿里云只允许 *.mp4, 所以添加 .mp4 后缀。参见 https://uniapp.dcloud.net.cn/uniCloud/storage?id=clouduploadfile
|
// iOS 上测试,filePath 为 *.MOV,而阿里云只允许 *.mp4, 所以添加 .mp4 后缀。参见 https://uniapp.dcloud.net.cn/uniCloud/storage?id=clouduploadfile
|
||||||
// 20200915测试,阿里云支持上传 *.mov 了。
|
// 20200915测试,阿里云支持上传 *.mov 了。
|
||||||
@ -367,7 +364,7 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (filePath) {
|
if (filePath) {
|
||||||
uni.showLoading()
|
this.showLoading()
|
||||||
const { fileID, requestId } = await uniCloud.uploadFile({
|
const { fileID, requestId } = await uniCloud.uploadFile({
|
||||||
filePath: filePath,
|
filePath: filePath,
|
||||||
cloudPath: process.env.NODE_ENV !== 'production' ? 'dev_' + cloudPath : cloudPath, // 关键是要具有文件格式后缀名,这样可以保持阿里云下载链接也用这个后缀名。
|
cloudPath: process.env.NODE_ENV !== 'production' ? 'dev_' + cloudPath : cloudPath, // 关键是要具有文件格式后缀名,这样可以保持阿里云下载链接也用这个后缀名。
|
||||||
@ -376,7 +373,7 @@ export default {
|
|||||||
var percentCompleted = Math.round((progressEvent.loaded * 100) / progressEvent.total)
|
var percentCompleted = Math.round((progressEvent.loaded * 100) / progressEvent.total)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
uni.hideLoading()
|
this.hideLoading()
|
||||||
|
|
||||||
if (fileID) {
|
if (fileID) {
|
||||||
return { _state: 'SUCCESS', fileUrl: fileID, requestId }
|
return { _state: 'SUCCESS', fileUrl: fileID, requestId }
|
||||||
@ -419,7 +416,7 @@ export default {
|
|||||||
|
|
||||||
parse_ua_to_browser () {
|
parse_ua_to_browser () {
|
||||||
// #ifdef H5
|
// #ifdef H5
|
||||||
userAgent = window.navigator.userAgent.toLowerCase()
|
let userAgent = globalThis.window?.navigator?.userAgent?.toLowerCase?.()
|
||||||
return /msie/.test(userAgent) && !/opera/.test(userAgent)
|
return /msie/.test(userAgent) && !/opera/.test(userAgent)
|
||||||
? 'msie'
|
? 'msie'
|
||||||
: /opera/.test(userAgent)
|
: /opera/.test(userAgent)
|
||||||
@ -479,7 +476,8 @@ export default {
|
|||||||
// #endif
|
// #endif
|
||||||
},
|
},
|
||||||
|
|
||||||
showLoading ({ title, mask }) {
|
showLoading ({ title = { zhCN: '加载中...', enUS: 'Loading...' }, mask } = {}) {
|
||||||
|
title = this.localizeText(title)
|
||||||
// #ifndef APP-PLUS
|
// #ifndef APP-PLUS
|
||||||
uni.showLoading({ title, mask })
|
uni.showLoading({ title, mask })
|
||||||
// #endif
|
// #endif
|
||||||
|
Loading…
Reference in New Issue
Block a user