Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
vk-uni
vk-unicloud-router
提交
b0c26706
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 搜索 >>
提交
b0c26706
编写于
5月 15, 2021
作者:
VK1688
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
2.0.0
上级
7d393134
变更
16
展开全部
隐藏空白更改
内联
并排
Showing
16 changed file
with
278 addition
and
28 deletion
+278
-28
README.md
README.md
+8
-6
README/2.0/2.0.0.md
README/2.0/2.0.0.md
+13
-0
changelog.md
changelog.md
+15
-0
package.json
package.json
+2
-2
store/modules/$user.js
store/modules/$user.js
+2
-1
uniCloud-aliyun/cloudfunctions/router/service/逻辑层目录说明.md
uniCloud-aliyun/cloudfunctions/router/service/逻辑层目录说明.md
+1
-1
uniCloud-aliyun/database/db_init.json
uniCloud-aliyun/database/db_init.json
+2
-1
uni_modules/vk-unicloud/changelog.md
uni_modules/vk-unicloud/changelog.md
+17
-0
uni_modules/vk-unicloud/package.json
uni_modules/vk-unicloud/package.json
+1
-1
uni_modules/vk-unicloud/uniCloud/cloudfunctions/common/vk-unicloud/index.js
...cloud/uniCloud/cloudfunctions/common/vk-unicloud/index.js
+1
-1
uni_modules/vk-unicloud/uniCloud/cloudfunctions/common/vk-unicloud/package.json
...d/uniCloud/cloudfunctions/common/vk-unicloud/package.json
+1
-1
uni_modules/vk-unicloud/vk_modules/vk-unicloud-page/libs/function/index.js
...icloud/vk_modules/vk-unicloud-page/libs/function/index.js
+2
-2
uni_modules/vk-unicloud/vk_modules/vk-unicloud-page/libs/function/permission.js
...d/vk_modules/vk-unicloud-page/libs/function/permission.js
+1
-1
uni_modules/vk-unicloud/vk_modules/vk-unicloud-page/libs/store/mixin/mixin.js
...oud/vk_modules/vk-unicloud-page/libs/store/mixin/mixin.js
+13
-11
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
+1
-0
使用帮助/11、万能连表.md
使用帮助/11、万能连表.md
+198
-0
未找到文件。
README.md
浏览文件 @
b0c26706
### uniCloud云函数路由框架研究Q群:22466457 如有问题或建议可以在群内讨论。
### 插件名称:`vk-unicloud-router`
### 作者:VK
### 更新时间:2021-04-23
## 序
##### 如果你热爱编程,想快速入门云开发,欢迎使用`vk-
cloud-router`
开发框架
##### 如果你热爱编程,想快速入门云开发,欢迎使用`vk-
unicloud`系列
开发框架
##### 无需转变开发习惯,0成本上手云开发。
##### 框架内置了众多API、工具包,为你的业务扫平障碍。使你的项目刚起步进度就是50%(微信登录、短信、验证码、缓存、生成小程序码等等)
##### 从此你又get一个新技能,只需用js,轻松搞定前后台整体业务。
##### 框架地址:`https://ext.dcloud.net.cn/plugin?id=2204` [点击查看](https://ext.dcloud.net.cn/plugin?id=2204)
##### 框架文档:`https://gitee.com/vk-uni/vk-uni-cloud-router/wikis/pages?sort_id=2912167&doc_id=975983` [点击查看](https://gitee.com/vk-uni/vk-uni-cloud-router/wikis/pages?sort_id=2912167&doc_id=975983)
##### 框架学习Q群:22466457 欢迎萌新和大佬来使用和共同改进框架
##### `client端`框架地址:`https://ext.dcloud.net.cn/plugin?id=2204` [点击查看](https://ext.dcloud.net.cn/plugin?id=2204)
##### `admin端`框架地址:`https://ext.dcloud.net.cn/plugin?name=vk-unicloud-admin` [点击查看](https://ext.dcloud.net.cn/plugin?name=vk-unicloud-admin)
##### `client端`框架文档:`https://gitee.com/vk-uni/vk-uni-cloud-router/wikis/pages?sort_id=2912167&doc_id=975983` [点击查看](https://gitee.com/vk-uni/vk-uni-cloud-router/wikis/pages?sort_id=2912167&doc_id=975983)
##### `admin端`框架文档:`https://gitee.com/vk-uni/vk-uni-cloud-router/wikis/pages?sort_id=4003875&doc_id=975983` [点击查看](https://gitee.com/vk-uni/vk-uni-cloud-router/wikis/pages?sort_id=4003875&doc_id=975983)
##### 框架学习Q群:`22466457` 欢迎萌新和大佬来使用和共同改进框架
## 主要功能 以及 对开发者的价值
...
...
@@ -282,4 +283,5 @@ this.vk.callFunction({
[
点击查看本插件『更新步骤』
](
https://gitee.com/vk-uni/vk-uni-cloud-router/wikis/pages?sort_id=3671081&doc_id=975983
)
## uniCloud云函数路由框架研究Q群:`22466457` 如有问题或建议可以在群内讨论。
## 你也可以在评论区发布留言交流心得。
\ No newline at end of file
### 如果你觉得框架对你有用,可以在下方进行评论,也可以进行赞赏。
\ No newline at end of file
README/2.0/2.0.0.md
0 → 100644
浏览文件 @
b0c26706
### uniCloud 云函数路由研究群:22466457 如有问题或建议可以在群内讨论。
### 更新内容
#### 1、【优化】用户角色权限,支持admin使用 [点击查看](https://gitee.com/vk-uni/vk-uni-cloud-router/wikis/pages?sort_id=4003879&doc_id=975983)
#### 2、`vk-unicloud-admin`开发框架已正式上线
#### 至此,`vk-unicloud` 系列如下,可以满足开发完整系统。
##### `client端`框架地址:`https://ext.dcloud.net.cn/plugin?id=2204` [点击查看](https://ext.dcloud.net.cn/plugin?id=2204)
##### `admin端`框架地址:`https://ext.dcloud.net.cn/plugin?name=vk-unicloud-admin` [点击查看](https://ext.dcloud.net.cn/plugin?name=vk-unicloud-admin)
##### `client端`框架文档:`https://gitee.com/vk-uni/vk-uni-cloud-router/wikis/pages?sort_id=2912167&doc_id=975983` [点击查看](https://gitee.com/vk-uni/vk-uni-cloud-router/wikis/pages?sort_id=2912167&doc_id=975983)
##### `admin端`框架文档:`https://gitee.com/vk-uni/vk-uni-cloud-router/wikis/pages?sort_id=4003875&doc_id=975983` [点击查看](https://gitee.com/vk-uni/vk-uni-cloud-router/wikis/pages?sort_id=4003875&doc_id=975983)
##### 框架学习Q群:`22466457` 欢迎萌新和大佬来使用和共同改进框架
### 如果你觉得框架对你有用,可以在下方进行评论,也可以进行赞赏。
changelog.md
浏览文件 @
b0c26706
## 2.0.0(2021-05-15)
### uniCloud 云函数路由研究群:22466457 如有问题或建议可以在群内讨论。
### 更新内容
#### 1、【优化】用户角色权限,支持admin使用 [点击查看](https://gitee.com/vk-uni/vk-uni-cloud-router/wikis/pages?sort_id=4003879&doc_id=975983)
#### 2、`vk-unicloud-admin`开发框架已正式上线
#### 至此,`vk-unicloud` 系列如下,可以满足开发完整系统。
##### `client端`框架地址:`https://ext.dcloud.net.cn/plugin?id=2204` [点击查看](https://ext.dcloud.net.cn/plugin?id=2204)
##### `admin端`框架地址:`https://ext.dcloud.net.cn/plugin?name=vk-unicloud-admin` [点击查看](https://ext.dcloud.net.cn/plugin?name=vk-unicloud-admin)
##### `client端`框架文档:`https://gitee.com/vk-uni/vk-uni-cloud-router/wikis/pages?sort_id=2912167&doc_id=975983` [点击查看](https://gitee.com/vk-uni/vk-uni-cloud-router/wikis/pages?sort_id=2912167&doc_id=975983)
##### `admin端`框架文档:`https://gitee.com/vk-uni/vk-uni-cloud-router/wikis/pages?sort_id=4003875&doc_id=975983` [点击查看](https://gitee.com/vk-uni/vk-uni-cloud-router/wikis/pages?sort_id=4003875&doc_id=975983)
##### 框架学习Q群:`22466457` 欢迎萌新和大佬来使用和共同改进框架
### 如果你觉得框架对你有用,可以在下方进行评论,也可以进行赞赏。
## 1.9.2(2021-04-23)
### uniCloud 云函数路由研究群:22466457 如有问题或建议可以在群内讨论。
### 更新内容
...
...
package.json
浏览文件 @
b0c26706
{
"id"
:
"vk-cloud-router"
,
"displayName"
:
"【开箱即用】vk-unicloud-router - 云函数路由模式开发框架 - 已集成uni-id 框架内置了众多API、工具包,为你的业务扫平障碍。使你的项目刚起步进度就是50%"
,
"version"
:
"
1.9.2
"
,
"description"
:
"
不仅仅局限于框架,也是云端一体项目模板(已包含核心库)已集成uni-id支持云函数url化。支持url重写,众多现成API供你使用(登录、注册、短信、微信百度服务端API等等)为你的业务扫平障碍。使你的项目刚起步进度就是50% ,内置小白也能轻松上手的数据库API。新增:URL重写
。"
,
"version"
:
"
2.0.0
"
,
"description"
:
"
这是一个unicloud快速开发框架+项目模板(已包含核心库)支持URL化,众多现成API供你使用(登录、注册、短信、微信百度服务端API等等)为你的业务扫平障碍。内置小白也能轻松上手的数据库API
。"
,
"keywords"
:
[
"vk-unicloud-router"
,
"云函数路由"
,
...
...
store/modules/$user.js
浏览文件 @
b0c26706
...
...
@@ -20,7 +20,8 @@ export default {
* js更新示例
* vk.setVuex('$user.userInfo.avatar', avatar);
*/
userInfo
:
lifeData
.
$user
.
userInfo
||
{}
userInfo
:
lifeData
.
$user
.
userInfo
||
{},
permission
:
lifeData
.
$user
.
permission
||
[],
},
/**
* 从基本数据(state)派生的数据,相当于state的计算属性
...
...
uniCloud-aliyun/cloudfunctions/router/service/逻辑层目录说明.md
浏览文件 @
b0c26706
...
...
@@ -5,7 +5,7 @@
```
.
├── service──────────────────────# 逻辑层(用于写业务逻辑)
│ └── admin────────────────# 后台管理端逻辑(admin框架开发中。。。)
│ └── admin────────────────#
PC
后台管理端逻辑(admin框架开发中。。。)
│ ── └── xxxxxxxxxxxxxxx──────#
│ ── └── xxxxxxxxxxxxxxx──────#
│ ── └── xxxxxxxxxxxxxxx──────#
...
...
uniCloud-aliyun/database/db_init.json
浏览文件 @
b0c26706
...
...
@@ -28,7 +28,8 @@
"register_ip"
:
"127.0.0.1"
,
"nickname"
:
"超级管理员"
,
"role"
:[
"admin"
],
"token"
:
[]
"token"
:
[],
"allow_login_background"
:
true
}
],
"index"
:
[
...
...
uni_modules/vk-unicloud/changelog.md
浏览文件 @
b0c26706
## 2.0.1(2021-05-15)
### 更新内容
#### 【优化】用户角色权限,支持admin使用 [点击查看](https://gitee.com/vk-uni/vk-uni-cloud-router/wikis/pages?sort_id=4003879&doc_id=975983)
#### 完整框架项目地址:`https://ext.dcloud.net.cn/plugin?id=2204`[点击查看](https://ext.dcloud.net.cn/plugin?id=2204)
## 2.0.0(2021-05-15)
### 更新内容
#### 【优化】用户角色权限,支持admin使用 [点击查看](https://gitee.com/vk-uni/vk-uni-cloud-router/wikis/pages?sort_id=4003879&doc_id=975983)
#### 完整框架项目地址:`https://ext.dcloud.net.cn/plugin?id=2204`[点击查看](https://ext.dcloud.net.cn/plugin?id=2204)
## 1.9.4(2021-05-10)
### uniCloud 云函数路由研究群:22466457 如有问题或建议可以在群内讨论。
### 更新内容
#### 1、【优化】`vk.baseDao.selects` 支持分组查询,对应 `groupJson` 参数 [点击查看万能连表场景6](https://gitee.com/vk-uni/vk-uni-cloud-router/wikis/pages?sort_id=3028633&doc_id=975983)
#### 2、【优化】`vk.globalDataCache.get` 支持如果缓存有值,则读取缓存,如果缓存无值,则执行函数,并将函数return的结果保存到缓存 [点击查看](https://gitee.com/vk-uni/vk-uni-cloud-router/wikis/pages?sort_id=3442025&doc_id=975983)
#### 完整框架项目地址:`https://ext.dcloud.net.cn/plugin?id=2204`[点击查看](https://ext.dcloud.net.cn/plugin?id=2204)
## 1.9.3(2021-04-23)
### 更新内容
### uniCloud 云函数路由研究群:22466457 如有问题或建议可以在群内讨论。
...
...
uni_modules/vk-unicloud/package.json
浏览文件 @
b0c26706
{
"id"
:
"vk-unicloud"
,
"displayName"
:
"vk-unicloud-router开发框架核心库 - 已集成uni-id 框架内置了众多API、工具包,为你的业务扫平障碍。使你的项目刚起步进度就是50%"
,
"version"
:
"
1.9.3
"
,
"version"
:
"
2.0.1
"
,
"description"
:
"此为vk-unicloud-router开发框架核心库(uni_modules版本)已集成uni-id支持云函数url化。众多现成API,内置小白也能轻松上手的数据库API。"
,
"keywords"
:
[
"vk-unicloud-router"
,
...
...
uni_modules/vk-unicloud/uniCloud/cloudfunctions/common/vk-unicloud/index.js
浏览文件 @
b0c26706
此差异已折叠。
点击以展开。
uni_modules/vk-unicloud/uniCloud/cloudfunctions/common/vk-unicloud/package.json
浏览文件 @
b0c26706
{
"name"
:
"vk-unicloud"
,
"version"
:
"1.1
4.3
"
,
"version"
:
"1.1
5.0
"
,
"description"
:
"【云函数端SDK】VK云函数路由模式uniCloud开发框架,在router目录下执行 npm i vk-unicloud 进行安装和升级"
,
"main"
:
"index.js"
,
"homepage"
:
"https://gitee.com/vk-uni/vk-uni-cloud-router.git"
,
...
...
uni_modules/vk-unicloud/vk_modules/vk-unicloud-page/libs/function/index.js
浏览文件 @
b0c26706
...
...
@@ -831,8 +831,8 @@ pubfn.regExpTest = function(text, expText){
pubfn
.
createOrderNo
=
function
(
prefix
=
""
){
// 获取当前时间字符串格式如20200803093000123
let
fullTime
=
pubfn
.
getFullTime
(
new
Date
(),
1
);
// 生成订单号
return
prefix
+
fullTime
+
pubfn
.
random
(
1
6
);
fullTime
=
fullTime
.
substring
(
2
);
return
prefix
+
fullTime
+
pubfn
.
random
(
1
0
);
};
// 前端专属开始 -----------------------------------------------------------
...
...
uni_modules/vk-unicloud/vk_modules/vk-unicloud-page/libs/function/permission.js
浏览文件 @
b0c26706
export
default
function
(
Vue
){
Vue
.
prototype
.
$hasPermission
=
function
hasPermission
(
name
)
{
const
permission
=
this
.
$store
.
state
.
$user
.
userInfo
.
permission
||
[]
const
permission
=
this
.
$store
.
state
.
$user
.
permission
||
[]
return
permission
.
indexOf
(
name
)
>
-
1
}
Vue
.
prototype
.
$hasRole
=
function
hasRole
(
name
)
{
...
...
uni_modules/vk-unicloud/vk_modules/vk-unicloud-page/libs/store/mixin/mixin.js
浏览文件 @
b0c26706
...
...
@@ -2,43 +2,45 @@ module.exports = {
beforeCreate
()
{
// 将vuex方法挂在到vk实例中 beforeCreate created
let
{
vk
,
$store
}
=
this
;
if
(
typeof
$store
!==
"
undefined
"
&&
!
vk
.
$store
){
vk
.
$store
=
$store
;
if
(
typeof
$store
!==
"
undefined
"
&&
typeof
vk
.
getVuexStore
===
"
undefined
"
){
vk
.
getVuexStore
=
function
(){
return
$store
;
};
vk
.
vuex
=
(
name
,
value
)
=>
{
vk
.
$store
.
commit
(
'
updateStore
'
,
{
name
,
value
});
$store
.
commit
(
'
updateStore
'
,
{
name
,
value
});
};
/**
* (推荐) 设置vuex
* vk.vuex.set('$user.userInfo.avatar', avatar);
*/
vk
.
vuex
.
set
=
(
name
,
value
)
=>
{
vk
.
$store
.
commit
(
'
updateStore
'
,
{
name
,
value
});
$store
.
commit
(
'
updateStore
'
,
{
name
,
value
});
};
/**
* (推荐) 读取vuex(具有解除对象内存印射功能,且任意一层数据为undefined,不会报错)
* vk.vuex.get('$user.userInfo.avatar');
*/
vk
.
vuex
.
get
=
(
name
)
=>
{
let
value
=
vk
.
pubfn
.
getData
(
vk
.
$store
.
state
,
name
);
let
value
=
vk
.
pubfn
.
getData
(
$store
.
state
,
name
);
if
(
typeof
value
===
"
undefined
"
)
return
""
;
return
JSON
.
parse
(
JSON
.
stringify
(
value
));
};
vk
.
vuex
.
getters
=
(
name
)
=>
{
return
vk
.
$store
.
getters
[
name
];
return
$store
.
getters
[
name
];
};
/**
* 触发vuex的指定actions(异步)
* $user是模块名,addFootprint是对应模块的action名称
* vk.vuex.dispatch('$user/addFootprint', data);
*/
vk
.
vuex
.
dispatch
=
vk
.
$store
.
dispatch
;
vk
.
vuex
.
dispatch
=
$store
.
dispatch
;
/**
* 触发vuex的指定mutations
* $user是模块名,setFootprint是对应模块的action名称
* vk.vuex.commit('$user/setFootprint', data);
*/
vk
.
vuex
.
commit
=
vk
.
$store
.
commit
;
vk
.
vuex
.
commit
=
$store
.
commit
;
/* 另一种方式 */
/**
* vk.setVuex('$user.userInfo.avatar', avatar);
...
...
@@ -53,6 +55,6 @@ module.exports = {
}
},
computed
:
{
}
}
\ No newline at end of file
}
uni_modules/vk-unicloud/vk_modules/vk-unicloud-page/libs/vk-unicloud/vk-unicloud-callFunctionUtil.js
浏览文件 @
b0c26706
...
...
@@ -80,6 +80,7 @@ class CallFunctionUtil {
if
(
typeof
vk
.
setVuex
===
"
function
"
)
{
// 有安装vuex则使用vuex
vk
.
setVuex
(
'
$user.userInfo
'
,
{});
vk
.
setVuex
(
'
$user.permission
'
,
[]);
vk
.
removeStorageSync
(
config
.
uniIdUserInfoKeyName
);
}
else
{
// 否则使用本地缓存
...
...
使用帮助/11、万能连表.md
0 → 100644
浏览文件 @
b0c26706
### 场景1 :1张主表多张副表
##### 主表:uni-id-users (用户表)
##### 副表:order (用户订单表)
##### 副表:vip (会员卡表)
##### 以下代码作用是:用一条聚合查询语句,查询前10个用户的信息,并查询他们的最新10个订单记录表,再查询他们的VIP信息
```
js
res
=
await
vk
.
baseDao
.
selects
({
dbName
:
"
uni-id-users
"
,
getCount
:
false
,
pageIndex
:
1
,
pageSize
:
10
,
// 主表where条件
whereJson
:
{
},
// 主表字段显示规则
fieldJson
:
{
token
:
false
,
password
:
false
,
},
// 主表排序规则
sortArr
:
[{
"
name
"
:
"
_id
"
,
"
type
"
:
"
desc
"
}],
// 副表列表
foreignDB
:
[
{
dbName
:
"
order
"
,
localKey
:
"
_id
"
,
foreignKey
:
"
user_id
"
,
as
:
"
orderList
"
,
limit
:
10
,
// 副表where条件
whereJson
:
{},
// 副表字段显示规则
fieldJson
:
{},
// 副表排序规则
sortArr
:
[{
"
name
"
:
"
time
"
,
"
type
"
:
"
desc
"
}],
},
{
dbName
:
"
vip
"
,
localKey
:
"
_id
"
,
foreignKey
:
"
user_id
"
,
as
:
"
vipInfo
"
,
limit
:
1
,
// 当limit = 1时,以对象形式返回,否则以数组形式返回
}
]
});
```
### 场景2 :1张主表多张副表,同时副表也有多张副表
##### 主表:opendb-mall-comments (评论表)
##### 副表:uni-id-users (用户表)
##### 副表的副表:opendb-mall-orders(用户订单表)
##### 以下代码作用是:用一条聚合查询语句,查询前10个评论信息,并查询评论的发布者信息,再查询他们各自最新的3个订单信息
```
js
res
=
await
vk
.
baseDao
.
selects
({
dbName
:
"
opendb-mall-comments
"
,
pageIndex
:
1
,
pageSize
:
10
,
// 副表列表
foreignDB
:[
{
dbName
:
"
uni-id-users
"
,
localKey
:
"
user_id
"
,
foreignKey
:
"
_id
"
,
as
:
"
userInfo
"
,
limit
:
1
,
foreignDB
:[
{
dbName
:
"
opendb-mall-orders
"
,
localKey
:
"
_id
"
,
foreignKey
:
"
user_id
"
,
as
:
"
orderList
"
,
limit
:
3
,
sortArr
:[{
"
name
"
:
"
_add_time
"
,
"
type
"
:
"
desc
"
}],
},
]
}
]
});
```
### 场景3 : 需要查询同时满足主表和副表的条件,即副表不满足条件,则主表记录也不获取
##### 主表:opendb-mall-comments (评论表)
##### 副表:uni-id-users (用户表)
##### 以下代码作用是:用一条聚合查询语句,查询前10条女性用户的评论信息
```
js
res
=
await
vk
.
baseDao
.
selects
({
dbName
:
"
opendb-mall-comments
"
,
pageIndex
:
1
,
pageSize
:
10
,
// 副表列表
foreignDB
:[
{
dbName
:
"
uni-id-users
"
,
localKey
:
"
user_id
"
,
foreignKey
:
"
_id
"
,
as
:
"
userInfo
"
,
limit
:
1
}
],
lastWhereJson
:{
"
userInfo.gender
"
:
2
}
});
```
### 场景4 : 连表查询时需要按照离给定点从近到远输出(地理位置经纬度)。
##### 主表:vk-test (地理位置测试表)
##### 副表:uni-id-users (用户表)
##### 以下代码作用是:用一条聚合查询语句,查询前10条离我最近的记录
```
js
res
=
await
vk
.
baseDao
.
selects
({
dbName
:
"
vk-test
"
,
getCount
:
true
,
pageIndex
:
1
,
pageSize
:
10
,
// 主表where条件
whereJson
:
{
location
:
_
.
geoNear
({
geometry
:
new
db
.
Geo
.
Point
(
120.12792
,
30.228932
),
// 点的地理位置
maxDistance
:
4000
,
// 选填,最大距离,米为单位
minDistance
:
0
,
// 选填,最小距离,米为单位
distanceMultiplier
:
1
,
// 返回时在距离上乘以该数字 1代表米 100 代表厘米 0.001 代表千米
distanceField
:
"
distance
"
,
// 输出的每个记录中 distance 即是与给定点的距离
})
},
// 副表列表
foreignDB
:
[{
dbName
:
"
uni-id-users
"
,
localKey
:
"
user_id
"
,
foreignKey
:
"
_id
"
,
as
:
"
userInfo
"
,
limit
:
1
}]
});
```
### 场景5 : 连表查询,主表外键是数组(id数组),查询出数组内的每个记录详情
##### 主表:uni-id-users (用户表)
##### 副表:uni-id-roles (角色表)
##### 以下代码作用是:用一条聚合查询语句,查询前10个用户信息(同时带出角色列表roleList)
```
js
res
=
await
vk
.
baseDao
.
selects
({
dbName
:
"
uni-id-users
"
,
getCount
:
true
,
pageIndex
:
1
,
pageSize
:
10
,
// 主表where条件
whereJson
:
{
},
// 副表列表
foreignDB
:
[{
dbName
:
"
uni-id-roles
"
,
localKey
:
"
role
"
,
localKeyType
:
"
array
"
,
foreignKey
:
"
role_id
"
,
as
:
"
roleList
"
,
limit
:
500
}]
});
```
### 场景6 :分组查询
##### 主表:你的消费记录表或订单表
##### 副表:uni-id-users (用户表)
##### 以下代码作用是:用一条聚合查询语句,查询排行榜前10名用户消费金额和用户信息
```
js
res
=
await
vk
.
baseDao
.
selects
({
dbName
:
"
你的消费记录表或订单表
"
,
pageIndex
:
1
,
pageSize
:
10
,
// 主表where条件
whereJson
:
{
},
groupJson
:
{
_id
:
"
$user_id
"
,
// _id是分组id,这里指按user_id字段进行分组
user_id
:
_
.
$
.
first
(
"
$user_id
"
),
// 这里是为了把user_id原样输出
payment_amount
:
_
.
$
.
sum
(
"
$payment_amount
"
),
// sum求和支付金额
},
sortArr
:
[{
name
:
"
payment_amount
"
,
type
:
"
desc
"
}],
// 对分组后的结果进行排序
// 副表列表
foreignDB
:
[{
dbName
:
"
uni-id-users
"
,
localKey
:
"
user_id
"
,
foreignKey
:
"
_id
"
,
as
:
"
userInfo
"
,
limit
:
1
}],
// 最后的where,主要用于对分组后的结果再进行筛选 如:筛选金额大于1000才能上榜
lastWhereJson
:{
payment_amount
:
_
.
gt
(
1000
)
}
});
```
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录