下面是查询代码
<template>
<unicloud-db
ref="udb"
:collection="collectionList"
:where="where"
page-data="replace"
:orderby="orderby"
:getcount="true"
:page-size="options.pageSize"
:page-current="options.pageCurrent"
v-slot:default="{ data, pagination, loading, error, options }"
:options="options"
>
<view v-if="error">{{ error.message }}</view>
<view v-else>{{ data }}</view>
</unicloud-db>
</template>
<script>
const db = uniCloud.database()
const dbOrderBy = 'created_time desc' // 排序字段
export default {
data() {
return {
collectionList: 'order',
adminVersion: version,
where: '',
orderby: dbOrderBy
}
},
}
</script>
下面是schema
{
"bsonType": "object",
"required": ["create_uid", "created_time", "product_id", "date", "uid"],
"permission": {
"read": true,
"create": "auth.uid!=null",
"update": "auth.uid==doc.uid",
"delete": "auth.uid==doc.uid"
},
"properties": {
"_id": {
"description": "ID,系统自动生成"
},
"created_time": {
"bsonType": "timestamp",
"title": "创建时间",
"description": "创建时间",
"forceDefaultValue": {
"$env": "now"
}
},
"create_uid": {
"bsonType": "string",
"title": "创建者",
"forceDefaultValue": {
"$env": "uid"
}
},
"date": {
"bsonType": "timestamp",
"title": "订货日期"
},
"uid": {
"bsonType": "string",
"title": "用户",
"defaultValue": {
"$env": "uid"
}
},
"store_id": {
"bsonType": "string",
"title": "门店",
"foreignKey": "store._id",
"enum": {
"collection": "store",
"field": "name as text,_id as value"
},
"componentForEdit": {
"name": "uni-data-checkbox"
}
},
"state": {
"bsonType": "int",
"title": "状态",
"enum": [{
"text": "待发货",
"value": 0
}, {
"text": "待确认",
"value": 1
}, {
"text": "已完成",
"value": 2
}],
"defaultValue":0
},
"product_id": {
"bsonType": "array",
"title": "商品"
},
"trade_snapshot": {
"bsonType": "string",
"title": "交易快照"
}
}
}