picker-view.uvue 3.9 KB
Newer Older
Y
yurj26 已提交
1
<template>
H
hdx 已提交
2 3 4 5 6 7
  <view>
    <page-head :title="title"></page-head>
    <view class="uni-padding-wrap">
      <view class="uni-title">
        日期:{{year}}年{{month}}月{{day}}日
      </view>
Y
yurj26 已提交
8
    </view>
DCloud-WZF's avatar
DCloud-WZF 已提交
9 10
    <picker-view class="picker-view" :value="value" @change="bindChange" :indicator-style="indicatorStyle"
      :indicator-class="indicatorClass" :mask-style="maskStyle" :mask-class="maskClass" :mask-top-style="maskTopStyle"
11
      :mask-bottom-style="maskBottomStyle">
H
hdx 已提交
12 13 14 15 16 17 18 19 20 21 22 23
      <picker-view-column class="picker-view-column">
        <view class="item" v-for="(item,index) in years" :key="index"><text class="text">{{item}}年</text></view>
      </picker-view-column>
      <picker-view-column class="picker-view-column">
        <view class="item" v-for="(item,index) in months" :key="index"><text class="text">{{item}}月</text>
        </view>
      </picker-view-column>
      <picker-view-column class="picker-view-column">
        <view class="item" v-for="(item,index) in days" :key="index"><text class="text">{{item}}日</text></view>
      </picker-view-column>
    </picker-view>
  </view>
Y
yurj26 已提交
24 25
</template>

DCloud-WZF's avatar
DCloud-WZF 已提交
26
<script lang="uts">
27
  import { state, setEventCallbackNum } from '@/store/index.uts'
H
hdx 已提交
28 29
  export default {
    data() {
30
      // 20180112 HBuilderX内测开始 :)
H
hdx 已提交
31
      const _years : number[] = []
32
      const _year = 2018
H
hdx 已提交
33
      const _months : number[] = []
34
      const _month : number = 1
H
hdx 已提交
35
      const _days : number[] = []
36
      const _day = 12
H
hdx 已提交
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
      for (let i = 2000; i <= _year; i++) {
        _years.push(i)
      }
      for (let i = 1; i <= 12; i++) {
        _months.push(i)
      }
      for (let i = 1; i <= 31; i++) {
        _days.push(i)
      }
      return {
        title: 'picker-view',
        years: _years as number[],
        year: _year as number,
        months: _months as number[],
        month: _month as number,
        days: _days as number[],
        day: _day as number,
        value: [_year - 2000, _month - 1, _day - 1] as number[],
        result: [] as number[],
DCloud-WZF's avatar
DCloud-WZF 已提交
56 57 58 59
        indicatorStyle: 'height: 50px;',
        // 自动化测试
        indicatorClass: '',
        maskStyle: '',
60
        maskClass: '',
H
hdx 已提交
61 62 63 64
        maskTopStyle: '',
        maskBottomStyle: ''
      }
    },
DCloud-WZF's avatar
DCloud-WZF 已提交
65 66 67 68
    methods: {
      // 自动化测试
      getEventCallbackNum() : number {
        return state.eventCallbackNum
69
      },
DCloud-WZF's avatar
DCloud-WZF 已提交
70 71 72 73 74
      // 自动化测试
      setEventCallbackNum(num : number) {
        setEventCallbackNum(num)
      },
      bindChange(e : UniPickerViewChangeEvent) {
75 76
        // 自动化测试 触发事件元素、type 类型
        // console.log(e.target?.tagName, e.type);
DCloud-WZF's avatar
DCloud-WZF 已提交
77 78 79 80 81 82
        if ((e.target?.tagName ?? '').includes('PICKER-VIEW')) {
          this.setEventCallbackNum(state.eventCallbackNum + 1)
        }
        if (e.type === 'change') {
          this.setEventCallbackNum(state.eventCallbackNum + 2)
        }
H
hdx 已提交
83 84 85 86 87 88 89
        const val = e.detail.value
        this.result = val
        this.year = this.years[val[0]]
        this.month = this.months[val[1]]
        this.day = this.days[val[2]]
      },
      setValue() {
90
        this.value = [0, 1, 30] as number[]
H
hdx 已提交
91 92 93 94
      },
      setValue1() {
        this.value = [10, 10, 10] as number[]
      },
Y
yurj26 已提交
95
    }
H
hdx 已提交
96
  }
Y
yurj26 已提交
97 98 99
</script>

<style>
H
hdx 已提交
100 101 102 103 104 105 106 107 108 109 110 111
  .picker-view {
    width: 100%;
    height: 320px;
    margin-top: 10px;
  }
  .item {
    height: 50px;
  }
  .text {
    line-height: 50px;
    text-align: center;
  }
DCloud-WZF's avatar
DCloud-WZF 已提交
112 113 114 115 116 117 118 119 120
  /* 自动化测试 */
  .indicator-test{
    height: 50px;
    border:#0055ff solid 1px;
    background:rgba(0, 170, 0, 0.4);
  }
  .mask-test{
    background-image: linear-gradient(to bottom, #d8e5ff, rgba(216, 229, 255, 0));
  }
DCloud-WZF's avatar
DCloud-WZF 已提交
121 122 123 124 125 126 127 128 129 130

  /* 自动化测试 */
  .indicator-test {
    height: 50px;
    border: #0055ff solid 1px;
    background: rgba(0, 170, 0, 0.4);
  }

  .mask-test {
    background-image: linear-gradient(to bottom, #d8e5ff, rgba(216, 229, 255, 0));
H
hdx 已提交
131
  }
DCloud-WZF's avatar
DCloud-WZF 已提交
132
</style>