preview-image.uvue 3.8 KB
Newer Older
DCloud-WZF's avatar
DCloud-WZF 已提交
1 2 3 4 5 6 7 8 9
<template>
  <!-- #ifdef APP -->
  <scroll-view style="flex: 1">
  <!-- #endif -->
    <view style="padding-left: 8px; padding-right: 8px">
      <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">
张磊 已提交
10
            <radio :disabled="isWeb" :checked="index == 0" :value="item.value">{{
DCloud-WZF's avatar
DCloud-WZF 已提交
11 12 13 14 15 16 17
              item.name
            }}</radio>
          </view>
        </radio-group>
      </view>
      <view>
        <checkbox-group @change="onCheckboxChange" style="margin-top: 16px; margin-bottom: 16px; margin-left: 8px">
张磊 已提交
18
          <checkbox :disabled="isWeb" :checked="isLoop" style="margin-right: 15px">循环播放</checkbox>
DCloud-WZF's avatar
DCloud-WZF 已提交
19 20 21 22 23 24 25 26 27 28 29 30 31 32
        </checkbox-group>
      </view>
      <view style="background-color: white">
        <text class="text-desc">点击图片开始预览</text>
        <view class="cell-ct" style="margin: 8px;">
          <view class="cell cell-choose-image" v-for="(image, index) in imageList" :key="index">
            <image style="width: 100px; height: 100px" 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>
张磊 已提交
33 34 35 36 37
      <view style="margin:8px;">
        <text style="color: black;font-size: 18px;margin-bottom: 4px;">注意事项:</text>
        <text style="font-size: 17px;margin-left: 4px;color: darkgray;">1、indicator属性仅App平台支持。</text>
        <text style="font-size: 17px;margin-left: 4px;color: darkgray;">2、Web平台不支持loop属性。</text>
      </view>
DCloud-WZF's avatar
DCloud-WZF 已提交
38 39 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
    </view>
  <!-- #ifdef APP -->
  </scroll-view>
  <!-- #endif -->
</template>

<script>
  type Indicator = "number" | "default" | "none"
  type ItemType = {
    value : Indicator,
    name : string
  }
  export default {
    data() {
      return {
        imageList: ["https://qiniu-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" as Indicator,
张磊 已提交
65 66 67 68 69 70
        // #ifdef WEB
        isWeb: true,
        // #endif
        // #ifndef WEB
        isWeb: false,
        // #endif
DCloud-WZF's avatar
DCloud-WZF 已提交
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 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
        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(_) {
          }
        })
      },
      onIndicatorChanged(e : UniRadioGroupChangeEvent) {
        this.currentIndicator = e.detail.value as Indicator
      },
      onCheckboxChange(_ : UniCheckboxGroupChangeEvent) {
        this.isLoop = !this.isLoop
      }
    }
  }
</script>

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

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

  .cell {
    margin-left: 3px;
    margin-right: 3px;
    width: 100px;
    height: 100px;
  }

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

  .indicator-it {
    margin: 8px;
  }
张磊 已提交
133
</style>