grid.vue 5.2 KB
Newer Older
DCloud_JSON's avatar
DCloud_JSON 已提交
1 2 3
<template>
	<view class="warp">
		<!-- #ifdef APP-PLUS -->
study夏羽's avatar
study夏羽 已提交
4
		<statusBar></statusBar>
5
		<!-- #endif -->
DCloud_JSON's avatar
DCloud_JSON 已提交
6
		
7 8 9 10
		<!-- banner -->
		<unicloud-db ref="bannerdb" v-slot:default="{data, loading, error, options}" collection="opendb-banner"
			field="_id,bannerfile,open_url,title" @load="onqueryload">
			<!-- 当无banner数据时显示占位图 -->
study夏羽's avatar
study夏羽 已提交
11 12 13 14 15 16 17 18 19
			<image v-if="!(loading||data.length)" class="banner-image" src="/static/uni-center/headers.png" mode="aspectFill" :draggable="false" />
			
			<swiper v-else class="swiper-box" @change="changeSwiper" :current="current" indicator-dots>
				<swiper-item v-for="(item, index) in data" :key="item._id">
					<view class="swiper-item" @click="clickBannerItem(item)">
						<image class="banner-image" :src="item.bannerfile.url" mode="aspectFill" :draggable="false" />
					</view>
				</swiper-item>
			</swiper>
20 21
		</unicloud-db>

study夏羽's avatar
study夏羽 已提交
22 23 24 25 26 27
		<!-- 宫格 -->
		<view class="section-box">
			<text class="decoration"></text>
			<text class="section-text">{{$t('grid.grid')}}</text>
		</view>
		
28 29 30 31 32 33 34 35 36 37 38 39
		<view class="example-body">
			<uni-grid :column="3" :highlight="true" @change="change">
				<template v-for="(item,i) in gridList">
					<uni-grid-item :index="i" :key="i"
						v-if="i<3 || i>2&&i<6&&hasLogin || i>5&&uniIDHasRole('admin')"
					>
						<view class="grid-item-box" style="background-color: #fff;">
							<!-- <image :src="'/static/grid/c'+(i+1)+'.png'" class="image" mode="aspectFill" /> -->
							<text class="big-number">{{i+1}}</text>
							<text class="text">{{item}}</text>
						</view>
					</uni-grid-item>
DCloud_JSON's avatar
DCloud_JSON 已提交
40 41 42 43 44 45 46
				</template>
			</uni-grid>
		</view>
	</view>
</template>

<script>
study夏羽's avatar
study夏羽 已提交
47
	// #ifdef APP-PLUS
DCloud_JSON's avatar
DCloud_JSON 已提交
48
	import statusBar from "@/uni_modules/uni-nav-bar/components/uni-nav-bar/uni-status-bar";
study夏羽's avatar
study夏羽 已提交
49
	// #endif
