更新:登录功能

This commit is contained in:
2025-11-04 12:37:04 +08:00
commit a21fb92916
897 changed files with 51500 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
@import '../common/abstracts/variable';
@import '../common/abstracts/mixin';
.wd-count-to{
vertical-align: bottom;
}

View File

@@ -0,0 +1,117 @@
import type { ComponentPublicInstance, ExtractPropTypes } from 'vue'
import { baseProps, makeBooleanProp, makeNumberProp, makeStringProp } from '../common/props'
import type { TextType } from '../wd-text/types'
export const countToProps = {
...baseProps,
// 字体大小
fontSize: makeNumberProp(16),
// 文本颜色
color: makeStringProp(''),
/**
* 主题类型
* 类型string
* 可选值:'default' /'primary' / 'error' / 'warning' / 'success'
* 默认值:'default'
*/
type: makeStringProp<TextType>('default'),
/**
* 起始值
* 类型number
* 默认值0
*/
startVal: makeNumberProp(0),
/**
* 最终值
* 类型number
* 默认值2021
*/
endVal: makeNumberProp(2024),
/**
* 从起始值到结束值数字变动的时间,单位毫秒
* 类型number
* 默认值3000
*/
duration: makeNumberProp(3000),
/**
* 是否自动开始
* 类型boolean
* 默认值true
*/
autoStart: makeBooleanProp(true),
/**
* 保留的小数位数
* 类型number
* 默认值0
* 校验大于等于0
*/
decimals: {
type: Number,
required: false,
default: 0,
validator(value: number) {
return value >= 0
}
},
// 小数点
decimal: makeStringProp('.'),
// 三位三位的隔开效果
separator: makeStringProp(','),
/**
* 前缀
* 类型string
* 默认值:''
* @example '¥' 人民币前缀
*/
prefix: makeStringProp(''),
/**
* 后缀
* 类型string
* 默认值:''
*/
suffix: makeStringProp(''),
/**
* 是否具有连贯性
* 类型boolean
* 默认值true
*/
useEasing: makeBooleanProp(true),
/**
* 自定义根节点样式
*/
customStyle: makeStringProp(''),
/**
* 自定义根节点样式类
*/
customClass: makeStringProp('')
}
export type CountDownProps = ExtractPropTypes<typeof countToProps>
export type CountUpExpose = {
/**
* 开始倒计时
*/
start: () => void
/**
* 暂停倒计时
*/
pause: () => void
/**
* 重设倒计时,若 auto-start 为 true重设后会自动开始倒计时
*/
reset: () => void
}
export type CountToInstance = ComponentPublicInstance<CountDownProps, CountUpExpose>

View File

@@ -0,0 +1,125 @@
<template>
<view :class="rootClass">
<!-- 前缀插槽 -->
<slot name="prefix">
<wd-text :type="props.type" :color="props.color" :size="`${props.fontSize * 0.7}px`" :text="props.prefix"></wd-text>
</slot>
<!-- 默认文本插槽 -->
<slot>
<wd-text :type="props.type" :color="props.color" :size="`${props.fontSize}px`" :text="timeText"></wd-text>
</slot>
<!-- 后缀插槽 -->
<slot name="suffix">
<wd-text :type="props.type" :color="props.color" :size="`${props.fontSize * 0.7}px`" :text="props.suffix"></wd-text>
</slot>
</view>
</template>
<script lang="ts">
export default {
name: 'wd-count-to',
options: {
virtualHost: true,
addGlobalClass: true,
styleIsolation: 'shared'
}
}
</script>
<script lang="ts" setup>
import wdText from '../wd-text/wd-text.vue'
import { computed, watch, onMounted } from 'vue'
import { countToProps } from './types'
import { easingFn, isNumber } from '../common/util'
import { useCountDown } from '../composables/useCountDown'
import type { CountDownExpose } from '../wd-count-down/types'
const props = defineProps(countToProps)
const emit = defineEmits(['mounted', 'finish'])
const { start, pause, reset, current } = useCountDown({
time: props.duration,
millisecond: true,
onFinish: () => emit('finish')
})
// 计算根元素的类名
const rootClass = computed(() => {
return `wd-count-to ${props.customClass}`
})
const timeText = computed(() => {
return parseFormat(current.value.total)
})
watch([() => props.startVal, () => props.endVal, () => props.duration], resetTime, { immediate: false })
onMounted(() => {
resetTime()
emit('mounted')
})
// 重置动画
function resetTime() {
reset(props.duration)
if (props.autoStart) {
start()
}
}
function parseFormat(remain: number) {
const { startVal, endVal, duration, useEasing } = props
const progress = duration - remain // 已经进行的时间
const isPositive = startVal > endVal // 判断startVal是否大于endVal
const progressRatio = progress / duration // 计算进度比例
let currentVal: number
if (useEasing) {
// 使用缓动函数计算currentVal
if (isPositive) {
currentVal = startVal - easingFn(progress, 0, startVal - endVal, duration) || 0
} else {
currentVal = easingFn(progress, startVal, endVal - startVal, duration)
}
} else {
// 不使用缓动函数时的计算方式
if (isPositive) {
currentVal = startVal - (startVal - endVal) * progressRatio
} else {
currentVal = startVal + (endVal - startVal) * progressRatio
}
}
// 确保currentVal在startVal和endVal之间
currentVal = isPositive ? Math.max(endVal, currentVal) : Math.min(endVal, currentVal)
return formatNumber(currentVal)
}
// 格式化数字
function formatNumber(num: any): string {
if (typeof num !== 'number') {
num = parseFloat(num)
if (isNaN(num)) {
return '0'
}
}
num = num.toFixed(props.decimals)
const parts = num.split('.')
let integerPart = parts[0]
const decimalPart = parts.length > 1 ? props.decimal + parts[1] : ''
const rgx = /(\d+)(\d{3})/
if (props.separator && !isNumber(props.separator)) {
while (rgx.test(integerPart)) {
integerPart = integerPart.replace(rgx, '$1' + props.separator + '$2')
}
}
return integerPart + decimalPart
}
defineExpose<CountDownExpose>({ start, reset: resetTime, pause })
</script>
<style lang="scss" scoped>
@import './index.scss';
</style>