preview-image.uvue 2.6 KB
Newer Older
1 2 3 4 5 6
<template>
	<view style="padding-left: 16rpx;padding-right: 16rpx;">
		<view>
			<text class="text-desc">图片指示器样式</text>
			<radio-group class="cell-ct" style="background-color: white;" @change="onIndicatorChanged">
				<view class="indicator-it" v-for="(item,index) in indicator" :key="item.value">
taohebin@dcloud.io's avatar
taohebin@dcloud.io 已提交
7
					<radio :checked="index == 0" :value="item.value">{{item.name}}</radio>
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
				</view>
			</radio-group>
		</view>
		<view>
			<checkbox-group @change="onCheckboxChange" style="margin-top: 32rpx;margin-bottom: 32rpx;margin-left: 16rpx;">
				<checkbox :checked="isLoop" style="margin-right: 30rpx;">循环播放</checkbox>
			</checkbox-group>
		</view>
		<view style="background-color: white;">
			<text class="text-desc">点击图片开始预览</text>
			<view class="cell-ct" style="background-color: #eeeeee; padding: 16rpx;">
				<view class="cell cell-choose-image" v-for="(image,index) in imageList" :key="index">
					<image style="width: 210rpx;height: 210rpx;" mode="aspectFit" :src="image" @click="previewImage(index)"></image>
				</view>
				<image class="cell cell-choose-image" src="/static/plus.png" @click="chooseImage">
					<view></view>
				</image>
			</view>
		</view>
	</view>
</template>

<script>
	type ItemType = {
		value: string,
		name: string
	}

	export default {
		data() {
			return {
张磊 已提交
39
				imageList: ["https://web-assets.dcloud.net.cn/unidoc/zh/uni@2x.png", "/static/uni.png"],
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
				indicator: [{
					value: "default",
					name: "圆点"
				}, {
					value: "number",
					name: "数字"
				}, {
					value: "none",
					name: "不显示"
				}] as ItemType[],
				currentIndicator: "default",
				isLoop: true
			}
		},
		methods: {
			previewImage(index: number) {
				uni.previewImage({
					urls: this.imageList,
					current: index,
					indicator: this.currentIndicator,
					loop: this.isLoop
				})
			},
			chooseImage() {
				uni.chooseImage({
					sourceType: ['album'],
					success: (e) => {
						this.imageList = this.imageList.concat(e.tempFilePaths)
					},
taohebin@dcloud.io's avatar
taohebin@dcloud.io 已提交
69
					fail(_) {
70 71 72 73 74 75
					}
				})
			},
			onIndicatorChanged(e: RadioGroupChangeEvent) {
				this.currentIndicator = e.detail.value
			},
taohebin@dcloud.io's avatar
taohebin@dcloud.io 已提交
76
			onCheckboxChange(_: CheckboxGroupChangeEvent) {
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
				this.isLoop = !this.isLoop
			}
		}
	}
</script>

<style>
	.text-desc {
		margin-top: 32rpx;
		margin-left: 16rpx;
		margin-bottom: 32rpx;
		font-weight: bold;
	}

	.cell-ct {
		display: flex;
		flex-wrap: wrap;
		flex-direction: row;
	}

	.cell {
		margin-left: 14rpx;
		width: 210rpx;
		height: 210rpx;
	}

	.cell-choose-image {
		border-width: 1px;
		border-color: lightgray;
	}

	.indicator-it {
		margin: 16rpx;
	}
</style>