radio.uvue 7.7 KB
Newer Older
1
<script>
2
  import { state, setEventCallbackNum } from '@/store/index.uts'
H
hdx 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
  type ItemType = {
    value : string
    name : string
  }
  export default {
    data() {
      return {
        items: [
          {
            value: 'CHN',
            name: '中国',
          },
          {
            value: 'USA',
            name: '美国',
          },
19

H
hdx 已提交
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
          {
            value: 'BRA',
            name: '巴西',
          },
          {
            value: 'JPN',
            name: '日本',
          },
          {
            value: 'ENG',
            name: '英国',
          },
          {
            value: 'FRA',
            name: '法国',
          },
        ] as ItemType[],
        current: 0,
38

H
hdx 已提交
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
        value: '',
        text: '未选中',
        wrapText: 'uni-app x,终极跨平台方案\nuts,大一统语言',
        disabled: true,
        checked: true,
        color: '#007aff',
        // 组件属性 autotest
        checked_boolean: false,
        disabled_boolean: false,
        color_input: "#007AFF",
        backgroundColor_input: "#ffffff",
        borderColor_input: "#d1d1d1",
        activeBackgroundColor_input: "#007AFF",
        activeBorderColor_input: "",
        iconColor_input: "#ffffff"
      }
    },
    methods: {
H
hdx 已提交
57
      radioChange(e : UniRadioGroupChangeEvent) {
H
hdx 已提交
58 59 60 61 62 63 64 65
        const selected = this.items.find((item) : boolean => {
          return item.value == e.detail.value
        })
        uni.showToast({
          icon: 'none',
          title: '当前选中:' + selected?.name,
        })
      },
66 67 68 69 70 71 72 73
      // 自动化测试
      getEventCallbackNum() : number {
        return state.eventCallbackNum
      },
      // 自动化测试
      setEventCallbackNum(num : number) {
        setEventCallbackNum(num)
      },
H
hdx 已提交
74
      testChange(e : UniRadioGroupChangeEvent) {
75 76 77 78 79 80 81 82
        // 自动化测试
        if ((e.target?.tagName ?? '').includes('RADIO-GROUP')) {
          this.setEventCallbackNum(state.eventCallbackNum + 1)
        }
        if (e.type === 'change') {
          this.setEventCallbackNum(state.eventCallbackNum + 2)
        }

H
hdx 已提交
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
        this.value = e.detail.value
      },
      radio_click() { console.log("组件被点击时触发") },
      radio_touchstart() { console.log("手指触摸动作开始") },
      radio_touchmove() { console.log("手指触摸后移动") },
      radio_touchcancel() { console.log("手指触摸动作被打断,如来电提醒,弹窗") },
      radio_touchend() { console.log("手指触摸动作结束") },
      radio_tap() { console.log("手指触摸后马上离开") },
      radio_longpress() { console.log("如果一个组件被绑定了 longpress 事件,那么当用户长按这个组件时,该事件将会被触发。") },
      change_checked_boolean(checked : boolean) { this.checked_boolean = checked },
      change_disabled_boolean(checked : boolean) { this.disabled_boolean = checked },
      confirm_color_input(value : string) { this.color_input = value },
      confirm_backgroundColor_input(value : string) { this.backgroundColor_input = value },
      confirm_borderColor_input(value : string) { this.borderColor_input = value },
      confirm_activeBackgroundColor_input(value : string) { this.activeBackgroundColor_input = value },
      confirm_activeBorderColor_input(value : string) { this.activeBorderColor_input = value },
      confirm_iconColor_input(value : string) { this.iconColor_input = value }
    }
  }
102 103
</script>

Y
init  
yurj26 已提交
104
<template>
105
  <view class="main">
H
hdx 已提交
106 107 108 109 110
    <radio :disabled="disabled_boolean" :checked="checked_boolean" :color="color_input"
      :backgroundColor="backgroundColor_input" :borderColor="borderColor_input"
      :activeBackgroundColor="activeBackgroundColor_input" :activeBorderColor="activeBorderColor_input"
      :iconColor="iconColor_input" @click="radio_click" @touchstart="radio_touchstart" @touchmove="radio_touchmove"
      @touchcancel="radio_touchcancel" @touchend="radio_touchend" @tap="radio_tap" @longpress="radio_longpress">
