提交 f1354bf3 编写于 作者: Y yurj26

feat(component): add picker-view

上级 0c9570a3
......@@ -68,6 +68,12 @@
"navigationBarTitleText": "slider"
}
},
{
"path": "pages/component/picker-view/picker-view",
"style": {
"navigationBarTitleText": "picker-view"
}
},
{
"path": "pages/component/slider-100/slider-100",
"style": {
......
function getData(key = '') {
return new Promise(async (resolve, reject) => {
const data = await page.data()
resolve(key ? data[key] : data)
})
}
let page
beforeAll(async () => {
page = await program.reLaunch('/pages/component/picker-view/picker-view')
await page.waitFor(1000)
})
describe('PickerView.uvue', () => {
it('value', async () => {
const el = await page.$('.picker-view')
await page.callMethod('setValue')
await page.waitFor(1000)
expect(await el.property('value')).toEqual([0, 0, 0])
expect(await getData('result')).toEqual([0, 0, 0])
await page.callMethod('setValue1')
await page.waitFor(1000)
expect(await el.property('value')).toEqual([10, 10, 10])
expect(await getData('result')).toEqual([10, 10, 10])
})
it('length', async () => {
const els = await page.$$('.picker-view')
expect(els.length).toBe(1)
const els1 = await page.$$('.picker-view-column')
expect(els1.length).toBe(3)
})
it('indicator-style', async () => {
const el = await page.$('.picker-view')
await page.setData({
indicatorStyle: 'height: 100px;'
})
await page.waitFor(500)
expect(await el.property('indicatorStyle')).toBe('height: 100px;')
})
it('mask-top-style', async () => {
const el = await page.$('.picker-view')
await page.setData({
maskTopStyle: 'background: #ffffff;'
})
await page.waitFor(500)
expect(await el.property('mask-top-style')).toBe('background: #ffffff;')
})
it('mask-bottom-style', async () => {
const el = await page.$('.picker-view')
await page.setData({
maskBottomStyle: 'background: #ffffff;'
})
await page.waitFor(500)
expect(await el.property('mask-bottom-style')).toBe('background: #ffffff;')
})
})
\ No newline at end of file
<template>
<view>
<page-head :title="title"></page-head>
<view class="uni-padding-wrap">
<view class="uni-title">
日期:{{year}}年{{month}}月{{day}}日
</view>
</view>
<picker-view class="picker-view" :indicator-style="indicatorStyle" :value="value" @change="bindChange"
:mask-top-style="maskTopStyle" :mask-bottom-style="maskBottomStyle">
<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>
</template>
<script lang="ts">
const date = new Date()
const _years : number[] = []
const _year = date.getFullYear()
const _months : number[] = []
const _month : number = date.getMonth() + 1
const _days : number[] = []
const _day = date.getDate()
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)
}
export default {
data() {
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[],
indicatorStyle: 'height: 50px;',
maskTopStyle: '',
maskBottomStyle: ''
}
},
methods: {
bindChange(e : PickerViewChangeEvent) {
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() {
this.value = [0, 0, 0] as number[]
},
setValue1() {
this.value = [10, 10, 10] as number[]
},
}
}
</script>
<style>
.picker-view {
width: 100%;
height: 600rpx;
margin-top: 20rpx;
}
.item {
height: 50px;
}
.text {
line-height: 50px;
text-align: center;
}
</style>
\ No newline at end of file
......@@ -115,8 +115,7 @@
name: 'picker',
enable: false */
}, {
name: 'picker-view',
enable: false
name: 'picker-view'
}, {
name: 'radio',
}, {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册