Skip to content

Commit

Permalink
fix: 修改代码格式化的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
wudengyao committed Feb 6, 2024
1 parent 2095738 commit e398662
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 93 deletions.
178 changes: 92 additions & 86 deletions src/components/Pagination/index.vue
Original file line number Diff line number Diff line change
@@ -1,108 +1,114 @@
<template>
<div :class="{ 'hidden': hidden }" class="pagination-container">
<div :class="{'hidden':hidden}" class="pagination-container">
<el-pagination
v-model:current-page="currentPage"
v-model:page-size="pageSize"
:background="background"
:current-page.sync="currentPage"
:page-size.sync="pageSize"
:layout="layout"
:page-sizes="pageSizes"
:pager-count="pagerCount"
:total="total"
v-bind="$attrs"
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
/>
</div>
</template>

<style scoped>
.pagination-container {
display: flex;
justify-content: end;
margin-top: 20px;
background: #fff;
}
.pagination-container.hidden {
display: none;
}
</style>
.pagination-container {
padding: 32px 16px;
background: #fff;
}
.pagination-container.hidden {
display: none;
}
</style>

<script setup>
<script>
import { scrollTo } from "@/utils/scroll-to";
import { computed } from "vue";
const props = defineProps(
total: {
required: true,
type: Number,
export default {
name: "pagination",
props: {
total: {
required: true,
type: Number
},
page: {
type: Number,
default: 1
},
limit: {
type: Number,
default: 20
},
pageSizes: {
type: Array,
default() {
return [10, 20, 30, 50];
}
},
// 移动端页码按钮的数量端默认值5
pagerCount: {
type: Number,
default: document.body.clientWidth < 992 ? 5 : 7
},
layout: {
type: String,
default: "total, sizes, prev, pager, next, jumper"
},
background: {
type: Boolean,
default: true
},
autoScroll: {
type: Boolean,
default: true
},
hidden: {
type: Boolean,
default: false
}
},
page: {
type: Number,
default: 1
data() {
return {
};
},
limit: {
type: Number,
default: 20
computed: {
currentPage: {
get() {
return this.page;
},
set(val) {
this.$emit("update:page", val);
}
},
pageSize: {
get() {
return this.limit;
},
set(val) {
this.$emit("update:limit", val);
}
}
},
pageSizes: {
type: Array,
default() {
return [10, 20, 30, 40, 50];
}
},
// 移动端页码按钮的数量端默认值5
pagerCount: {
type: Number,
default: document.body.clientWidth < 992 ? 5 : 7
},
layout: {
type: String,
default: "total, sizes, prev, pager, next, jumper"
},
background: {
type: Boolean,
default: true
},
autoScroll: {
type: Boolean,
default: true
},
hidden: {
type: Boolean,
default: false
}
});
const emit = defineEmits();
const currentPage = computed({
get() {
return props.page;
},
set(val) {
emit("update:page", val);
}
});
const pageSize = computed({
get() {
return props.limit;
},
set(val) {
emit("update:limit", val);
}
});
function handleSizeChange(val) {
if (currentPage.value * val > props.total) {
currentPage.value = 1;
methods: {
handleSizeChange(val) {
if (this.currentPage * val > this.total) {
this.currentPage = 1;
}
this.$emit("pagination", { page: this.currentPage, limit: val });
if (this.autoScroll) {
scrollTo(0, 800);
}
},
handleCurrentChange(val) {
this.$emit("pagination", { page: val, limit: this.pageSize });
if (this.autoScroll) {
scrollTo(0, 800);
}
}
}
emit("pagination", { page: currentPage.value, limit: val });
if (props.autoScroll) {
scrollTo(0, 800);
}
}
function handleCurrentChange(val) {
emit("pagination", { page: val, limit: pageSize.value });
if (props.autoScroll) {
scrollTo(0, 800);
}
}
};
</script>
18 changes: 12 additions & 6 deletions src/layout/components/Sidebar/SidebarMenu.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<template>
<!-- 一级 menu 菜单 -->
<el-menu
:collapse="!$store.getters.sidebarOpened"
:default-active="activeMenu"
:unique-opened="true"
:collapse="!$store.getters.sidebarOpened"
:background-color="$store.getters.cssVar.menuBg"
:text-color="$store.getters.cssVar.menuText"
:active-text-color="$store.getters.cssVar.menuActiveText"
:unique-opened="false"
:unique-opened="true"
router
>
<sidebar-item
Expand All @@ -17,22 +16,29 @@
></sidebar-item>
</el-menu>
</template>

<style lang="scss" scoped></style>

<script setup>
import { computed } from "vue";
import SidebarItem from "./SidebarItem";
import { useRouter, useRoute } from "vue-router";
import { filterRouters, generateMenus } from "@/utils/route";
import SidebarItem from "./SidebarItem";
// 计算路由表结构
const router = useRouter();
const routes = computed(() => {
const filterRoutes = filterRouters(router.getRoutes());
return generateMenus(filterRoutes);
});
console.log("routes111==", routes);
// 计算高亮 menu 的方法
const route = useRoute();
const activeMenu = computed(() => {
const { path } = route;
const { meta, path } = route;
if (meta.activeMenu) {
return meta.activeMenu;
}
return path;
});
</script>
3 changes: 2 additions & 1 deletion src/main.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { createApp } from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";

import router from "./router";

// 导入权限控制模块
import "./permission";
import "@/styles/index.scss";
Expand Down

0 comments on commit e398662

Please sign in to comment.