preview-image.uvue 3.1 KB
Newer Older
1
<template>
DCloud-WZF's avatar
DCloud-WZF 已提交
2 3 4 5 6 7 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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
  <!-- #ifdef APP -->
  <scroll-view style="flex: 1">
    <!-- #endif -->
    <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"
          >
            <radio :checked="index == 0" :value="item.value">{{
              item.name
            }}</radio>
          </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>
    <!-- #ifdef APP -->
  </scroll-view>
  <!-- #endif -->
62 63 64
</template>

<script>
DCloud-WZF's avatar
DCloud-WZF 已提交
65 66 67 68
type ItemType = {
	value: string,
	name: string
}
69

DCloud-WZF's avatar
DCloud-WZF 已提交
70 71 72 73 74 75 76 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
export default {
	data() {
		return {
			imageList: ["https://web-assets.dcloud.net.cn/unidoc/zh/uni@2x.png", "/static/uni.png"],
			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)
				},
				fail(_) {
				}
			})
106
		},
DCloud-WZF's avatar
DCloud-WZF 已提交
107 108 109 110 111
		onIndicatorChanged(e: RadioGroupChangeEvent) {
			this.currentIndicator = e.detail.value
		},
		onCheckboxChange(_: CheckboxGroupChangeEvent) {
			this.isLoop = !this.isLoop
112 113
		}
	}
DCloud-WZF's avatar
DCloud-WZF 已提交
114
}
115 116 117
</script>

<style>
DCloud-WZF's avatar
DCloud-WZF 已提交
118 119 120 121 122 123
.text-desc {
  margin-top: 32rpx;
  margin-left: 16rpx;
  margin-bottom: 32rpx;
  font-weight: bold;
}
124

DCloud-WZF's avatar
DCloud-WZF 已提交
125 126 127 128 129
.cell-ct {
  display: flex;
  flex-wrap: wrap;
  flex-direction: row;
}
130

DCloud-WZF's avatar
DCloud-WZF 已提交
131 132 133 134 135
.cell {
  margin-left: 14rpx;
  width: 210rpx;
  height: 210rpx;
}
136

DCloud-WZF's avatar
DCloud-WZF 已提交
137 138
.cell-choose-image {
  border-width: 1px;
xuty73419315's avatar
xuty73419315 已提交
139
  border-style: solid;
DCloud-WZF's avatar
DCloud-WZF 已提交
140 141
  border-color: lightgray;
}
142

DCloud-WZF's avatar
DCloud-WZF 已提交
143 144 145 146
.indicator-it {
  margin: 16rpx;
}
</style>