mirror of
				https://github.com/pure-admin/vue-pure-admin.git
				synced 2025-11-03 13:44:47 +08:00 
			
		
		
		
	feat: add countTo example
This commit is contained in:
		
							parent
							
								
									90b2ac8599
								
							
						
					
					
						commit
						65aac55053
					
				@ -1,5 +1,5 @@
 | 
				
			|||||||
<template>
 | 
					<template>
 | 
				
			||||||
  <span>{{ displayValue }}</span>
 | 
					  <span :style="{color: color}">{{ displayValue }}</span>
 | 
				
			||||||
</template>
 | 
					</template>
 | 
				
			||||||
<script lang="ts">
 | 
					<script lang="ts">
 | 
				
			||||||
import {
 | 
					import {
 | 
				
			||||||
@ -28,6 +28,7 @@ export default defineComponent({
 | 
				
			|||||||
      timestamp: number | null;
 | 
					      timestamp: number | null;
 | 
				
			||||||
      rAF: any;
 | 
					      rAF: any;
 | 
				
			||||||
      remaining: number | null;
 | 
					      remaining: number | null;
 | 
				
			||||||
 | 
					      color: any;
 | 
				
			||||||
    }>({
 | 
					    }>({
 | 
				
			||||||
      localStartVal: props.startVal,
 | 
					      localStartVal: props.startVal,
 | 
				
			||||||
      displayValue: formatNumber(props.startVal),
 | 
					      displayValue: formatNumber(props.startVal),
 | 
				
			||||||
@ -37,7 +38,8 @@ export default defineComponent({
 | 
				
			|||||||
      startTime: null,
 | 
					      startTime: null,
 | 
				
			||||||
      timestamp: null,
 | 
					      timestamp: null,
 | 
				
			||||||
      remaining: null,
 | 
					      remaining: null,
 | 
				
			||||||
      rAF: null
 | 
					      rAF: null,
 | 
				
			||||||
 | 
					      color: null
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    onMounted(() => {
 | 
					    onMounted(() => {
 | 
				
			||||||
@ -58,11 +60,12 @@ export default defineComponent({
 | 
				
			|||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    function start() {
 | 
					    function start() {
 | 
				
			||||||
      const { startVal, duration } = props;
 | 
					      const { startVal, duration, color } = props;
 | 
				
			||||||
      state.localStartVal = startVal;
 | 
					      state.localStartVal = startVal;
 | 
				
			||||||
      state.startTime = null;
 | 
					      state.startTime = null;
 | 
				
			||||||
      state.localDuration = duration;
 | 
					      state.localDuration = duration;
 | 
				
			||||||
      state.paused = false;
 | 
					      state.paused = false;
 | 
				
			||||||
 | 
					      state.color = color;
 | 
				
			||||||
      state.rAF = requestAnimationFrame(count);
 | 
					      state.rAF = requestAnimationFrame(count);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -1,3 +1,4 @@
 | 
				
			|||||||
 | 
					import { strict } from 'assert'
 | 
				
			||||||
import { PropType } from 'vue'
 | 
					import { PropType } from 'vue'
 | 
				
			||||||
import { propTypes } from '/@/utils/propTypes'
 | 
					import { propTypes } from '/@/utils/propTypes'
 | 
				
			||||||
export const countToProps = {
 | 
					export const countToProps = {
 | 
				
			||||||
@ -13,6 +14,10 @@ export const countToProps = {
 | 
				
			|||||||
      return value >= 0
 | 
					      return value >= 0
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
 | 
					  color: {
 | 
				
			||||||
 | 
					    type: String as PropType<string>,
 | 
				
			||||||
 | 
					    require: false
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
  decimal: propTypes.string.def('.'),
 | 
					  decimal: propTypes.string.def('.'),
 | 
				
			||||||
  separator: propTypes.string.def(','),
 | 
					  separator: propTypes.string.def(','),
 | 
				
			||||||
  prefix: propTypes.string.def(''),
 | 
					  prefix: propTypes.string.def(''),
 | 
				
			||||||
 | 
				
			|||||||
@ -15,5 +15,6 @@
 | 
				
			|||||||
  "draggable": "拖拽组件",
 | 
					  "draggable": "拖拽组件",
 | 
				
			||||||
  "split-pane": "切割面板",
 | 
					  "split-pane": "切割面板",
 | 
				
			||||||
  "button": "按钮组件",
 | 
					  "button": "按钮组件",
 | 
				
			||||||
  "cropping": "图片裁剪"
 | 
					  "cropping": "图片裁剪",
 | 
				
			||||||
 | 
					  "countTo": "数字动画"
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -15,5 +15,6 @@
 | 
				
			|||||||
  "draggable": "Draggable Components",
 | 
					  "draggable": "Draggable Components",
 | 
				
			||||||
  "split-pane": "Split Pane",
 | 
					  "split-pane": "Split Pane",
 | 
				
			||||||
  "button": "Button Components",
 | 
					  "button": "Button Components",
 | 
				
			||||||
  "cropping": "Picture Cropping"
 | 
					  "cropping": "Picture Cropping",
 | 
				
			||||||
 | 
					  "countTo": "Digital Animation"
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -85,6 +85,15 @@ const routes: Array<RouteRecordRaw> = [
 | 
				
			|||||||
          showLink: false,
 | 
					          showLink: false,
 | 
				
			||||||
          savedPosition: true
 | 
					          savedPosition: true
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        path: '/components/countTo',
 | 
				
			||||||
 | 
					        component: () => import(/* webpackChunkName: "components" */ '../views/components/countTo/index.vue'),
 | 
				
			||||||
 | 
					        meta: {
 | 
				
			||||||
 | 
					          title: 'countTo',
 | 
				
			||||||
 | 
					          showLink: false,
 | 
				
			||||||
 | 
					          savedPosition: true
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    ],
 | 
					    ],
 | 
				
			||||||
    meta: {
 | 
					    meta: {
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										34
									
								
								src/views/components/countTo/index.vue
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								src/views/components/countTo/index.vue
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,34 @@
 | 
				
			|||||||
 | 
					<template>
 | 
				
			||||||
 | 
					  <div style="margin:10px">
 | 
				
			||||||
 | 
					    <el-row :gutter="10">
 | 
				
			||||||
 | 
					      <el-col :span="10">
 | 
				
			||||||
 | 
					        <el-card shadow="always">
 | 
				
			||||||
 | 
					          <CountTo prefix="$" :color="'#409EFF'" :startVal="1" :endVal="1000" />
 | 
				
			||||||
 | 
					        </el-card>
 | 
				
			||||||
 | 
					      </el-col>
 | 
				
			||||||
 | 
					      <el-col :span="10">
 | 
				
			||||||
 | 
					        <el-card shadow="always">
 | 
				
			||||||
 | 
					          <CountTo prefix="$" :color="'green'" :startVal="1" :endVal="1500" />
 | 
				
			||||||
 | 
					        </el-card>
 | 
				
			||||||
 | 
					      </el-col>
 | 
				
			||||||
 | 
					    </el-row>
 | 
				
			||||||
 | 
					  </div>
 | 
				
			||||||
 | 
					</template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<script lang='ts'>
 | 
				
			||||||
 | 
					import CountTo from "../../../components/countTo/src/index.vue";
 | 
				
			||||||
 | 
					export default {
 | 
				
			||||||
 | 
					  components: {
 | 
				
			||||||
 | 
					    CountTo
 | 
				
			||||||
 | 
					  },
 | 
				
			||||||
 | 
					  setup() {
 | 
				
			||||||
 | 
					    return {};
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					</script>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<style lang="scss" scoped>
 | 
				
			||||||
 | 
					:deep(.el-card) {
 | 
				
			||||||
 | 
					  text-align: center;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					</style>
 | 
				
			||||||
@ -23,13 +23,11 @@
 | 
				
			|||||||
        </template>
 | 
					        </template>
 | 
				
			||||||
      </el-skeleton>
 | 
					      </el-skeleton>
 | 
				
			||||||
    </el-card>
 | 
					    </el-card>
 | 
				
			||||||
    <!-- <CountTo prefix="$" :startVal="1" :endVal="200" /> -->
 | 
					 | 
				
			||||||
  </div>
 | 
					  </div>
 | 
				
			||||||
</template>
 | 
					</template>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<script lang='ts'>
 | 
					<script lang='ts'>
 | 
				
			||||||
import flop from "../components/flop/index.vue";
 | 
					import flop from "../components/flop/index.vue";
 | 
				
			||||||
import CountTo from "../components/countTo/src/index.vue";
 | 
					 | 
				
			||||||
import { ref, computed, onMounted, inject, nextTick } from "vue";
 | 
					import { ref, computed, onMounted, inject, nextTick } from "vue";
 | 
				
			||||||
import { deviceDetection } from "../utils/deviceDetection";
 | 
					import { deviceDetection } from "../utils/deviceDetection";
 | 
				
			||||||
import { echartsJson } from "../api/mock";
 | 
					import { echartsJson } from "../api/mock";
 | 
				
			||||||
@ -39,8 +37,7 @@ let brokenLine: any = null; //折线图实例
 | 
				
			|||||||
export default {
 | 
					export default {
 | 
				
			||||||
  name: "welcome",
 | 
					  name: "welcome",
 | 
				
			||||||
  components: {
 | 
					  components: {
 | 
				
			||||||
    flop,
 | 
					    flop
 | 
				
			||||||
    CountTo,
 | 
					 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  setup() {
 | 
					  setup() {
 | 
				
			||||||
    let mobile = ref(deviceDetection());
 | 
					    let mobile = ref(deviceDetection());
 | 
				
			||||||
@ -52,7 +49,7 @@ export default {
 | 
				
			|||||||
      loading.value = !loading.value;
 | 
					      loading.value = !loading.value;
 | 
				
			||||||
      nextTick(() => {
 | 
					      nextTick(() => {
 | 
				
			||||||
        initbrokenLine();
 | 
					        initbrokenLine();
 | 
				
			||||||
      })
 | 
					      });
 | 
				
			||||||
    }, 2000);
 | 
					    }, 2000);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let greetings = computed(() => {
 | 
					    let greetings = computed(() => {
 | 
				
			||||||
@ -74,39 +71,39 @@ export default {
 | 
				
			|||||||
        brokenLine.setOption({
 | 
					        brokenLine.setOption({
 | 
				
			||||||
          title: {
 | 
					          title: {
 | 
				
			||||||
            text: "上海 空气质量指数",
 | 
					            text: "上海 空气质量指数",
 | 
				
			||||||
            left: "1%",
 | 
					            left: "1%"
 | 
				
			||||||
          },
 | 
					          },
 | 
				
			||||||
          tooltip: {
 | 
					          tooltip: {
 | 
				
			||||||
            trigger: "axis",
 | 
					            trigger: "axis"
 | 
				
			||||||
          },
 | 
					          },
 | 
				
			||||||
          grid: {
 | 
					          grid: {
 | 
				
			||||||
            left: "5%",
 | 
					            left: "5%",
 | 
				
			||||||
            right: "15%",
 | 
					            right: "15%",
 | 
				
			||||||
            bottom: "10%",
 | 
					            bottom: "10%"
 | 
				
			||||||
          },
 | 
					          },
 | 
				
			||||||
          xAxis: {
 | 
					          xAxis: {
 | 
				
			||||||
            data: info.map(function(item) {
 | 
					            data: info.map(function(item) {
 | 
				
			||||||
              return item[0];
 | 
					              return item[0];
 | 
				
			||||||
            }),
 | 
					            })
 | 
				
			||||||
          },
 | 
					          },
 | 
				
			||||||
          yAxis: {},
 | 
					          yAxis: {},
 | 
				
			||||||
          toolbox: {
 | 
					          toolbox: {
 | 
				
			||||||
            right: 10,
 | 
					            right: 10,
 | 
				
			||||||
            feature: {
 | 
					            feature: {
 | 
				
			||||||
              dataZoom: {
 | 
					              dataZoom: {
 | 
				
			||||||
                yAxisIndex: "none",
 | 
					                yAxisIndex: "none"
 | 
				
			||||||
              },
 | 
					              },
 | 
				
			||||||
              restore: {},
 | 
					              restore: {},
 | 
				
			||||||
              saveAsImage: {},
 | 
					              saveAsImage: {}
 | 
				
			||||||
            },
 | 
					            }
 | 
				
			||||||
          },
 | 
					          },
 | 
				
			||||||
          dataZoom: [
 | 
					          dataZoom: [
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
              startValue: "2014-06-01",
 | 
					              startValue: "2014-06-01"
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
              type: "inside",
 | 
					              type: "inside"
 | 
				
			||||||
            },
 | 
					            }
 | 
				
			||||||
          ],
 | 
					          ],
 | 
				
			||||||
          visualMap: {
 | 
					          visualMap: {
 | 
				
			||||||
            top: 50,
 | 
					            top: 50,
 | 
				
			||||||
@ -115,36 +112,36 @@ export default {
 | 
				
			|||||||
              {
 | 
					              {
 | 
				
			||||||
                gt: 0,
 | 
					                gt: 0,
 | 
				
			||||||
                lte: 50,
 | 
					                lte: 50,
 | 
				
			||||||
                color: "#93CE07",
 | 
					                color: "#93CE07"
 | 
				
			||||||
              },
 | 
					              },
 | 
				
			||||||
              {
 | 
					              {
 | 
				
			||||||
                gt: 50,
 | 
					                gt: 50,
 | 
				
			||||||
                lte: 100,
 | 
					                lte: 100,
 | 
				
			||||||
                color: "#FBDB0F",
 | 
					                color: "#FBDB0F"
 | 
				
			||||||
              },
 | 
					              },
 | 
				
			||||||
              {
 | 
					              {
 | 
				
			||||||
                gt: 100,
 | 
					                gt: 100,
 | 
				
			||||||
                lte: 150,
 | 
					                lte: 150,
 | 
				
			||||||
                color: "#FC7D02",
 | 
					                color: "#FC7D02"
 | 
				
			||||||
              },
 | 
					              },
 | 
				
			||||||
              {
 | 
					              {
 | 
				
			||||||
                gt: 150,
 | 
					                gt: 150,
 | 
				
			||||||
                lte: 200,
 | 
					                lte: 200,
 | 
				
			||||||
                color: "#FD0100",
 | 
					                color: "#FD0100"
 | 
				
			||||||
              },
 | 
					              },
 | 
				
			||||||
              {
 | 
					              {
 | 
				
			||||||
                gt: 200,
 | 
					                gt: 200,
 | 
				
			||||||
                lte: 300,
 | 
					                lte: 300,
 | 
				
			||||||
                color: "#AA069F",
 | 
					                color: "#AA069F"
 | 
				
			||||||
              },
 | 
					              },
 | 
				
			||||||
              {
 | 
					              {
 | 
				
			||||||
                gt: 300,
 | 
					                gt: 300,
 | 
				
			||||||
                color: "#AC3B2A",
 | 
					                color: "#AC3B2A"
 | 
				
			||||||
              },
 | 
					              }
 | 
				
			||||||
            ],
 | 
					            ],
 | 
				
			||||||
            outOfRange: {
 | 
					            outOfRange: {
 | 
				
			||||||
              color: "#999",
 | 
					              color: "#999"
 | 
				
			||||||
            },
 | 
					            }
 | 
				
			||||||
          },
 | 
					          },
 | 
				
			||||||
          series: {
 | 
					          series: {
 | 
				
			||||||
            name: "上海 空气质量指数",
 | 
					            name: "上海 空气质量指数",
 | 
				
			||||||
@ -155,34 +152,34 @@ export default {
 | 
				
			|||||||
            markLine: {
 | 
					            markLine: {
 | 
				
			||||||
              silent: true,
 | 
					              silent: true,
 | 
				
			||||||
              lineStyle: {
 | 
					              lineStyle: {
 | 
				
			||||||
                color: "#333",
 | 
					                color: "#333"
 | 
				
			||||||
              },
 | 
					              },
 | 
				
			||||||
              data: [
 | 
					              data: [
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                  yAxis: 50,
 | 
					                  yAxis: 50
 | 
				
			||||||
                },
 | 
					                },
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                  yAxis: 100,
 | 
					                  yAxis: 100
 | 
				
			||||||
                },
 | 
					                },
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                  yAxis: 150,
 | 
					                  yAxis: 150
 | 
				
			||||||
                },
 | 
					                },
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                  yAxis: 200,
 | 
					                  yAxis: 200
 | 
				
			||||||
                },
 | 
					                },
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                  yAxis: 300,
 | 
					                  yAxis: 300
 | 
				
			||||||
                },
 | 
					                }
 | 
				
			||||||
              ],
 | 
					              ]
 | 
				
			||||||
            },
 | 
					            }
 | 
				
			||||||
          },
 | 
					          }
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
      });
 | 
					      });
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const openDepot = (): void => {
 | 
					    const openDepot = (): void => {
 | 
				
			||||||
      window.open('https://github.com/xiaoxian521/vue-pure-admin')
 | 
					      window.open("https://github.com/xiaoxian521/vue-pure-admin");
 | 
				
			||||||
    }
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    onMounted(() => {
 | 
					    onMounted(() => {
 | 
				
			||||||
      useEventListener("resize", () => {
 | 
					      useEventListener("resize", () => {
 | 
				
			||||||
@ -197,7 +194,7 @@ export default {
 | 
				
			|||||||
      loading,
 | 
					      loading,
 | 
				
			||||||
      openDepot
 | 
					      openDepot
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
  },
 | 
					  }
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
</script>
 | 
					</script>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user