buttonstatus.uvue 11.0 KB
Newer Older
W
WOSHIMAHAIFENG 已提交
1 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 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 65 66 67 68 69 70 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 133 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 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
<script>
  import { ItemType } from '@/components/enum-data/enum-data'
  export default {
    data() {
      return {
        plain_boolean: false,
        disabled_boolean: false,
        default_style: false,
        size_enum: [{ "value": 0, "name": "default" }, { "value": 1, "name": "mini" }] as ItemType[],
        size_enum_current: 0,
        type_enum: [{ "value": 0, "name": "default" }, { "value": 1, "name": "primary" }, { "value": 2, "name": "warn" }] as ItemType[],
        type_enum_current: 0,
        count: 0,
        text: 'uni-app-x'
      }
    },
    methods: {
      button_click() {
        console.log("组件被点击时触发")
        this.count++
      },
      button_touchstart() { console.log("手指触摸动作开始") },
      button_touchmove() { console.log("手指触摸后移动") },
      button_touchcancel() { console.log("手指触摸动作被打断,如来电提醒,弹窗") },
      button_touchend() { console.log("手指触摸动作结束") },
      button_tap() { console.log("手指触摸后马上离开") },
      button_longpress() { console.log("如果一个组件被绑定了 longpress 事件,那么当用户长按这个组件时,该事件将会被触发。") },
      change_plain_boolean(checked : boolean) { this.plain_boolean = checked },
      change_disabled_boolean(checked : boolean) { this.disabled_boolean = checked },
      change_default_style(checked : boolean) { this.default_style = checked },
      radio_change_size_enum(checked : number) { this.size_enum_current = checked },
      radio_change_type_enum(checked : number) { this.type_enum_current = checked },
      confirm_text_input(value : string) { this.text = value }
    }
  }
</script>

<template>
  <view class="main">
    <button :disabled="disabled_boolean" :size="size_enum[size_enum_current].name"
      :type="type_enum[type_enum_current].name" :plain="plain_boolean" @click="button_click"
      @touchstart="button_touchstart" @touchmove="button_touchmove" @touchcancel="button_touchcancel"
      @touchend="button_touchend" @tap="button_tap" @longpress="button_longpress" class="btn"
      :class="default_style ? 'custom-btn' : ''" :hover-class="default_style ? 'is-hover' : 'button-hover'">
      {{ text }}
    </button>
  </view>
  <scroll-view style="flex: 1">
    <view class="content">
      <boolean-data :defaultValue="false" title="按钮是否镂空,背景色透明" @change="change_plain_boolean"></boolean-data>
      <boolean-data :defaultValue="false" title="是否禁用" @change="change_disabled_boolean"></boolean-data>
      <boolean-data :defaultValue="false" title="修改默认样式和点击效果(高优先)" @change="change_default_style"></boolean-data>
      <enum-data :items="size_enum" title="按钮的大小" @change="radio_change_size_enum"></enum-data>
      <enum-data :items="type_enum" title="按钮的类型" @change="radio_change_type_enum"></enum-data>
      <input-data :defaultValue="text" title="按钮的文案" type="text" @confirm="confirm_text_input"></input-data>
    </view>
  </scroll-view>
</template>

<style>
  .main {
    padding: 5px 0;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    flex-direction: row;
    justify-content: center;
  }

  .main .list-item {
    width: 100%;
    height: 100px;
    border: 1px solid #666;
  }

  .custom-btn {
    color: #ffffff;
    background-color: #1AAD19;
    border-color: #1AAD19;
  }

  .is-hover {
    color: rgba(255, 255, 255, 0.6);
    background-color: #179b16;
    border-color: #179b16;
  }
</style>
<script>
  import { ItemType } from '@/components/enum-data/enum-data'
  export default {
    data() {
      return {
        plain_boolean: false,
        disabled_boolean: false,
        default_style: false,
        size_enum: [{ "value": 0, "name": "default" }, { "value": 1, "name": "mini" }] as ItemType[],
        size_enum_current: 0,
        type_enum: [{ "value": 0, "name": "default" }, { "value": 1, "name": "primary" }, { "value": 2, "name": "warn" }] as ItemType[],
        type_enum_current: 0,
        count: 0,
        text: 'uni-app-x'
      }
    },
    methods: {
      button_click() {
        console.log("组件被点击时触发")
        this.count++
      },
      button_touchstart() { console.log("手指触摸动作开始") },
      button_touchmove() { console.log("手指触摸后移动") },
      button_touchcancel() { console.log("手指触摸动作被打断,如来电提醒,弹窗") },
      button_touchend() { console.log("手指触摸动作结束") },
      button_tap() { console.log("手指触摸后马上离开") },
      button_longpress() { console.log("如果一个组件被绑定了 longpress 事件,那么当用户长按这个组件时,该事件将会被触发。") },
      change_plain_boolean(checked : boolean) { this.plain_boolean = checked },
      change_disabled_boolean(checked : boolean) { this.disabled_boolean = checked },
      change_default_style(checked : boolean) { this.default_style = checked },
      radio_change_size_enum(checked : number) { this.size_enum_current = checked },
      radio_change_type_enum(checked : number) { this.type_enum_current = checked },
      confirm_text_input(value : string) { this.text = value }
    }
  }
</script>

