chore: remote isWeapp mixin (#9236)

* chore: remote isWeapp mixin

* fix: demo locale
This commit is contained in:
neverland 2021-08-11 11:06:53 +08:00 committed by GitHub
parent 4c41908ac1
commit 735f7dd24a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 31 additions and 45 deletions

View File

@ -5,15 +5,6 @@ Locale.add({
'en-US': enUS, 'en-US': enUS,
}); });
export const DemoLocaleMixin = {
computed: {
// flag for vant-weapp demos
isWeapp() {
return location.search.indexOf('weapp=1') !== -1;
},
},
};
// switch lang after routing // switch lang after routing
if (window.vueRouter) { if (window.vueRouter) {
window.vueRouter.afterEach((to) => { window.vueRouter.afterEach((to) => {

View File

@ -1,11 +1,8 @@
import { DemoLocaleMixin } from './demo-locale'; import './demo-locale';
import Lazyload from '../../src/lazyload'; import Lazyload from '../../src/lazyload';
const { app } = window; const { app } = window;
if (app) { if (app) {
// helper for demo locales
app.mixin(DemoLocaleMixin);
app.use(Lazyload, { app.use(Lazyload, {
lazyComponent: true, lazyComponent: true,
}); });

View File

@ -72,7 +72,7 @@ const onClickButton = () => Toast(t('clickButton'));
</van-action-bar> </van-action-bar>
</demo-block> </demo-block>
<demo-block v-if="!isWeapp" :title="t('customIconColor')"> <demo-block :title="t('customIconColor')">
<van-action-bar> <van-action-bar>
<van-action-bar-icon icon="chat-o" :text="t('icon1')" color="#ee0a24" /> <van-action-bar-icon icon="chat-o" :text="t('icon1')" color="#ee0a24" />
<van-action-bar-icon icon="cart-o" :text="t('icon2')" /> <van-action-bar-icon icon="cart-o" :text="t('icon2')" />

View File

@ -124,7 +124,7 @@ const t = useTranslate(i18n);
<van-button type="primary" block>{{ t('blockElement') }}</van-button> <van-button type="primary" block>{{ t('blockElement') }}</van-button>
</demo-block> </demo-block>
<demo-block v-if="!isWeapp" :title="t('router')"> <demo-block :title="t('router')">
<van-button :text="t('urlRoute')" type="primary" url="/vant/mobile.html" /> <van-button :text="t('urlRoute')" type="primary" url="/vant/mobile.html" />
<van-button :text="t('vueRoute')" type="primary" to="index" /> <van-button :text="t('vueRoute')" type="primary" to="index" />
</demo-block> </demo-block>

View File

@ -282,7 +282,6 @@ const onConfirm = (date: Date | Date[]) => {
/> />
<van-cell <van-cell
v-if="!isWeapp"
is-link is-link
:title="t('firstDayOfWeek')" :title="t('firstDayOfWeek')"
@click="show('single', 'firstDayOfWeek')" @click="show('single', 'firstDayOfWeek')"

View File

@ -45,7 +45,7 @@ const t = useTranslate(i18n);
</van-cell-group> </van-cell-group>
</demo-block> </demo-block>
<demo-block v-if="!isWeapp" :title="t('insetGrouped')"> <demo-block :title="t('insetGrouped')">
<van-cell-group inset> <van-cell-group inset>
<van-cell :title="t('cell')" :value="t('content')" /> <van-cell :title="t('cell')" :value="t('content')" />
<van-cell :title="t('cell')" :value="t('content')" :label="t('desc')" /> <van-cell :title="t('cell')" :value="t('content')" :label="t('desc')" />
@ -66,7 +66,7 @@ const t = useTranslate(i18n);
<van-cell :title="t('cell')" :value="t('content')" icon="location-o" /> <van-cell :title="t('cell')" :value="t('content')" icon="location-o" />
</demo-block> </demo-block>
<demo-block v-if="!isWeapp" :title="t('valueOnly')"> <demo-block :title="t('valueOnly')">
<van-cell :value="t('content')" /> <van-cell :value="t('content')" />
</demo-block> </demo-block>

View File

@ -126,7 +126,7 @@ const toggleAll = () => {
</van-checkbox-group> </van-checkbox-group>
</demo-block> </demo-block>
<demo-block v-if="!isWeapp" :title="t('horizontal')"> <demo-block :title="t('horizontal')">
<van-checkbox-group v-model="state.horizontalResult" direction="horizontal"> <van-checkbox-group v-model="state.horizontalResult" direction="horizontal">
<van-checkbox name="a">{{ t('checkbox') }} a</van-checkbox> <van-checkbox name="a">{{ t('checkbox') }} a</van-checkbox>
<van-checkbox name="b">{{ t('checkbox') }} b</van-checkbox> <van-checkbox name="b">{{ t('checkbox') }} b</van-checkbox>
@ -141,7 +141,7 @@ const toggleAll = () => {
</van-checkbox-group> </van-checkbox-group>
</demo-block> </demo-block>
<demo-block v-if="!isWeapp" :title="t('toggleAll')"> <demo-block :title="t('toggleAll')">
<van-checkbox-group v-model="state.checkAllResult" ref="group"> <van-checkbox-group v-model="state.checkAllResult" ref="group">
<van-checkbox name="a">{{ t('checkbox') }} a</van-checkbox> <van-checkbox name="a">{{ t('checkbox') }} a</van-checkbox>
<van-checkbox name="b">{{ t('checkbox') }} b</van-checkbox> <van-checkbox name="b">{{ t('checkbox') }} b</van-checkbox>

View File

@ -41,7 +41,7 @@ const t = useTranslate(i18n);
</van-row> </van-row>
</demo-block> </demo-block>
<demo-block v-if="!isWeapp" :title="t('justify')"> <demo-block :title="t('justify')">
<van-row justify="center"> <van-row justify="center">
<van-col span="6">span: 6</van-col> <van-col span="6">span: 6</van-col>
<van-col span="6">span: 6</van-col> <van-col span="6">span: 6</van-col>

View File

@ -89,7 +89,7 @@ const formatter = (type: string, value: string) => {
/> />
</demo-block> </demo-block>
<demo-block v-if="!isWeapp" card :title="t('monthDayType')"> <demo-block card :title="t('monthDayType')">
<van-datetime-picker <van-datetime-picker
v-model="value.monthDay" v-model="value.monthDay"
type="month-day" type="month-day"
@ -120,7 +120,7 @@ const formatter = (type: string, value: string) => {
/> />
</demo-block> </demo-block>
<demo-block v-if="!isWeapp" card :title="t('datehourType')"> <demo-block card :title="t('datehourType')">
<van-datetime-picker <van-datetime-picker
v-model="value.datehour" v-model="value.datehour"
type="datehour" type="datehour"
@ -139,7 +139,7 @@ const formatter = (type: string, value: string) => {
/> />
</demo-block> </demo-block>
<demo-block v-if="!isWeapp" card :title="t('sortColumns')"> <demo-block card :title="t('sortColumns')">
<van-datetime-picker <van-datetime-picker
v-model="value.sortColumnsDate" v-model="value.sortColumnsDate"
type="date" type="date"

View File

@ -26,7 +26,7 @@ const formatter = (value: string) => value.replace(/\d/g, '');
</script> </script>
<template> <template>
<demo-block v-if="!isWeapp" :title="t('formatValue')"> <demo-block :title="t('formatValue')">
<van-cell-group inset> <van-cell-group inset>
<van-field <van-field
v-model="state.value1" v-model="state.value1"

View File

@ -20,7 +20,7 @@ const value = ref('');
</script> </script>
<template> <template>
<demo-block v-if="!isWeapp" :title="t('showWordLimit')"> <demo-block :title="t('showWordLimit')">
<van-cell-group inset> <van-cell-group inset>
<van-field <van-field
v-model="value" v-model="value"

View File

@ -55,7 +55,7 @@ const t = useTranslate(i18n);
/> />
</demo-block> </demo-block>
<demo-block v-if="!isWeapp" :title="t('verticalScroll')"> <demo-block :title="t('verticalScroll')">
<van-notice-bar left-icon="volume-o" :scrollable="false"> <van-notice-bar left-icon="volume-o" :scrollable="false">
<van-swipe <van-swipe
vertical vertical

View File

@ -149,7 +149,7 @@ const onConfirm2 = (value: string) => {
/> />
</demo-block> </demo-block>
<demo-block card v-if="!isWeapp" :title="t('cascade')"> <demo-block card :title="t('cascade')">
<van-picker :title="t('title')" :columns="t('cascadeColumns')" /> <van-picker :title="t('title')" :columns="t('cascadeColumns')" />
</demo-block> </demo-block>
@ -170,7 +170,7 @@ const onConfirm2 = (value: string) => {
<van-picker loading :title="t('title')" :columns="columns" /> <van-picker loading :title="t('title')" :columns="columns" />
</demo-block> </demo-block>
<demo-block card v-if="!isWeapp" :title="t('withPopup')"> <demo-block card :title="t('withPopup')">
<van-field <van-field
v-model="fieldValue" v-model="fieldValue"
is-link is-link

View File

@ -129,7 +129,7 @@ const showCustomIconPosition = ref(false);
/> />
</demo-block> </demo-block>
<demo-block card v-if="!isWeapp" :title="t('teleport')"> <demo-block card :title="t('teleport')">
<van-cell :title="t('teleport')" is-link @click="showGetContainer = true" /> <van-cell :title="t('teleport')" is-link @click="showGetContainer = true" />
<van-popup <van-popup
v-model:show="showGetContainer" v-model:show="showGetContainer"

View File

@ -22,7 +22,7 @@ const t = useTranslate(i18n);
<van-progress :percentage="50" /> <van-progress :percentage="50" />
</demo-block> </demo-block>
<demo-block v-if="!isWeapp" :title="t('strokeWidth')"> <demo-block :title="t('strokeWidth')">
<van-progress :percentage="50" stroke-width="8" /> <van-progress :percentage="50" stroke-width="8" />
</demo-block> </demo-block>

View File

@ -51,7 +51,7 @@ const inactiveIcon = 'https://img.yzcdn.cn/vant/user-inactive.png';
</van-radio-group> </van-radio-group>
</demo-block> </demo-block>
<demo-block v-if="!isWeapp" :title="t('horizontal')"> <demo-block :title="t('horizontal')">
<van-radio-group <van-radio-group
v-model="radioHorizontal" v-model="radioHorizontal"
class="demo-radio-group" class="demo-radio-group"

View File

@ -80,7 +80,7 @@ const onChange = (value: number) => Toast(t('toastContent', value));
<van-rate v-model="value7" readonly allow-half /> <van-rate v-model="value7" readonly allow-half />
</demo-block> </demo-block>
<demo-block v-if="!isWeapp" :title="t('changeEvent')"> <demo-block :title="t('changeEvent')">
<van-rate v-model="value8" @change="onChange" /> <van-rate v-model="value8" @change="onChange" />
</demo-block> </demo-block>
</template> </template>

View File

@ -47,7 +47,7 @@ const onChange = (value: string) => Toast(t('text') + value);
<van-slider v-model="value1" @change="onChange" /> <van-slider v-model="value1" @change="onChange" />
</demo-block> </demo-block>
<demo-block v-if="!isWeapp" :title="t('title2')"> <demo-block :title="t('title2')">
<van-slider range v-model="value2" @change="onChange" /> <van-slider range v-model="value2" @change="onChange" />
</demo-block> </demo-block>
@ -80,7 +80,7 @@ const onChange = (value: string) => Toast(t('text') + value);
</van-slider> </van-slider>
</demo-block> </demo-block>
<demo-block v-if="!isWeapp" :title="t('vertical')"> <demo-block :title="t('vertical')">
<div :style="{ height: '150px', paddingLeft: '30px' }"> <div :style="{ height: '150px', paddingLeft: '30px' }">
<van-slider v-model="value8" vertical @change="onChange" /> <van-slider v-model="value8" vertical @change="onChange" />
<van-slider <van-slider

View File

@ -106,7 +106,7 @@ const beforeChange = () => {
</template> </template>
</van-cell> </van-cell>
<van-cell v-if="!isWeapp" center :title="t('roundTheme')"> <van-cell center :title="t('roundTheme')">
<template #value> <template #value>
<van-stepper <van-stepper
v-model="stepperRound" v-model="stepperRound"

View File

@ -36,7 +36,7 @@ const container = ref(null);
</van-sticky> </van-sticky>
</demo-block> </demo-block>
<demo-block v-if="!isWeapp" :title="t('setContainer')"> <demo-block :title="t('setContainer')">
<div ref="container" style="height: 150px; background-color: #fff"> <div ref="container" style="height: 150px; background-color: #fff">
<van-sticky :container="container"> <van-sticky :container="container">
<van-button type="warning" style="margin-left: 215px"> <van-button type="warning" style="margin-left: 215px">

View File

@ -119,7 +119,7 @@ const beforeChange = (name: number) => {
</van-tabs> </van-tabs>
</demo-block> </demo-block>
<demo-block v-if="!isWeapp" :title="t('title7')"> <demo-block :title="t('title7')">
<van-tabs :active="active"> <van-tabs :active="active">
<van-tab v-for="index in 2" :key="index"> <van-tab v-for="index in 2" :key="index">
<template #title> <van-icon name="more-o" />{{ t('tab') }} </template> <template #title> <van-icon name="more-o" />{{ t('tab') }} </template>
@ -144,7 +144,7 @@ const beforeChange = (name: number) => {
</van-tabs> </van-tabs>
</demo-block> </demo-block>
<demo-block v-if="!isWeapp" :title="t('title10')"> <demo-block :title="t('title10')">
<van-tabs scrollspy sticky> <van-tabs scrollspy sticky>
<van-tab :title="t('tab') + index" v-for="index in 8" :key="index"> <van-tab :title="t('tab') + index" v-for="index in 8" :key="index">
{{ t('content') }} {{ index }} {{ t('content') }} {{ index }}
@ -152,7 +152,7 @@ const beforeChange = (name: number) => {
</van-tabs> </van-tabs>
</demo-block> </demo-block>
<demo-block v-if="!isWeapp" :title="t('beforeChange')"> <demo-block :title="t('beforeChange')">
<van-tabs :before-change="beforeChange"> <van-tabs :before-change="beforeChange">
<van-tab :title="t('tab') + index" v-for="index in 4" :key="index"> <van-tab :title="t('tab') + index" v-for="index in 4" :key="index">
{{ t('content') }} {{ index }} {{ t('content') }} {{ index }}

View File

@ -116,7 +116,7 @@ const showCustomizedToast = () => {
<van-cell is-link :title="t('fail')" @click="showFailToast" /> <van-cell is-link :title="t('fail')" @click="showFailToast" />
</demo-block> </demo-block>
<demo-block card v-if="!isWeapp" :title="t('customIcon')"> <demo-block card :title="t('customIcon')">
<van-cell is-link :title="t('customIcon')" @click="showIconToast" /> <van-cell is-link :title="t('customIcon')" @click="showIconToast" />
<van-cell is-link :title="t('customImage')" @click="showImageToast" /> <van-cell is-link :title="t('customImage')" @click="showImageToast" />
<van-cell <van-cell
@ -126,7 +126,7 @@ const showCustomizedToast = () => {
/> />
</demo-block> </demo-block>
<demo-block card v-if="!isWeapp" :title="t('customPosition')"> <demo-block card :title="t('customPosition')">
<van-cell is-link :title="t('positionTop')" @click="showTopToast" /> <van-cell is-link :title="t('positionTop')" @click="showTopToast" />
<van-cell is-link :title="t('positionBottom')" @click="showBottomToast" /> <van-cell is-link :title="t('positionBottom')" @click="showBottomToast" />
</demo-block> </demo-block>

View File

@ -132,7 +132,7 @@ const onOversize = (file: UploaderFileListItem, detail: unknown) => {
<van-uploader v-model="fileList" multiple accept="*" /> <van-uploader v-model="fileList" multiple accept="*" />
</demo-block> </demo-block>
<demo-block v-if="!isWeapp" :title="t('status')"> <demo-block :title="t('status')">
<van-uploader v-model="statusFileList" :after-read="afterReadFailed" /> <van-uploader v-model="statusFileList" :after-read="afterReadFailed" />
</demo-block> </demo-block>

View File

@ -1,7 +1,7 @@
import { h, defineComponent } from 'vue'; import { h, defineComponent } from 'vue';
import Locale from '../src/locale'; import Locale from '../src/locale';
import { mount, later } from '.'; import { mount, later } from '.';
import { DemoLocaleMixin } from '../docs/site/demo-locale'; import '../docs/site/demo-locale';
const EmptyComponent = defineComponent({ const EmptyComponent = defineComponent({
inheritAttrs: false, inheritAttrs: false,
@ -22,7 +22,6 @@ export function snapshotDemo(Demo: any, option: any = {}) {
const wrapper = mount(Demo, { const wrapper = mount(Demo, {
global: { global: {
mixins: [DemoLocaleMixin],
components: { components: {
'demo-block': EmptyComponent, 'demo-block': EmptyComponent,
}, },