show-toast.uvue 6.2 KB
Newer Older
1
<template>
Anne_LXM's avatar
Anne_LXM 已提交
2 3 4
  <!-- #ifdef APP -->
  <scroll-view direction="vertical" style="flex:1">
  <!-- #endif -->
5 6
    <page-head :title="title"></page-head>
    <view class="uni-padding-wrap">
Anne_LXM's avatar
Anne_LXM 已提交
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
      <view class="uni-padding-wrap">
        <text class="uni-title-text uni-common-mb">设置icon</text>
      </view>
      <view class="uni-list uni-common-pl">
        <radio-group @change="radioChangeIcon">
          <radio class="uni-list-cell uni-list-cell-pd radio-icon" v-for="(icon, index) in icon_enum" :key="icon.value"
            :class="index < icon_enum.length - 1 ? 'uni-list-cell-line' : ''" :value="icon.value"
            :checked="index === icon_current">{{icon.name}}</radio>
        </radio-group>
      </view>
      <view class="uni-list-cell uni-list-cell-padding">
        <view class="uni-list-cell-db">是否显示自定义图标</view>
        <switch :checked="imageSelect" @change="change_image_boolean" />
      </view>
      <view class="uni-list-cell uni-list-cell-padding">
        <view class="uni-list-cell-db">是否显示透明蒙层-屏蔽点击事件</view>
        <switch :checked="maskSelect" @change="change_mask_boolean" />
      </view>
      <view class="uni-title uni-list-cell-padding">提示的延迟时间,默认:1500(单位毫秒)</view>
      <view class="uni-list-cell-padding">
DCloud-WZF's avatar
DCloud-WZF 已提交
27 28
        <slider @change="sliderChange" foreColor="#007AFF" :value="intervalSelect" :min="1500" :max="5000"
          :show-value="true" />
Anne_LXM's avatar
Anne_LXM 已提交
29
      </view>
30
      <view class="uni-btn-v">
Anne_LXM's avatar
Anne_LXM 已提交
31
        <button class="uni-btn-v" type="default" @tap="toast1Tap" id="btn-toast-default">点击弹出toast</button>
杜庆泉's avatar
杜庆泉 已提交
32
        <button class="uni-btn-v" type="default" @tap="hideToast" id="btn-toast-hide">点击隐藏toast</button>
33
      </view>
Anne_LXM's avatar
Anne_LXM 已提交
34 35 36 37 38
      <!-- #ifdef APP -->
      <view class="uni-padding-wrap uni-common-mt">
        <text class="uni-title-text uni-common-mb"> 设置position,仅App生效 </text>
      </view>
      <view class="uni-list uni-common-pl">
DCloud-WZF's avatar
DCloud-WZF 已提交
39 40 41 42 43
        <radio-group @change="radioChangePosition">
          <radio class="uni-list-cell uni-list-cell-pd radio-position" v-for="(position, index) in position_enum"
            :key="position.value" :class="index < position_enum.length - 1 ? 'uni-list-cell-line' : ''"
            :value="position.value" :checked="index === position_current">{{position.name}}</radio>
        </radio-group>
Anne_LXM's avatar
Anne_LXM 已提交
44 45 46
      </view>
      <button class="uni-btn uni-btn-v uni-common-mb" type="default" @tap="toast2Tap">点击弹出设置position的toast</button>
      <!-- #endif -->
47 48
      <text>{{exeRet}}</text>
    </view>
Anne_LXM's avatar
Anne_LXM 已提交
49 50 51
  <!-- #ifdef APP -->
  </scroll-view>
  <!-- #endif -->
52
</template>
H
hdx 已提交
53

Anne_LXM's avatar
Anne_LXM 已提交
54 55 56 57 58 59 60 61 62
<script lang="uts">
  type IconItemType = {
    value : "success" | "error" | "fail" | "exception" | "loading" | "none";
    name : string
  }
  type PositionItemType = {
    value : "top" | "center" | "bottom";
    name : string
  }
