general-attribute.uvue 3.2 KB
Newer Older
1 2 3 4 5 6 7 8
<template>
  <!-- #ifdef APP -->
  <scroll-view style="flex: 1">
    <!-- #endif -->
    <view>
      <page-head :title="title"></page-head>
      <view class="uni-padding-wrap uni-common-mt container">
        <view :id="generalId" :class="generalClass" :name="generalName" :title="generalTitle" :data-test="generalData" style="background-color: aqua" ref="general-target"> </view>
9 10 11
        <view class="btn uni-common-mt" @click="validateGeneralAttributes">
          <text class="btn-inner">{{ validateGeneralAttrText }}</text>
        </view>
12
        <view class="view-class" :hover-class="hoverClass" ref="view-target">
DCloud-WZF's avatar
DCloud-WZF 已提交
13 14
          <text class="text">按下 50 ms 后背景变红</text>
          <text class="text">抬起 400 ms 后背景恢复</text>
15 16
        </view>
        <view class="view-class" :hover-class="hoverClass" :hover-start-time="1000" :hover-stay-time="1000" ref="view-target">
DCloud-WZF's avatar
DCloud-WZF 已提交
17 18
          <text class="text">按下 1000 ms 后背景变红</text>
          <text class="text">抬起 1000 ms 后背景恢复</text>
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
        </view>
      </view>
    </view>
    <!-- #ifdef APP -->
  </scroll-view>
  <!-- #endif -->
</template>

<script lang="uts">
export default {
  data() {
    return {
      title: 'general-attribute',
      generalId: 'general-id',
      generalClass: 'general-class',
      generalName: 'general-name',
      generalTitle: 'general-title',
      generalData: 'general-data',
      validateGeneralAttrText: '验证基础属性',
      hoverClass: 'hover-class',
      validateViewAttrText: '验证 view 属性',
    }
  },
  methods: {
    validateGeneralAttributes() {
      const generalTarget = this.$refs.get('general-target') as INode
      const generalId = generalTarget.getAttribute('id')
      if (generalId != this.generalId) {
        this.validateGeneralAttrText = '基础属性 id 验证失败'
        return
      }
      const classList = generalTarget.ext['classList'] as string[]
      if (!classList.includes('general-class')) {
        this.validateGeneralAttrText = '基础属性 class 验证失败'
        return
      }
      const generalName = generalTarget.getAttribute('name')
      if (generalName != this.generalName) {
        this.validateGeneralAttrText = '基础属性 name 验证失败'
        return
      }
      const generalTitle = generalTarget.getAttribute('title')
      if (generalTitle != this.generalTitle) {
        this.validateGeneralAttrText = '基础属性 title 验证失败'
        return
      }
      const generalData = generalTarget.getAttribute('data-test')
      if (generalData != this.generalData) {
        this.validateGeneralAttrText = '基础属性 data-test 验证失败'
        return
      }
      this.validateGeneralAttrText = '基础属性验证成功'
    },
  },
}
</script>

<style>
77 78 79 80 81 82 83 84 85 86 87
.btn {
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #409eff;
  border-radius: 5px;
}
.btn-inner {
  color: #fff;
}
88 89 90 91 92 93 94 95 96 97 98 99 100
.general-class {
  margin: 20px 0 0 50px;
  width: 240px;
  height: 100px;
  background-color: antiquewhite;
}
.view-class {
  margin: 20px 0 0 50px;
  padding: 10px;
  width: 240px;
  height: 100px;
  background-color: antiquewhite;
}
DCloud-WZF's avatar
DCloud-WZF 已提交
101
.view-class .text {
102
  margin-top: 5px;
103 104 105 106 107 108
  text-align: center;
}
.hover-class {
  background-color: red;
}
</style>