Merge branch 'dev' into next

This commit is contained in:
chenjiahan 2022-02-09 16:31:47 +08:00
commit 0fdaf133bb
17 changed files with 59 additions and 31 deletions

View File

@ -296,7 +296,7 @@ export default {
&__subtitle { &__subtitle {
display: inline-block; display: inline-block;
color: #999; color: #999;
margin-left: 8px; margin-left: 4px;
vertical-align: -4px; vertical-align: -4px;
font-size: 13px; font-size: 13px;
} }

View File

@ -37,7 +37,10 @@ import { Toast } from 'vant';
export default { export default {
setup() { setup() {
const editingContact = ref({}); const editingContact = ref({
tel: '',
name: '',
});
const onSave = (contactInfo) => Toast('Save'); const onSave = (contactInfo) => Toast('Save');
const onDelete = (contactInfo) => Toast('Delete'); const onDelete = (contactInfo) => Toast('Delete');
return { return {

View File

@ -37,7 +37,10 @@ import { Toast } from 'vant';
export default { export default {
setup() { setup() {
const editingContact = ref({}); const editingContact = ref({
tel: '',
name: '',
});
const onSave = (contactInfo) => Toast('保存'); const onSave = (contactInfo) => Toast('保存');
const onDelete = (contactInfo) => Toast('删除'); const onDelete = (contactInfo) => Toast('删除');
return { return {

View File

@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import VanContactEdit from '..';
import { ref } from 'vue'; import { ref } from 'vue';
import VanContactEdit, { type ContactEditInfo } from '..';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site/use-translate';
import { Toast } from '../../toast'; import { Toast } from '../../toast';
@ -13,7 +13,10 @@ const t = useTranslate({
}, },
}); });
const editingContact = ref({}); const editingContact = ref<ContactEditInfo>({
tel: '',
name: '',
});
const onSave = () => Toast(t('save')); const onSave = () => Toast(t('save'));
const onDelete = () => Toast(t('delete')); const onDelete = () => Toast(t('delete'));

View File

@ -1,11 +1,10 @@
<script setup lang="ts"> <script setup lang="ts">
import VanCountDown from '..';
import VanGrid from '../../grid'; import VanGrid from '../../grid';
import VanGridItem from '../../grid-item'; import VanGridItem from '../../grid-item';
import VanCountDown, { type CountDownInstance } from '..';
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site/use-translate';
import { Toast } from '../../toast'; import { Toast } from '../../toast';
import type { CountDownInstance } from '..';
const t = useTranslate({ const t = useTranslate({
'zh-CN': { 'zh-CN': {

View File

@ -1,7 +1,10 @@
import { KeepAlive, nextTick } from 'vue'; import { nextTick, KeepAlive } from 'vue';
import { CountDown } from '..'; import {
CountDown,
type CountDownInstance,
type CountDownCurrentTime,
} from '..';
import { mount, later } from '../../../test'; import { mount, later } from '../../../test';
import type { CountDownCurrentTime, CountDownInstance } from '../CountDown';
test('should emit finish event when finished', async () => { test('should emit finish event when finished', async () => {
const wrapper = mount(CountDown, { const wrapper = mount(CountDown, {

View File

@ -58,7 +58,7 @@ const indexBarProps = {
highlightColor: String, highlightColor: String,
stickyOffsetTop: makeNumberProp(0), stickyOffsetTop: makeNumberProp(0),
indexList: { indexList: {
type: Array as PropType<string[]>, type: Array as PropType<Array<string | number>>,
default: genAlphabet, default: genAlphabet,
}, },
}; };
@ -76,7 +76,7 @@ export default defineComponent({
setup(props, { emit, slots }) { setup(props, { emit, slots }) {
const root = ref<HTMLElement>(); const root = ref<HTMLElement>();
const activeAnchor = ref(''); const activeAnchor = ref<string | number>('');
const touch = useTouch(); const touch = useTouch();
const scrollParent = useScrollParent(root); const scrollParent = useScrollParent(root);

View File

@ -1,10 +1,9 @@
<script setup lang="ts"> <script setup lang="ts">
import VanCell from '../../cell'; import VanCell from '../../cell';
import VanIcon from '../../icon'; import VanIcon from '../../icon';
import { Notify } from '..';
import { ref } from 'vue'; import { ref } from 'vue';
import { Notify, type NotifyType } from '..';
import { useTranslate } from '../../../docs/site/use-translate'; import { useTranslate } from '../../../docs/site/use-translate';
import { NotifyType } from '../Notify';
const VanNotify = Notify.Component; const VanNotify = Notify.Component;

View File

@ -42,7 +42,7 @@ const disabledInput = ref(1);
const beforeChange = () => { const beforeChange = () => {
Toast.loading({ forbidClick: true }); Toast.loading({ forbidClick: true });
return new Promise((resolve) => { return new Promise<boolean>((resolve) => {
setTimeout(() => { setTimeout(() => {
Toast.clear(); Toast.clear();
resolve(true); resolve(true);

View File

@ -17,7 +17,7 @@ const t = useTranslate({
}, },
}); });
const container = ref(null); const container = ref<Element>();
</script> </script>
<template> <template>

View File

@ -38,10 +38,12 @@ const beforeClose = ({ position }: { position: string }) => {
case 'outside': case 'outside':
return true; return true;
case 'right': case 'right':
return new Promise((resolve) => { return new Promise<boolean>((resolve) => {
Dialog.confirm({ Dialog.confirm({
title: t('confirm'), title: t('confirm'),
}).then(resolve); }).then(() => {
resolve(true);
});
}); });
} }
}; };

View File

@ -64,7 +64,7 @@ const beforeChange = (name: number) => {
if (name === 1) { if (name === 1) {
return false; return false;
} }
return new Promise((resolve) => { return new Promise<boolean>((resolve) => {
resolve(name !== 3); resolve(name !== 3);
}); });
}; };

View File

@ -4,6 +4,7 @@ import {
onUnmounted, onUnmounted,
defineComponent, defineComponent,
type PropType, type PropType,
type TeleportProps,
type CSSProperties, type CSSProperties,
type ExtractPropTypes, type ExtractPropTypes,
} from 'vue'; } from 'vue';
@ -49,6 +50,7 @@ const toastProps = {
iconSize: numericProp, iconSize: numericProp,
duration: makeNumberProp(2000), duration: makeNumberProp(2000),
position: makeStringProp<ToastPosition>('middle'), position: makeStringProp<ToastPosition>('middle'),
teleport: [String, Object] as PropType<TeleportProps['to']>,
className: unknownProp, className: unknownProp,
iconPrefix: String, iconPrefix: String,
transition: makeStringProp('van-fade'), transition: makeStringProp('van-fade'),

View File

@ -56,7 +56,7 @@ const fileList3 = ref([]);
const fileList4 = ref([{ url: 'https://img.yzcdn.cn/vant/sand.jpg' }]); const fileList4 = ref([{ url: 'https://img.yzcdn.cn/vant/sand.jpg' }]);
const fileList5 = ref([ const fileList5 = ref<UploaderFileListItem[]>([
{ url: 'https://img.yzcdn.cn/vant/leaf.jpg' }, { url: 'https://img.yzcdn.cn/vant/leaf.jpg' },
{ {
url: 'https://img.yzcdn.cn/vant/sand.jpg', url: 'https://img.yzcdn.cn/vant/sand.jpg',
@ -73,7 +73,7 @@ const fileList5 = ref([
}, },
]); ]);
const statusFileList = ref([ const statusFileList = ref<UploaderFileListItem[]>([
{ {
url: 'https://img.yzcdn.cn/vant/leaf.jpg', url: 'https://img.yzcdn.cn/vant/leaf.jpg',
status: 'uploading', status: 'uploading',
@ -86,16 +86,19 @@ const statusFileList = ref([
}, },
]); ]);
const previewCoverFiles = ref([ const previewCoverFiles = ref<UploaderFileListItem[]>([
{ {
url: 'https://img.yzcdn.cn/vant/leaf.jpg', url: 'https://img.yzcdn.cn/vant/leaf.jpg',
file: { file: {
name: t('imageName'), name: t('imageName'),
}, } as File,
}, },
]); ]);
const beforeRead = (file: File) => { const beforeRead = (file: File | File[]) => {
if (Array.isArray(file)) {
return true;
}
if (file.type !== 'image/jpeg') { if (file.type !== 'image/jpeg') {
Toast(t('invalidType')); Toast(t('invalidType'));
return false; return false;
@ -103,11 +106,14 @@ const beforeRead = (file: File) => {
return true; return true;
}; };
const afterRead = (file: UploaderFileListItem, detail: unknown) => { const afterRead = (
file: UploaderFileListItem | UploaderFileListItem[],
detail: unknown
) => {
console.log(file, detail); console.log(file, detail);
}; };
const afterReadFailed = (item: UploaderFileListItem) => { const setItemLoading = (item: UploaderFileListItem) => {
item.status = 'uploading'; item.status = 'uploading';
item.message = t('uploading'); item.message = t('uploading');
@ -117,6 +123,16 @@ const afterReadFailed = (item: UploaderFileListItem) => {
}, 1000); }, 1000);
}; };
const afterReadFailed = (
item: UploaderFileListItem | UploaderFileListItem[]
) => {
if (Array.isArray(item)) {
item.forEach(setItemLoading);
} else {
setItemLoading(item);
}
};
const onOversize = (file: UploaderFileListItem, detail: unknown) => { const onOversize = (file: UploaderFileListItem, detail: unknown) => {
console.log(file, detail); console.log(file, detail);
Toast(t('overSizeTip')); Toast(t('overSizeTip'));

View File

@ -99,7 +99,7 @@ test('set input name', (done) => {
detail: { name: string | number; index: number } detail: { name: string | number; index: number }
) => { ) => {
expect(detail.name).toEqual('uploader'); expect(detail.name).toEqual('uploader');
return file; return true;
}, },
afterRead: ( afterRead: (
readFile: UploaderFileListItem | UploaderFileListItem[], readFile: UploaderFileListItem | UploaderFileListItem[],

View File

@ -20,15 +20,13 @@ export type UploaderFileListItem = {
export type UploaderMaxSize = number | string | ((file: File) => boolean); export type UploaderMaxSize = number | string | ((file: File) => boolean);
type PromiseOrNot<T> = T | Promise<T>;
export type UploaderBeforeRead = ( export type UploaderBeforeRead = (
file: File | File[], file: File | File[],
detail: { detail: {
name: string | number; name: string | number;
index: number; index: number;
} }
) => PromiseOrNot<File | File[] | undefined>; ) => boolean | undefined | Promise<File | File[] | undefined>;
export type UploaderAfterRead = ( export type UploaderAfterRead = (
items: UploaderFileListItem | UploaderFileListItem[], items: UploaderFileListItem | UploaderFileListItem[],

View File

@ -3,7 +3,7 @@ import { isPromise } from './validate';
export type Interceptor = ( export type Interceptor = (
...args: any[] ...args: any[]
) => Promise<boolean> | boolean | undefined; ) => Promise<boolean> | boolean | undefined | void;
export function callInterceptor( export function callInterceptor(
interceptor: Interceptor | undefined, interceptor: Interceptor | undefined,