DCloud_JSON's avatar
DCloud_JSON 已提交
50
	export default {
study夏羽's avatar
study夏羽 已提交
51
		// #ifdef APP-PLUS
DCloud_JSON's avatar
DCloud_JSON 已提交
52 53 54
		components: {
			statusBar
		},
study夏羽's avatar
study夏羽 已提交
55
		// #endif
DCloud_JSON's avatar
DCloud_JSON 已提交
56 57 58 59
		data() {
			return {
				gridList: [],
				current: 0,
DCloud_JSON's avatar
DCloud_JSON 已提交
60
				hasLogin:false
DCloud_JSON's avatar
DCloud_JSON 已提交
61 62
			}
		},
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
		onShow() {
			this.hasLogin = uniCloud.getCurrentUserInfo().tokenExpired > Date.now()
		},
		onLoad() {
			let gridList = []
			for (var i = 0; i < 3; i++) {
				gridList.push( this.$t('grid.visibleToAll') )
			}
			for (var i = 0; i < 3; i++) {
				gridList.push( this.$t('grid.invisibleToTourists') )
			}
			for (var i = 0; i < 3; i++) {
				gridList.push( this.$t('grid.adminVisible') )
			}
			this.gridList = gridList
DCloud_JSON's avatar
DCloud_JSON 已提交
78 79 80 81
		},
		methods: {
			change(e) {
				uni.showToast({
82
					title:this.$t('grid.clickTip') + " " + `${e.detail.index + 1}` + " " + this.$t('grid.clickTipGrid'),
DCloud_JSON's avatar
DCloud_JSON 已提交
83 84 85 86 87 88
					icon: 'none'
				})
			},
			/**
			 * banner加载后触发的回调
			 */
89
			onqueryload(data) {
DCloud_JSON's avatar
DCloud_JSON 已提交
90 91 92 93 94 95 96 97 98 99 100
			},
			changeSwiper(e) {
				this.current = e.detail.current
			},
			/**
			 * 点击banner的处理
			 */
			clickBannerItem(item) {
				// 有外部链接-跳转url
				if (item.open_url) {
					uni.navigateTo({
study夏羽's avatar
study夏羽 已提交
101
						url: '/uni_modules/uni-id-pages/pages/common/webview/webview?url=' + item.open_url + '&title=' + item.title,
DCloud_JSON's avatar
DCloud_JSON 已提交
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
						success: res => {},
						fail: () => {},
						complete: () => {}
					});
				}
				// 其余业务处理
			}
		}
	}
</script>

<style>
	/* #ifndef APP-NVUE */
	page {
		display: flex;
		flex-direction: column;
		box-sizing: border-box;
		background-color: #fff;
		min-height: 100%;
		height: auto;
	}
	view {
		font-size: 14px;
		line-height: inherit;
	}
	.example-body {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		flex-wrap: wrap;
		justify-content: center;
		padding: 0;
		font-size: 14px;
		background-color: #ffffff;
	}
	/* #endif */
study夏羽's avatar
study夏羽 已提交
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
	
	.section-box{
		display: flex;
		flex-direction: row;
		align-items: center;
		padding: 20rpx;
	}
	.decoration{
		width: 4px;
		height: 12px;
		border-radius: 10px;
		background-color: #2979ff;
	}
	.section-text{
		color: #333;
		margin-left: 15rpx;
	}
DCloud_JSON's avatar
DCloud_JSON 已提交
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172

	/* #ifdef APP-NVUE */
	.warp {
		background-color: #fff;
	}
	/* #endif */

	.example-body {
		flex-direction: column;
		padding: 15px;
		background-color: #ffffff;
	}

	.image {
		width: 50rpx;
		height: 50rpx;
	}
173 174 175 176 177 178 179
	
	.big-number{
		font-size: 50rpx;
		font-weight: 700;
		font-stretch: condensed;
		font-style:oblique;
	}
180
	
DCloud_JSON's avatar
DCloud_JSON 已提交
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
	.text {
		text-align: center;
		font-size: 26rpx;
		margin-top: 10rpx;
	}

	.example-body {
		/* #ifndef APP-NVUE */
		display: block;
		/* #endif */
	}

	.grid-item-box {
		flex: 1;
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
		align-items: center;
		justify-content: center;
		padding: 15px 0;
	}

	.banner-image {
		width: 750rpx;
		height: 400rpx;
	}

	.swiper-box {
		height: 400rpx;
	}

	.search-icons {
		padding: 16rpx;
	}

	.search-container-bar {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		justify-content: center;
		align-items: center;
		position: fixed;
		left: 0;
		right: 0;
		z-index: 10;
		background-color: #fff;
	}

	/* #ifndef APP-NVUE || VUE3*/
232
	::v-deep
DCloud_JSON's avatar
DCloud_JSON 已提交
233 234 235 236 237 238
	/* #endif */
	.uni-searchbar__box {
		border-width: 0;
	}

	/* #ifndef APP-NVUE || VUE3 */
239
	::v-deep
DCloud_JSON's avatar
DCloud_JSON 已提交
240 241 242 243
	/* #endif */
	.uni-input-placeholder {
		font-size: 28rpx;
	}
244
</style>