chore: make some improvement (#8255)

* chore: make some improvement

* chore: upd
This commit is contained in:
neverland 2021-03-03 17:13:45 +08:00 committed by GitHub
parent 2d8914c2c8
commit d606b32c64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 21 additions and 16 deletions

View File

@ -1,4 +1,4 @@
import { PropType, CSSProperties } from 'vue'; import { PropType, CSSProperties, ButtonHTMLAttributes } from 'vue';
// Utils // Utils
import { createNamespace } from '../utils'; import { createNamespace } from '../utils';
@ -49,7 +49,7 @@ export default createComponent({
default: 'normal', default: 'normal',
}, },
nativeType: { nativeType: {
type: String, type: String as PropType<ButtonHTMLAttributes['type']>,
default: 'button', default: 'button',
}, },
loadingSize: { loadingSize: {

View File

@ -10,14 +10,14 @@ const [createComponent, bem] = createNamespace('card');
export default createComponent({ export default createComponent({
props: { props: {
tag: String, tag: String,
num: [Number, String],
desc: String, desc: String,
thumb: String, thumb: String,
title: String, title: String,
price: [Number, String],
centered: Boolean, centered: Boolean,
lazyLoad: Boolean, lazyLoad: Boolean,
thumbLink: String, thumbLink: String,
num: [Number, String],
price: [Number, String],
originPrice: [Number, String], originPrice: [Number, String],
currency: { currency: {
type: String, type: String,

View File

@ -74,10 +74,10 @@ export default createComponent({
}; };
const renderValue = () => { const renderValue = () => {
const hasTitle = slots.title || isDef(props.title);
const hasValue = slots.default || isDef(props.value); const hasValue = slots.default || isDef(props.value);
if (hasValue) { if (hasValue) {
const hasTitle = slots.title || isDef(props.title);
return ( return (
<div class={[bem('value', { alone: !hasTitle }), props.valueClass]}> <div class={[bem('value', { alone: !hasTitle }), props.valueClass]}>
{slots.default ? slots.default() : <span>{props.value}</span>} {slots.default ? slots.default() : <span>{props.value}</span>}

View File

@ -1,4 +1,4 @@
import { watch, computed, PropType } from 'vue'; import { watch, computed, PropType, CSSProperties } from 'vue';
import { raf, cancelRaf } from '@vant/use'; import { raf, cancelRaf } from '@vant/use';
import { isObject, getSizeStyle, createNamespace } from '../utils'; import { isObject, getSizeStyle, createNamespace } from '../utils';
@ -62,7 +62,8 @@ export default createComponent({
watch( watch(
() => props.rate, () => props.rate,
(rate) => { (rate) => {
let rafId; let rafId: number | undefined;
const startTime = Date.now(); const startTime = Date.now();
const startRate = props.currentRate; const startRate = props.currentRate;
const endRate = format(rate); const endRate = format(rate);
@ -97,11 +98,11 @@ export default createComponent({
const renderHover = () => { const renderHover = () => {
const PERIMETER = 3140; const PERIMETER = 3140;
const { strokeWidth, currentRate, strokeLinecap } = props; const { strokeWidth, currentRate, strokeLinecap } = props;
let { color } = props;
const offset = (PERIMETER * currentRate) / 100; const offset = (PERIMETER * currentRate) / 100;
color = isObject(color) ? `url(#${id})` : color; const color = isObject(props.color) ? `url(#${id})` : props.color;
const style = {
stroke: `${color}`, const style: CSSProperties = {
stroke: color,
strokeWidth: `${+strokeWidth + 1}px`, strokeWidth: `${+strokeWidth + 1}px`,
strokeLinecap, strokeLinecap,
strokeDasharray: `${offset}px ${PERIMETER}px`, strokeDasharray: `${offset}px ${PERIMETER}px`,

View File

@ -10,7 +10,7 @@ exports[`should render demo and match snapshot 1`] = `
> >
</path> </path>
<path d="M 520 520 m 0, -500 a 500, 500 0 1, 1 0, 1000 a 500, 500 0 1, 1 0, -1000" <path d="M 520 520 m 0, -500 a 500, 500 0 1, 1 0, 1000 a 500, 500 0 1, 1 0, -1000"
style="stroke: undefined; stroke-width: 41px; stroke-dasharray: 2198px 3140px;" style="stroke-width: 41px; stroke-dasharray: 2198px 3140px;"
class="van-circle__hover" class="van-circle__hover"
> >
</path> </path>
@ -29,7 +29,7 @@ exports[`should render demo and match snapshot 1`] = `
> >
</path> </path>
<path d="M 530 530 m 0, -500 a 500, 500 0 1, 1 0, 1000 a 500, 500 0 1, 1 0, -1000" <path d="M 530 530 m 0, -500 a 500, 500 0 1, 1 0, 1000 a 500, 500 0 1, 1 0, -1000"
style="stroke: undefined; stroke-width: 61px; stroke-dasharray: 2198px 3140px;" style="stroke-width: 61px; stroke-dasharray: 2198px 3140px;"
class="van-circle__hover" class="van-circle__hover"
> >
</path> </path>

View File

@ -9,7 +9,7 @@ exports[`should change stroke linecap when using stroke-linecap prop 1`] = `
> >
</path> </path>
<path d="M 520 520 m 0, -500 a 500, 500 0 1, 1 0, 1000 a 500, 500 0 1, 1 0, -1000" <path d="M 520 520 m 0, -500 a 500, 500 0 1, 1 0, 1000 a 500, 500 0 1, 1 0, -1000"
style="stroke: undefined; stroke-width: 41px; stroke-linecap: square; stroke-dasharray: 0px 3140px;" style="stroke-width: 41px; stroke-linecap: square; stroke-dasharray: 0px 3140px;"
class="van-circle__hover" class="van-circle__hover"
> >
</path> </path>

View File

@ -48,9 +48,13 @@ export default createComponent({
const renderTag = () => { const renderTag = () => {
const { type, mark, plain, round, size, closeable } = props; const { type, mark, plain, round, size, closeable } = props;
const classes: Record<string, boolean> = { mark, plain, round }; const classes: Record<string, unknown> = {
mark,
plain,
round,
};
if (size) { if (size) {
classes[size] = !!size; classes[size] = size;
} }
const CloseIcon = closeable && ( const CloseIcon = closeable && (