button.uvue 4.7 KB
Newer Older
Y
yurj26 已提交
1
<script>
D
DCloud_LXH 已提交
2
  import { ItemType } from '@/components/enum-data/enum-data-types'
Y
yurj26 已提交
3 4 5 6 7 8 9 10 11 12 13
  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,
14
        text: ''
Y
yurj26 已提交
15
      }
DCloud-WZF's avatar
DCloud-WZF 已提交
16 17 18
    },
    onReady() {
      this.text = 'uni-app-x'
19
    },
Y
yurj26 已提交
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
    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 },
W
WOSHIMAHAIFENG 已提交
36 37 38 39 40
      confirm_text_input(value : string) { this.text = value },
      navigateToChild() {
        uni.navigateTo({
          url: 'buttonstatus',
        })
41 42 43 44 45
      },
      openPrivacyDialog() {
        uni.openDialogPage({
          url: '/pages/component/button/privacy',
        })
W
WOSHIMAHAIFENG 已提交
46 47 48 49 50 51 52 53
      },
      //用于自动化测试
      checkUniButtonElement() : boolean {
        const button = uni.getElementById("testButton")
        if (button != null && button instanceof UniButtonElement) {
          return true
        }
        return false
54
      }
Y
yurj26 已提交
55
    }
Y
yurj26 已提交
56 57 58 59
  }
</script>

<template>
D
DCloud_LXH 已提交
60
  <view class="main">
61
    <button id="testButton" :disabled="disabled_boolean" :size="size_enum[size_enum_current].name"
D
DCloud_LXH 已提交
62 63 64
      :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"
65 66
      :class="default_style ? (disabled_boolean ? 'custom-btn-disable' : 'custom-btn') : ''"
      :hover-class="default_style ? 'is-hover' : 'button-hover'">
D
DCloud_LXH 已提交
67 68 69
      {{ text }}
    </button>
  </view>
雪洛's avatar
雪洛 已提交
70
  <scroll-view style="flex: 1">
Y
yurj26 已提交
71
    <view class="content">
Y
yurj26 已提交
72 73 74 75 76
      <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>
W
WOSHIMAHAIFENG 已提交
77
      <input-data :defaultValue="text" title="按钮的文案" type="text" @confirm="confirm_text_input"></input-data>
W
WOSHIMAHAIFENG 已提交
78
      <view style="height: 10px;"></view>
79 80 81 82
      <button @click="openPrivacyDialog">open-type实现隐私政策弹框</button>
      <view style="height: 10px;"></view>
      <button @click="navigateToChild">更多示例</button>
      <view style="height: 10px;"></view>
Y
yurj26 已提交
83 84 85 86 87
    </view>
  </scroll-view>
</template>

<style>
Y
yurj26 已提交
88
  .main {
H
hdx 已提交
89
    padding: 5px 0;
Y
yurj26 已提交
90 91 92 93
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    flex-direction: row;
    justify-content: center;
  }
Y
yurj26 已提交
94

Y
yurj26 已提交
95 96
  .main .list-item {
    width: 100%;
H
hdx 已提交
97
    height: 100px;
Y
yurj26 已提交
98
    border: 1px solid #666;
H
hdx 已提交
99 100 101 102 103 104
  }

  .custom-btn {
    color: #ffffff;
    background-color: #1AAD19;
    border-color: #1AAD19;
Y
yurj26 已提交
105
  }
Y
yurj26 已提交
106

107 108 109 110 111 112
  .custom-btn-disable {
    color: rgba(255, 255, 255, 0.7);
    background-color: rgba(26, 173, 25, 0.7);
    border-color: rgba(26, 173, 25, 0.7);
  }

Y
yurj26 已提交
113 114 115 116 117
  .is-hover {
    color: rgba(255, 255, 255, 0.6);
    background-color: #179b16;
    border-color: #179b16;
  }
W
WOSHIMAHAIFENG 已提交
118 119 120 121 122

  .button-hover {
    color: rgba(0, 0, 0, 0.6);
    background-color: #dedede;
  }
D
DCloud_LXH 已提交
123
</style>