line-up.schema.json
// 文档教程: https://uniapp.dcloud.net.cn/uniCloud/schema
{
"bsonType": "object",
"required": [
"name", "type", "start_time", "end_time", "city", "address"
],
"permission": {
"read": true,
"create": true,
"update": true,
"delete": false
},
"properties": {
"_id": {
"description": "ID,系统自动生成"
},
"user_id": {
"bsonType": "string",
"title": "用户id",
"description": "用户id"
},
"type": {
"bsonType": "int",
"title": "类型",
"enum": [{
"text": "默认",
"value": 0
}, {
"text": "1类",
"value": 1
}, {
"text": "2类",
"value": 2
}],
"defaultValue": 0,
"description": "类型"
},
"name": {
"bsonType": "string",
"title": "名称",
"description": "名称"
},
"start_time": {
"bsonType": "timestamp",
"title": "开始时间",
"description": "开始时间"
},
"end_time": {
"bsonType": "timestamp",
"title": "结束时间",
"description": "结束时间"
},
"address": {
"bsonType": "string",
"title": "地址",
"description": "地址"
},
"longitude": {
"bsonType": "string",
"title": "经度",
"description": "坐标,经度"
},
"latitude": {
"bsonType": "string",
"title": "纬度",
"description": "坐标,纬度"
},
"location_disclosure": {
"bsonType": "bool",
"title": "位置公开",
"defaultValue": true,
"description": "位置公开"
},
"queue_time": {
"bsonType": "int",
"title": "排队时间",
"defaultValue": 0,
"description": "预计排队时间"
},
"area": {
"bsonType": "string",
"title": "所在区域",
"description": "所在区域",
"enum": {
"collection": "opendb-city-china",
"field": "code as value,name as text, eq(type, 2) as isleaf"
},
"foreignKey": "opendb-city-china.code",
"enumType": "tree"
},
"create_time": {
"bsonType": "timestamp",
"description": "创建时间",
"title": "创建时间",
"forceDefaultValue": {
"$env": "now"
}
}
}
}
list.vue
<template>
<view class="container">
<unicloud-db ref="udb" v-slot:default="{data, pagination, loading, hasMore, error}" :collection="collectionList"
orderby="line-up.create_time desc"
field="user_id,type,name,start_time,end_time,address,longitude,latitude,location_disclosure,area{name as text},'line-up'.create_time">
<view v-if="error">{{error.message}}</view>
<view v-else-if="data">
<view v-for="(item, index) in data" :key="index" class="box margin-20 padding-30">
<view class="flex justify-between">
<u--text :lines="1" :text="item.name"></u--text>
<u-tag v-if="item.type>0" :text="formOptions.type_localdata[item.type].text" plain size="mini"
type="warning"></u-tag>
</view>
<view v-if="item.address" class="margin-top10 text-gray">
<text class="margin-right10">{{item.area && item.area[0] && item.area[0].text}}</text>
<text>{{item.address}}</text>
<!-- <u-text prefixIcon="baidu" type="info" text="公开"></u-text> -->
<!-- <view class="margin-left10">
<uni-icons custom-prefix="iconfont" type="icon-dizhi" size="14"></uni-icons>
</view> -->
</view>
<view class="margin-top10 flex justify-between align-end">
<view class="">
<view class="flex align-center">
<u-icon name="arrow-up-fill" color="#53c21d" size="10"></u-icon>
<text class="margin-left10">开始</text>
<uni-dateformat format="MM-dd | hh:mm" :date="item.start_time"></uni-dateformat>
</view>
<view class="flex align-center">
<u-icon name="arrow-up-fill" color="#e45656" size="10"></u-icon>
<text class="margin-left10">结束</text>
<uni-dateformat format="MM-dd | hh:mm" :date="item.end_time"></uni-dateformat>
</view>
</view>
<view class="flex align-end">
<view class="margin-right10">
<u-button type="primary" size="mini" text="编辑" @click="edit(item._id)"></u-button>
</view>
<u-button type="primary" size="mini" text="排队时间" @click="queueTime(item._id)"></u-button>
</view>
</view>
</view>
</view>
<uni-load-more :status="loading?'loading':(hasMore ? 'more' : 'noMore')"></uni-load-more>
</unicloud-db>
<!-- <uni-fab ref="fab" horizontal="right" vertical="bottom" :pop-menu="false" @fabClick="fabClick" /> -->
</view>
</template>
<script>
const db = uniCloud.database()
export default {
data() {
return {
collectionList: "line-up,opendb-city-china",
formOptions: {
"type_localdata": [{
"text": "默认",
"value": 0
},
{
"text": "1类",
"value": 1
},
{
"text": "2类",
"value": 2
}
]
},
loadMore: {
contentdown: '',
contentrefresh: '',
contentnomore: ''
}
}
},
onPullDownRefresh() {
this.$refs.udb.loadData({
clear: true
}, () => {
uni.stopPullDownRefresh()
})
},
onReachBottom() {
this.$refs.udb.loadMore()
},
methods: {
queueTime(id) {
uni.navigateTo({
url: "/pages/line-up/setQueueTime?id=" + id,
events: {
// 监听修改页面成功修改数据后, 刷新当前页面数据
refreshData: () => {
this.$refs.udb.loadData({
clear: true
})
}
}
});
},
edit(id) {
uni.navigateTo({
url: "/pages/line-up/edit?id=" + id,
events: {
// 监听修改页面成功修改数据后, 刷新当前页面数据
refreshData: () => {
this.$refs.udb.loadData({
clear: true
})
}
}
});
},
handleItemClick(id) {
uni.navigateTo({
url: './detail?id=' + id
})
},
fabClick() {
// 打开新增页面
uni.navigateTo({
url: './add',
events: {
// 监听新增数据成功后, 刷新当前页面数据
refreshData: () => {
this.$refs.udb.loadData({
clear: true
})
}
}
})
}
}
}
</script>
<style lang="scss">
.box {
background-color: white;
border: 1upx solid #e1e1e1;
margin: 20upx;
border-radius: 10upx;
box-shadow: 6upx 6upx 12upx -4upx #ccc;
}
</style>
<style lang="scss">
page {
background-color: $u-bg-color;
}
</style>
5***@qq.com (作者)
问题解决了。谢谢!建议在文档中添加此提示。
2022-10-30 03:15