rename clientInfo in frontend to _clientInfo

This commit is contained in:
Luk 2025-02-28 13:39:33 +08:00
parent 4e45a4e642
commit dce1e02085

View File

@ -99,7 +99,7 @@ module.exports = {
windowTitle = windowTitle =
windowTitle || wo?.envar?.callnames?.[langNow] || wo?.pagesJson?.appInfo?.i18nText?.[langNow] || wo?.pagesJson?.globalStyle?.navigationBarTitleText || '' windowTitle || wo?.envar?.callnames?.[langNow] || wo?.pagesJson?.appInfo?.i18nText?.[langNow] || wo?.pagesJson?.globalStyle?.navigationBarTitleText || ''
if (wo.envar.clientInfo.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 })
@ -109,7 +109,7 @@ module.exports = {
//// 设置窗口标题栏 document.title //// 设置窗口标题栏 document.title
//// navibarTitle 也会被用于浏览器的标签标题,可用 document.title 去覆盖。必须放在 setNavigationBarTitle 之后。 //// navibarTitle 也会被用于浏览器的标签标题,可用 document.title 去覆盖。必须放在 setNavigationBarTitle 之后。
//// 但这个方案,在电脑上,还是会显示 navibarTitle 在浏览器窗口顶栏,不知为何。 //// 但这个方案,在电脑上,还是会显示 navibarTitle 在浏览器窗口顶栏,不知为何。
if (wo.envar.clientInfo.deviceType !== 'pc' && /MicroMessenger/i.test(globalThis.window?.navigator?.userAgent)) { if (wo.envar._clientInfo.deviceType !== 'pc' && /MicroMessenger/i.test(globalThis.window?.navigator?.userAgent)) {
//// 微信浏览器里,本身就显示了标题栏,和自有的导航栏形成功能重叠和混淆。 //// 微信浏览器里,本身就显示了标题栏,和自有的导航栏形成功能重叠和混淆。
//// 设置标题栏为空或覆盖 //// 设置标题栏为空或覆盖
document.title = windowTitle document.title = windowTitle
@ -118,7 +118,7 @@ module.exports = {
} }
//#endif //#endif
if (wo.envar.clientInfo.deviceType === 'pc') { if (wo.envar._clientInfo.deviceType === 'pc') {
uni.hideTabBar() uni.hideTabBar()
} else { } else {
// 必须要在有 tab 的页面里 setTabBarItem 才有效果 // 必须要在有 tab 的页面里 setTabBarItem 才有效果
@ -197,7 +197,7 @@ module.exports = {
const startTime = new Date().toJSON() const startTime = new Date().toJSON()
let apiurl = undefined let apiurl = undefined
apiWhat._clientInfo = { apiWhat._clientInfo = {
...globalThis.wo?.envar?.clientInfo, ...globalThis.wo?.envar?._clientInfo,
lang: globalThis.wo?.ss?.i18n?.mylang, lang: globalThis.wo?.ss?.i18n?.mylang,
// #ifdef WEB // #ifdef WEB
requrl: globalThis.location?.href, requrl: globalThis.location?.href,
@ -482,7 +482,7 @@ module.exports = {
fileSize = fileDragged.size fileSize = fileDragged.size
filePath = fileDragged.filePath filePath = fileDragged.filePath
filePicked = fileDragged filePicked = fileDragged
cloudPath = `WEB_${wo.envar.clientInfo.osName}_${random}_${path.extname(fileDragged.name || { image: '.jpg', video: '.mp4' }[mediaType] || '')}` // tempFile and name are H5 only cloudPath = `WEB_${wo.envar._clientInfo.osName}_${random}_${path.extname(fileDragged.name || { image: '.jpg', video: '.mp4' }[mediaType] || '')}` // tempFile and name are H5 only
} else if (mediaType === 'image') { } else if (mediaType === 'image') {
let [errorChoose, { tempFilePaths, tempFiles } = {}] = await uni.chooseImage({ count, sizeType, sourceType }) let [errorChoose, { tempFilePaths, tempFiles } = {}] = await uni.chooseImage({ count, sizeType, sourceType })
if (errorChoose) { if (errorChoose) {
@ -497,10 +497,10 @@ module.exports = {
// #ifndef WEB // #ifndef WEB
// 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_${wo.envar.clientInfo.osName}_${random}${path.extname(filePath || '.jpg')}` cloudPath = `APP_${wo.envar._clientInfo.osName}_${random}${path.extname(filePath || '.jpg')}`
// #endif // #endif
// #ifdef WEB // #ifdef WEB
cloudPath = `WEB_${wo.envar.clientInfo.osName}_${random}${path.extname(tempFiles?.[0]?.name || '.jpg')}` // name is available in H5 only. 只包含文件名和后缀名,不包含路径。 cloudPath = `WEB_${wo.envar._clientInfo.osName}_${random}${path.extname(tempFiles?.[0]?.name || '.jpg')}` // 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 })
@ -514,10 +514,10 @@ module.exports = {
filePicked = tempFile filePicked = tempFile
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 WEB // #ifndef WEB
cloudPath = `APP_${wo.envar.clientInfo.osName}_${random}_dur${duration}${path.extname(filePath || '.mp4')}` cloudPath = `APP_${wo.envar._clientInfo.osName}_${random}_dur${duration}${path.extname(filePath || '.mp4')}`
// #endif // #endif
// #ifdef WEB // #ifdef WEB
cloudPath = `WEB_${wo.envar.clientInfo.osName}_${random}_dur${duration}${path.extname(name || '.mp4')}` // tempFile and name are H5 only cloudPath = `WEB_${wo.envar._clientInfo.osName}_${random}_dur${duration}${path.extname(name || '.mp4')}` // 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 了。
@ -541,7 +541,7 @@ module.exports = {
fileSize = tempFiles?.[0]?.size fileSize = tempFiles?.[0]?.size
filePicked = tempFiles?.[0] filePicked = tempFiles?.[0]
filePath = tempFilePaths?.[0] filePath = tempFilePaths?.[0]
cloudPath = `WEB_${wo.envar.clientInfo.osName}_${random}${path.extname(tempFiles?.[0]?.name || '')}` // name is available in H5 only. 只包含文件名和后缀名,不包含路径。 cloudPath = `WEB_${wo.envar._clientInfo.osName}_${random}${path.extname(tempFiles?.[0]?.name || '')}` // name is available in H5 only. 只包含文件名和后缀名,不包含路径。
// #endif // #endif
// #ifndef WEB // #ifndef WEB
return { _state: 'UNSUPPORTED_FILETYPE', _msg: { zhCN: '请切换到网页端上传文件!', enUS: 'Please switch to WebApp to upload files.' } } return { _state: 'UNSUPPORTED_FILETYPE', _msg: { zhCN: '请切换到网页端上传文件!', enUS: 'Please switch to WebApp to upload files.' } }
@ -668,20 +668,30 @@ module.exports = {
parse_ua_to_browser () { parse_ua_to_browser () {
// #ifdef WEB // #ifdef WEB
let userAgent = globalThis.window?.navigator?.userAgent?.toLowerCase?.() let ua = globalThis.window?.navigator?.userAgent?.toLowerCase?.()
return /msie/.test(userAgent) && !/opera/.test(userAgent) if (/msie/.test(ua) && !/opera/.test(ua)) {
? 'msie' return 'msie'
: /opera/.test(userAgent) } else if (/opera/.test(ua)) {
? 'opera' return 'opera'
: /version.*safari/.test(userAgent) } else if (/version.*safari/.test(ua)) {
? 'safari' return 'safari'
: /chrome/.test(userAgent) } else if (/chrome/.test(ua)) {
? 'chrome' return 'chrome'
: /gecko/.test(userAgent) && !/webkit/.test(userAgent) } else if (/gecko/.test(ua) && !/webkit/.test(ua)) {
? 'firefox' return 'firefox'
: /micromessenger/.test(userAgent) } else if (ua.match(/MicroMessenger/i) == 'micromessenger' && ua.match(/miniprogram/i) == 'miniprogram') {
? 'wechat' // 微信小程序
: 'unknown' // 只要在 H5, 即使不认识也要返回一个名称。 return 'wechat_mp'
} else if (/micromessenger/.test(ua)) {
// 微信公众号或微信浏览器
return 'wechat'
} else if (ua.match(/alipay/i) == 'alipay' && ua.match(/miniprogram/i) == 'miniprogram') {
return 'alipay_mp'
} else if (ua.match(/alipay/i) == 'alipay') {
return 'alipay'
} else {
return 'unknown' // 只要在 H5, 即使不认识也要返回一个名称。
}
// #endif // #endif
return '' // 如果不在 H5。 return '' // 如果不在 H5。
}, },
@ -727,16 +737,17 @@ module.exports = {
mytoast?.show?.({ type, title, duration, ...rest }) mytoast?.show?.({ type, title, duration, ...rest })
} else { } else {
// #ifdef APP // #ifdef APP
uni.showToast({ icon: 'none', title, duration, ...rest }) uni.showToast({ icon: ['error', 'success'].includes(type) ? type : 'none', title, duration, ...rest })
// plus.nativeUI.toast( title, { align: center/left/right, verticalAlign: bottom/center/top, duration:long/short, icon, iconWidth, iconHeight, style: block/inline, type:text/richtext }) // plus.nativeUI.toast( title, { align: center/left/right, verticalAlign: bottom/center/top, duration:long/short, icon, iconWidth, iconHeight, style: block/inline, type:text/richtext })
// #endif // #endif
// #ifndef APP // #ifndef APP
uni.showToast({ icon: 'none', image, title, duration, ...rest }) uni.showToast({ icon: ['error', 'success'].includes(type) ? type : 'none', image, title, duration, ...rest })
// #endif // #endif
} }
}, },
showModal (option = {}) { showModal (option = {}) {
option = { ...option } // 避免在 option 里直接增删。
option.title = this.localizeText(option.title) option.title = this.localizeText(option.title)
option.content = option.content =
(uni.getSystemInfoSync().uniPlatform === 'app' ? '\n' : '') + this.localizeText(option.content)?.substring?.(0, option.contentLength || 300) (uni.getSystemInfoSync().uniPlatform === 'app' ? '\n' : '') + this.localizeText(option.content)?.substring?.(0, option.contentLength || 300)