Compare commits

...

6 Commits

Author SHA1 Message Date
landluck
e67ff09e37 docs(changelog): @vant/weapp 1.10.21 2023-07-10 21:13:37 +08:00
landluck
4756994212 release: 1.10.21 2023-07-10 21:09:29 +08:00
landluck
799a06379d build: compile 1.10.21 2023-07-10 21:09:25 +08:00
johnsonwong666
917ab22907
feat(dialog): add extra custom class (#5478) 2023-07-10 21:07:54 +08:00
johnsonwong666
7498ed12c3
fix(uploader): fix chooseImage error in PC (#5477) 2023-07-10 19:17:54 +08:00
landluck
f197c5f3c3
feat(field): expand click area support (#5479) 2023-07-10 17:49:20 +08:00
49 changed files with 285 additions and 130 deletions

View File

@ -22,6 +22,7 @@
bindgetuserinfo="onGetUserInfo"
bindcontact="onContact"
bindgetphonenumber="onGetPhoneNumber"
bindgetrealtimephonenumber="onGetRealTimePhoneNumber"
binderror="onError"
bindlaunchapp="onLaunchApp"
bindopensetting="onOpenSetting"

View File

@ -40,6 +40,7 @@ VantComponent({
},
defaultDate: {
type: null,
value: getToday().getTime(),
observer(val) {
this.setData({ currentDate: val });
this.scrollIntoView();
@ -164,6 +165,8 @@ VantComponent({
},
getInitialDate(defaultDate = null) {
const { type, minDate, maxDate, allowSameDay } = this.data;
if (!defaultDate)
return [];
const now = getToday().getTime();
if (type === 'range') {
if (!Array.isArray(defaultDate)) {
@ -190,6 +193,8 @@ VantComponent({
scrollIntoView() {
requestAnimationFrame(() => {
const { currentDate, type, show, poppable, minDate, maxDate } = this.data;
if (!currentDate)
return;
// @ts-ignore
const targetDate = type === 'single' ? currentDate : currentDate[0];
const displayed = show || !poppable;

View File

@ -93,6 +93,8 @@ VantComponent({
const { color, size } = this.data;
if (isObj(color)) {
return this.getContext().then((context) => {
if (!context)
return;
const LinearColor = context.createLinearGradient(size, 0, 0, 0);
Object.keys(color)
.sort((a, b) => parseFloat(a) - parseFloat(b))
@ -134,6 +136,8 @@ VantComponent({
drawCircle(currentValue) {
const { size } = this.data;
this.getContext().then((context) => {
if (!context)
return;
context.clearRect(0, 0, size, size);
this.renderLayerCircle(context);
const formatValue = format(currentValue);

View File

@ -17,3 +17,4 @@ export declare function toPromise(promiseLike: Promise<unknown> | unknown): Prom
export declare function addNumber(num1: any, num2: any): number;
export declare const clamp: (num: any, min: any, max: any) => number;
export declare function getCurrentPage<T>(): T & WechatMiniprogram.OptionalInterface<WechatMiniprogram.Page.ILifetime> & WechatMiniprogram.Page.InstanceProperties & WechatMiniprogram.Page.InstanceMethods<WechatMiniprogram.IAnyObject> & WechatMiniprogram.Page.Data<WechatMiniprogram.IAnyObject> & WechatMiniprogram.IAnyObject;
export declare const isPC: boolean;

View File

@ -1,5 +1,5 @@
import { isDef, isNumber, isPlainObject, isPromise } from './validator';
import { canIUseGroupSetData, canIUseNextTick } from './version';
import { canIUseGroupSetData, canIUseNextTick, getSystemInfoSync, } from './version';
export { isDef } from './validator';
export { getSystemInfoSync } from './version';
export function range(num, min, max) {
@ -81,3 +81,4 @@ export function getCurrentPage() {
const pages = getCurrentPages();
return pages[pages.length - 1];
}
export const isPC = ['mac', 'windows'].includes(getSystemInfoSync().platform);

View File

@ -4,6 +4,7 @@ import { GRAY, RED } from '../common/color';
import { toPromise } from '../common/utils';
VantComponent({
mixins: [button],
classes: ['cancle-button-class', 'confirm-button-class'],
props: {
show: {
type: Boolean,

View File

@ -33,7 +33,7 @@
size="large"
loading="{{ loading.cancel }}"
class="van-dialog__button van-hairline--right"
custom-class="van-dialog__cancel"
custom-class="van-dialog__cancel cancle-button-class"
custom-style="color: {{ cancelButtonColor }}"
bind:click="onCancel"
>
@ -44,7 +44,7 @@
size="large"
class="van-dialog__button"
loading="{{ loading.confirm }}"
custom-class="van-dialog__confirm"
custom-class="van-dialog__confirm confirm-button-class"
custom-style="color: {{ confirmButtonColor }}"
open-type="{{ confirmButtonOpenType }}"
@ -75,7 +75,7 @@
size="large"
loading="{{ loading.cancel }}"
class="van-dialog__button van-hairline--right"
custom-class="van-dialog__cancel"
custom-class="van-dialog__cancel cancle-button-class"
custom-style="color: {{ cancelButtonColor }}"
bind:click="onCancel"
>
@ -86,7 +86,7 @@
size="large"
class="van-dialog__button"
loading="{{ loading.confirm }}"
custom-class="van-dialog__confirm"
custom-class="van-dialog__confirm confirm-button-class"
custom-style="color: {{ confirmButtonColor }}"
open-type="{{ confirmButtonOpenType }}"

14
dist/field/index.wxml vendored
View File

@ -13,12 +13,12 @@
title-style="margin-right: 12px;"
custom-style="{{ customStyle }}"
arrow-direction="{{ arrowDirection }}"
custom-class="van-field"
custom-class="custom-class van-field"
>
<slot name="left-icon" slot="icon" />
<view wx:if="{{ label }}" class="label-class {{ utils.bem('field__label', { disabled }) }}" slot="title">
<label for="{{ name }}" wx:if="{{ label }}" class="label-class {{ utils.bem('field__label', { disabled }) }}" slot="title">
{{ label }}
</view>
</label>
<slot wx:else name="label" slot="title" />
<view class="{{ utils.bem('field__body', [type]) }}">
<view class="{{ utils.bem('field__control', [inputAlign, 'custom']) }}" bindtap="onClickInput">
@ -47,10 +47,10 @@
<slot name="button" />
</view>
</view>
<view wx:if="{{ showWordLimit && maxlength }}" class="van-field__word-limit">
<label for="{{ name }}" wx:if="{{ showWordLimit && maxlength }}" class="van-field__word-limit">
<view class="{{ utils.bem('field__word-num', { full: value.length >= maxlength }) }}">{{ value.length >= maxlength ? maxlength : value.length }}</view>/{{ maxlength }}
</view>
<view wx:if="{{ errorMessage }}" class="{{ utils.bem('field__error-message', [errorMessageAlign, { disabled, error }]) }}">
</label>
<label for="{{ name }}" wx:if="{{ errorMessage }}" class="{{ utils.bem('field__error-message', [errorMessageAlign, { disabled, error }]) }}">
{{ errorMessage }}
</view>
</label>
</van-cell>

View File

@ -1,4 +1,5 @@
<input
id="{{ name }}"
class="{{ utils.bem('field__control', [inputAlign, { disabled, error }]) }} input-class"
type="{{ type }}"
focus="{{ focus }}"

View File

@ -1,4 +1,5 @@
<textarea
id="{{ name }}"
class="{{ utils.bem('field__control', [inputAlign, type, { disabled, error }]) }} input-class"
fixed="{{ fixed }}"
focus="{{ focus }}"

View File

@ -10,7 +10,7 @@
disabled="{{ disabled }}"
open-type="{{ openType }}"
class="{{ utils.bem('goods-action-button', [type, { first: isFirst, last: isLast, plain: plain }])}}"
custom-class="van-goods-action-button__inner"
custom-class="van-goods-action-button__inner custom-class"
business-id="{{ businessId }}"
session-from="{{ sessionFrom }}"
app-parameter="{{ appParameter }}"

View File

@ -28,6 +28,9 @@ export const button = Behavior({
onGetPhoneNumber(event) {
this.triggerEvent('getphonenumber', event.detail);
},
onGetRealTimePhoneNumber(event) {
this.triggerEvent('getrealtimephonenumber', event.detail);
},
onError(event) {
this.triggerEvent('error', event.detail);
},

12
dist/sticky/index.js vendored
View File

@ -57,10 +57,8 @@ VantComponent({
}
this.scrollTop = scrollTop || this.scrollTop;
if (typeof container === 'function') {
Promise.all([
getRect(this, ROOT_ELEMENT),
this.getContainerRect(),
]).then(([root, container]) => {
Promise.all([getRect(this, ROOT_ELEMENT), this.getContainerRect()])
.then(([root, container]) => {
if (offsetTop + root.height > container.height + container.top) {
this.setDataAfterDiff({
fixed: false,
@ -77,7 +75,8 @@ VantComponent({
else {
this.setDataAfterDiff({ fixed: false, transform: 0 });
}
});
})
.catch(() => { });
return;
}
getRect(this, ROOT_ELEMENT).then((root) => {
@ -112,6 +111,9 @@ VantComponent({
},
getContainerRect() {
const nodesRef = this.data.container();
if (!nodesRef) {
return Promise.reject(new Error('not found container'));
}
return new Promise((resolve) => nodesRef.boundingClientRect(resolve).exec());
},
},

View File

@ -34,6 +34,9 @@ VantComponent({
}, previewFullImage: {
type: Boolean,
value: true,
}, videoFit: {
type: String,
value: 'contain',
}, imageFit: {
type: String,
value: 'scaleToFill',

View File

@ -28,6 +28,7 @@
title="{{ item.name || ('视频' + index) }}"
poster="{{ item.thumb }}"
autoplay="{{ item.autoplay }}"
object-fit="{{videoFit}}"
class="van-uploader__preview-image"
style="{{ computed.sizeStyle({ previewSize }) }}"
data-index="{{ index }}"

View File

@ -1,4 +1,4 @@
import { pickExclude } from '../common/utils';
import { pickExclude, isPC } from '../common/utils';
import { isImageUrl, isVideoUrl } from '../common/validator';
export function isImageFile(item) {
if (item.isImage != null) {
@ -25,7 +25,7 @@ export function isVideoFile(item) {
return false;
}
function formatImage(res) {
return res.tempFiles.map((item) => (Object.assign(Object.assign({}, pickExclude(item, ['path'])), { type: 'image', url: item.tempFilePath, thumb: item.tempFilePath })));
return res.tempFiles.map((item) => (Object.assign(Object.assign({}, pickExclude(item, ['path'])), { type: 'image', url: item.tempFilePath || item.path, thumb: item.tempFilePath || item.path })));
}
function formatVideo(res) {
return [
@ -42,16 +42,27 @@ export function chooseFile({ accept, multiple, capture, compressed, maxDuration,
return new Promise((resolve, reject) => {
switch (accept) {
case 'image':
wx.chooseMedia({
count: multiple ? Math.min(maxCount, 9) : 1,
mediaType: ['image'],
sourceType: capture,
maxDuration,
sizeType,
camera,
success: (res) => resolve(formatImage(res)),
fail: reject,
});
if (isPC) {
wx.chooseImage({
count: multiple ? Math.min(maxCount, 9) : 1,
sourceType: capture,
sizeType,
success: (res) => resolve(formatImage(res)),
fail: reject,
});
}
else {
wx.chooseMedia({
count: multiple ? Math.min(maxCount, 9) : 1,
mediaType: ['image'],
sourceType: capture,
maxDuration,
sizeType,
camera,
success: (res) => resolve(formatImage(res)),
fail: reject,
});
}
break;
case 'media':
wx.chooseMedia({

View File

@ -1,4 +1,21 @@
# 更新日志
### [v1.10.21](https://github.com/youzan/vant-weapp/compare/v1.10.20...v1.10.21)
`2023-07-10`
**Bug Fixes**
- uploader: 修复无法唤起选择图片框在 PC 下 [#5477](https://github.com/youzan/vant-weapp/issues/5477)
**Feature**
- button: 增加 getRealtimePhoneNumber 支持 [#5471](https://github.com/youzan/vant-weapp/issues/5471)
- calendar: 增加 default-date 为 null 支持 [#5395](https://github.com/youzan/vant-weapp/issues/5395)
- dialog: 增加确认/取消按钮外部样式类支持 [#5478](https://github.com/youzan/vant-weapp/issues/5478)
- field: 增加自定义样式类支持 [#5476](https://github.com/youzan/vant-weapp/issues/5476)
- field: 扩大 input 点击区域支持 [#5479](https://github.com/youzan/vant-weapp/issues/5479)
- Upload: 增加 videoFit 属性支持 [#5475](https://github.com/youzan/vant-weapp/issues/5475)
### [v1.10.20](https://github.com/youzan/vant-weapp/compare/v1.10.19...v1.10.20)
`2023-07-03`

View File

@ -22,6 +22,7 @@
bindgetuserinfo="onGetUserInfo"
bindcontact="onContact"
bindgetphonenumber="onGetPhoneNumber"
bindgetrealtimephonenumber="onGetRealTimePhoneNumber"
binderror="onError"
bindlaunchapp="onLaunchApp"
bindopensetting="onOpenSetting"

View File

@ -56,6 +56,7 @@ var getTime = function (date) {
},
defaultDate: {
type: null,
value: (0, utils_1.getToday)().getTime(),
observer: function (val) {
this.setData({ currentDate: val });
this.scrollIntoView();
@ -185,6 +186,8 @@ var getTime = function (date) {
var _this = this;
if (defaultDate === void 0) { defaultDate = null; }
var _a = this.data, type = _a.type, minDate = _a.minDate, maxDate = _a.maxDate, allowSameDay = _a.allowSameDay;
if (!defaultDate)
return [];
var now = (0, utils_1.getToday)().getTime();
if (type === 'range') {
if (!Array.isArray(defaultDate)) {
@ -212,6 +215,8 @@ var getTime = function (date) {
var _this = this;
(0, utils_2.requestAnimationFrame)(function () {
var _a = _this.data, currentDate = _a.currentDate, type = _a.type, show = _a.show, poppable = _a.poppable, minDate = _a.minDate, maxDate = _a.maxDate;
if (!currentDate)
return;
// @ts-ignore
var targetDate = type === 'single' ? currentDate : currentDate[0];
var displayed = show || !poppable;

View File

@ -98,6 +98,8 @@ var STEP = 1;
var _a = this.data, color = _a.color, size = _a.size;
if ((0, validator_1.isObj)(color)) {
return this.getContext().then(function (context) {
if (!context)
return;
var LinearColor = context.createLinearGradient(size, 0, 0, 0);
Object.keys(color)
.sort(function (a, b) { return parseFloat(a) - parseFloat(b); })
@ -142,6 +144,8 @@ var STEP = 1;
var _this = this;
var size = this.data.size;
this.getContext().then(function (context) {
if (!context)
return;
context.clearRect(0, 0, size, size);
_this.renderLayerCircle(context);
var formatValue = format(currentValue);

View File

@ -17,3 +17,4 @@ export declare function toPromise(promiseLike: Promise<unknown> | unknown): Prom
export declare function addNumber(num1: any, num2: any): number;
export declare const clamp: (num: any, min: any, max: any) => number;
export declare function getCurrentPage<T>(): T & WechatMiniprogram.OptionalInterface<WechatMiniprogram.Page.ILifetime> & WechatMiniprogram.Page.InstanceProperties & WechatMiniprogram.Page.InstanceMethods<WechatMiniprogram.IAnyObject> & WechatMiniprogram.Page.Data<WechatMiniprogram.IAnyObject> & WechatMiniprogram.IAnyObject;
export declare const isPC: boolean;

View File

@ -1,6 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCurrentPage = exports.clamp = exports.addNumber = exports.toPromise = exports.groupSetData = exports.getAllRect = exports.getRect = exports.pickExclude = exports.requestAnimationFrame = exports.addUnit = exports.nextTick = exports.range = exports.getSystemInfoSync = exports.isDef = void 0;
exports.isPC = exports.getCurrentPage = exports.clamp = exports.addNumber = exports.toPromise = exports.groupSetData = exports.getAllRect = exports.getRect = exports.pickExclude = exports.requestAnimationFrame = exports.addUnit = exports.nextTick = exports.range = exports.getSystemInfoSync = exports.isDef = void 0;
var validator_1 = require("./validator");
var version_1 = require("./version");
var validator_2 = require("./validator");
@ -104,3 +104,4 @@ function getCurrentPage() {
return pages[pages.length - 1];
}
exports.getCurrentPage = getCurrentPage;
exports.isPC = ['mac', 'windows'].includes((0, version_1.getSystemInfoSync)().platform);

View File

@ -6,6 +6,7 @@ var color_1 = require("../common/color");
var utils_1 = require("../common/utils");
(0, component_1.VantComponent)({
mixins: [button_1.button],
classes: ['cancle-button-class', 'confirm-button-class'],
props: {
show: {
type: Boolean,

View File

@ -33,7 +33,7 @@
size="large"
loading="{{ loading.cancel }}"
class="van-dialog__button van-hairline--right"
custom-class="van-dialog__cancel"
custom-class="van-dialog__cancel cancle-button-class"
custom-style="color: {{ cancelButtonColor }}"
bind:click="onCancel"
>
@ -44,7 +44,7 @@
size="large"
class="van-dialog__button"
loading="{{ loading.confirm }}"
custom-class="van-dialog__confirm"
custom-class="van-dialog__confirm confirm-button-class"
custom-style="color: {{ confirmButtonColor }}"
open-type="{{ confirmButtonOpenType }}"
@ -75,7 +75,7 @@
size="large"
loading="{{ loading.cancel }}"
class="van-dialog__button van-hairline--right"
custom-class="van-dialog__cancel"
custom-class="van-dialog__cancel cancle-button-class"
custom-style="color: {{ cancelButtonColor }}"
bind:click="onCancel"
>
@ -86,7 +86,7 @@
size="large"
class="van-dialog__button"
loading="{{ loading.confirm }}"
custom-class="van-dialog__confirm"
custom-class="van-dialog__confirm confirm-button-class"
custom-style="color: {{ confirmButtonColor }}"
open-type="{{ confirmButtonOpenType }}"

View File

@ -13,12 +13,12 @@
title-style="margin-right: 12px;"
custom-style="{{ customStyle }}"
arrow-direction="{{ arrowDirection }}"
custom-class="van-field"
custom-class="custom-class van-field"
>
<slot name="left-icon" slot="icon" />
<view wx:if="{{ label }}" class="label-class {{ utils.bem('field__label', { disabled }) }}" slot="title">
<label for="{{ name }}" wx:if="{{ label }}" class="label-class {{ utils.bem('field__label', { disabled }) }}" slot="title">
{{ label }}
</view>
</label>
<slot wx:else name="label" slot="title" />
<view class="{{ utils.bem('field__body', [type]) }}">
<view class="{{ utils.bem('field__control', [inputAlign, 'custom']) }}" bindtap="onClickInput">
@ -47,10 +47,10 @@
<slot name="button" />
</view>
</view>
<view wx:if="{{ showWordLimit && maxlength }}" class="van-field__word-limit">
<label for="{{ name }}" wx:if="{{ showWordLimit && maxlength }}" class="van-field__word-limit">
<view class="{{ utils.bem('field__word-num', { full: value.length >= maxlength }) }}">{{ value.length >= maxlength ? maxlength : value.length }}</view>/{{ maxlength }}
</view>
<view wx:if="{{ errorMessage }}" class="{{ utils.bem('field__error-message', [errorMessageAlign, { disabled, error }]) }}">
</label>
<label for="{{ name }}" wx:if="{{ errorMessage }}" class="{{ utils.bem('field__error-message', [errorMessageAlign, { disabled, error }]) }}">
{{ errorMessage }}
</view>
</label>
</van-cell>

View File

@ -1,4 +1,5 @@
<input
id="{{ name }}"
class="{{ utils.bem('field__control', [inputAlign, { disabled, error }]) }} input-class"
type="{{ type }}"
focus="{{ focus }}"

View File

@ -1,4 +1,5 @@
<textarea
id="{{ name }}"
class="{{ utils.bem('field__control', [inputAlign, type, { disabled, error }]) }} input-class"
fixed="{{ fixed }}"
focus="{{ focus }}"

View File

@ -10,7 +10,7 @@
disabled="{{ disabled }}"
open-type="{{ openType }}"
class="{{ utils.bem('goods-action-button', [type, { first: isFirst, last: isLast, plain: plain }])}}"
custom-class="van-goods-action-button__inner"
custom-class="van-goods-action-button__inner custom-class"
business-id="{{ businessId }}"
session-from="{{ sessionFrom }}"
app-parameter="{{ appParameter }}"

View File

@ -31,6 +31,9 @@ exports.button = Behavior({
onGetPhoneNumber: function (event) {
this.triggerEvent('getphonenumber', event.detail);
},
onGetRealTimePhoneNumber: function (event) {
this.triggerEvent('getrealtimephonenumber', event.detail);
},
onError: function (event) {
this.triggerEvent('error', event.detail);
},

View File

@ -61,10 +61,8 @@ var ROOT_ELEMENT = '.van-sticky';
}
this.scrollTop = scrollTop || this.scrollTop;
if (typeof container === 'function') {
Promise.all([
(0, utils_1.getRect)(this, ROOT_ELEMENT),
this.getContainerRect(),
]).then(function (_a) {
Promise.all([(0, utils_1.getRect)(this, ROOT_ELEMENT), this.getContainerRect()])
.then(function (_a) {
var root = _a[0], container = _a[1];
if (offsetTop + root.height > container.height + container.top) {
_this.setDataAfterDiff({
@ -82,7 +80,8 @@ var ROOT_ELEMENT = '.van-sticky';
else {
_this.setDataAfterDiff({ fixed: false, transform: 0 });
}
});
})
.catch(function () { });
return;
}
(0, utils_1.getRect)(this, ROOT_ELEMENT).then(function (root) {
@ -118,6 +117,9 @@ var ROOT_ELEMENT = '.van-sticky';
},
getContainerRect: function () {
var nodesRef = this.data.container();
if (!nodesRef) {
return Promise.reject(new Error('not found container'));
}
return new Promise(function (resolve) { return nodesRef.boundingClientRect(resolve).exec(); });
},
},

View File

@ -47,6 +47,9 @@ var validator_1 = require("../common/validator");
}, previewFullImage: {
type: Boolean,
value: true,
}, videoFit: {
type: String,
value: 'contain',
}, imageFit: {
type: String,
value: 'scaleToFill',

View File

@ -28,6 +28,7 @@
title="{{ item.name || ('视频' + index) }}"
poster="{{ item.thumb }}"
autoplay="{{ item.autoplay }}"
object-fit="{{videoFit}}"
class="van-uploader__preview-image"
style="{{ computed.sizeStyle({ previewSize }) }}"
data-index="{{ index }}"

View File

@ -41,7 +41,7 @@ function isVideoFile(item) {
}
exports.isVideoFile = isVideoFile;
function formatImage(res) {
return res.tempFiles.map(function (item) { return (__assign(__assign({}, (0, utils_1.pickExclude)(item, ['path'])), { type: 'image', url: item.tempFilePath, thumb: item.tempFilePath })); });
return res.tempFiles.map(function (item) { return (__assign(__assign({}, (0, utils_1.pickExclude)(item, ['path'])), { type: 'image', url: item.tempFilePath || item.path, thumb: item.tempFilePath || item.path })); });
}
function formatVideo(res) {
return [
@ -59,16 +59,27 @@ function chooseFile(_a) {
return new Promise(function (resolve, reject) {
switch (accept) {
case 'image':
wx.chooseMedia({
count: multiple ? Math.min(maxCount, 9) : 1,
mediaType: ['image'],
sourceType: capture,
maxDuration: maxDuration,
sizeType: sizeType,
camera: camera,
success: function (res) { return resolve(formatImage(res)); },
fail: reject,
});
if (utils_1.isPC) {
wx.chooseImage({
count: multiple ? Math.min(maxCount, 9) : 1,
sourceType: capture,
sizeType: sizeType,
success: function (res) { return resolve(formatImage(res)); },
fail: reject,
});
}
else {
wx.chooseMedia({
count: multiple ? Math.min(maxCount, 9) : 1,
mediaType: ['image'],
sourceType: capture,
maxDuration: maxDuration,
sizeType: sizeType,
camera: camera,
success: function (res) { return resolve(formatImage(res)); },
fail: reject,
});
}
break;
case 'media':
wx.chooseMedia({

View File

@ -1,6 +1,6 @@
{
"name": "@vant/weapp",
"version": "1.10.20",
"version": "1.10.21",
"author": "vant-ui",
"license": "MIT",
"miniprogram": "lib",

View File

@ -29,14 +29,15 @@ exports[`should render demo and match snapshot 1`] = `
class="van-cell__title title-class"
style="max-width:6.2em;min-width:6.2em;margin-right: 12px;"
>
<wx-view
<wx-label
class="label-class van-field__label"
for=""
slot="title"
>
地区
</wx-view>
</wx-label>
</wx-view>
<wx-view
class="van-cell__value value-class"
@ -60,6 +61,7 @@ exports[`should render demo and match snapshot 1`] = `
disabled="{{true}}"
focus="{{false}}"
holdKeyboard="{{false}}"
id=""
maxlength="{{-1}}"
password="{{false}}"
placeholder="请选择地区"
@ -138,14 +140,15 @@ exports[`should render demo and match snapshot 1`] = `
class="van-cell__title title-class"
style="max-width:6.2em;min-width:6.2em;margin-right: 12px;"
>
<wx-view
<wx-label
class="label-class van-field__label"
for=""
slot="title"
>
地区
</wx-view>
</wx-label>
</wx-view>
<wx-view
class="van-cell__value value-class"
@ -169,6 +172,7 @@ exports[`should render demo and match snapshot 1`] = `
disabled="{{true}}"
focus="{{false}}"
holdKeyboard="{{false}}"
id=""
maxlength="{{-1}}"
password="{{false}}"
placeholder="请选择地区"
@ -247,14 +251,15 @@ exports[`should render demo and match snapshot 1`] = `
class="van-cell__title title-class"
style="max-width:6.2em;min-width:6.2em;margin-right: 12px;"
>
<wx-view
<wx-label
class="label-class van-field__label"
for=""
slot="title"
>
地区
</wx-view>
</wx-label>
</wx-view>
<wx-view
class="van-cell__value value-class"
@ -278,6 +283,7 @@ exports[`should render demo and match snapshot 1`] = `
disabled="{{true}}"
focus="{{false}}"
holdKeyboard="{{false}}"
id=""
maxlength="{{-1}}"
password="{{false}}"
placeholder="请选择地区"
@ -356,14 +362,15 @@ exports[`should render demo and match snapshot 1`] = `
class="van-cell__title title-class"
style="max-width:6.2em;min-width:6.2em;margin-right: 12px;"
>
<wx-view
<wx-label
class="label-class van-field__label"
for=""
slot="title"
>
地区
</wx-view>
</wx-label>
</wx-view>
<wx-view
class="van-cell__value value-class"
@ -387,6 +394,7 @@ exports[`should render demo and match snapshot 1`] = `
disabled="{{true}}"
focus="{{false}}"
holdKeyboard="{{false}}"
id=""
maxlength="{{-1}}"
password="{{false}}"
placeholder="请选择地区"

View File

@ -1,5 +1,9 @@
import { isDef, isNumber, isPlainObject, isPromise } from './validator';
import { canIUseGroupSetData, canIUseNextTick } from './version';
import {
canIUseGroupSetData,
canIUseNextTick,
getSystemInfoSync,
} from './version';
export { isDef } from './validator';
export { getSystemInfoSync } from './version';
@ -109,3 +113,5 @@ export function getCurrentPage<T>() {
const pages = getCurrentPages();
return pages[pages.length - 1] as T & WechatMiniprogram.Page.TrivialInstance;
}
export const isPC = ['mac', 'windows'].includes(getSystemInfoSync().platform);

View File

@ -30,14 +30,15 @@ exports[`should render demo and match snapshot 1`] = `
class="van-cell__title title-class"
style="max-width:6.2em;min-width:6.2em;margin-right: 12px;"
>
<wx-view
<wx-label
class="label-class van-field__label"
for=""
slot="title"
>
评分
</wx-view>
</wx-label>
</wx-view>
<wx-view
class="van-cell__value value-class"
@ -167,6 +168,7 @@ exports[`should render demo and match snapshot 1`] = `
disabled="{{false}}"
focus="{{false}}"
holdKeyboard="{{false}}"
id=""
maxlength="{{-1}}"
password="{{false}}"
placeholder=""
@ -210,14 +212,15 @@ exports[`should render demo and match snapshot 1`] = `
class="van-cell__title title-class"
style="max-width:6.2em;min-width:6.2em;margin-right: 12px;"
>
<wx-view
<wx-label
class="label-class van-field__label"
for=""
slot="title"
>
滑块
</wx-view>
</wx-label>
</wx-view>
<wx-view
class="van-cell__value value-class"
@ -282,6 +285,7 @@ exports[`should render demo and match snapshot 1`] = `
disabled="{{false}}"
focus="{{false}}"
holdKeyboard="{{false}}"
id=""
maxlength="{{-1}}"
password="{{false}}"
placeholder=""
@ -386,14 +390,15 @@ exports[`should render demo and match snapshot 1`] = `
class="van-cell__title title-class"
style="max-width:6.2em;min-width:6.2em;margin-right: 12px;"
>
<wx-view
<wx-label
class="label-class van-field__label"
for=""
slot="title"
>
评分
</wx-view>
</wx-label>
</wx-view>
<wx-view
class="van-cell__value value-class"
@ -523,6 +528,7 @@ exports[`should render demo and match snapshot 1`] = `
disabled="{{false}}"
focus="{{false}}"
holdKeyboard="{{false}}"
id=""
maxlength="{{-1}}"
password="{{false}}"
placeholder=""
@ -566,14 +572,15 @@ exports[`should render demo and match snapshot 1`] = `
class="van-cell__title title-class"
style="max-width:6.2em;min-width:6.2em;margin-right: 12px;"
>
<wx-view
<wx-label
class="label-class van-field__label"
for=""
slot="title"
>
滑块
</wx-view>
</wx-label>
</wx-view>
<wx-view
class="van-cell__value value-class"
@ -638,6 +645,7 @@ exports[`should render demo and match snapshot 1`] = `
disabled="{{false}}"
focus="{{false}}"
holdKeyboard="{{false}}"
id=""
maxlength="{{-1}}"
password="{{false}}"
placeholder=""

View File

@ -303,3 +303,6 @@ Page({
| 类名 | 说明 |
| ---------------------- | ------------ |
| custom-class `v1.10.8` | 根节点样式类 |
| cancle-button-class `v1.10.21` | 取消按钮样式类 |
| confirm-button-class `v1.10.21` | 确认按钮样式类 |

View File

@ -6,6 +6,7 @@ import type { Action } from './dialog';
VantComponent({
mixins: [button],
classes: ['cancle-button-class', 'confirm-button-class'],
props: {
show: {
@ -71,7 +72,7 @@ VantComponent({
confirm: false,
cancel: false,
},
callback: ((() => {}) as unknown) as (
callback: (() => {}) as unknown as (
action: string,
context: WechatMiniprogram.Component.TrivialInstance
) => void,

View File

@ -33,7 +33,7 @@
size="large"
loading="{{ loading.cancel }}"
class="van-dialog__button van-hairline--right"
custom-class="van-dialog__cancel"
custom-class="van-dialog__cancel cancle-button-class"
custom-style="color: {{ cancelButtonColor }}"
bind:click="onCancel"
>
@ -44,7 +44,7 @@
size="large"
class="van-dialog__button"
loading="{{ loading.confirm }}"
custom-class="van-dialog__confirm"
custom-class="van-dialog__confirm confirm-button-class"
custom-style="color: {{ confirmButtonColor }}"
open-type="{{ confirmButtonOpenType }}"
@ -75,7 +75,7 @@
size="large"
loading="{{ loading.cancel }}"
class="van-dialog__button van-hairline--right"
custom-class="van-dialog__cancel"
custom-class="van-dialog__cancel cancle-button-class"
custom-style="color: {{ cancelButtonColor }}"
bind:click="onCancel"
>
@ -86,7 +86,7 @@
size="large"
class="van-dialog__button"
loading="{{ loading.confirm }}"
custom-class="van-dialog__confirm"
custom-class="van-dialog__confirm confirm-button-class"
custom-style="color: {{ confirmButtonColor }}"
open-type="{{ confirmButtonOpenType }}"

View File

@ -240,13 +240,17 @@ Page({
相关的讨论可以查看[微信开放社区](https://developers.weixin.qq.com/community/search?query=input%20%E6%89%8B%E5%86%99%E8%BE%93%E5%85%A5&page=1&block=1&random=1567079239098)。
### 如何扩大点击区域?点击 label、错误信息 都能聚焦唤起键盘呢?
升级至 1.10.21 版本及以上,配置 `name` 属性即可
## API
### Props
| 参数 | 说明 | 类型 | 默认值 |
| --- | --- | --- | --- |
| name | 在表单内提交时的标识符 | _string_ | - |
| name | 在表单内提交时的标识符。可以通过配置 `name` 来扩大点击区域 | _string_ | - |
| label | 输入框左侧文本 | _string_ | - |
| size | 单元格大小,可选值为 `large` | _string_ | - |
| value | 当前输入的值 | _string \| number_ | - |

View File

@ -16,9 +16,9 @@
custom-class="custom-class van-field"
>
<slot name="left-icon" slot="icon" />
<view wx:if="{{ label }}" class="label-class {{ utils.bem('field__label', { disabled }) }}" slot="title">
<label for="{{ name }}" wx:if="{{ label }}" class="label-class {{ utils.bem('field__label', { disabled }) }}" slot="title">
{{ label }}
</view>
</label>
<slot wx:else name="label" slot="title" />
<view class="{{ utils.bem('field__body', [type]) }}">
<view class="{{ utils.bem('field__control', [inputAlign, 'custom']) }}" bindtap="onClickInput">
@ -47,10 +47,10 @@
<slot name="button" />
</view>
</view>
<view wx:if="{{ showWordLimit && maxlength }}" class="van-field__word-limit">
<label for="{{ name }}" wx:if="{{ showWordLimit && maxlength }}" class="van-field__word-limit">
<view class="{{ utils.bem('field__word-num', { full: value.length >= maxlength }) }}">{{ value.length >= maxlength ? maxlength : value.length }}</view>/{{ maxlength }}
</view>
<view wx:if="{{ errorMessage }}" class="{{ utils.bem('field__error-message', [errorMessageAlign, { disabled, error }]) }}">
</label>
<label for="{{ name }}" wx:if="{{ errorMessage }}" class="{{ utils.bem('field__error-message', [errorMessageAlign, { disabled, error }]) }}">
{{ errorMessage }}
</view>
</label>
</van-cell>

View File

@ -1,4 +1,5 @@
<input
id="{{ name }}"
class="{{ utils.bem('field__control', [inputAlign, { disabled, error }]) }} input-class"
type="{{ type }}"
focus="{{ focus }}"

View File

@ -52,6 +52,7 @@ exports[`should render demo and match snapshot 1`] = `
disabled="{{false}}"
focus="{{false}}"
holdKeyboard="{{false}}"
id=""
maxlength="{{-1}}"
password="{{false}}"
placeholder="请输入用户名"
@ -115,14 +116,15 @@ exports[`should render demo and match snapshot 1`] = `
class="van-cell__title title-class"
style="max-width:6.2em;min-width:6.2em;margin-right: 12px;"
>
<wx-view
<wx-label
class="label-class van-field__label"
for=""
slot="title"
>
用户名
</wx-view>
</wx-label>
</wx-view>
<wx-view
class="van-cell__value value-class"
@ -146,6 +148,7 @@ exports[`should render demo and match snapshot 1`] = `
disabled="{{false}}"
focus="{{false}}"
holdKeyboard="{{false}}"
id=""
maxlength="{{-1}}"
password="{{false}}"
placeholder="请输入用户名"
@ -200,14 +203,15 @@ exports[`should render demo and match snapshot 1`] = `
class="van-cell__title title-class"
style="max-width:6.2em;min-width:6.2em;margin-right: 12px;"
>
<wx-view
<wx-label
class="label-class van-field__label"
for=""
slot="title"
>
密码
</wx-view>
</wx-label>
</wx-view>
<wx-view
class="van-cell__value value-class"
@ -231,6 +235,7 @@ exports[`should render demo and match snapshot 1`] = `
disabled="{{false}}"
focus="{{false}}"
holdKeyboard="{{false}}"
id=""
maxlength="{{-1}}"
password="{{true}}"
placeholder="请输入密码"
@ -301,14 +306,15 @@ exports[`should render demo and match snapshot 1`] = `
class="van-cell__title title-class"
style="max-width:6.2em;min-width:6.2em;margin-right: 12px;"
>
<wx-view
<wx-label
class="label-class van-field__label van-field__label--disabled"
for=""
slot="title"
>
用户名
</wx-view>
</wx-label>
</wx-view>
<wx-view
class="van-cell__value value-class"
@ -332,6 +338,7 @@ exports[`should render demo and match snapshot 1`] = `
disabled="{{true}}"
focus="{{false}}"
holdKeyboard="{{false}}"
id=""
maxlength="{{-1}}"
password="{{false}}"
placeholder=""
@ -392,14 +399,15 @@ exports[`should render demo and match snapshot 1`] = `
class="van-cell__title title-class"
style="max-width:6.2em;min-width:6.2em;margin-right: 12px;"
>
<wx-view
<wx-label
class="label-class van-field__label"
for=""
slot="title"
>
用户名
</wx-view>
</wx-label>
</wx-view>
<wx-view
class="van-cell__value value-class"
@ -423,6 +431,7 @@ exports[`should render demo and match snapshot 1`] = `
disabled="{{false}}"
focus="{{false}}"
holdKeyboard="{{false}}"
id=""
maxlength="{{-1}}"
password="{{false}}"
placeholder="请输入用户名"
@ -466,14 +475,15 @@ exports[`should render demo and match snapshot 1`] = `
class="van-cell__title title-class"
style="max-width:6.2em;min-width:6.2em;margin-right: 12px;"
>
<wx-view
<wx-label
class="label-class van-field__label"
for=""
slot="title"
>
手机号
</wx-view>
</wx-label>
</wx-view>
<wx-view
class="van-cell__value value-class"
@ -497,6 +507,7 @@ exports[`should render demo and match snapshot 1`] = `
disabled="{{false}}"
focus="{{false}}"
holdKeyboard="{{false}}"
id=""
maxlength="{{-1}}"
password="{{false}}"
placeholder="请输入手机号"
@ -521,13 +532,14 @@ exports[`should render demo and match snapshot 1`] = `
class="van-field__button"
/>
</wx-view>
<wx-view
<wx-label
class="van-field__error-message"
for=""
>
手机号格式错误
</wx-view>
</wx-label>
</wx-view>
</wx-view>
</van-cell>
@ -564,14 +576,15 @@ exports[`should render demo and match snapshot 1`] = `
class="van-cell__title title-class"
style="max-width:6.2em;min-width:6.2em;margin-right: 12px;"
>
<wx-view
<wx-label
class="label-class van-field__label"
for=""
slot="title"
>
用户名
</wx-view>
</wx-label>
</wx-view>
<wx-view
class="van-cell__value value-class"
@ -595,6 +608,7 @@ exports[`should render demo and match snapshot 1`] = `
disabled="{{false}}"
focus="{{false}}"
holdKeyboard="{{false}}"
id=""
maxlength="{{-1}}"
password="{{false}}"
placeholder="请输入用户名"
@ -657,14 +671,15 @@ exports[`should render demo and match snapshot 1`] = `
class="van-cell__title title-class"
style="max-width:6.2em;min-width:6.2em;margin-right: 12px;"
>
<wx-view
<wx-label
class="label-class van-field__label"
for=""
slot="title"
>
留言
</wx-view>
</wx-label>
</wx-view>
<wx-view
class="van-cell__value value-class"
@ -688,6 +703,7 @@ exports[`should render demo and match snapshot 1`] = `
fixed="{{false}}"
focus="{{false}}"
holdKeyboard="{{false}}"
id=""
maxlength="{{-1}}"
placeholder="请输入留言"
placeholderClass="van-field__placeholder"
@ -751,14 +767,15 @@ exports[`should render demo and match snapshot 1`] = `
class="van-cell__title title-class"
style="max-width:6.2em;min-width:6.2em;margin-right: 12px;"
>
<wx-view
<wx-label
class="label-class van-field__label"
for=""
slot="title"
>
短信验证码
</wx-view>
</wx-label>
</wx-view>
<wx-view
class="van-cell__value value-class"
@ -782,6 +799,7 @@ exports[`should render demo and match snapshot 1`] = `
disabled="{{false}}"
focus="{{false}}"
holdKeyboard="{{false}}"
id=""
maxlength="{{-1}}"
password="{{false}}"
placeholder="请输入短信验证码"

View File

@ -1,4 +1,5 @@
<textarea
id="{{ name }}"
class="{{ utils.bem('field__control', [inputAlign, type, { disabled, error }]) }} input-class"
fixed="{{ fixed }}"
focus="{{ focus }}"

View File

@ -10,7 +10,7 @@
disabled="{{ disabled }}"
open-type="{{ openType }}"
class="{{ utils.bem('goods-action-button', [type, { first: isFirst, last: isLast, plain: plain }])}}"
custom-class="van-goods-action-button__inner"
custom-class="van-goods-action-button__inner custom-class"
business-id="{{ businessId }}"
session-from="{{ sessionFrom }}"
app-parameter="{{ appParameter }}"

View File

@ -154,7 +154,7 @@ exports[`should render demo and match snapshot 1`] = `
>
<van-button
class="van-goods-action-button van-goods-action-button--warning van-goods-action-button--first"
customClass="van-goods-action-button__inner"
customClass="van-goods-action-button__inner custom-class"
bind:click="onClick"
bind:contact="onContact"
bind:error="onError"
@ -205,7 +205,7 @@ exports[`should render demo and match snapshot 1`] = `
>
<van-button
class="van-goods-action-button van-goods-action-button--danger van-goods-action-button--last"
customClass="van-goods-action-button__inner"
customClass="van-goods-action-button__inner custom-class"
bind:click="onClick"
bind:contact="onContact"
bind:error="onError"
@ -482,7 +482,7 @@ exports[`should render demo and match snapshot 1`] = `
<van-goods-action-button>
<van-button
class="van-goods-action-button van-goods-action-button--warning van-goods-action-button--first"
customClass="van-goods-action-button__inner"
customClass="van-goods-action-button__inner custom-class"
bind:click="onClick"
bind:contact="onContact"
bind:error="onError"
@ -531,7 +531,7 @@ exports[`should render demo and match snapshot 1`] = `
<van-goods-action-button>
<van-button
class="van-goods-action-button van-goods-action-button--danger van-goods-action-button--last"
customClass="van-goods-action-button__inner"
customClass="van-goods-action-button__inner custom-class"
bind:click="onClick"
bind:contact="onContact"
bind:error="onError"
@ -729,7 +729,7 @@ exports[`should render demo and match snapshot 1`] = `
<van-goods-action-button>
<van-button
class="van-goods-action-button van-goods-action-button--warning van-goods-action-button--first"
customClass="van-goods-action-button__inner"
customClass="van-goods-action-button__inner custom-class"
bind:click="onClick"
bind:contact="onContact"
bind:error="onError"
@ -778,7 +778,7 @@ exports[`should render demo and match snapshot 1`] = `
<van-goods-action-button>
<van-button
class="van-goods-action-button van-goods-action-button--danger van-goods-action-button--last"
customClass="van-goods-action-button__inner"
customClass="van-goods-action-button__inner custom-class"
bind:click="onClick"
bind:contact="onContact"
bind:error="onError"
@ -976,7 +976,7 @@ exports[`should render demo and match snapshot 1`] = `
<van-goods-action-button>
<van-button
class="van-goods-action-button van-goods-action-button--warning van-goods-action-button--first"
customClass="van-goods-action-button__inner"
customClass="van-goods-action-button__inner custom-class"
bind:click="onClick"
bind:contact="onContact"
bind:error="onError"
@ -1025,7 +1025,7 @@ exports[`should render demo and match snapshot 1`] = `
<van-goods-action-button>
<van-button
class="van-goods-action-button van-goods-action-button--danger van-goods-action-button--last van-goods-action-button--plain"
customClass="van-goods-action-button__inner"
customClass="van-goods-action-button__inner custom-class"
bind:click="onClick"
bind:contact="onContact"
bind:error="onError"

View File

@ -77,6 +77,7 @@ exports[`should render demo and match snapshot 1`] = `
disabled="{{false}}"
focus="{{false}}"
holdKeyboard="{{false}}"
id=""
maxlength="{{-1}}"
password="{{false}}"
placeholder="请输入搜索关键词"
@ -187,6 +188,7 @@ exports[`should render demo and match snapshot 1`] = `
disabled="{{false}}"
focus="{{false}}"
holdKeyboard="{{false}}"
id=""
maxlength="{{-1}}"
password="{{false}}"
placeholder="请输入搜索关键词"
@ -305,6 +307,7 @@ exports[`should render demo and match snapshot 1`] = `
disabled="{{false}}"
focus="{{false}}"
holdKeyboard="{{false}}"
id=""
maxlength="{{-1}}"
password="{{false}}"
placeholder="请输入搜索关键词"
@ -411,6 +414,7 @@ exports[`should render demo and match snapshot 1`] = `
disabled="{{true}}"
focus="{{false}}"
holdKeyboard="{{false}}"
id=""
maxlength="{{-1}}"
password="{{false}}"
placeholder="请输入搜索关键词"
@ -517,6 +521,7 @@ exports[`should render demo and match snapshot 1`] = `
disabled="{{false}}"
focus="{{false}}"
holdKeyboard="{{false}}"
id=""
maxlength="{{-1}}"
password="{{false}}"
placeholder="请输入搜索关键词"
@ -630,6 +635,7 @@ exports[`should render demo and match snapshot 1`] = `
disabled="{{false}}"
focus="{{false}}"
holdKeyboard="{{false}}"
id=""
maxlength="{{-1}}"
password="{{false}}"
placeholder="请输入搜索关键词"

View File

@ -1,4 +1,4 @@
import { pickExclude } from '../common/utils';
import { pickExclude, isPC } from '../common/utils';
import { isImageUrl, isVideoUrl } from '../common/validator';
export interface File {
@ -45,13 +45,15 @@ export function isVideoFile(item: File): boolean {
}
function formatImage(
res: WechatMiniprogram.ChooseMediaSuccessCallbackResult
res:
| WechatMiniprogram.ChooseMediaSuccessCallbackResult
| WechatMiniprogram.ChooseImageSuccessCallbackResult
): File[] {
return res.tempFiles.map((item) => ({
...pickExclude(item, ['path']),
type: 'image',
url: item.tempFilePath,
thumb: item.tempFilePath,
url: item.tempFilePath || item.path,
thumb: item.tempFilePath || item.path,
}));
}
@ -101,16 +103,26 @@ export function chooseFile({
return new Promise<File | File[]>((resolve, reject) => {
switch (accept) {
case 'image':
wx.chooseMedia({
count: multiple ? Math.min(maxCount, 9) : 1,
mediaType: ['image'],
sourceType: capture,
maxDuration,
sizeType,
camera,
success: (res) => resolve(formatImage(res)),
fail: reject,
});
if (isPC) {
wx.chooseImage({
count: multiple ? Math.min(maxCount, 9) : 1,
sourceType: capture,
sizeType,
success: (res) => resolve(formatImage(res)),
fail: reject,
});
} else {
wx.chooseMedia({
count: multiple ? Math.min(maxCount, 9) : 1,
mediaType: ['image'],
sourceType: capture,
maxDuration,
sizeType,
camera,
success: (res) => resolve(formatImage(res)),
fail: reject,
});
}
break;
case 'media':
wx.chooseMedia({