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

<script>
雪洛's avatar
雪洛 已提交
40
  type Indicator = "number" | "default" | "none"
H
hdx 已提交
41
  type ItemType = {
雪洛's avatar
雪洛 已提交
42
    value : Indicator,
H
hdx 已提交
43 44 45 46 47
    name : string
  }
  export default {
    data() {
      return {
雪洛's avatar
雪洛 已提交
48
        imageList: ["https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/uni@2x.png", "/static/uni.png"],
H
hdx 已提交
49 50 51 52 53 54 55 56 57 58
        indicator: [{
          value: "default",
          name: "圆点"
        }, {
          value: "number",
          name: "数字"
        }, {
          value: "none",
          name: "不显示"
        }] as ItemType[],
雪洛's avatar
雪洛 已提交
59
        currentIndicator: "default" as Indicator,
H
hdx 已提交
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
        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(_) {
          }
        })
      },
H
hdx 已提交
82
      onIndicatorChanged(e : UniRadioGroupChangeEvent) {
雪洛's avatar
雪洛 已提交
83
        this.currentIndicator = e.detail.value as Indicator
H
hdx 已提交
84
      },
H
hdx 已提交
85
      onCheckboxChange(_ : UniCheckboxGroupChangeEvent) {
H
hdx 已提交
86 87 88 89
        this.isLoop = !this.isLoop
      }
    }
  }
90 91 92
</script>

<style>
H
hdx 已提交
93 94 95 96 97 98
  .text-desc {
    margin-top: 16px;
    margin-left: 8px;
    margin-bottom: 16px;
    font-weight: bold;
  }
99

H
hdx 已提交
100 101 102 103 104
  .cell-ct {
    display: flex;
    flex-wrap: wrap;
    flex-direction: row;
  }
105

H
hdx 已提交
106
  .cell {
张磊 已提交
107 108 109 110
    margin-left: 3px;
    margin-right: 3px;
    width: 100px;
    height: 100px;
H
hdx 已提交
111
  }
112

H
hdx 已提交
113 114 115 116 117
  .cell-choose-image {
    border-width: 1px;
    border-style: solid;
    border-color: lightgray;
  }
118

H
hdx 已提交
119 120 121
  .indicator-it {
    margin: 8px;
  }
DCloud-WZF's avatar
DCloud-WZF 已提交
122
</style>