build: compile 1.6.4

This commit is contained in:
zhongnan 2020-12-18 15:29:19 +08:00
parent 76f58a12f6
commit 7d2fa01574
79 changed files with 557 additions and 536 deletions

23
dist/button/index.js vendored
View File

@ -45,28 +45,7 @@ VantComponent({
type: String, type: String,
value: '20px', value: '20px',
}, },
color: { color: String,
type: String,
observer(color) {
let style = '';
if (color) {
style += `color: ${this.data.plain ? color : 'white'};`;
if (!this.data.plain) {
// Use background instead of backgroundColor to make linear-gradient work
style += `background: ${color};`;
}
// hide border when color is linear-gradient
if (color.indexOf('gradient') !== -1) {
style += 'border: 0;';
} else {
style += `border-color: ${color};`;
}
}
if (style !== this.data.baseStyle) {
this.setData({ baseStyle: style });
}
},
},
}, },
methods: { methods: {
onClick() { onClick() {

View File

@ -1,4 +1,5 @@
<wxs src="../wxs/utils.wxs" module="utils" /> <wxs src="../wxs/utils.wxs" module="utils" />
<wxs src="./index.wxs" module="computed" />
<button <button
id="{{ id }}" id="{{ id }}"
@ -7,7 +8,7 @@
hover-class="van-button--active hover-class" hover-class="van-button--active hover-class"
lang="{{ lang }}" lang="{{ lang }}"
form-type="{{ formType }}" form-type="{{ formType }}"
style="{{ baseStyle }} {{ customStyle }}" style="{{ computed.rootStyle({ plain, color }) }} {{ customStyle }}"
open-type="{{ disabled ? '' : openType }}" open-type="{{ disabled ? '' : openType }}"
business-id="{{ businessId }}" business-id="{{ businessId }}"
session-from="{{ sessionFrom }}" session-from="{{ sessionFrom }}"
@ -30,7 +31,7 @@
custom-class="loading-class" custom-class="loading-class"
size="{{ loadingSize }}" size="{{ loadingSize }}"
type="{{ loadingType }}" type="{{ loadingType }}"
color="{{ loadingColor(type,color,plain) }}" color="{{ computed.loadingColor({ type, color, plain }) }}"
/> />
<view wx:if="{{ loadingText }}" class="van-button__loading-text"> <view wx:if="{{ loadingText }}" class="van-button__loading-text">
{{ loadingText }} {{ loadingText }}
@ -50,19 +51,3 @@
</view> </view>
</block> </block>
</button> </button>
<wxs module="loadingColor">
function get(type, color,plain) {
if(plain) {
return color ? color: '#c9c9c9';
}
if(type === 'default') {
return '#c9c9c9';
}
return 'white';
}
module.exports = get;
</wxs>

39
dist/button/index.wxs vendored Normal file
View File

@ -0,0 +1,39 @@
/* eslint-disable */
var style = require('../wxs/style.wxs');
function rootStyle(data) {
if (!data.color) {
return '';
}
var properties = {
color: data.plain ? data.color : '#fff',
background: data.plain ? null : data.color,
};
// hide border when color is linear-gradient
if (data.color.indexOf('gradient') !== -1) {
properties.border = 0;
} else {
properties['border-color'] = data.color;
}
return style(properties);
}
function loadingColor(data) {
if (data.plain) {
return data.color ? data.color : '#c9c9c9';
}
if (data.type === 'default') {
return '#c9c9c9';
}
return '#fff';
}
module.exports = {
rootStyle: rootStyle,
loadingColor: loadingColor,
};

View File

@ -1,20 +1,20 @@
/* eslint-disable */ /* eslint-disable */
var utils = require('../wxs/utils.wxs'); var style = require('../wxs/style.wxs');
var addUnit = require('../wxs/add-unit.wxs');
function iconStyle(checkedColor, value, disabled, parentDisabled, iconSize) { function iconStyle(checkedColor, value, disabled, parentDisabled, iconSize) {
var styles = [['font-size', utils.addUnit(iconSize)]]; var styles = {
'font-size': addUnit(iconSize),
};
if (checkedColor && value && !disabled && !parentDisabled) { if (checkedColor && value && !disabled && !parentDisabled) {
styles.push(['border-color', checkedColor]); styles['border-color'] = checkedColor;
styles.push(['background-color', checkedColor]); styles['background-color'] = checkedColor;
} }
return styles return style(styles);
.map(function(item) {
return item.join(':');
})
.join(';');
} }
module.exports = { module.exports = {
iconStyle: iconStyle iconStyle: iconStyle,
}; };

View File

@ -1,7 +1,8 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { isObj } from '../common/utils';
import { BLUE, WHITE } from '../common/color'; import { BLUE, WHITE } from '../common/color';
import { adaptor } from './canvas'; import { adaptor } from './canvas';
import { isObj } from '../common/validator';
import { getSystemInfoSync } from '../common/utils';
function format(rate) { function format(rate) {
return Math.min(Math.max(rate, 0), 100); return Math.min(Math.max(rate, 0), 100);
} }
@ -68,7 +69,7 @@ VantComponent({
const ctx = wx.createCanvasContext('van-circle', this); const ctx = wx.createCanvasContext('van-circle', this);
return Promise.resolve(ctx); return Promise.resolve(ctx);
} }
const dpr = wx.getSystemInfoSync().pixelRatio; const dpr = getSystemInfoSync().pixelRatio;
return new Promise((resolve) => { return new Promise((resolve) => {
wx.createSelectorQuery() wx.createSelectorQuery()
.in(this) .in(this)

View File

@ -60,8 +60,7 @@ function useAnimation(context, expanded, mounted, height) {
}); });
} }
export function setContentAnimate(context, expanded, mounted) { export function setContentAnimate(context, expanded, mounted) {
getRect getRect(context, '.van-collapse-item__content')
.call(context, '.van-collapse-item__content')
.then((rect) => rect.height) .then((rect) => rect.height)
.then((height) => { .then((height) => {
canIUseAnimate() canIUseAnimate()

View File

@ -1,22 +1,24 @@
/// <reference types="miniprogram-api-typings" /> /// <reference types="miniprogram-api-typings" />
export declare function isDef(value: any): boolean;
export declare function isObj(x: any): boolean;
export declare function range(num: number, min: number, max: number): number; export declare function range(num: number, min: number, max: number): number;
export declare function nextTick(fn: Function): void; export declare function nextTick(cb: (...args: any[]) => void): void;
export declare function getSystemInfoSync(): WechatMiniprogram.GetSystemInfoSyncResult; export declare function getSystemInfoSync(): WechatMiniprogram.GetSystemInfoSyncResult;
export declare function addUnit(value?: string | number): string | undefined; export declare function addUnit(value?: string | number): string | undefined;
export declare function requestAnimationFrame( export declare function requestAnimationFrame(
cb: Function cb: () => void
): void | WechatMiniprogram.NodesRef; ): number | WechatMiniprogram.NodesRef;
export declare function pickExclude(obj: unknown, keys: string[]): {}; export declare function pickExclude(obj: unknown, keys: string[]): {};
export declare function getRect( export declare function getRect(
this: WechatMiniprogram.Component.TrivialInstance, context: WechatMiniprogram.Component.TrivialInstance,
selector: string selector: string
): Promise<WechatMiniprogram.BoundingClientRectCallbackResult>; ): Promise<WechatMiniprogram.BoundingClientRectCallbackResult>;
export declare function getAllRect( export declare function getAllRect(
this: WechatMiniprogram.Component.TrivialInstance, context: WechatMiniprogram.Component.TrivialInstance,
selector: string selector: string
): Promise<WechatMiniprogram.BoundingClientRectCallbackResult[]>; ): Promise<WechatMiniprogram.BoundingClientRectCallbackResult[]>;
export declare function groupSetData(
context: WechatMiniprogram.Component.TrivialInstance,
cb: () => void
): void;
export declare function toPromise( export declare function toPromise(
promiseLike: Promise<unknown> | unknown promiseLike: Promise<unknown> | unknown
): Promise<unknown>; ): Promise<unknown>;

41
dist/common/utils.js vendored
View File

@ -1,18 +1,16 @@
import { isNumber, isPlainObject, isPromise } from './validator'; import { isDef, isNumber, isPlainObject, isPromise } from './validator';
export function isDef(value) { import { canIUseGroupSetData, canIUseNextTick } from './version';
return value !== undefined && value !== null;
}
export function isObj(x) {
const type = typeof x;
return x !== null && (type === 'object' || type === 'function');
}
export function range(num, min, max) { export function range(num, min, max) {
return Math.min(Math.max(num, min), max); return Math.min(Math.max(num, min), max);
} }
export function nextTick(fn) { export function nextTick(cb) {
setTimeout(() => { if (canIUseNextTick()) {
fn(); wx.nextTick(cb);
}, 1000 / 30); } else {
setTimeout(() => {
cb();
}, 1000 / 30);
}
} }
let systemInfo; let systemInfo;
export function getSystemInfoSync() { export function getSystemInfoSync() {
@ -31,7 +29,9 @@ export function addUnit(value) {
export function requestAnimationFrame(cb) { export function requestAnimationFrame(cb) {
const systemInfo = getSystemInfoSync(); const systemInfo = getSystemInfoSync();
if (systemInfo.platform === 'devtools') { if (systemInfo.platform === 'devtools') {
return nextTick(cb); return setTimeout(() => {
cb();
}, 1000 / 30);
} }
return wx return wx
.createSelectorQuery() .createSelectorQuery()
@ -52,24 +52,31 @@ export function pickExclude(obj, keys) {
return prev; return prev;
}, {}); }, {});
} }
export function getRect(selector) { export function getRect(context, selector) {
return new Promise((resolve) => { return new Promise((resolve) => {
wx.createSelectorQuery() wx.createSelectorQuery()
.in(this) .in(context)
.select(selector) .select(selector)
.boundingClientRect() .boundingClientRect()
.exec((rect = []) => resolve(rect[0])); .exec((rect = []) => resolve(rect[0]));
}); });
} }
export function getAllRect(selector) { export function getAllRect(context, selector) {
return new Promise((resolve) => { return new Promise((resolve) => {
wx.createSelectorQuery() wx.createSelectorQuery()
.in(this) .in(context)
.selectAll(selector) .selectAll(selector)
.boundingClientRect() .boundingClientRect()
.exec((rect = []) => resolve(rect[0])); .exec((rect = []) => resolve(rect[0]));
}); });
} }
export function groupSetData(context, cb) {
if (canIUseGroupSetData()) {
context.groupSetData(cb);
} else {
cb();
}
}
export function toPromise(promiseLike) { export function toPromise(promiseLike) {
if (isPromise(promiseLike)) { if (isPromise(promiseLike)) {
return promiseLike; return promiseLike;

View File

@ -3,7 +3,7 @@ export declare function isPlainObject(
val: unknown val: unknown
): val is Record<string, unknown>; ): val is Record<string, unknown>;
export declare function isPromise<T = unknown>(val: unknown): val is Promise<T>; export declare function isPromise<T = unknown>(val: unknown): val is Promise<T>;
export declare function isDef(value: any): boolean; export declare function isDef(value: unknown): boolean;
export declare function isObj(x: unknown): x is Record<string, unknown>; export declare function isObj(x: unknown): x is Record<string, unknown>;
export declare function isNumber(value: string): boolean; export declare function isNumber(value: string): boolean;
export declare function isBoolean(value: unknown): value is boolean; export declare function isBoolean(value: unknown): value is boolean;

View File

@ -1,3 +1,5 @@
export declare function canIUseModel(): boolean; export declare function canIUseModel(): boolean;
export declare function canIUseFormFieldButton(): boolean; export declare function canIUseFormFieldButton(): boolean;
export declare function canIUseAnimate(): boolean; export declare function canIUseAnimate(): boolean;
export declare function canIUseGroupSetData(): boolean;
export declare function canIUseNextTick(): boolean;

View File

@ -33,3 +33,10 @@ export function canIUseAnimate() {
const system = getSystemInfoSync(); const system = getSystemInfoSync();
return compareVersion(system.SDKVersion, '2.9.0') >= 0; return compareVersion(system.SDKVersion, '2.9.0') >= 0;
} }
export function canIUseGroupSetData() {
const system = getSystemInfoSync();
return compareVersion(system.SDKVersion, '2.4.0') >= 0;
}
export function canIUseNextTick() {
return wx.canIUse('nextTick');
}

View File

@ -1,5 +1,5 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { isDef } from '../common/utils'; import { isDef } from '../common/validator';
import { pickerProps } from '../picker/shared'; import { pickerProps } from '../picker/shared';
const currentYear = new Date().getFullYear(); const currentYear = new Date().getFullYear();
function isValidDate(date) { function isValidDate(date) {

View File

@ -1,5 +1,5 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { addUnit, getRect } from '../common/utils'; import { addUnit, getRect, getSystemInfoSync } from '../common/utils';
let ARRAY = []; let ARRAY = [];
VantComponent({ VantComponent({
field: true, field: true,
@ -52,7 +52,7 @@ VantComponent({
itemListData: [], itemListData: [],
}, },
beforeCreate() { beforeCreate() {
const { windowHeight } = wx.getSystemInfoSync(); const { windowHeight } = getSystemInfoSync();
this.windowHeight = windowHeight; this.windowHeight = windowHeight;
ARRAY.push(this); ARRAY.push(this);
}, },
@ -87,7 +87,7 @@ VantComponent({
}, },
getChildWrapperStyle() { getChildWrapperStyle() {
const { zIndex, direction } = this.data; const { zIndex, direction } = this.data;
return getRect.call(this, '.van-dropdown-menu').then((rect) => { return getRect(this, '.van-dropdown-menu').then((rect) => {
const { top = 0, bottom = 0 } = rect; const { top = 0, bottom = 0 } = rect;
const offset = direction === 'down' ? bottom : this.windowHeight - top; const offset = direction === 'down' ? bottom : this.windowHeight - top;
let wrapperStyle = `z-index: ${zIndex};`; let wrapperStyle = `z-index: ${zIndex};`;

View File

@ -1 +1 @@
@import '../common/index.wxss';.van-goods-action{position:fixed;right:0;bottom:0;left:0;display:-webkit-flex;display:flex;-webkit-align-items:center;align-items:center;height:50px;height:var(--goods-action-height,50px);background-color:#fff;background-color:var(--goods-action-background-color,#fff)}.van-goods-action--safe{padding-bottom:env(safe-area-inset-bottom)} @import '../common/index.wxss';.van-goods-action{position:fixed;right:0;bottom:0;left:0;display:-webkit-flex;display:flex;-webkit-align-items:center;align-items:center;box-sizing:initial;height:50px;height:var(--goods-action-height,50px);background-color:#fff;background-color:var(--goods-action-background-color,#fff)}.van-goods-action--safe{padding-bottom:env(safe-area-inset-bottom)}

View File

@ -1,6 +1,5 @@
import { link } from '../mixins/link'; import { link } from '../mixins/link';
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { addUnit } from '../common/utils';
VantComponent({ VantComponent({
relation: { relation: {
name: 'grid', name: 'grid',
@ -40,32 +39,7 @@ VantComponent({
direction, direction,
iconSize, iconSize,
} = data; } = data;
const width = `${100 / columnNum}%`;
const styleWrapper = [];
styleWrapper.push(`width: ${width}`);
if (square) {
styleWrapper.push(`padding-top: ${width}`);
}
if (gutter) {
const gutterValue = addUnit(gutter);
styleWrapper.push(`padding-right: ${gutterValue}`);
const index = children.indexOf(this);
if (index >= columnNum && !square) {
styleWrapper.push(`margin-top: ${gutterValue}`);
}
}
let contentStyle = '';
if (square && gutter) {
const gutterValue = addUnit(gutter);
contentStyle = `
right: ${gutterValue};
bottom: ${gutterValue};
height: auto;
`;
}
this.setData({ this.setData({
viewStyle: styleWrapper.join('; '),
contentStyle,
center, center,
border, border,
square, square,
@ -73,6 +47,8 @@ VantComponent({
clickable, clickable,
direction, direction,
iconSize, iconSize,
index: children.indexOf(this),
columnNum,
}); });
}, },
onClick() { onClick() {

View File

@ -1,9 +1,14 @@
<wxs src="../wxs/utils.wxs" module="utils" /> <wxs src="../wxs/utils.wxs" module="utils" />
<wxs src="./index.wxs" module="computed" />
<view class="custom-class {{ utils.bem('grid-item', { square }) }}" style="{{ viewStyle }}" bindtap="onClick"> <view
class="custom-class {{ utils.bem('grid-item', { square }) }}"
style="{{ computed.wrapperStyle({ square, gutter, columnNum, index }) }}"
bindtap="onClick"
>
<view <view
class="content-class {{ utils.bem('grid-item__content', [direction, { center, square, clickable, surround: border && gutter }]) }} {{ border ? 'van-hairline--surround' : '' }}" class="content-class {{ utils.bem('grid-item__content', [direction, { center, square, clickable, surround: border && gutter }]) }} {{ border ? 'van-hairline--surround' : '' }}"
style="{{ contentStyle }}" style="{{ computed.contentStyle({ square, gutter }) }}"
> >
<block wx:if="{{ useSlot }}"> <block wx:if="{{ useSlot }}">
<slot /> <slot />

32
dist/grid-item/index.wxs vendored Normal file
View File

@ -0,0 +1,32 @@
/* eslint-disable */
var style = require('../wxs/style.wxs');
var addUnit = require('../wxs/add-unit.wxs');
function wrapperStyle(data) {
var width = 100 / data.columnNum + '%';
return style({
width: width,
'padding-top': data.square ? width : null,
'padding-right': addUnit(data.gutter),
'margin-top':
data.index >= data.columnNum && !data.square
? addUnit(data.gutter)
: null,
});
}
function contentStyle(data) {
return data.square
? style({
right: addUnit(data.gutter),
bottom: addUnit(data.gutter),
height: 'auto',
})
: '';
}
module.exports = {
wrapperStyle: wrapperStyle,
contentStyle: contentStyle,
};

12
dist/grid/index.js vendored
View File

@ -1,5 +1,4 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { addUnit } from '../common/utils';
VantComponent({ VantComponent({
relation: { relation: {
name: 'grid-item', name: 'grid-item',
@ -44,17 +43,6 @@ VantComponent({
observer: 'updateChildren', observer: 'updateChildren',
}, },
}, },
data: {
viewStyle: '',
},
created() {
const { gutter } = this.data;
if (gutter) {
this.setData({
viewStyle: `padding-left: ${addUnit(gutter)}`,
});
}
},
methods: { methods: {
updateChildren() { updateChildren() {
this.children.forEach((child) => { this.children.forEach((child) => {

View File

@ -1,3 +1,8 @@
<view class="van-grid custom-class {{ border && !gutter ? 'van-hairline--top' : '' }}" style="{{ viewStyle }}"> <wxs src="./index.wxs" module="computed" />
<view
class="van-grid custom-class {{ border && !gutter ? 'van-hairline--top' : '' }}"
style="{{ computed.rootStyle({ gutter }) }}"
>
<slot /> <slot />
</view> </view>

13
dist/grid/index.wxs vendored Normal file
View File

@ -0,0 +1,13 @@
/* eslint-disable */
var style = require('../wxs/style.wxs');
var addUnit = require('../wxs/add-unit.wxs');
function rootStyle(data) {
return style({
'padding-left': addUnit(data.gutter),
});
}
module.exports = {
rootStyle: rootStyle,
};

View File

@ -1,10 +1,9 @@
<wxs src="../wxs/utils.wxs" module="utils" /> <wxs src="./index.wxs" module="computed" />
<wxs src="./computed.wxs" module="computed" />
<view <view
class="{{ computed.rootClass({ classPrefix, name }) }}" class="{{ computed.rootClass({ classPrefix, name }) }}"
style="{{ computed.rootStyle({ customStyle, color, size }) }}" style="{{ computed.rootStyle({ customStyle, color, size }) }}"
bind:tap="onClick" bindtap="onClick"
> >
<van-info <van-info
wx:if="{{ info !== null || dot }}" wx:if="{{ info !== null || dot }}"

View File

@ -1,5 +1,6 @@
/* eslint-disable */ /* eslint-disable */
var utils = require('../wxs/utils.wxs'); var style = require('../wxs/style.wxs');
var addUnit = require('../wxs/add-unit.wxs');
function isImage(name) { function isImage(name) {
return name.indexOf('/') !== -1; return name.indexOf('/') !== -1;
@ -22,25 +23,13 @@ function rootClass(data) {
} }
function rootStyle(data) { function rootStyle(data) {
var styles = []; return style([
{
if (data.color) { color: data.color,
styles.push(['color', data.color]); 'font-size': addUnit(data.size),
} },
data.customStyle,
if (data.size) { ]);
styles.push(['font-size', utils.addUnit(data.size)]);
}
if (data.customStyle) {
styles.push([data.customStyle]);
}
return styles
.map(function (pair) {
return pair.join(':');
})
.join(';');
} }
module.exports = { module.exports = {

44
dist/image/index.js vendored
View File

@ -1,15 +1,6 @@
import { addUnit, isDef } from '../common/utils';
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { button } from '../mixins/button'; import { button } from '../mixins/button';
import { openType } from '../mixins/open-type'; import { openType } from '../mixins/open-type';
const FIT_MODE_MAP = {
none: 'center',
fill: 'scaleToFill',
cover: 'aspectFill',
contain: 'aspectFit',
widthFix: 'widthFix',
heightFix: 'heightFix',
};
VantComponent({ VantComponent({
mixins: [button, openType], mixins: [button, openType],
classes: ['custom-class', 'loading-class', 'error-class', 'image-class'], classes: ['custom-class', 'loading-class', 'error-class', 'image-class'],
@ -24,14 +15,8 @@ VantComponent({
}, },
}, },
round: Boolean, round: Boolean,
width: { width: null,
type: null, height: null,
observer: 'setStyle',
},
height: {
type: null,
observer: 'setStyle',
},
radius: null, radius: null,
lazyLoad: Boolean, lazyLoad: Boolean,
useErrorSlot: Boolean, useErrorSlot: Boolean,
@ -40,7 +25,6 @@ VantComponent({
fit: { fit: {
type: String, type: String,
value: 'fill', value: 'fill',
observer: 'setMode',
}, },
showError: { showError: {
type: Boolean, type: Boolean,
@ -56,31 +40,7 @@ VantComponent({
loading: true, loading: true,
viewStyle: '', viewStyle: '',
}, },
mounted() {
this.setMode();
this.setStyle();
},
methods: { methods: {
setMode() {
this.setData({
mode: FIT_MODE_MAP[this.data.fit],
});
},
setStyle() {
const { width, height, radius } = this.data;
let style = '';
if (isDef(width)) {
style += `width: ${addUnit(width)};`;
}
if (isDef(height)) {
style += `height: ${addUnit(height)};`;
}
if (isDef(radius)) {
style += 'overflow: hidden;';
style += `border-radius: ${addUnit(radius)};`;
}
this.setData({ viewStyle: style });
},
onLoad(event) { onLoad(event) {
this.setData({ this.setData({
loading: false, loading: false,

View File

@ -1,14 +1,15 @@
<wxs src="../wxs/utils.wxs" module="utils" /> <wxs src="../wxs/utils.wxs" module="utils" />
<wxs src="./index.wxs" module="computed" />
<view <view
style="{{ viewStyle }}" style="{{ computed.rootStyle({ width, height, radius }) }}"
class="custom-class {{ utils.bem('image', { round })}}" class="custom-class {{ utils.bem('image', { round })}}"
bind:tap="onClick" bind:tap="onClick"
> >
<image <image
wx:if="{{ !error }}" wx:if="{{ !error }}"
src="{{ src }}" src="{{ src }}"
mode="{{ mode }}" mode="{{ computed.mode(fit) }}"
lazy-load="{{ lazyLoad }}" lazy-load="{{ lazyLoad }}"
class="image-class van-image__img" class="image-class van-image__img"
show-menu-by-longpress="{{ showMenuByLongpress }}" show-menu-by-longpress="{{ showMenuByLongpress }}"

32
dist/image/index.wxs vendored Normal file
View File

@ -0,0 +1,32 @@
/* eslint-disable */
var style = require('../wxs/style.wxs');
var addUnit = require('../wxs/add-unit.wxs');
function rootStyle(data) {
return style([
{
width: addUnit(data.width),
height: addUnit(data.height),
'border-radius': addUnit(data.radius),
},
data.radius ? 'overflow: hidden' : null,
]);
}
var FIT_MODE_MAP = {
none: 'center',
fill: 'scaleToFill',
cover: 'aspectFill',
contain: 'aspectFit',
widthFix: 'widthFix',
heightFix: 'heightFix',
};
function mode(fit) {
return FIT_MODE_MAP[fit];
}
module.exports = {
rootStyle: rootStyle,
mode: mode,
};

View File

@ -17,7 +17,7 @@ VantComponent({
}, },
methods: { methods: {
scrollIntoView(scrollTop) { scrollIntoView(scrollTop) {
getRect.call(this, '.van-index-anchor-wrapper').then((rect) => { getRect(this, '.van-index-anchor-wrapper').then((rect) => {
wx.pageScrollTo({ wx.pageScrollTo({
duration: 0, duration: 0,
scrollTop: scrollTop + rect.top - this.parent.data.stickyOffsetTop, scrollTop: scrollTop + rect.top - this.parent.data.stickyOffsetTop,

View File

@ -84,7 +84,7 @@ VantComponent({
setAnchorsRect() { setAnchorsRect() {
return Promise.all( return Promise.all(
this.children.map((anchor) => this.children.map((anchor) =>
getRect.call(anchor, '.van-index-anchor-wrapper').then((rect) => { getRect(anchor, '.van-index-anchor-wrapper').then((rect) => {
Object.assign(anchor, { Object.assign(anchor, {
height: rect.height, height: rect.height,
top: rect.top + this.scrollTop, top: rect.top + this.scrollTop,
@ -94,7 +94,7 @@ VantComponent({
); );
}, },
setListRect() { setListRect() {
return getRect.call(this, '.van-index-bar').then((rect) => { return getRect(this, '.van-index-bar').then((rect) => {
Object.assign(this, { Object.assign(this, {
height: rect.height, height: rect.height,
top: rect.top + this.scrollTop, top: rect.top + this.scrollTop,
@ -102,7 +102,7 @@ VantComponent({
}); });
}, },
setSiderbarRect() { setSiderbarRect() {
return getRect.call(this, '.van-index-bar__sidebar').then((res) => { return getRect(this, '.van-index-bar__sidebar').then((res) => {
this.sidebar = { this.sidebar = {
height: res.height, height: res.height,
top: res.top, top: res.top,
@ -121,7 +121,7 @@ VantComponent({
} }
}, },
getAnchorRect(anchor) { getAnchorRect(anchor) {
return getRect.call(anchor, '.van-index-anchor-wrapper').then((rect) => ({ return getRect(anchor, '.van-index-anchor-wrapper').then((rect) => ({
height: rect.height, height: rect.height,
top: rect.top, top: rect.top,
})); }));

View File

@ -1,5 +1,6 @@
// @ts-nocheck // @ts-nocheck
import { isObj, requestAnimationFrame } from '../common/utils'; import { requestAnimationFrame } from '../common/utils';
import { isObj } from '../common/validator';
const getClassNames = (name) => ({ const getClassNames = (name) => ({
enter: `van-${name}-enter van-${name}-enter-active enter-class enter-active-class`, enter: `van-${name}-enter van-${name}-enter-active enter-class enter-active-class`,
'enter-to': `van-${name}-enter-to van-${name}-enter-active enter-to-class enter-active-class`, 'enter-to': `van-${name}-enter-to van-${name}-enter-active enter-to-class enter-active-class`,

View File

@ -54,7 +54,7 @@ VantComponent({
return; return;
} }
wx.nextTick(() => { wx.nextTick(() => {
getRect.call(this, '.van-nav-bar').then((res) => { getRect(this, '.van-nav-bar').then((res) => {
if (res && 'height' in res) { if (res && 'height' in res) {
this.setData({ height: res.height }); this.setData({ height: res.height });
} }

View File

@ -64,8 +64,8 @@ VantComponent({
methods: { methods: {
init() { init() {
Promise.all([ Promise.all([
getRect.call(this, '.van-notice-bar__content'), getRect(this, '.van-notice-bar__content'),
getRect.call(this, '.van-notice-bar__wrap'), getRect(this, '.van-notice-bar__wrap'),
]).then((rects) => { ]).then((rects) => {
const [contentRect, wrapRect] = rects; const [contentRect, wrapRect] = rects;
if ( if (

View File

@ -1,5 +1,6 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { WHITE } from '../common/color'; import { WHITE } from '../common/color';
import { getSystemInfoSync } from '../common/utils';
VantComponent({ VantComponent({
props: { props: {
message: String, message: String,
@ -30,7 +31,7 @@ VantComponent({
show: false, show: false,
}, },
created() { created() {
const { statusBarHeight } = wx.getSystemInfoSync(); const { statusBarHeight } = getSystemInfoSync();
this.setData({ statusBarHeight }); this.setData({ statusBarHeight });
}, },
methods: { methods: {

View File

@ -1,5 +1,6 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { isObj, range } from '../common/utils'; import { range } from '../common/utils';
import { isObj } from '../common/validator';
const DEFAULT_DURATION = 200; const DEFAULT_DURATION = 200;
VantComponent({ VantComponent({
classes: ['active-class'], classes: ['active-class'],

View File

@ -37,8 +37,8 @@ VantComponent({
methods: { methods: {
setLeft() { setLeft() {
Promise.all([ Promise.all([
getRect.call(this, '.van-progress'), getRect(this, '.van-progress'),
getRect.call(this, '.van-progress__pivot'), getRect(this, '.van-progress__pivot'),
]).then(([portion, pivot]) => { ]).then(([portion, pivot]) => {
if (portion && pivot) { if (portion && pivot) {
this.setData({ this.setData({

2
dist/rate/index.js vendored
View File

@ -73,7 +73,7 @@ VantComponent({
const { touchable } = this.data; const { touchable } = this.data;
if (!touchable) return; if (!touchable) return;
const { clientX } = event.touches[0]; const { clientX } = event.touches[0];
getAllRect.call(this, '.van-rate__icon').then((list) => { getAllRect(this, '.van-rate__icon').then((list) => {
const target = list const target = list
.sort((item) => item.right - item.left) .sort((item) => item.right - item.left)
.find((item) => clientX >= item.left && clientX <= item.right); .find((item) => clientX >= item.left && clientX <= item.right);

View File

@ -52,8 +52,8 @@ VantComponent({
} }
this.touchMove(event); this.touchMove(event);
this.dragStatus = 'draging'; this.dragStatus = 'draging';
getRect.call(this, '.van-slider').then((rect) => { getRect(this, '.van-slider').then((rect) => {
const diff = (this.deltaX / rect.width) * 100; const diff = (this.deltaX / rect.width) * this.getRange();
this.newValue = this.startValue + diff; this.newValue = this.startValue + diff;
this.updateValue(this.newValue, false, true); this.updateValue(this.newValue, false, true);
}); });
@ -68,7 +68,7 @@ VantComponent({
onClick(event) { onClick(event) {
if (this.data.disabled) return; if (this.data.disabled) return;
const { min } = this.data; const { min } = this.data;
getRect.call(this, '.van-slider').then((rect) => { getRect(this, '.van-slider').then((rect) => {
const value = const value =
((event.detail.x - rect.left) / rect.width) * this.getRange() + min; ((event.detail.x - rect.left) / rect.width) * this.getRange() + min;
this.updateValue(value, true); this.updateValue(value, true);

18
dist/slider/index.wxs vendored
View File

@ -1,18 +1,12 @@
/* eslint-disable */ /* eslint-disable */
var utils = require('../wxs/utils.wxs'); var style = require('../wxs/style.wxs');
var addUnit = require('../wxs/add-unit.wxs');
function barStyle(barHeight, activeColor) { function barStyle(barHeight, activeColor) {
var styles = [['height', utils.addUnit(barHeight)]]; return style({
height: addUnit(barHeight),
if (activeColor) { background: activeColor,
styles.push(['background', activeColor]); });
}
return styles
.map(function (item) {
return item.join(':');
})
.join(';');
} }
module.exports = { module.exports = {

View File

@ -1,5 +1,5 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { isDef } from '../common/utils'; import { isDef } from '../common/validator';
const LONG_PRESS_START_TIME = 600; const LONG_PRESS_START_TIME = 600;
const LONG_PRESS_INTERVAL = 200; const LONG_PRESS_INTERVAL = 200;
// add num and avoid float number // add num and avoid float number

View File

@ -57,7 +57,7 @@ VantComponent({
this.scrollTop = scrollTop || this.scrollTop; this.scrollTop = scrollTop || this.scrollTop;
if (typeof container === 'function') { if (typeof container === 'function') {
Promise.all([ Promise.all([
getRect.call(this, ROOT_ELEMENT), getRect(this, ROOT_ELEMENT),
this.getContainerRect(), this.getContainerRect(),
]).then(([root, container]) => { ]).then(([root, container]) => {
if (offsetTop + root.height > container.height + container.top) { if (offsetTop + root.height > container.height + container.top) {
@ -77,7 +77,7 @@ VantComponent({
}); });
return; return;
} }
getRect.call(this, ROOT_ELEMENT).then((root) => { getRect(this, ROOT_ELEMENT).then((root) => {
if (offsetTop >= root.top) { if (offsetTop >= root.top) {
this.setDataAfterDiff({ fixed: true, height: root.height }); this.setDataAfterDiff({ fixed: true, height: root.height });
this.transform = 0; this.transform = 0;

View File

@ -64,7 +64,7 @@ VantComponent({
return; return;
} }
wx.nextTick(() => { wx.nextTick(() => {
getRect.call(this, '.van-tabbar').then((res) => { getRect(this, '.van-tabbar').then((res) => {
this.setData({ height: res.height }); this.setData({ height: res.height });
}); });
}); });

48
dist/tabs/index.js vendored
View File

@ -1,6 +1,13 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
import { touch } from '../mixins/touch'; import { touch } from '../mixins/touch';
import { getAllRect, getRect, isDef } from '../common/utils'; import {
getAllRect,
getRect,
groupSetData,
nextTick,
requestAnimationFrame,
} from '../common/utils';
import { isDef } from '../common/validator';
VantComponent({ VantComponent({
mixins: [touch], mixins: [touch],
classes: ['nav-class', 'tab-class', 'tab-active-class', 'line-class'], classes: ['nav-class', 'tab-class', 'tab-active-class', 'line-class'],
@ -89,27 +96,23 @@ VantComponent({
}, },
data: { data: {
tabs: [], tabs: [],
lineStyle: '',
scrollLeft: 0, scrollLeft: 0,
scrollable: false, scrollable: false,
trackStyle: '',
currentIndex: 0, currentIndex: 0,
container: null, container: null,
skipTransition: true, skipTransition: true,
lineOffsetLeft: 0, lineOffsetLeft: 0,
}, },
mounted() { mounted() {
wx.nextTick(() => { requestAnimationFrame(() => {
this.setData({
container: () => this.createSelectorQuery().select('.van-tabs'),
});
this.resize(true); this.resize(true);
this.scrollIntoView(); this.scrollIntoView();
}); });
}, },
methods: { methods: {
updateContainer() {
this.setData({
container: () => this.createSelectorQuery().select('.van-tabs'),
});
},
updateTabs() { updateTabs() {
const { children = [], data } = this; const { children = [], data } = this;
this.setData({ this.setData({
@ -117,7 +120,7 @@ VantComponent({
scrollable: scrollable:
this.children.length > data.swipeThreshold || !data.ellipsis, this.children.length > data.swipeThreshold || !data.ellipsis,
}); });
this.setCurrentIndexByName(this.getCurrentName() || data.active); this.setCurrentIndexByName(data.active || this.getCurrentName());
}, },
trigger(eventName, child) { trigger(eventName, child) {
const { currentIndex } = this.data; const { currentIndex } = this.data;
@ -138,7 +141,7 @@ VantComponent({
this.trigger('disabled', child); this.trigger('disabled', child);
} else { } else {
this.setCurrentIndex(index); this.setCurrentIndex(index);
wx.nextTick(() => { nextTick(() => {
this.trigger('click'); this.trigger('click');
}); });
} }
@ -162,21 +165,22 @@ VantComponent({
) { ) {
return; return;
} }
children.forEach((item, index) => { groupSetData(this, () => {
const active = index === currentIndex; children.forEach((item, index) => {
if (active !== item.data.active || !item.inited) { const active = index === currentIndex;
item.updateRender(active, this); if (active !== item.data.active || !item.inited) {
} item.updateRender(active, this);
}
});
}); });
if (currentIndex === data.currentIndex) { if (currentIndex === data.currentIndex) {
return; return;
} }
const shouldEmitChange = data.currentIndex !== null; const shouldEmitChange = data.currentIndex !== null;
this.setData({ currentIndex }); this.setData({ currentIndex });
wx.nextTick(() => { nextTick(() => {
this.resize(); this.resize();
this.scrollIntoView(); this.scrollIntoView();
this.updateContainer();
this.trigger('input'); this.trigger('input');
if (shouldEmitChange) { if (shouldEmitChange) {
this.trigger('change'); this.trigger('change');
@ -195,8 +199,8 @@ VantComponent({
} }
const { currentIndex, ellipsis } = this.data; const { currentIndex, ellipsis } = this.data;
Promise.all([ Promise.all([
getAllRect.call(this, '.van-tab'), getAllRect(this, '.van-tab'),
getRect.call(this, '.van-tabs__line'), getRect(this, '.van-tabs__line'),
]).then(([rects = [], lineRect]) => { ]).then(([rects = [], lineRect]) => {
const rect = rects[currentIndex]; const rect = rects[currentIndex];
if (rect == null) { if (rect == null) {
@ -220,8 +224,8 @@ VantComponent({
return; return;
} }
Promise.all([ Promise.all([
getAllRect.call(this, '.van-tab'), getAllRect(this, '.van-tab'),
getRect.call(this, '.van-tabs__nav'), getRect(this, '.van-tabs__nav'),
]).then(([tabRects, navRect]) => { ]).then(([tabRects, navRect]) => {
const tabRect = tabRects[currentIndex]; const tabRect = tabRects[currentIndex];
const offsetLeft = tabRects const offsetLeft = tabRects

2
dist/toast/toast.js vendored
View File

@ -1,4 +1,4 @@
import { isObj } from '../common/utils'; import { isObj } from '../common/validator';
const defaultOptions = { const defaultOptions = {
type: 'text', type: 'text',
mask: false, mask: false,

View File

@ -47,28 +47,7 @@ component_1.VantComponent({
type: String, type: String,
value: '20px', value: '20px',
}, },
color: { color: String,
type: String,
observer: function (color) {
var style = '';
if (color) {
style += 'color: ' + (this.data.plain ? color : 'white') + ';';
if (!this.data.plain) {
// Use background instead of backgroundColor to make linear-gradient work
style += 'background: ' + color + ';';
}
// hide border when color is linear-gradient
if (color.indexOf('gradient') !== -1) {
style += 'border: 0;';
} else {
style += 'border-color: ' + color + ';';
}
}
if (style !== this.data.baseStyle) {
this.setData({ baseStyle: style });
}
},
},
}, },
methods: { methods: {
onClick: function () { onClick: function () {

View File

@ -1,4 +1,5 @@
<wxs src="../wxs/utils.wxs" module="utils" /> <wxs src="../wxs/utils.wxs" module="utils" />
<wxs src="./index.wxs" module="computed" />
<button <button
id="{{ id }}" id="{{ id }}"
@ -7,7 +8,7 @@
hover-class="van-button--active hover-class" hover-class="van-button--active hover-class"
lang="{{ lang }}" lang="{{ lang }}"
form-type="{{ formType }}" form-type="{{ formType }}"
style="{{ baseStyle }} {{ customStyle }}" style="{{ computed.rootStyle({ plain, color }) }} {{ customStyle }}"
open-type="{{ disabled ? '' : openType }}" open-type="{{ disabled ? '' : openType }}"
business-id="{{ businessId }}" business-id="{{ businessId }}"
session-from="{{ sessionFrom }}" session-from="{{ sessionFrom }}"
@ -30,7 +31,7 @@
custom-class="loading-class" custom-class="loading-class"
size="{{ loadingSize }}" size="{{ loadingSize }}"
type="{{ loadingType }}" type="{{ loadingType }}"
color="{{ loadingColor(type,color,plain) }}" color="{{ computed.loadingColor({ type, color, plain }) }}"
/> />
<view wx:if="{{ loadingText }}" class="van-button__loading-text"> <view wx:if="{{ loadingText }}" class="van-button__loading-text">
{{ loadingText }} {{ loadingText }}
@ -50,19 +51,3 @@
</view> </view>
</block> </block>
</button> </button>
<wxs module="loadingColor">
function get(type, color,plain) {
if(plain) {
return color ? color: '#c9c9c9';
}
if(type === 'default') {
return '#c9c9c9';
}
return 'white';
}
module.exports = get;
</wxs>

39
lib/button/index.wxs Normal file
View File

@ -0,0 +1,39 @@
/* eslint-disable */
var style = require('../wxs/style.wxs');
function rootStyle(data) {
if (!data.color) {
return '';
}
var properties = {
color: data.plain ? data.color : '#fff',
background: data.plain ? null : data.color,
};
// hide border when color is linear-gradient
if (data.color.indexOf('gradient') !== -1) {
properties.border = 0;
} else {
properties['border-color'] = data.color;
}
return style(properties);
}
function loadingColor(data) {
if (data.plain) {
return data.color ? data.color : '#c9c9c9';
}
if (data.type === 'default') {
return '#c9c9c9';
}
return '#fff';
}
module.exports = {
rootStyle: rootStyle,
loadingColor: loadingColor,
};

View File

@ -1,20 +1,20 @@
/* eslint-disable */ /* eslint-disable */
var utils = require('../wxs/utils.wxs'); var style = require('../wxs/style.wxs');
var addUnit = require('../wxs/add-unit.wxs');
function iconStyle(checkedColor, value, disabled, parentDisabled, iconSize) { function iconStyle(checkedColor, value, disabled, parentDisabled, iconSize) {
var styles = [['font-size', utils.addUnit(iconSize)]]; var styles = {
'font-size': addUnit(iconSize),
};
if (checkedColor && value && !disabled && !parentDisabled) { if (checkedColor && value && !disabled && !parentDisabled) {
styles.push(['border-color', checkedColor]); styles['border-color'] = checkedColor;
styles.push(['background-color', checkedColor]); styles['background-color'] = checkedColor;
} }
return styles return style(styles);
.map(function(item) {
return item.join(':');
})
.join(';');
} }
module.exports = { module.exports = {
iconStyle: iconStyle iconStyle: iconStyle,
}; };

View File

@ -1,9 +1,10 @@
'use strict'; 'use strict';
Object.defineProperty(exports, '__esModule', { value: true }); Object.defineProperty(exports, '__esModule', { value: true });
var component_1 = require('../common/component'); var component_1 = require('../common/component');
var utils_1 = require('../common/utils');
var color_1 = require('../common/color'); var color_1 = require('../common/color');
var canvas_1 = require('./canvas'); var canvas_1 = require('./canvas');
var validator_1 = require('../common/validator');
var utils_1 = require('../common/utils');
function format(rate) { function format(rate) {
return Math.min(Math.max(rate, 0), 100); return Math.min(Math.max(rate, 0), 100);
} }
@ -74,7 +75,7 @@ component_1.VantComponent({
var ctx = wx.createCanvasContext('van-circle', this); var ctx = wx.createCanvasContext('van-circle', this);
return Promise.resolve(ctx); return Promise.resolve(ctx);
} }
var dpr = wx.getSystemInfoSync().pixelRatio; var dpr = utils_1.getSystemInfoSync().pixelRatio;
return new Promise(function (resolve) { return new Promise(function (resolve) {
wx.createSelectorQuery() wx.createSelectorQuery()
.in(_this) .in(_this)
@ -98,7 +99,7 @@ component_1.VantComponent({
var _a = this.data, var _a = this.data,
color = _a.color, color = _a.color,
size = _a.size; size = _a.size;
if (utils_1.isObj(color)) { if (validator_1.isObj(color)) {
return this.getContext().then(function (context) { return this.getContext().then(function (context) {
var LinearColor = context.createLinearGradient(size, 0, 0, 0); var LinearColor = context.createLinearGradient(size, 0, 0, 0);
Object.keys(color) Object.keys(color)

View File

@ -63,8 +63,8 @@ function useAnimation(context, expanded, mounted, height) {
}); });
} }
function setContentAnimate(context, expanded, mounted) { function setContentAnimate(context, expanded, mounted) {
utils_1.getRect utils_1
.call(context, '.van-collapse-item__content') .getRect(context, '.van-collapse-item__content')
.then(function (rect) { .then(function (rect) {
return rect.height; return rect.height;
}) })

View File

@ -1,24 +1,20 @@
'use strict'; 'use strict';
Object.defineProperty(exports, '__esModule', { value: true }); Object.defineProperty(exports, '__esModule', { value: true });
exports.toPromise = exports.getAllRect = exports.getRect = exports.pickExclude = exports.requestAnimationFrame = exports.addUnit = exports.getSystemInfoSync = exports.nextTick = exports.range = exports.isObj = exports.isDef = void 0; exports.toPromise = exports.groupSetData = exports.getAllRect = exports.getRect = exports.pickExclude = exports.requestAnimationFrame = exports.addUnit = exports.getSystemInfoSync = exports.nextTick = exports.range = void 0;
var validator_1 = require('./validator'); var validator_1 = require('./validator');
function isDef(value) { var version_1 = require('./version');
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 range(num, min, max) { function range(num, min, max) {
return Math.min(Math.max(num, min), max); return Math.min(Math.max(num, min), max);
} }
exports.range = range; exports.range = range;
function nextTick(fn) { function nextTick(cb) {
setTimeout(function () { if (version_1.canIUseNextTick()) {
fn(); wx.nextTick(cb);
}, 1000 / 30); } else {
setTimeout(function () {
cb();
}, 1000 / 30);
}
} }
exports.nextTick = nextTick; exports.nextTick = nextTick;
var systemInfo; var systemInfo;
@ -30,7 +26,7 @@ function getSystemInfoSync() {
} }
exports.getSystemInfoSync = getSystemInfoSync; exports.getSystemInfoSync = getSystemInfoSync;
function addUnit(value) { function addUnit(value) {
if (!isDef(value)) { if (!validator_1.isDef(value)) {
return undefined; return undefined;
} }
value = String(value); value = String(value);
@ -40,7 +36,9 @@ exports.addUnit = addUnit;
function requestAnimationFrame(cb) { function requestAnimationFrame(cb) {
var systemInfo = getSystemInfoSync(); var systemInfo = getSystemInfoSync();
if (systemInfo.platform === 'devtools') { if (systemInfo.platform === 'devtools') {
return nextTick(cb); return setTimeout(function () {
cb();
}, 1000 / 30);
} }
return wx return wx
.createSelectorQuery() .createSelectorQuery()
@ -63,11 +61,10 @@ function pickExclude(obj, keys) {
}, {}); }, {});
} }
exports.pickExclude = pickExclude; exports.pickExclude = pickExclude;
function getRect(selector) { function getRect(context, selector) {
var _this = this;
return new Promise(function (resolve) { return new Promise(function (resolve) {
wx.createSelectorQuery() wx.createSelectorQuery()
.in(_this) .in(context)
.select(selector) .select(selector)
.boundingClientRect() .boundingClientRect()
.exec(function (rect) { .exec(function (rect) {
@ -79,11 +76,10 @@ function getRect(selector) {
}); });
} }
exports.getRect = getRect; exports.getRect = getRect;
function getAllRect(selector) { function getAllRect(context, selector) {
var _this = this;
return new Promise(function (resolve) { return new Promise(function (resolve) {
wx.createSelectorQuery() wx.createSelectorQuery()
.in(_this) .in(context)
.selectAll(selector) .selectAll(selector)
.boundingClientRect() .boundingClientRect()
.exec(function (rect) { .exec(function (rect) {
@ -95,6 +91,14 @@ function getAllRect(selector) {
}); });
} }
exports.getAllRect = getAllRect; exports.getAllRect = getAllRect;
function groupSetData(context, cb) {
if (version_1.canIUseGroupSetData()) {
context.groupSetData(cb);
} else {
cb();
}
}
exports.groupSetData = groupSetData;
function toPromise(promiseLike) { function toPromise(promiseLike) {
if (validator_1.isPromise(promiseLike)) { if (validator_1.isPromise(promiseLike)) {
return promiseLike; return promiseLike;

View File

@ -1,6 +1,6 @@
'use strict'; 'use strict';
Object.defineProperty(exports, '__esModule', { value: true }); Object.defineProperty(exports, '__esModule', { value: true });
exports.canIUseAnimate = exports.canIUseFormFieldButton = exports.canIUseModel = void 0; exports.canIUseNextTick = exports.canIUseGroupSetData = exports.canIUseAnimate = exports.canIUseFormFieldButton = exports.canIUseModel = void 0;
var utils_1 = require('./utils'); var utils_1 = require('./utils');
function compareVersion(v1, v2) { function compareVersion(v1, v2) {
v1 = v1.split('.'); v1 = v1.split('.');
@ -39,3 +39,12 @@ function canIUseAnimate() {
return compareVersion(system.SDKVersion, '2.9.0') >= 0; return compareVersion(system.SDKVersion, '2.9.0') >= 0;
} }
exports.canIUseAnimate = canIUseAnimate; exports.canIUseAnimate = canIUseAnimate;
function canIUseGroupSetData() {
var system = utils_1.getSystemInfoSync();
return compareVersion(system.SDKVersion, '2.4.0') >= 0;
}
exports.canIUseGroupSetData = canIUseGroupSetData;
function canIUseNextTick() {
return wx.canIUse('nextTick');
}
exports.canIUseNextTick = canIUseNextTick;

View File

@ -26,11 +26,11 @@ var __spreadArrays =
}; };
Object.defineProperty(exports, '__esModule', { value: true }); Object.defineProperty(exports, '__esModule', { value: true });
var component_1 = require('../common/component'); var component_1 = require('../common/component');
var utils_1 = require('../common/utils'); var validator_1 = require('../common/validator');
var shared_1 = require('../picker/shared'); var shared_1 = require('../picker/shared');
var currentYear = new Date().getFullYear(); var currentYear = new Date().getFullYear();
function isValidDate(date) { function isValidDate(date) {
return utils_1.isDef(date) && !isNaN(new Date(date).getTime()); return validator_1.isDef(date) && !isNaN(new Date(date).getTime());
} }
function range(num, min, max) { function range(num, min, max) {
return Math.min(Math.max(num, min), max); return Math.min(Math.max(num, min), max);

View File

@ -54,7 +54,7 @@ component_1.VantComponent({
itemListData: [], itemListData: [],
}, },
beforeCreate: function () { beforeCreate: function () {
var windowHeight = wx.getSystemInfoSync().windowHeight; var windowHeight = utils_1.getSystemInfoSync().windowHeight;
this.windowHeight = windowHeight; this.windowHeight = windowHeight;
ARRAY.push(this); ARRAY.push(this);
}, },
@ -97,22 +97,20 @@ component_1.VantComponent({
var _a = this.data, var _a = this.data,
zIndex = _a.zIndex, zIndex = _a.zIndex,
direction = _a.direction; direction = _a.direction;
return utils_1.getRect return utils_1.getRect(this, '.van-dropdown-menu').then(function (rect) {
.call(this, '.van-dropdown-menu') var _a = rect.top,
.then(function (rect) { top = _a === void 0 ? 0 : _a,
var _a = rect.top, _b = rect.bottom,
top = _a === void 0 ? 0 : _a, bottom = _b === void 0 ? 0 : _b;
_b = rect.bottom, var offset = direction === 'down' ? bottom : _this.windowHeight - top;
bottom = _b === void 0 ? 0 : _b; var wrapperStyle = 'z-index: ' + zIndex + ';';
var offset = direction === 'down' ? bottom : _this.windowHeight - top; if (direction === 'down') {
var wrapperStyle = 'z-index: ' + zIndex + ';'; wrapperStyle += 'top: ' + utils_1.addUnit(offset) + ';';
if (direction === 'down') { } else {
wrapperStyle += 'top: ' + utils_1.addUnit(offset) + ';'; wrapperStyle += 'bottom: ' + utils_1.addUnit(offset) + ';';
} else { }
wrapperStyle += 'bottom: ' + utils_1.addUnit(offset) + ';'; return wrapperStyle;
} });
return wrapperStyle;
});
}, },
onTitleTap: function (event) { onTitleTap: function (event) {
var _this = this; var _this = this;

View File

@ -1 +1 @@
@import '../common/index.wxss';.van-goods-action{position:fixed;right:0;bottom:0;left:0;display:-webkit-flex;display:flex;-webkit-align-items:center;align-items:center;height:50px;height:var(--goods-action-height,50px);background-color:#fff;background-color:var(--goods-action-background-color,#fff)}.van-goods-action--safe{padding-bottom:env(safe-area-inset-bottom)} @import '../common/index.wxss';.van-goods-action{position:fixed;right:0;bottom:0;left:0;display:-webkit-flex;display:flex;-webkit-align-items:center;align-items:center;box-sizing:initial;height:50px;height:var(--goods-action-height,50px);background-color:#fff;background-color:var(--goods-action-background-color,#fff)}.van-goods-action--safe{padding-bottom:env(safe-area-inset-bottom)}

View File

@ -2,7 +2,6 @@
Object.defineProperty(exports, '__esModule', { value: true }); Object.defineProperty(exports, '__esModule', { value: true });
var link_1 = require('../mixins/link'); var link_1 = require('../mixins/link');
var component_1 = require('../common/component'); var component_1 = require('../common/component');
var utils_1 = require('../common/utils');
component_1.VantComponent({ component_1.VantComponent({
relation: { relation: {
name: 'grid', name: 'grid',
@ -42,33 +41,7 @@ component_1.VantComponent({
center = data.center, center = data.center,
direction = data.direction, direction = data.direction,
iconSize = data.iconSize; iconSize = data.iconSize;
var width = 100 / columnNum + '%';
var styleWrapper = [];
styleWrapper.push('width: ' + width);
if (square) {
styleWrapper.push('padding-top: ' + width);
}
if (gutter) {
var gutterValue = utils_1.addUnit(gutter);
styleWrapper.push('padding-right: ' + gutterValue);
var index = children.indexOf(this);
if (index >= columnNum && !square) {
styleWrapper.push('margin-top: ' + gutterValue);
}
}
var contentStyle = '';
if (square && gutter) {
var gutterValue = utils_1.addUnit(gutter);
contentStyle =
'\n right: ' +
gutterValue +
';\n bottom: ' +
gutterValue +
';\n height: auto;\n ';
}
this.setData({ this.setData({
viewStyle: styleWrapper.join('; '),
contentStyle: contentStyle,
center: center, center: center,
border: border, border: border,
square: square, square: square,
@ -76,6 +49,8 @@ component_1.VantComponent({
clickable: clickable, clickable: clickable,
direction: direction, direction: direction,
iconSize: iconSize, iconSize: iconSize,
index: children.indexOf(this),
columnNum: columnNum,
}); });
}, },
onClick: function () { onClick: function () {

View File

@ -1,9 +1,14 @@
<wxs src="../wxs/utils.wxs" module="utils" /> <wxs src="../wxs/utils.wxs" module="utils" />
<wxs src="./index.wxs" module="computed" />
<view class="custom-class {{ utils.bem('grid-item', { square }) }}" style="{{ viewStyle }}" bindtap="onClick"> <view
class="custom-class {{ utils.bem('grid-item', { square }) }}"
style="{{ computed.wrapperStyle({ square, gutter, columnNum, index }) }}"
bindtap="onClick"
>
<view <view
class="content-class {{ utils.bem('grid-item__content', [direction, { center, square, clickable, surround: border && gutter }]) }} {{ border ? 'van-hairline--surround' : '' }}" class="content-class {{ utils.bem('grid-item__content', [direction, { center, square, clickable, surround: border && gutter }]) }} {{ border ? 'van-hairline--surround' : '' }}"
style="{{ contentStyle }}" style="{{ computed.contentStyle({ square, gutter }) }}"
> >
<block wx:if="{{ useSlot }}"> <block wx:if="{{ useSlot }}">
<slot /> <slot />

32
lib/grid-item/index.wxs Normal file
View File

@ -0,0 +1,32 @@
/* eslint-disable */
var style = require('../wxs/style.wxs');
var addUnit = require('../wxs/add-unit.wxs');
function wrapperStyle(data) {
var width = 100 / data.columnNum + '%';
return style({
width: width,
'padding-top': data.square ? width : null,
'padding-right': addUnit(data.gutter),
'margin-top':
data.index >= data.columnNum && !data.square
? addUnit(data.gutter)
: null,
});
}
function contentStyle(data) {
return data.square
? style({
right: addUnit(data.gutter),
bottom: addUnit(data.gutter),
height: 'auto',
})
: '';
}
module.exports = {
wrapperStyle: wrapperStyle,
contentStyle: contentStyle,
};

View File

@ -1,7 +1,6 @@
'use strict'; 'use strict';
Object.defineProperty(exports, '__esModule', { value: true }); Object.defineProperty(exports, '__esModule', { value: true });
var component_1 = require('../common/component'); var component_1 = require('../common/component');
var utils_1 = require('../common/utils');
component_1.VantComponent({ component_1.VantComponent({
relation: { relation: {
name: 'grid-item', name: 'grid-item',
@ -46,17 +45,6 @@ component_1.VantComponent({
observer: 'updateChildren', observer: 'updateChildren',
}, },
}, },
data: {
viewStyle: '',
},
created: function () {
var gutter = this.data.gutter;
if (gutter) {
this.setData({
viewStyle: 'padding-left: ' + utils_1.addUnit(gutter),
});
}
},
methods: { methods: {
updateChildren: function () { updateChildren: function () {
this.children.forEach(function (child) { this.children.forEach(function (child) {

View File

@ -1,3 +1,8 @@
<view class="van-grid custom-class {{ border && !gutter ? 'van-hairline--top' : '' }}" style="{{ viewStyle }}"> <wxs src="./index.wxs" module="computed" />
<view
class="van-grid custom-class {{ border && !gutter ? 'van-hairline--top' : '' }}"
style="{{ computed.rootStyle({ gutter }) }}"
>
<slot /> <slot />
</view> </view>

13
lib/grid/index.wxs Normal file
View File

@ -0,0 +1,13 @@
/* eslint-disable */
var style = require('../wxs/style.wxs');
var addUnit = require('../wxs/add-unit.wxs');
function rootStyle(data) {
return style({
'padding-left': addUnit(data.gutter),
});
}
module.exports = {
rootStyle: rootStyle,
};

View File

@ -1,10 +1,9 @@
<wxs src="../wxs/utils.wxs" module="utils" /> <wxs src="./index.wxs" module="computed" />
<wxs src="./computed.wxs" module="computed" />
<view <view
class="{{ computed.rootClass({ classPrefix, name }) }}" class="{{ computed.rootClass({ classPrefix, name }) }}"
style="{{ computed.rootStyle({ customStyle, color, size }) }}" style="{{ computed.rootStyle({ customStyle, color, size }) }}"
bind:tap="onClick" bindtap="onClick"
> >
<van-info <van-info
wx:if="{{ info !== null || dot }}" wx:if="{{ info !== null || dot }}"

View File

@ -1,5 +1,6 @@
/* eslint-disable */ /* eslint-disable */
var utils = require('../wxs/utils.wxs'); var style = require('../wxs/style.wxs');
var addUnit = require('../wxs/add-unit.wxs');
function isImage(name) { function isImage(name) {
return name.indexOf('/') !== -1; return name.indexOf('/') !== -1;
@ -22,25 +23,13 @@ function rootClass(data) {
} }
function rootStyle(data) { function rootStyle(data) {
var styles = []; return style([
{
if (data.color) { color: data.color,
styles.push(['color', data.color]); 'font-size': addUnit(data.size),
} },
data.customStyle,
if (data.size) { ]);
styles.push(['font-size', utils.addUnit(data.size)]);
}
if (data.customStyle) {
styles.push([data.customStyle]);
}
return styles
.map(function (pair) {
return pair.join(':');
})
.join(';');
} }
module.exports = { module.exports = {

View File

@ -1,17 +1,8 @@
'use strict'; 'use strict';
Object.defineProperty(exports, '__esModule', { value: true }); Object.defineProperty(exports, '__esModule', { value: true });
var utils_1 = require('../common/utils');
var component_1 = require('../common/component'); var component_1 = require('../common/component');
var button_1 = require('../mixins/button'); var button_1 = require('../mixins/button');
var open_type_1 = require('../mixins/open-type'); var open_type_1 = require('../mixins/open-type');
var FIT_MODE_MAP = {
none: 'center',
fill: 'scaleToFill',
cover: 'aspectFill',
contain: 'aspectFit',
widthFix: 'widthFix',
heightFix: 'heightFix',
};
component_1.VantComponent({ component_1.VantComponent({
mixins: [button_1.button, open_type_1.openType], mixins: [button_1.button, open_type_1.openType],
classes: ['custom-class', 'loading-class', 'error-class', 'image-class'], classes: ['custom-class', 'loading-class', 'error-class', 'image-class'],
@ -26,14 +17,8 @@ component_1.VantComponent({
}, },
}, },
round: Boolean, round: Boolean,
width: { width: null,
type: null, height: null,
observer: 'setStyle',
},
height: {
type: null,
observer: 'setStyle',
},
radius: null, radius: null,
lazyLoad: Boolean, lazyLoad: Boolean,
useErrorSlot: Boolean, useErrorSlot: Boolean,
@ -42,7 +27,6 @@ component_1.VantComponent({
fit: { fit: {
type: String, type: String,
value: 'fill', value: 'fill',
observer: 'setMode',
}, },
showError: { showError: {
type: Boolean, type: Boolean,
@ -58,34 +42,7 @@ component_1.VantComponent({
loading: true, loading: true,
viewStyle: '', viewStyle: '',
}, },
mounted: function () {
this.setMode();
this.setStyle();
},
methods: { methods: {
setMode: function () {
this.setData({
mode: FIT_MODE_MAP[this.data.fit],
});
},
setStyle: function () {
var _a = this.data,
width = _a.width,
height = _a.height,
radius = _a.radius;
var style = '';
if (utils_1.isDef(width)) {
style += 'width: ' + utils_1.addUnit(width) + ';';
}
if (utils_1.isDef(height)) {
style += 'height: ' + utils_1.addUnit(height) + ';';
}
if (utils_1.isDef(radius)) {
style += 'overflow: hidden;';
style += 'border-radius: ' + utils_1.addUnit(radius) + ';';
}
this.setData({ viewStyle: style });
},
onLoad: function (event) { onLoad: function (event) {
this.setData({ this.setData({
loading: false, loading: false,

View File

@ -1,14 +1,15 @@
<wxs src="../wxs/utils.wxs" module="utils" /> <wxs src="../wxs/utils.wxs" module="utils" />
<wxs src="./index.wxs" module="computed" />
<view <view
style="{{ viewStyle }}" style="{{ computed.rootStyle({ width, height, radius }) }}"
class="custom-class {{ utils.bem('image', { round })}}" class="custom-class {{ utils.bem('image', { round })}}"
bind:tap="onClick" bind:tap="onClick"
> >
<image <image
wx:if="{{ !error }}" wx:if="{{ !error }}"
src="{{ src }}" src="{{ src }}"
mode="{{ mode }}" mode="{{ computed.mode(fit) }}"
lazy-load="{{ lazyLoad }}" lazy-load="{{ lazyLoad }}"
class="image-class van-image__img" class="image-class van-image__img"
show-menu-by-longpress="{{ showMenuByLongpress }}" show-menu-by-longpress="{{ showMenuByLongpress }}"

32
lib/image/index.wxs Normal file
View File

@ -0,0 +1,32 @@
/* eslint-disable */
var style = require('../wxs/style.wxs');
var addUnit = require('../wxs/add-unit.wxs');
function rootStyle(data) {
return style([
{
width: addUnit(data.width),
height: addUnit(data.height),
'border-radius': addUnit(data.radius),
},
data.radius ? 'overflow: hidden' : null,
]);
}
var FIT_MODE_MAP = {
none: 'center',
fill: 'scaleToFill',
cover: 'aspectFill',
contain: 'aspectFit',
widthFix: 'widthFix',
heightFix: 'heightFix',
};
function mode(fit) {
return FIT_MODE_MAP[fit];
}
module.exports = {
rootStyle: rootStyle,
mode: mode,
};

View File

@ -20,14 +20,12 @@ component_1.VantComponent({
methods: { methods: {
scrollIntoView: function (scrollTop) { scrollIntoView: function (scrollTop) {
var _this = this; var _this = this;
utils_1.getRect utils_1.getRect(this, '.van-index-anchor-wrapper').then(function (rect) {
.call(this, '.van-index-anchor-wrapper') wx.pageScrollTo({
.then(function (rect) { duration: 0,
wx.pageScrollTo({ scrollTop: scrollTop + rect.top - _this.parent.data.stickyOffsetTop,
duration: 0,
scrollTop: scrollTop + rect.top - _this.parent.data.stickyOffsetTop,
});
}); });
});
}, },
}, },
}); });

View File

@ -88,8 +88,8 @@ component_1.VantComponent({
var _this = this; var _this = this;
return Promise.all( return Promise.all(
this.children.map(function (anchor) { this.children.map(function (anchor) {
return utils_1.getRect return utils_1
.call(anchor, '.van-index-anchor-wrapper') .getRect(anchor, '.van-index-anchor-wrapper')
.then(function (rect) { .then(function (rect) {
Object.assign(anchor, { Object.assign(anchor, {
height: rect.height, height: rect.height,
@ -101,7 +101,7 @@ component_1.VantComponent({
}, },
setListRect: function () { setListRect: function () {
var _this = this; var _this = this;
return utils_1.getRect.call(this, '.van-index-bar').then(function (rect) { return utils_1.getRect(this, '.van-index-bar').then(function (rect) {
Object.assign(_this, { Object.assign(_this, {
height: rect.height, height: rect.height,
top: rect.top + _this.scrollTop, top: rect.top + _this.scrollTop,
@ -110,8 +110,8 @@ component_1.VantComponent({
}, },
setSiderbarRect: function () { setSiderbarRect: function () {
var _this = this; var _this = this;
return utils_1.getRect return utils_1
.call(this, '.van-index-bar__sidebar') .getRect(this, '.van-index-bar__sidebar')
.then(function (res) { .then(function (res) {
_this.sidebar = { _this.sidebar = {
height: res.height, height: res.height,
@ -133,8 +133,8 @@ component_1.VantComponent({
} }
}, },
getAnchorRect: function (anchor) { getAnchorRect: function (anchor) {
return utils_1.getRect return utils_1
.call(anchor, '.van-index-anchor-wrapper') .getRect(anchor, '.van-index-anchor-wrapper')
.then(function (rect) { .then(function (rect) {
return { return {
height: rect.height, height: rect.height,

View File

@ -3,6 +3,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
exports.transition = void 0; exports.transition = void 0;
// @ts-nocheck // @ts-nocheck
var utils_1 = require('../common/utils'); var utils_1 = require('../common/utils');
var validator_1 = require('../common/validator');
var getClassNames = function (name) { var getClassNames = function (name) {
return { return {
enter: enter:
@ -70,7 +71,7 @@ function transition(showDefaultValue) {
duration = _a.duration, duration = _a.duration,
name = _a.name; name = _a.name;
var classNames = getClassNames(name); var classNames = getClassNames(name);
var currentDuration = utils_1.isObj(duration) var currentDuration = validator_1.isObj(duration)
? duration.enter ? duration.enter
: duration; : duration;
this.status = 'enter'; this.status = 'enter';
@ -100,7 +101,7 @@ function transition(showDefaultValue) {
duration = _a.duration, duration = _a.duration,
name = _a.name; name = _a.name;
var classNames = getClassNames(name); var classNames = getClassNames(name);
var currentDuration = utils_1.isObj(duration) var currentDuration = validator_1.isObj(duration)
? duration.leave ? duration.leave
: duration; : duration;
this.status = 'leave'; this.status = 'leave';

View File

@ -57,7 +57,7 @@ component_1.VantComponent({
return; return;
} }
wx.nextTick(function () { wx.nextTick(function () {
utils_1.getRect.call(_this, '.van-nav-bar').then(function (res) { utils_1.getRect(_this, '.van-nav-bar').then(function (res) {
if (res && 'height' in res) { if (res && 'height' in res) {
_this.setData({ height: res.height }); _this.setData({ height: res.height });
} }

View File

@ -69,8 +69,8 @@ component_1.VantComponent({
init: function () { init: function () {
var _this = this; var _this = this;
Promise.all([ Promise.all([
utils_1.getRect.call(this, '.van-notice-bar__content'), utils_1.getRect(this, '.van-notice-bar__content'),
utils_1.getRect.call(this, '.van-notice-bar__wrap'), utils_1.getRect(this, '.van-notice-bar__wrap'),
]).then(function (rects) { ]).then(function (rects) {
var contentRect = rects[0], var contentRect = rects[0],
wrapRect = rects[1]; wrapRect = rects[1];

View File

@ -2,6 +2,7 @@
Object.defineProperty(exports, '__esModule', { value: true }); Object.defineProperty(exports, '__esModule', { value: true });
var component_1 = require('../common/component'); var component_1 = require('../common/component');
var color_1 = require('../common/color'); var color_1 = require('../common/color');
var utils_1 = require('../common/utils');
component_1.VantComponent({ component_1.VantComponent({
props: { props: {
message: String, message: String,
@ -32,7 +33,7 @@ component_1.VantComponent({
show: false, show: false,
}, },
created: function () { created: function () {
var statusBarHeight = wx.getSystemInfoSync().statusBarHeight; var statusBarHeight = utils_1.getSystemInfoSync().statusBarHeight;
this.setData({ statusBarHeight: statusBarHeight }); this.setData({ statusBarHeight: statusBarHeight });
}, },
methods: { methods: {

View File

@ -2,6 +2,7 @@
Object.defineProperty(exports, '__esModule', { value: true }); Object.defineProperty(exports, '__esModule', { value: true });
var component_1 = require('../common/component'); var component_1 = require('../common/component');
var utils_1 = require('../common/utils'); var utils_1 = require('../common/utils');
var validator_1 = require('../common/validator');
var DEFAULT_DURATION = 200; var DEFAULT_DURATION = 200;
component_1.VantComponent({ component_1.VantComponent({
classes: ['active-class'], classes: ['active-class'],
@ -92,11 +93,11 @@ component_1.VantComponent({
} }
}, },
isDisabled: function (option) { isDisabled: function (option) {
return utils_1.isObj(option) && option.disabled; return validator_1.isObj(option) && option.disabled;
}, },
getOptionText: function (option) { getOptionText: function (option) {
var data = this.data; var data = this.data;
return utils_1.isObj(option) && data.valueKey in option return validator_1.isObj(option) && data.valueKey in option
? option[data.valueKey] ? option[data.valueKey]
: option; : option;
}, },

View File

@ -40,8 +40,8 @@ component_1.VantComponent({
setLeft: function () { setLeft: function () {
var _this = this; var _this = this;
Promise.all([ Promise.all([
utils_1.getRect.call(this, '.van-progress'), utils_1.getRect(this, '.van-progress'),
utils_1.getRect.call(this, '.van-progress__pivot'), utils_1.getRect(this, '.van-progress__pivot'),
]).then(function (_a) { ]).then(function (_a) {
var portion = _a[0], var portion = _a[0],
pivot = _a[1]; pivot = _a[1];

View File

@ -92,7 +92,7 @@ component_1.VantComponent({
var touchable = this.data.touchable; var touchable = this.data.touchable;
if (!touchable) return; if (!touchable) return;
var clientX = event.touches[0].clientX; var clientX = event.touches[0].clientX;
utils_1.getAllRect.call(this, '.van-rate__icon').then(function (list) { utils_1.getAllRect(this, '.van-rate__icon').then(function (list) {
var target = list var target = list
.sort(function (item) { .sort(function (item) {
return item.right - item.left; return item.right - item.left;

View File

@ -55,12 +55,8 @@ component_1.VantComponent({
} }
this.touchMove(event); this.touchMove(event);
this.dragStatus = 'draging'; this.dragStatus = 'draging';
utils_1.getRect.call(this, '.van-slider').then(function (rect) { utils_1.getRect(this, '.van-slider').then(function (rect) {
var diff = (_this.deltaX / rect.width) * 100; var diff = (_this.deltaX / rect.width) * _this.getRange();
// 当设置最大值时(及自定义等分),滑动触发步进需按照等分后的滑动距离触发
if (this.data.max) {
diff = diff * this.data.max / 100
}
_this.newValue = _this.startValue + diff; _this.newValue = _this.startValue + diff;
_this.updateValue(_this.newValue, false, true); _this.updateValue(_this.newValue, false, true);
}); });
@ -76,7 +72,7 @@ component_1.VantComponent({
var _this = this; var _this = this;
if (this.data.disabled) return; if (this.data.disabled) return;
var min = this.data.min; var min = this.data.min;
utils_1.getRect.call(this, '.van-slider').then(function (rect) { utils_1.getRect(this, '.van-slider').then(function (rect) {
var value = var value =
((event.detail.x - rect.left) / rect.width) * _this.getRange() + min; ((event.detail.x - rect.left) / rect.width) * _this.getRange() + min;
_this.updateValue(value, true); _this.updateValue(value, true);

View File

@ -1,18 +1,12 @@
/* eslint-disable */ /* eslint-disable */
var utils = require('../wxs/utils.wxs'); var style = require('../wxs/style.wxs');
var addUnit = require('../wxs/add-unit.wxs');
function barStyle(barHeight, activeColor) { function barStyle(barHeight, activeColor) {
var styles = [['height', utils.addUnit(barHeight)]]; return style({
height: addUnit(barHeight),
if (activeColor) { background: activeColor,
styles.push(['background', activeColor]); });
}
return styles
.map(function (item) {
return item.join(':');
})
.join(';');
} }
module.exports = { module.exports = {

View File

@ -16,7 +16,7 @@ var __assign =
}; };
Object.defineProperty(exports, '__esModule', { value: true }); Object.defineProperty(exports, '__esModule', { value: true });
var component_1 = require('../common/component'); var component_1 = require('../common/component');
var utils_1 = require('../common/utils'); var validator_1 = require('../common/validator');
var LONG_PRESS_START_TIME = 600; var LONG_PRESS_START_TIME = 600;
var LONG_PRESS_INTERVAL = 200; var LONG_PRESS_INTERVAL = 200;
// add num and avoid float number // add num and avoid float number
@ -137,7 +137,7 @@ component_1.VantComponent({
value = value === '' ? 0 : +value; value = value === '' ? 0 : +value;
value = Math.max(Math.min(this.data.max, value), this.data.min); value = Math.max(Math.min(this.data.max, value), this.data.min);
// format decimal // format decimal
if (utils_1.isDef(this.data.decimalLength)) { if (validator_1.isDef(this.data.decimalLength)) {
value = value.toFixed(this.data.decimalLength); value = value.toFixed(this.data.decimalLength);
} }
return value; return value;
@ -152,7 +152,7 @@ component_1.VantComponent({
var formatted = this.filter(value); var formatted = this.filter(value);
// limit max decimal length // limit max decimal length
if ( if (
utils_1.isDef(this.data.decimalLength) && validator_1.isDef(this.data.decimalLength) &&
formatted.indexOf('.') !== -1 formatted.indexOf('.') !== -1
) { ) {
var pair = formatted.split('.'); var pair = formatted.split('.');

View File

@ -64,7 +64,7 @@ component_1.VantComponent({
this.scrollTop = scrollTop || this.scrollTop; this.scrollTop = scrollTop || this.scrollTop;
if (typeof container === 'function') { if (typeof container === 'function') {
Promise.all([ Promise.all([
utils_1.getRect.call(this, ROOT_ELEMENT), utils_1.getRect(this, ROOT_ELEMENT),
this.getContainerRect(), this.getContainerRect(),
]).then(function (_a) { ]).then(function (_a) {
var root = _a[0], var root = _a[0],
@ -86,7 +86,7 @@ component_1.VantComponent({
}); });
return; return;
} }
utils_1.getRect.call(this, ROOT_ELEMENT).then(function (root) { utils_1.getRect(this, ROOT_ELEMENT).then(function (root) {
if (offsetTop >= root.top) { if (offsetTop >= root.top) {
_this.setDataAfterDiff({ fixed: true, height: root.height }); _this.setDataAfterDiff({ fixed: true, height: root.height });
_this.transform = 0; _this.transform = 0;

View File

@ -69,7 +69,7 @@ component_1.VantComponent({
return; return;
} }
wx.nextTick(function () { wx.nextTick(function () {
utils_1.getRect.call(_this, '.van-tabbar').then(function (res) { utils_1.getRect(_this, '.van-tabbar').then(function (res) {
_this.setData({ height: res.height }); _this.setData({ height: res.height });
}); });
}); });

View File

@ -3,6 +3,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
var component_1 = require('../common/component'); var component_1 = require('../common/component');
var touch_1 = require('../mixins/touch'); var touch_1 = require('../mixins/touch');
var utils_1 = require('../common/utils'); var utils_1 = require('../common/utils');
var validator_1 = require('../common/validator');
component_1.VantComponent({ component_1.VantComponent({
mixins: [touch_1.touch], mixins: [touch_1.touch],
classes: ['nav-class', 'tab-class', 'tab-active-class', 'line-class'], classes: ['nav-class', 'tab-class', 'tab-active-class', 'line-class'],
@ -92,10 +93,8 @@ component_1.VantComponent({
}, },
data: { data: {
tabs: [], tabs: [],
lineStyle: '',
scrollLeft: 0, scrollLeft: 0,
scrollable: false, scrollable: false,
trackStyle: '',
currentIndex: 0, currentIndex: 0,
container: null, container: null,
skipTransition: true, skipTransition: true,
@ -103,20 +102,17 @@ component_1.VantComponent({
}, },
mounted: function () { mounted: function () {
var _this = this; var _this = this;
wx.nextTick(function () { utils_1.requestAnimationFrame(function () {
_this.setData({
container: function () {
return _this.createSelectorQuery().select('.van-tabs');
},
});
_this.resize(true); _this.resize(true);
_this.scrollIntoView(); _this.scrollIntoView();
}); });
}, },
methods: { methods: {
updateContainer: function () {
var _this = this;
this.setData({
container: function () {
return _this.createSelectorQuery().select('.van-tabs');
},
});
},
updateTabs: function () { updateTabs: function () {
var _a = this, var _a = this,
_b = _a.children, _b = _a.children,
@ -129,12 +125,12 @@ component_1.VantComponent({
scrollable: scrollable:
this.children.length > data.swipeThreshold || !data.ellipsis, this.children.length > data.swipeThreshold || !data.ellipsis,
}); });
this.setCurrentIndexByName(this.getCurrentName() || data.active); this.setCurrentIndexByName(data.active || this.getCurrentName());
}, },
trigger: function (eventName, child) { trigger: function (eventName, child) {
var currentIndex = this.data.currentIndex; var currentIndex = this.data.currentIndex;
var currentChild = child || this.children[currentIndex]; var currentChild = child || this.children[currentIndex];
if (!utils_1.isDef(currentChild)) { if (!validator_1.isDef(currentChild)) {
return; return;
} }
this.$emit(eventName, { this.$emit(eventName, {
@ -151,7 +147,7 @@ component_1.VantComponent({
this.trigger('disabled', child); this.trigger('disabled', child);
} else { } else {
this.setCurrentIndex(index); this.setCurrentIndex(index);
wx.nextTick(function () { utils_1.nextTick(function () {
_this.trigger('click'); _this.trigger('click');
}); });
} }
@ -174,27 +170,28 @@ component_1.VantComponent({
_b = _a.children, _b = _a.children,
children = _b === void 0 ? [] : _b; children = _b === void 0 ? [] : _b;
if ( if (
!utils_1.isDef(currentIndex) || !validator_1.isDef(currentIndex) ||
currentIndex >= children.length || currentIndex >= children.length ||
currentIndex < 0 currentIndex < 0
) { ) {
return; return;
} }
children.forEach(function (item, index) { utils_1.groupSetData(this, function () {
var active = index === currentIndex; children.forEach(function (item, index) {
if (active !== item.data.active || !item.inited) { var active = index === currentIndex;
item.updateRender(active, _this); if (active !== item.data.active || !item.inited) {
} item.updateRender(active, _this);
}
});
}); });
if (currentIndex === data.currentIndex) { if (currentIndex === data.currentIndex) {
return; return;
} }
var shouldEmitChange = data.currentIndex !== null; var shouldEmitChange = data.currentIndex !== null;
this.setData({ currentIndex: currentIndex }); this.setData({ currentIndex: currentIndex });
wx.nextTick(function () { utils_1.nextTick(function () {
_this.resize(); _this.resize();
_this.scrollIntoView(); _this.scrollIntoView();
_this.updateContainer();
_this.trigger('input'); _this.trigger('input');
if (shouldEmitChange) { if (shouldEmitChange) {
_this.trigger('change'); _this.trigger('change');
@ -219,8 +216,8 @@ component_1.VantComponent({
currentIndex = _a.currentIndex, currentIndex = _a.currentIndex,
ellipsis = _a.ellipsis; ellipsis = _a.ellipsis;
Promise.all([ Promise.all([
utils_1.getAllRect.call(this, '.van-tab'), utils_1.getAllRect(this, '.van-tab'),
utils_1.getRect.call(this, '.van-tabs__line'), utils_1.getRect(this, '.van-tabs__line'),
]).then(function (_a) { ]).then(function (_a) {
var _b = _a[0], var _b = _a[0],
rects = _b === void 0 ? [] : _b, rects = _b === void 0 ? [] : _b,
@ -252,8 +249,8 @@ component_1.VantComponent({
return; return;
} }
Promise.all([ Promise.all([
utils_1.getAllRect.call(this, '.van-tab'), utils_1.getAllRect(this, '.van-tab'),
utils_1.getRect.call(this, '.van-tabs__nav'), utils_1.getRect(this, '.van-tabs__nav'),
]).then(function (_a) { ]).then(function (_a) {
var tabRects = _a[0], var tabRects = _a[0],
navRect = _a[1]; navRect = _a[1];

View File

@ -15,7 +15,7 @@ var __assign =
return __assign.apply(this, arguments); return __assign.apply(this, arguments);
}; };
Object.defineProperty(exports, '__esModule', { value: true }); Object.defineProperty(exports, '__esModule', { value: true });
var utils_1 = require('../common/utils'); var validator_1 = require('../common/validator');
var defaultOptions = { var defaultOptions = {
type: 'text', type: 'text',
mask: false, mask: false,
@ -31,7 +31,7 @@ var defaultOptions = {
var queue = []; var queue = [];
var currentOptions = __assign({}, defaultOptions); var currentOptions = __assign({}, defaultOptions);
function parseOptions(message) { function parseOptions(message) {
return utils_1.isObj(message) ? message : { message: message }; return validator_1.isObj(message) ? message : { message: message };
} }
function getContext() { function getContext() {
var pages = getCurrentPages(); var pages = getCurrentPages();