chore: demo ts (#8160)

* chore: demo ts

* chore: fix
This commit is contained in:
neverland 2021-02-14 19:50:45 +08:00 committed by GitHub
parent 8cbf153073
commit a8060bb599
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 96 additions and 79 deletions

View File

@ -103,10 +103,11 @@
</demo-block> </demo-block>
</template> </template>
<script> <script lang="ts">
import { ref, reactive, toRefs } from 'vue'; import { ref, reactive, toRefs } from 'vue';
import { useTranslate } from '@demo/use-translate'; import { useTranslate } from '@demo/use-translate';
import { useRefs } from '../../composables/use-refs'; import { useRefs } from '../../composables/use-refs';
import { ComponentInstance } from 'src/utils';
const i18n = { const i18n = {
'zh-CN': { 'zh-CN': {
@ -159,19 +160,19 @@ export default {
horizontalResult: [], horizontalResult: [],
}); });
const group = ref(); const group = ref<ComponentInstance>();
const [refs, setRefs] = useRefs(); const [refs, setRefs] = useRefs<ComponentInstance>();
const toggle = (index) => { const toggle = (index: number) => {
refs.value[index].toggle(); refs.value[index].toggle();
}; };
const checkAll = () => { const checkAll = () => {
group.value.toggleAll(true); group.value?.toggleAll(true);
}; };
const toggleAll = () => { const toggleAll = () => {
group.value.toggleAll(); group.value?.toggleAll();
}; };
return { return {

View File

@ -40,9 +40,10 @@
</demo-block> </demo-block>
</template> </template>
<script> <script lang="ts">
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '@demo/use-translate'; import { useTranslate } from '@demo/use-translate';
import { ComponentInstance } from '../../utils';
import Toast from '../../toast'; import Toast from '../../toast';
const i18n = { const i18n = {
@ -74,16 +75,16 @@ export default {
setup() { setup() {
const t = useTranslate(i18n); const t = useTranslate(i18n);
const time = ref(30 * 60 * 60 * 1000); const time = ref(30 * 60 * 60 * 1000);
const countDown = ref(null); const countDown = ref<ComponentInstance>();
const start = () => { const start = () => {
countDown.value.start(); countDown.value?.start();
}; };
const pause = () => { const pause = () => {
countDown.value.pause(); countDown.value?.pause();
}; };
const reset = () => { const reset = () => {
countDown.value.reset(); countDown.value?.reset();
}; };
const onFinish = () => Toast(t('finished')); const onFinish = () => Toast(t('finished'));

View File

@ -27,10 +27,11 @@
</demo-block> </demo-block>
</template> </template>
<script> <script lang="ts">
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '@demo/use-translate'; import { useTranslate } from '@demo/use-translate';
import Dialog from '..'; import Dialog from '..';
import { DialogAction } from 'types/dialog';
const i18n = { const i18n = {
'zh-CN': { 'zh-CN': {
@ -93,8 +94,8 @@ export default {
}; };
const onClickBeforeClose = () => { const onClickBeforeClose = () => {
const beforeClose = (action) => const beforeClose = (action: DialogAction) =>
new Promise((resolve) => { new Promise<boolean>((resolve) => {
setTimeout(() => resolve(action === 'confirm'), 1000); setTimeout(() => resolve(action === 'confirm'), 1000);
}); });

View File

@ -11,17 +11,17 @@
<input-align /> <input-align />
</template> </template>
<script> <script lang="ts">
import BasicUsage from './BasicUsage'; import BasicUsage from './BasicUsage.vue';
import CustomType from './CustomType'; import CustomType from './CustomType.vue';
import Disabled from './Disabled'; import Disabled from './Disabled.vue';
import ShowIcon from './ShowIcon'; import ShowIcon from './ShowIcon.vue';
import ErrorInfo from './ErrorInfo'; import ErrorInfo from './ErrorInfo.vue';
import InsertButton from './InsertButton'; import InsertButton from './InsertButton.vue';
import FormatValue from './FormatValue'; import FormatValue from './FormatValue.vue';
import Autosize from './Autosize'; import Autosize from './Autosize.vue';
import ShowWordLimit from './ShowWordLimit'; import ShowWordLimit from './ShowWordLimit.vue';
import InputAlign from './InputAlign'; import InputAlign from './InputAlign.vue';
export default { export default {
components: { components: {

View File

@ -25,9 +25,10 @@
</demo-block> </demo-block>
</template> </template>
<script> <script lang="ts">
import { reactive, toRefs } from 'vue'; import { reactive, toRefs } from 'vue';
import { useTranslate } from '@demo/use-translate'; import { useTranslate } from '@demo/use-translate';
import { FieldValidateError } from '../../field/types';
const i18n = { const i18n = {
'zh-CN': { 'zh-CN': {
@ -54,10 +55,14 @@ export default {
password: '', password: '',
}); });
const onSubmit = (values) => { const onSubmit = (values: Record<string, string>) => {
console.log('submit', values); console.log('submit', values);
}; };
const onFailed = (errorInfo) => {
const onFailed = (errorInfo: {
values: Record<string, string>;
errors: FieldValidateError[];
}) => {
console.log('failed', errorInfo); console.log('failed', errorInfo);
}; };

View File

@ -73,13 +73,13 @@
</demo-block> </demo-block>
</template> </template>
<script> <script lang="ts">
import { reactive, toRefs } from 'vue'; import { reactive, toRefs } from 'vue';
import { useTranslate } from '@demo/use-translate'; import { useTranslate } from '@demo/use-translate';
import FieldTypeArea from './FieldTypeArea'; import FieldTypeArea from './FieldTypeArea.vue';
import FieldTypePicker from './FieldTypePicker'; import FieldTypePicker from './FieldTypePicker.vue';
import FieldTypeCalendar from './FieldTypeCalendar'; import FieldTypeCalendar from './FieldTypeCalendar.vue';
import FieldTypeDatetimePicker from './FieldTypeDatetimePicker'; import FieldTypeDatetimePicker from './FieldTypeDatetimePicker.vue';
const i18n = { const i18n = {
'zh-CN': { 'zh-CN': {
@ -133,7 +133,7 @@ export default {
switchChecked: false, switchChecked: false,
}); });
const onSubmit = (values) => { const onSubmit = (values: Record<string, string>) => {
console.log(values); console.log(values);
}; };

View File

@ -17,9 +17,10 @@
</van-popup> </van-popup>
</template> </template>
<script> <script lang="ts">
import { reactive, toRefs } from 'vue'; import { reactive, toRefs } from 'vue';
import { useTranslate } from '@demo/use-translate'; import { useTranslate } from '@demo/use-translate';
import { AreaColumnOption } from '../../area';
import AreaList from '../../area/demo/area'; import AreaList from '../../area/demo/area';
import AreaListEn from '../../area/demo/area-en'; import AreaListEn from '../../area/demo/area-en';
@ -44,7 +45,7 @@ export default {
showArea: false, showArea: false,
}); });
const onConfirm = (values) => { const onConfirm = (values: AreaColumnOption[]) => {
state.value = values state.value = values
.filter((item) => !!item) .filter((item) => !!item)
.map((item) => item.name) .map((item) => item.name)

View File

@ -16,7 +16,7 @@
/> />
</template> </template>
<script> <script lang="ts">
import { reactive, toRefs } from 'vue'; import { reactive, toRefs } from 'vue';
import { useTranslate } from '@demo/use-translate'; import { useTranslate } from '@demo/use-translate';
@ -39,9 +39,10 @@ export default {
showCalendar: false, showCalendar: false,
}); });
const formatDate = (date) => `${date.getMonth() + 1}/${date.getDate()}`; const formatDate = (date: Date) =>
`${date.getMonth() + 1}/${date.getDate()}`;
const onConfirm = (date) => { const onConfirm = (date: Date) => {
state.value = formatDate(date); state.value = formatDate(date);
state.showCalendar = false; state.showCalendar = false;
}; };

View File

@ -13,7 +13,7 @@
</van-popup> </van-popup>
</template> </template>
<script> <script lang="ts">
import { reactive, toRefs } from 'vue'; import { reactive, toRefs } from 'vue';
import { useTranslate } from '@demo/use-translate'; import { useTranslate } from '@demo/use-translate';
@ -36,10 +36,11 @@ export default {
showPicker: false, showPicker: false,
}); });
const onConfirm = (time) => { const onConfirm = (time: string) => {
state.value = time; state.value = time;
state.showPicker = false; state.showPicker = false;
}; };
const onCancel = () => { const onCancel = () => {
state.showPicker = false; state.showPicker = false;
}; };

View File

@ -17,7 +17,7 @@
</van-popup> </van-popup>
</template> </template>
<script> <script lang="ts">
import { reactive, toRefs } from 'vue'; import { reactive, toRefs } from 'vue';
import { useTranslate } from '@demo/use-translate'; import { useTranslate } from '@demo/use-translate';
@ -42,7 +42,7 @@ export default {
showPicker: false, showPicker: false,
}); });
const onConfirm = (value) => { const onConfirm = (value: string) => {
state.value = value; state.value = value;
state.showPicker = false; state.showPicker = false;
}; };

View File

@ -38,9 +38,10 @@
</demo-block> </demo-block>
</template> </template>
<script> <script lang="ts">
import { reactive, toRefs } from 'vue'; import { reactive, toRefs } from 'vue';
import { useTranslate } from '@demo/use-translate'; import { useTranslate } from '@demo/use-translate';
import { FieldValidateError } from '../../field/types';
import Toast from '../../toast'; import Toast from '../../toast';
const i18n = { const i18n = {
@ -49,7 +50,7 @@ const i18n = {
title: '校验规则', title: '校验规则',
submit: '提交', submit: '提交',
message: '请输入正确内容', message: '请输入正确内容',
invalid: (val) => `${val} 不合法,请重新输入`, invalid: (val: string) => `${val} 不合法,请重新输入`,
pattern: '正则校验', pattern: '正则校验',
validator: '函数校验', validator: '函数校验',
validating: '验证中...', validating: '验证中...',
@ -61,7 +62,7 @@ const i18n = {
title: 'Validate Rules', title: 'Validate Rules',
submit: 'Submit', submit: 'Submit',
message: 'Error message', message: 'Error message',
invalid: (val) => `${val} is invalid`, invalid: (val: string) => `${val} is invalid`,
pattern: 'Use pattern', pattern: 'Use pattern',
validator: 'Use validator', validator: 'Use validator',
validating: 'Validating...', validating: 'Validating...',
@ -80,11 +81,11 @@ export default {
value4: '', value4: '',
}); });
const validator = (val) => /1\d{10}/.test(val); const validator = (val: string) => /1\d{10}/.test(val);
const validatorMessage = (val) => t('invalid', val); const validatorMessage = (val: string) => t('invalid', val);
const asyncValidator = (val) => const asyncValidator = (val: string) =>
new Promise((resolve) => { new Promise((resolve) => {
Toast.loading(t('validating')); Toast.loading(t('validating'));
@ -94,11 +95,14 @@ export default {
}, 1000); }, 1000);
}); });
const onSubmit = (values) => { const onSubmit = (values: Record<string, string>) => {
console.log('submit', values); console.log('submit', values);
}; };
const onFailed = (errorInfo) => { const onFailed = (errorInfo: {
values: Record<string, string>;
errors: FieldValidateError[];
}) => {
console.log('failed', errorInfo); console.log('failed', errorInfo);
}; };

View File

@ -4,10 +4,10 @@
<field-type /> <field-type />
</template> </template>
<script> <script lang="ts">
import BasicUsage from './BasicUsage'; import BasicUsage from './BasicUsage.vue';
import ValidateRules from './ValidateRules'; import ValidateRules from './ValidateRules.vue';
import FieldType from './FieldType'; import FieldType from './FieldType.vue';
export default { export default {
components: { components: {

View File

@ -73,7 +73,7 @@
</demo-block> </demo-block>
</template> </template>
<script> <script lang="ts">
import { ref, computed, reactive, toRefs } from 'vue'; import { ref, computed, reactive, toRefs } from 'vue';
import { dateColumns, cascadeColumns, cascadeColumnsCustomKey } from './data'; import { dateColumns, cascadeColumns, cascadeColumnsCustomKey } from './data';
import { useTranslate } from '@demo/use-translate'; import { useTranslate } from '@demo/use-translate';
@ -92,7 +92,7 @@ const i18n = {
cascadeColumns: cascadeColumns['zh-CN'], cascadeColumns: cascadeColumns['zh-CN'],
multipleColumns: '多列选择', multipleColumns: '多列选择',
setColumnValues: '动态设置选项', setColumnValues: '动态设置选项',
customChildrenKey: '自定义Columns字段', customChildrenKey: '自定义 Columns 结构',
customChildrenColumns: cascadeColumnsCustomKey['zh-CN'], customChildrenColumns: cascadeColumnsCustomKey['zh-CN'],
textColumns: [ textColumns: [
'杭州', '杭州',
@ -113,7 +113,8 @@ const i18n = {
浙江: ['杭州', '宁波', '温州', '嘉兴', '湖州'], 浙江: ['杭州', '宁波', '温州', '嘉兴', '湖州'],
福建: ['福州', '厦门', '莆田', '三明', '泉州'], 福建: ['福州', '厦门', '莆田', '三明', '泉州'],
}, },
toastContent: (value, index) => `当前值:${value}, 当前索引:${index}`, toastContent: (value: string, index: number) =>
`当前值:${value}, 当前索引:${index}`,
}, },
'en-US': { 'en-US': {
city: 'City', city: 'City',
@ -139,7 +140,8 @@ const i18n = {
Group1: ['Delaware', 'Florida', 'Georqia', 'Indiana', 'Maine'], Group1: ['Delaware', 'Florida', 'Georqia', 'Indiana', 'Maine'],
Group2: ['Alabama', 'Kansas', 'Louisiana', 'Texas'], Group2: ['Alabama', 'Kansas', 'Louisiana', 'Texas'],
}, },
toastContent: (value, index) => `Value: ${value}, Index${index}`, toastContent: (value: string, index: number) =>
`Value: ${value}, Index${index}`,
}, },
}; };
@ -171,15 +173,15 @@ export default {
]; ];
}); });
const onChange1 = (value, index) => { const onChange1 = (value: string, index: number) => {
Toast(t('toastContent', value, index)); Toast(t('toastContent', value, index));
}; };
const onChange2 = (values) => { const onChange2 = (values: string[]) => {
picker.value.setColumnValues(1, t('column3')[values[0]]); picker.value.setColumnValues(1, t('column3')[values[0]]);
}; };
const onConfirm = (value, index) => { const onConfirm = (value: string, index: number) => {
Toast(t('toastContent', value, index)); Toast(t('toastContent', value, index));
}; };
@ -193,7 +195,7 @@ export default {
state.showPicker = true; state.showPicker = true;
}; };
const onConfirm2 = (value) => { const onConfirm2 = (value: string) => {
state.showPicker = false; state.showPicker = false;
state.fieldValue = value; state.fieldValue = value;
}; };

View File

@ -41,7 +41,7 @@
</van-tabs> </van-tabs>
</template> </template>
<script> <script lang="ts">
import { computed, onMounted, reactive, toRefs } from 'vue'; import { computed, onMounted, reactive, toRefs } from 'vue';
import { useTranslate } from '@demo/use-translate'; import { useTranslate } from '@demo/use-translate';
import Toast from '../../toast'; import Toast from '../../toast';
@ -78,7 +78,7 @@ export default {
return t('try'); return t('try');
}); });
const onRefresh = (showToast) => { const onRefresh = (showToast: boolean) => {
setTimeout(() => { setTimeout(() => {
if (showToast) { if (showToast) {
Toast(t('success')); Toast(t('success'));

View File

@ -44,7 +44,7 @@
</demo-block> </demo-block>
</template> </template>
<script> <script lang="ts">
import { toRefs, reactive } from 'vue'; import { toRefs, reactive } from 'vue';
import { useTranslate } from '@demo/use-translate'; import { useTranslate } from '@demo/use-translate';
import Toast from '../../toast'; import Toast from '../../toast';
@ -58,7 +58,7 @@ const i18n = {
customCount: '自定义数量', customCount: '自定义数量',
readonly: '只读状态', readonly: '只读状态',
changeEvent: '监听 change 事件', changeEvent: '监听 change 事件',
toastContent: (value) => `当前值:${value}`, toastContent: (value: number) => `当前值:${value}`,
}, },
'en-US': { 'en-US': {
halfStar: 'Half Star', halfStar: 'Half Star',
@ -68,7 +68,7 @@ const i18n = {
customCount: 'Custom Count', customCount: 'Custom Count',
readonly: 'Readonly', readonly: 'Readonly',
changeEvent: 'Change Event', changeEvent: 'Change Event',
toastContent: (value) => `current value${value}`, toastContent: (value: number) => `current value${value}`,
}, },
}; };
@ -85,7 +85,7 @@ export default {
value7: 2, value7: 2,
}); });
const onChange = (value) => Toast(t('toastContent', value)); const onChange = (value: number) => Toast(t('toastContent', value));
return { return {
...toRefs(state), ...toRefs(state),

View File

@ -51,7 +51,7 @@
</demo-block> </demo-block>
</template> </template>
<script> <script lang="ts">
import { reactive, toRefs } from 'vue'; import { reactive, toRefs } from 'vue';
import { useTranslate } from '@demo/use-translate'; import { useTranslate } from '@demo/use-translate';
import Toast from '../../toast'; import Toast from '../../toast';
@ -89,7 +89,7 @@ export default {
value6: '', value6: '',
}); });
const onSearch = (val) => Toast(val); const onSearch = (val: string) => Toast(val);
const onCancel = () => Toast(t('cancel')); const onCancel = () => Toast(t('cancel'));
return { return {

View File

@ -50,7 +50,7 @@
</demo-block> </demo-block>
</template> </template>
<script> <script lang="ts">
import { reactive, toRefs } from 'vue'; import { reactive, toRefs } from 'vue';
import { useTranslate } from '@demo/use-translate'; import { useTranslate } from '@demo/use-translate';
import Toast from '../../toast'; import Toast from '../../toast';
@ -95,7 +95,7 @@ export default {
value9: [20, 60], value9: [20, 60],
}); });
const onChange = (value) => Toast(t('text') + value); const onChange = (value: string) => Toast(t('text') + value);
return { return {
...toRefs(state), ...toRefs(state),

View File

@ -45,7 +45,7 @@
</van-cell> </van-cell>
</template> </template>
<script> <script lang="ts">
import { reactive, toRefs } from 'vue'; import { reactive, toRefs } from 'vue';
import { useTranslate } from '@demo/use-translate'; import { useTranslate } from '@demo/use-translate';
import Toast from '../../toast'; import Toast from '../../toast';

View File

@ -63,7 +63,7 @@
</demo-block> </demo-block>
</template> </template>
<script> <script lang="ts">
import { ref } from 'vue'; import { ref } from 'vue';
import { useTranslate } from '@demo/use-translate'; import { useTranslate } from '@demo/use-translate';
import Toast from '../../toast'; import Toast from '../../toast';
@ -98,8 +98,8 @@ export default {
'https://img01.yzcdn.cn/vant/apple-4.jpg', 'https://img01.yzcdn.cn/vant/apple-4.jpg',
]; ];
const onChange1 = (index) => Toast(t('message') + index); const onChange1 = (index: number) => Toast(t('message') + index);
const onChange2 = (index) => { const onChange2 = (index: number) => {
current.value = index; current.value = index;
}; };

View File

@ -36,7 +36,7 @@
</demo-block> </demo-block>
</template> </template>
<script> <script lang="ts">
import { reactive, toRefs } from 'vue'; import { reactive, toRefs } from 'vue';
import { useTranslate } from '@demo/use-translate'; import { useTranslate } from '@demo/use-translate';
import Dialog from '../../dialog'; import Dialog from '../../dialog';
@ -74,7 +74,7 @@ export default {
checked6: false, checked6: false,
}); });
const onUpdateValue = (checked) => { const onUpdateValue = (checked: boolean) => {
Dialog.confirm({ Dialog.confirm({
title: t('title'), title: t('title'),
message: t('message'), message: t('message'),