提交 5820d78c 编写于 作者: S shutao

Merge branch 'master' of https://gitee.com/dcloud/unidocs-zh

......@@ -38,10 +38,53 @@
- `<page-meta>` 目前支持的配置仅为上表所列,并不支持所有 page.json 的配置
- `<page-meta>` 与 pages.json 的设置相冲突时,会覆盖 page.json 的配置
#### head标签@head
#### 示例代码
> 新增于`HBuilderX 3.3.0`
vue3 下还可以使用在`page-meta`内使用浏览器原生 head 标签,**此用法仅 vue3 版本可用**,方便在 编译为 ssr 时进行 seo 优化。
```html
<template>
<page-meta
:background-text-style="bgTextStyle"
:background-color="bgColor"
:background-color-top="bgColorTop"
:background-color-bottom="bgColorBottom"
:scroll-top="scrollTop"
page-style="color: green"
root-font-size="16px"
>
<head> // 仅vue3支持,此节点下的元素会被拷贝到h5页面的head标签下(服务端渲染时也会生效),可以利用此特性进行seo优化
<meta name="keyword" :content="title" />
</head>
</page-meta>
<view class="content">
</view>
</template>
<script>
export default {
data() {
return {
keyword: '',
}
},
serverPrefetch(){ // 仅vue3版本支持
this.keyword = "ServerKeyword"
},
onLoad() {
},
methods: {
}
}
</script>
```
#### 示例代码
```html
<template>
<page-meta
:background-text-style="bgTextStyle"
......@@ -85,3 +128,4 @@
}
</script>
```
......@@ -3410,6 +3410,101 @@ let res = await db.collection('orders').aggregate()
]
```
**多表联表查询**
假设 `orders` 集合有以下记录:
```js
[
{"_id":4,"book":"book1","price":30,"quantity":2},
{"_id":5,"book":"book2","price":20,"quantity":1}
]
```
`books` 集合有以下记录:
```js
[
{"_id":"book1","author":"author1","title":"novel 1"},
{"_id":"book2","author":"author2","title":"science 1"},
]
```
`authors` 集合有以下记录:
```js
[
{"_id":"author1","name":"A1"},
{"_id":"author2","author":"A2"}
]
```
如需orders关联books,book再关联authors查询,可以在pipeline内再使用lookup
```js
const db = cloud.database()
const $ = db.command.aggregate
let res = await db.collection('orders').aggregate()
.lookup({
from: 'books',
let: {
book_id: '$book'
},
pipeline: $.pipeline()
.match(
$.expr($.eq(['$_id', '$$book_id']))
)
.lookup({
from: 'authors',
let: {
author_id: '$author'
},
pipeline: $.pipeline()
.match(
$.expr($.eq(['$_id', '$$author_id']))
)
.done(),
as: 'authorList'
})
.done(),
as: 'bookList',
})
.end()
```
结果如下
```js
[
{
"_id":4,
"book":"book1",
"price":30,
"quantity":2,
"bookList": [{
"_id":"book1",
"author":"author1",
"title":"novel 1",
authorList: [{
"_id":"author1",
"name":"A1"
}]
}]
},
{
"_id":5,
"book":"book2",
"price":20,
"quantity":1,
"bookList": [{
"_id":"book2",
"author":"author2",
"title":"science 1",
authorList: [{
"_id":"author2",
"name":"A2"
}]
}]
}
]
```
### match@aggregate-match
聚合阶段。根据条件过滤文档,并且把符合条件的文档传递给下一个流水线阶段。
......
......@@ -5,7 +5,9 @@
keyword: 短信,sms
-->
从HBuilderX 2.8.1起,uniCloud内置了短信发送API。给开发者提供更方便、更便宜的短信发送能力。
> 自HBuilderX 3.3.0-alpha起,本接口支持传入phoneList参数批量发送短信,其他参数均于发送单条短信相同
自HBuilderX 2.8.1起,uniCloud内置了短信发送API。给开发者提供更方便、更便宜的短信发送能力。
该服务类似小程序的模板消息,在一个固定模板格式的文字里自定义某些字段,而不是所有文字都可以随便写。
......@@ -141,6 +143,7 @@ keyword: 短信,sms
**调用示例**
```js
// 发送单条短信示例
'use strict';
exports.main = async (event, context) => {
try {
......@@ -149,7 +152,7 @@ exports.main = async (event, context) => {
smsKey: '****************',
smsSecret: '****************',
phone: '188********',
templateId: 'uniID_code',
templateId: '100**', // 请替换为自己申请的模板id
data: {
name: 'DCloud',
code: '123456',
......@@ -170,6 +173,35 @@ exports.main = async (event, context) => {
}
};
// 批量发送短信示例
'use strict';
exports.main = async (event, context) => {
try {
const res = await uniCloud.sendSms({
appid: '__UNI__xxxxxxx',
smsKey: '****************',
smsSecret: '****************',
phoneList: ['188********', '138********'],
templateId: '100**', // 请替换为自己申请的模板id
data: {
name: 'DCloud',
code: '123456',
action: '注册',
expMinute: '3',
}
})
// 调用成功,请注意这时不代表发送成功
return res
} catch(err) {
// 调用失败
console.log(err.errCode)
console.log(err.errMsg)
return {
code: err.errCode,
msg: err.errMsg
}
}
};
```
本示例使用的模板为:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册