Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
vk-uni
vk-unicloud-router
提交
1c22b829
vk-unicloud-router
项目概览
vk-uni
/
vk-unicloud-router
10 个月 前同步成功
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
vk-unicloud-router
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
1c22b829
编写于
6月 21, 2023
作者:
VK1688
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
【优化】`vk.uploadFile` 新增参数 `cloudDirectory` 可以设置上传至指定的云端目录
上级
b76d1573
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
73 addition
and
24 deletion
+73
-24
changelog.new.md
changelog.new.md
+3
-3
uni_modules/vk-unicloud/vk_modules/vk-unicloud-page/libs/function/aliyunOSSUtil.js
...k_modules/vk-unicloud-page/libs/function/aliyunOSSUtil.js
+26
-7
uni_modules/vk-unicloud/vk_modules/vk-unicloud-page/libs/vk-unicloud/vk-unicloud-callFunctionUtil.js
...oud-page/libs/vk-unicloud/vk-unicloud-callFunctionUtil.js
+44
-14
未找到文件。
changelog.new.md
浏览文件 @
1c22b829
*
1、【
新增】支付宝小程序api
[
传送门
](
https://vkdoc.fsq.pub/client/uniCloud/plus/alipay.html
)
*
2、【
修复】因
`2.14.2`
更新导致的支付宝小程序报错问题。
*
3、【优化】
注册接口前端全局防抖
*
1、【
优化】云函数、云对象404时的错误提示
*
2、【
优化】
`vk.uploadFile`
新增参数
`cloudPathAsRealPath`
默认为true,代表支持阿里云目录
*
3、【优化】
`vk.uploadFile`
新增参数
`cloudDirectory`
可以设置上传至指定的云端目录
##### 框架学习Q群:`22466457` 欢迎萌新和大佬来使用和共同改进框架
\ No newline at end of file
uni_modules/vk-unicloud/vk_modules/vk-unicloud-page/libs/function/aliyunOSSUtil.js
浏览文件 @
1c22b829
...
...
@@ -43,6 +43,8 @@ aliyunOSSUtil.uploadFile = function(obj) {
needSave
=
false
,
category_id
,
title
,
cloudPathRemoveChinese
=
true
,
// 删除文件名中的中文
cloudDirectory
,
}
=
obj
;
let
vk
=
getApp
().
globalData
.
vk
;
if
(
title
)
vk
.
showLoading
(
title
);
...
...
@@ -179,9 +181,11 @@ function getConfig() {
// 生成文件名
function
createFileName
(
obj
=
{})
{
let
{
file
,
filePath
,
index
=
0
,
fil
e
,
filePath
,
cloudPathRemoveChinese
=
tru
e
,
cloudDirectory
}
=
obj
;
let
vk
=
getApp
().
globalData
.
vk
;
let
aliyunOSS
=
getConfig
();
...
...
@@ -195,7 +199,9 @@ function createFileName(obj = {}) {
let
suffixName
=
file
.
name
.
substring
(
file
.
name
.
lastIndexOf
(
"
.
"
)
+
1
);
if
(
suffixName
&&
suffixName
.
length
<
5
)
oldName
=
file
.
name
;
// 只保留["数字","英文",".","-"]
oldName
=
oldName
.
replace
(
/
[^
a-zA-Z.-d
]
/g
,
''
);
if
(
cloudPathRemoveChinese
)
{
oldName
=
oldName
.
replace
(
/
[^
a-zA-Z.-d
]
/g
,
''
);
}
if
(
oldName
.
indexOf
(
"
.
"
)
==
0
)
oldName
=
"
0
"
+
oldName
;
}
let
date
=
new
Date
();
...
...
@@ -205,13 +211,26 @@ function createFileName(obj = {}) {
let
dateTimeEnd8
=
dateTime
.
substring
(
dateTime
.
length
-
8
,
dateTime
.
length
);
let
randomNumber
=
vk
.
pubfn
.
random
(
8
);
// 8位随机数
// 文件路径 = 固定路径名 + 业务路径
// 业务路径
let
servicePath
=
""
;
let
newFilePath
=
dirname
+
"
/
"
+
servicePath
+
dateYYYYMMDD
+
"
/
"
;
if
(
cloudDirectory
)
{
// 如果自定义了上传目录,则使用自定义的上传目录
if
(
cloudDirectory
.
lastIndexOf
(
"
/
"
)
!==
cloudDirectory
.
length
-
1
)
{
cloudDirectory
=
cloudDirectory
+
"
/
"
;
}
servicePath
=
cloudDirectory
;
}
else
{
// 否则,使用年月日作为上传目录
servicePath
=
dateYYYYMMDD
+
"
/
"
;
}
// 文件名 = 时间戳后8位 - 随机数8位 + 后缀名
let
fileNickName
=
dateTimeEnd8
+
randomNumber
+
"
-
"
+
oldName
;
// 文件名全称(包含文件路径) = 外网域名 + 文件路径 + 文件名
let
fileFullName
=
newFilePath
+
fileNickName
;
// 外网地址 = 外网域名 + 文件路径 + 文件名
// 文件相对路径 = 业务目录 + 文件名
let
fileRelativePath
=
servicePath
+
fileNickName
;
// 文件名全称(包含文件路径) = 根目录 + 文件相对路径
let
fileFullName
=
dirname
+
"
/
"
+
fileRelativePath
;
// 外网地址 = 外网域名 + 文件名全称
let
url
=
host
+
"
/
"
+
fileFullName
;
fileObj
.
url
=
url
;
fileObj
.
fileFullName
=
fileFullName
;
...
...
uni_modules/vk-unicloud/vk_modules/vk-unicloud-page/libs/vk-unicloud/vk-unicloud-callFunctionUtil.js
浏览文件 @
1c22b829
...
...
@@ -442,13 +442,24 @@ class CallFunctionUtil {
}
/**
* 云函数上传图片
* @param {String} filePath 要上传的文件对象
* @param {String} cloudPath 文件的绝对路径,包含文件名(若不传,会自动生成文件名)
* @param {String} fileType 文件类型,可选image、video、audio 默认image
* @param {Function} onUploadProgress 上传进度回调
* @param {Function} success 请求成功时,执行的回调函数
* @param {Function} fail 请求失败时,执行的回调函数
* @param {Function} complete 无论请求成功与否,都会执行的回调函数
* @param {String} title 上传时的loading提示语
* @param {String} file 要上传的文件对象,file与filePath二选一即可
* @param {String} filePath 要上传的文件路径,file与filePath二选一即可
* @param {String} suffix 指定上传后的文件后缀,如果传了file 参数,则此参数可不传
* @param {String} provider 云存储供应商,支持:unicloud、aliyun
* @param {String} cloudPath 指定上传后的云端文件路径(不指定会自动生成)cloudPath优先级大于cloudDirectory
* @param {String} cloudDirectory 指定上传后的云端文件目录(不指定会自动生成)
* @param {String} needSave 是否需要将图片信息保存到admin素材库
* @param {String} category_id 素材库分类id,当needSave为true时生效
* @param {String} uniCloud 上传到其他空间时使用,uniCloud和env二选一即可
* @param {String} env 上传到其他空间时使用,uniCloud和env二选一即可
* @param {String} cloudPathAsRealPath 阿里云目录支持,需HBX3.8.5以上版本才支持
* @param {String} cloudPathRemoveChinese 删除文件名中的中文
* @param {String} fileType 文件类型,可选image、video、audio 不用传,会自动识别
* @param {Function} onUploadProgress 上传进度回调
* @param {Function} success 上传成功时,执行的回调函数
* @param {Function} fail 上传失败时,执行的回调函数
* @param {Function} complete 无论上传成功与否,都会执行的回调函数
* vk.callFunctionUtil.uploadFile
*/
this
.
uploadFile
=
(
obj
=
{})
=>
{
...
...
@@ -470,7 +481,10 @@ class CallFunctionUtil {
needSave
=
false
,
category_id
,
uniCloud
:
myCloud
,
env
=
"
default
"
env
=
"
default
"
,
cloudPathAsRealPath
=
true
,
// 阿里云目录支持,需HBX3.8.5以上版本才支持
cloudPathRemoveChinese
=
true
,
// 删除文件名中的中文
cloudDirectory
,
}
=
obj
;
// 获取文件类型(image:图片 video:视频 other:其他)
let
fileType
=
this
.
getFileType
(
obj
);
...
...
@@ -500,6 +514,7 @@ class CallFunctionUtil {
filePath
:
filePath
,
cloudPath
:
cloudPath
,
fileType
:
fileType
,
cloudPathAsRealPath
,
onUploadProgress
:
function
(
progressEvent
)
{
let
percentCompleted
=
Math
.
round
(
(
progressEvent
.
loaded
*
100
)
/
progressEvent
.
total
...
...
@@ -897,17 +912,22 @@ class CallFunctionUtil {
// 生成文件名
createFileName
(
obj
=
{})
{
let
{
file
,
filePath
,
index
=
0
,
fil
e
,
filePath
cloudPathRemoveChinese
=
tru
e
,
cloudDirectory
}
=
obj
;
let
suffix
=
this
.
getFileSuffix
(
obj
);
let
oldName
=
index
+
"
.
"
+
suffix
;
// 注意:小程序无法获取到 file.name
if
(
file
&&
file
.
name
)
{
let
suffixName
=
file
.
name
.
substring
(
file
.
name
.
lastIndexOf
(
"
.
"
)
+
1
);
if
(
suffixName
&&
suffixName
.
length
<
5
)
oldName
=
file
.
name
;
// 只保留["数字","英文",".","-"]
oldName
=
oldName
.
replace
(
/
[^
a-zA-Z.-d
]
/g
,
''
);
if
(
cloudPathRemoveChinese
)
{
oldName
=
oldName
.
replace
(
/
[^
a-zA-Z.-d
]
/g
,
''
);
}
if
(
oldName
.
indexOf
(
"
.
"
)
==
0
)
oldName
=
"
0
"
+
oldName
;
}
let
date
=
new
Date
();
...
...
@@ -917,10 +937,20 @@ class CallFunctionUtil {
let
dateTimeEnd8
=
dateTime
.
substring
(
dateTime
.
length
-
8
,
dateTime
.
length
);
let
randomNumber
=
vk
.
pubfn
.
random
(
8
);
// 8位随机数
// 文件路径
let
newFilePath
=
dateYYYYMMDD
+
"
/
"
;
// 文件名 = 时间戳 - 随机数32位 + 后缀名
let
newFilePath
=
""
;
if
(
cloudDirectory
)
{
// 如果自定义了上传目录,则使用自定义的上传目录
if
(
cloudDirectory
.
lastIndexOf
(
"
/
"
)
!==
cloudDirectory
.
length
-
1
)
{
cloudDirectory
=
cloudDirectory
+
"
/
"
;
}
newFilePath
=
cloudDirectory
;
}
else
{
// 否则,使用年月日作为上传目录
newFilePath
=
dateYYYYMMDD
+
"
/
"
;
}
// 文件名 = 时间戳后8位 - 随机数8位 + 原本文件名
let
fileNickName
=
dateTimeEnd8
+
"
-
"
+
randomNumber
+
"
-
"
+
oldName
;
// 文件名全称
(包含文件路径) = 外网域名 +
文件路径 + 文件名
// 文件名全称
(包含文件路径) =
文件路径 + 文件名
let
fileFullName
=
newFilePath
+
fileNickName
;
return
fileFullName
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录