Compare commits
12 Commits
dd3cedcd23
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
92ca0f339a | ||
|
|
4c95f401bc | ||
| 95c5416959 | |||
|
|
f9ffbb4989 | ||
|
|
0c05bfd464 | ||
| 612f8ed85e | |||
| 27cc887045 | |||
|
|
5f3cc1fb12 | ||
|
|
fc146dc10d | ||
|
|
3e52b5a9f4 | ||
|
|
280cba80d6 | ||
|
|
df386d8266 |
@@ -22,8 +22,16 @@
|
||||
*.nosf/
|
||||
*.nosf.*/
|
||||
|
||||
## everything 'git pull or fetch' will update `.git/FETCH_HEAD`, even if the content doesn't change. To avoid too many useless updates of this file in Seafile history:
|
||||
FETCH_HEAD
|
||||
*/FETCH_HEAD
|
||||
|
||||
.Trash/
|
||||
.Trashes/
|
||||
|
||||
.DS_Store
|
||||
*/.DS_Store
|
||||
*.aae # AAE 文件主要在苹果的照片应用程序中使用,保存对原始照片所做的编辑,比如,裁剪、旋转或调整亮度等操作的信息。
|
||||
|
||||
.thumbnails
|
||||
*/.thumbnails
|
||||
@@ -48,12 +56,18 @@ _desktop.ini
|
||||
node_modules/
|
||||
*/node_modules/
|
||||
package-lock.json
|
||||
*/package-lock.json
|
||||
|
||||
pages4loader.json5
|
||||
*/pages4loader.json5
|
||||
|
||||
.deploy_git/
|
||||
*/.deploy_git/
|
||||
|
||||
# next.js 项目
|
||||
.next/
|
||||
*/.next/
|
||||
|
||||
# HBuilder 目录
|
||||
unpackage/
|
||||
*/unpackage/
|
||||
|
||||
67
tool_core.js
67
tool_core.js
@@ -38,27 +38,50 @@ module.exports = {
|
||||
return obj
|
||||
},
|
||||
|
||||
parse_json (value, { failsafe } = {}) {
|
||||
failsafe = typeof failsafe !== 'undefined' ? failsafe : value
|
||||
if (typeof value === 'object') return value
|
||||
else if (typeof value === 'string') {
|
||||
try {
|
||||
return JSON.parse(value)
|
||||
} catch (e) {
|
||||
return failsafe
|
||||
}
|
||||
} else {
|
||||
return failsafe
|
||||
}
|
||||
},
|
||||
|
||||
parse_json_anyway (value) {
|
||||
if (typeof value === 'object') return value
|
||||
else if (typeof value === 'string') {
|
||||
try {
|
||||
return JSON.parse(value)
|
||||
} catch (e) {
|
||||
return undefined
|
||||
}
|
||||
} else {
|
||||
return undefined
|
||||
}
|
||||
},
|
||||
|
||||
parse_json_or_keep (value) {
|
||||
if (typeof value === 'object') return value
|
||||
else if (typeof value === 'string') {
|
||||
try {
|
||||
return JSON.parse(value)
|
||||
} catch (e) {
|
||||
return value
|
||||
}
|
||||
} else {
|
||||
return value
|
||||
}
|
||||
},
|
||||
|
||||
// 按顺序展开,哪怕嵌套。
|
||||
stringify_by_keyorder (obj, { cmp, cycles = false, space = '', replacer, schemaColumns, excludeKeys = [] } = {}) {
|
||||
/* 这个解决方法不考虑缺省值,不能把嵌套对象也按顺序展开。*/
|
||||
// return JSON.stringify(obj, Object.keys(schemaColumns || entity).sort().filter(key => ! excludeKeys.includes(key))) // JSON.stringify 可根据第二个数组参数的顺序排序,但这导致了嵌套对象不能按顺序展开。
|
||||
|
||||
let newObj = {}
|
||||
if (schemaColumns) {
|
||||
for (let key in schemaColumns) {
|
||||
@@ -191,8 +214,8 @@ module.exports = {
|
||||
return num
|
||||
},
|
||||
|
||||
hash_easy (data, { hasher = 'sha256', salt, input = 'utf8', output = 'hex' } = {}) {
|
||||
if (typeof data !== 'string' && !(data instanceof Buffer) && !(data instanceof DataView)) data = JSON.stringify(data)
|
||||
hash_stable (data, { hasher = 'sha256', salt, input = 'utf8', output = 'hex' } = {}) {
|
||||
if (typeof data !== 'string' && !(data instanceof Buffer) && !(data instanceof DataView)) data = this.stringify_by_keyorder(data)
|
||||
if (salt && typeof salt === 'string') data = data + salt
|
||||
const inputEncoding = input // my.INPUT_LIST.indexOf(option.input)>=0?option.input:my.INPUT // 'utf8', 'ascii' or 'latin1' for string data, default to utf8 if not specified; ignored for Buffer, TypedArray, or DataView.
|
||||
const outputEncoding = output === 'buf' ? undefined : output // (my.OUTPUT_LIST.indexOf(output)>=0?output:my.OUTPUT) // option.output: 留空=》默认输出hex格式;或者手动指定 'buf', hex', 'latin1' or 'base64'
|
||||
@@ -286,7 +309,10 @@ module.exports = {
|
||||
let parent = root || globalThis || global || window || {}
|
||||
let keychain = path.split('.')
|
||||
for (let key of keychain) {
|
||||
if (typeof parent === 'object' && /^\w+\(.*\)$/.test(key)) {
|
||||
if (!parent) {
|
||||
// 如果 parent 是 null 或 undefined,直接返回空值。
|
||||
return emptyValue
|
||||
} else if (typeof parent === 'object' && /^\w+\(.*\)$/.test(key)) {
|
||||
// 支持 myfunc(param) 作为一个路径节点。
|
||||
let [all, func, param] = key.match(/^(\w+)\((.*)\)$/)
|
||||
parent = parent[func](param)
|
||||
@@ -330,19 +356,27 @@ module.exports = {
|
||||
// 返回新的数组
|
||||
filter_story (story) {
|
||||
if (Array.isArray(story) && story.length) {
|
||||
return story.filter((section) => Object.values(section || {}).some((val) => !this.is_empty(val))) // (section.text || section.image || section.video)?.trim?.()
|
||||
return story.filter((section) => {
|
||||
if (!section) return false
|
||||
return Object.values(section).some((val) => !this.is_empty(val))
|
||||
//return Object.entries(section).some(([key, val]) => !key.startsWith('_') && !this.is_empty(val)) // don't check properties '_xxx'
|
||||
})
|
||||
} else {
|
||||
return []
|
||||
}
|
||||
},
|
||||
|
||||
extract_story_title (story) {
|
||||
extract_story_title ({ story, lang = 'enUS' } = {}) {
|
||||
if (Array.isArray(story) && story.length) {
|
||||
return (
|
||||
story
|
||||
.map(({ text = '' } = {}) => text.trim().replace(/\n/g, ' '))
|
||||
.join(' ')
|
||||
.substring(0, 140) || ''
|
||||
.map(({ text = '' } = {}) => {
|
||||
if (typeof text === 'string') return text.trim?.()?.replace?.(/\n+/g, ' ')
|
||||
else if (typeof text === 'object') return (text[lang] || text['enUS'])?.trim?.()?.replace?.(/\n+/g, ' ')
|
||||
})
|
||||
?.join(' ')
|
||||
?.trim?.()
|
||||
?.substring?.(0, 140) || ''
|
||||
)
|
||||
} else {
|
||||
return ''
|
||||
@@ -352,7 +386,7 @@ module.exports = {
|
||||
summarize_story (story = []) {
|
||||
// story is an array of objects, each object could either be {text:'some string'}, {image: url} or {video:url}. Please construct a summary object as result: { textLength, imageCount, VideoCount }
|
||||
return story.reduce(
|
||||
(summary, { text, image, video, file } = {}) => {
|
||||
(summary, { text, image, video, audio, file, linkTarget, _autocontent } = {}) => {
|
||||
if (text) {
|
||||
summary.textLength += text.length
|
||||
summary.wordCount += text.split(/\s+/).length
|
||||
@@ -360,12 +394,20 @@ module.exports = {
|
||||
summary.imageCount++
|
||||
} else if (video) {
|
||||
summary.videoCount++
|
||||
} else if (audio) {
|
||||
summary.audioCount++
|
||||
} else if (file) {
|
||||
summary.fileCount++
|
||||
} else if (linkTarget) {
|
||||
summary.linkCount++
|
||||
} else if (_autocontent) {
|
||||
summary.emptyContent++
|
||||
} else {
|
||||
summary.untypeCount++
|
||||
}
|
||||
return summary
|
||||
},
|
||||
{ textLength: 0, wordCount: 0, imageCount: 0, videoCount: 0 }
|
||||
{ textLength: 0, wordCount: 0, imageCount: 0, videoCount: 0, audioCount: 0, fileCount: 0, linkCount: 0, emptyContent: 0, untypeCount: 0 }
|
||||
)
|
||||
},
|
||||
|
||||
@@ -462,6 +504,7 @@ module.exports = {
|
||||
})
|
||||
},
|
||||
|
||||
// 洗牌算法,随机打乱数组顺序
|
||||
shuffle_array (array = []) {
|
||||
if (Array.isArray(array)) {
|
||||
for (let i = array.length - 1; i > 0; i--) {
|
||||
@@ -473,6 +516,6 @@ module.exports = {
|
||||
},
|
||||
|
||||
is_uuid (uuid) {
|
||||
return /^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(unid)
|
||||
return /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(uuid)
|
||||
},
|
||||
}
|
||||
|
||||
104
tool_uniapp.js
104
tool_uniapp.js
@@ -39,15 +39,19 @@ module.exports = {
|
||||
|
||||
is_text_file (fileName = '') {
|
||||
const ext = /\./.test(fileName) ? fileName.split('.').pop().toLowerCase() : ''
|
||||
return (wo.envar.textExtensionList || ['txt', 'text']).includes(ext)
|
||||
return wo.ss.textExtensionList?.includes?.(ext)
|
||||
},
|
||||
is_image_file (fileName = '') {
|
||||
const ext = /\./.test(fileName) ? fileName.split('.').pop().toLowerCase() : ''
|
||||
return (wo.envar.imageExtensionList || ['jpg', 'jpeg', 'png', 'gif', 'webp', 'image']).includes(ext)
|
||||
return wo.ss.imageExtensionList?.includes?.(ext)
|
||||
},
|
||||
is_video_file (fileName = '') {
|
||||
const ext = /\./.test(fileName) ? fileName.split('.').pop().toLowerCase() : ''
|
||||
return (wo.envar.videoExtensionList || ['avi', 'mp4', 'mov', 'wmv', 'video']).includes(ext)
|
||||
return wo.ss.videoExtensionList?.includes?.(ext)
|
||||
},
|
||||
is_audio_file (fileName = '') {
|
||||
const ext = /\./.test(fileName) ? fileName.split('.').pop().toLowerCase() : ''
|
||||
return wo.ss.audioExtensionList?.includes?.(ext)
|
||||
},
|
||||
|
||||
thisPage () {
|
||||
@@ -60,15 +64,14 @@ module.exports = {
|
||||
i18nText =
|
||||
i18nText || // 如果传入i18n参数 ({zhCN:'...', enUS:'...'})
|
||||
this.i18nText || // 1) 如果挂载到具体页面的 computed { lote: wo?.localizeText } 那么 this 就是当前页面,直接取用 this.i18nText 即可。2) 对于组件内定义的 i18nText,要使用 this 来获得组件内的 i18nText
|
||||
getCurrentPages()?.pop()?.i18nText // 如果不是挂载到 Vue.prototype 而是 挂载到 wo 下调用,那么 this.i18nText 就不存在了。因此通过 pageNow.i18nText 访问。
|
||||
getCurrentPages?.()?.pop?.()?.i18nText // 如果不是挂载到 Vue.prototype 而是 挂载到 wo 下调用,那么 this.i18nText 就不存在了。因此通过 pageNow.i18nText 访问。
|
||||
if (['string', 'number', 'boolean'].includes(typeof i18nText)) {
|
||||
// 必须先检测是否标量值,如果直接返回 i18nText 可能返回{}等,导致依赖于返回空值的前端出错
|
||||
return i18nText
|
||||
} else if (typeof i18nText === 'object' && i18nText) {
|
||||
return (
|
||||
i18nText?.[langCode] ||
|
||||
i18nText?.[my.get_mylang()] ||
|
||||
(precise ? '' : i18nText?.earTH || i18nText?.defLAN || i18nText?.gloBAL || i18nText?.enUS || Object.values(i18nText)[0] || '')
|
||||
i18nText[langCode || my.get_mylang()] ||
|
||||
(precise ? '' : i18nText.earTH || i18nText.gloBAL || i18nText.defLAN || i18nText.enUS || Object.values(i18nText)[0] || '')
|
||||
)
|
||||
} else {
|
||||
return ''
|
||||
@@ -97,9 +100,13 @@ module.exports = {
|
||||
)
|
||||
|
||||
windowTitle =
|
||||
windowTitle || wo?.envar?.callnames?.[langNow] || wo?.pagesJson?.appInfo?.i18nText?.[langNow] || wo?.pagesJson?.globalStyle?.navigationBarTitleText || ''
|
||||
windowTitle ||
|
||||
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 })
|
||||
@@ -109,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
|
||||
@@ -118,7 +125,7 @@ module.exports = {
|
||||
}
|
||||
//#endif
|
||||
|
||||
if (wo.envar._clientInfo.deviceType === 'pc') {
|
||||
if (wo.ss._clientInfo.deviceType === 'pc') {
|
||||
uni.hideTabBar()
|
||||
} else {
|
||||
// 必须要在有 tab 的页面里 setTabBarItem 才有效果
|
||||
@@ -139,7 +146,7 @@ module.exports = {
|
||||
}
|
||||
},
|
||||
|
||||
make_server_url (route, envar = globalThis.wo?.envar || {}) {
|
||||
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
|
||||
@@ -156,22 +163,26 @@ module.exports = {
|
||||
if (/^\/static\//.test(route)) {
|
||||
return route
|
||||
}
|
||||
route = route.replace(/^\//, '')
|
||||
// 对 route='abc.com' 这种,应当有 fullUrl===true,就直接使用,而不是组装成 pexserver.tic.cc/abc.com
|
||||
// 纯数字和字母的cid
|
||||
if (/^[\da-zA-Z]+$/.test(route) && envar.ipfsLens) {
|
||||
return `${envar.ipfsLens.replace(/\/$/, '')}/${route.replace(/^\//, '')}`
|
||||
if (/^[0-9a-zA-Z]+$/.test(route) && envar?.ipfsLens) {
|
||||
return `${envar.ipfsLens.replace(/\/$/, '')}/${route}`
|
||||
}
|
||||
//// base url / 后台服务器url 需要组装。包括了 route === '_filestore/xxx' 的情况
|
||||
route = route.replace(/^\//, '')
|
||||
// 已有现成后端服务域名
|
||||
if (envar.servUrl) {
|
||||
if (fullUrl) {
|
||||
return `http://${route}`
|
||||
} else if (envar?.servUrl) {
|
||||
return `${envar.servUrl.replace(/\/$/, '')}/${route}`
|
||||
} else {
|
||||
} else if (envar?.servHostname) {
|
||||
// 需要组装后端服务域名
|
||||
const hostname = envar.servHostname /*|| globalThis.window?.location?.hostname*/ || 'localhost'
|
||||
const port = envar.servPort /*|| globalThis.window?.location?.port*/ || ''
|
||||
const protocol = hostname === 'localhost' ? 'http' : envar.servProtocol || (process.env.NODE_ENV === 'production' ? 'https' : 'http')
|
||||
return `${protocol}://${hostname}${port ? ':' : ''}${port}/${route}`
|
||||
}
|
||||
return route
|
||||
},
|
||||
|
||||
make_bgurl (image) {
|
||||
@@ -185,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,
|
||||
@@ -197,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,
|
||||
@@ -340,7 +351,13 @@ module.exports = {
|
||||
filePath = fileDragged.filePath
|
||||
filePicked = fileDragged
|
||||
if (!mediaType) {
|
||||
mediaType = this.is_image_file(fileDragged.name) ? 'image' : this.is_video_file(fileDragged.name) ? 'video' : 'file'
|
||||
mediaType = this.is_image_file(fileDragged.name)
|
||||
? 'image'
|
||||
: this.is_video_file(fileDragged.name)
|
||||
? 'video'
|
||||
: this.is_audio_file(fileDragged.name)
|
||||
? 'audio'
|
||||
: 'file'
|
||||
}
|
||||
} else if (mediaType === 'image') {
|
||||
let [errorChoose, { tempFilePaths, tempFiles } = {}] = await uni.chooseImage({ count, sizeType, sourceType })
|
||||
@@ -364,6 +381,27 @@ module.exports = {
|
||||
fileSize = size
|
||||
filePicked = tempFile
|
||||
filePath = tempFilePath
|
||||
} else if (mediaType === 'audio') {
|
||||
// #ifdef WEB
|
||||
// https://uniapp.dcloud.net.cn/api/media/file.html
|
||||
let [errorChoose, { tempFilePaths, tempFiles } = {}] = await uni.chooseFile({
|
||||
count,
|
||||
extension: wo.ss.audioExtensionList,
|
||||
type: undefined,
|
||||
}) // 20240429 但是测试下来 extension 参数无效
|
||||
if (errorChoose) {
|
||||
return {
|
||||
_state: 'CER_FAIL_CHOOSE',
|
||||
_msg: '', // { zhCN: '文件选择失败。请稍后再试,或向客服投诉。', enUS: 'File choose failed. Please try again later, or report to customer service.' },
|
||||
}
|
||||
}
|
||||
fileSize = tempFiles?.[0]?.size
|
||||
filePicked = tempFiles?.[0]
|
||||
filePath = tempFilePaths?.[0]
|
||||
// #endif
|
||||
// #ifndef WEB
|
||||
return { _state: 'UNSUPPORTED_FILETYPE', _msg: { zhCN: '请切换到网页端上传文件!', enUS: 'Please switch to Web App to upload files.' } }
|
||||
// #endif
|
||||
} else {
|
||||
// #ifdef WEB
|
||||
// https://uniapp.dcloud.net.cn/api/media/file.html
|
||||
@@ -393,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` },
|
||||
@@ -482,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) {
|
||||
@@ -497,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 })
|
||||
@@ -514,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 了。
|
||||
@@ -541,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.' } }
|
||||
@@ -552,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` },
|
||||
@@ -605,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,
|
||||
@@ -631,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
|
||||
@@ -657,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
|
||||
|
||||
Reference in New Issue
Block a user