modal.uvue 5.2 KB
Newer Older
1
<template>
H
hdx 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
  <!-- #ifdef APP -->
  <scroll-view style="flex: 1">
  <!-- #endif -->
    <view>
      <page-head :title="title"></page-head>
      <view class="uni-list">
        <radio-group @change="radioChange">
          <radio class="uni-list-cell uni-list-cell-pd" v-for="(item, index) in items" :key="item.value"
            :class="index < items.length - 1 ? 'uni-list-cell-line' : ''" :value="item.value"
            :checked="index === current">
            {{ item.name }}
          </radio>
        </radio-group>
      </view>
      <view class="uni-list">
        <view class="uni-list-cell uni-list-cell-pd">
          <view class="uni-list-cell-db">是否显示取消按钮</view>
          <switch :checked="showCancelSelect" @change="showCancelChange" />
        </view>
        <view class="uni-list-cell uni-list-cell-pd">
          <view class="uni-list-cell-db">定制取消文案</view>
          <switch :checked="cancelTextSelect" @change="cancelTextChange" />
        </view>
        <view class="uni-list-cell uni-list-cell-pd">
          <view class="uni-list-cell-db">定制确认文案</view>
          <switch :checked="confirmTextSelect" @change="confirmTextChange" />
        </view>
        <view class="uni-list-cell uni-list-cell-pd">
          <view class="uni-list-cell-db">是否显示输入框</view>
          <switch :checked="editableSelect" @change="editableChange" />
        </view>
        <view class="uni-list-cell uni-list-cell-pd">
          <view class="uni-list-cell-db">是否定制输入提示词</view>
          <switch :checked="placeholderTextSelect" @change="placeholderTextChange" />
        </view>
      </view>
      <view class="uni-padding-wrap uni-common-mt">
        <view class="uni-btn-v">
杜庆泉's avatar
杜庆泉 已提交
40
          <button class="uni-btn-v" type="default" @tap="modalTap" id="btn-modal-show">
H
hdx 已提交
41 42 43 44 45 46 47 48 49
            modal测试
          </button>
        </view>
        <text>{{ exeRet }}</text>
      </view>
    </view>
  <!-- #ifdef APP -->
  </scroll-view>
  <!-- #endif -->
50
</template>
H
hdx 已提交
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 82 83

<script>
  type ItemType = {
    value : string,
    name : string,
  }
  export default {
    data() {
      return {
        title: 'modal',
        showCancelSelect: false,
        cancelTextSelect: false,
        confirmTextSelect: false,
        editableSelect: false,
        placeholderTextSelect: false,
        exeRet: "",
        items: [{
          value: '标题',
          name: '有标题'
        },
        {
          value: '',
          name: '无标题'
        },
        {
          value: '超长标题测试内容,测试超过显示最大范围之后的样式-超长标题测试内容,测试超过显示最大范围之后的样式',
          name: '超长标题'
        }
        ] as ItemType[],
        current: 0
      }
    },
    onLoad() {
杜庆泉's avatar
杜庆泉 已提交
84 85
      uni.showModal({
        title: "onLoad 调用示例,请手动取消",
H
hdx 已提交
86
        showCancel: false
杜庆泉's avatar
杜庆泉 已提交
87 88
      })
    },
H
hdx 已提交
89
    methods: {
杜庆泉's avatar
杜庆泉 已提交
90 91 92 93
      //自动化测试例专用
      jest_getWindowInfo() : GetWindowInfoResult {
        return uni.getWindowInfo();
      },
H
hdx 已提交
94
      showCancelChange: function (e : UniSwitchChangeEvent) {
H
hdx 已提交
95 96
        this.showCancelSelect = e.detail.value
      },
H
hdx 已提交
97
      cancelTextChange: function (e : UniSwitchChangeEvent) {
H
hdx 已提交
98 99
        this.cancelTextSelect = e.detail.value
      },
H
hdx 已提交
100
      confirmTextChange: function (e : UniSwitchChangeEvent) {
H
hdx 已提交
101 102
        this.confirmTextSelect = e.detail.value
      },
H
hdx 已提交
103
      editableChange: function (e : UniSwitchChangeEvent) {
H
hdx 已提交
104 105
        this.editableSelect = e.detail.value
      },
H
hdx 已提交
106
      placeholderTextChange: function (e : UniSwitchChangeEvent) {
H
hdx 已提交
107 108
        this.placeholderTextSelect = e.detail.value
      },
H
hdx 已提交
109
      radioChange(e : UniRadioGroupChangeEvent) {
H
hdx 已提交
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
        for (let i = 0; i < this.items.length; i++) {
          if (this.items[i].value === e.detail.value) {
            this.current = i;
            break;
          }
        }
      },
      modalTap: function () {
        let cancelTextVal : string
        let cancelColorVal = ''
        if (this.cancelTextSelect) {
          cancelTextVal = "修改后的取消文本"
          cancelColorVal = "#ff00ff"
        } else {
          cancelTextVal = "取消"
        }
126

H
hdx 已提交
127 128 129 130 131 132
        let confirmTextVal = '确定'
        let confirmColorVal = ''
        if (this.confirmTextSelect) {
          confirmTextVal = "修改后的确定文本"
          confirmColorVal = "#00ffff"
        }
133

H
hdx 已提交
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
        let placeholderTextVal = ''
        let contentVal = "弹窗内容,告知当前状态、信息和解决方法,描述文字尽量控制在三行内"
        if (this.placeholderTextSelect) {
          placeholderTextVal = "定制提示信息"
          contentVal = ""
        }
        uni.showModal({
          title: this.items[this.current].value,
          editable: this.editableSelect,
          placeholderText: placeholderTextVal,
          content: contentVal,
          showCancel: this.showCancelSelect,
          cancelText: cancelTextVal,
          cancelColor: cancelColorVal,
          confirmText: confirmTextVal,
          confirmColor: confirmColorVal,
          success: (res) => {
            this.exeRet = JSON.stringify(res)
          },
          fail: (res) => {
            this.exeRet = JSON.stringify(res)
          }
        })
      }
    }
  }
160
</script>