chore: add cdnURL helper (#10439)

This commit is contained in:
neverland 2022-03-27 17:24:50 +08:00 committed by GitHub
parent c89d407a41
commit dbad7571ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 94 additions and 118 deletions

View File

@ -104,3 +104,7 @@ export function useTranslate(i18n: Record<string, any>) {
return createTranslate(demoName); return createTranslate(demoName);
} }
/** Generate the CDN URL of assets. */
export const cdnURL = (path: string) =>
`https://cdn.jsdelivr.net/npm/@vant/assets/${path}`;

View File

@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import VanButton from '..'; import VanButton from '..';
import { useTranslate } from '../../../docs/site/use-translate'; import { cdnURL, useTranslate } from '../../../docs/site/use-translate';
const t = useTranslate({ const t = useTranslate({
'zh-CN': { 'zh-CN': {
@ -107,7 +107,7 @@ const t = useTranslate({
<van-button <van-button
plain plain
type="primary" type="primary"
icon="https://cdn.jsdelivr.net/npm/@vant/assets/user-active.png" :icon="cdnURL('user-active.png')"
:text="t('button')" :text="t('button')"
/> />
</demo-block> </demo-block>

View File

@ -2,7 +2,7 @@
import VanCard from '..'; import VanCard from '..';
import VanTag from '../../tag'; import VanTag from '../../tag';
import VanButton from '../../button'; import VanButton from '../../button';
import { useTranslate } from '../../../docs/site/use-translate'; import { cdnURL, useTranslate } from '../../../docs/site/use-translate';
const t = useTranslate({ const t = useTranslate({
'zh-CN': { 'zh-CN': {
@ -16,7 +16,7 @@ const t = useTranslate({
}, },
}); });
const imageURL = 'https://cdn.jsdelivr.net/npm/@vant/assets/ipad.jpeg'; const imageURL = cdnURL('ipad.jpeg');
</script> </script>
<template> <template>

View File

@ -5,7 +5,7 @@ import VanButton from '../../button';
import VanCellGroup from '../../cell-group'; import VanCellGroup from '../../cell-group';
import VanCell from '../../cell'; import VanCell from '../../cell';
import { ref, reactive } from 'vue'; import { ref, reactive } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { cdnURL, useTranslate } from '../../../docs/site/use-translate';
import { useRefs } from '../../composables/use-refs'; import { useRefs } from '../../composables/use-refs';
import type { CheckboxInstance } from '../types'; import type { CheckboxInstance } from '../types';
import type { CheckboxGroupInstance } from '../../checkbox-group'; import type { CheckboxGroupInstance } from '../../checkbox-group';
@ -49,7 +49,7 @@ const state = reactive({
checkbox3: true, checkbox3: true,
checkboxShape: true, checkboxShape: true,
checkboxLabel: true, checkboxLabel: true,
checboxIcon: true, checkboxIcon: true,
list: ['a', 'b'], list: ['a', 'b'],
result: ['a', 'b'], result: ['a', 'b'],
result2: [], result2: [],
@ -58,9 +58,8 @@ const state = reactive({
horizontalResult: [], horizontalResult: [],
}); });
const activeIcon = 'https://cdn.jsdelivr.net/npm/@vant/assets/user-active.png'; const activeIcon = cdnURL('user-active.png');
const inactiveIcon = const inactiveIcon = cdnURL('user-inactive.png');
'https://cdn.jsdelivr.net/npm/@vant/assets/user-inactive.png';
const group = ref<CheckboxGroupInstance>(); const group = ref<CheckboxGroupInstance>();
const [refs, setRefs] = useRefs<CheckboxInstance>(); const [refs, setRefs] = useRefs<CheckboxInstance>();
@ -105,7 +104,7 @@ const toggleAll = () => {
</demo-block> </demo-block>
<demo-block :title="t('customIconSize')"> <demo-block :title="t('customIconSize')">
<van-checkbox v-model="state.checboxIcon" icon-size="24px"> <van-checkbox v-model="state.checkboxIcon" icon-size="24px">
{{ t('customIconSize') }} {{ t('customIconSize') }}
</van-checkbox> </van-checkbox>
</demo-block> </demo-block>

View File

@ -1,5 +1,6 @@
import { later, mount } from '../../../test'; import { later, mount } from '../../../test';
import { CouponList } from '..'; import { CouponList } from '..';
import { cdnURL } from '../../../docs/site/use-translate';
const coupon = { const coupon = {
id: 1, id: 1,
@ -106,7 +107,7 @@ test('should have two "van-coupon-list__empty" classes when render coupon list i
test('should use custom src when using empty-image prop', async () => { test('should use custom src when using empty-image prop', async () => {
const wrapper = mount(CouponList, { const wrapper = mount(CouponList, {
props: { props: {
emptyImage: 'https://cdn.jsdelivr.net/npm/@vant/assets/xxx.jpeg', emptyImage: cdnURL('xxx.jpeg'),
}, },
}); });

View File

@ -2,7 +2,7 @@
import VanCell from '../../cell'; import VanCell from '../../cell';
import { Dialog } from '..'; import { Dialog } from '..';
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { cdnURL, useTranslate } from '../../../docs/site/use-translate';
import type { DialogAction } from '../types'; import type { DialogAction } from '../types';
const VanDialog = Dialog.Component; const VanDialog = Dialog.Component;
@ -36,7 +36,7 @@ const t = useTranslate({
}); });
const show = ref(false); const show = ref(false);
const image = 'https://cdn.jsdelivr.net/npm/@vant/assets/apple-3.jpeg'; const image = cdnURL('apple-3.jpeg');
const onClickAlert = () => { const onClickAlert = () => {
Dialog.alert({ Dialog.alert({

View File

@ -4,7 +4,7 @@ import VanTabs from '../../tabs';
import VanTab from '../../tab'; import VanTab from '../../tab';
import VanButton from '../../button'; import VanButton from '../../button';
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { cdnURL, useTranslate } from '../../../docs/site/use-translate';
const t = useTranslate({ const t = useTranslate({
'zh-CN': { 'zh-CN': {
@ -52,7 +52,7 @@ const active = ref('error');
<demo-block :title="t('customImage')"> <demo-block :title="t('customImage')">
<van-empty <van-empty
class="custom-image" class="custom-image"
image="https://cdn.jsdelivr.net/npm/@vant/assets/custom-empty-image.png" :image="cdnURL('custom-empty-image.png')"
:description="t('description')" :description="t('description')"
/> />
</demo-block> </demo-block>

View File

@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { cdnURL, useTranslate } from '../../../docs/site/use-translate';
import VanForm from '..'; import VanForm from '..';
import VanRate from '../../rate'; import VanRate from '../../rate';
import VanRadio from '../../radio'; import VanRadio from '../../radio';
@ -54,9 +54,7 @@ const rate = ref(3);
const radio = ref('1'); const radio = ref('1');
const slider = ref(50); const slider = ref(50);
const stepper = ref(1); const stepper = ref(1);
const uploader = ref([ const uploader = ref([{ url: cdnURL('leaf.jpeg') }]);
{ url: 'https://cdn.jsdelivr.net/npm/@vant/assets/leaf.jpeg' },
]);
const checkbox = ref(false); const checkbox = ref(false);
const checkboxGroup = ref([]); const checkboxGroup = ref([]);
const switchChecked = ref(false); const switchChecked = ref(false);

View File

@ -2,7 +2,7 @@
import VanGrid from '..'; import VanGrid from '..';
import VanGridItem from '../../grid-item'; import VanGridItem from '../../grid-item';
import VanImage from '../../image'; import VanImage from '../../image';
import { useTranslate } from '../../../docs/site/use-translate'; import { cdnURL, useTranslate } from '../../../docs/site/use-translate';
const t = useTranslate({ const t = useTranslate({
'zh-CN': { 'zh-CN': {
@ -48,22 +48,13 @@ const t = useTranslate({
<demo-block :title="t('customContent')"> <demo-block :title="t('customContent')">
<van-grid :border="false" :column-num="3"> <van-grid :border="false" :column-num="3">
<van-grid-item> <van-grid-item>
<van-image <van-image fit="contain" :src="cdnURL('apple-1.jpeg')" />
fit="contain"
src="https://cdn.jsdelivr.net/npm/@vant/assets/apple-1.jpeg"
/>
</van-grid-item> </van-grid-item>
<van-grid-item> <van-grid-item>
<van-image <van-image fit="contain" :src="cdnURL('apple-2.jpeg')" />
fit="contain"
src="https://cdn.jsdelivr.net/npm/@vant/assets/apple-2.jpeg"
/>
</van-grid-item> </van-grid-item>
<van-grid-item> <van-grid-item>
<van-image <van-image fit="contain" :src="cdnURL('apple-3.jpeg')" />
fit="contain"
src="https://cdn.jsdelivr.net/npm/@vant/assets/apple-3.jpeg"
/>
</van-grid-item> </van-grid-item>
</van-grid> </van-grid>
</demo-block> </demo-block>

View File

@ -6,7 +6,7 @@ import VanRow from '../../row';
import VanCol from '../../col'; import VanCol from '../../col';
import icons from '@vant/icons'; import icons from '@vant/icons';
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { cdnURL, useTranslate } from '../../../docs/site/use-translate';
import { Notify } from '../../notify'; import { Notify } from '../../notify';
// from https://30secondsofcode.org // from https://30secondsofcode.org
@ -63,7 +63,7 @@ const t = useTranslate({
const tab = ref(0); const tab = ref(0);
const demoIcon = 'chat-o'; const demoIcon = 'chat-o';
const demoImage = 'https://cdn.jsdelivr.net/npm/@vant/assets/icon-demo.png'; const demoImage = cdnURL('icon-demo.png');
const copy = (icon: string, option: Record<string, unknown> = {}) => { const copy = (icon: string, option: Record<string, unknown> = {}) => {
let tag = `<van-icon name="${icon}"`; let tag = `<van-icon name="${icon}"`;

View File

@ -1,5 +1,6 @@
import { Icon } from '..'; import { Icon } from '..';
import { mount } from '../../../test'; import { mount } from '../../../test';
import { cdnURL } from '../../../docs/site/use-translate';
test('should render icon with builtin icon name correctly', () => { test('should render icon with builtin icon name correctly', () => {
const wrapper = mount(Icon, { const wrapper = mount(Icon, {
@ -13,7 +14,7 @@ test('should render icon with builtin icon name correctly', () => {
test('should render icon with url name correctly', () => { test('should render icon with url name correctly', () => {
const wrapper = mount(Icon, { const wrapper = mount(Icon, {
props: { props: {
name: 'https://cdn.jsdelivr.net/npm/@vant/assets/cat.jpeg', name: cdnURL('cat.jpeg'),
}, },
}); });
expect(wrapper.html()).toMatchSnapshot(); expect(wrapper.html()).toMatchSnapshot();

View File

@ -2,7 +2,7 @@
import VanCell from '../../cell'; import VanCell from '../../cell';
import { ImagePreview, ImagePreviewOptions } from '..'; import { ImagePreview, ImagePreviewOptions } from '..';
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { cdnURL, useTranslate } from '../../../docs/site/use-translate';
import { Toast } from '../../toast'; import { Toast } from '../../toast';
const VanImagePreview = ImagePreview.Component; const VanImagePreview = ImagePreview.Component;
@ -33,10 +33,10 @@ const t = useTranslate({
}); });
const images = [ const images = [
'https://cdn.jsdelivr.net/npm/@vant/assets/apple-1.jpeg', cdnURL('apple-1.jpeg'),
'https://cdn.jsdelivr.net/npm/@vant/assets/apple-2.jpeg', cdnURL('apple-2.jpeg'),
'https://cdn.jsdelivr.net/npm/@vant/assets/apple-3.jpeg', cdnURL('apple-3.jpeg'),
'https://cdn.jsdelivr.net/npm/@vant/assets/apple-4.jpeg', cdnURL('apple-4.jpeg'),
]; ];
const show = ref(false); const show = ref(false);

View File

@ -1,10 +1,11 @@
import { DOMWrapper } from '@vue/test-utils/dist/domWrapper'; import { DOMWrapper } from '@vue/test-utils/dist/domWrapper';
import { cdnURL } from '../../../docs/site/use-translate';
import { trigger } from '../../../test'; import { trigger } from '../../../test';
export const images = [ export const images = [
'https://cdn.jsdelivr.net/npm/@vant/assets/apple-1.jpeg', cdnURL('apple-1.jpeg'),
'https://cdn.jsdelivr.net/npm/@vant/assets/apple-2.jpeg', cdnURL('apple-2.jpeg'),
'https://cdn.jsdelivr.net/npm/@vant/assets/apple-3.jpeg', cdnURL('apple-3.jpeg'),
]; ];
function triggerTwoFingerTouchmove( function triggerTwoFingerTouchmove(

View File

@ -3,7 +3,7 @@ import VanRow from '../../row';
import VanImage from '..'; import VanImage from '..';
import VanCol from '../../col'; import VanCol from '../../col';
import VanLoading from '../../loading'; import VanLoading from '../../loading';
import { useTranslate } from '../../../docs/site/use-translate'; import { cdnURL, useTranslate } from '../../../docs/site/use-translate';
const t = useTranslate({ const t = useTranslate({
'zh-CN': { 'zh-CN': {
@ -28,7 +28,7 @@ const t = useTranslate({
}, },
}); });
const image = 'https://cdn.jsdelivr.net/npm/@vant/assets/cat.jpeg'; const image = cdnURL('cat.jpeg');
const fits = ['contain', 'cover', 'fill', 'none', 'scale-down'] as const; const fits = ['contain', 'cover', 'fill', 'none', 'scale-down'] as const;
const positions1 = ['left', 'center', 'right'] as const; const positions1 = ['left', 'center', 'right'] as const;
const positions2 = ['top', 'center', 'bottom'] as const; const positions2 = ['top', 'center', 'bottom'] as const;

View File

@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import Lazyload from '..'; import Lazyload from '..';
import { useTranslate } from '../../../docs/site/use-translate'; import { cdnURL, useTranslate } from '../../../docs/site/use-translate';
if (window.app) { if (window.app) {
window.app.use(Lazyload, { lazyComponent: true }); window.app.use(Lazyload, { lazyComponent: true });
@ -18,19 +18,13 @@ const t = useTranslate({
}); });
const imageList = [ const imageList = [
'https://cdn.jsdelivr.net/npm/@vant/assets/apple-1.jpeg', cdnURL('apple-1.jpeg'),
'https://cdn.jsdelivr.net/npm/@vant/assets/apple-2.jpeg', cdnURL('apple-2.jpeg'),
'https://cdn.jsdelivr.net/npm/@vant/assets/apple-3.jpeg', cdnURL('apple-3.jpeg'),
'https://cdn.jsdelivr.net/npm/@vant/assets/apple-4.jpeg', cdnURL('apple-4.jpeg'),
];
const backgroundImageList = [
'https://cdn.jsdelivr.net/npm/@vant/assets/apple-5.jpeg',
'https://cdn.jsdelivr.net/npm/@vant/assets/apple-6.jpeg',
];
const componentImageList = [
'https://cdn.jsdelivr.net/npm/@vant/assets/apple-8.jpeg',
'https://cdn.jsdelivr.net/npm/@vant/assets/apple-7.jpeg',
]; ];
const backgroundImageList = [cdnURL('apple-5.jpeg'), cdnURL('apple-6.jpeg')];
const componentImageList = [cdnURL('apple-8.jpeg'), cdnURL('apple-7.jpeg')];
</script> </script>
<template> <template>

View File

@ -3,7 +3,7 @@ import VanTabs from '../../tabs';
import VanTab from '../../tab'; import VanTab from '../../tab';
import VanPullRefresh from '..'; import VanPullRefresh from '..';
import { computed, onMounted, ref } from 'vue'; import { computed, onMounted, ref } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { cdnURL, useTranslate } from '../../../docs/site/use-translate';
import { Toast } from '../../toast'; import { Toast } from '../../toast';
const t = useTranslate({ const t = useTranslate({
@ -48,8 +48,8 @@ const preloadImage = () => {
const doge = new Image(); const doge = new Image();
const dogeFire = new Image(); const dogeFire = new Image();
doge.src = 'https://cdn.jsdelivr.net/npm/@vant/assets/doge.png'; doge.src = cdnURL('doge.png');
dogeFire.src = 'https://cdn.jsdelivr.net/npm/@vant/assets/doge-fire.jpeg'; dogeFire.src = cdnURL('doge-fire.jpeg');
}; };
onMounted(preloadImage); onMounted(preloadImage);
@ -82,21 +82,15 @@ onMounted(preloadImage);
<template #pulling="{ distance }"> <template #pulling="{ distance }">
<img <img
class="doge" class="doge"
src="https://cdn.jsdelivr.net/npm/@vant/assets/doge.png" :src="cdnURL('doge.png')"
:style="{ transform: `scale(${distance / 80})` }" :style="{ transform: `scale(${distance / 80})` }"
/> />
</template> </template>
<template #loosing> <template #loosing>
<img <img :src="cdnURL('doge.png')" class="doge" />
src="https://cdn.jsdelivr.net/npm/@vant/assets/doge.png"
class="doge"
/>
</template> </template>
<template #loading> <template #loading>
<img <img :src="cdnURL('doge-fire.jpeg')" class="doge" />
src="https://cdn.jsdelivr.net/npm/@vant/assets/doge-fire.jpeg"
class="doge"
/>
</template> </template>
<p>{{ tips }}</p> <p>{{ tips }}</p>
</van-pull-refresh> </van-pull-refresh>

View File

@ -4,7 +4,7 @@ import VanRadio from '..';
import VanCellGroup from '../../cell-group'; import VanCellGroup from '../../cell-group';
import VanCell from '../../cell'; import VanCell from '../../cell';
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { cdnURL, useTranslate } from '../../../docs/site/use-translate';
const t = useTranslate({ const t = useTranslate({
'zh-CN': { 'zh-CN': {
@ -42,9 +42,8 @@ const radioLabel = ref('1');
const radioShape = ref('1'); const radioShape = ref('1');
const radioIconSize = ref('1'); const radioIconSize = ref('1');
const radioHorizontal = ref('1'); const radioHorizontal = ref('1');
const activeIcon = 'https://cdn.jsdelivr.net/npm/@vant/assets/user-active.png'; const activeIcon = cdnURL('user-active.png');
const inactiveIcon = const inactiveIcon = cdnURL('user-inactive.png');
'https://cdn.jsdelivr.net/npm/@vant/assets/user-inactive.png';
</script> </script>
<template> <template>

View File

@ -2,7 +2,7 @@
import VanCell from '../../cell'; import VanCell from '../../cell';
import VanShareSheet, { ShareSheetOption, ShareSheetOptions } from '..'; import VanShareSheet, { ShareSheetOption, ShareSheetOptions } from '..';
import { ref, computed } from 'vue'; import { ref, computed } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { cdnURL, useTranslate } from '../../../docs/site/use-translate';
import { Toast } from '../../toast'; import { Toast } from '../../toast';
const t = useTranslate({ const t = useTranslate({
@ -73,15 +73,15 @@ const multiLineOptions = computed(() => [
const customIconOptions = computed(() => [ const customIconOptions = computed(() => [
{ {
name: t('name'), name: t('name'),
icon: 'https://cdn.jsdelivr.net/npm/@vant/assets/custom-icon-fire.png', icon: cdnURL('custom-icon-fire.png'),
}, },
{ {
name: t('name'), name: t('name'),
icon: 'https://cdn.jsdelivr.net/npm/@vant/assets/custom-icon-light.png', icon: cdnURL('custom-icon-light.png'),
}, },
{ {
name: t('name'), name: t('name'),
icon: 'https://cdn.jsdelivr.net/npm/@vant/assets/custom-icon-water.png', icon: cdnURL('custom-icon-water.png'),
}, },
]); ]);

View File

@ -2,7 +2,7 @@
import VanSkeleton from '..'; import VanSkeleton from '..';
import VanSwitch from '../../switch'; import VanSwitch from '../../switch';
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { cdnURL, useTranslate } from '../../../docs/site/use-translate';
const t = useTranslate({ const t = useTranslate({
'zh-CN': { 'zh-CN': {
@ -35,7 +35,7 @@ const show = ref(false);
<van-switch v-model="show" size="24px" /> <van-switch v-model="show" size="24px" />
<van-skeleton title avatar :row="3" :loading="!show"> <van-skeleton title avatar :row="3" :loading="!show">
<div class="demo-preview"> <div class="demo-preview">
<img src="https://cdn.jsdelivr.net/npm/@vant/assets/logo.png" /> <img :src="cdnURL('logo.png')" />
<div class="demo-content"> <div class="demo-content">
<h3>{{ t('title') }}</h3> <h3>{{ t('title') }}</h3>
<p>{{ t('desc') }}</p> <p>{{ t('desc') }}</p>

View File

@ -3,7 +3,7 @@ import VanSwipeCell from '..';
import VanButton from '../../button'; import VanButton from '../../button';
import VanCell from '../../cell'; import VanCell from '../../cell';
import VanCard from '../../card'; import VanCard from '../../card';
import { useTranslate } from '../../../docs/site/use-translate'; import { cdnURL, useTranslate } from '../../../docs/site/use-translate';
import { Dialog } from '../../dialog'; import { Dialog } from '../../dialog';
const t = useTranslate({ const t = useTranslate({
@ -29,7 +29,7 @@ const t = useTranslate({
}, },
}); });
const imageURL = 'https://cdn.jsdelivr.net/npm/@vant/assets/ipad.jpeg'; const imageURL = cdnURL('ipad.jpeg');
const beforeClose = ({ position }: { position: string }) => { const beforeClose = ({ position }: { position: string }) => {
switch (position) { switch (position) {

View File

@ -1,7 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
import VanSwipe from '..'; import VanSwipe from '..';
import VanSwipeItem from '../../swipe-item'; import VanSwipeItem from '../../swipe-item';
import { useTranslate } from '../../../docs/site/use-translate'; import { cdnURL, useTranslate } from '../../../docs/site/use-translate';
import { Toast } from '../../toast'; import { Toast } from '../../toast';
const t = useTranslate({ const t = useTranslate({
@ -24,10 +24,10 @@ const t = useTranslate({
}); });
const images = [ const images = [
'https://cdn.jsdelivr.net/npm/@vant/assets/apple-1.jpeg', cdnURL('apple-1.jpeg'),
'https://cdn.jsdelivr.net/npm/@vant/assets/apple-2.jpeg', cdnURL('apple-2.jpeg'),
'https://cdn.jsdelivr.net/npm/@vant/assets/apple-3.jpeg', cdnURL('apple-3.jpeg'),
'https://cdn.jsdelivr.net/npm/@vant/assets/apple-4.jpeg', cdnURL('apple-4.jpeg'),
]; ];
const onChange = (index: number) => Toast(t('message') + index); const onChange = (index: number) => Toast(t('message') + index);

View File

@ -2,7 +2,7 @@
import VanTabbar from '..'; import VanTabbar from '..';
import VanTabbarItem from '../../tabbar-item'; import VanTabbarItem from '../../tabbar-item';
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { cdnURL, useTranslate } from '../../../docs/site/use-translate';
import { Toast } from '../../toast'; import { Toast } from '../../toast';
const t = useTranslate({ const t = useTranslate({
@ -30,8 +30,8 @@ const active5 = ref(0);
const activeName = ref('home'); const activeName = ref('home');
const icon = { const icon = {
active: 'https://cdn.jsdelivr.net/npm/@vant/assets/user-active.png', active: cdnURL('user-active.png'),
inactive: 'https://cdn.jsdelivr.net/npm/@vant/assets/user-inactive.png', inactive: cdnURL('user-inactive.png'),
}; };
const onChange = (index: number) => { const onChange = (index: number) => {

View File

@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import VanCell from '../../cell'; import VanCell from '../../cell';
import { useTranslate } from '../../../docs/site/use-translate'; import { cdnURL, useTranslate } from '../../../docs/site/use-translate';
import { Toast } from '..'; import { Toast } from '..';
import type { LoadingType } from '../../loading'; import type { LoadingType } from '../../loading';
@ -83,7 +83,7 @@ const showIconToast = () => {
const showImageToast = () => { const showImageToast = () => {
Toast({ Toast({
message: t('customImage'), message: t('customImage'),
icon: 'https://cdn.jsdelivr.net/npm/@vant/assets/logo.png', icon: cdnURL('logo.png'),
}); });
}; };

View File

@ -2,7 +2,7 @@
import VanTreeSelect from '..'; import VanTreeSelect from '..';
import VanImage from '../../image'; import VanImage from '../../image';
import { ref, computed } from 'vue'; import { ref, computed } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { cdnURL, useTranslate } from '../../../docs/site/use-translate';
import { zhCNData } from './data-zh'; import { zhCNData } from './data-zh';
import { enUSData } from './data-en'; import { enUSData } from './data-en';
import { deepClone } from '../../utils/deep-clone'; import { deepClone } from '../../utils/deep-clone';
@ -73,12 +73,12 @@ const badgeItems = computed(() => {
<van-image <van-image
v-if="activeIndex3 === 0" v-if="activeIndex3 === 0"
:show-loading="false" :show-loading="false"
src="https://cdn.jsdelivr.net/npm/@vant/assets/apple-1.jpeg" :src="cdnURL('apple-1.jpeg')"
/> />
<van-image <van-image
v-if="activeIndex3 === 1" v-if="activeIndex3 === 1"
:show-loading="false" :show-loading="false"
src="https://cdn.jsdelivr.net/npm/@vant/assets/apple-2.jpeg" :src="cdnURL('apple-2.jpeg')"
/> />
</template> </template>
</van-tree-select> </van-tree-select>

View File

@ -2,7 +2,7 @@
import VanUploader from '..'; import VanUploader from '..';
import VanButton from '../../button'; import VanButton from '../../button';
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '../../../docs/site/use-translate'; import { cdnURL, useTranslate } from '../../../docs/site/use-translate';
import { UploaderFileListItem } from '../types'; import { UploaderFileListItem } from '../types';
import { Toast } from '../../toast'; import { Toast } from '../../toast';
@ -48,42 +48,38 @@ const t = useTranslate({
}); });
const fileList = ref([ const fileList = ref([
{ url: 'https://cdn.jsdelivr.net/npm/@vant/assets/leaf.jpeg' }, { url: cdnURL('leaf.jpeg') },
{ url: 'https://cdn.jsdelivr.net/npm/@vant/assets/tree.jpeg' }, { url: cdnURL('tree.jpeg') },
]); ]);
const fileList2 = ref([ const fileList2 = ref([{ url: cdnURL('sand.jpeg') }]);
{ url: 'https://cdn.jsdelivr.net/npm/@vant/assets/sand.jpeg' },
]);
const fileList3 = ref([]); const fileList3 = ref([]);
const fileList4 = ref([ const fileList4 = ref([{ url: cdnURL('sand.jpeg') }]);
{ url: 'https://cdn.jsdelivr.net/npm/@vant/assets/sand.jpeg' },
]);
const fileList5 = ref<UploaderFileListItem[]>([ const fileList5 = ref<UploaderFileListItem[]>([
{ {
url: 'https://cdn.jsdelivr.net/npm/@vant/assets/sand.jpeg', url: cdnURL('sand.jpeg'),
deletable: true, deletable: true,
beforeDelete: () => { beforeDelete: () => {
Toast(t('deleteMessage')); Toast(t('deleteMessage'));
}, },
}, },
{ {
url: 'https://cdn.jsdelivr.net/npm/@vant/assets/tree.jpeg', url: cdnURL('tree.jpeg'),
imageFit: 'contain', imageFit: 'contain',
}, },
]); ]);
const statusFileList = ref<UploaderFileListItem[]>([ const statusFileList = ref<UploaderFileListItem[]>([
{ {
url: 'https://cdn.jsdelivr.net/npm/@vant/assets/leaf.jpeg', url: cdnURL('leaf.jpeg'),
status: 'uploading', status: 'uploading',
message: t('uploading'), message: t('uploading'),
}, },
{ {
url: 'https://cdn.jsdelivr.net/npm/@vant/assets/tree.jpeg', url: cdnURL('tree.jpeg'),
status: 'failed', status: 'failed',
message: t('failed'), message: t('failed'),
}, },
@ -91,7 +87,7 @@ const statusFileList = ref<UploaderFileListItem[]>([
const previewCoverFiles = ref<UploaderFileListItem[]>([ const previewCoverFiles = ref<UploaderFileListItem[]>([
{ {
url: 'https://cdn.jsdelivr.net/npm/@vant/assets/leaf.jpeg', url: cdnURL('leaf.jpeg'),
file: { file: {
name: t('imageName'), name: t('imageName'),
} as File, } as File,
@ -100,7 +96,7 @@ const previewCoverFiles = ref<UploaderFileListItem[]>([
const previewSizeFiles = ref<UploaderFileListItem[]>([ const previewSizeFiles = ref<UploaderFileListItem[]>([
{ {
url: 'https://cdn.jsdelivr.net/npm/@vant/assets/leaf.jpeg', url: cdnURL('leaf.jpeg'),
}, },
]); ]);

View File

@ -1,3 +1,4 @@
import { cdnURL } from '../../../docs/site/use-translate';
import { nextTick } from 'vue'; import { nextTick } from 'vue';
import Uploader, { UploaderFileListItem } from '..'; import Uploader, { UploaderFileListItem } from '..';
import { mount, later, triggerDrag } from '../../../test'; import { mount, later, triggerDrag } from '../../../test';
@ -6,8 +7,8 @@ const mockFileDataUrl = 'data:image/test';
const mockFile = new File([new ArrayBuffer(10000)], 'test.jpg', { const mockFile = new File([new ArrayBuffer(10000)], 'test.jpg', {
type: 'test', type: 'test',
}); });
const IMAGE = 'https://cdn.jsdelivr.net/npm/@vant/assets/cat.jpeg'; const IMAGE = cdnURL('cat.jpeg');
const PDF = 'https://cdn.jsdelivr.net/npm/@vant/assets/test.pdf'; const PDF = cdnURL('test.pdf');
function mockFileReader() { function mockFileReader() {
function mockReadAsText(this: FileReader) { function mockReadAsText(this: FileReader) {
@ -293,8 +294,8 @@ test('render preview image', async () => {
const wrapper = mount(Uploader, { const wrapper = mount(Uploader, {
props: { props: {
modelValue: [ modelValue: [
{ url: 'https://cdn.jsdelivr.net/npm/@vant/assets/cat.jpeg' }, { url: cdnURL('cat.jpeg') },
{ url: 'https://cdn.jsdelivr.net/npm/@vant/assets/test.pdf' }, { url: cdnURL('test.pdf') },
{ file: mockFile }, { file: mockFile },
], ],
}, },
@ -307,9 +308,7 @@ test('image-fit prop', () => {
const wrapper = mount(Uploader, { const wrapper = mount(Uploader, {
props: { props: {
imageFit: 'contain', imageFit: 'contain',
modelValue: [ modelValue: [{ url: cdnURL('cat.jpeg') }],
{ url: 'https://cdn.jsdelivr.net/npm/@vant/assets/cat.jpeg' },
],
}, },
}); });
@ -368,7 +367,6 @@ test('should allow to custom size by preview-size prop', async () => {
}, },
}); });
console.log(wrapper.html());
const image = wrapper.find('.van-uploader__file'); const image = wrapper.find('.van-uploader__file');
expect(image.style.width).toEqual('30px'); expect(image.style.width).toEqual('30px');
expect(image.style.height).toEqual('30px'); expect(image.style.height).toEqual('30px');