<template>
  <view class="main">
    <!--type-->
    <view class="container">
      <button style="margin: 10px;" :disabled="disabled_boolean" :size="size_enum[size_enum_current].name"
        :type="type_enum[0].name" :plain="plain_boolean" @click="button_click" @touchstart="button_touchstart"
        @touchmove="button_touchmove" @touchcancel="button_touchcancel" @touchend="button_touchend" @tap="button_tap"
        @longpress="button_longpress" class="btn" :class="default_style ? 'custom-btn' : ''"
        :hover-class="default_style ? 'is-hover' : 'button-hover'">
        {{ text }}
      </button>
    </view>
    <view class="container">
      <button style="margin: 10px;" :disabled="disabled_boolean" :size="size_enum[size_enum_current].name"
        :type="type_enum[1].name" :plain="plain_boolean" @click="button_click" @touchstart="button_touchstart"
        @touchmove="button_touchmove" @touchcancel="button_touchcancel" @touchend="button_touchend" @tap="button_tap"
        @longpress="button_longpress" class="btn" :class="default_style ? 'custom-btn' : ''"
        :hover-class="default_style ? 'is-hover' : 'button-hover'">
        {{ text }}
      </button>
    </view>
    <view class="container">
      <button style="margin: 10px;" :disabled="disabled_boolean" :size="size_enum[size_enum_current].name"
        :type="type_enum[2].name" :plain="plain_boolean" @click="button_click" @touchstart="button_touchstart"
        @touchmove="button_touchmove" @touchcancel="button_touchcancel" @touchend="button_touchend" @tap="button_tap"
        @longpress="button_longpress" class="btn" :class="default_style ? 'custom-btn' : ''"
        :hover-class="default_style ? 'is-hover' : 'button-hover'">
        {{ text }}
      </button>
    </view>
    <!--size-->
    <view class="container">
      <button style="margin: 10px;" :disabled="disabled_boolean" :size="size_enum[0].name"
        :type="type_enum[type_enum_current].name" :plain="plain_boolean" @click="button_click"
        @touchstart="button_touchstart" @touchmove="button_touchmove" @touchcancel="button_touchcancel"
        @touchend="button_touchend" @tap="button_tap" @longpress="button_longpress" class="btn"
        :class="default_style ? 'custom-btn' : ''" :hover-class="default_style ? 'is-hover' : 'button-hover'">
        {{ text }}
      </button>
    </view>
    <view class="container">
      <button style="margin: 10px;" :disabled="disabled_boolean" :size="size_enum[1].name"
        :type="type_enum[type_enum_current].name" :plain="plain_boolean" @click="button_click"
        @touchstart="button_touchstart" @touchmove="button_touchmove" @touchcancel="button_touchcancel"
        @touchend="button_touchend" @tap="button_tap" @longpress="button_longpress" class="btn"
        :class="default_style ? 'custom-btn' : ''" :hover-class="default_style ? 'is-hover' : 'button-hover'">
        {{ text }}
      </button>
    </view>
    <!--plain-->
    <view class="container">
      <button style="margin: 10px;" :disabled="disabled_boolean" :size="size_enum[size_enum_current].name"
        :type="type_enum[type_enum_current].name" :plain="true" @click="button_click" @touchstart="button_touchstart"
        @touchmove="button_touchmove" @touchcancel="button_touchcancel" @touchend="button_touchend" @tap="button_tap"
        @longpress="button_longpress" class="btn" :class="default_style ? 'custom-btn' : ''"
        :hover-class="default_style ? 'is-hover' : 'button-hover'">
        {{ text }}
      </button>
    </view>
    <view class="container">
      <button style="margin: 10px;" :disabled="disabled_boolean" :size="size_enum[size_enum_current].name"
        :type="type_enum[type_enum_current].name" :plain="false" @click="button_click" @touchstart="button_touchstart"
        @touchmove="button_touchmove" @touchcancel="button_touchcancel" @touchend="button_touchend" @tap="button_tap"
        @longpress="button_longpress" class="btn" :class="default_style ? 'custom-btn' : ''"
        :hover-class="default_style ? 'is-hover' : 'button-hover'">
        {{ text }}
      </button>
    </view>
    <!--disable-->
    <view class="container">
      <button style="margin: 10px;" :disabled="false" :size="size_enum[size_enum_current].name"
        :type="type_enum[type_enum_current].name" :plain="plain_boolean" @click="button_click"
        @touchstart="button_touchstart" @touchmove="button_touchmove" @touchcancel="button_touchcancel"
        @touchend="button_touchend" @tap="button_tap" @longpress="button_longpress" class="btn"
        :class="default_style ? 'custom-btn' : ''" :hover-class="default_style ? 'is-hover' : 'button-hover'">
        {{ text }}
      </button>
    </view>
    <view class="container">
      <button style="margin: 10px;" :disabled="true" :size="size_enum[size_enum_current].name"
        :type="type_enum[type_enum_current].name" :plain="plain_boolean" @click="button_click"
        @touchstart="button_touchstart" @touchmove="button_touchmove" @touchcancel="button_touchcancel"
        @touchend="button_touchend" @tap="button_tap" @longpress="button_longpress" class="btn"
        :class="default_style ? 'custom-btn' : ''" :hover-class="default_style ? 'is-hover' : 'button-hover'">
        {{ text }}
      </button>
    </view>
  </view>
</template>

<style>
  .main {
    padding: 5px 0;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    flex-direction: column;
    justify-content: center;
  }

  .main .list-item {
    width: 100%;
    height: 100px;
    border: 1px solid #666;
  }

  .custom-btn {
    color: #ffffff;
    background-color: #1AAD19;
    border-color: #1AAD19;
    border-radius: 5px;
    border-width: 0.5px;
    height: 53px;
  }

  .is-hover {
    color: rgba(255, 255, 255, 0.6);
    background-color: #179b16;
    border-color: #179b16;
  }

  .container {
    width: 100%;
    height: 60px;
    /* background-color: orange; */
  }
</style>