[tool_uniapp.js] use wo.ss instead of wo.envar for frontend

This commit is contained in:
Luk
2026-04-21 19:49:10 +08:00
parent 4c95f401bc
commit 92ca0f339a
2 changed files with 27 additions and 25 deletions

View File

@@ -27,9 +27,11 @@ FETCH_HEAD
*/FETCH_HEAD
.Trash/
.Trashes/
.DS_Store
*/.DS_Store
*.aae # AAE 文件主要在苹果的照片应用程序中使用,保存对原始照片所做的编辑,比如,裁剪、旋转或调整亮度等操作的信息。
.thumbnails
*/.thumbnails

View File

@@ -39,19 +39,19 @@ module.exports = {
is_text_file (fileName = '') {
const ext = /\./.test(fileName) ? fileName.split('.').pop().toLowerCase() : ''
return wo.envar.textExtensionList?.includes?.(ext)
return wo.ss.textExtensionList?.includes?.(ext)
},
is_image_file (fileName = '') {
const ext = /\./.test(fileName) ? fileName.split('.').pop().toLowerCase() : ''
return wo.envar.imageExtensionList?.includes?.(ext)
return wo.ss.imageExtensionList?.includes?.(ext)
},
is_video_file (fileName = '') {
const ext = /\./.test(fileName) ? fileName.split('.').pop().toLowerCase() : ''
return wo.envar.videoExtensionList?.includes?.(ext)
return wo.ss.videoExtensionList?.includes?.(ext)
},
is_audio_file (fileName = '') {
const ext = /\./.test(fileName) ? fileName.split('.').pop().toLowerCase() : ''
return wo.envar.audioExtensionList?.includes?.(ext)
return wo.ss.audioExtensionList?.includes?.(ext)
},
thisPage () {
@@ -101,12 +101,12 @@ module.exports = {
windowTitle =
windowTitle ||
this.localizeText(wo?.envar?.callnames, { langCode: langNow }) ||
this.localizeText(wo?.ss?.callnames, { langCode: langNow }) ||
this.localizeText(wo?.pagesJson?.appInfo?.i18nText, { langCode: langNow }) ||
wo?.pagesJson?.globalStyle?.navigationBarTitleText ||
''
if (wo.envar._clientInfo.deviceType === 'pc') {
if (wo.ss._clientInfo.deviceType === 'pc') {
uni.setNavigationBarTitle({ title: windowTitle + (navibarTitle ? ` - ${navibarTitle}` : '') })
} else {
uni.setNavigationBarTitle({ title: navibarTitle })
@@ -116,7 +116,7 @@ module.exports = {
//// 设置窗口标题栏 document.title
//// navibarTitle 也会被用于浏览器的标签标题,可用 document.title 去覆盖。必须放在 setNavigationBarTitle 之后。
//// 但这个方案,在电脑上,还是会显示 navibarTitle 在浏览器窗口顶栏,不知为何。
if (wo.envar._clientInfo.deviceType !== 'pc' && /MicroMessenger/i.test(globalThis.window?.navigator?.userAgent)) {
if (wo.ss._clientInfo.deviceType !== 'pc' && /MicroMessenger/i.test(globalThis.window?.navigator?.userAgent)) {
//// 微信浏览器里,本身就显示了标题栏,和自有的导航栏形成功能重叠和混淆。
//// 设置标题栏为空或覆盖
document.title = windowTitle
@@ -125,7 +125,7 @@ module.exports = {
}
//#endif
if (wo.envar._clientInfo.deviceType === 'pc') {
if (wo.ss._clientInfo.deviceType === 'pc') {
uni.hideTabBar()
} else {
// 必须要在有 tab 的页面里 setTabBarItem 才有效果
@@ -146,7 +146,7 @@ module.exports = {
}
},
make_server_url (route, { envar = globalThis.wo?.envar, fullUrl = false } = {}) {
make_server_url (route, { envar = globalThis.wo?.ss, fullUrl = false } = {}) {
if (typeof route === 'string') route = route.replace('\\', '/')
else if (route?.apiWho && route?.apiTodo) {
const { apiVersion = 'api', apiWho, apiTodo } = route
@@ -196,7 +196,7 @@ module.exports = {
* - CLINET_WOBASE_EXCEPTION: 前端发现后台异常
**/
async callBase ({
baseType = globalThis.wo?.envar?.baseTypeDefault || this.BASE_TYPE_DEFAULT,
baseType = globalThis.wo?.ss?.baseTypeDefault || this.BASE_TYPE_DEFAULT,
httpMethod = 'POST',
apiVersion = 'api',
apiWho,
@@ -208,7 +208,7 @@ module.exports = {
const startTime = new Date().toJSON()
let apiurl = undefined
apiWhat._clientInfo = {
...globalThis.wo?.envar?._clientInfo,
...globalThis.wo?.ss?._clientInfo,
lang: globalThis.wo?.ss?.i18n?.mylang,
// #ifdef WEB
requrl: globalThis.location?.href,
@@ -386,7 +386,7 @@ module.exports = {
// https://uniapp.dcloud.net.cn/api/media/file.html
let [errorChoose, { tempFilePaths, tempFiles } = {}] = await uni.chooseFile({
count,
extension: wo.envar.audioExtensionList,
extension: wo.ss.audioExtensionList,
type: undefined,
}) // 20240429 但是测试下来 extension 参数无效
if (errorChoose) {
@@ -431,8 +431,8 @@ module.exports = {
_state: 'CER_EMPTY_FILE',
_msg: { zhCN: '文件为空,无法上传:\n' + fileName, enUS: 'Empty files cannot be uploaded:\n' + fileName },
}
} else if (fileSize > (globalThis.wo?.envar?.fileSizeLimit || 10485760)) {
let sizeLimitMB = parseInt((globalThis.wo?.envar?.fileSizeLimit || 10485760) / 1048576) + 'MB'
} else if (fileSize > (globalThis.wo?.ss?.fileSizeLimit || 10485760)) {
let sizeLimitMB = parseInt((globalThis.wo?.ss?.fileSizeLimit || 10485760) / 1048576) + 'MB'
return {
_state: 'CER_FILE_TOO_LARGE',
_msg: { zhCN: `文件大于 ${sizeLimitMB},无法上传`, enUS: `The file exceeds ${sizeLimitMB} and cannot be uploaded` },
@@ -520,7 +520,7 @@ module.exports = {
fileSize = fileDragged.size
filePath = fileDragged.filePath
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.ss._clientInfo.osName}_${random}_${path.extname(fileDragged.name || { image: '.jpg', video: '.mp4' }[mediaType] || '')}` // tempFile and name are H5 only
} else if (mediaType === 'image') {
let [errorChoose, { tempFilePaths, tempFiles } = {}] = await uni.chooseImage({ count, sizeType, sourceType })
if (errorChoose) {
@@ -535,10 +535,10 @@ module.exports = {
// #ifndef WEB
// 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 = `APP_${wo.envar._clientInfo.osName}_${random}${path.extname(filePath || '.jpg')}`
cloudPath = `APP_${wo.ss._clientInfo.osName}_${random}${path.extname(filePath || '.jpg')}`
// #endif
// #ifdef WEB
cloudPath = `WEB_${wo.envar._clientInfo.osName}_${random}${path.extname(tempFiles?.[0]?.name || '.jpg')}` // name is available in H5 only. 只包含文件名和后缀名,不包含路径。
cloudPath = `WEB_${wo.ss._clientInfo.osName}_${random}${path.extname(tempFiles?.[0]?.name || '.jpg')}` // name is available in H5 only. 只包含文件名和后缀名,不包含路径。
// #endif
} else if (mediaType === 'video') {
let [errorChoose, { tempFilePath, tempFile, duration, size, width, height, name }] = await uni.chooseVideo({ sourceType, maxDuration })
@@ -552,10 +552,10 @@ module.exports = {
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"
// #ifndef WEB
cloudPath = `APP_${wo.envar._clientInfo.osName}_${random}_dur${duration}${path.extname(filePath || '.mp4')}`
cloudPath = `APP_${wo.ss._clientInfo.osName}_${random}_dur${duration}${path.extname(filePath || '.mp4')}`
// #endif
// #ifdef WEB
cloudPath = `WEB_${wo.envar._clientInfo.osName}_${random}_dur${duration}${path.extname(name || '.mp4')}` // tempFile and name are H5 only
cloudPath = `WEB_${wo.ss._clientInfo.osName}_${random}_dur${duration}${path.extname(name || '.mp4')}` // tempFile and name are H5 only
// #endif
// iOS 上测试filePath 为 *.MOV而阿里云只允许 *.mp4, 所以默认添加 .mp4 后缀。参见 https://uniapp.dcloud.net.cn/uniCloud/storage?id=clouduploadfile
// 20200915测试阿里云支持上传 *.mov 了。
@@ -579,7 +579,7 @@ module.exports = {
fileSize = tempFiles?.[0]?.size
filePicked = tempFiles?.[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.ss._clientInfo.osName}_${random}${path.extname(tempFiles?.[0]?.name || '')}` // name is available in H5 only. 只包含文件名和后缀名,不包含路径。
// #endif
// #ifndef WEB
return { _state: 'UNSUPPORTED_FILETYPE', _msg: { zhCN: '请切换到网页端上传文件!', enUS: 'Please switch to Web App to upload files.' } }
@@ -590,8 +590,8 @@ module.exports = {
if (!fileSize) {
return { _state: 'CER_EMPTY_FILE', _msg: { zhCN: '文件为空,无法上传:\n' + fileName, enUS: 'Empty files cannot be uploaded:\n' + fileName } }
} else if (fileSize > (globalThis.wo?.envar?.fileSizeLimit || 10485760)) {
let sizeLimitMB = parseInt((globalThis.wo?.envar?.fileSizeLimit || 10485760) / 1048576) + 'MB'
} else if (fileSize > (globalThis.wo?.ss?.fileSizeLimit || 10485760)) {
let sizeLimitMB = parseInt((globalThis.wo?.ss?.fileSizeLimit || 10485760) / 1048576) + 'MB'
return {
_state: 'CER_FILE_TOO_LARGE',
_msg: { zhCN: `文件大于 ${sizeLimitMB},无法上传`, enUS: `The file exceeds ${sizeLimitMB} and cannot be uploaded` },
@@ -643,7 +643,7 @@ module.exports = {
},
async pickupFile ({
baseType = globalThis.wo?.envar?.baseTypeDefault || this.BASE_TYPE_DEFAULT,
baseType = globalThis.wo?.ss?.baseTypeDefault || this.BASE_TYPE_DEFAULT,
fileDragged,
mediaType = 'image', // could be image, video, array of supported extensions, anything else // 20240502 todo: rename to pickupFileType
count = 1,
@@ -669,7 +669,7 @@ module.exports = {
if (!url) {
return
}
if (wo.envar.inPc) {
if (wo.ss.inPc) {
window.open(url, '_blank')
} else if (inWebview) {
wo.ss.webviewUrl = url
@@ -695,7 +695,7 @@ module.exports = {
},
open_url_in_webview ({ url, title }) {
url = this.localizeText?.(url) || url
if (wo.envar.inPc) {
if (wo.ss.inPc) {
window.open(url, '_blank')
} else {
wo.ss.webviewUrl = url