mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
Merge remote-tracking branch 'upstream/dev' into dev
This commit is contained in:
commit
4bef267d02
@ -1,9 +1,26 @@
|
||||
## 更新日志
|
||||
|
||||
## [v0.8.5](https://github.com/youzan/vant/tree/v0.8.5) (2017-08-21)
|
||||
[Full Changelog](https://github.com/youzan/vant/compare/v0.8.4...v0.8.5)
|
||||
|
||||
**非兼容更新和新特性:**
|
||||
|
||||
- Doc: add usage guide && top progress [\#83](https://github.com/youzan/vant/pull/83) ([chenjiahan](https://github.com/chenjiahan))
|
||||
|
||||
**修复:**
|
||||
|
||||
- Popup: not preventScroll by default [\#84](https://github.com/youzan/vant/pull/84) ([chenjiahan](https://github.com/chenjiahan))
|
||||
- fix: swipe sometimes will change to drag image [\#81](https://github.com/youzan/vant/pull/81) ([pangxie1991](https://github.com/pangxie1991))
|
||||
|
||||
**处理的 Issue:**
|
||||
|
||||
- Href link does not work [\#82](https://github.com/youzan/vant/issues/82)
|
||||
- Swipe image not displayed [\#79](https://github.com/youzan/vant/issues/79)
|
||||
|
||||
## [v0.8.4](https://github.com/youzan/vant/tree/v0.8.4) (2017-08-18)
|
||||
[Full Changelog](https://github.com/youzan/vant/compare/v0.8.3...v0.8.4)
|
||||
|
||||
**合并的 Pull Request (可能有不兼容改动):**
|
||||
**修复:**
|
||||
|
||||
- fix: field 计算autosize,需要nextTick [\#78](https://github.com/youzan/vant/pull/78) ([pangxie1991](https://github.com/pangxie1991))
|
||||
|
||||
|
@ -5,15 +5,16 @@ export default {
|
||||
minHour: 10,
|
||||
maxHour: 20,
|
||||
minDate: new Date(),
|
||||
currentDate1: null,
|
||||
maxDate: new Date(2019, 10, 1),
|
||||
currentDate1: new Date(2018, 0, 1),
|
||||
currentDate2: null,
|
||||
currentDate3: null
|
||||
};
|
||||
},
|
||||
|
||||
methods: {
|
||||
handlePickerChange(picker, values) {
|
||||
console.log(values);
|
||||
handlePickerChange(picker) {
|
||||
console.log(picker);
|
||||
},
|
||||
handlePickerCancel() {
|
||||
console.log('picker cancel');
|
||||
@ -43,10 +44,10 @@ Vue.component(DatetimePicker.name, DatetimePicker);
|
||||
<van-datetime-picker
|
||||
v-model="currentDate1"
|
||||
type="datetime"
|
||||
format="yyyy.mm.dd hh时 mm分"
|
||||
:min-hour="minHour"
|
||||
:max-hour="maxHour"
|
||||
:min-date="minDate"
|
||||
:max-date="maxDate"
|
||||
@change="handlePickerChange">
|
||||
</van-datetime-picker>
|
||||
|
||||
@ -57,13 +58,14 @@ export default {
|
||||
minHour: 10,
|
||||
maxHour: 20,
|
||||
minDate: new Date(),
|
||||
currentDate: null
|
||||
maxDate: new Date(2019, 10, 1),
|
||||
currentDate: new Date(2018, 0, 1)
|
||||
};
|
||||
},
|
||||
|
||||
methods: {
|
||||
handlePickerChange(picker, values) {
|
||||
picker.setColumnValues(1, citys[values[0]]);
|
||||
handlePickerChange(picker) {
|
||||
console.log(picker);
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -78,7 +80,6 @@ export default {
|
||||
<van-datetime-picker
|
||||
v-model="currentDate2"
|
||||
type="date"
|
||||
format="yyyy.mm.dd hh时 mm分"
|
||||
:min-hour="minHour"
|
||||
:max-hour="maxHour"
|
||||
:min-date="minDate"
|
||||
@ -94,7 +95,6 @@ export default {
|
||||
<van-datetime-picker
|
||||
v-model="currentDate3"
|
||||
type="time"
|
||||
format="yyyy.mm.dd hh时 mm分"
|
||||
:min-hour="minHour"
|
||||
:max-hour="maxHour"
|
||||
:min-date="minDate"
|
||||
@ -109,19 +109,11 @@ export default {
|
||||
| 参数 | 说明 | 类型 | 默认值 | 可选值 |
|
||||
|-----------|-----------|-----------|-------------|-------------|
|
||||
| visibileColumnCount | 每一列可见备选元素的个数 | Number | 5 | |
|
||||
| itemHeight | 选中元素区高度 | Number | 44 | |
|
||||
| columns | 对象数组,配置每一列显示的数据 | Array | | |
|
||||
| showToolbar | 是否在组件顶部显示一个toolbar | Boolean | true | |
|
||||
|
||||
### columns
|
||||
|
||||
`API`中的`columns`为一个对象数组,数组中的每一个对象配置每一列,每一列有以下`key`:
|
||||
|
||||
| key | 说明 |
|
||||
|-----------|-----------|
|
||||
| values | 列中对应的备选值 |
|
||||
| defaultIndex | 初始选中值的索引,默认为0 |
|
||||
| className | 为对应列添加特殊的`class` |
|
||||
| type | 组件类型 | String | 'datetime' | 'datetime', 'date', 'time' |
|
||||
| minDate | 可选的最小日期 | Date | 十年前的 1 月 1 日 | |
|
||||
| maxDate | 可选的最大日期 | Date | 十年后的 12 月 31 日 | |
|
||||
| minHour | 可选的最小小时 | Number | 0 | |
|
||||
| maxHour | 可选的最大小时 | Number | 23 | |
|
||||
|
||||
### Event
|
||||
|
||||
|
@ -9,33 +9,29 @@
|
||||
<script>
|
||||
import { Dialog } from 'packages/index';
|
||||
|
||||
const message = '弹窗内容';
|
||||
|
||||
export default {
|
||||
methods: {
|
||||
handleAlertClick() {
|
||||
onClickAlert() {
|
||||
Dialog.alert({
|
||||
title: 'alert标题',
|
||||
message: '弹窗提示文字,左右始终距离边20PX,上下距离20PX,文字左对齐。弹窗提示文字,左右始终距离边20PX,上下距离20PX,文字左对齐。'
|
||||
}).then((action) => {
|
||||
console.log(action);
|
||||
title: '标题',
|
||||
message
|
||||
});
|
||||
},
|
||||
|
||||
handleAlert2Click() {
|
||||
onClickAlert2() {
|
||||
Dialog.alert({
|
||||
message: '无标题alert'
|
||||
}).then((action) => {
|
||||
console.log(action);
|
||||
message
|
||||
});
|
||||
},
|
||||
|
||||
handleConfirmClick() {
|
||||
onClickConfirm() {
|
||||
Dialog.confirm({
|
||||
title: 'confirm标题',
|
||||
message: '弹窗提示文字,左右始终距离边20PX,上下距离20PX,文字左对齐。弹窗提示文字,左右始终距离边20PX,上下距离20PX,文字左对齐。'
|
||||
}).then((action) => {
|
||||
title: '标题',
|
||||
message
|
||||
}).catch(action => {
|
||||
console.log(action);
|
||||
}, (error) => {
|
||||
console.log(error);
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -46,8 +42,6 @@ export default {
|
||||
|
||||
### 使用指南
|
||||
|
||||
`Dialog`和其他组件不同,不是通过HTML结构的方式来使用,而是通过函数调用的方式。使用前需要先引入它,它接受一个数组作为参数,数组中的每一项对应了图片链接。
|
||||
|
||||
```js
|
||||
import { Dialog } from 'vant';
|
||||
```
|
||||
@ -56,30 +50,30 @@ import { Dialog } from 'vant';
|
||||
|
||||
#### 消息提示
|
||||
|
||||
用于提示一些消息,只包含一个确认按钮。
|
||||
用于提示一些消息,只包含一个确认按钮
|
||||
|
||||
:::demo 消息提示
|
||||
```html
|
||||
<van-button @click="handleAlertClick">alert</van-button>
|
||||
<van-button @click="handleAlert2Click">无标题alert</van-button>
|
||||
<van-button @click="onClickAlert">Alert</van-button>
|
||||
<van-button @click="onClickAlert2">无标题 Alert</van-button>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
methods: {
|
||||
handleAlertClick() {
|
||||
onClickAlert() {
|
||||
Dialog.alert({
|
||||
title: 'alert标题',
|
||||
message: '弹窗提示文字,左右始终距离边20PX,上下距离20PX,文字左对齐。弹窗提示文字,左右始终距离边20PX,上下距离20PX,文字左对齐。'
|
||||
}).then((action) => {
|
||||
console.log(action);
|
||||
title: '标题',
|
||||
message: '弹窗内容'
|
||||
}).then(() => {
|
||||
// on close
|
||||
});
|
||||
},
|
||||
|
||||
handleAlert2Click() {
|
||||
onClickAlert2() {
|
||||
Dialog.alert({
|
||||
message: '弹窗提示文字,左右始终距离边20PX,上下距离20PX,文字左对齐。弹窗提示文字,左右始终距离边20PX,上下距离20PX,文字左对齐。'
|
||||
}).then((action) => {
|
||||
console.log(action);
|
||||
message: '弹窗内容'
|
||||
}).then(() => {
|
||||
// on close
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -90,23 +84,23 @@ export default {
|
||||
|
||||
#### 消息确认
|
||||
|
||||
用于确认消息,包含取消和确认按钮。
|
||||
用于确认消息,包含取消和确认按钮
|
||||
|
||||
:::demo 消息确认
|
||||
```html
|
||||
<van-button @click="handleConfirmClick">confirm</van-button>
|
||||
<van-button @click="onClickConfirm">Confirm</van-button>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
methods: {
|
||||
handleConfirmClick() {
|
||||
onClickConfirm() {
|
||||
Dialog.confirm({
|
||||
title: 'confirm标题',
|
||||
message: '弹窗提示文字,左右始终距离边20PX,上下距离20PX,文字左对齐。弹窗提示文字,左右始终距离边20PX,上下距离20PX,文字左对齐。'
|
||||
}).then((action) => {
|
||||
console.log(action);
|
||||
}, (error) => {
|
||||
console.log(error);
|
||||
title: '标题',
|
||||
message: '弹窗内容'
|
||||
}).then(() => {
|
||||
// on confirm
|
||||
}).catch(() => {
|
||||
// on cancel
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -117,19 +111,22 @@ export default {
|
||||
|
||||
### 方法
|
||||
|
||||
#### Dialog.alert(options)
|
||||
|
||||
消息提示时使用该方法。
|
||||
|
||||
#### Dialog.confirm(options)
|
||||
|
||||
消息确认时使用该方法。
|
||||
| 方法名 | 参数 | 返回值 | 介绍 |
|
||||
|-----------|-----------|-----------|-------------|
|
||||
| Dialog.alert | options | `Promise` | 展示消息提示弹窗 |
|
||||
| Dialog.confirm | options | `Promise` | 展示消息确认弹窗 |
|
||||
| Dialog.close | - | `void` | 关闭弹窗 |
|
||||
|
||||
### Options
|
||||
|
||||
| 参数 | 说明 | 类型 | 默认值 | 可选值 |
|
||||
|-----------|-----------|-----------|-------------|-------------|
|
||||
| title | 标题 | `string` | | |
|
||||
| message | 内容 | `string` | | |
|
||||
| confirmButtonText | 确认按钮的文案 | `string` | `确认` | |
|
||||
| cancelButtonText | 取消按钮的文案 | `string` | `取消` | |
|
||||
| title | 标题 | `String` | | |
|
||||
| message | 内容 | `String` | | |
|
||||
| showConfirmButton | 是否展示确认按钮 | `Boolean` | `true` | |
|
||||
| showCancelButton | 是否展示取消按钮 | `Boolean` | `false` | |
|
||||
| confirmButtonText | 确认按钮的文案 | `String` | `确认` | |
|
||||
| cancelButtonText | 取消按钮的文案 | `String` | `取消` | |
|
||||
| overlay | 是否展示蒙层 | `Boolean` | `true` | |
|
||||
| closeOnClickOverlay | 点击蒙层时是否关闭弹窗 | `Boolean` | `false` | |
|
||||
| lockOnScroll | 是否禁用背景滚动 | `Boolean` | `true` | |
|
||||
|
@ -1,13 +1,11 @@
|
||||
<style>
|
||||
.demo-progress {
|
||||
&__wrapper {
|
||||
padding: 5px;
|
||||
.van-progress {
|
||||
margin: 20px 10px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
## Progress 进度条
|
||||
|
||||
### 使用指南
|
||||
@ -21,57 +19,37 @@ Vue.component(Progress.name, Progress);
|
||||
|
||||
#### 基础用法
|
||||
|
||||
默认情况进度条为蓝色,使用`percentage`属性来设置当前进度。
|
||||
进度条默认为蓝色,使用`percentage`属性来设置当前进度
|
||||
|
||||
:::demo 基础用法
|
||||
```html
|
||||
<div class="demo-progress__wrapper">
|
||||
<van-progress class="demo-progress__demo1" :percentage="0"></van-progress>
|
||||
</div>
|
||||
<div class="demo-progress__wrapper">
|
||||
<van-progress class="demo-progress__demo2" :percentage="46"></van-progress>
|
||||
</div>
|
||||
<div class="demo-progress__wrapper">
|
||||
<van-progress class="demo-progress__demo1" :percentage="100"></van-progress>
|
||||
</div>
|
||||
<van-progress :percentage="0"></van-progress>
|
||||
<van-progress :percentage="46"></van-progress>
|
||||
<van-progress :percentage="100"></van-progress>
|
||||
```
|
||||
:::
|
||||
|
||||
|
||||
#### Inactive
|
||||
#### 进度条置灰
|
||||
|
||||
是否置灰进度条,一般用于进度条被取消时。
|
||||
|
||||
:::demo Inactive
|
||||
:::demo 进度条置灰
|
||||
```html
|
||||
<div class="demo-progress__wrapper">
|
||||
<van-progress class="demo-progress__demo1" inactive :percentage="0"></van-progress>
|
||||
</div>
|
||||
<div class="demo-progress__wrapper">
|
||||
<van-progress class="demo-progress__demo2" inactive :percentage="46"></van-progress>
|
||||
</div>
|
||||
<div class="demo-progress__wrapper">
|
||||
<van-progress class="demo-progress__demo1" inactive :percentage="100"></van-progress>
|
||||
</div>
|
||||
<van-progress inactive :percentage="0"></van-progress>
|
||||
<van-progress inactive :percentage="46"></van-progress>
|
||||
<van-progress inactive :percentage="100"></van-progress>
|
||||
```
|
||||
:::
|
||||
|
||||
|
||||
#### 自定义颜色和文字
|
||||
#### 样式定制
|
||||
|
||||
可以使用`pivot-text`属性自定义文字,`color`属性自定义进度条颜色
|
||||
|
||||
:::demo 自定义颜色和文字
|
||||
:::demo 样式定制
|
||||
```html
|
||||
<div class="demo-progress__wrapper">
|
||||
<van-progress class="demo-progress__demo1" pivot-text="红色" color="#ed5050" :percentage="26"></van-progress>
|
||||
</div>
|
||||
<div class="demo-progress__wrapper">
|
||||
<van-progress class="demo-progress__demo1" pivot-text="橙色" color="#f60" :percentage="46"></van-progress>
|
||||
</div>
|
||||
<div class="demo-progress__wrapper">
|
||||
<van-progress class="demo-progress__demo1" pivot-text="黄色" color="#f09000" :percentage="66"></van-progress>
|
||||
</div>
|
||||
<van-progress pivot-text="红色" color="#ed5050" :percentage="26"></van-progress>
|
||||
<van-progress pivot-text="橙色" color="#f60" :percentage="46"></van-progress>
|
||||
<van-progress pivot-text="黄色" color="#f09000" :percentage="66"></van-progress>
|
||||
```
|
||||
:::
|
||||
|
||||
@ -79,9 +57,8 @@ Vue.component(Progress.name, Progress);
|
||||
|
||||
| 参数 | 说明 | 类型 | 默认值 | 可选值 |
|
||||
|-----------|-----------|-----------|-------------|-------------|
|
||||
| inactive | 是否置灰 | `boolean` | `false` | `true`, `false` |
|
||||
| percentage | 进度百分比 | `number` | `false` | `0-100` |
|
||||
| pivotText | 文字显示 | `string` | 百分比文字 | - |
|
||||
| color | 进度条颜色 | `string` | `#38f` | hexvalue |
|
||||
| textColor | 进度条文字颜色 | `string` | `#fff` | hexvalue |
|
||||
|
||||
| inactive | 是否置灰 | `boolean` | `false` | |
|
||||
| percentage | 进度百分比 | `number` | `false` | `0-100` |
|
||||
| pivotText | 文字显示 | `string` | 百分比文字 | - |
|
||||
| color | 进度条颜色 | `string` | `#38f` | hexvalue |
|
||||
| textColor | 进度条文字颜色 | `string` | `#fff` | hexvalue |
|
||||
|
@ -26,21 +26,21 @@ module.exports = {
|
||||
"title": "快速上手",
|
||||
noExample: true
|
||||
},
|
||||
{
|
||||
"title": "业务组件",
|
||||
"link": "/zanui/captain/component/quickstart"
|
||||
},
|
||||
{
|
||||
"path": "/changelog",
|
||||
"title": "更新日志",
|
||||
noExample: true
|
||||
},
|
||||
{
|
||||
"title": "业务组件",
|
||||
"link": "/zanui/captain/component/quickstart"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "组件列表",
|
||||
"name": "组件",
|
||||
"showInMobile": true,
|
||||
"groups": [
|
||||
{
|
||||
|
@ -5,6 +5,7 @@ import routes from './router.config';
|
||||
import ZanUI from 'packages/index';
|
||||
import ZanDoc from 'zan-doc';
|
||||
import 'packages/vant-css/src/index.css';
|
||||
import 'zan-doc/src/helper/touch-simulator';
|
||||
|
||||
import DemoList from './components/demo-list.vue';
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "vant",
|
||||
"version": "0.8.5",
|
||||
"version": "0.8.6",
|
||||
"description": "有赞vue wap组件库",
|
||||
"main": "lib/vant.js",
|
||||
"style": "lib/vant-css/index.css",
|
||||
@ -26,6 +26,7 @@
|
||||
"test": "karma start test/unit/karma.conf.js --single-run",
|
||||
"test:coverage": "open test/unit/coverage/lcov-report/index.html",
|
||||
"test:watch": "karma start test/unit/karma.conf.js",
|
||||
"test:single": "node ./test/unit/selector.js",
|
||||
"release": "npm run bootstrap && sh build/release.sh"
|
||||
},
|
||||
"repository": {
|
||||
@ -66,7 +67,7 @@
|
||||
"cross-env": "^5.0.5",
|
||||
"css-loader": "^0.28.5",
|
||||
"eslint-plugin-vue": "^2.1.0",
|
||||
"extract-text-webpack-plugin": "2.1.2",
|
||||
"extract-text-webpack-plugin": "2.0.0",
|
||||
"felint": "^0.5.0-alpha.3",
|
||||
"file-loader": "^0.11.2",
|
||||
"file-save": "^0.2.0",
|
||||
@ -108,7 +109,7 @@
|
||||
"vue": "^2.4.2",
|
||||
"vue-html-loader": "^1.2.4",
|
||||
"vue-loader": "^13.0.4",
|
||||
"vue-markdown-loader": "^2.0.0",
|
||||
"vue-markdown-loader": "^2.1.0",
|
||||
"vue-router": "^2.7.0",
|
||||
"vue-sfc-compiler": "^0.0.2",
|
||||
"vue-style-loader": "^3.0.0",
|
||||
@ -116,6 +117,6 @@
|
||||
"webpack": "^3.5.5",
|
||||
"webpack-dev-server": "^2.7.1",
|
||||
"webpack-merge": "^4.1.0",
|
||||
"zan-doc": "^0.2.1"
|
||||
"zan-doc": "^0.2.2"
|
||||
}
|
||||
}
|
||||
|
@ -28,8 +28,8 @@
|
||||
|
||||
<script>
|
||||
import Popup from '../mixins/popup';
|
||||
import VanIcon from '../icon';
|
||||
import VanLoading from '../loading';
|
||||
import Icon from '../icon';
|
||||
import Loading from '../loading';
|
||||
|
||||
export default {
|
||||
name: 'van-actionsheet',
|
||||
@ -37,8 +37,8 @@ export default {
|
||||
mixins: [Popup],
|
||||
|
||||
components: {
|
||||
[VanIcon.name]: VanIcon,
|
||||
[VanLoading.name]: VanLoading
|
||||
[Icon.name]: Icon,
|
||||
[Loading.name]: Loading
|
||||
},
|
||||
|
||||
props: {
|
||||
|
@ -5,21 +5,21 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'van-badge-group',
|
||||
export default {
|
||||
name: 'van-badge-group',
|
||||
|
||||
props: {
|
||||
// 当前激活 tab 面板的 key
|
||||
activeKey: {
|
||||
type: [Number, String],
|
||||
default: 0
|
||||
}
|
||||
},
|
||||
|
||||
data() {
|
||||
return {
|
||||
badges: []
|
||||
};
|
||||
props: {
|
||||
// 当前激活 tab 面板的 key
|
||||
activeKey: {
|
||||
type: [Number, String],
|
||||
default: 0
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
data() {
|
||||
return {
|
||||
badges: []
|
||||
};
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
@ -1,15 +1,19 @@
|
||||
<template>
|
||||
<div v-clickoutside:touchstart="swipeMove" @click="swipeMove()" @touchstart="startDrag" @touchmove="onDrag" @touchend="endDrag" class="van-cell-swipe" ref="cell">
|
||||
<div class="van-cell-wrapper">
|
||||
<slot>单元格内容</slot>
|
||||
</div>
|
||||
<div class="van-cell-left">
|
||||
<div ref="left">
|
||||
<div
|
||||
v-clickoutside:touchstart="swipeMove"
|
||||
class="van-cell-swipe"
|
||||
@click="swipeMove()"
|
||||
@touchstart="startDrag"
|
||||
@touchmove="onDrag"
|
||||
@touchend="endDrag"
|
||||
@touchcancel="endDrag"
|
||||
>
|
||||
<div class="van-cell-swipe__wrapper" :style="wrapperStyle" @transitionend="swipe = false">
|
||||
<div class="van-cell-swipe__left" v-if="leftWidth">
|
||||
<slot name="left"></slot>
|
||||
</div>
|
||||
</div>
|
||||
<div class="van-cell-right">
|
||||
<div ref="right">
|
||||
<slot></slot>
|
||||
<div class="van-cell-swipe__right" v-if="rightWidth">
|
||||
<slot name="right"></slot>
|
||||
</div>
|
||||
</div>
|
||||
@ -17,112 +21,100 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { once } from '../utils/dom';
|
||||
import Clickoutside from '../utils/clickoutside';
|
||||
|
||||
export default {
|
||||
name: 'van-cell-swipe',
|
||||
|
||||
props: {
|
||||
'leftWidth': { type: Number, default: 0 },
|
||||
'rightWidth': { type: Number, default: 0 }
|
||||
},
|
||||
directives: { Clickoutside },
|
||||
data() {
|
||||
return {
|
||||
start: { x: 0, y: 0 }
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
leftDefaultTransform() {
|
||||
return this.translate3d(-this.leftWidth - 1);
|
||||
leftWidth: {
|
||||
type: Number,
|
||||
default: 0
|
||||
},
|
||||
rightDefaultTransform() {
|
||||
return this.translate3d(this.rightWidth);
|
||||
rightWidth: {
|
||||
type: Number,
|
||||
default: 0
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.wrap = this.$refs.cell.querySelector('.van-cell-wrapper');
|
||||
this.leftElm = this.$refs.left;
|
||||
this.leftWrapElm = this.leftElm.parentNode;
|
||||
this.leftWrapElm.style.webkitTransform = this.leftDefaultTransform;
|
||||
|
||||
this.rightElm = this.$refs.right;
|
||||
this.rightWrapElm = this.rightElm.parentNode;
|
||||
this.rightWrapElm.style.webkitTransform = this.rightDefaultTransform;
|
||||
directives: {
|
||||
Clickoutside
|
||||
},
|
||||
|
||||
data() {
|
||||
return {
|
||||
offset: 0
|
||||
};
|
||||
},
|
||||
|
||||
computed: {
|
||||
wrapperStyle() {
|
||||
return {
|
||||
transform: `translate3d(${this.offset}px, 0, 0)`
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
resetSwipeStatus() {
|
||||
this.swiping = false; // 是否正在拖动
|
||||
this.opened = true; // 记录是否滑动左右 或者 注册
|
||||
this.offsetLeft = 0; // 记录单次拖动的拖动距离
|
||||
},
|
||||
translate3d(offset) {
|
||||
return `translate3d(${offset}px, 0, 0)`;
|
||||
},
|
||||
|
||||
swipeMove(offset = 0) {
|
||||
this.wrap.style.webkitTransform = this.translate3d(offset);
|
||||
this.rightWrapElm.style.webkitTransform = this.translate3d(this.rightWidth + offset);
|
||||
this.leftWrapElm.style.webkitTransform = this.translate3d(-this.leftWidth + offset);
|
||||
this.offset = offset;
|
||||
offset && (this.swiping = true);
|
||||
},
|
||||
|
||||
swipeLeaveTransition(direction) {
|
||||
setTimeout(() => {
|
||||
this.swipeLeave = true;
|
||||
// left
|
||||
if (direction > 0 && -this.offsetLeft > this.rightWidth * 0.4 && this.rightWidth > 0) {
|
||||
this.swipeMove(-this.rightWidth);
|
||||
this.resetSwipeStatus();
|
||||
return;
|
||||
// right
|
||||
} else if (direction < 0 && this.offsetLeft > this.leftWidth * 0.4 && this.leftWidth > 0) {
|
||||
this.swipeMove(this.leftWidth);
|
||||
this.resetSwipeStatus();
|
||||
return;
|
||||
} else {
|
||||
this.swipeMove(0);
|
||||
once(this.wrap, 'webkitTransitionEnd', () => {
|
||||
this.wrap.style.webkitTransform = '';
|
||||
this.rightWrapElm.style.webkitTransform = this.rightDefaultTransform;
|
||||
this.leftWrapElm.style.webkitTransform = this.leftDefaultTransform;
|
||||
this.swipeLeave = false;
|
||||
this.swiping = false;
|
||||
});
|
||||
}
|
||||
}, 0);
|
||||
const { offset, leftWidth, rightWidth } = this;
|
||||
// right
|
||||
if (direction > 0 && -offset > rightWidth * 0.4 && rightWidth > 0) {
|
||||
this.swipeMove(-rightWidth);
|
||||
this.resetSwipeStatus();
|
||||
// left
|
||||
} else if (direction < 0 && offset > leftWidth * 0.4 && leftWidth > 0) {
|
||||
this.swipeMove(leftWidth);
|
||||
this.resetSwipeStatus();
|
||||
} else {
|
||||
this.swipeMove();
|
||||
}
|
||||
},
|
||||
startDrag(evt) {
|
||||
evt = evt.changedTouches ? evt.changedTouches[0] : evt;
|
||||
this.dragging = true;
|
||||
this.start.x = evt.pageX;
|
||||
this.start.y = evt.pageY;
|
||||
|
||||
startDrag(event) {
|
||||
this.startX = event.changedTouches[0].pageX;
|
||||
this.startY = event.changedTouches[0].pageY;
|
||||
},
|
||||
onDrag(evt) {
|
||||
|
||||
onDrag(event) {
|
||||
if (this.opened) {
|
||||
!this.swiping && this.swipeMove(0);
|
||||
!this.swiping && this.swipeMove();
|
||||
this.opened = false;
|
||||
return;
|
||||
}
|
||||
if (!this.dragging) return;
|
||||
let swiping;
|
||||
const e = evt.changedTouches ? evt.changedTouches[0] : evt;
|
||||
const offsetTop = e.pageY - this.start.y;
|
||||
const offsetLeft = this.offsetLeft = e.pageX - this.start.x;
|
||||
|
||||
const offsetTop = event.changedTouches[0].pageY - this.startY;
|
||||
const offsetLeft = event.changedTouches[0].pageX - this.startX;
|
||||
if ((offsetLeft < 0 && -offsetLeft > this.rightWidth) ||
|
||||
(offsetLeft > 0 && offsetLeft > this.leftWidth) ||
|
||||
(offsetLeft > 0 && !this.leftWidth) ||
|
||||
(offsetLeft < 0 && !this.rightWidth)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const y = Math.abs(offsetTop);
|
||||
const x = Math.abs(offsetLeft);
|
||||
swiping = !(x < 5 || (x >= 5 && y >= x * 1.73));
|
||||
if (!swiping) return;
|
||||
evt.preventDefault();
|
||||
this.swipeMove(offsetLeft);
|
||||
const swiping = !(x < 5 || (x >= 5 && y >= x * 1.73));
|
||||
if (swiping) {
|
||||
event.preventDefault();
|
||||
this.swipeMove(offsetLeft);
|
||||
};
|
||||
},
|
||||
|
||||
endDrag() {
|
||||
if (!this.swiping) return;
|
||||
this.swipeLeaveTransition(this.offsetLeft > 0 ? -1 : 1);
|
||||
if (this.swiping) {
|
||||
this.swipeLeaveTransition(this.offset > 0 ? -1 : 1);
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -19,7 +19,7 @@ export default {
|
||||
name: 'van-datetime-picker',
|
||||
|
||||
components: {
|
||||
'van-picker': Picker
|
||||
[Picker.name]: Picker
|
||||
},
|
||||
|
||||
props: {
|
||||
@ -270,6 +270,9 @@ export default {
|
||||
});
|
||||
},
|
||||
setColumnByValues(values) {
|
||||
if (!this.$refs.picker) {
|
||||
return;
|
||||
}
|
||||
const setColumnValue = this.$refs.picker.setColumnValue;
|
||||
if (this.type === 'time') {
|
||||
setColumnValue(0, values[0]);
|
||||
@ -285,6 +288,10 @@ export default {
|
||||
}
|
||||
[].forEach.call(this.$refs.picker.$children, child => child.doOnValueChange());
|
||||
}
|
||||
},
|
||||
|
||||
mounted() {
|
||||
this.updateColumnValue(this.innerValue);
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
@ -2,8 +2,10 @@
|
||||
<transition name="van-dialog-bounce">
|
||||
<div class="van-dialog" v-show="value">
|
||||
<div class="van-dialog__header" v-if="title" v-text="title" />
|
||||
<div class="van-dialog__content" v-if="message">
|
||||
<div class="van-dialog__message" :class="{ 'van-dialog__message--withtitle': title }" v-html="message" />
|
||||
<div class="van-dialog__content">
|
||||
<slot>
|
||||
<div class="van-dialog__message" v-if="message" :class="{ 'van-dialog__message--withtitle': title }" v-html="message" />
|
||||
</slot>
|
||||
</div>
|
||||
<div class="van-dialog__footer" :class="{ 'is-twobtn': showCancelButton && showConfirmButton }">
|
||||
<van-button size="large" class="van-dialog__cancel" v-show="showCancelButton" @click="handleAction('cancel')">{{ cancelButtonText }}</van-button>
|
||||
@ -27,33 +29,48 @@ export default {
|
||||
mixins: [Popup],
|
||||
|
||||
props: {
|
||||
title: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
message: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
showConfirmButton: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
},
|
||||
showCancelButton: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
confirmButtonText: {
|
||||
type: String,
|
||||
default: '确认'
|
||||
},
|
||||
cancelButtonText: {
|
||||
type: String,
|
||||
default: '取消'
|
||||
},
|
||||
callback: {
|
||||
type: Function
|
||||
},
|
||||
overlay: {
|
||||
default: true
|
||||
},
|
||||
closeOnClickOverlay: {
|
||||
default: true
|
||||
default: false
|
||||
},
|
||||
lockOnScroll: {
|
||||
default: true
|
||||
}
|
||||
},
|
||||
|
||||
data() {
|
||||
return {
|
||||
title: '',
|
||||
message: '',
|
||||
type: '',
|
||||
showConfirmButton: true,
|
||||
showCancelButton: false,
|
||||
confirmButtonText: '确认',
|
||||
cancelButtonText: '取消',
|
||||
callback: null
|
||||
};
|
||||
},
|
||||
|
||||
methods: {
|
||||
handleAction(action) {
|
||||
this.$emit('input', false);
|
||||
this.$emit(action);
|
||||
this.callback && this.callback(action);
|
||||
}
|
||||
}
|
||||
|
@ -1,97 +1,62 @@
|
||||
import Vue from 'vue';
|
||||
import Dialog from './dialog';
|
||||
import DialogComponent from './dialog';
|
||||
|
||||
const DialogConstructor = Vue.extend(Dialog);
|
||||
|
||||
let currentDialog;
|
||||
let instance;
|
||||
let dialogQueue = [];
|
||||
|
||||
const defaultCallback = action => {
|
||||
/* istanbul ignore else */
|
||||
if (currentDialog) {
|
||||
if (currentDialog.resolve && action === 'confirm') {
|
||||
currentDialog.resolve(action);
|
||||
} else if (currentDialog.reject && action === 'cancel') {
|
||||
currentDialog.reject(action);
|
||||
}
|
||||
const defaultConfig = {
|
||||
value: true,
|
||||
title: '',
|
||||
message: '',
|
||||
showCancelButton: false,
|
||||
closeOnClickOverlay: false,
|
||||
callback: action => {
|
||||
instance[action === 'confirm' ? 'resolve' : 'reject'](action);
|
||||
}
|
||||
};
|
||||
|
||||
const initInstance = () => {
|
||||
const DialogConstructor = Vue.extend(DialogComponent);
|
||||
instance = new DialogConstructor({
|
||||
el: document.createElement('div')
|
||||
});
|
||||
|
||||
instance.$on('input', value => {
|
||||
instance.value = value;
|
||||
})
|
||||
instance.callback = defaultCallback;
|
||||
});
|
||||
|
||||
document.body.appendChild(instance.$el);
|
||||
};
|
||||
|
||||
const showNextDialog = () => {
|
||||
if (!instance) {
|
||||
initInstance();
|
||||
}
|
||||
|
||||
/* istanbul ignore else */
|
||||
if (!instance.value && dialogQueue.length > 0) {
|
||||
currentDialog = dialogQueue.shift();
|
||||
|
||||
const { options } = currentDialog;
|
||||
|
||||
for (const prop in options) {
|
||||
/* istanbul ignore else */
|
||||
if (options.hasOwnProperty(prop)) {
|
||||
instance[prop] = options[prop];
|
||||
}
|
||||
const Dialog = options => {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!instance) {
|
||||
initInstance();
|
||||
}
|
||||
|
||||
instance.callback = options.callback || defaultCallback;
|
||||
instance.value = true;
|
||||
document.body.appendChild(instance.$el);
|
||||
}
|
||||
};
|
||||
|
||||
const DialogBox = options => {
|
||||
return new Promise((resolve, reject) => { // eslint-disable-line
|
||||
dialogQueue.push({
|
||||
options: { ...options },
|
||||
callback: options.callback,
|
||||
resolve: resolve,
|
||||
reject: reject
|
||||
Object.assign(instance, {
|
||||
resolve,
|
||||
reject,
|
||||
...options
|
||||
});
|
||||
|
||||
showNextDialog();
|
||||
});
|
||||
};
|
||||
|
||||
DialogBox.alert = function(options) {
|
||||
return DialogBox({
|
||||
type: 'alert',
|
||||
title: '',
|
||||
message: '',
|
||||
closeOnClickOverlay: false,
|
||||
showCancelButton: false,
|
||||
...options
|
||||
});
|
||||
};
|
||||
Dialog.alert = options => Dialog({
|
||||
...defaultConfig,
|
||||
...options
|
||||
});
|
||||
|
||||
DialogBox.confirm = function(options) {
|
||||
return DialogBox({
|
||||
type: 'confirm',
|
||||
title: '',
|
||||
message: '',
|
||||
closeOnClickOverlay: true,
|
||||
showCancelButton: true,
|
||||
...options
|
||||
});
|
||||
};
|
||||
Dialog.confirm = options => Dialog({
|
||||
...defaultConfig,
|
||||
showCancelButton: true,
|
||||
...options
|
||||
});
|
||||
|
||||
DialogBox.close = function() {
|
||||
Dialog.close = () => {
|
||||
instance.value = false;
|
||||
dialogQueue = [];
|
||||
currentDialog = null;
|
||||
};
|
||||
|
||||
export default DialogBox;
|
||||
export default Dialog;
|
||||
export {
|
||||
Dialog
|
||||
};
|
||||
|
@ -48,15 +48,15 @@
|
||||
|
||||
<script>
|
||||
const VALID_TYPES = ['text', 'number', 'email', 'url', 'tel', 'date', 'time', 'datetime', 'password', 'textarea'];
|
||||
import vanCell from '../cell';
|
||||
import vanIcon from '../icon';
|
||||
import Cell from '../cell';
|
||||
import Icon from '../icon';
|
||||
|
||||
export default {
|
||||
name: 'van-field',
|
||||
|
||||
components: {
|
||||
vanCell,
|
||||
vanIcon
|
||||
[Cell.name]: Cell,
|
||||
[Icon.name]: Icon
|
||||
},
|
||||
|
||||
props: {
|
||||
|
@ -13,8 +13,8 @@
|
||||
<script>
|
||||
import Vue from 'vue';
|
||||
import Popup from '../mixins/popup';
|
||||
import VanSwipe from '../swipe';
|
||||
import VanSwipeItem from '../swipe-item';
|
||||
import Swipe from '../swipe';
|
||||
import SwipeItem from '../swipe-item';
|
||||
|
||||
export default {
|
||||
name: 'van-image-preview',
|
||||
@ -22,8 +22,8 @@ export default {
|
||||
mixins: [Popup],
|
||||
|
||||
components: {
|
||||
VanSwipe,
|
||||
VanSwipeItem
|
||||
[Swipe.name]: Swipe,
|
||||
[SwipeItem.name]: SwipeItem
|
||||
},
|
||||
|
||||
props: {
|
||||
|
@ -37,7 +37,7 @@ import Swipe from './swipe';
|
||||
import SwipeItem from './swipe-item';
|
||||
import DatetimePicker from './datetime-picker';
|
||||
|
||||
const version = '0.8.5';
|
||||
const version = '0.8.6';
|
||||
const components = [
|
||||
Button,
|
||||
Switch,
|
||||
|
@ -1,12 +1,13 @@
|
||||
<template>
|
||||
<div class="van-loading" :class="['van-loading--' + type]">
|
||||
<span class="van-loading__spinner" :class="['van-loading__spinner--' + type, 'van-loading__spinner--' + color]"></span>
|
||||
<div :class="['van-loading', 'van-loading--' + type]">
|
||||
<span :class="['van-loading__spinner', 'van-loading__spinner--' + type, 'van-loading__spinner--' + color]"></span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
const VALID_TYPES = ['gradient-circle', 'circle'];
|
||||
const VALID_COLORS = ['black', 'white'];
|
||||
|
||||
export default {
|
||||
name: 'van-loading',
|
||||
|
||||
@ -14,16 +15,12 @@ export default {
|
||||
type: {
|
||||
type: String,
|
||||
default: 'gradient-circle',
|
||||
validator(value) {
|
||||
return VALID_TYPES.indexOf(value) > -1;
|
||||
}
|
||||
validator: value => VALID_TYPES.indexOf(value) > -1
|
||||
},
|
||||
color: {
|
||||
type: String,
|
||||
default: 'black',
|
||||
validator(value) {
|
||||
return VALID_COLORS.indexOf(value) > -1;
|
||||
}
|
||||
validator: value => VALID_COLORS.indexOf(value) > -1
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -138,7 +138,7 @@ export default {
|
||||
|
||||
if (this.preventScroll) {
|
||||
document.addEventListener('touchstart', this.recordPosition, false);
|
||||
document.addEventListener('touchmove', this.watchTouchMove, false);
|
||||
document.addEventListener('touchmove', this.watchTouchMove, false);
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -82,7 +82,7 @@ const PopupManager = {
|
||||
|
||||
let domParentNode;
|
||||
if (dom && dom.parentNode && dom.parentNode.nodeType !== 11) {
|
||||
domParentNode = dom.parentNode
|
||||
domParentNode = dom.parentNode;
|
||||
} else {
|
||||
domParentNode = document.body;
|
||||
}
|
||||
|
@ -8,7 +8,7 @@
|
||||
</slot>
|
||||
</div>
|
||||
<div class="van-picker__columns" :class="['van-picker__columns--' + columns.length]">
|
||||
<picker-column
|
||||
<van-picker-column
|
||||
v-for="(item, index) in columns"
|
||||
:key="index"
|
||||
v-model="values[index]"
|
||||
@ -17,8 +17,8 @@
|
||||
:itemHeight="itemHeight"
|
||||
:visible-item-count="visibileColumnCount"
|
||||
:value-key="valueKey"
|
||||
@columnChange="columnValueChange(index)">
|
||||
</picker-column>
|
||||
@columnChange="columnValueChange(index)"
|
||||
/>
|
||||
<div class="van-picker-center-highlight" :style="{ height: itemHeight + 'px', marginTop: -itemHeight / 2 + 'px' }"></div>
|
||||
</div>
|
||||
</div>
|
||||
@ -33,7 +33,7 @@ export default {
|
||||
name: 'van-picker',
|
||||
|
||||
components: {
|
||||
PickerColumn
|
||||
[PickerColumn.name]: PickerColumn
|
||||
},
|
||||
|
||||
props: {
|
||||
|
@ -1,27 +1,11 @@
|
||||
<template>
|
||||
<div class="van-progress">
|
||||
<div class="van-progress__bar">
|
||||
<span class="van-progress__bar__finished-portion" :style="{backgroundColor: componentColor, width: percentage + '%'}"></span>
|
||||
<span class="van-progress__bar__pivot" :style="pivotStyle">{{ pivotText }}</span>
|
||||
</div>
|
||||
<span class="van-progress__portion" :style="portionStyle"></span>
|
||||
<span class="van-progress__pivot" :style="pivotStyle">{{ pivotText }}</span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
/**
|
||||
* van-progress
|
||||
* @module components/progress
|
||||
* @desc 开关
|
||||
* @param {boolean} [inactive=false] - 是否置灰
|
||||
* @param {number} [percentage=0] - 进度百分比
|
||||
* @param {string} [pivotText=percentage] - 进度条显示文字
|
||||
* @param {string} [color='#38f'] - 进度条颜色
|
||||
* @param {string} [textColor='#fff'] - 进度条文字颜色
|
||||
*
|
||||
* @example
|
||||
* <van-switch checked="true" disabled="false"></van-switch>
|
||||
*/
|
||||
|
||||
const DEFAULT_COLOR = '#38f';
|
||||
const DEFAULT_TEXT_COLOR = '#fff';
|
||||
const INACTIVE_COLOR = '#cacaca';
|
||||
@ -33,14 +17,12 @@ export default {
|
||||
percentage: {
|
||||
type: Number,
|
||||
required: true,
|
||||
validator(value) {
|
||||
return value <= 100 && value >= 0;
|
||||
}
|
||||
validator: value => value >= 0 && value <= 100
|
||||
},
|
||||
inactive: Boolean,
|
||||
pivotText: {
|
||||
type: String,
|
||||
default: function() {
|
||||
default() {
|
||||
return this.percentage + '%';
|
||||
}
|
||||
},
|
||||
@ -59,24 +41,19 @@ export default {
|
||||
return this.inactive ? INACTIVE_COLOR : this.color;
|
||||
},
|
||||
pivotStyle() {
|
||||
const pivotStyle = {
|
||||
backgroundColor: this.componentColor,
|
||||
const { percentage } = this;
|
||||
return {
|
||||
color: this.textColor,
|
||||
left: this.percentage + '%',
|
||||
marginLeft: '-14px'
|
||||
backgroundColor: this.componentColor,
|
||||
left: percentage <= 5 ? '0%' : percentage >= 95 ? '100%' : percentage + '%',
|
||||
marginLeft: percentage <= 5 ? '0' : percentage >= 95 ? '-28px' : '-14px'
|
||||
};
|
||||
},
|
||||
portionStyle() {
|
||||
return {
|
||||
width: this.percentage + '%',
|
||||
backgroundColor: this.componentColor
|
||||
};
|
||||
if (this.percentage <= 5) {
|
||||
pivotStyle.left = '0%';
|
||||
pivotStyle.marginLeft = '0';
|
||||
} else if (this.percentage >= 95) {
|
||||
pivotStyle.left = '100%';
|
||||
pivotStyle.marginLeft = '-28px';
|
||||
} else {
|
||||
pivotStyle.left = this.percentage + '%';
|
||||
pivotStyle.marginLeft = '-14px';
|
||||
}
|
||||
|
||||
return pivotStyle;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -20,14 +20,14 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import VanIcon from '../icon';
|
||||
import Icon from '../icon';
|
||||
import Clickoutside from '../utils/clickoutside';
|
||||
|
||||
export default {
|
||||
name: 'van-search',
|
||||
|
||||
components: {
|
||||
VanIcon
|
||||
[Icon.name]: Icon
|
||||
},
|
||||
|
||||
props: {
|
||||
|
@ -30,7 +30,7 @@ export default {
|
||||
name: 'van-steps',
|
||||
|
||||
components: {
|
||||
'van-icon': Icon
|
||||
[Icon.name]: Icon
|
||||
},
|
||||
|
||||
props: {
|
||||
|
@ -13,9 +13,9 @@ export default {
|
||||
},
|
||||
|
||||
destroyed() {
|
||||
const index = this.$parent.swipes.indexOf(this)
|
||||
const index = this.$parent.swipes.indexOf(this);
|
||||
if (index > -1) {
|
||||
this.$parent.swipes.splice(index, 1)
|
||||
this.$parent.swipes.splice(index, 1);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -61,27 +61,27 @@ export default {
|
||||
}).on('autoPlay', function(dist, isEnd) {
|
||||
scroll.movePage(dist.x, isEnd);
|
||||
});
|
||||
this.dummy = dummy
|
||||
this.dummy = dummy;
|
||||
},
|
||||
|
||||
watch: {
|
||||
swipes(value) {
|
||||
if (this.autoPlay && value.length > 1) {
|
||||
this.dummy.initMove()
|
||||
this.dummy.initMove();
|
||||
} else {
|
||||
this.dummy.clearMove()
|
||||
this.dummy.clearMove();
|
||||
}
|
||||
this.scroll.update();
|
||||
return value
|
||||
return value;
|
||||
},
|
||||
|
||||
autoPlay(value) {
|
||||
if (value && this.swipes.length > 1) {
|
||||
this.dummy.initMove()
|
||||
this.dummy.initMove();
|
||||
} else {
|
||||
this.dummy.clearMove()
|
||||
this.dummy.clearMove();
|
||||
}
|
||||
return value
|
||||
return value;
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -8,22 +8,12 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import VanLoading from '../loading';
|
||||
/**
|
||||
* van-switch
|
||||
* @module components/switch
|
||||
* @desc 开关
|
||||
* @param {boolean} [value=false] - 开关状态
|
||||
* @param {boolean} [disabled=false] - 禁用
|
||||
* @param {boolean} [loading=false] - loading状态
|
||||
*
|
||||
* @example
|
||||
* <van-switch :checked="true" :disabled="false"></van-switch>
|
||||
*/
|
||||
import Loading from '../loading';
|
||||
|
||||
export default {
|
||||
name: 'van-switch',
|
||||
components: {
|
||||
'van-loading': VanLoading
|
||||
[Loading.name]: Loading
|
||||
},
|
||||
props: {
|
||||
value: Boolean,
|
||||
|
@ -192,7 +192,7 @@
|
||||
const translate = swipeState.startTranslateLeft + deltaX;
|
||||
|
||||
/* istanbul ignore else */
|
||||
if (translate > 0 || (translate * -1) > this.maxTranslate ) return;
|
||||
if (translate > 0 || (translate * -1) > this.maxTranslate) return;
|
||||
|
||||
translateUtil.translateElement(el, translate, null);
|
||||
},
|
||||
@ -200,7 +200,7 @@
|
||||
end: () => {
|
||||
this.isSwiping = false;
|
||||
}
|
||||
})
|
||||
});
|
||||
},
|
||||
|
||||
doOnValueChange() {
|
||||
|
@ -12,9 +12,7 @@
|
||||
props: {
|
||||
type: {
|
||||
type: String,
|
||||
validator: function (val) {
|
||||
return ~ALLOW_TYPE.indexOf(val);
|
||||
}
|
||||
validator: val => ~ALLOW_TYPE.indexOf(val)
|
||||
},
|
||||
mark: Boolean,
|
||||
plain: Boolean
|
||||
|
@ -20,8 +20,8 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import vanLoading from '../loading';
|
||||
import vanIcon from '../icon';
|
||||
import Icon from '../icon';
|
||||
import Loading from '../loading';
|
||||
|
||||
const TOAST_TYPES = ['text', 'html', 'loading', 'success', 'fail'];
|
||||
const DEFAULT_STYLE_LIST = ['success', 'fail'];
|
||||
@ -37,8 +37,8 @@ export default {
|
||||
name: 'van-toast',
|
||||
|
||||
components: {
|
||||
'van-loading': vanLoading,
|
||||
'van-icon': vanIcon
|
||||
[Icon.name]: Icon,
|
||||
[Loading.name]: Loading
|
||||
},
|
||||
props: {
|
||||
type: {
|
||||
|
@ -1,57 +1,54 @@
|
||||
<template>
|
||||
<div class="van-uploader">
|
||||
<slot></slot>
|
||||
<template v-if="disabled">
|
||||
<input type="file" @change="onValueChange" disabled="disabled" class="van-uploader__input" />
|
||||
</template>
|
||||
<template v-else>
|
||||
<input type="file" @change="onValueChange" class="van-uploader__input" ref="input" />
|
||||
</template>
|
||||
<input type="file" @change="onValueChange" :disabled="disabled" class="van-uploader__input" ref="input" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'van-uploader',
|
||||
props: {
|
||||
disabled: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
beforeRead: Function,
|
||||
afterRead: Function,
|
||||
resultType: {
|
||||
type: String,
|
||||
default: 'dataUrl',
|
||||
validator(value) {
|
||||
return value === 'dataUrl' || value === 'text';
|
||||
}
|
||||
}
|
||||
export default {
|
||||
name: 'van-uploader',
|
||||
|
||||
props: {
|
||||
disabled: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
methods: {
|
||||
onValueChange(event) {
|
||||
if (this.disabled) {
|
||||
return;
|
||||
}
|
||||
var files = event.target.files;
|
||||
var file = files[0];
|
||||
if (!file) return;
|
||||
if (this.beforeRead && !this.beforeRead(file)) return;
|
||||
var reader = new FileReader();
|
||||
reader.onload = (e) => {
|
||||
this.afterRead && this.afterRead(
|
||||
{
|
||||
file: file,
|
||||
content: e.target.result
|
||||
});
|
||||
this.$refs.input && (this.$refs.input.value = '');
|
||||
};
|
||||
if (this.resultType === 'dataUrl') {
|
||||
reader.readAsDataURL(file);
|
||||
} else if (this.resultType === 'text') {
|
||||
reader.readAsText(file);
|
||||
}
|
||||
beforeRead: Function,
|
||||
afterRead: Function,
|
||||
resultType: {
|
||||
type: String,
|
||||
default: 'dataUrl',
|
||||
validator: value => value === 'dataUrl' || value === 'text'
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
onValueChange(event) {
|
||||
if (this.disabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
const file = event.target.files[0];
|
||||
if (!file || (this.beforeRead && !this.beforeRead(file))) {
|
||||
return;
|
||||
}
|
||||
|
||||
const reader = new FileReader();
|
||||
reader.onload = (e) => {
|
||||
this.afterRead && this.afterRead({
|
||||
file,
|
||||
content: e.target.result
|
||||
});
|
||||
this.$refs.input && (this.$refs.input.value = '');
|
||||
};
|
||||
|
||||
if (this.resultType === 'dataUrl') {
|
||||
reader.readAsDataURL(file);
|
||||
} else if (this.resultType === 'text') {
|
||||
reader.readAsText(file);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
@ -1,11 +0,0 @@
|
||||
import Vue from 'vue';
|
||||
|
||||
export const once = function(el, event, fn) {
|
||||
const listener = function() {
|
||||
if (fn) {
|
||||
fn.apply(this, arguments);
|
||||
}
|
||||
el.removeEventListener(event, listener);
|
||||
};
|
||||
el.addEventListener(event, listener);
|
||||
};
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "vant-css",
|
||||
"version": "0.8.5",
|
||||
"version": "0.8.6",
|
||||
"description": "vant css.",
|
||||
"main": "lib/index.css",
|
||||
"style": "lib/index.css",
|
||||
|
@ -11,7 +11,6 @@
|
||||
font-size: 16px;
|
||||
text-align: center;
|
||||
outline: 0;
|
||||
overflow: hidden;
|
||||
-webkit-appearance: none;
|
||||
|
||||
&::after {
|
||||
|
@ -1,29 +1,26 @@
|
||||
.van-cell {
|
||||
&-swipe {
|
||||
position: relative;
|
||||
min-height: 48px;
|
||||
overflow: hidden;
|
||||
.van-cell-swipe {
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
|
||||
.van-cell-wrapper,
|
||||
.van-cell-left,
|
||||
.van-cell-right {
|
||||
transition: transform 150ms ease-in-out;
|
||||
}
|
||||
&__wrapper,
|
||||
&__left,
|
||||
&__right {
|
||||
transition: transform .15s ease-in-out;
|
||||
}
|
||||
|
||||
&-left,
|
||||
&-right {
|
||||
position: absolute;
|
||||
height: 100%;
|
||||
&__left,
|
||||
&__right {
|
||||
top: 0;
|
||||
height: 100%;
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
&-left {
|
||||
&__left {
|
||||
left: 0;
|
||||
transform: translate3d(-100%, 0, 0);
|
||||
}
|
||||
|
||||
&-right {
|
||||
&__right {
|
||||
right: 0;
|
||||
transform: translate3d(100%, 0, 0);
|
||||
}
|
||||
|
@ -42,9 +42,10 @@
|
||||
overflow: hidden;
|
||||
|
||||
&.is-twobtn {
|
||||
display: flex;
|
||||
|
||||
.van-button {
|
||||
width: 50%;
|
||||
float: left;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.van-dialog__cancel {
|
||||
@ -63,7 +64,10 @@
|
||||
}
|
||||
|
||||
&__confirm {
|
||||
color: #00C000;
|
||||
&,
|
||||
&:active {
|
||||
color: #00C000;
|
||||
}
|
||||
}
|
||||
|
||||
&-bounce-enter {
|
||||
|
@ -1,32 +1,27 @@
|
||||
@import './common/var.css';
|
||||
|
||||
.van-progress {
|
||||
&__bar {
|
||||
height: 4px;
|
||||
border-radius: 4.5px;
|
||||
width: 100%;
|
||||
background: $c-gray-light;
|
||||
position: relative;
|
||||
height: 4px;
|
||||
position: relative;
|
||||
border-radius: 4px;
|
||||
background: $c-gray-light;
|
||||
|
||||
&__finished-portion {
|
||||
border-radius: 4.5px;
|
||||
height: 100%;
|
||||
position: absolute;
|
||||
left: 0;
|
||||
display: inline-block;
|
||||
}
|
||||
&__portion {
|
||||
left: 0;
|
||||
height: 100%;
|
||||
position: absolute;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
&__pivot {
|
||||
padding: 2px 0;
|
||||
font-size: 8px;
|
||||
position: absolute;
|
||||
border-radius: 6px;
|
||||
width: 28px;
|
||||
background-color: $c-gray-light;
|
||||
line-height: 8px;
|
||||
text-align: center;
|
||||
top: 50%;
|
||||
transform: translate3d(0, -50%, 0);
|
||||
}
|
||||
&__pivot {
|
||||
top: 50%;
|
||||
width: 28px;
|
||||
font-size: 8px;
|
||||
margin-top: -6px;
|
||||
position: absolute;
|
||||
border-radius: 6px;
|
||||
line-height: 12px;
|
||||
text-align: center;
|
||||
background-color: $c-gray-light;
|
||||
}
|
||||
}
|
||||
|
@ -2,96 +2,96 @@ const path = require('path');
|
||||
const webpack = require('webpack');
|
||||
const ProgressBarPlugin = require('progress-bar-webpack-plugin');
|
||||
|
||||
const webpackConfig = {
|
||||
output: {
|
||||
path: path.resolve(process.cwd(), 'dist'),
|
||||
publicPath: '/dist/',
|
||||
filename: '[name].js',
|
||||
chunkFilename: '[id].js',
|
||||
libraryTarget: 'umd'
|
||||
},
|
||||
plugins: [
|
||||
new ProgressBarPlugin(),
|
||||
new webpack.LoaderOptionsPlugin({
|
||||
minimize: true,
|
||||
options: {
|
||||
babel: {
|
||||
presets: ['env'],
|
||||
plugins: ['transform-runtime', 'transform-vue-jsx']
|
||||
},
|
||||
vue: {
|
||||
autoprefixer: false,
|
||||
preserveWhitespace: false
|
||||
function getWebpackConfig(testFileName) {
|
||||
return {
|
||||
output: {
|
||||
path: path.resolve(process.cwd(), 'dist'),
|
||||
publicPath: '/dist/',
|
||||
filename: '[name].js',
|
||||
chunkFilename: '[id].js',
|
||||
libraryTarget: 'umd'
|
||||
},
|
||||
plugins: [
|
||||
new ProgressBarPlugin(),
|
||||
new webpack.LoaderOptionsPlugin({
|
||||
minimize: true,
|
||||
options: {
|
||||
babel: {
|
||||
presets: ['env'],
|
||||
plugins: ['transform-runtime', 'transform-vue-jsx']
|
||||
},
|
||||
vue: {
|
||||
autoprefixer: false,
|
||||
preserveWhitespace: false
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
],
|
||||
stats: 'errors-only',
|
||||
resolve: {
|
||||
modules: [
|
||||
path.resolve(process.cwd(), 'node_modules'),
|
||||
'node_modules'
|
||||
}),
|
||||
new webpack.DefinePlugin({
|
||||
'process.env': {
|
||||
TEST_FILE: `"${testFileName}"`
|
||||
}
|
||||
})
|
||||
],
|
||||
extensions: ['.js', '.json', '.vue'],
|
||||
alias: {
|
||||
src: path.resolve(process.cwd(), 'src'),
|
||||
packages: path.resolve(process.cwd(), 'packages'),
|
||||
examples: path.resolve(process.cwd(), 'examples'),
|
||||
vue$: 'vue/dist/vue.common.js'
|
||||
}
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
enforce: 'pre',
|
||||
test: /\.js$/,
|
||||
exclude: /node_modules|vue-router\/|vue-loader\/|docs|test|src\/index|src\/utils|src\/mixins|packages\/swipe/,
|
||||
use: ['isparta-loader']
|
||||
},
|
||||
{
|
||||
test: /\.js$/,
|
||||
exclude: /node_modules|vue-router\/|vue-loader\//,
|
||||
use: ['babel-loader']
|
||||
},
|
||||
{
|
||||
test: /\.(css|pcss)$/,
|
||||
use: [
|
||||
'style-loader',
|
||||
'css-loader',
|
||||
'postcss-loader'
|
||||
]
|
||||
},
|
||||
{
|
||||
test: /\.(gif|png|jpe?g)(\?\S*)?$/,
|
||||
use: [{
|
||||
loader: 'url-loader',
|
||||
options: {
|
||||
query: {
|
||||
limit: 10000,
|
||||
name: 'static/[name].[hash:7].[ext]'
|
||||
}
|
||||
}
|
||||
}]
|
||||
},
|
||||
{
|
||||
test: /\.vue$/,
|
||||
use: [{
|
||||
loader: 'vue-loader',
|
||||
options: {
|
||||
loaders: {
|
||||
css: [
|
||||
'style-loader',
|
||||
'css-loader',
|
||||
'postcss-loader'
|
||||
],
|
||||
js: ['isparta-loader']
|
||||
}
|
||||
}
|
||||
}]
|
||||
stats: 'errors-only',
|
||||
resolve: {
|
||||
modules: [path.resolve(process.cwd(), 'node_modules'), 'node_modules'],
|
||||
extensions: ['.js', '.json', '.vue'],
|
||||
alias: {
|
||||
src: path.resolve(process.cwd(), 'src'),
|
||||
packages: path.resolve(process.cwd(), 'packages'),
|
||||
examples: path.resolve(process.cwd(), 'examples'),
|
||||
vue$: 'vue/dist/vue.common.js'
|
||||
}
|
||||
]
|
||||
},
|
||||
devtool: '#inline-source-map'
|
||||
};
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
enforce: 'pre',
|
||||
test: /\.js$/,
|
||||
exclude: /node_modules|vue-router\/|vue-loader\/|docs|test|src\/index|src\/utils|src\/mixins|packages\/swipe/,
|
||||
use: ['isparta-loader']
|
||||
},
|
||||
{
|
||||
test: /\.js$/,
|
||||
exclude: /node_modules|vue-router\/|vue-loader\//,
|
||||
use: ['babel-loader']
|
||||
},
|
||||
{
|
||||
test: /\.(css|pcss)$/,
|
||||
use: ['style-loader', 'css-loader', 'postcss-loader']
|
||||
},
|
||||
{
|
||||
test: /\.(gif|png|jpe?g)(\?\S*)?$/,
|
||||
use: [
|
||||
{
|
||||
loader: 'url-loader',
|
||||
options: {
|
||||
query: {
|
||||
limit: 10000,
|
||||
name: 'static/[name].[hash:7].[ext]'
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
test: /\.vue$/,
|
||||
use: [
|
||||
{
|
||||
loader: 'vue-loader',
|
||||
options: {
|
||||
loaders: {
|
||||
css: ['style-loader', 'css-loader', 'postcss-loader'],
|
||||
js: ['isparta-loader']
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
devtool: '#inline-source-map'
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = webpackConfig;
|
||||
module.exports = getWebpackConfig;
|
||||
|
@ -1,5 +1,16 @@
|
||||
require('packages/vant-css/src/index.css');
|
||||
|
||||
// require all test files (files that ends with .spec.js)
|
||||
// hack for test touch event
|
||||
window.ontouchstart = {};
|
||||
|
||||
// 读取配置文件,判断运行单个测试文件还是所有测试文件
|
||||
const testsReq = require.context('./specs', true, /\.spec$/);
|
||||
testsReq.keys().forEach(testsReq);
|
||||
if (process.env.TEST_FILE) {
|
||||
testsReq.keys().forEach((file) => {
|
||||
if (file.indexOf(process.env.TEST_FILE) !== -1) {
|
||||
testsReq(file);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
testsReq.keys().forEach(testsReq);
|
||||
}
|
@ -4,7 +4,7 @@ require('babel-core/register')({
|
||||
presets: [require('babel-preset-env')]
|
||||
});
|
||||
|
||||
var webpackConfig = require('./get-webpack-conf');
|
||||
var getWebpackConfig = require('./get-webpack-conf');
|
||||
var travis = process.env.TRAVIS;
|
||||
|
||||
module.exports = function(config) {
|
||||
@ -16,7 +16,7 @@ module.exports = function(config) {
|
||||
preprocessors: {
|
||||
'./index.js': ['webpack', 'sourcemap']
|
||||
},
|
||||
webpack: webpackConfig,
|
||||
webpack: getWebpackConfig(getTestFileName()),
|
||||
webpackMiddleware: {
|
||||
noInfo: true
|
||||
},
|
||||
@ -30,3 +30,8 @@ module.exports = function(config) {
|
||||
singleRun: false
|
||||
});
|
||||
};
|
||||
|
||||
function getTestFileName() {
|
||||
const flagIndex = process.argv.indexOf('--file');
|
||||
return flagIndex !== -1 ? process.argv[flagIndex + 1] : '';
|
||||
}
|
||||
|
19
test/unit/selector.js
Normal file
19
test/unit/selector.js
Normal file
@ -0,0 +1,19 @@
|
||||
/**
|
||||
* 运行单个测试文件
|
||||
*/
|
||||
|
||||
const fs = require('fs');
|
||||
const inquirer = require('inquirer');
|
||||
const path = require('path');
|
||||
const shell = require('shelljs');
|
||||
const files = fs.readdirSync(path.resolve(__dirname, './specs'));
|
||||
|
||||
inquirer.prompt([{
|
||||
type: 'list',
|
||||
name: 'select',
|
||||
message: '请选择要运行的测试文件:',
|
||||
choices: files
|
||||
}], (result) => {
|
||||
const file = result.select.replace('.spec.js', '');
|
||||
shell.exec('karma start test/unit/karma.conf.js --color alway --file ' + file);
|
||||
});
|
@ -1,141 +1,117 @@
|
||||
import CellSwipe from 'packages/cell-swipe';
|
||||
import { mount } from 'avoriaz';
|
||||
import { triggerTouch } from '../utils';
|
||||
|
||||
const defaultProps = {
|
||||
propsData: {
|
||||
leftWidth: 100,
|
||||
rightWidth: 100
|
||||
}
|
||||
}
|
||||
|
||||
describe('CellSwipe', () => {
|
||||
let wrapper;
|
||||
afterEach(() => {
|
||||
wrapper && wrapper.destroy();
|
||||
});
|
||||
|
||||
it('render left or right part when has width', () => {
|
||||
wrapper = mount(CellSwipe, defaultProps);
|
||||
expect(wrapper.find('.van-cell-swipe__left').length).to.equal(1);
|
||||
expect(wrapper.find('.van-cell-swipe__right').length).to.equal(1);
|
||||
});
|
||||
|
||||
it('create a CellSwipe', () => {
|
||||
wrapper = mount(CellSwipe, {
|
||||
propsData: {
|
||||
leftWidth: 2,
|
||||
rightWidth: 2
|
||||
}
|
||||
it('not render left or right part when width is 0', () => {
|
||||
wrapper = mount(CellSwipe);
|
||||
expect(wrapper.find('.van-cell-swipe__left').length).to.equal(0);
|
||||
expect(wrapper.find('.van-cell-swipe__right').length).to.equal(0);
|
||||
});
|
||||
|
||||
it('drag and show left part', () => {
|
||||
wrapper = mount(CellSwipe, defaultProps);
|
||||
|
||||
triggerTouch(wrapper, 'touchstart', 0, 0);
|
||||
expect(wrapper.vm.startX).to.equal(0);
|
||||
expect(wrapper.vm.startY).to.equal(0);
|
||||
|
||||
triggerTouch(wrapper, 'touchmove', 50, 0);
|
||||
expect(wrapper.vm.offset).to.equal(50);
|
||||
|
||||
triggerTouch(wrapper, 'touchend', 50, 0);
|
||||
expect(wrapper.vm.offset).to.equal(100);
|
||||
wrapper.vm.$nextTick(() => {
|
||||
expect(wrapper.vm.opened).to.be.true;
|
||||
});
|
||||
wrapper.vm.startDrag({
|
||||
pageX: 0,
|
||||
pageY: 0
|
||||
});
|
||||
|
||||
it('drag and show right part', () => {
|
||||
wrapper = mount(CellSwipe, defaultProps);
|
||||
|
||||
triggerTouch(wrapper, 'touchstart', 0, 0);
|
||||
triggerTouch(wrapper, 'touchmove', -50, 0);
|
||||
triggerTouch(wrapper, 'touchend', -50, 0);
|
||||
expect(wrapper.vm.offset).to.equal(-100);
|
||||
wrapper.vm.$nextTick(() => {
|
||||
expect(wrapper.vm.opened).to.be.true;
|
||||
});
|
||||
wrapper.vm.onDrag({
|
||||
preventDefault() {},
|
||||
pageY: 0,
|
||||
pageX: 50
|
||||
});
|
||||
|
||||
it('drag and reset left part', () => {
|
||||
wrapper = mount(CellSwipe, defaultProps);
|
||||
|
||||
triggerTouch(wrapper, 'touchstart', 0, 0);
|
||||
triggerTouch(wrapper, 'touchmove', 10, 0);
|
||||
triggerTouch(wrapper, 'touchmove', 30, 0);
|
||||
triggerTouch(wrapper, 'touchend', 30, 0);
|
||||
expect(wrapper.vm.offset).to.equal(0);
|
||||
});
|
||||
|
||||
it('drag and reset right part', () => {
|
||||
wrapper = mount(CellSwipe, defaultProps);
|
||||
|
||||
triggerTouch(wrapper, 'touchstart', 0, 0);
|
||||
triggerTouch(wrapper, 'touchmove', -10, 0);
|
||||
triggerTouch(wrapper, 'touchmove', -30, 0);
|
||||
triggerTouch(wrapper, 'touchend', -30, 0);
|
||||
expect(wrapper.vm.offset).to.equal(0);
|
||||
});
|
||||
|
||||
it('drag distance out of ranges', () => {
|
||||
wrapper = mount(CellSwipe, defaultProps);
|
||||
|
||||
triggerTouch(wrapper, 'touchstart', 0, 0);
|
||||
triggerTouch(wrapper, 'touchmove', 1000, 0);
|
||||
expect(wrapper.vm.offset).to.equal(0);
|
||||
});
|
||||
|
||||
it('drag and hide left part', (done) => {
|
||||
wrapper = mount(CellSwipe, defaultProps);
|
||||
|
||||
triggerTouch(wrapper, 'touchstart', 0, 0);
|
||||
triggerTouch(wrapper, 'touchmove', 20, 0);
|
||||
triggerTouch(wrapper, 'touchmove', 50, 0);
|
||||
triggerTouch(wrapper, 'touchend', 50, 0);
|
||||
expect(wrapper.vm.offset).to.equal(100);
|
||||
wrapper.vm.$nextTick(() => {
|
||||
expect(wrapper.vm.opened).to.be.true;
|
||||
|
||||
triggerTouch(wrapper, 'touchstart', 0, 0);
|
||||
triggerTouch(wrapper, 'touchmove', 1, 0);
|
||||
|
||||
wrapper.vm.$nextTick(() => {
|
||||
expect(wrapper.vm.offset).to.equal(0);
|
||||
expect(wrapper.vm.opened).to.be.false;
|
||||
done();
|
||||
});
|
||||
});
|
||||
wrapper.vm.offsetLeft = -20;
|
||||
wrapper.vm.rightWidth = 10;
|
||||
wrapper.vm.swipeLeaveTransition(1);
|
||||
wrapper.vm.endDrag();
|
||||
expect(wrapper.hasClass('van-cell-swipe')).to.be.true;
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('CellSwipe-left', () => {
|
||||
let wrapper;
|
||||
afterEach(() => {
|
||||
wrapper && wrapper.destroy();
|
||||
});
|
||||
|
||||
it('create a CellSwipe left', () => {
|
||||
wrapper = mount(CellSwipe, {
|
||||
propsData: {
|
||||
leftWidth: 2,
|
||||
rightWidth: 2
|
||||
}
|
||||
});
|
||||
wrapper.vm.startDrag({
|
||||
changedTouches: [{
|
||||
pageX: 0,
|
||||
pageY: 0
|
||||
}
|
||||
]
|
||||
});
|
||||
wrapper.vm.onDrag({
|
||||
preventDefault() {},
|
||||
changedTouches: [{
|
||||
pageX: 0,
|
||||
pageY: -50
|
||||
}
|
||||
]
|
||||
});
|
||||
wrapper.vm.offsetLeft = 20;
|
||||
wrapper.vm.rightWidth = 10;
|
||||
wrapper.vm.swipeLeaveTransition(-1);
|
||||
wrapper.vm.endDrag();
|
||||
expect(wrapper.hasClass('van-cell-swipe')).to.be.true;
|
||||
});
|
||||
});
|
||||
|
||||
describe('CellSwipe-0', () => {
|
||||
let wrapper;
|
||||
afterEach(() => {
|
||||
wrapper && wrapper.destroy();
|
||||
});
|
||||
|
||||
it('create a CellSwipe 0', () => {
|
||||
wrapper = mount(CellSwipe, {
|
||||
propsData: {
|
||||
leftWidth: 0,
|
||||
rightWidth: 2
|
||||
}
|
||||
});
|
||||
wrapper.vm.startDrag({
|
||||
pageX: 0,
|
||||
pageY: 0
|
||||
});
|
||||
wrapper.vm.onDrag({
|
||||
preventDefault() {},
|
||||
pageY: 0,
|
||||
pageX: -2
|
||||
});
|
||||
wrapper.vm.opened = true;
|
||||
wrapper.vm.onDrag({
|
||||
preventDefault() {},
|
||||
pageY: 0,
|
||||
pageX: -2
|
||||
});
|
||||
wrapper.vm.opened = false;
|
||||
wrapper.vm.onDrag({
|
||||
preventDefault() {},
|
||||
pageY: 0,
|
||||
pageX: 40
|
||||
});
|
||||
wrapper.vm.swipeLeaveTransition(0);
|
||||
wrapper.vm.endDrag();
|
||||
expect(wrapper.hasClass('van-cell-swipe')).to.be.true;
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('CellSwipe-0', () => {
|
||||
let wrapper;
|
||||
afterEach(() => {
|
||||
wrapper && wrapper.destroy();
|
||||
});
|
||||
|
||||
it('create a CellSwipe 0', () => {
|
||||
wrapper = mount(CellSwipe, {
|
||||
propsData: {
|
||||
leftWidth: 0,
|
||||
rightWidth: 2
|
||||
}
|
||||
});
|
||||
wrapper.vm.startDrag({
|
||||
pageX: 0,
|
||||
pageY: 0
|
||||
});
|
||||
wrapper.vm.onDrag({
|
||||
preventDefault() {},
|
||||
pageY: 1000,
|
||||
pageX: 40
|
||||
});
|
||||
wrapper.vm.swipeMove();
|
||||
wrapper.vm.swiping = false;
|
||||
wrapper.vm.endDrag();
|
||||
wrapper.vm.swiping = true;
|
||||
wrapper.vm.endDrag();
|
||||
expect(wrapper.hasClass('van-cell-swipe')).to.be.true;
|
||||
});
|
||||
|
||||
it('drag vertical', () => {
|
||||
wrapper = mount(CellSwipe, defaultProps);
|
||||
|
||||
triggerTouch(wrapper, 'touchstart', 0, 0);
|
||||
triggerTouch(wrapper, 'touchmove', 0, 100);
|
||||
triggerTouch(wrapper, 'touchend', 0, 100);
|
||||
expect(wrapper.vm.offset).to.equal(0);
|
||||
});
|
||||
});
|
||||
|
@ -1,5 +1,20 @@
|
||||
import DatetimePicker from 'packages/datetime-picker';
|
||||
import { mount } from 'avoriaz';
|
||||
import { triggerTouch } from '../utils';
|
||||
|
||||
const dragHelper = (el, position) => {
|
||||
triggerTouch(el, 'touchstart', 0, 0);
|
||||
triggerTouch(el, 'touchmove', 0, position / 4);
|
||||
triggerTouch(el, 'touchmove', 0, position / 3);
|
||||
triggerTouch(el, 'touchmove', 0, position / 2);
|
||||
triggerTouch(el, 'touchmove', 0, position);
|
||||
triggerTouch(el, 'touchend', 0, position);
|
||||
};
|
||||
|
||||
const testTime = '10:00';
|
||||
const testDate = new Date('2017/03/10 10:00');
|
||||
const minDate = new Date('2000/01/01 00:00');
|
||||
const maxDate = new Date('3000/01/01 00:00');
|
||||
|
||||
describe('DatetimePicker', () => {
|
||||
let wrapper;
|
||||
@ -7,36 +22,117 @@ describe('DatetimePicker', () => {
|
||||
wrapper && wrapper.destroy();
|
||||
});
|
||||
|
||||
it('create a datetime picker', () => {
|
||||
const date = new Date();
|
||||
it('create a time picker', () => {
|
||||
wrapper = mount(DatetimePicker, {
|
||||
attachToDocument: true,
|
||||
propsData: {
|
||||
type: 'datetime',
|
||||
value: date
|
||||
type: 'time',
|
||||
value: testTime
|
||||
}
|
||||
});
|
||||
expect(wrapper.data().innerValue.getTime()).to.equal(date.getTime());
|
||||
expect(wrapper.vm.innerValue).to.equal(testTime);
|
||||
});
|
||||
|
||||
it('create a date picker', () => {
|
||||
const date = new Date();
|
||||
wrapper = mount(DatetimePicker, {
|
||||
attachToDocument: true,
|
||||
propsData: {
|
||||
type: 'date',
|
||||
value: date
|
||||
value: testDate
|
||||
}
|
||||
});
|
||||
expect(wrapper.data().innerValue.getTime()).to.equal(date.getTime());
|
||||
expect(wrapper.vm.innerValue.getTime()).to.equal(testDate.getTime());
|
||||
});
|
||||
|
||||
it('create a time picker', () => {
|
||||
const time = '10:00';
|
||||
it('create a datetime picker', () => {
|
||||
wrapper = mount(DatetimePicker, {
|
||||
attachToDocument: true,
|
||||
propsData: {
|
||||
type: 'time',
|
||||
value: time
|
||||
type: 'datetime',
|
||||
value: testDate
|
||||
}
|
||||
});
|
||||
expect(wrapper.data().innerValue).to.equal(time);
|
||||
expect(wrapper.vm.innerValue.getTime()).to.equal(testDate.getTime());
|
||||
});
|
||||
|
||||
it('drag time picker', (done) => {
|
||||
wrapper = mount(DatetimePicker, {
|
||||
attachToDocument: true,
|
||||
propsData: {
|
||||
type: 'time',
|
||||
value: testTime
|
||||
}
|
||||
});
|
||||
|
||||
const [hour, minute] = wrapper.find('.van-picker-column-wrapper');
|
||||
dragHelper(hour, -50);
|
||||
dragHelper(minute, -50);
|
||||
|
||||
setTimeout(() => {
|
||||
expect(wrapper.vm.innerValue).to.equal('5:05');
|
||||
done();
|
||||
}, 10);
|
||||
});
|
||||
|
||||
it('drag date picker', (done) => {
|
||||
wrapper = mount(DatetimePicker, {
|
||||
attachToDocument: true,
|
||||
propsData: {
|
||||
type: 'date',
|
||||
value: testDate,
|
||||
minDate,
|
||||
maxDate
|
||||
}
|
||||
});
|
||||
|
||||
setTimeout(() => {
|
||||
const [year, month, day] = wrapper.find('.van-picker-column-wrapper');
|
||||
dragHelper(year, -50);
|
||||
dragHelper(month, -50);
|
||||
dragHelper(day, -50);
|
||||
setTimeout(() => {
|
||||
const newYear = wrapper.vm.innerValue.getFullYear();
|
||||
const newMonth = wrapper.vm.innerValue.getMonth() + 1;
|
||||
const newDay = wrapper.vm.innerValue.getDate();
|
||||
expect(newYear).to.equal(2022);
|
||||
expect(newMonth).to.equal(8);
|
||||
expect(newDay).to.equal(15);
|
||||
done();
|
||||
}, 10);
|
||||
}, 10);
|
||||
});
|
||||
|
||||
it('drag datetime picker', (done) => {
|
||||
wrapper = mount(DatetimePicker, {
|
||||
attachToDocument: true,
|
||||
propsData: {
|
||||
type: 'datetime',
|
||||
value: testDate,
|
||||
minDate,
|
||||
maxDate
|
||||
}
|
||||
});
|
||||
|
||||
setTimeout(() => {
|
||||
const [year, month, day, hour, minute] = wrapper.find('.van-picker-column-wrapper');
|
||||
dragHelper(year, -50);
|
||||
dragHelper(month, -50);
|
||||
dragHelper(day, -50);
|
||||
dragHelper(hour, -50);
|
||||
dragHelper(minute, -50);
|
||||
setTimeout(() => {
|
||||
const newYear = wrapper.vm.innerValue.getFullYear();
|
||||
const newMonth = wrapper.vm.innerValue.getMonth() + 1;
|
||||
const newDay = wrapper.vm.innerValue.getDate();
|
||||
const newHour = wrapper.vm.innerValue.getHours();
|
||||
const newMinute = wrapper.vm.innerValue.getMinutes();
|
||||
expect(newYear).to.equal(2022);
|
||||
expect(newMonth).to.equal(8);
|
||||
expect(newDay).to.equal(15);
|
||||
expect(newHour).to.equal(15);
|
||||
expect(newMinute).to.equal(5);
|
||||
done();
|
||||
}, 10);
|
||||
}, 10);
|
||||
});
|
||||
});
|
||||
|
@ -3,11 +3,6 @@ import Vue from 'vue';
|
||||
|
||||
describe('Dialog', () => {
|
||||
afterEach(() => {
|
||||
const el = document.querySelector('.van-dialog');
|
||||
if (!el) return;
|
||||
if (el.parentNode) {
|
||||
el.parentNode.removeChild(el);
|
||||
}
|
||||
Dialog.close();
|
||||
});
|
||||
|
||||
@ -28,30 +23,32 @@ describe('Dialog', () => {
|
||||
}, 500);
|
||||
});
|
||||
|
||||
it('create a confirm dialog', () => {
|
||||
it('create a confirm dialog', (done) => {
|
||||
Dialog.confirm({
|
||||
title: 'title',
|
||||
message: 'message'
|
||||
}).catch((action) => {
|
||||
expect(action).to.equal('cancel');
|
||||
done();
|
||||
});
|
||||
|
||||
expect(document.querySelector('.van-dialog')).to.exist;
|
||||
|
||||
setTimeout(() => {
|
||||
document.querySelector('.van-dialog__cancel').click();
|
||||
}, 500);
|
||||
});
|
||||
|
||||
it('create a confirm dialog with callback', (done) => {
|
||||
let dialogAction;
|
||||
Dialog.confirm({
|
||||
title: 'title',
|
||||
message: 'message',
|
||||
callback: (action) => {
|
||||
dialogAction = action;
|
||||
expect(action).to.equal('cancel');
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
expect(document.querySelector('.van-dialog')).to.exist;
|
||||
setTimeout(() => {
|
||||
document.querySelector('.van-dialog__cancel').click();
|
||||
expect(dialogAction).to.equal('cancel');
|
||||
done();
|
||||
}, 500);
|
||||
});
|
||||
});
|
||||
|
@ -9,8 +9,8 @@ describe('Progress', () => {
|
||||
wrapper = mount(Progress, {
|
||||
propsData: propsData
|
||||
});
|
||||
bar = wrapper.find('.van-progress__bar__finished-portion')[0];
|
||||
pivot = wrapper.find('.van-progress__bar__pivot')[0];
|
||||
bar = wrapper.find('.van-progress__portion')[0];
|
||||
pivot = wrapper.find('.van-progress__pivot')[0];
|
||||
};
|
||||
|
||||
afterEach(() => {
|
||||
|
@ -31,7 +31,9 @@ export function DOMChecker(wrapper, rules) {
|
||||
if (style) {
|
||||
Object.keys(style).forEach(key => {
|
||||
Object.keys(style[key]).forEach(prop => {
|
||||
expect(wrapper.find(key)[0].hasStyle(prop, style[key][prop])).to.equal(true);
|
||||
expect(wrapper.find(key)[0].hasStyle(prop, style[key][prop])).to.equal(
|
||||
true
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -39,8 +41,35 @@ export function DOMChecker(wrapper, rules) {
|
||||
if (noStyle) {
|
||||
Object.keys(noStyle).forEach(key => {
|
||||
Object.keys(noStyle[key]).forEach(prop => {
|
||||
expect(wrapper.find(key)[0].hasStyle(prop, noStyle[key][prop])).to.equal(false);
|
||||
expect(
|
||||
wrapper.find(key)[0].hasStyle(prop, noStyle[key][prop])
|
||||
).to.equal(false);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 触发一个 touch 事件
|
||||
export function triggerTouch(wrapper, eventName, x, y) {
|
||||
const el = wrapper.element ? wrapper.element : wrapper;
|
||||
const touch = {
|
||||
identifier: Date.now(),
|
||||
target: el,
|
||||
pageX: x,
|
||||
pageY: y,
|
||||
clientX: x,
|
||||
clientY: y,
|
||||
radiusX: 2.5,
|
||||
radiusY: 2.5,
|
||||
rotationAngle: 10,
|
||||
force: 0.5
|
||||
};
|
||||
|
||||
const event = document.createEvent('CustomEvent');
|
||||
event.initCustomEvent(eventName, true, true, {});
|
||||
event.touches = [touch];
|
||||
event.targetTouches = [touch];
|
||||
event.changedTouches = [touch];
|
||||
|
||||
el.dispatchEvent(event);
|
||||
}
|
||||
|
35
yarn.lock
35
yarn.lock
@ -67,7 +67,7 @@ ajv-keywords@^2.0.0:
|
||||
version "2.1.0"
|
||||
resolved "https://registry.yarnpkg.com/ajv-keywords/-/ajv-keywords-2.1.0.tgz#a296e17f7bfae7c1ce4f7e0de53d29cb32162df0"
|
||||
|
||||
ajv@^4.7.0, ajv@^4.9.1:
|
||||
ajv@^4.11.2, ajv@^4.7.0, ajv@^4.9.1:
|
||||
version "4.11.8"
|
||||
resolved "https://registry.yarnpkg.com/ajv/-/ajv-4.11.8.tgz#82ffb02b29e662ae53bdc20af15947706739c536"
|
||||
dependencies:
|
||||
@ -2768,14 +2768,14 @@ extglob@^0.3.1:
|
||||
dependencies:
|
||||
is-extglob "^1.0.0"
|
||||
|
||||
extract-text-webpack-plugin@2.1.2:
|
||||
version "2.1.2"
|
||||
resolved "https://registry.yarnpkg.com/extract-text-webpack-plugin/-/extract-text-webpack-plugin-2.1.2.tgz#756ef4efa8155c3681833fbc34da53b941746d6c"
|
||||
extract-text-webpack-plugin@2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.npmjs.org/extract-text-webpack-plugin/-/extract-text-webpack-plugin-2.0.0.tgz#8640f72609800a3528f13a2a9634d566a5c1ae60"
|
||||
dependencies:
|
||||
ajv "^4.11.2"
|
||||
async "^2.1.2"
|
||||
loader-utils "^1.0.2"
|
||||
schema-utils "^0.3.0"
|
||||
webpack-sources "^1.0.1"
|
||||
webpack-sources "^0.1.0"
|
||||
|
||||
extract-zip@~1.6.5:
|
||||
version "1.6.5"
|
||||
@ -6816,6 +6816,10 @@ source-list-map@^2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/source-list-map/-/source-list-map-2.0.0.tgz#aaa47403f7b245a92fbc97ea08f250d6087ed085"
|
||||
|
||||
source-list-map@~0.1.7:
|
||||
version "0.1.8"
|
||||
resolved "https://registry.npmjs.org/source-list-map/-/source-list-map-0.1.8.tgz#c550b2ab5427f6b3f21f5afead88c4f5587b2106"
|
||||
|
||||
source-map-support@^0.4.15:
|
||||
version "0.4.16"
|
||||
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.4.16.tgz#16fecf98212467d017d586a2af68d628b9421cd8"
|
||||
@ -7603,9 +7607,9 @@ vue-loader@^13.0.4:
|
||||
vue-style-loader "^3.0.0"
|
||||
vue-template-es2015-compiler "^1.5.3"
|
||||
|
||||
vue-markdown-loader@^2.0.0:
|
||||
version "2.0.0"
|
||||
resolved "https://registry.yarnpkg.com/vue-markdown-loader/-/vue-markdown-loader-2.0.0.tgz#d3cadbf9c8976a81f2d5e39496d505fd4f31bc96"
|
||||
vue-markdown-loader@^2.1.0:
|
||||
version "2.1.0"
|
||||
resolved "https://registry.npmjs.org/vue-markdown-loader/-/vue-markdown-loader-2.1.0.tgz#112d1921dd56daa29906b7c012623c6c5d6e0d8c"
|
||||
dependencies:
|
||||
cheerio "^0.20.0"
|
||||
highlight.js "^9.4.0"
|
||||
@ -7707,6 +7711,13 @@ webpack-merge@^4.1.0:
|
||||
dependencies:
|
||||
lodash "^4.17.4"
|
||||
|
||||
webpack-sources@^0.1.0:
|
||||
version "0.1.5"
|
||||
resolved "https://registry.npmjs.org/webpack-sources/-/webpack-sources-0.1.5.tgz#aa1f3abf0f0d74db7111c40e500b84f966640750"
|
||||
dependencies:
|
||||
source-list-map "~0.1.7"
|
||||
source-map "~0.5.3"
|
||||
|
||||
webpack-sources@^1.0.1:
|
||||
version "1.0.1"
|
||||
resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-1.0.1.tgz#c7356436a4d13123be2e2426a05d1dad9cbe65cf"
|
||||
@ -7926,9 +7937,9 @@ yeast@0.1.2:
|
||||
version "0.1.2"
|
||||
resolved "https://registry.yarnpkg.com/yeast/-/yeast-0.1.2.tgz#008e06d8094320c372dbc2f8ed76a0ca6c8ac419"
|
||||
|
||||
zan-doc@^0.2.1:
|
||||
version "0.2.1"
|
||||
resolved "https://registry.npmjs.org/zan-doc/-/zan-doc-0.2.1.tgz#34723ea180d0ac2e183b66d2a3e4a04b4f6fe91b"
|
||||
zan-doc@^0.2.2:
|
||||
version "0.2.2"
|
||||
resolved "https://registry.npmjs.org/zan-doc/-/zan-doc-0.2.2.tgz#ebf8ffda5bd3cf9277cc3e59c48476a3fbf84d9f"
|
||||
dependencies:
|
||||
cheerio "0.22.0"
|
||||
decamelize "^1.2.0"
|
||||
|
Loading…
x
Reference in New Issue
Block a user