mirror of
https://gitee.com/vant-contrib/vant-weapp.git
synced 2025-04-06 03:58:05 +08:00
Merge branch 'dev' of https://github.com/youzan/vant-weapp into dev
This commit is contained in:
commit
353b8288d4
@ -34,5 +34,4 @@
|
|||||||
<van-button size="small" class="demo-margin-right">小型按钮</van-button>
|
<van-button size="small" class="demo-margin-right">小型按钮</van-button>
|
||||||
<van-button size="mini">迷你按钮</van-button>
|
<van-button size="mini">迷你按钮</van-button>
|
||||||
</demo-block>
|
</demo-block>
|
||||||
|
|
||||||
</demo-section>
|
</demo-section>
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
import { VantComponent } from '../common/component';
|
import { VantComponent } from '../common/component';
|
||||||
|
import { iphonex } from '../mixins/iphonex';
|
||||||
|
|
||||||
VantComponent({
|
VantComponent({
|
||||||
|
mixins: [iphonex],
|
||||||
|
|
||||||
props: {
|
props: {
|
||||||
show: Boolean,
|
show: Boolean,
|
||||||
title: String,
|
title: String,
|
||||||
@ -20,10 +23,6 @@ VantComponent({
|
|||||||
closeOnClickOverlay: {
|
closeOnClickOverlay: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
value: true
|
value: true
|
||||||
},
|
|
||||||
safeAreaInsetBottom: {
|
|
||||||
type: Boolean,
|
|
||||||
value: true
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -24,21 +24,6 @@ VantComponent({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
computed: {
|
|
||||||
classes(): string {
|
|
||||||
const { type, size, block, plain, round, square, loading, disabled } = this.data;
|
|
||||||
return this.classNames('van-button', `van-button--${type}`, `van-button--${size}`, {
|
|
||||||
'van-button--block': block,
|
|
||||||
'van-button--round': round,
|
|
||||||
'van-button--plain': plain,
|
|
||||||
'van-button--square': square,
|
|
||||||
'van-button--loading': loading,
|
|
||||||
'van-button--disabled': disabled,
|
|
||||||
'van-button--unclickable': disabled || loading
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
onClick() {
|
onClick() {
|
||||||
if (!this.data.disabled && !this.data.loading) {
|
if (!this.data.disabled && !this.data.loading) {
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
|
<wxs src="../wxs/utils.wxs" module="utils" />
|
||||||
|
|
||||||
<button
|
<button
|
||||||
id="{{ id }}"
|
id="{{ id }}"
|
||||||
lang="{{ lang }}"
|
lang="{{ lang }}"
|
||||||
class="custom-class {{ classes }}"
|
class="custom-class {{ utils.bem('button', [type, size, { block, round, plain, square, loading, disabled, unclickable: disabled || loading }]) }}"
|
||||||
open-type="{{ openType }}"
|
open-type="{{ openType }}"
|
||||||
session-from="{{ sessionFrom }}"
|
session-from="{{ sessionFrom }}"
|
||||||
app-parameter="{{ appParameter }}"
|
app-parameter="{{ appParameter }}"
|
||||||
|
@ -24,7 +24,8 @@
|
|||||||
```
|
```
|
||||||
|
|
||||||
#### 高级用法
|
#### 高级用法
|
||||||
可以通过具名`slot`添加定制内容
|
|
||||||
|
可以通过插槽添加定制内容
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<van-card
|
<van-card
|
||||||
@ -47,7 +48,7 @@
|
|||||||
| 参数 | 说明 | 类型 | 默认值 |
|
| 参数 | 说明 | 类型 | 默认值 |
|
||||||
|-----------|-----------|-----------|-------------|
|
|-----------|-----------|-----------|-------------|
|
||||||
| thumb | 左侧图片 | `String` | - |
|
| thumb | 左侧图片 | `String` | - |
|
||||||
| thumb-mode | 左侧图片裁剪、缩放的模式,可选值参考小程序 image 组件 mode 属性值 | `String` | `scaleToFill` |
|
| thumb-mode | 左侧图片裁剪、缩放的模式,可选值参考小程序 image 组件 mode 属性值 | `String` | `aspectFit` |
|
||||||
| title | 标题 | `String` | - |
|
| title | 标题 | `String` | - |
|
||||||
| desc | 描述 | `String` | - |
|
| desc | 描述 | `String` | - |
|
||||||
| tag | 标签 | `String` | - |
|
| tag | 标签 | `String` | - |
|
||||||
|
@ -26,7 +26,7 @@ VantComponent({
|
|||||||
originPrice: String,
|
originPrice: String,
|
||||||
thumbMode: {
|
thumbMode: {
|
||||||
type: String,
|
type: String,
|
||||||
value: 'scaleToFill'
|
value: 'aspectFit'
|
||||||
},
|
},
|
||||||
currency: {
|
currency: {
|
||||||
type: String,
|
type: String,
|
||||||
|
@ -30,24 +30,6 @@ VantComponent({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
computed: {
|
|
||||||
cellClass(): string {
|
|
||||||
const { data } = this;
|
|
||||||
return this.classNames('van-cell', {
|
|
||||||
'van-cell--center': data.center,
|
|
||||||
'van-cell--required': data.required,
|
|
||||||
'van-cell--borderless': !data.border,
|
|
||||||
'van-cell--clickable': data.isLink || data.clickable,
|
|
||||||
[`van-cell--${data.size}`]: data.size
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
titleStyle(): string {
|
|
||||||
const { titleWidth } = this.data;
|
|
||||||
return titleWidth ? `max-width: ${titleWidth};min-width: ${titleWidth}` : '';
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
onClick(event: Weapp.Event) {
|
onClick(event: Weapp.Event) {
|
||||||
this.$emit('click', event.detail);
|
this.$emit('click', event.detail);
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
|
<wxs src="../wxs/utils.wxs" module="utils" />
|
||||||
|
|
||||||
<view
|
<view
|
||||||
class="custom-class {{ cellClass }}"
|
class="custom-class {{ utils.bem('cell', [size, { center, required, borderless: !border, clickable: isLink || clickable }]) }}"
|
||||||
style="{{ customStyle }}"
|
style="{{ customStyle }}"
|
||||||
bind:tap="onClick"
|
bind:tap="onClick"
|
||||||
>
|
>
|
||||||
@ -12,7 +14,7 @@
|
|||||||
<slot wx:else name="icon" />
|
<slot wx:else name="icon" />
|
||||||
|
|
||||||
<view
|
<view
|
||||||
style="{{ titleStyle }}"
|
style="{{ titleWidth ? 'max-width:' + titleWidth + ';min-width:' + titleWidth : '' }}"
|
||||||
class="van-cell__title title-class"
|
class="van-cell__title title-class"
|
||||||
>
|
>
|
||||||
<block wx:if="{{ title }}">
|
<block wx:if="{{ title }}">
|
||||||
|
@ -24,18 +24,6 @@ VantComponent({
|
|||||||
},
|
},
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
iconClass(): string {
|
|
||||||
const { disabled, value, shape } = this.data;
|
|
||||||
return this.classNames(
|
|
||||||
'van-checkbox__icon',
|
|
||||||
`van-checkbox__icon--${shape}`,
|
|
||||||
{
|
|
||||||
'van-checkbox__icon--disabled': disabled,
|
|
||||||
'van-checkbox__icon--checked': value
|
|
||||||
}
|
|
||||||
);
|
|
||||||
},
|
|
||||||
|
|
||||||
iconStyle(): string {
|
iconStyle(): string {
|
||||||
const { value, disabled, checkedColor } = this.data;
|
const { value, disabled, checkedColor } = this.data;
|
||||||
if (checkedColor && value && !disabled) {
|
if (checkedColor && value && !disabled) {
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
|
<wxs src="../wxs/utils.wxs" module="utils" />
|
||||||
|
|
||||||
<view class="van-checkbox custom-class">
|
<view class="van-checkbox custom-class">
|
||||||
<view class="van-checkbox__icon-wrap" bindtap="toggle">
|
<view class="van-checkbox__icon-wrap" bindtap="toggle">
|
||||||
<slot wx:if="{{ useIconSlot }}" name="icon" />
|
<slot wx:if="{{ useIconSlot }}" name="icon" />
|
||||||
<van-icon
|
<van-icon
|
||||||
wx:else
|
wx:else
|
||||||
name="success"
|
name="success"
|
||||||
class="{{ iconClass }}"
|
class="{{ utils.bem('checkbox__icon', [shape, { disabled, checked: value }]) }}"
|
||||||
style="{{ iconStyle }}"
|
style="{{ iconStyle }}"
|
||||||
custom-class="icon-class"
|
custom-class="icon-class"
|
||||||
custom-style="line-height: 20px;"
|
custom-style="line-height: 20px;"
|
||||||
|
@ -15,16 +15,6 @@ VantComponent({
|
|||||||
style: ''
|
style: ''
|
||||||
},
|
},
|
||||||
|
|
||||||
computed: {
|
|
||||||
classes(): string {
|
|
||||||
const { span, offset } = this.data;
|
|
||||||
return this.classNames('van-col', {
|
|
||||||
[`van-col--${span}`]: span,
|
|
||||||
[`van-col--offset-${offset}`]: offset
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
setGutter(gutter: number) {
|
setGutter(gutter: number) {
|
||||||
const padding = `${gutter / 2}px`;
|
const padding = `${gutter / 2}px`;
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
|
<wxs src="../wxs/utils.wxs" module="utils" />
|
||||||
|
|
||||||
<view
|
<view
|
||||||
class="custom-class {{ classes }}"
|
class="custom-class {{ utils.bem('col', [span]) }} {{ offset ? 'van-col--offset-' + offset : '' }}"
|
||||||
style="{{ style }}"
|
style="{{ style }}"
|
||||||
>
|
>
|
||||||
<slot />
|
<slot />
|
||||||
|
@ -12,11 +12,11 @@ VantComponent({
|
|||||||
},
|
},
|
||||||
|
|
||||||
props: {
|
props: {
|
||||||
name: [String, Number],
|
name: null,
|
||||||
|
title: null,
|
||||||
|
value: null,
|
||||||
icon: String,
|
icon: String,
|
||||||
label: String,
|
label: String,
|
||||||
title: [String, Number],
|
|
||||||
value: [String, Number],
|
|
||||||
disabled: Boolean,
|
disabled: Boolean,
|
||||||
border: {
|
border: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
@ -33,16 +33,6 @@ VantComponent({
|
|||||||
expanded: false
|
expanded: false
|
||||||
},
|
},
|
||||||
|
|
||||||
computed: {
|
|
||||||
titleClass() {
|
|
||||||
const { disabled, expanded } = this.data;
|
|
||||||
return this.classNames('van-collapse-item__title', {
|
|
||||||
'van-collapse-item__title--disabled': disabled,
|
|
||||||
'van-collapse-item__title--expanded': expanded
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
updateExpanded() {
|
updateExpanded() {
|
||||||
if (!this.parent) {
|
if (!this.parent) {
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
<wxs src="../wxs/utils.wxs" module="utils" />
|
||||||
|
|
||||||
<view class="van-collapse-item van-hairline--top custom-class">
|
<view class="van-collapse-item van-hairline--top custom-class">
|
||||||
<van-cell
|
<van-cell
|
||||||
title="{{ title }}"
|
title="{{ title }}"
|
||||||
@ -6,7 +8,7 @@
|
|||||||
value="{{ value }}"
|
value="{{ value }}"
|
||||||
label="{{ label }}"
|
label="{{ label }}"
|
||||||
border="{{ border && expanded }}"
|
border="{{ border && expanded }}"
|
||||||
class="{{ titleClass }}"
|
class="{{ utils.bem('collapse-item__title', { disabled, expanded }) }}"
|
||||||
right-icon-class="van-cell__right-icon"
|
right-icon-class="van-cell__right-icon"
|
||||||
custom-class="van-cell"
|
custom-class="van-cell"
|
||||||
bind:click="onClick"
|
bind:click="onClick"
|
||||||
|
@ -32,6 +32,11 @@
|
|||||||
Page({
|
Page({
|
||||||
data: {
|
data: {
|
||||||
activeNames: ['1']
|
activeNames: ['1']
|
||||||
|
},
|
||||||
|
onChange(event) {
|
||||||
|
this.setData({
|
||||||
|
activeNames: event.detail
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
@ -57,6 +62,11 @@ Page({
|
|||||||
Page({
|
Page({
|
||||||
data: {
|
data: {
|
||||||
activeName: '1'
|
activeName: '1'
|
||||||
|
},
|
||||||
|
onChange(event) {
|
||||||
|
this.setData({
|
||||||
|
activeNames: event.detail
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
@ -75,6 +85,19 @@ Page({
|
|||||||
</van-collapse>
|
</van-collapse>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
``` javascript
|
||||||
|
Page({
|
||||||
|
data: {
|
||||||
|
activeName: ['1']
|
||||||
|
},
|
||||||
|
onChange(event) {
|
||||||
|
this.setData({
|
||||||
|
activeNames: event.detail
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### Collapse API
|
### Collapse API
|
||||||
|
@ -1,29 +0,0 @@
|
|||||||
const hasOwn = {}.hasOwnProperty;
|
|
||||||
|
|
||||||
export function classNames(): string {
|
|
||||||
const classes = [];
|
|
||||||
|
|
||||||
for (let i = 0; i < arguments.length; i++) {
|
|
||||||
const arg = arguments[i];
|
|
||||||
if (!arg) continue;
|
|
||||||
|
|
||||||
const argType = typeof arg;
|
|
||||||
|
|
||||||
if (argType === 'string' || argType === 'number') {
|
|
||||||
classes.push(arg);
|
|
||||||
} else if (Array.isArray(arg) && arg.length) {
|
|
||||||
const inner = classNames.apply(null, arg);
|
|
||||||
if (inner) {
|
|
||||||
classes.push(inner);
|
|
||||||
}
|
|
||||||
} else if (argType === 'object') {
|
|
||||||
for (const key in arg) {
|
|
||||||
if (hasOwn.call(arg, key) && arg[key]) {
|
|
||||||
classes.push(key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return classes.join(' ');
|
|
||||||
};
|
|
@ -1,5 +0,0 @@
|
|||||||
function isSrc(url) {
|
|
||||||
return url.indexOf('http') === 0 || url.indexOf('data:image') === 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports.isSrc = isSrc;
|
|
@ -13,6 +13,8 @@
|
|||||||
|
|
||||||
#### 选择完整时间
|
#### 选择完整时间
|
||||||
|
|
||||||
|
`value` 为时间戳
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<van-datetime-picker
|
<van-datetime-picker
|
||||||
type="datetime"
|
type="datetime"
|
||||||
@ -43,6 +45,8 @@ Page({
|
|||||||
|
|
||||||
#### 选择日期(年月日)
|
#### 选择日期(年月日)
|
||||||
|
|
||||||
|
`value` 为时间戳
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<van-datetime-picker
|
<van-datetime-picker
|
||||||
type="date"
|
type="date"
|
||||||
@ -69,6 +73,8 @@ Page({
|
|||||||
|
|
||||||
#### 选择日期(年月)
|
#### 选择日期(年月)
|
||||||
|
|
||||||
|
`value` 为时间戳
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<van-datetime-picker
|
<van-datetime-picker
|
||||||
type="year-month"
|
type="year-month"
|
||||||
@ -95,6 +101,8 @@ Page({
|
|||||||
|
|
||||||
#### 选择时间
|
#### 选择时间
|
||||||
|
|
||||||
|
`value` 为字符串
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<van-datetime-picker
|
<van-datetime-picker
|
||||||
type="time"
|
type="time"
|
||||||
@ -125,7 +133,8 @@ Page({
|
|||||||
|
|
||||||
| 参数 | 说明 | 类型 | 默认值 |
|
| 参数 | 说明 | 类型 | 默认值 |
|
||||||
|------|------|------|------|------|
|
|------|------|------|------|------|
|
||||||
| type | 类型,可选值为 `date` <br> `time` `year-month` | `String` | `datetime` |
|
| value | 当前选中值 | `String | Number` | - |
|
||||||
|
| type | 类型,可选值为 `date` `time` `year-month` <br> <strong>不建议动态修改</strong> | `String` | `datetime` |
|
||||||
| min-date | 可选的最小时间,精确到分钟 | `Number` | 十年前 |
|
| min-date | 可选的最小时间,精确到分钟 | `Number` | 十年前 |
|
||||||
| max-date | 可选的最大时间,精确到分钟 | `Number` | 十年后 |
|
| max-date | 可选的最大时间,精确到分钟 | `Number` | 十年后 |
|
||||||
| min-hour | 可选的最小小时,针对 time 类型 | `Number` | `0` |
|
| min-hour | 可选的最小小时,针对 time 类型 | `Number` | `0` |
|
||||||
|
@ -95,7 +95,9 @@ VantComponent({
|
|||||||
this.close();
|
this.close();
|
||||||
}
|
}
|
||||||
this.$emit('close', action);
|
this.$emit('close', action);
|
||||||
this.$emit(action);
|
|
||||||
|
//把 dialog 实例传递出去,可以通过 stopLoading() 在外部关闭按钮的 loading
|
||||||
|
this.$emit(action, { dialog: this });
|
||||||
|
|
||||||
const callback = this.data[action === 'confirm' ? 'onConfirm' : 'onCancel'];
|
const callback = this.data[action === 'confirm' ? 'onConfirm' : 'onCancel'];
|
||||||
if (callback) {
|
if (callback) {
|
||||||
|
@ -164,6 +164,7 @@ Page({
|
|||||||
| adjust-position | 键盘弹起时,是否自动上推页面 | `Boolean` | `true` |
|
| adjust-position | 键盘弹起时,是否自动上推页面 | `Boolean` | `true` |
|
||||||
| use-icon-slot | 是否使用 icon slot | `Boolean` | `false` |
|
| use-icon-slot | 是否使用 icon slot | `Boolean` | `false` |
|
||||||
| use-button-slot | 是否使用 button slot | `Boolean` | `false` |
|
| use-button-slot | 是否使用 button slot | `Boolean` | `false` |
|
||||||
|
| show-confirm-bar | 是否显示键盘上方带有”完成“按钮那一栏,只对 textarea 有效 | `Boolean` | `true` |
|
||||||
|
|
||||||
### Event
|
### Event
|
||||||
|
|
||||||
|
@ -37,6 +37,10 @@
|
|||||||
&--right {
|
&--right {
|
||||||
text-align: right;
|
text-align: right;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&--error {
|
||||||
|
color: @red;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&__clear-root {
|
&__clear-root {
|
||||||
@ -78,8 +82,4 @@
|
|||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
}
|
}
|
||||||
|
|
||||||
&--error {
|
|
||||||
color: @red;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,10 @@ VantComponent({
|
|||||||
customStyle: String,
|
customStyle: String,
|
||||||
useIconSlot: Boolean,
|
useIconSlot: Boolean,
|
||||||
useButtonSlot: Boolean,
|
useButtonSlot: Boolean,
|
||||||
|
showConfirmBar: {
|
||||||
|
type: Boolean,
|
||||||
|
value: true
|
||||||
|
},
|
||||||
placeholderStyle: String,
|
placeholderStyle: String,
|
||||||
adjustPosition: {
|
adjustPosition: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
@ -60,18 +64,6 @@ VantComponent({
|
|||||||
showClear: false
|
showClear: false
|
||||||
},
|
},
|
||||||
|
|
||||||
computed: {
|
|
||||||
inputClass(): string {
|
|
||||||
const { data } = this;
|
|
||||||
return this.classNames('input-class', 'van-field__input', {
|
|
||||||
'van-field--error': data.error,
|
|
||||||
'van-field__textarea': data.type === 'textarea',
|
|
||||||
'van-field__input--disabled': data.disabled,
|
|
||||||
[`van-field__input--${data.inputAlign}`]: data.inputAlign
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
beforeCreate() {
|
beforeCreate() {
|
||||||
this.focused = false;
|
this.focused = false;
|
||||||
},
|
},
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
<wxs src="../wxs/utils.wxs" module="utils" />
|
||||||
|
|
||||||
<van-cell
|
<van-cell
|
||||||
icon="{{ leftIcon }}"
|
icon="{{ leftIcon }}"
|
||||||
title="{{ label }}"
|
title="{{ label }}"
|
||||||
@ -14,7 +16,7 @@
|
|||||||
<view class="van-field__body {{ type === 'textarea' ? 'van-field__body--textarea' : '' }}">
|
<view class="van-field__body {{ type === 'textarea' ? 'van-field__body--textarea' : '' }}">
|
||||||
<textarea
|
<textarea
|
||||||
wx:if="{{ type === 'textarea' }}"
|
wx:if="{{ type === 'textarea' }}"
|
||||||
class="{{ inputClass }}"
|
class="input-class {{ utils.bem('field__input', [inputAlign, { disabled, error }]) }}"
|
||||||
fixed="{{ fixed }}"
|
fixed="{{ fixed }}"
|
||||||
focus="{{ focus }}"
|
focus="{{ focus }}"
|
||||||
value="{{ value }}"
|
value="{{ value }}"
|
||||||
@ -23,9 +25,10 @@
|
|||||||
auto-height="{{ autosize }}"
|
auto-height="{{ autosize }}"
|
||||||
placeholder="{{ placeholder }}"
|
placeholder="{{ placeholder }}"
|
||||||
placeholder-style="{{ placeholderStyle }}"
|
placeholder-style="{{ placeholderStyle }}"
|
||||||
placeholder-class="{{ error ? 'van-field--error' : '' }}"
|
placeholder-class="{{ error ? 'van-field__input--error' : '' }}"
|
||||||
cursor-spacing="{{ cursorSpacing }}"
|
cursor-spacing="{{ cursorSpacing }}"
|
||||||
adjust-position="{{ adjustPosition }}"
|
adjust-position="{{ adjustPosition }}"
|
||||||
|
show-confirm-bar="{{ showConfirmBar }}"
|
||||||
bindinput="onInput"
|
bindinput="onInput"
|
||||||
bind:blur="onBlur"
|
bind:blur="onBlur"
|
||||||
bind:focus="onFocus"
|
bind:focus="onFocus"
|
||||||
@ -33,7 +36,7 @@
|
|||||||
/>
|
/>
|
||||||
<input
|
<input
|
||||||
wx:else
|
wx:else
|
||||||
class="{{ inputClass }}"
|
class="input-class {{ utils.bem('field__input', [inputAlign, { disabled, error }]) }}"
|
||||||
type="{{ type }}"
|
type="{{ type }}"
|
||||||
focus="{{ focus }}"
|
focus="{{ focus }}"
|
||||||
value="{{ value }}"
|
value="{{ value }}"
|
||||||
@ -41,7 +44,7 @@
|
|||||||
maxlength="{{ maxlength }}"
|
maxlength="{{ maxlength }}"
|
||||||
placeholder="{{ placeholder }}"
|
placeholder="{{ placeholder }}"
|
||||||
placeholder-style="{{ placeholderStyle }}"
|
placeholder-style="{{ placeholderStyle }}"
|
||||||
placeholder-class="{{ error ? 'van-field--error' : '' }}"
|
placeholder-class="{{ error ? 'van-field__input--error' : '' }}"
|
||||||
confirm-type="{{ confirmType }}"
|
confirm-type="{{ confirmType }}"
|
||||||
confirm-hold="{{ confirmHold }}"
|
confirm-hold="{{ confirmHold }}"
|
||||||
cursor-spacing="{{ cursorSpacing }}"
|
cursor-spacing="{{ cursorSpacing }}"
|
||||||
|
@ -1,19 +1,6 @@
|
|||||||
import { VantComponent } from '../common/component';
|
import { VantComponent } from '../common/component';
|
||||||
|
import { iphonex } from '../mixins/iphonex';
|
||||||
|
|
||||||
VantComponent({
|
VantComponent({
|
||||||
props: {
|
mixins: [iphonex]
|
||||||
safeAreaInsetBottom: {
|
|
||||||
type: Boolean,
|
|
||||||
value: true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
computed: {
|
|
||||||
rootClass() {
|
|
||||||
const { safeAreaInsetBottom, isIPhoneX } = this.data;
|
|
||||||
return this.classNames('van-goods-action', 'custom-class', {
|
|
||||||
[`van-goods-action--safe`]: isIPhoneX && safeAreaInsetBottom
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
<view class="{{ rootClass }}">
|
<wxs src="../wxs/utils.wxs" module="utils" />
|
||||||
|
|
||||||
|
<view class="custom-class {{ utils.bem('goods-action', { safe: isIPhoneX && safeAreaInsetBottom }) }}">
|
||||||
<slot />
|
<slot />
|
||||||
</view>
|
</view>
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
<wxs src="../wxs/utils.wxs" module="utils" />
|
||||||
|
|
||||||
<view
|
<view
|
||||||
class="custom-class {{ classPrefix }} {{ utils.isSrc(name) ? 'van-icon--image' : classPrefix + '-' + name }}"
|
class="custom-class {{ classPrefix }} {{ utils.isSrc(name) ? 'van-icon--image' : classPrefix + '-' + name }}"
|
||||||
style="{{ color ? 'color: ' + color + ';' : '' }}{{ size ? 'font-size: ' + size + ';' : '' }}{{ customStyle }}"
|
style="{{ color ? 'color: ' + color + ';' : '' }}{{ size ? 'font-size: ' + size + ';' : '' }}{{ customStyle }}"
|
||||||
@ -14,5 +16,3 @@
|
|||||||
src="{{ name }}"
|
src="{{ name }}"
|
||||||
/>
|
/>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<wxs src="../common/utils.wxs" module="utils" />
|
|
||||||
|
@ -1,24 +1,5 @@
|
|||||||
import { classNames } from '../common/class-names';
|
|
||||||
|
|
||||||
export const basic = Behavior({
|
export const basic = Behavior({
|
||||||
created() {
|
|
||||||
wx.getSystemInfo({
|
|
||||||
success: ({ model, screenHeight }) => {
|
|
||||||
const isIphoneX = /iphone x/i.test(model);
|
|
||||||
const isIphoneNew = /iPhone11/i.test(model) && screenHeight === 812;
|
|
||||||
|
|
||||||
if (isIphoneX || isIphoneNew) {
|
|
||||||
this.set({
|
|
||||||
isIPhoneX: true
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
classNames,
|
|
||||||
|
|
||||||
$emit() {
|
$emit() {
|
||||||
this.triggerEvent.apply(this, arguments);
|
this.triggerEvent.apply(this, arguments);
|
||||||
},
|
},
|
||||||
|
34
packages/mixins/iphonex.ts
Normal file
34
packages/mixins/iphonex.ts
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
let isIPhoneX = null;
|
||||||
|
|
||||||
|
function getIsIPhoneX() {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
if (isIPhoneX !== null) {
|
||||||
|
resolve(isIPhoneX);
|
||||||
|
} else {
|
||||||
|
wx.getSystemInfo({
|
||||||
|
success: ({ model, screenHeight }) => {
|
||||||
|
const iphoneX = /iphone x/i.test(model);
|
||||||
|
const iphoneNew = /iPhone11/i.test(model) && screenHeight === 812;
|
||||||
|
isIPhoneX = iphoneX || iphoneNew;
|
||||||
|
resolve(isIPhoneX);
|
||||||
|
},
|
||||||
|
fail: reject
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export const iphonex = Behavior({
|
||||||
|
properties: {
|
||||||
|
safeAreaInsetBottom: {
|
||||||
|
type: Boolean,
|
||||||
|
value: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
created() {
|
||||||
|
getIsIPhoneX().then(isIPhoneX => {
|
||||||
|
this.set({ isIPhoneX });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
@ -1,8 +1,9 @@
|
|||||||
import { VantComponent } from '../common/component';
|
import { VantComponent } from '../common/component';
|
||||||
import { transition } from '../mixins/transition';
|
import { transition } from '../mixins/transition';
|
||||||
|
import { iphonex } from '../mixins/iphonex';
|
||||||
|
|
||||||
VantComponent({
|
VantComponent({
|
||||||
mixins: [transition(false)],
|
mixins: [transition(false), iphonex],
|
||||||
|
|
||||||
props: {
|
props: {
|
||||||
transition: String,
|
transition: String,
|
||||||
@ -23,20 +24,6 @@ VantComponent({
|
|||||||
position: {
|
position: {
|
||||||
type: String,
|
type: String,
|
||||||
value: 'center'
|
value: 'center'
|
||||||
},
|
|
||||||
safeAreaInsetBottom: {
|
|
||||||
type: Boolean,
|
|
||||||
value: true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
computed: {
|
|
||||||
popupClass() {
|
|
||||||
const { position, safeAreaInsetBottom, isIPhoneX } = this.data;
|
|
||||||
return this.classNames('custom-class', 'van-popup', {
|
|
||||||
[`van-popup--${position}`]: position,
|
|
||||||
[`van-popup--safe`]: isIPhoneX && safeAreaInsetBottom && position === 'bottom'
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
<wxs src="../wxs/utils.wxs" module="utils" />
|
||||||
|
|
||||||
<van-overlay
|
<van-overlay
|
||||||
wx:if="{{ inited && overlay }}"
|
wx:if="{{ inited && overlay }}"
|
||||||
mask
|
mask
|
||||||
@ -8,7 +10,7 @@
|
|||||||
/>
|
/>
|
||||||
<view
|
<view
|
||||||
wx:if="{{ inited }}"
|
wx:if="{{ inited }}"
|
||||||
class="{{ popupClass }}"
|
class="custom-class {{ utils.bem('popup', [position, { safe: isIPhoneX && safeAreaInsetBottom && position === 'bottom' }]) }}"
|
||||||
style="z-index: {{ zIndex }}; -webkit-animation: van-{{ transition || position }}-{{ type }} {{ duration }}ms both; animation: van-{{ transition || position }}-{{ type }} {{ duration }}ms both; {{ display ? '' : 'display: none;' }}{{ customStyle }}"
|
style="z-index: {{ zIndex }}; -webkit-animation: van-{{ transition || position }}-{{ type }} {{ duration }}ms both; animation: van-{{ transition || position }}-{{ type }} {{ duration }}ms both; {{ display ? '' : 'display: none;' }}{{ customStyle }}"
|
||||||
bind:animationend="onAnimationEnd"
|
bind:animationend="onAnimationEnd"
|
||||||
>
|
>
|
||||||
|
@ -19,17 +19,6 @@ VantComponent({
|
|||||||
checkedColor: String
|
checkedColor: String
|
||||||
},
|
},
|
||||||
|
|
||||||
computed: {
|
|
||||||
iconClass(): string {
|
|
||||||
const { disabled, name, value } = this.data;
|
|
||||||
return this.classNames('van-radio__icon', {
|
|
||||||
'van-radio__icon--disabled': disabled,
|
|
||||||
'van-radio__icon--checked': !disabled && name === value,
|
|
||||||
'van-radio__icon--check': !disabled && name !== value
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
emitChange(value) {
|
emitChange(value) {
|
||||||
const instance = this.getRelationNodes('../radio-group/index')[0] || this;
|
const instance = this.getRelationNodes('../radio-group/index')[0] || this;
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
<wxs src="../wxs/utils.wxs" module="utils" />
|
||||||
|
|
||||||
<view class="van-radio custom-class">
|
<view class="van-radio custom-class">
|
||||||
<view class="van-radio__input">
|
<view class="van-radio__input">
|
||||||
<radio-group bindchange="onChange">
|
<radio-group bindchange="onChange">
|
||||||
@ -9,7 +11,7 @@
|
|||||||
/>
|
/>
|
||||||
</radio-group>
|
</radio-group>
|
||||||
<van-icon
|
<van-icon
|
||||||
class="{{ iconClass }}"
|
class="{{ utils.bem('radio__icon', { disabled, checked: !disabled && name === value, check: !disabled && name !== value }) }}"
|
||||||
custom-class="icon-class"
|
custom-class="icon-class"
|
||||||
color="{{ value === name ? checkedColor : '' }}"
|
color="{{ value === name ? checkedColor : '' }}"
|
||||||
name="{{ value === name ? 'checked' : 'check' }}"
|
name="{{ value === name ? 'checked' : 'check' }}"
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
import { VantComponent } from '../common/component';
|
import { VantComponent } from '../common/component';
|
||||||
|
import { iphonex } from '../mixins/iphonex';
|
||||||
|
|
||||||
VantComponent({
|
VantComponent({
|
||||||
|
mixins: [iphonex],
|
||||||
|
|
||||||
classes: [
|
classes: [
|
||||||
'bar-class',
|
'bar-class',
|
||||||
'price-class',
|
'price-class',
|
||||||
@ -22,10 +25,6 @@ VantComponent({
|
|||||||
buttonType: {
|
buttonType: {
|
||||||
type: String,
|
type: String,
|
||||||
value: 'danger'
|
value: 'danger'
|
||||||
},
|
|
||||||
safeAreaInsetBottom: {
|
|
||||||
type: Boolean,
|
|
||||||
value: true
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -41,13 +40,6 @@ VantComponent({
|
|||||||
tipStr() {
|
tipStr() {
|
||||||
const { tip } = this.data;
|
const { tip } = this.data;
|
||||||
return typeof tip === 'string' ? tip : '';
|
return typeof tip === 'string' ? tip : '';
|
||||||
},
|
|
||||||
|
|
||||||
barClass() {
|
|
||||||
const { isIPhoneX, safeAreaInsetBottom } = this.data;
|
|
||||||
return this.classNames('van-submit-bar__bar', 'bar-class', {
|
|
||||||
'van-submit-bar__bar--safe': safeAreaInsetBottom && isIPhoneX
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
<wxs src="../wxs/utils.wxs" module="utils" />
|
||||||
|
|
||||||
<view class="van-submit-bar custom-class">
|
<view class="van-submit-bar custom-class">
|
||||||
<slot name="top" />
|
<slot name="top" />
|
||||||
|
|
||||||
@ -5,7 +7,7 @@
|
|||||||
{{ tipStr }}<slot name="tip" />
|
{{ tipStr }}<slot name="tip" />
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view class="{{ barClass }}">
|
<view class="bar-class {{ utils.bem('submit-bar__bar', { safe: safeAreaInsetBottom && isIPhoneX }) }}">
|
||||||
<slot />
|
<slot />
|
||||||
<view class="van-submit-bar__text">
|
<view class="van-submit-bar__text">
|
||||||
<block wx:if="{{ hasPrice }}">
|
<block wx:if="{{ hasPrice }}">
|
||||||
|
@ -24,13 +24,6 @@ VantComponent({
|
|||||||
},
|
},
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
classes(): string {
|
|
||||||
return this.classNames('van-switch', {
|
|
||||||
'van-switch--on': this.data.checked,
|
|
||||||
'van-switch--disabled': this.data.disabled
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
style() {
|
style() {
|
||||||
const backgroundColor = this.data.checked ? this.data.activeColor : this.data.inactiveColor;
|
const backgroundColor = this.data.checked ? this.data.activeColor : this.data.inactiveColor;
|
||||||
return `font-size: ${this.data.size}; ${ backgroundColor ? `background-color: ${backgroundColor}` : '' }`
|
return `font-size: ${this.data.size}; ${ backgroundColor ? `background-color: ${backgroundColor}` : '' }`
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
|
<wxs src="../wxs/utils.wxs" module="utils" />
|
||||||
|
|
||||||
<view
|
<view
|
||||||
style="{{ style }}"
|
style="{{ style }}"
|
||||||
class="custom-class {{ classes }}"
|
class="custom-class {{ utils.bem('switch', { on: checked, disabled }) }}"
|
||||||
bind:tap="onClick"
|
bind:tap="onClick"
|
||||||
>
|
>
|
||||||
<view class="van-switch__node node-class">
|
<view class="van-switch__node node-class">
|
||||||
|
@ -116,7 +116,7 @@ Page({
|
|||||||
通过`sticky`属性可以开启粘性布局,粘性布局下,当 Tab 滚动到顶部时会自动吸顶
|
通过`sticky`属性可以开启粘性布局,粘性布局下,当 Tab 滚动到顶部时会自动吸顶
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<van-tabs sticky>
|
<van-tabs sticky scroll-top="{{ scrollTop }}">
|
||||||
<van-tab title="标签 1">内容 1</van-tab>
|
<van-tab title="标签 1">内容 1</van-tab>
|
||||||
<van-tab title="标签 2">内容 2</van-tab>
|
<van-tab title="标签 2">内容 2</van-tab>
|
||||||
<van-tab title="标签 3">内容 3</van-tab>
|
<van-tab title="标签 3">内容 3</van-tab>
|
||||||
@ -124,6 +124,19 @@ Page({
|
|||||||
</van-tabs>
|
</van-tabs>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
Page({
|
||||||
|
data: {
|
||||||
|
scrollTop: 0
|
||||||
|
},
|
||||||
|
onPageScroll(event) {
|
||||||
|
this.setData({
|
||||||
|
scrollTop: event.scrollTop
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
#### 切换动画
|
#### 切换动画
|
||||||
|
|
||||||
可以通过`animated`来设置是否启用切换tab时的动画。
|
可以通过`animated`来设置是否启用切换tab时的动画。
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
import { VantComponent } from '../common/component';
|
import { VantComponent } from '../common/component';
|
||||||
|
import { iphonex } from '../mixins/iphonex';
|
||||||
|
|
||||||
VantComponent({
|
VantComponent({
|
||||||
|
mixins: [iphonex],
|
||||||
|
|
||||||
relation: {
|
relation: {
|
||||||
name: 'tabbar-item',
|
name: 'tabbar-item',
|
||||||
type: 'descendant',
|
type: 'descendant',
|
||||||
@ -27,10 +30,6 @@ VantComponent({
|
|||||||
zIndex: {
|
zIndex: {
|
||||||
type: Number,
|
type: Number,
|
||||||
value: 1
|
value: 1
|
||||||
},
|
|
||||||
safeAreaInsetBottom: {
|
|
||||||
type: Boolean,
|
|
||||||
value: true
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -39,16 +38,6 @@ VantComponent({
|
|||||||
currentActive: -1
|
currentActive: -1
|
||||||
},
|
},
|
||||||
|
|
||||||
computed: {
|
|
||||||
tabbarClass() {
|
|
||||||
const { fixed, isIPhoneX, safeAreaInsetBottom } = this.data;
|
|
||||||
return this.classNames('custom-class', 'van-tabbar', 'van-hairline--top-bottom', {
|
|
||||||
'van-tabbar--fixed': fixed,
|
|
||||||
'van-tabbar--safe': isIPhoneX && safeAreaInsetBottom
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
watch: {
|
watch: {
|
||||||
active(active) {
|
active(active) {
|
||||||
this.set({ currentActive: active });
|
this.set({ currentActive: active });
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
|
<wxs src="../wxs/utils.wxs" module="utils" />
|
||||||
|
|
||||||
<view
|
<view
|
||||||
class="{{ tabbarClass }}"
|
class="custom-class van-hairline--top-bottom {{ utils.bem('tabbar', { fixed, safe: isIPhoneX && safeAreaInsetBottom }) }}"
|
||||||
style="{{ zIndex ? 'z-index: ' + zIndex : '' }}"
|
style="{{ zIndex ? 'z-index: ' + zIndex : '' }}"
|
||||||
>
|
>
|
||||||
<slot />
|
<slot />
|
||||||
|
@ -19,17 +19,6 @@ VantComponent({
|
|||||||
},
|
},
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
classes() {
|
|
||||||
const { data } = this;
|
|
||||||
return this.classNames('van-tag', {
|
|
||||||
'van-tag--mark': data.mark,
|
|
||||||
'van-tag--plain': data.plain,
|
|
||||||
'van-tag--round': data.round,
|
|
||||||
[`van-tag--${data.size}`]: data.size,
|
|
||||||
'van-hairline--surround': data.plain
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
style() {
|
style() {
|
||||||
const color = this.data.color || COLOR_MAP[this.data.type] || DEFAULT_COLOR;
|
const color = this.data.color || COLOR_MAP[this.data.type] || DEFAULT_COLOR;
|
||||||
const key = this.data.plain ? 'color' : 'background-color';
|
const key = this.data.plain ? 'color' : 'background-color';
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
|
<wxs src="../wxs/utils.wxs" module="utils" />
|
||||||
|
|
||||||
<view
|
<view
|
||||||
class="custom-class {{ classes }}"
|
class="custom-class {{ utils.bem('tag', [size, { mark, plain, round }]) }} {{ plain ? 'van-hairline--surround' : '' }}"
|
||||||
style="{{ style }}"
|
style="{{ style }}"
|
||||||
>
|
>
|
||||||
<slot />
|
<slot />
|
||||||
|
5
packages/wxs/array.wxs
Normal file
5
packages/wxs/array.wxs
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
function isArray(obj) {
|
||||||
|
return obj && obj.constructor === 'Array';
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.isArray = isArray;
|
38
packages/wxs/bem.wxs
Normal file
38
packages/wxs/bem.wxs
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
var array = require('./array.wxs');
|
||||||
|
var object = require('./object.wxs');
|
||||||
|
var PREFIX = 'van-';
|
||||||
|
|
||||||
|
function join(name, mods) {
|
||||||
|
name = PREFIX + name;
|
||||||
|
mods = mods.map(function(mod) {
|
||||||
|
return name + '--' + mod;
|
||||||
|
});
|
||||||
|
mods.unshift(name);
|
||||||
|
return mods.join(' ');
|
||||||
|
}
|
||||||
|
|
||||||
|
function traversing(mods, conf) {
|
||||||
|
if (!conf) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof conf === 'string' || typeof conf === 'number') {
|
||||||
|
mods.push(conf);
|
||||||
|
} else if (array.isArray(conf)) {
|
||||||
|
conf.forEach(function(item) {
|
||||||
|
traversing(mods, item);
|
||||||
|
});
|
||||||
|
} else if (typeof conf === 'object') {
|
||||||
|
object.keys(conf).forEach(function(key) {
|
||||||
|
conf[key] && mods.push(key);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function bem(name, conf) {
|
||||||
|
var mods = [];
|
||||||
|
traversing(mods, conf);
|
||||||
|
return join(name, mods);
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.bem = bem;
|
52
packages/wxs/memoize.wxs
Normal file
52
packages/wxs/memoize.wxs
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
/**
|
||||||
|
* Simple memoize
|
||||||
|
* wxs doesn't support fn.apply, so this memoize only support up to 2 args
|
||||||
|
*/
|
||||||
|
|
||||||
|
function isPrimitive(value) {
|
||||||
|
var type = typeof value;
|
||||||
|
return (
|
||||||
|
type === 'boolean' ||
|
||||||
|
type === 'number' ||
|
||||||
|
type === 'string' ||
|
||||||
|
type === 'undefined' ||
|
||||||
|
value === null
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// mock simple fn.call in wxs
|
||||||
|
function call(fn, args) {
|
||||||
|
if (args.length === 2) {
|
||||||
|
return fn(args[0], args[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.length === 1) {
|
||||||
|
return fn(args[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return fn();
|
||||||
|
}
|
||||||
|
|
||||||
|
function serializer(args) {
|
||||||
|
if (args.length === 1 && isPrimitive(args[0])) {
|
||||||
|
return args[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
return JSON.stringify(args.length === 1 ? args[0] : args);
|
||||||
|
}
|
||||||
|
|
||||||
|
function memoize(fn) {
|
||||||
|
var cache = {};
|
||||||
|
|
||||||
|
return function() {
|
||||||
|
var key = serializer(arguments);
|
||||||
|
|
||||||
|
if (cache[key] === undefined) {
|
||||||
|
cache[key] = call(fn, arguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
return cache[key];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.memoize = memoize;
|
13
packages/wxs/object.wxs
Normal file
13
packages/wxs/object.wxs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
/* eslint-disable */
|
||||||
|
var REGEXP = getRegExp('{|}|"', 'g');
|
||||||
|
|
||||||
|
function keys(obj) {
|
||||||
|
return JSON.stringify(obj)
|
||||||
|
.replace(REGEXP, '')
|
||||||
|
.split(',')
|
||||||
|
.map(function(item) {
|
||||||
|
return item.split(':')[0];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.keys = keys;
|
12
packages/wxs/utils.wxs
Normal file
12
packages/wxs/utils.wxs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
var bem = require('./bem.wxs').bem;
|
||||||
|
var memoize = require('./memoize.wxs').memoize;
|
||||||
|
|
||||||
|
function isSrc(url) {
|
||||||
|
return url.indexOf('http') === 0 || url.indexOf('data:image') === 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
bem: memoize(bem),
|
||||||
|
isSrc: isSrc,
|
||||||
|
memoize: memoize
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user