2018-06-30 14:52:34 +08:00
|
|
|
<template>
|
|
|
|
<div class="md-activity-indicator-rolling">
|
2018-12-10 14:48:41 +08:00
|
|
|
<div class="rolling-container">
|
|
|
|
<svg
|
|
|
|
:viewBox="`0 0 ${viewBoxSize} ${viewBoxSize}`"
|
2018-12-10 17:52:42 +08:00
|
|
|
:style="{width: `${size}px`, height: `${size}px`, transform: `rotateZ(${rotate}deg)`}"
|
2018-12-10 14:48:41 +08:00
|
|
|
preserveAspectRatio="xMidYMid"
|
|
|
|
class="md-activity-indicator-svg rolling"
|
2018-06-30 14:52:34 +08:00
|
|
|
>
|
|
|
|
<circle
|
2018-12-10 14:48:41 +08:00
|
|
|
fill="none"
|
|
|
|
:stroke="borderColor"
|
|
|
|
:stroke-width="strokeWidth"
|
2018-06-30 14:52:34 +08:00
|
|
|
:cx="viewBoxSize/2"
|
|
|
|
:cy="viewBoxSize/2"
|
|
|
|
:r="radius"
|
2018-12-10 14:48:41 +08:00
|
|
|
/>
|
|
|
|
<g
|
|
|
|
v-if="!$slots.circle"
|
|
|
|
class="circle"
|
2018-06-30 14:52:34 +08:00
|
|
|
>
|
2018-12-10 14:48:41 +08:00
|
|
|
<circle
|
2019-04-02 18:14:04 +08:00
|
|
|
v-if="isAutoAnimation || process > 0"
|
2018-12-10 14:48:41 +08:00
|
|
|
class="stroke"
|
|
|
|
:cx="viewBoxSize/2"
|
|
|
|
:cy="viewBoxSize/2"
|
|
|
|
:fill="fill"
|
|
|
|
:stroke="color"
|
|
|
|
:stroke-width="strokeWidth"
|
|
|
|
:stroke-dasharray="isAutoAnimation ? `${110 * circlePerimeter / 125}` : strokeDasharray"
|
|
|
|
:stroke-linecap="linecap"
|
|
|
|
:r="radius"
|
|
|
|
>
|
|
|
|
<animate
|
|
|
|
v-if="isAutoAnimation"
|
|
|
|
attributeName="stroke-dashoffset"
|
|
|
|
:values="`${360 * circlePerimeter / 125};${140 * circlePerimeter / 125}`"
|
|
|
|
dur="2.2s"
|
|
|
|
keyTimes="0;1"
|
|
|
|
calcMode="spline"
|
|
|
|
fill="freeze"
|
|
|
|
keySplines="0.41,0.314,0.8,0.54"
|
|
|
|
repeatCount="indefinite"
|
|
|
|
begin="0"
|
|
|
|
/>
|
|
|
|
<animateTransform
|
|
|
|
v-if="isAutoAnimation"
|
|
|
|
:dur="`${duration}s`"
|
|
|
|
:values="`0 ${viewBoxSize/2} ${viewBoxSize/2};360 ${viewBoxSize/2} ${viewBoxSize/2}`"
|
|
|
|
attributeName="transform"
|
|
|
|
type="rotate"
|
|
|
|
calcMode="linear"
|
|
|
|
keyTimes="0;1"
|
|
|
|
begin="0"
|
|
|
|
repeatCount="indefinite"
|
|
|
|
></animateTransform>
|
|
|
|
</circle>
|
|
|
|
</g>
|
|
|
|
<slot name="circle" v-else></slot>
|
|
|
|
<slot name="defs"></slot>
|
|
|
|
</svg>
|
|
|
|
<div class="content"><slot></slot></div>
|
|
|
|
</div>
|
2018-06-30 14:52:34 +08:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
export default {
|
|
|
|
name: 'md-activity-indicator-rolling',
|
|
|
|
|
|
|
|
props: {
|
|
|
|
size: {
|
|
|
|
type: Number,
|
|
|
|
default: 70,
|
|
|
|
},
|
2018-09-29 15:31:05 +08:00
|
|
|
width: {
|
|
|
|
type: Number,
|
|
|
|
},
|
2018-06-30 14:52:34 +08:00
|
|
|
color: {
|
|
|
|
type: String,
|
2018-08-22 14:55:06 +08:00
|
|
|
default: '#2F86F6',
|
2018-06-30 14:52:34 +08:00
|
|
|
},
|
2018-09-28 15:19:20 +08:00
|
|
|
borderColor: {
|
|
|
|
type: String,
|
|
|
|
default: 'rgba(0, 0, 0, .1)',
|
|
|
|
},
|
2018-06-30 14:52:34 +08:00
|
|
|
fill: {
|
|
|
|
type: String,
|
|
|
|
default: 'transparent',
|
|
|
|
},
|
2018-12-10 14:48:41 +08:00
|
|
|
linecap: {
|
|
|
|
// butt | round | square | inherit
|
|
|
|
type: String,
|
|
|
|
default: 'round',
|
|
|
|
},
|
2018-12-10 17:52:42 +08:00
|
|
|
rotate: {
|
|
|
|
type: Number,
|
|
|
|
default: 0,
|
|
|
|
},
|
2018-06-30 19:34:33 +08:00
|
|
|
process: {
|
|
|
|
// process control 0-1
|
|
|
|
type: Number,
|
|
|
|
},
|
2018-06-30 14:52:34 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
|
|
|
id() {
|
|
|
|
return `${this.$options.name}-keyframes-${this.size}`
|
|
|
|
},
|
|
|
|
strokeWidth() {
|
2018-09-29 15:31:05 +08:00
|
|
|
return this.width || this.size / 12
|
|
|
|
},
|
|
|
|
strokeDasharray() {
|
|
|
|
return `${this.process * this.circlePerimeter} ${(1 - this.process) * this.circlePerimeter}`
|
2018-06-30 14:52:34 +08:00
|
|
|
},
|
|
|
|
radius() {
|
|
|
|
return this.size / 2
|
|
|
|
},
|
|
|
|
viewBoxSize() {
|
|
|
|
return this.size + 2 * this.strokeWidth
|
|
|
|
},
|
|
|
|
circlePerimeter() {
|
|
|
|
return this.size * 3.1415
|
|
|
|
},
|
|
|
|
duration() {
|
|
|
|
return 2
|
|
|
|
},
|
2018-09-29 15:31:05 +08:00
|
|
|
isAutoAnimation() {
|
|
|
|
return this.process === undefined
|
2018-06-30 14:52:34 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="stylus">
|
|
|
|
.md-activity-indicator-rolling
|
|
|
|
clearfix()
|
2018-12-10 14:48:41 +08:00
|
|
|
.rolling-container
|
|
|
|
position relative
|
2018-12-26 11:29:55 +08:00
|
|
|
float left
|
2018-06-30 14:52:34 +08:00
|
|
|
.rolling
|
|
|
|
float left
|
|
|
|
circle.stroke
|
|
|
|
will-change auto
|
2018-12-10 14:48:41 +08:00
|
|
|
.content
|
|
|
|
position absolute
|
|
|
|
absolute-pos()
|
|
|
|
display flex
|
|
|
|
justify-content center
|
|
|
|
align-items center
|
2018-06-30 14:52:34 +08:00
|
|
|
</style>
|