Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
vk-uni
vk-unicloud-router
比较版本
b76d1573ef0d04d891d162e0f1d8596aeda368f7...488547c0ddf80c23ccfe14fd9bd26a7024286e97
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 搜索 >>
源分支
488547c0ddf80c23ccfe14fd9bd26a7024286e97
选择Git版本
...
目标分支
b76d1573ef0d04d891d162e0f1d8596aeda368f7
选择Git版本
比较
Commits (2)
https://gitcode.net/vk-uni/vk-uni-cloud-router/-/commit/1c22b82903a85a6d8063075ebd85590c393f6cce
【优化】`vk.uploadFile` 新增参数 `cloudDirectory` 可以设置上传至指定的云端目录
2023-06-21T11:23:24+08:00
VK云桌面
370725567@qq.com
https://gitcode.net/vk-uni/vk-uni-cloud-router/-/commit/488547c0ddf80c23ccfe14fd9bd26a7024286e97
注册接口统一去除前端的role参数,防止发生安全性问题
2023-06-21T17:31:21+08:00
VK云桌面
370725567@qq.com
隐藏空白更改
内联
并排
Showing
10 changed file
with
157 addition
and
53 deletion
+157
-53
changelog.new.md
changelog.new.md
+3
-3
uniCloud-aliyun/cloudfunctions/router/service/user/pub/loginByAlipay.js
...n/cloudfunctions/router/service/user/pub/loginByAlipay.js
+12
-1
uniCloud-aliyun/cloudfunctions/router/service/user/pub/loginByEmail.js
...un/cloudfunctions/router/service/user/pub/loginByEmail.js
+3
-6
uniCloud-aliyun/cloudfunctions/router/service/user/pub/loginByQQ.js
...liyun/cloudfunctions/router/service/user/pub/loginByQQ.js
+14
-1
uniCloud-aliyun/cloudfunctions/router/service/user/pub/loginBySms.js
...iyun/cloudfunctions/router/service/user/pub/loginBySms.js
+10
-4
uniCloud-aliyun/cloudfunctions/router/service/user/pub/loginByUniverify.js
...loudfunctions/router/service/user/pub/loginByUniverify.js
+18
-1
uniCloud-aliyun/cloudfunctions/router/service/user/pub/register.js
...aliyun/cloudfunctions/router/service/user/pub/register.js
+24
-16
uniCloud-aliyun/cloudfunctions/router/service/user/pub/sendEmailCode.js
...n/cloudfunctions/router/service/user/pub/sendEmailCode.js
+3
-0
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
浏览文件 @
488547c0
*
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
uniCloud-aliyun/cloudfunctions/router/service/user/pub/loginByAlipay.js
浏览文件 @
488547c0
...
...
@@ -18,7 +18,18 @@ module.exports = {
let
{
uid
}
=
data
;
let
res
=
{};
// 业务逻辑开始-----------------------------------------------------------
res
=
await
uniID
.
loginByAlipay
(
data
);
let
{
code
,
type
,
myInviteCode
,
needPermission
}
=
data
;
res
=
await
uniID
.
loginByAlipay
({
code
,
type
,
myInviteCode
,
needPermission
});
if
(
res
.
token
)
{
if
(
!
res
.
msg
)
{
res
.
msg
=
res
.
type
===
"
register
"
?
"
注册成功
"
:
"
登录成功
"
;
...
...
uniCloud-aliyun/cloudfunctions/router/service/user/pub/loginByEmail.js
浏览文件 @
488547c0
module
.
exports
=
{
/**
* 用户登录
(支付宝授权)
* 用户登录
(邮箱+验证码登录)
* @url user/pub/loginByEmail 前端调用的url参数地址
* @description 用户登录(支付宝授权)
* data 请求参数 说明
* @param {String} email 邮箱
* @param {String} code 邮箱收到的验证码
...
...
@@ -10,7 +9,6 @@ module.exports = {
* @param {String} password 密码,当前用户为新注册时生效
* @param {String} myInviteCode 设置当前注册用户自己的邀请码,当前用户为新注册时生效(不传会自动生成)
* @param {Boolean} needPermission 设置为true时会在checkToken时返回用户权限(permission),如果是在admin端,需传true
* @param {Array} role 设定用户角色,当前用户为新注册时生效
* res 返回参数说明
* @param {Number} code 错误码,0表示成功
* @param {String} msg 详细信息
...
...
@@ -23,15 +21,14 @@ module.exports = {
let
{
uid
}
=
data
;
let
res
=
{};
// 业务逻辑开始-----------------------------------------------------------
let
{
email
,
code
,
type
,
password
,
needPermission
,
myInviteCode
,
role
}
=
data
;
let
{
email
,
code
,
type
,
password
,
needPermission
,
myInviteCode
}
=
data
;
res
=
await
uniID
.
loginByEmail
({
email
,
code
,
type
,
password
,
myInviteCode
,
needPermission
,
role
needPermission
});
if
(
res
.
token
)
{
if
(
!
res
.
msg
)
{
...
...
uniCloud-aliyun/cloudfunctions/router/service/user/pub/loginByQQ.js
浏览文件 @
488547c0
...
...
@@ -18,7 +18,20 @@ module.exports = {
let
{
uid
}
=
data
;
let
res
=
{};
// 业务逻辑开始-----------------------------------------------------------
res
=
await
uniID
.
loginByQQ
(
data
);
let
{
code
,
accessToken
,
type
,
myInviteCode
,
needPermission
}
=
data
;
res
=
await
uniID
.
loginByQQ
({
code
,
accessToken
,
type
,
myInviteCode
,
needPermission
});
if
(
res
.
token
)
{
if
(
!
res
.
msg
)
{
res
.
msg
=
res
.
type
===
"
register
"
?
"
注册成功
"
:
"
登录成功
"
;
...
...
uniCloud-aliyun/cloudfunctions/router/service/user/pub/loginBySms.js
浏览文件 @
488547c0
...
...
@@ -11,7 +11,6 @@ module.exports = {
* @param {String} inviteCode 邀请人的邀请码,当前用户为新注册时生效
* @param {String} myInviteCode 设置当前注册用户自己的邀请码,当前用户为新注册时生效(不传会自动生成)
* @param {Boolean} needPermission 设置为true时会在checkToken时返回用户权限(permission),如果是在admin端,需传true
* @param {Array} role 设定用户角色,当前用户为新注册时生效
* res 返回参数说明
* @param {Number} code 错误码,0表示成功
* @param {String} msg 详细信息
...
...
@@ -24,7 +23,15 @@ module.exports = {
let
{
uid
}
=
data
;
let
res
=
{};
// 业务逻辑开始-----------------------------------------------------------
let
{
mobile
,
code
,
password
,
inviteCode
,
myInviteCode
,
needPermission
,
role
,
type
}
=
data
;
let
{
mobile
,
code
,
type
,
password
,
inviteCode
,
myInviteCode
,
needPermission
}
=
data
;
res
=
await
uniID
.
loginBySms
({
mobile
,
code
,
...
...
@@ -32,8 +39,7 @@ module.exports = {
password
,
inviteCode
,
myInviteCode
,
needPermission
,
role
needPermission
});
// 修改用户昵称为:手机尾号xxxx用户
if
(
res
.
token
)
{
...
...
uniCloud-aliyun/cloudfunctions/router/service/user/pub/loginByUniverify.js
浏览文件 @
488547c0
...
...
@@ -25,7 +25,24 @@ module.exports = {
let
{
uid
}
=
data
;
let
res
=
{
code
:
0
,
msg
:
''
};
// 业务逻辑开始-----------------------------------------------------------
res
=
await
uniID
.
loginByUniverify
(
data
);
let
{
access_token
,
openid
,
type
,
password
,
inviteCode
,
myInviteCode
,
needPermission
}
=
data
;
res
=
await
uniID
.
loginByUniverify
({
access_token
,
openid
,
type
,
password
,
inviteCode
,
myInviteCode
,
needPermission
});
if
(
res
.
token
)
{
if
(
!
res
.
msg
)
{
res
.
msg
=
res
.
type
===
"
register
"
?
"
注册成功
"
:
"
登录成功
"
;
...
...
uniCloud-aliyun/cloudfunctions/router/service/user/pub/register.js
浏览文件 @
488547c0
module
.
exports
=
{
/**
* 用户注册(账号+密码)
* @url user/pub/register 前端调用的url参数地址
* @description 用户注册(账号+密码)
/**
* 用户注册(账号+密码)
* @url user/pub/register 前端调用的url参数地址
* @description 用户注册(账号+密码)
* data 请求参数 说明
* @param {String} username 用户名,唯一
* @param {String} password 密码
...
...
@@ -12,26 +12,34 @@ module.exports = {
* @param {String} token 注册完成自动登录之后返回的token信息
* @param {String} tokenExpired token过期时间
* @param {Object} userInfo 用户信息
*/
*/
main
:
async
(
event
)
=>
{
let
{
data
=
{},
userInfo
,
util
,
originalParam
}
=
event
;
let
{
uniID
,
config
,
pubFun
,
vk
,
db
,
_
}
=
util
;
let
{
uniID
,
config
,
pubFun
,
vk
,
db
,
_
}
=
util
;
let
{
uid
}
=
data
;
let
res
=
{
code
:
-
1
,
msg
:
''
};
let
res
=
{
code
:
-
1
,
msg
:
''
};
// 业务逻辑开始-----------------------------------------------------------
let
{
username
,
password
,
needPermission
}
=
data
;
let
{
username
,
password
,
needPermission
,
myInviteCode
}
=
data
;
// username必须以字母开头,长度在6~18之间,只能包含字母、数字和下划线
if
(
!
vk
.
pubfn
.
test
(
username
,
"
username
"
))
{
return
{
code
:
-
1
,
msg
:
"
账号必须以字母开头,长度在6~18之间,只能包含字母、数字和下划线
"
};
if
(
!
vk
.
pubfn
.
test
(
username
,
"
username
"
))
{
return
{
code
:
-
1
,
msg
:
"
账号必须以字母开头,长度在6~18之间,只能包含字母、数字和下划线
"
};
}
// password 长度在6~18之间,只能包含字母、数字和下划线
if
(
!
vk
.
pubfn
.
test
(
password
,
"
pwd
"
))
{
return
{
code
:
-
1
,
msg
:
"
密码长度在6~18之间,只能包含字母、数字和下划线
"
};
if
(
!
vk
.
pubfn
.
test
(
password
,
"
pwd
"
))
{
return
{
code
:
-
1
,
msg
:
"
密码长度在6~18之间,只能包含字母、数字和下划线
"
};
}
res
=
await
uniID
.
register
({
username
,
password
,
needPermission
});
res
=
await
uniID
.
register
({
username
,
password
,
needPermission
,
myInviteCode
});
// 业务逻辑结束-----------------------------------------------------------
return
res
;
}
}
}
\ No newline at end of file
uniCloud-aliyun/cloudfunctions/router/service/user/pub/sendEmailCode.js
浏览文件 @
488547c0
...
...
@@ -29,6 +29,9 @@ module.exports = {
}
=
data
;
let
res
=
{
code
:
0
,
msg
:
'
ok
'
};
// 业务逻辑开始-----------------------------------------------------------
if
(
!
vkmail
)
{
return
{
code
:
-
1
,
msg
:
"
请先添加公共模块:vk-mail(右键对应的云函数,点击管理公共模块或扩展库依赖,勾选vk-mail依赖)
"
};
}
let
code
=
vk
.
pubfn
.
random
(
6
,
"
0123456789
"
);
let
param
=
{
code
,
...
...
uni_modules/vk-unicloud/vk_modules/vk-unicloud-page/libs/function/aliyunOSSUtil.js
浏览文件 @
488547c0
...
...
@@ -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
浏览文件 @
488547c0
...
...
@@ -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
;
}
...
...