preview-image.uvue 3.1 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>
H
hdx 已提交
23 24 25 26
        <view class="cell-ct" style="background-color: #eeeeee; padding: 8px">
          <view class="cell cell-choose-image" v-for="(image, index) in imageList" :key="index">
            <image style="width: 105px; height: 105px" mode="aspectFit" :src="image" @click="previewImage(index)">
            </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>
H
hdx 已提交
40 41 42 43
  type ItemType = {
    value : string,
    name : string
  }
44

H
hdx 已提交
45 46 47
  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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
        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(_) {
          }
        })
      },
H
hdx 已提交
82
      onIndicatorChanged(e : UniRadioGroupChangeEvent) {
H
hdx 已提交
83 84
        this.currentIndicator = e.detail.value
      },
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 107 108 109 110
  .cell {
    margin-left: 7px;
    width: 105px;
    height: 105px;
  }
111

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

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