Merge branch 'develop' of gitee.com:layui-vue/layui-vue into develop
This commit is contained in:
@@ -37,6 +37,7 @@ import LaySwitch from "./module/switch/index";
|
||||
import LayCollapse from "./module/collapse/index";
|
||||
import LayCollapseItem from "./module/collapseItem/index";
|
||||
import LayContainer from "./module/container/index";
|
||||
import LayCountUp from "./module/countUp/index";
|
||||
import LayMenu from "./module/menu/index";
|
||||
import LayMenuItem from "./module/menuItem/index";
|
||||
import LayMenuChildItem from "./module/menuChildItem/index";
|
||||
@@ -128,6 +129,7 @@ const components: Record<string, IDefineComponent> = {
|
||||
LayModal,
|
||||
LayTooltip,
|
||||
LayInputNumber,
|
||||
LayCountUp,
|
||||
};
|
||||
|
||||
const install = (app: App, options?: InstallOptions): void => {
|
||||
|
||||
9
src/module/countUp/index.ts
Normal file
9
src/module/countUp/index.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import type { App } from "vue";
|
||||
import Component from "./index.vue";
|
||||
import type { IDefineComponent } from "../type/index";
|
||||
|
||||
Component.install = (app: App) => {
|
||||
app.component(Component.name || "LayCountUp", Component);
|
||||
};
|
||||
|
||||
export default Component as IDefineComponent;
|
||||
74
src/module/countUp/index.vue
Normal file
74
src/module/countUp/index.vue
Normal file
@@ -0,0 +1,74 @@
|
||||
<template>
|
||||
<slot name="prefix"></slot>
|
||||
<span ref="counterRef" style="font-family:sans-serif;" />
|
||||
<slot name="suffix"></slot>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref, watch } from 'vue'
|
||||
import { CountUp } from 'countup.js'
|
||||
import type { CountUpOptions } from 'countup.js'
|
||||
|
||||
export interface LayCountupProps {
|
||||
endVal?: number; //显示的值
|
||||
decimalPlaces?: number; // 小数位数
|
||||
useGrouping?: boolean; // 是否使用千位分隔符
|
||||
separator?: string; // 千位分隔符
|
||||
useEasing?: boolean; // 使用动画
|
||||
duration?: number; // 动画持续时间
|
||||
prefix?: string; // 前缀
|
||||
suffix?: string; // 后缀
|
||||
option?: CountUpOptions; // 选项
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<LayCountupProps>(), {
|
||||
endVal: 0,
|
||||
option: () => {
|
||||
return {}
|
||||
}
|
||||
});
|
||||
|
||||
const counterRef = ref<HTMLDivElement | null>(null);
|
||||
const instance = ref<CountUp | null>(null);
|
||||
const {decimalPlaces,useGrouping,separator,useEasing,duration,prefix,suffix} = props;
|
||||
const defaultOptions: CountUpOptions = {
|
||||
startVal: 0, // 开始数字
|
||||
decimalPlaces: decimalPlaces ? decimalPlaces : 0, // 小数位数
|
||||
useEasing: useEasing ? useEasing : true, // 使用缓动动画
|
||||
duration: duration ? duration : 2, // 动画持续时间
|
||||
useGrouping: useGrouping ? useGrouping : true, // 是否使用千位分隔符
|
||||
separator:separator ? separator : ",", // 千位分隔符
|
||||
decimal:".", // 小数点分隔符
|
||||
prefix: prefix ? prefix : "", // 前缀
|
||||
suffix: suffix ? suffix : "", // 后缀
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.endVal,
|
||||
() => {
|
||||
update(props.endVal)
|
||||
}
|
||||
);
|
||||
|
||||
onMounted(() => {
|
||||
createCounter()
|
||||
})
|
||||
|
||||
const createCounter = () => {
|
||||
if (!counterRef.value) return
|
||||
const opts: CountUpOptions = Object.assign(defaultOptions, props.option)
|
||||
instance.value = new CountUp(counterRef?.value, props.endVal, opts);
|
||||
start();
|
||||
}
|
||||
|
||||
const start = () => {
|
||||
if (!instance.value) return
|
||||
instance?.value.start();
|
||||
}
|
||||
|
||||
const update = (newEndVal: number) => {
|
||||
if (!instance.value) return
|
||||
instance?.value.update(newEndVal);
|
||||
}
|
||||
|
||||
</script>
|
||||
@@ -1,57 +1,60 @@
|
||||
<template>
|
||||
<div class="layui-box layui-laypage layui-laypage-default">
|
||||
<span v-if="showCount" class="layui-laypage-count">共 {{ total }} 条 {{ maxPage }}页</span>
|
||||
<a
|
||||
<span v-if="showCount" class="layui-laypage-count">共 {{ total }} 条</span
|
||||
><a
|
||||
href="javascript:;"
|
||||
class="layui-laypage-prev"
|
||||
:class="[currentPage === 1 ? 'layui-disabled' : '']"
|
||||
@click="prev()"
|
||||
><slot v-if="slots.prev" name="prev"></slot>
|
||||
<template v-else>上一页</template></a
|
||||
>
|
||||
<slot v-if="slots.prev" name="prev"></slot>
|
||||
<template v-else>上一页</template>
|
||||
</a>
|
||||
<template v-if="showPage">
|
||||
<template v-for="index of totalPage" :key="index">
|
||||
<span v-if="index === currentPage" class="layui-laypage-curr">
|
||||
<em class="layui-laypage-em" :class="[theme ? 'layui-bg-' + theme : '']"></em>
|
||||
<em>{{ index }}</em>
|
||||
</span>
|
||||
<a v-else href="javascript:;" @click="jump(index)">{{ index }}</a>
|
||||
<span v-if="index === currentPage" class="layui-laypage-curr"
|
||||
><em
|
||||
class="layui-laypage-em"
|
||||
:class="[theme ? 'layui-bg-' + theme : '']"
|
||||
></em
|
||||
><em>{{ index }}</em></span
|
||||
>
|
||||
<a v-else href="javascript:;" @click="jump(index)">
|
||||
{{ index }}
|
||||
</a>
|
||||
</template>
|
||||
</template>
|
||||
|
||||
<a
|
||||
href="javascript:;"
|
||||
class="layui-laypage-next"
|
||||
:class="[currentPage === maxPage ? 'layui-disabled' : '']"
|
||||
:class="[currentPage === totalPage ? 'layui-disabled' : '']"
|
||||
@click="next()"
|
||||
><slot v-if="slots.next" name="next"></slot>
|
||||
<template v-else>下一页</template></a
|
||||
><span v-if="showLimit" class="layui-laypage-limits"
|
||||
><select v-model="inlimit">
|
||||
<option value="10">10 条/页</option>
|
||||
<option value="20">20 条/页</option>
|
||||
<option value="30">30 条/页</option>
|
||||
<option value="40">40 条/页</option>
|
||||
<option value="50">50 条/页</option>
|
||||
</select></span
|
||||
><a v-if="showRefresh" href="javascript:;" class="layui-laypage-refresh"
|
||||
><i class="layui-icon layui-icon-refresh"></i></a
|
||||
><span v-if="showSkip" class="layui-laypage-skip"
|
||||
>到第<input
|
||||
v-model="currentPageShow"
|
||||
type="number"
|
||||
class="layui-input layui-input-number"
|
||||
/>页<button type="button" class="layui-laypage-btn" @click="jumpPage()">
|
||||
确定
|
||||
</button></span
|
||||
>
|
||||
<slot v-if="slots.next" name="next"></slot>
|
||||
<template v-else>下一页</template>
|
||||
</a>
|
||||
<span v-if="showLimit" class="layui-laypage-limits">
|
||||
<select v-model="inlimit">
|
||||
<option v-for="val of limits" :key="val" :value="val">{{ val }} 条/页</option>
|
||||
</select>
|
||||
</span>
|
||||
<a v-if="showRefresh" href="javascript:;" class="layui-laypage-refresh">
|
||||
<i class="layui-icon layui-icon-refresh"></i>
|
||||
</a>
|
||||
<span v-if="showSkip" class="layui-laypage-skip">
|
||||
到第
|
||||
<input v-model="currentPageShow" type="number" class="layui-input layui-input-number" />页
|
||||
<button
|
||||
type="button"
|
||||
class="layui-laypage-btn"
|
||||
@click="jumpPage()"
|
||||
:disabled="currentPageShow > maxPage"
|
||||
>确定</button>
|
||||
</span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup name="LayPage" lang="ts">
|
||||
import { defineProps, Ref, ref, watch, useSlots, computed } from "vue";
|
||||
import { defineProps, Ref, ref, watch, useSlots, computed, ComputedRef } from "vue";
|
||||
|
||||
const slots = useSlots();
|
||||
|
||||
@@ -66,8 +69,6 @@ const props = withDefaults(
|
||||
showLimit?: boolean | string;
|
||||
showInput?: boolean | string;
|
||||
showRefresh?: boolean | string;
|
||||
pages?: number,
|
||||
limits?: number[]
|
||||
}>(),
|
||||
{
|
||||
limit: 10,
|
||||
@@ -78,8 +79,6 @@ const props = withDefaults(
|
||||
showLimit: true,
|
||||
showInput: false,
|
||||
showRefresh: false,
|
||||
pages: 10,
|
||||
limits: () => [10, 20, 30, 40, 50]
|
||||
}
|
||||
);
|
||||
const limits = ref(props.limits);
|
||||
@@ -98,8 +97,7 @@ const totalPage = computed(() => {
|
||||
})
|
||||
const currentPage: Ref<number> = ref(1);
|
||||
const currentPageShow: Ref<number> = ref(currentPage.value);
|
||||
|
||||
const emit = defineEmits(["jump", "limit"]);
|
||||
const emit = defineEmits(["jump"]);
|
||||
|
||||
const prev = function () {
|
||||
if (currentPage.value === 1) {
|
||||
@@ -109,7 +107,7 @@ const prev = function () {
|
||||
};
|
||||
|
||||
const next = function () {
|
||||
if (currentPage.value === maxPage.value) {
|
||||
if (currentPage.value === totalPage.value) {
|
||||
return;
|
||||
}
|
||||
currentPage.value++;
|
||||
@@ -125,11 +123,11 @@ const jumpPage = function () {
|
||||
|
||||
watch(inlimit, function () {
|
||||
currentPage.value = 1;
|
||||
maxPage.value = Math.ceil(props.total / inlimit.value);
|
||||
totalPage.value = Math.ceil(props.total / inlimit.value);
|
||||
});
|
||||
|
||||
watch(currentPage, function () {
|
||||
currentPageShow.value = currentPage.value;
|
||||
emit("jump", { current: currentPage.value });
|
||||
});
|
||||
</script>
|
||||
</script>
|
||||
Reference in New Issue
Block a user