切换私有源
This commit is contained in:
parent
064a436451
commit
a455abee12
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "@layui/layui-vue",
|
"name": "@ctsy/layui-vue",
|
||||||
"version": "0.3.2",
|
"version": "0.3.2",
|
||||||
"author": "sleeprite",
|
"author": "sleeprite",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="layui-box layui-laypage layui-laypage-default">
|
<div class="layui-box layui-laypage layui-laypage-default">
|
||||||
<span v-if="showCount" class="layui-laypage-count">共 {{ total }} 条</span
|
<span v-if="showCount" class="layui-laypage-count"
|
||||||
|
>共 {{ total }} 条 {{}} 页</span
|
||||||
><a
|
><a
|
||||||
href="javascript:;"
|
href="javascript:;"
|
||||||
class="layui-laypage-prev"
|
class="layui-laypage-prev"
|
||||||
@ -54,14 +55,23 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup name="LayPage" lang="ts">
|
<script setup name="LayPage" lang="ts">
|
||||||
import { defineProps, Ref, ref, watch, useSlots, computed, ComputedRef } from "vue";
|
import {
|
||||||
|
defineProps,
|
||||||
|
Ref,
|
||||||
|
ref,
|
||||||
|
watch,
|
||||||
|
useSlots,
|
||||||
|
computed,
|
||||||
|
ComputedRef,
|
||||||
|
} from "vue";
|
||||||
|
|
||||||
const slots = useSlots();
|
const slots = useSlots();
|
||||||
|
|
||||||
const props = withDefaults(
|
const props = withDefaults(
|
||||||
defineProps<{
|
defineProps<{
|
||||||
total: number;
|
total: number;
|
||||||
limit: number;
|
limit?: number;
|
||||||
|
pages?: number;
|
||||||
theme?: string;
|
theme?: string;
|
||||||
showPage?: boolean | string;
|
showPage?: boolean | string;
|
||||||
showSkip?: boolean | string;
|
showSkip?: boolean | string;
|
||||||
@ -72,6 +82,7 @@ const props = withDefaults(
|
|||||||
}>(),
|
}>(),
|
||||||
{
|
{
|
||||||
limit: 10,
|
limit: 10,
|
||||||
|
pages: 10,
|
||||||
theme: "green",
|
theme: "green",
|
||||||
showPage: false,
|
showPage: false,
|
||||||
showSkip: false,
|
showSkip: false,
|
||||||
@ -81,23 +92,35 @@ const props = withDefaults(
|
|||||||
showRefresh: false,
|
showRefresh: false,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
const limits = ref(props.limits);
|
const pages = props.pages / 2;
|
||||||
const pages = props.pages / 2
|
const inlimit = computed({
|
||||||
const inlimit = computed({ get() { return props.limit }, set(v: number) { emit('limit', v) } })
|
get() {
|
||||||
|
return props.limit;
|
||||||
|
},
|
||||||
|
set(v: number) {
|
||||||
|
emit("limit", v);
|
||||||
|
},
|
||||||
|
});
|
||||||
const maxPage = ref(Math.ceil(props.total / props.limit));
|
const maxPage = ref(Math.ceil(props.total / props.limit));
|
||||||
const totalPage = computed(() => {
|
const totalPage = computed(() => {
|
||||||
let r: number[] = [], start = (maxPage.value <= props.pages ? 1 : currentPage.value > pages ? currentPage.value - pages : 1)
|
let r: number[] = [],
|
||||||
|
start =
|
||||||
|
maxPage.value <= props.pages
|
||||||
|
? 1
|
||||||
|
: currentPage.value > pages
|
||||||
|
? currentPage.value - pages
|
||||||
|
: 1;
|
||||||
for (let i = start; ; i++) {
|
for (let i = start; ; i++) {
|
||||||
if (r.length >= props.pages || i > maxPage.value) {
|
if (r.length >= props.pages || i > maxPage.value) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
r.push(i)
|
r.push(i);
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
})
|
});
|
||||||
const currentPage: Ref<number> = ref(1);
|
const currentPage: Ref<number> = ref(1);
|
||||||
const currentPageShow: Ref<number> = ref(currentPage.value);
|
const currentPageShow: Ref<number> = ref(currentPage.value);
|
||||||
const emit = defineEmits(["jump"]);
|
const emit = defineEmits(["jump", "limit"]);
|
||||||
|
|
||||||
const prev = function () {
|
const prev = function () {
|
||||||
if (currentPage.value === 1) {
|
if (currentPage.value === 1) {
|
||||||
@ -107,7 +130,7 @@ const prev = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const next = function () {
|
const next = function () {
|
||||||
if (currentPage.value === totalPage.value) {
|
if (currentPage.value === totalPage.value[totalPage.value.length - 1]) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
currentPage.value++;
|
currentPage.value++;
|
||||||
@ -123,7 +146,7 @@ const jumpPage = function () {
|
|||||||
|
|
||||||
watch(inlimit, function () {
|
watch(inlimit, function () {
|
||||||
currentPage.value = 1;
|
currentPage.value = 1;
|
||||||
totalPage.value = Math.ceil(props.total / inlimit.value);
|
// totalPage.value = Math.ceil(props.total / inlimit.value);
|
||||||
});
|
});
|
||||||
|
|
||||||
watch(currentPage, function () {
|
watch(currentPage, function () {
|
||||||
|
Loading…
Reference in New Issue
Block a user