111 112 113
      <text>uni-app-x</text>
    </radio>
  </view>
Y
yurj26 已提交
114

雪洛's avatar
雪洛 已提交
115
  <scroll-view style="flex: 1">
A
Anne_LXM 已提交
116
    <view class="content">
117
      <page-head title="组件属性"></page-head>
H
hdx 已提交
118 119 120 121 122 123 124 125 126 127 128 129
      <boolean-data :defaultValue="false" title="<radio/> 当前是否选中" @change="change_checked_boolean"></boolean-data>
      <boolean-data :defaultValue="false" title="是否禁用" @change="change_disabled_boolean"></boolean-data>
      <input-data defaultValue="#007AFF" title="radio的颜色" type="text" @confirm="confirm_color_input"></input-data>
      <input-data defaultValue="#ffffff" title="radio默认的背景颜色" type="text"
        @confirm="confirm_backgroundColor_input"></input-data>
      <input-data defaultValue="#d1d1d1" title="radio默认的边框颜色" type="text"
        @confirm="confirm_borderColor_input"></input-data>
      <input-data defaultValue="#007AFF" title="radio选中时的背景颜色,优先级大于color属性" type="text"
        @confirm="confirm_activeBackgroundColor_input"></input-data>
      <input-data defaultValue="" title="radio选中时的边框颜色" type="text"
        @confirm="confirm_activeBorderColor_input"></input-data>
      <input-data defaultValue="#ffffff" title="radio的图标颜色" type="text" @confirm="confirm_iconColor_input"></input-data>
130
    </view>
Y
yurj26 已提交
131

132 133 134 135 136 137
    <view>
      <page-head title="默认及使用"></page-head>
      <view class="uni-padding-wrap">
        <view class="uni-title uni-common-mt">
          <text class="uni-title-text"> 默认样式 </text>
        </view>
H
hdx 已提交
138
        <radio-group class="uni-flex uni-row radio-group" @change="testChange" style="flex-wrap: wrap">
139 140
          <radio id="trigger-change" value="r" :checked="checked" :color="color" style="margin-right: 15px"
            class="radio r">选中
141
          </radio>
H
hdx 已提交
142
          <radio value="r1" style="margin-right: 15px" class="radio r1">{{
143 144 145
            text
          }}</radio>
          <radio value="r2" :disabled="disabled" class="radio r2">禁用</radio>
H
hdx 已提交
146
          <radio value="r3" class="radio r3" style="margin-top: 10px">{{
147 148 149 150
            wrapText
          }}</radio>
        </radio-group>
      </view>
Y
yurj26 已提交
151

152 153 154 155 156
      <view class="uni-padding-wrap">
        <view class="uni-title uni-common-mt">
          <text class="uni-title-text"> 不同颜色和尺寸的radio </text>
        </view>
        <radio-group class="uni-flex uni-row radio-group">
H
hdx 已提交
157
          <radio value="r1" :checked="true" color="#FFCC33" style="transform: scale(0.7); margin-right: 15px"
H
hdx 已提交
158
            class="radio">选中
159
          </radio>
H
hdx 已提交
160
          <radio value="r2" color="#FFCC33" style="transform: scale(0.7)" class="radio">未选中</radio>
161 162
        </radio-group>
      </view>
DCloud-WZF's avatar
DCloud-WZF 已提交
163

164 165 166 167 168 169 170
      <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">
        <radio-group @change="radioChange" class="radio-group">
H
hdx 已提交
171 172 173
          <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">
174 175 176 177 178 179
            {{ item.name }}
          </radio>
        </radio-group>
      </view>
    </view>
  </scroll-view>
180
</template>
Y
init  
yurj26 已提交
181 182

<style>
H
hdx 已提交
183
  .main {
H
hdx 已提交
184
    max-height: 250px;
H
hdx 已提交
185 186 187 188 189
    padding: 5px 0;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    flex-direction: row;
    justify-content: center;
  }
190

H
hdx 已提交
191 192 193 194 195
  .main .list-item {
    width: 100%;
    height: 100px;
    border: 1px solid #666;
  }
196

H
hdx 已提交
197 198 199 200
  .uni-list-cell {
    justify-content: flex-start;
  }
</style>