diff --git a/dist/action-sheet/index.js b/dist/action-sheet/index.js index 28bf57fa..225b463a 100644 --- a/dist/action-sheet/index.js +++ b/dist/action-sheet/index.js @@ -1,7 +1,7 @@ import { VantComponent } from '../common/component'; -import { iphonex } from '../mixins/iphonex'; +import { safeArea } from '../mixins/safe-area'; VantComponent({ - mixins: [iphonex], + mixins: [safeArea()], props: { show: Boolean, title: String, diff --git a/dist/button/index.js b/dist/button/index.js index 001cdf73..0fb37987 100644 --- a/dist/button/index.js +++ b/dist/button/index.js @@ -10,6 +10,7 @@ VantComponent({ round: Boolean, square: Boolean, loading: Boolean, + hairline: Boolean, disabled: Boolean, loadingText: String, type: { diff --git a/dist/button/index.wxml b/dist/button/index.wxml index 3d56d448..0b0763ad 100644 --- a/dist/button/index.wxml +++ b/dist/button/index.wxml @@ -2,7 +2,7 @@ + + + + {{ cancelText }} + + diff --git a/lib/action-sheet/index.wxss b/lib/action-sheet/index.wxss new file mode 100644 index 00000000..a3087b1b --- /dev/null +++ b/lib/action-sheet/index.wxss @@ -0,0 +1 @@ +@import '../common/index.wxss';.van-action-sheet{max-height:90%!important;color:#333}.van-action-sheet__cancel,.van-action-sheet__item{height:50px;font-size:16px;line-height:50px;text-align:center;background-color:#fff}.van-action-sheet__cancel--hover,.van-action-sheet__item--hover{background-color:#f2f3f5}.van-action-sheet__cancel{height:60px}.van-action-sheet__cancel:before{display:block;height:10px;background-color:#f8f8f8;content:" "}.van-action-sheet__item--disabled{color:#c9c9c9}.van-action-sheet__item--disabled.van-action-sheet__item--hover{background-color:#fff}.van-action-sheet__subname{margin-left:5px;font-size:12px;color:#7d7e80}.van-action-sheet__header{font-size:16px;font-weight:500;line-height:44px;text-align:center}.van-action-sheet__close{position:absolute!important;top:0;right:0;padding:0 15px;font-size:18px!important;line-height:inherit!important;color:#999} \ No newline at end of file diff --git a/lib/area/index.js b/lib/area/index.js new file mode 100644 index 00000000..65403818 --- /dev/null +++ b/lib/area/index.js @@ -0,0 +1,176 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var component_1 = require("../common/component"); +component_1.VantComponent({ + classes: ['active-class', 'toolbar-class', 'column-class'], + props: { + title: String, + value: String, + loading: Boolean, + cancelButtonText: String, + confirmButtonText: String, + itemHeight: { + type: Number, + value: 44 + }, + visibleItemCount: { + type: Number, + value: 5 + }, + columnsNum: { + type: [String, Number], + value: 3 + }, + areaList: { + type: Object, + value: {} + } + }, + data: { + columns: [{ values: [] }, { values: [] }, { values: [] }], + displayColumns: [{ values: [] }, { values: [] }, { values: [] }] + }, + watch: { + value: function (value) { + this.code = value; + this.setValues(); + }, + areaList: 'setValues', + columnsNum: function (value) { + this.set({ + displayColumns: this.data.columns.slice(0, +value) + }); + } + }, + methods: { + getPicker: function () { + if (this.picker == null) { + this.picker = this.selectComponent('.van-area__picker'); + } + return this.picker; + }, + onCancel: function (event) { + this.emit('cancel', event.detail); + }, + onConfirm: function (event) { + this.emit('confirm', event.detail); + }, + emit: function (type, detail) { + detail.values = detail.value; + delete detail.value; + this.$emit(type, detail); + }, + onChange: function (event) { + var _this = this; + var _a = event.detail, index = _a.index, picker = _a.picker, value = _a.value; + this.code = value[index].code; + this.setValues().then(function () { + _this.$emit('change', { + picker: picker, + values: picker.getValues(), + index: index + }); + }); + }, + getConfig: function (type) { + var areaList = this.data.areaList; + return (areaList && areaList[type + "_list"]) || {}; + }, + getList: function (type, code) { + var result = []; + if (type !== 'province' && !code) { + return result; + } + var list = this.getConfig(type); + result = Object.keys(list).map(function (code) { return ({ + code: code, + name: list[code] + }); }); + if (code) { + // oversea code + if (code[0] === '9' && type === 'city') { + code = '9'; + } + result = result.filter(function (item) { return item.code.indexOf(code) === 0; }); + } + return result; + }, + getIndex: function (type, code) { + var compareNum = type === 'province' ? 2 : type === 'city' ? 4 : 6; + var list = this.getList(type, code.slice(0, compareNum - 2)); + // oversea code + if (code[0] === '9' && type === 'province') { + compareNum = 1; + } + code = code.slice(0, compareNum); + for (var i = 0; i < list.length; i++) { + if (list[i].code.slice(0, compareNum) === code) { + return i; + } + } + return 0; + }, + setValues: function () { + var _this = this; + var county = this.getConfig('county'); + var code = this.code || Object.keys(county)[0] || ''; + var province = this.getList('province'); + var city = this.getList('city', code.slice(0, 2)); + var picker = this.getPicker(); + if (!picker) { + return; + } + var stack = []; + stack.push(picker.setColumnValues(0, province, false)); + stack.push(picker.setColumnValues(1, city, false)); + if (city.length && code.slice(2, 4) === '00') { + ; + code = city[0].code; + } + stack.push(picker.setColumnValues(2, this.getList('county', code.slice(0, 4)), false)); + return Promise.all(stack) + .catch(function () { }) + .then(function () { + return picker.setIndexes([ + _this.getIndex('province', code), + _this.getIndex('city', code), + _this.getIndex('county', code) + ]); + }) + .catch(function () { }); + }, + getValues: function () { + var picker = this.getPicker(); + return picker ? picker.getValues().filter(function (value) { return !!value; }) : []; + }, + getDetail: function () { + var values = this.getValues(); + var area = { + code: '', + country: '', + province: '', + city: '', + county: '' + }; + if (!values.length) { + return area; + } + var names = values.map(function (item) { return item.name; }); + area.code = values[values.length - 1].code; + if (area.code[0] === '9') { + area.country = names[1] || ''; + area.province = names[2] || ''; + } + else { + area.province = names[0] || ''; + area.city = names[1] || ''; + area.county = names[2] || ''; + } + return area; + }, + reset: function () { + this.code = ''; + return this.setValues(); + } + } +}); diff --git a/lib/area/index.json b/lib/area/index.json new file mode 100644 index 00000000..a778e91c --- /dev/null +++ b/lib/area/index.json @@ -0,0 +1,6 @@ +{ + "component": true, + "usingComponents": { + "van-picker": "../picker/index" + } +} diff --git a/lib/area/index.wxml b/lib/area/index.wxml new file mode 100644 index 00000000..60757941 --- /dev/null +++ b/lib/area/index.wxml @@ -0,0 +1,18 @@ + diff --git a/lib/area/index.wxss b/lib/area/index.wxss new file mode 100644 index 00000000..99694d60 --- /dev/null +++ b/lib/area/index.wxss @@ -0,0 +1 @@ +@import '../common/index.wxss'; \ No newline at end of file diff --git a/lib/badge-group/index.js b/lib/badge-group/index.js new file mode 100644 index 00000000..dce7a51a --- /dev/null +++ b/lib/badge-group/index.js @@ -0,0 +1,51 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var component_1 = require("../common/component"); +var utils_1 = require("../common/utils"); +component_1.VantComponent({ + relation: { + name: 'badge', + type: 'descendant', + linked: function (target) { + this.badges.push(target); + this.setActive(); + }, + unlinked: function (target) { + this.badges = this.badges.filter(function (item) { return item !== target; }); + this.setActive(); + } + }, + props: { + active: { + type: Number, + value: 0 + } + }, + watch: { + active: 'setActive' + }, + beforeCreate: function () { + this.badges = []; + this.currentActive = -1; + }, + methods: { + setActive: function (badge) { + var active = this.data.active; + var badges = this.badges; + if (badge && !utils_1.isNumber(badge)) { + active = badges.indexOf(badge); + } + if (active === this.currentActive) { + return; + } + if (this.currentActive !== -1 && badges[this.currentActive]) { + this.$emit('change', active); + badges[this.currentActive].setActive(false); + } + if (badges[active]) { + badges[active].setActive(true); + this.currentActive = active; + } + } + } +}); diff --git a/lib/badge-group/index.json b/lib/badge-group/index.json new file mode 100644 index 00000000..467ce294 --- /dev/null +++ b/lib/badge-group/index.json @@ -0,0 +1,3 @@ +{ + "component": true +} diff --git a/lib/badge-group/index.wxml b/lib/badge-group/index.wxml new file mode 100644 index 00000000..04a0c8f3 --- /dev/null +++ b/lib/badge-group/index.wxml @@ -0,0 +1,3 @@ + + + diff --git a/lib/badge-group/index.wxss b/lib/badge-group/index.wxss new file mode 100644 index 00000000..5149eabf --- /dev/null +++ b/lib/badge-group/index.wxss @@ -0,0 +1 @@ +@import '../common/index.wxss';.van-badge-group{width:85px} \ No newline at end of file diff --git a/lib/badge/index.js b/lib/badge/index.js new file mode 100644 index 00000000..37cb16c6 --- /dev/null +++ b/lib/badge/index.js @@ -0,0 +1,24 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var component_1 = require("../common/component"); +component_1.VantComponent({ + relation: { + type: 'ancestor', + name: 'badge-group' + }, + props: { + info: null, + title: String + }, + methods: { + onClick: function () { + var group = this.getRelationNodes('../badge-group/index')[0]; + if (group) { + group.setActive(this); + } + }, + setActive: function (active) { + this.set({ active: active }); + } + } +}); diff --git a/lib/badge/index.json b/lib/badge/index.json new file mode 100644 index 00000000..bf0ebe00 --- /dev/null +++ b/lib/badge/index.json @@ -0,0 +1,6 @@ +{ + "component": true, + "usingComponents": { + "van-info": "../info/index" + } +} diff --git a/lib/badge/index.wxml b/lib/badge/index.wxml new file mode 100644 index 00000000..3563bdbf --- /dev/null +++ b/lib/badge/index.wxml @@ -0,0 +1,17 @@ + + + + + + {{ title }} + + diff --git a/lib/badge/index.wxss b/lib/badge/index.wxss new file mode 100644 index 00000000..73cb2c1e --- /dev/null +++ b/lib/badge/index.wxss @@ -0,0 +1 @@ +@import '../common/index.wxss';.van-badge{display:block;padding:20px 12px 20px 9px;overflow:hidden;font-size:14px;line-height:1.4;color:#7d7e80;word-break:break-all;background-color:#f8f8f8;border-left:3px solid transparent;box-sizing:border-box;-webkit-user-select:none;user-select:none}.van-badge--hover{background-color:#f2f3f5}.van-badge:after{border-bottom-width:1px}.van-badge--active{font-weight:700;color:#333;border-color:#f44}.van-badge--active:after{border-right-width:1px}.van-badge--active,.van-badge--active.van-badge--hover{background-color:#fff}.van-badge__text{position:relative} \ No newline at end of file diff --git a/lib/button/index.js b/lib/button/index.js new file mode 100644 index 00000000..59c454a1 --- /dev/null +++ b/lib/button/index.js @@ -0,0 +1,38 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var component_1 = require("../common/component"); +var button_1 = require("../mixins/button"); +var open_type_1 = require("../mixins/open-type"); +component_1.VantComponent({ + mixins: [button_1.button, open_type_1.openType], + classes: ['hover-class', 'loading-class'], + props: { + plain: Boolean, + block: Boolean, + round: Boolean, + square: Boolean, + loading: Boolean, + hairline: Boolean, + disabled: Boolean, + loadingText: String, + type: { + type: String, + value: 'default' + }, + size: { + type: String, + value: 'normal' + }, + loadingSize: { + type: String, + value: '20px' + } + }, + methods: { + onClick: function () { + if (!this.data.disabled && !this.data.loading) { + this.$emit('click'); + } + } + } +}); diff --git a/lib/button/index.json b/lib/button/index.json new file mode 100644 index 00000000..cae21702 --- /dev/null +++ b/lib/button/index.json @@ -0,0 +1,6 @@ +{ + "component": true, + "usingComponents": { + "van-loading": "../loading/index" + } +} \ No newline at end of file diff --git a/lib/button/index.wxml b/lib/button/index.wxml new file mode 100644 index 00000000..0b0763ad --- /dev/null +++ b/lib/button/index.wxml @@ -0,0 +1,39 @@ + + + diff --git a/lib/button/index.wxss b/lib/button/index.wxss new file mode 100644 index 00000000..e6da32d8 --- /dev/null +++ b/lib/button/index.wxss @@ -0,0 +1 @@ +@import '../common/index.wxss';.van-button{position:relative;display:inline-block;height:44px;padding:0;font-size:16px;line-height:42px;text-align:center;vertical-align:middle;box-sizing:border-box;border-radius:2px;-webkit-appearance:none;-webkit-text-size-adjust:100%}.van-button:before{position:absolute;top:50%;left:50%;width:100%;height:100%;background-color:#000;border:inherit;border-color:#000;border-radius:inherit;content:" ";opacity:0;-webkit-transform:translate(-50%,-50%);transform:translate(-50%,-50%)}.van-button:after{border-width:0}.van-button--active:before{opacity:.15}.van-button--unclickable:after{display:none}.van-button--default{color:#333;background-color:#fff;border:1px solid #eee}.van-button--primary{color:#fff;background-color:#07c160;border:1px solid #07c160}.van-button--info{color:#fff;background-color:#1989fa;border:1px solid #1989fa}.van-button--danger{color:#fff;background-color:#f44;border:1px solid #f44}.van-button--warning{color:#fff;background-color:#ff976a;border:1px solid #ff976a}.van-button--plain{background-color:#fff}.van-button--plain.van-button--primary{color:#07c160}.van-button--plain.van-button--info{color:#1989fa}.van-button--plain.van-button--danger{color:#f44}.van-button--plain.van-button--warning{color:#ff976a}.van-button--large{width:100%;height:50px;line-height:48px}.van-button--normal{padding:0 15px;font-size:14px}.van-button--small{height:30px;min-width:60px;padding:0 8px;font-size:12px;line-height:28px}.van-button--mini{display:inline-block;width:50px;height:22px;font-size:10px;line-height:20px}.van-button--mini+.van-button--mini{margin-left:5px}.van-button--block{display:block;width:100%}.van-button--round{border-radius:10em}.van-button--square{border-radius:0}.van-button--disabled{opacity:.5}.van-button__loading-text{margin-left:5px;display:inline-block;vertical-align:middle}.van-button--hairline{border-width:0;padding-top:1px}.van-button--hairline:after{border-width:1px;border-color:inherit;border-radius:4px}.van-button--hairline.van-button--round:after{border-radius:10em}.van-button--hairline.van-button--square:after{border-radius:0} \ No newline at end of file diff --git a/lib/card/index.js b/lib/card/index.js new file mode 100644 index 00000000..47a7d832 --- /dev/null +++ b/lib/card/index.js @@ -0,0 +1,40 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var link_1 = require("../mixins/link"); +var component_1 = require("../common/component"); +component_1.VantComponent({ + classes: [ + 'num-class', + 'desc-class', + 'thumb-class', + 'title-class', + 'price-class', + 'origin-price-class', + ], + mixins: [link_1.link], + props: { + tag: String, + num: String, + desc: String, + thumb: String, + title: String, + price: String, + centered: Boolean, + lazyLoad: Boolean, + thumbLink: String, + originPrice: String, + thumbMode: { + type: String, + value: 'aspectFit' + }, + currency: { + type: String, + value: '¥' + } + }, + methods: { + onClickThumb: function () { + this.jumpLink('thumbLink'); + } + } +}); diff --git a/lib/card/index.json b/lib/card/index.json new file mode 100644 index 00000000..e9174076 --- /dev/null +++ b/lib/card/index.json @@ -0,0 +1,6 @@ +{ + "component": true, + "usingComponents": { + "van-tag": "../tag/index" + } +} diff --git a/lib/card/index.wxml b/lib/card/index.wxml new file mode 100644 index 00000000..46d9d813 --- /dev/null +++ b/lib/card/index.wxml @@ -0,0 +1,44 @@ + + + + + + + + + {{ tag }} + + + + + {{ title }} + + + {{ desc }} + + + + + + {{ currency }} {{ price }} + {{ currency }} {{ originPrice }} + x {{ num }} + + + + + + + + diff --git a/lib/card/index.wxss b/lib/card/index.wxss new file mode 100644 index 00000000..6a749258 --- /dev/null +++ b/lib/card/index.wxss @@ -0,0 +1 @@ +@import '../common/index.wxss';.van-card{position:relative;padding:5px 15px;font-size:12px;color:#333;background-color:#fafafa;box-sizing:border-box}.van-card__header{display:-webkit-flex;display:flex}.van-card__header--center{-webkit-align-items:center;align-items:center;-webkit-justify-content:center;justify-content:center}.van-card__thumb{position:relative;width:90px;height:90px;margin-right:10px;-webkit-flex:none;flex:none}.van-card__thumb:empty{display:none}.van-card__img{width:100%;height:100%}.van-card__content{position:relative;min-width:0;-webkit-flex:1;flex:1}.van-card__desc,.van-card__title{word-break:break-all}.van-card__title{font-weight:700;line-height:16px}.van-card__desc{color:#7d7e80}.van-card__bottom,.van-card__desc{line-height:20px}.van-card__price{display:inline-block;font-weight:700;color:#f44}.van-card__origin-price{display:inline-block;margin-left:5px;font-size:10px;color:#7d7e80;text-decoration:line-through}.van-card__num{float:right}.van-card__tag{position:absolute;top:2px;left:0}.van-card__footer{width:100%;text-align:right;-webkit-flex:none;flex:none} \ No newline at end of file diff --git a/lib/cell-group/index.js b/lib/cell-group/index.js new file mode 100644 index 00000000..c81ce4bb --- /dev/null +++ b/lib/cell-group/index.js @@ -0,0 +1,12 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var component_1 = require("../common/component"); +component_1.VantComponent({ + props: { + title: String, + border: { + type: Boolean, + value: true + } + } +}); diff --git a/lib/cell-group/index.json b/lib/cell-group/index.json new file mode 100644 index 00000000..32640e0d --- /dev/null +++ b/lib/cell-group/index.json @@ -0,0 +1,3 @@ +{ + "component": true +} \ No newline at end of file diff --git a/lib/cell-group/index.wxml b/lib/cell-group/index.wxml new file mode 100644 index 00000000..6e0b471d --- /dev/null +++ b/lib/cell-group/index.wxml @@ -0,0 +1,9 @@ + + {{ title }} + + + + diff --git a/lib/cell-group/index.wxss b/lib/cell-group/index.wxss new file mode 100644 index 00000000..e0fc603d --- /dev/null +++ b/lib/cell-group/index.wxss @@ -0,0 +1 @@ +@import '../common/index.wxss';.van-cell-group__title{font-size:14px;padding:15px 15px 5px;color:#999;line-height:16px} \ No newline at end of file diff --git a/lib/cell/index.js b/lib/cell/index.js new file mode 100644 index 00000000..5a62f45b --- /dev/null +++ b/lib/cell/index.js @@ -0,0 +1,38 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var link_1 = require("../mixins/link"); +var component_1 = require("../common/component"); +component_1.VantComponent({ + classes: [ + 'title-class', + 'label-class', + 'value-class', + 'right-icon-class', + 'hover-class' + ], + mixins: [link_1.link], + props: { + title: null, + value: null, + icon: String, + size: String, + label: String, + center: Boolean, + isLink: Boolean, + required: Boolean, + clickable: Boolean, + titleWidth: String, + customStyle: String, + arrowDirection: String, + border: { + type: Boolean, + value: true + } + }, + methods: { + onClick: function (event) { + this.$emit('click', event.detail); + this.jumpLink(); + } + } +}); diff --git a/lib/cell/index.json b/lib/cell/index.json new file mode 100644 index 00000000..a9ab393a --- /dev/null +++ b/lib/cell/index.json @@ -0,0 +1,6 @@ +{ + "component": true, + "usingComponents": { + "van-icon": "../icon/index" + } +} \ No newline at end of file diff --git a/lib/cell/index.wxml b/lib/cell/index.wxml new file mode 100644 index 00000000..44f643d8 --- /dev/null +++ b/lib/cell/index.wxml @@ -0,0 +1,43 @@ + + + + + + + + + {{ title }} + {{ label }} + + + + + + {{ value }} + + + + + + + + diff --git a/lib/cell/index.wxss b/lib/cell/index.wxss new file mode 100644 index 00000000..a476af17 --- /dev/null +++ b/lib/cell/index.wxss @@ -0,0 +1 @@ +@import '../common/index.wxss';.van-cell{position:relative;display:-webkit-flex;display:flex;width:100%;padding:10px 15px;font-size:14px;line-height:24px;color:#333;background-color:#fff;box-sizing:border-box}.van-cell:after{content:" ";position:absolute;pointer-events:none;box-sizing:border-box;-webkit-transform-origin:center;transform-origin:center;top:auto;left:15px;right:0;bottom:0;-webkit-transform:scaleY(.5);transform:scaleY(.5);border-bottom:1px solid #eee}.van-cell--borderless:after{display:none}.van-cell-group{background-color:#fff}.van-cell__label{margin-top:3px;font-size:12px;line-height:18px;color:#999}.van-cell__value{overflow:hidden;color:#999;text-align:right;vertical-align:middle}.van-cell__title,.van-cell__value{-webkit-flex:1;flex:1}.van-cell__title:empty,.van-cell__value:empty{display:none}.van-cell__left-icon-wrap,.van-cell__right-icon-wrap{display:-webkit-flex;display:flex;height:24px;font-size:16px;-webkit-align-items:center;align-items:center}.van-cell__left-icon-wrap{margin-right:5px}.van-cell__right-icon-wrap{margin-left:5px;color:#999}.van-cell__left-icon{line-height:24px;vertical-align:middle}.van-cell__right-icon{line-height:24px}.van-cell--clickable.van-cell--hover{background-color:#f2f3f5}.van-cell--required{overflow:visible}.van-cell--required:before{position:absolute;left:7px;font-size:14px;color:#f44;content:"*"}.van-cell--center{-webkit-align-items:center;align-items:center}.van-cell--large{padding-top:12px;padding-bottom:12px}.van-cell--large .van-cell__title{font-size:16px}.van-cell--large .van-cell__label{font-size:14px} \ No newline at end of file diff --git a/lib/checkbox-group/index.js b/lib/checkbox-group/index.js new file mode 100644 index 00000000..4882bec1 --- /dev/null +++ b/lib/checkbox-group/index.js @@ -0,0 +1,36 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var component_1 = require("../common/component"); +component_1.VantComponent({ + field: true, + relation: { + name: 'checkbox', + type: 'descendant', + linked: function (target) { + var _a = this.data, value = _a.value, disabled = _a.disabled; + target.set({ + value: value.indexOf(target.data.name) !== -1, + disabled: disabled || target.data.disabled + }); + } + }, + props: { + max: Number, + value: Array, + disabled: Boolean + }, + watch: { + value: function (value) { + var children = this.getRelationNodes('../checkbox/index'); + children.forEach(function (child) { + child.set({ value: value.indexOf(child.data.name) !== -1 }); + }); + }, + disabled: function (disabled) { + var children = this.getRelationNodes('../checkbox/index'); + children.forEach(function (child) { + child.set({ disabled: disabled || child.data.disabled }); + }); + } + } +}); diff --git a/lib/checkbox-group/index.json b/lib/checkbox-group/index.json new file mode 100644 index 00000000..0a336c08 --- /dev/null +++ b/lib/checkbox-group/index.json @@ -0,0 +1,6 @@ +{ + "component": true, + "usingComponents": { + "van-icon": "../icon/index" + } +} diff --git a/lib/checkbox-group/index.wxml b/lib/checkbox-group/index.wxml new file mode 100644 index 00000000..4fa864ce --- /dev/null +++ b/lib/checkbox-group/index.wxml @@ -0,0 +1 @@ + diff --git a/lib/checkbox-group/index.wxss b/lib/checkbox-group/index.wxss new file mode 100644 index 00000000..99694d60 --- /dev/null +++ b/lib/checkbox-group/index.wxss @@ -0,0 +1 @@ +@import '../common/index.wxss'; \ No newline at end of file diff --git a/lib/checkbox/index.js b/lib/checkbox/index.js new file mode 100644 index 00000000..6e4b4bea --- /dev/null +++ b/lib/checkbox/index.js @@ -0,0 +1,69 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var component_1 = require("../common/component"); +component_1.VantComponent({ + field: true, + relation: { + name: 'checkbox-group', + type: 'ancestor' + }, + classes: ['icon-class', 'label-class'], + props: { + value: null, + disabled: Boolean, + useIconSlot: Boolean, + checkedColor: String, + labelPosition: String, + labelDisabled: Boolean, + shape: { + type: String, + value: 'round' + } + }, + methods: { + emitChange: function (value) { + var parent = this.getRelationNodes('../checkbox-group/index')[0]; + if (parent) { + this.setParentValue(parent, value); + } + else { + this.$emit('input', value); + this.$emit('change', value); + } + }, + toggle: function () { + if (!this.data.disabled) { + this.emitChange(!this.data.value); + } + }, + onClickLabel: function () { + if (!this.data.disabled && !this.data.labelDisabled) { + this.emitChange(!this.data.value); + } + }, + setParentValue: function (parent, value) { + var parentValue = parent.data.value.slice(); + var name = this.data.name; + if (value) { + if (parent.data.max && parentValue.length >= parent.data.max) { + return; + } + /* istanbul ignore else */ + if (parentValue.indexOf(name) === -1) { + parentValue.push(name); + parent.$emit('input', parentValue); + parent.$emit('change', parentValue); + } + } + else { + var index = parentValue.indexOf(name); + /* istanbul ignore else */ + if (index !== -1) { + parentValue.splice(index, 1); + parent.$emit('input', parentValue); + parent.$emit('change', parentValue); + } + } + } + } +}); diff --git a/lib/checkbox/index.json b/lib/checkbox/index.json new file mode 100644 index 00000000..0a336c08 --- /dev/null +++ b/lib/checkbox/index.json @@ -0,0 +1,6 @@ +{ + "component": true, + "usingComponents": { + "van-icon": "../icon/index" + } +} diff --git a/lib/checkbox/index.wxml b/lib/checkbox/index.wxml new file mode 100644 index 00000000..1659ba43 --- /dev/null +++ b/lib/checkbox/index.wxml @@ -0,0 +1,18 @@ + + + + + + + + + + + diff --git a/lib/checkbox/index.wxss b/lib/checkbox/index.wxss new file mode 100644 index 00000000..9ead73ea --- /dev/null +++ b/lib/checkbox/index.wxss @@ -0,0 +1 @@ +@import '../common/index.wxss';.van-checkbox{overflow:hidden;-webkit-user-select:none;user-select:none}.van-checkbox__icon-wrap,.van-checkbox__label{display:inline-block;line-height:20px;vertical-align:middle}.van-checkbox__icon{display:block;font-size:14px;width:20px;height:20px;color:transparent;text-align:center;box-sizing:border-box;border:1px solid #e5e5e5;transition:.2s}.van-checkbox__icon--round{border-radius:100%}.van-checkbox__icon--checked{color:#fff;border-color:#1989fa;background-color:#1989fa}.van-checkbox__icon--disabled{border-color:#c9c9c9;background-color:#eee}.van-checkbox__icon--disabled.van-checkbox__icon--checked{color:#c9c9c9}.van-checkbox__label{color:#333;margin-left:10px}.van-checkbox__label--left{float:left;margin:0 10px 0 0}.van-checkbox__label--disabled{color:#c9c9c9}.van-checkbox__label:empty{margin:0} \ No newline at end of file diff --git a/lib/col/index.js b/lib/col/index.js new file mode 100644 index 00000000..1f6beedb --- /dev/null +++ b/lib/col/index.js @@ -0,0 +1,25 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var component_1 = require("../common/component"); +component_1.VantComponent({ + relation: { + name: 'row', + type: 'ancestor' + }, + props: { + span: Number, + offset: Number + }, + data: { + style: '' + }, + methods: { + setGutter: function (gutter) { + var padding = gutter / 2 + "px"; + var style = gutter ? "padding-left: " + padding + "; padding-right: " + padding + ";" : ''; + if (style !== this.data.style) { + this.set({ style: style }); + } + } + } +}); diff --git a/lib/col/index.json b/lib/col/index.json new file mode 100644 index 00000000..467ce294 --- /dev/null +++ b/lib/col/index.json @@ -0,0 +1,3 @@ +{ + "component": true +} diff --git a/lib/col/index.wxml b/lib/col/index.wxml new file mode 100644 index 00000000..a759aac5 --- /dev/null +++ b/lib/col/index.wxml @@ -0,0 +1,8 @@ + + + + + diff --git a/lib/col/index.wxss b/lib/col/index.wxss new file mode 100644 index 00000000..44c896a3 --- /dev/null +++ b/lib/col/index.wxss @@ -0,0 +1 @@ +@import '../common/index.wxss';.van-col{float:left;box-sizing:border-box}.van-col--1{width:4.16666667%}.van-col--offset-1{margin-left:4.16666667%}.van-col--2{width:8.33333333%}.van-col--offset-2{margin-left:8.33333333%}.van-col--3{width:12.5%}.van-col--offset-3{margin-left:12.5%}.van-col--4{width:16.66666667%}.van-col--offset-4{margin-left:16.66666667%}.van-col--5{width:20.83333333%}.van-col--offset-5{margin-left:20.83333333%}.van-col--6{width:25%}.van-col--offset-6{margin-left:25%}.van-col--7{width:29.16666667%}.van-col--offset-7{margin-left:29.16666667%}.van-col--8{width:33.33333333%}.van-col--offset-8{margin-left:33.33333333%}.van-col--9{width:37.5%}.van-col--offset-9{margin-left:37.5%}.van-col--10{width:41.66666667%}.van-col--offset-10{margin-left:41.66666667%}.van-col--11{width:45.83333333%}.van-col--offset-11{margin-left:45.83333333%}.van-col--12{width:50%}.van-col--offset-12{margin-left:50%}.van-col--13{width:54.16666667%}.van-col--offset-13{margin-left:54.16666667%}.van-col--14{width:58.33333333%}.van-col--offset-14{margin-left:58.33333333%}.van-col--15{width:62.5%}.van-col--offset-15{margin-left:62.5%}.van-col--16{width:66.66666667%}.van-col--offset-16{margin-left:66.66666667%}.van-col--17{width:70.83333333%}.van-col--offset-17{margin-left:70.83333333%}.van-col--18{width:75%}.van-col--offset-18{margin-left:75%}.van-col--19{width:79.16666667%}.van-col--offset-19{margin-left:79.16666667%}.van-col--20{width:83.33333333%}.van-col--offset-20{margin-left:83.33333333%}.van-col--21{width:87.5%}.van-col--offset-21{margin-left:87.5%}.van-col--22{width:91.66666667%}.van-col--offset-22{margin-left:91.66666667%}.van-col--23{width:95.83333333%}.van-col--offset-23{margin-left:95.83333333%}.van-col--24{width:100%}.van-col--offset-24{margin-left:100%} \ No newline at end of file diff --git a/lib/collapse-item/index.js b/lib/collapse-item/index.js new file mode 100644 index 00000000..3d200cca --- /dev/null +++ b/lib/collapse-item/index.js @@ -0,0 +1,94 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var component_1 = require("../common/component"); +component_1.VantComponent({ + classes: ['title-class', 'content-class'], + relation: { + name: 'collapse', + type: 'ancestor', + linked: function (parent) { + this.parent = parent; + } + }, + props: { + name: null, + title: null, + value: null, + icon: String, + label: String, + disabled: Boolean, + border: { + type: Boolean, + value: true + }, + isLink: { + type: Boolean, + value: true + } + }, + data: { + contentHeight: 0, + expanded: false + }, + beforeCreate: function () { + this.animation = wx.createAnimation({ + duration: 300, + timingFunction: 'ease-in-out' + }); + }, + methods: { + updateExpanded: function () { + if (!this.parent) { + return null; + } + var _a = this.parent.data, value = _a.value, accordion = _a.accordion, items = _a.items; + var name = this.data.name; + var index = items.indexOf(this); + var currentName = name == null ? index : name; + var expanded = accordion + ? value === currentName + : value.some(function (name) { return name === currentName; }); + if (expanded !== this.data.expanded) { + this.updateStyle(expanded); + } + this.set({ index: index, expanded: expanded }); + }, + updateStyle: function (expanded) { + var _this = this; + this.getRect('.van-collapse-item__content').then(function (res) { + var animationData = _this.animation + .height(expanded ? res.height : 0) + .step() + .export(); + if (expanded) { + _this.set({ animationData: animationData }); + } + else { + _this.set({ + contentHeight: res.height + 'px' + }, function () { + setTimeout(function () { + _this.set({ animationData: animationData }); + }, 20); + }); + } + }); + }, + onClick: function () { + if (this.data.disabled) { + return; + } + var _a = this.data, name = _a.name, expanded = _a.expanded; + var index = this.parent.data.items.indexOf(this); + var currentName = name == null ? index : name; + this.parent.switch(currentName, !expanded); + }, + onTransitionEnd: function () { + if (this.data.expanded) { + this.set({ + contentHeight: 'auto' + }); + } + } + } +}); diff --git a/lib/collapse-item/index.json b/lib/collapse-item/index.json new file mode 100644 index 00000000..0e5425cd --- /dev/null +++ b/lib/collapse-item/index.json @@ -0,0 +1,6 @@ +{ + "component": true, + "usingComponents": { + "van-cell": "../cell/index" + } +} diff --git a/lib/collapse-item/index.wxml b/lib/collapse-item/index.wxml new file mode 100644 index 00000000..b39e4cea --- /dev/null +++ b/lib/collapse-item/index.wxml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + diff --git a/lib/collapse-item/index.wxss b/lib/collapse-item/index.wxss new file mode 100644 index 00000000..34f032ad --- /dev/null +++ b/lib/collapse-item/index.wxss @@ -0,0 +1 @@ +@import '../common/index.wxss';.van-collapse-item__title .van-cell__right-icon{-webkit-transform:rotate(90deg);transform:rotate(90deg);transition:.3s}.van-collapse-item__title--expanded .van-cell__right-icon{-webkit-transform:rotate(-90deg);transform:rotate(-90deg)}.van-collapse-item__title--disabled .van-cell,.van-collapse-item__title--disabled .van-cell__right-icon{color:#c9c9c9!important}.van-collapse-item__title--disabled .van-cell--hover{background-color:#fff!important}.van-collapse-item__wrapper{overflow:hidden}.van-collapse-item__content{padding:15px;font-size:13px;line-height:1.5;color:#999;background-color:#fff} \ No newline at end of file diff --git a/lib/collapse/index.js b/lib/collapse/index.js new file mode 100644 index 00000000..6ddc0090 --- /dev/null +++ b/lib/collapse/index.js @@ -0,0 +1,54 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var component_1 = require("../common/component"); +component_1.VantComponent({ + relation: { + name: 'collapse-item', + type: 'descendant', + linked: function (child) { + this.set({ + items: this.data.items.concat([child]) + }, function () { + child.updateExpanded(); + }); + } + }, + props: { + value: null, + accordion: Boolean, + border: { + type: Boolean, + value: true + } + }, + data: { + items: [] + }, + watch: { + value: function () { + this.data.items.forEach(function (child) { + child.updateExpanded(); + }); + }, + accordion: function () { + this.data.items.forEach(function (child) { + child.updateExpanded(); + }); + } + }, + methods: { + switch: function (name, expanded) { + var _a = this.data, accordion = _a.accordion, value = _a.value; + if (!accordion) { + name = expanded + ? value.concat(name) + : value.filter(function (activeName) { return activeName !== name; }); + } + else { + name = expanded ? name : ''; + } + this.$emit('change', name); + this.$emit('input', name); + } + } +}); diff --git a/lib/collapse/index.json b/lib/collapse/index.json new file mode 100644 index 00000000..467ce294 --- /dev/null +++ b/lib/collapse/index.json @@ -0,0 +1,3 @@ +{ + "component": true +} diff --git a/lib/collapse/index.wxml b/lib/collapse/index.wxml new file mode 100644 index 00000000..fd4e1719 --- /dev/null +++ b/lib/collapse/index.wxml @@ -0,0 +1,3 @@ + + + diff --git a/lib/collapse/index.wxss b/lib/collapse/index.wxss new file mode 100644 index 00000000..99694d60 --- /dev/null +++ b/lib/collapse/index.wxss @@ -0,0 +1 @@ +@import '../common/index.wxss'; \ No newline at end of file diff --git a/lib/common/color.js b/lib/common/color.js new file mode 100644 index 00000000..be4c57b5 --- /dev/null +++ b/lib/common/color.js @@ -0,0 +1,5 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.RED = '#f44'; +exports.BLUE = '#1989fa'; +exports.GREEN = '#07c160'; diff --git a/lib/common/component.js b/lib/common/component.js new file mode 100644 index 00000000..1444a8c2 --- /dev/null +++ b/lib/common/component.js @@ -0,0 +1,52 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var basic_1 = require("../mixins/basic"); +var index_1 = require("../mixins/observer/index"); +function mapKeys(source, target, map) { + Object.keys(map).forEach(function (key) { + if (source[key]) { + target[map[key]] = source[key]; + } + }); +} +function VantComponent(vantOptions) { + if (vantOptions === void 0) { vantOptions = {}; } + var _a; + var options = {}; + mapKeys(vantOptions, options, { + data: 'data', + props: 'properties', + mixins: 'behaviors', + methods: 'methods', + beforeCreate: 'created', + created: 'attached', + mounted: 'ready', + relations: 'relations', + destroyed: 'detached', + classes: 'externalClasses' + }); + var relation = vantOptions.relation; + if (relation) { + options.relations = Object.assign(options.relations || {}, (_a = {}, + _a["../" + relation.name + "/index"] = relation, + _a)); + } + // add default externalClasses + options.externalClasses = options.externalClasses || []; + options.externalClasses.push('custom-class'); + // add default behaviors + options.behaviors = options.behaviors || []; + options.behaviors.push(basic_1.basic); + // map field to form-field behavior + if (vantOptions.field) { + options.behaviors.push('wx://form-field'); + } + // add default options + options.options = { + multipleSlots: true, + addGlobalClass: true + }; + index_1.observe(vantOptions, options); + Component(options); +} +exports.VantComponent = VantComponent; diff --git a/lib/common/index.wxss b/lib/common/index.wxss new file mode 100644 index 00000000..1b5b4ee2 --- /dev/null +++ b/lib/common/index.wxss @@ -0,0 +1 @@ +.van-ellipsis{overflow:hidden;white-space:nowrap;text-overflow:ellipsis}.van-multi-ellipsis--l2{-webkit-line-clamp:2}.van-multi-ellipsis--l2,.van-multi-ellipsis--l3{overflow:hidden;text-overflow:ellipsis;display:-webkit-box;-webkit-box-orient:vertical}.van-multi-ellipsis--l3{-webkit-line-clamp:3}.van-clearfix:after{content:"";display:table;clear:both}.van-hairline,.van-hairline--bottom,.van-hairline--left,.van-hairline--right,.van-hairline--surround,.van-hairline--top,.van-hairline--top-bottom{position:relative}.van-hairline--bottom:after,.van-hairline--left:after,.van-hairline--right:after,.van-hairline--surround:after,.van-hairline--top-bottom:after,.van-hairline--top:after,.van-hairline:after{content:" ";position:absolute;pointer-events:none;box-sizing:border-box;-webkit-transform-origin:center;transform-origin:center;top:-50%;left:-50%;right:-50%;bottom:-50%;-webkit-transform:scale(.5);transform:scale(.5);border:0 solid #eee}.van-hairline--top:after{border-top-width:1px}.van-hairline--left:after{border-left-width:1px}.van-hairline--right:after{border-right-width:1px}.van-hairline--bottom:after{border-bottom-width:1px}.van-hairline--top-bottom:after{border-width:1px 0}.van-hairline--surround:after{border-width:1px} \ No newline at end of file diff --git a/lib/common/style/clearfix.wxss b/lib/common/style/clearfix.wxss new file mode 100644 index 00000000..8d6328c2 --- /dev/null +++ b/lib/common/style/clearfix.wxss @@ -0,0 +1 @@ +.van-clearfix:after{content:"";display:table;clear:both} \ No newline at end of file diff --git a/lib/common/style/ellipsis.wxss b/lib/common/style/ellipsis.wxss new file mode 100644 index 00000000..a829a98f --- /dev/null +++ b/lib/common/style/ellipsis.wxss @@ -0,0 +1 @@ +.van-ellipsis{overflow:hidden;white-space:nowrap;text-overflow:ellipsis}.van-multi-ellipsis--l2{-webkit-line-clamp:2}.van-multi-ellipsis--l2,.van-multi-ellipsis--l3{overflow:hidden;text-overflow:ellipsis;display:-webkit-box;-webkit-box-orient:vertical}.van-multi-ellipsis--l3{-webkit-line-clamp:3} \ No newline at end of file diff --git a/lib/common/style/hairline.wxss b/lib/common/style/hairline.wxss new file mode 100644 index 00000000..53508ad9 --- /dev/null +++ b/lib/common/style/hairline.wxss @@ -0,0 +1 @@ +.van-hairline,.van-hairline--bottom,.van-hairline--left,.van-hairline--right,.van-hairline--surround,.van-hairline--top,.van-hairline--top-bottom{position:relative}.van-hairline--bottom:after,.van-hairline--left:after,.van-hairline--right:after,.van-hairline--surround:after,.van-hairline--top-bottom:after,.van-hairline--top:after,.van-hairline:after{content:" ";position:absolute;pointer-events:none;box-sizing:border-box;-webkit-transform-origin:center;transform-origin:center;top:-50%;left:-50%;right:-50%;bottom:-50%;-webkit-transform:scale(.5);transform:scale(.5);border:0 solid #eee}.van-hairline--top:after{border-top-width:1px}.van-hairline--left:after{border-left-width:1px}.van-hairline--right:after{border-right-width:1px}.van-hairline--bottom:after{border-bottom-width:1px}.van-hairline--top-bottom:after{border-width:1px 0}.van-hairline--surround:after{border-width:1px} \ No newline at end of file diff --git a/lib/common/style/mixins/clearfix.wxss b/lib/common/style/mixins/clearfix.wxss new file mode 100644 index 00000000..e69de29b diff --git a/lib/common/style/mixins/ellipsis.wxss b/lib/common/style/mixins/ellipsis.wxss new file mode 100644 index 00000000..e69de29b diff --git a/lib/common/style/mixins/hairline.wxss b/lib/common/style/mixins/hairline.wxss new file mode 100644 index 00000000..e69de29b diff --git a/lib/common/style/var.wxss b/lib/common/style/var.wxss new file mode 100644 index 00000000..e69de29b diff --git a/lib/common/utils.js b/lib/common/utils.js new file mode 100644 index 00000000..503a9826 --- /dev/null +++ b/lib/common/utils.js @@ -0,0 +1,19 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +function isDef(value) { + return value !== undefined && value !== null; +} +exports.isDef = isDef; +function isObj(x) { + var type = typeof x; + return x !== null && (type === 'object' || type === 'function'); +} +exports.isObj = isObj; +function isNumber(value) { + return /^\d+$/.test(value); +} +exports.isNumber = isNumber; +function range(num, min, max) { + return Math.min(Math.max(num, min), max); +} +exports.range = range; diff --git a/lib/datetime-picker/index.js b/lib/datetime-picker/index.js new file mode 100644 index 00000000..8fd2858e --- /dev/null +++ b/lib/datetime-picker/index.js @@ -0,0 +1,309 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var component_1 = require("../common/component"); +var utils_1 = require("../common/utils"); +var currentYear = new Date().getFullYear(); +function isValidDate(date) { + return utils_1.isDef(date) && !isNaN(new Date(date).getTime()); +} +function range(num, min, max) { + return Math.min(Math.max(num, min), max); +} +function padZero(val) { + return ("00" + val).slice(-2); +} +function times(n, iteratee) { + var index = -1; + var result = Array(n); + while (++index < n) { + result[index] = iteratee(index); + } + return result; +} +function getTrueValue(formattedValue) { + if (!formattedValue) + return; + while (isNaN(parseInt(formattedValue, 10))) { + formattedValue = formattedValue.slice(1); + } + return parseInt(formattedValue, 10); +} +function getMonthEndDay(year, month) { + return 32 - new Date(year, month - 1, 32).getDate(); +} +component_1.VantComponent({ + props: { + value: null, + title: String, + loading: Boolean, + itemHeight: { + type: Number, + value: 44 + }, + visibleItemCount: { + type: Number, + value: 5 + }, + confirmButtonText: { + type: String, + value: '确认' + }, + cancelButtonText: { + type: String, + value: '取消' + }, + type: { + type: String, + value: 'datetime' + }, + showToolbar: { + type: Boolean, + value: true + }, + minDate: { + type: Number, + value: new Date(currentYear - 10, 0, 1).getTime() + }, + maxDate: { + type: Number, + value: new Date(currentYear + 10, 11, 31).getTime() + }, + minHour: { + type: Number, + value: 0 + }, + maxHour: { + type: Number, + value: 23 + }, + minMinute: { + type: Number, + value: 0 + }, + maxMinute: { + type: Number, + value: 59 + } + }, + data: { + innerValue: Date.now(), + columns: [] + }, + watch: { + value: function (val) { + var _this = this; + var data = this.data; + val = this.correctValue(val); + var isEqual = val === data.innerValue; + if (!isEqual) { + this.updateColumnValue(val).then(function () { + _this.$emit('input', val); + }); + } + }, + type: 'updateColumns', + minHour: 'updateColumns', + maxHour: 'updateColumns', + minMinute: 'updateColumns', + maxMinute: 'updateColumns' + }, + methods: { + getPicker: function () { + if (this.picker == null) { + var picker_1 = this.picker = this.selectComponent('.van-datetime-picker'); + var setColumnValues_1 = picker_1.setColumnValues; + picker_1.setColumnValues = function () { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + return setColumnValues_1.apply(picker_1, args.concat([false])); + }; + } + return this.picker; + }, + updateColumns: function () { + var results = this.getRanges().map(function (_a, index) { + var type = _a.type, range = _a.range; + var values = times(range[1] - range[0] + 1, function (index) { + var value = range[0] + index; + value = type === 'year' ? "" + value : padZero(value); + return value; + }); + return { values: values }; + }); + return this.set({ columns: results }); + }, + getRanges: function () { + var data = this.data; + if (data.type === 'time') { + return [ + { + type: 'hour', + range: [data.minHour, data.maxHour] + }, + { + type: 'minute', + range: [data.minMinute, data.maxMinute] + } + ]; + } + var _a = this.getBoundary('max', data.innerValue), maxYear = _a.maxYear, maxDate = _a.maxDate, maxMonth = _a.maxMonth, maxHour = _a.maxHour, maxMinute = _a.maxMinute; + var _b = this.getBoundary('min', data.innerValue), minYear = _b.minYear, minDate = _b.minDate, minMonth = _b.minMonth, minHour = _b.minHour, minMinute = _b.minMinute; + var result = [ + { + type: 'year', + range: [minYear, maxYear] + }, + { + type: 'month', + range: [minMonth, maxMonth] + }, + { + type: 'day', + range: [minDate, maxDate] + }, + { + type: 'hour', + range: [minHour, maxHour] + }, + { + type: 'minute', + range: [minMinute, maxMinute] + } + ]; + if (data.type === 'date') + result.splice(3, 2); + if (data.type === 'year-month') + result.splice(2, 3); + return result; + }, + correctValue: function (value) { + var data = this.data; + // validate value + var isDateType = data.type !== 'time'; + if (isDateType && !isValidDate(value)) { + value = data.minDate; + } + else if (!isDateType && !value) { + var minHour = data.minHour; + value = padZero(minHour) + ":00"; + } + // time type + if (!isDateType) { + var _a = value.split(':'), hour = _a[0], minute = _a[1]; + hour = padZero(range(hour, data.minHour, data.maxHour)); + minute = padZero(range(minute, data.minMinute, data.maxMinute)); + return hour + ":" + minute; + } + // date type + value = Math.max(value, data.minDate); + value = Math.min(value, data.maxDate); + return value; + }, + getBoundary: function (type, innerValue) { + var _a; + var value = new Date(innerValue); + var boundary = new Date(this.data[type + "Date"]); + var year = boundary.getFullYear(); + var month = 1; + var date = 1; + var hour = 0; + var minute = 0; + if (type === 'max') { + month = 12; + date = getMonthEndDay(value.getFullYear(), value.getMonth() + 1); + hour = 23; + minute = 59; + } + if (value.getFullYear() === year) { + month = boundary.getMonth() + 1; + if (value.getMonth() + 1 === month) { + date = boundary.getDate(); + if (value.getDate() === date) { + hour = boundary.getHours(); + if (value.getHours() === hour) { + minute = boundary.getMinutes(); + } + } + } + } + return _a = {}, + _a[type + "Year"] = year, + _a[type + "Month"] = month, + _a[type + "Date"] = date, + _a[type + "Hour"] = hour, + _a[type + "Minute"] = minute, + _a; + }, + onCancel: function () { + this.$emit('cancel'); + }, + onConfirm: function () { + this.$emit('confirm', this.data.innerValue); + }, + onChange: function () { + var _this = this; + var data = this.data; + var value; + var picker = this.getPicker(); + if (data.type === 'time') { + var indexes = picker.getIndexes(); + value = indexes[0] + data.minHour + ":" + (indexes[1] + data.minMinute); + } + else { + var values = picker.getValues(); + var year = getTrueValue(values[0]); + var month = getTrueValue(values[1]); + var maxDate = getMonthEndDay(year, month); + var date = getTrueValue(values[2]); + if (data.type === 'year-month') { + date = 1; + } + date = date > maxDate ? maxDate : date; + var hour = 0; + var minute = 0; + if (data.type === 'datetime') { + hour = getTrueValue(values[3]); + minute = getTrueValue(values[4]); + } + value = new Date(year, month - 1, date, hour, minute); + } + value = this.correctValue(value); + this.updateColumnValue(value).then(function () { + _this.$emit('input', value); + _this.$emit('change', picker); + }); + }, + updateColumnValue: function (value) { + var _this = this; + var values = []; + var data = this.data; + var picker = this.getPicker(); + if (data.type === 'time') { + var pair = value.split(':'); + values = [pair[0], pair[1]]; + } + else { + var date = new Date(value); + values = ["" + date.getFullYear(), padZero(date.getMonth() + 1)]; + if (data.type === 'date') { + values.push(padZero(date.getDate())); + } + if (data.type === 'datetime') { + values.push(padZero(date.getDate()), padZero(date.getHours()), padZero(date.getMinutes())); + } + } + return this.set({ innerValue: value }) + .then(function () { return _this.updateColumns(); }) + .then(function () { return picker.setValues(values); }); + } + }, + created: function () { + var _this = this; + var innerValue = this.correctValue(this.data.value); + this.updateColumnValue(innerValue).then(function () { + _this.$emit('input', innerValue); + }); + } +}); diff --git a/lib/datetime-picker/index.json b/lib/datetime-picker/index.json new file mode 100644 index 00000000..a778e91c --- /dev/null +++ b/lib/datetime-picker/index.json @@ -0,0 +1,6 @@ +{ + "component": true, + "usingComponents": { + "van-picker": "../picker/index" + } +} diff --git a/lib/datetime-picker/index.wxml b/lib/datetime-picker/index.wxml new file mode 100644 index 00000000..13a1b478 --- /dev/null +++ b/lib/datetime-picker/index.wxml @@ -0,0 +1,13 @@ + diff --git a/lib/datetime-picker/index.wxss b/lib/datetime-picker/index.wxss new file mode 100644 index 00000000..99694d60 --- /dev/null +++ b/lib/datetime-picker/index.wxss @@ -0,0 +1 @@ +@import '../common/index.wxss'; \ No newline at end of file diff --git a/lib/dialog/dialog.js b/lib/dialog/dialog.js new file mode 100644 index 00000000..501ed0a1 --- /dev/null +++ b/lib/dialog/dialog.js @@ -0,0 +1,73 @@ +"use strict"; +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var queue = []; +function getContext() { + var pages = getCurrentPages(); + return pages[pages.length - 1]; +} +var Dialog = function (options) { + options = __assign({}, Dialog.currentOptions, options); + return new Promise(function (resolve, reject) { + var context = options.context || getContext(); + var dialog = context.selectComponent(options.selector); + delete options.selector; + if (dialog) { + dialog.set(__assign({ onCancel: reject, onConfirm: resolve }, options)); + queue.push(dialog); + } + else { + console.warn('未找到 van-dialog 节点,请确认 selector 及 context 是否正确'); + } + }); +}; +Dialog.defaultOptions = { + show: true, + title: '', + message: '', + zIndex: 100, + overlay: true, + asyncClose: false, + messageAlign: '', + transition: 'scale', + selector: '#van-dialog', + confirmButtonText: '确认', + cancelButtonText: '取消', + showConfirmButton: true, + showCancelButton: false, + closeOnClickOverlay: false, + confirmButtonOpenType: '' +}; +Dialog.alert = Dialog; +Dialog.confirm = function (options) { + return Dialog(__assign({ showCancelButton: true }, options)); +}; +Dialog.close = function () { + queue.forEach(function (dialog) { + dialog.close(); + }); + queue = []; +}; +Dialog.stopLoading = function () { + queue.forEach(function (dialog) { + dialog.stopLoading(); + }); +}; +Dialog.setDefaultOptions = function (options) { + Object.assign(Dialog.currentOptions, options); +}; +Dialog.resetDefaultOptions = function () { + Dialog.currentOptions = __assign({}, Dialog.defaultOptions); +}; +Dialog.resetDefaultOptions(); +exports.default = Dialog; diff --git a/lib/dialog/index.js b/lib/dialog/index.js new file mode 100644 index 00000000..e1926466 --- /dev/null +++ b/lib/dialog/index.js @@ -0,0 +1,99 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var component_1 = require("../common/component"); +var button_1 = require("../mixins/button"); +var open_type_1 = require("../mixins/open-type"); +component_1.VantComponent({ + mixins: [button_1.button, open_type_1.openType], + props: { + show: Boolean, + title: String, + message: String, + useSlot: Boolean, + asyncClose: Boolean, + messageAlign: String, + showCancelButton: Boolean, + closeOnClickOverlay: Boolean, + confirmButtonOpenType: String, + zIndex: { + type: Number, + value: 2000 + }, + confirmButtonText: { + type: String, + value: '确认' + }, + cancelButtonText: { + type: String, + value: '取消' + }, + showConfirmButton: { + type: Boolean, + value: true + }, + overlay: { + type: Boolean, + value: true + }, + transition: { + type: String, + value: 'scale' + } + }, + data: { + loading: { + confirm: false, + cancel: false + } + }, + watch: { + show: function (show) { + !show && this.stopLoading(); + } + }, + methods: { + onConfirm: function () { + this.handleAction('confirm'); + }, + onCancel: function () { + this.handleAction('cancel'); + }, + onClickOverlay: function () { + this.onClose('overlay'); + }, + handleAction: function (action) { + var _a; + if (this.data.asyncClose) { + this.set((_a = {}, + _a["loading." + action] = true, + _a)); + } + this.onClose(action); + }, + close: function () { + this.set({ + show: false + }); + }, + stopLoading: function () { + this.set({ + loading: { + confirm: false, + cancel: false + } + }); + }, + onClose: function (action) { + if (!this.data.asyncClose) { + this.close(); + } + this.$emit('close', action); + //把 dialog 实例传递出去,可以通过 stopLoading() 在外部关闭按钮的 loading + this.$emit(action, { dialog: this }); + var callback = this.data[action === 'confirm' ? 'onConfirm' : 'onCancel']; + if (callback) { + callback(this); + } + } + } +}); diff --git a/lib/dialog/index.json b/lib/dialog/index.json new file mode 100644 index 00000000..e2ee09ae --- /dev/null +++ b/lib/dialog/index.json @@ -0,0 +1,7 @@ +{ + "component": true, + "usingComponents": { + "van-popup": "../popup/index", + "van-button": "../button/index" + } +} diff --git a/lib/dialog/index.wxml b/lib/dialog/index.wxml new file mode 100644 index 00000000..c1d38990 --- /dev/null +++ b/lib/dialog/index.wxml @@ -0,0 +1,64 @@ + + + {{ title }} + + + + + {{ message }} + + + + + {{ cancelButtonText }} + + + {{ confirmButtonText }} + + + diff --git a/lib/dialog/index.wxss b/lib/dialog/index.wxss new file mode 100644 index 00000000..eea753a8 --- /dev/null +++ b/lib/dialog/index.wxss @@ -0,0 +1 @@ +@import '../common/index.wxss';.van-dialog{width:85%;overflow:hidden;font-size:16px;background-color:#fff;border-radius:4px}.van-dialog__header{padding-top:25px;font-weight:500;text-align:center}.van-dialog__header--isolated{padding:25px 0}.van-dialog__message{max-height:60vh;padding:25px;overflow-y:auto;font-size:14px;line-height:1.5;text-align:center;-webkit-overflow-scrolling:touch}.van-dialog__message--has-title{padding-top:12px;color:#7d7e80}.van-dialog__message--left{text-align:left}.van-dialog__message--right{text-align:right}.van-dialog__footer{display:-webkit-flex;display:flex}.van-dialog__button{-webkit-flex:1;flex:1}.van-dialog__cancel,.van-dialog__confirm{border:0!important}.van-dialog__confirm{color:#1989fa!important}.van-dialog-bounce-enter{opacity:0;-webkit-transform:translate3d(-50%,-50%,0) scale(.7);transform:translate3d(-50%,-50%,0) scale(.7)}.van-dialog-bounce-leave-active{opacity:0;-webkit-transform:translate3d(-50%,-50%,0) scale(.9);transform:translate3d(-50%,-50%,0) scale(.9)} \ No newline at end of file diff --git a/lib/field/index.js b/lib/field/index.js new file mode 100644 index 00000000..1c439e40 --- /dev/null +++ b/lib/field/index.js @@ -0,0 +1,135 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var component_1 = require("../common/component"); +component_1.VantComponent({ + field: true, + classes: ['input-class'], + props: { + size: String, + icon: String, + label: String, + error: Boolean, + fixed: Boolean, + focus: Boolean, + center: Boolean, + isLink: Boolean, + leftIcon: String, + disabled: Boolean, + autosize: Boolean, + readonly: Boolean, + required: Boolean, + iconClass: String, + clearable: Boolean, + inputAlign: String, + customClass: String, + confirmType: String, + confirmHold: Boolean, + errorMessage: String, + placeholder: String, + customStyle: String, + useIconSlot: Boolean, + useButtonSlot: Boolean, + showConfirmBar: { + type: Boolean, + value: true + }, + placeholderStyle: String, + adjustPosition: { + type: Boolean, + value: true + }, + cursorSpacing: { + type: Number, + value: 50 + }, + maxlength: { + type: Number, + value: -1 + }, + type: { + type: String, + value: 'text' + }, + border: { + type: Boolean, + value: true + }, + titleWidth: { + type: String, + value: '90px' + } + }, + data: { + showClear: false + }, + beforeCreate: function () { + this.focused = false; + }, + methods: { + onInput: function (event) { + var _this = this; + var _a = (event.detail || {}).value, value = _a === void 0 ? '' : _a; + this.set({ + value: value, + showClear: this.getShowClear(value) + }, function () { + _this.emitChange(value); + }); + }, + onFocus: function (event) { + var _a = event.detail || {}, _b = _a.value, value = _b === void 0 ? '' : _b, _c = _a.height, height = _c === void 0 ? 0 : _c; + this.$emit('focus', { value: value, height: height }); + this.focused = true; + this.blurFromClear = false; + this.set({ + showClear: this.getShowClear() + }); + }, + onBlur: function (event) { + var _this = this; + var _a = event.detail || {}, _b = _a.value, value = _b === void 0 ? '' : _b, _c = _a.cursor, cursor = _c === void 0 ? 0 : _c; + this.$emit('blur', { value: value, cursor: cursor }); + this.focused = false; + var showClear = this.getShowClear(); + if (this.data.value === value) { + this.set({ + showClear: showClear + }); + } + else if (!this.blurFromClear) { + // fix: the handwritten keyboard does not trigger input change + this.set({ + value: value, + showClear: showClear + }, function () { + _this.emitChange(value); + }); + } + }, + onClickIcon: function () { + this.$emit('click-icon'); + }, + getShowClear: function (value) { + value = value === undefined ? this.data.value : value; + return (this.data.clearable && this.focused && value && !this.data.readonly); + }, + onClear: function () { + var _this = this; + this.blurFromClear = true; + this.set({ + value: '', + showClear: this.getShowClear('') + }, function () { + _this.emitChange(''); + _this.$emit('clear', ''); + }); + }, + onConfirm: function () { + this.$emit('confirm', this.data.value); + }, + emitChange: function (value) { + this.$emit('input', value); + this.$emit('change', value); + } + } +}); diff --git a/lib/field/index.json b/lib/field/index.json new file mode 100644 index 00000000..8809c46b --- /dev/null +++ b/lib/field/index.json @@ -0,0 +1,7 @@ +{ + "component": true, + "usingComponents": { + "van-cell": "../cell/index", + "van-icon": "../icon/index" + } +} \ No newline at end of file diff --git a/lib/field/index.wxml b/lib/field/index.wxml new file mode 100644 index 00000000..baa5f4df --- /dev/null +++ b/lib/field/index.wxml @@ -0,0 +1,82 @@ + + + + + + +