loading.uvue 3.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
<template>
  <view>
    <page-head :title="title"></page-head>
    <view class="uni-list">
      <view class="uni-list-cell uni-list-cell-pd">
        <view class="uni-list-cell-db">是否显示透明蒙层-屏蔽点击事件</view>
        <switch :checked="maskSelect" @change="maskChange" />
      </view>
      <view class="uni-padding-wrap">
        <view class="uni-title uni-common-mt">
          <text class="uni-title-text"> 设置标题 </text>
        </view>
      </view>
      <view class="uni-list uni-common-pl">
A
Anne_LXM 已提交
15
        <radio-group @change="radioChange">
16 17 18 19
          <radio class="uni-list-cell uni-list-cell-pd radio" v-for="(item, index) in items" :key="item.value"
            :class="index < items.length - 1 ? 'uni-list-cell-line' : ''" :value="item.value"
            :checked="index === current">
        <radio-group @change="radioChange" class="radio-group">
DCloud-WZF's avatar
DCloud-WZF 已提交
20 21 22 23 24 25 26 27
          <radio
            class="uni-list-cell uni-list-cell-pd radio"
            v-for="(item, index) in items"
            :key="item.value"
            :class="index < items.length - 1 ? 'uni-list-cell-line' : ''"
            :value="item.value"
            :checked="index === current"
          >
28 29 30 31 32 33 34
            {{ item.name }}
          </radio>
        </radio-group>
      </view>
    </view>
    <view class="uni-padding-wrap">
      <view class="uni-btn-v">
DCloud-WZF's avatar
DCloud-WZF 已提交
35 36 37 38 39 40
        <button class="uni-btn-v" type="primary" @click="showLoading">
          显示 loading 提示框
        </button>
        <button class="uni-btn-v" @click="hideLoading">
          隐藏 loading 提示框
        </button>
W
wanganxp 已提交
41
        <text>为方便演示,loading弹出3秒后自动关闭</text>
42 43 44 45 46 47 48 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
      </view>
    </view>
  </view>
</template>
<script lang="uts">
  type ItemType = {
    value : string
    name : string
  }
  export default {
    data() {
      return {
        title: 'loading',
        items: [
          {
            value: 'null',
            name: '无标题',
          },
          {
            value: '三秒后自动关闭',
            name: '普通标题',
          },
          {
            value: '超长文本内容,测试超出范围-超长文本内容,测试超出范围-三秒后自动关闭',
            name: '长标题',
          },
        ] as ItemType[],
        current: 0,
        maskSelect: false,
        titleSelect: "null"
      }
    },
杜庆泉's avatar
杜庆泉 已提交
74 75 76 77 78 79 80 81
    onLoad(){
      uni.showLoading({
      	title:'onLoad 调用示例,1秒后消失'
      })
      setTimeout(function() {
        uni.hideLoading()
      }, 1000);
    },
82
    methods: {
DCloud-WZF's avatar
DCloud-WZF 已提交
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
type ItemType = {
  value : string
  name : string
}
export default {
  data() {
    return {
      title: 'loading',
      items: [
        {
          value: 'null',
          name: '无标题',
        },
        {
          value: '三秒后自动关闭',
          name: '普通标题',
        },
        {
          value: '超长文本内容,测试超出范围-超长文本内容,测试超出范围-三秒后自动关闭',
          name: '长标题',
        },
      ] as ItemType[],
      current: 0,
      maskSelect: false,
      titleSelect: "null"
    }
  },
  methods: {

    radioChange(e : RadioGroupChangeEvent) {
      const selected = this.items.find((item) : boolean => {
        return item.value == e.detail.value
      })
      if (selected != null) {
        this.titleSelect = selected.value
118 119
      }
    },
DCloud-WZF's avatar
DCloud-WZF 已提交
120 121 122 123
    maskChange: function (e : SwitchChangeEvent) {
      this.maskSelect = e.detail.value
    },
    showLoading: function () {
124

DCloud-WZF's avatar
DCloud-WZF 已提交
125 126 127 128 129 130 131 132 133 134 135
      console.log(this.titleSelect)
      if (this.titleSelect == "null") {
        uni.showLoading({
          title: "",
          mask: this.maskSelect
        });
      } else {
        uni.showLoading({
          title: this.titleSelect,
          mask: this.maskSelect
        });
136
      }
DCloud-WZF's avatar
DCloud-WZF 已提交
137 138 139 140 141 142
      setTimeout(() => {
        this.hideLoading();
      }, 3000);
    },
    hideLoading: function () {
      uni.hideLoading();
143 144
    }
  }
DCloud-WZF's avatar
DCloud-WZF 已提交
145
}
146
</script>