63 64 65 66
  export default {
    data() {
      return {
        title: 'toast',
Anne_LXM's avatar
Anne_LXM 已提交
67
        exeRet: '',
DCloud-WZF's avatar
DCloud-WZF 已提交
68
        imageSelect: false,
Anne_LXM's avatar
Anne_LXM 已提交
69 70
        maskSelect: false,
        intervalSelect: 1500,
DCloud-WZF's avatar
DCloud-WZF 已提交
71
        position_current: 0,
Anne_LXM's avatar
Anne_LXM 已提交
72
        position_enum: [
Anne_LXM's avatar
Anne_LXM 已提交
73 74
          { "value": "top", "name": "top: 居上显示(Android 暂不支持)" },
          { "value": "center", "name": "center: 居中显示(Android 暂不支持)" },
Anne_LXM's avatar
Anne_LXM 已提交
75 76
          { "value": "bottom", "name": "bottom: 居底显示" },
        ] as PositionItemType[],
DCloud-WZF's avatar
DCloud-WZF 已提交
77
        icon_current: 0,
Anne_LXM's avatar
Anne_LXM 已提交
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
        icon_enum: [
          {
            value: 'success',
            name: '显示成功图标',
          },
          {
            value: 'error',
            name: '显示错误图标',
          },
          // {
          //   value: 'fail',
          //   name: '显示错误图标',
          // },
          // {
          //   value: 'exception',
          //   name: '显示异常图标,此时title文本无长度显示',
          // },
          {
            value: 'loading',
            name: '显示加载图标',
          },
          {
            value: 'none',
            name: '不显示图标',
          },
        ] as IconItemType[],
104 105
      }
    },
H
hdx 已提交
106
    onLoad() {
杜庆泉's avatar
杜庆泉 已提交
107
      uni.showToast({
H
hdx 已提交
108
        title: 'onLoad 调用示例,2秒后消失'
杜庆泉's avatar
杜庆泉 已提交
109
      })
H
hdx 已提交
110
      setTimeout(function () {
杜庆泉's avatar
杜庆泉 已提交
111
        uni.hideToast()
112
      }, 2000);
杜庆泉's avatar
杜庆泉 已提交
113
    },
114
    methods: {
115 116 117 118
      //自动化测试例专用
      jest_getWindowInfo() : GetWindowInfoResult {
        return uni.getWindowInfo();
      },
Anne_LXM's avatar
Anne_LXM 已提交
119 120 121 122 123 124 125
      radioChangeIcon(e : UniRadioGroupChangeEvent) {
        for (let i = 0; i < this.icon_enum.length; i++) {
          if (this.icon_enum[i].value === e.detail.value) {
            this.icon_current = i;
            break;
          }
        }
126
      },
Anne_LXM's avatar
Anne_LXM 已提交
127 128
      change_image_boolean: function (e : UniSwitchChangeEvent) {
        this.imageSelect = e.detail.value
129
      },
Anne_LXM's avatar
Anne_LXM 已提交
130 131
      change_mask_boolean: function (e : UniSwitchChangeEvent) {
        this.maskSelect = e.detail.value
132
      },
Anne_LXM's avatar
Anne_LXM 已提交
133 134 135 136 137 138 139 140 141 142
      sliderChange(e : UniSliderChangeEvent) {
        this.intervalSelect = e.detail.value
      },
      radioChangePosition(e : UniRadioGroupChangeEvent) {
        for (let i = 0; i < this.position_enum.length; i++) {
          if (this.position_enum[i].value === e.detail.value) {
            this.position_current = i;
            break;
          }
        }
143
      },
Anne_LXM's avatar
Anne_LXM 已提交
144
      toast1Tap: function () {
145
        uni.showToast({
Anne_LXM's avatar
Anne_LXM 已提交
146 147 148
          title: "默认",
          icon: this.icon_enum[this.icon_current].value,
          duration: this.intervalSelect,
DCloud-WZF's avatar
DCloud-WZF 已提交
149
          image: this.imageSelect ? "/static/uni.png" : null,
Anne_LXM's avatar
Anne_LXM 已提交
150
          mask: this.maskSelect,
151
          success: (res) => {
Anne_LXM's avatar
Anne_LXM 已提交
152
            // console.log('success:',res)
杜庆泉's avatar
杜庆泉 已提交
153
            this.exeRet = "success:" + JSON.stringify(res)
154 155 156 157 158 159
          },
          fail: (res) => {
            this.exeRet = "fail:" + JSON.stringify(res)
          },
        })
      },
160
      // #ifdef APP
Anne_LXM's avatar
Anne_LXM 已提交
161 162
      toast2Tap: function () {
        let positionValue = this.position_enum[this.position_current].value
163
        uni.showToast({
Anne_LXM's avatar
Anne_LXM 已提交
164 165
          title: "显示一段轻提示,position:" + positionValue,
          position: positionValue,
166
          success: (res) => {
杜庆泉's avatar
杜庆泉 已提交
167
            this.exeRet = "success:" + JSON.stringify(res)
168 169 170 171 172 173 174 175 176 177 178 179
          },
          fail: (res) => {
            this.exeRet = "fail:" + JSON.stringify(res)
          },
        })
      },
      // #endif
      hideToast: function () {
        uni.hideToast()
      }
    }
  }
Y
yurj26 已提交
180
</script>