Amour1688
4 years ago
7 changed files with 121 additions and 102 deletions
@ -1,70 +0,0 @@
|
||||
import { Circle as VCCircle } from '../vc-progress'; |
||||
import { validProgress } from './utils'; |
||||
|
||||
const statusColorMap = { |
||||
normal: '#108ee9', |
||||
exception: '#ff5500', |
||||
success: '#87d068', |
||||
}; |
||||
|
||||
function getPercentage({ percent, successPercent }) { |
||||
const ptg = validProgress(percent); |
||||
if (!successPercent) return ptg; |
||||
|
||||
const successPtg = validProgress(successPercent); |
||||
return [successPercent, validProgress(ptg - successPtg)]; |
||||
} |
||||
|
||||
function getStrokeColor({ progressStatus, successPercent, strokeColor }) { |
||||
const color = strokeColor || statusColorMap[progressStatus]; |
||||
if (!successPercent) return color; |
||||
return [statusColorMap.success, color]; |
||||
} |
||||
|
||||
const Circle = (_, { attrs, slots }) => { |
||||
const { |
||||
prefixCls, |
||||
width, |
||||
strokeWidth, |
||||
trailColor, |
||||
strokeLinecap, |
||||
gapPosition, |
||||
gapDegree, |
||||
type, |
||||
} = attrs; |
||||
const circleSize = width || 120; |
||||
const circleStyle = { |
||||
width: typeof circleSize === 'number' ? `${circleSize}px` : circleSize, |
||||
height: typeof circleSize === 'number' ? `${circleSize}px` : circleSize, |
||||
fontSize: `${circleSize * 0.15 + 6}px`, |
||||
}; |
||||
const circleWidth = strokeWidth || 6; |
||||
const gapPos = gapPosition || (type === 'dashboard' && 'bottom') || 'top'; |
||||
const gapDeg = gapDegree || (type === 'dashboard' && 75); |
||||
const strokeColor = getStrokeColor(attrs); |
||||
const isGradient = Object.prototype.toString.call(strokeColor) === '[object Object]'; |
||||
|
||||
const wrapperClassName = { |
||||
[`${prefixCls}-inner`]: true, |
||||
[`${prefixCls}-circle-gradient`]: isGradient, |
||||
}; |
||||
|
||||
return ( |
||||
<div class={wrapperClassName} style={circleStyle}> |
||||
<VCCircle |
||||
percent={getPercentage(attrs)} |
||||
strokeWidth={circleWidth} |
||||
trailWidth={circleWidth} |
||||
strokeColor={strokeColor} |
||||
strokeLinecap={strokeLinecap} |
||||
trailColor={trailColor} |
||||
prefixCls={prefixCls} |
||||
gapDegree={gapDeg} |
||||
gapPosition={gapPos} |
||||
/> |
||||
{slots?.default()} |
||||
</div> |
||||
); |
||||
}; |
||||
|
||||
export default Circle; |
@ -0,0 +1,85 @@
|
||||
import { defineComponent, ExtractPropTypes } from 'vue'; |
||||
import { Circle as VCCircle } from '../vc-progress'; |
||||
import PropTypes from '../_util/vue-types'; |
||||
import { validProgress } from './utils'; |
||||
import { ProgressProps } from './props'; |
||||
|
||||
const CircleProps = { |
||||
...ProgressProps, |
||||
progressStatus: PropTypes.string, |
||||
}; |
||||
|
||||
const statusColorMap: Record<string, string> = { |
||||
normal: '#108ee9', |
||||
exception: '#ff5500', |
||||
success: '#87d068', |
||||
}; |
||||
|
||||
export type ICircleProps = ExtractPropTypes<typeof CircleProps>; |
||||
|
||||
function getPercentage({ percent, successPercent }: ICircleProps) { |
||||
const ptg = validProgress(percent); |
||||
if (!successPercent) return ptg; |
||||
|
||||
const successPtg = validProgress(successPercent); |
||||
return [successPercent, validProgress(ptg - successPtg)]; |
||||
} |
||||
|
||||
function getStrokeColor({ progressStatus, successPercent, strokeColor }: ICircleProps) { |
||||
const color = strokeColor || statusColorMap[progressStatus]; |
||||
if (!successPercent) return color; |
||||
return [statusColorMap.success, color]; |
||||
} |
||||
|
||||
const Circle = defineComponent({ |
||||
props: CircleProps, |
||||
setup(props, { slots }) { |
||||
return () => { |
||||
const { |
||||
prefixCls, |
||||
width, |
||||
strokeWidth, |
||||
trailColor, |
||||
strokeLinecap, |
||||
gapPosition, |
||||
gapDegree, |
||||
type, |
||||
} = props; |
||||
const circleSize = width || 120; |
||||
const circleStyle = { |
||||
width: typeof circleSize === 'number' ? `${circleSize}px` : circleSize, |
||||
height: typeof circleSize === 'number' ? `${circleSize}px` : circleSize, |
||||
fontSize: `${circleSize * 0.15 + 6}px`, |
||||
}; |
||||
const circleWidth = strokeWidth || 6; |
||||
const gapPos = gapPosition || (type === 'dashboard' && 'bottom') || 'top'; |
||||
const gapDeg = gapDegree || (type === 'dashboard' && 75); |
||||
const strokeColor = getStrokeColor(props); |
||||
const isGradient = Object.prototype.toString.call(strokeColor) === '[object Object]'; |
||||
|
||||
const wrapperClassName = { |
||||
[`${prefixCls}-inner`]: true, |
||||
[`${prefixCls}-circle-gradient`]: isGradient, |
||||
}; |
||||
|
||||
return ( |
||||
<div class={wrapperClassName} style={circleStyle}> |
||||
<VCCircle |
||||
percent={getPercentage(props)} |
||||
strokeWidth={circleWidth} |
||||
trailWidth={circleWidth} |
||||
strokeColor={strokeColor} |
||||
strokeLinecap={strokeLinecap} |
||||
trailColor={trailColor} |
||||
prefixCls={prefixCls} |
||||
gapDegree={gapDeg} |
||||
gapPosition={gapPos} |
||||
/> |
||||
{slots?.default()} |
||||
</div> |
||||
); |
||||
}; |
||||
}, |
||||
}); |
||||
|
||||
export default Circle; |
@ -1,9 +1,10 @@
|
||||
import { App } from 'vue'; |
||||
import Progress from './progress'; |
||||
|
||||
export { ProgressProps } from './progress'; |
||||
export { ProgressProps } from './props'; |
||||
|
||||
/* istanbul ignore next */ |
||||
Progress.install = function(app) { |
||||
Progress.install = function(app: App) { |
||||
app.component(Progress.name, Progress); |
||||
return app; |
||||
}; |
@ -0,0 +1,24 @@
|
||||
import PropTypes from '../_util/vue-types'; |
||||
import { tuple } from '../_util/type'; |
||||
|
||||
export const ProgressStatuses = tuple('normal', 'exception', 'active', 'success'); |
||||
export const ProgressType = PropTypes.oneOf(tuple('line', 'circle', 'dashboard')); |
||||
export const ProgressSize = PropTypes.oneOf(tuple('default', 'small')); |
||||
|
||||
export const ProgressProps = { |
||||
prefixCls: PropTypes.string, |
||||
type: ProgressType, |
||||
percent: PropTypes.number, |
||||
successPercent: PropTypes.number, |
||||
format: PropTypes.func, |
||||
status: PropTypes.oneOf(ProgressStatuses), |
||||
showInfo: PropTypes.looseBool, |
||||
strokeWidth: PropTypes.number, |
||||
strokeLinecap: PropTypes.oneOf(['butt', 'round', 'square']), |
||||
strokeColor: PropTypes.oneOfType([PropTypes.string, PropTypes.object]), |
||||
trailColor: PropTypes.string, |
||||
width: PropTypes.number, |
||||
gapDegree: PropTypes.number, |
||||
gapPosition: PropTypes.oneOf(tuple('top', 'bottom', 'left', 'right')), |
||||
size: ProgressSize, |
||||
}; |
Loading…
Reference in new issue