2020-10-12 05:27:16 +00:00
|
|
|
import { defineComponent } from 'vue';
|
2019-01-12 03:33:27 +00:00
|
|
|
import { initDefaultProps } from '../../_util/props-util';
|
|
|
|
import enhancer from './enhancer';
|
|
|
|
import { propTypes, defaultProps } from './types';
|
2018-04-03 03:00:05 +00:00
|
|
|
|
2020-10-12 05:27:16 +00:00
|
|
|
const Line = defineComponent({
|
2020-06-26 02:08:47 +00:00
|
|
|
name: 'Line',
|
2018-04-03 03:00:05 +00:00
|
|
|
props: initDefaultProps(propTypes, defaultProps),
|
2019-03-10 14:10:58 +00:00
|
|
|
created() {
|
2019-02-19 14:35:03 +00:00
|
|
|
this.paths = {};
|
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
render() {
|
2018-04-03 03:00:05 +00:00
|
|
|
const {
|
|
|
|
percent,
|
|
|
|
prefixCls,
|
|
|
|
strokeColor,
|
|
|
|
strokeLinecap,
|
|
|
|
strokeWidth,
|
|
|
|
trailColor,
|
|
|
|
trailWidth,
|
2020-03-07 11:45:13 +00:00
|
|
|
transition,
|
2018-04-03 03:00:05 +00:00
|
|
|
...restProps
|
2019-01-12 03:33:27 +00:00
|
|
|
} = this.$props;
|
2018-04-03 03:00:05 +00:00
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
delete restProps.gapPosition;
|
2018-04-03 03:00:05 +00:00
|
|
|
|
2019-02-19 14:35:03 +00:00
|
|
|
const percentList = Array.isArray(percent) ? percent : [percent];
|
|
|
|
const strokeColorList = Array.isArray(strokeColor) ? strokeColor : [strokeColor];
|
2018-04-03 03:00:05 +00:00
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
const center = strokeWidth / 2;
|
|
|
|
const right = 100 - strokeWidth / 2;
|
|
|
|
const pathString = `M ${strokeLinecap === 'round' ? center : 0},${center}
|
|
|
|
L ${strokeLinecap === 'round' ? right : 100},${center}`;
|
|
|
|
const viewBoxString = `0 0 100 ${strokeWidth}`;
|
2018-12-10 14:25:16 +00:00
|
|
|
|
2019-02-19 14:35:03 +00:00
|
|
|
let stackPtg = 0;
|
|
|
|
|
2018-04-03 03:00:05 +00:00
|
|
|
const pathFirst = {
|
2020-06-26 02:08:47 +00:00
|
|
|
d: pathString,
|
|
|
|
'stroke-linecap': strokeLinecap,
|
|
|
|
stroke: trailColor,
|
|
|
|
'stroke-width': trailWidth || strokeWidth,
|
|
|
|
'fill-opacity': '0',
|
2018-04-03 03:00:05 +00:00
|
|
|
class: `${prefixCls}-line-trail`,
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2018-04-03 03:00:05 +00:00
|
|
|
return (
|
|
|
|
<svg
|
|
|
|
class={`${prefixCls}-line`}
|
|
|
|
viewBox={viewBoxString}
|
2019-01-12 03:33:27 +00:00
|
|
|
preserveAspectRatio="none"
|
2018-04-03 03:00:05 +00:00
|
|
|
{...restProps}
|
|
|
|
>
|
2019-01-12 03:33:27 +00:00
|
|
|
<path {...pathFirst} />
|
2019-02-19 14:35:03 +00:00
|
|
|
{percentList.map((ptg, index) => {
|
|
|
|
const pathStyle = {
|
|
|
|
strokeDasharray: `${ptg}px, 100px`,
|
|
|
|
strokeDashoffset: `-${stackPtg}px`,
|
|
|
|
transition:
|
2020-03-07 11:45:13 +00:00
|
|
|
transition ||
|
2019-02-19 14:35:03 +00:00
|
|
|
'stroke-dashoffset 0.3s ease 0s, stroke-dasharray .3s ease 0s, stroke 0.3s linear',
|
|
|
|
};
|
|
|
|
const color = strokeColorList[index] || strokeColorList[strokeColorList.length - 1];
|
|
|
|
|
|
|
|
stackPtg += ptg;
|
|
|
|
|
|
|
|
const pathProps = {
|
2019-03-10 14:10:58 +00:00
|
|
|
key: index,
|
2020-06-26 02:08:47 +00:00
|
|
|
d: pathString,
|
|
|
|
'stroke-linecap': strokeLinecap,
|
|
|
|
stroke: color,
|
|
|
|
'stroke-width': strokeWidth,
|
|
|
|
'fill-opacity': '0',
|
2019-02-19 14:35:03 +00:00
|
|
|
class: `${prefixCls}-line-path`,
|
|
|
|
style: pathStyle,
|
|
|
|
};
|
|
|
|
|
2020-06-25 14:21:23 +00:00
|
|
|
return <path ref={c => (this.paths[index] = c)} {...pathProps} />;
|
2019-02-19 14:35:03 +00:00
|
|
|
})}
|
2018-04-03 03:00:05 +00:00
|
|
|
</svg>
|
2019-01-12 03:33:27 +00:00
|
|
|
);
|
2018-04-03 03:00:05 +00:00
|
|
|
},
|
2020-10-12 05:27:16 +00:00
|
|
|
});
|
2018-04-03 03:00:05 +00:00
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
export default enhancer(Line);
|