Refactor drawing query pages and routing structure

This commit is contained in:
wangqiao
2025-08-29 17:40:54 +08:00
parent a2c2a87e38
commit 7fe259299e
7 changed files with 345 additions and 565 deletions

View File

@ -33,13 +33,20 @@
import { getDictTree } from '~/api/home/index'
import type { pageRes, pageReq } from '~/api/upnew/types'
const route = useRoute()
const projectType = computed(() => route.query?.projectType as string)
const projectType = computed(() => (route.params?.projectType ? route.params?.projectType : ''))
const pageNo = computed(() => Number(route.params?.pageNo))
const pageSize = computed(() => Number(route.params?.pageSize))
const editions = computed(() => (route.params?.editions ? route.params?.editions : ''))
const source = computed(() => (route.params?.source ? Number(route.params?.source) : ''))
console.log('route.params----', route.params)
const level = ref(
route.query?.valuelevel
? JSON.parse(route.query.valuelevel as string)
: [
{
id: '0',
id: -1,
name: '图纸库',
isChildren: false,
},
@ -48,11 +55,11 @@
const keywords = ref((route.query?.valuekeywords as string) || '')
const query = ref<pageReq>({
pageNo: 1,
pageSize: 12,
projectType: projectType.value,
editions: '',
source: '',
pageNo: pageNo.value || 1,
pageSize: pageSize.value || 12,
projectType: projectType.value || '-1',
editions: editions.value || '-1',
source: source.value || -1,
type: 1,
title: keywords.value,
})
@ -63,23 +70,30 @@
// idprojectType
if (level.value.length) {
query.value.projectType = level.value[level.value.length - 1].id || ''
// query.value.projectType = level.value[level.value.length - 1].id || ''
}
const handleClickSize = (val: number) => {
query.value.pageSize = val
getPage()
// getPage()
navigateTo(`/drawe/${query.value.projectType}/${query.value.pageNo}/${val}/${query.value.editions}/${query.value.source}`)
}
const handeClickCurrent = (val: number) => {
query.value.pageNo = val
getPage()
// getPage()
navigateTo(`/drawe/${query.value.projectType}/${val}/${query.value.pageSize}/${query.value.editions}/${query.value.source}`)
}
const { data: result, refresh: getPage } = useAsyncData(
`draw-page-list-${Date.now()}`,
`draw-page-list-${query.value.projectType}-${query.value.editions}-${query.value.source}-${query.value.pageNo}-${query.value.pageSize}-${query.value.title}`,
async () => {
const res = await page(query.value)
const res = await page({
...query.value,
editions: query.value.editions === '-1' ? '' : query.value.editions,
source: query.value.source === -1 ? '' : query.value.source,
projectType: query.value.projectType === '-1' ? '' : query.value.projectType,
})
return res.data
},
{
@ -98,7 +112,7 @@
watch([() => query.value.projectType, () => query.value.editions, () => query.value.source], (val) => {
if (val) {
getPage()
navigateTo(`/drawe/${query.value.projectType}/1/${query.value.pageSize}/${query.value.editions}/${query.value.source}`)
}
})
</script>

View File

@ -33,12 +33,13 @@
import { getDictTree } from '~/api/home/index'
import type { pageRes, pageReq } from '~/api/upnew/types'
const route = useRoute()
const level = ref(
route.query?.valuelevel
? JSON.parse(route.query.valuelevel as string)
: [
{
id: '0',
id: -1,
name: '图纸库',
isChildren: false,
},
@ -49,9 +50,9 @@
const query = ref<pageReq>({
pageNo: 1,
pageSize: 12,
projectType: '',
editions: '',
source: '',
projectType: '-1',
editions: '-1',
source: -1,
type: 1,
title: keywords.value,
})
@ -62,23 +63,30 @@
// 如果id存在则设置projectType
if (level.value.length) {
query.value.projectType = level.value[level.value.length - 1].id || ''
// query.value.projectType = level.value[level.value.length - 1].id || ''
}
const handleClickSize = (val: number) => {
query.value.pageSize = val
getPage()
// getPage()
navigateTo(`/drawe/${query.value.projectType}/${query.value.pageNo}/${val}/${query.value.editions}/${query.value.source}`)
}
const handeClickCurrent = (val: number) => {
query.value.pageNo = val
getPage()
// getPage()
navigateTo(`/drawe/${query.value.projectType}/${val}/${query.value.pageSize}/${query.value.editions}/${query.value.source}`)
}
const { data: result, refresh: getPage } = useAsyncData(
`draw-page-list-${Date.now()}`,
`draw-page-list-${query.value.projectType}-${query.value.editions}-${query.value.source}-${query.value.pageNo}-${query.value.pageSize}-${query.value.title}`,
async () => {
const res = await page(query.value)
const res = await page({
...query.value,
editions: query.value.editions === '-1' ? '' : query.value.editions,
source: query.value.source === -1 ? '' : query.value.source,
projectType: query.value.projectType === '-1' ? '' : query.value.projectType,
})
return res.data
},
{
@ -97,7 +105,7 @@
watch([() => query.value.projectType, () => query.value.editions, () => query.value.source], (val) => {
if (val) {
getPage()
navigateTo(`/drawe/${query.value.projectType}/1/${query.value.pageSize}/${query.value.editions}/${query.value.source}`)
}
})
</script>

View File

@ -1,110 +0,0 @@
<template>
<!-- 导航 -->
<KlNavTab active="图纸" :type="1" />
<div class="ma-auto w-[1440px]">
<!-- 图纸分类 -->
<KlWallpaperCategory v-model="query" v-model:level="level" :type="1" />
<!-- 推荐栏目 -->
<RecommendedColumnsV2 v-model="query" v-model:result="result"></RecommendedColumnsV2>
<!-- 精选专题 -->
<!-- <FeaturedSpecials></FeaturedSpecials> -->
<!-- 分页 -->
<div class="mt-[10px] flex justify-center">
<el-pagination
v-model:current-page="query.pageNo"
v-model:page-size="query.pageSize"
:page-sizes="[12, 24, 48]"
:total="result?.total"
layout="total, sizes, prev, pager, next, jumper"
@size-change="handleClickSize"
@current-change="handeClickCurrent"
/>
</div>
</div>
</template>
<script setup lang="ts">
import KlNavTab from '~/components/kl-nav-tab/index.vue'
import KlWallpaperCategory from '~/components/kl-wallpaper-category/index.vue'
import RecommendedColumnsV2 from '~/components/drawe-components/RecommendedColumnsV2.vue'
// import FeaturedSpecials from './components/FeaturedSpecials.vue'
import { useRoute } from 'vue-router'
import { reactive, watch, ref } from 'vue'
import { page } from '~/api/upnew/index'
import { getDictTree } from '~/api/home/index'
import type { pageRes, pageReq } from '~/api/upnew/types'
const route = useRoute()
const level = ref(
route.query?.valuelevel
? JSON.parse(route.query.valuelevel as string)
: [
{
id: '0',
name: '图纸库',
isChildren: false,
},
]
)
const keywords = ref((route.query?.valuekeywords as string) || '')
const query = ref<pageReq>({
pageNo: 1,
pageSize: 12,
projectType: '',
editions: '',
source: '',
type: 1,
title: keywords.value,
})
// const result = reactive<pageRes>({
// list: [],
// total: 0,
// })
// 如果id存在则设置projectType
if (level.value.length) {
query.value.projectType = level.value[level.value.length - 1].id || ''
}
const handleClickSize = (val: number) => {
query.value.pageSize = val
getPage()
}
const handeClickCurrent = (val: number) => {
query.value.pageNo = val
getPage()
}
const { data: result, refresh: getPage } = useAsyncData(
`draw-page-list-${Date.now()}`,
async () => {
const res = await page(query.value)
return res.data
},
{
immediate: true,
}
)
// const getPage = () => {
// page(query).then((res) => {
// const { data, code } = res
// if (code === 0) {
// result.list = data.list
// result.total = data.total
// }
// })
// }
watch([() => query.value.projectType, () => query.value.editions, () => query.value.source], (val) => {
if (val) {
getPage()
}
})
</script>
<style lang="scss" scoped>
:deep(.el-pagination) {
.el-input__inner {
text-align: center !important;
}
}
</style>

View File

@ -1,110 +0,0 @@
<template>
<!-- 导航 -->
<KlNavTab active="图纸" :type="1" />
<div class="ma-auto w-[1440px]">
<!-- 图纸分类 -->
<KlWallpaperCategory v-model="query" v-model:level="level" :type="1" />
<!-- 推荐栏目 -->
<RecommendedColumnsV2 v-model="query" v-model:result="result"></RecommendedColumnsV2>
<!-- 精选专题 -->
<!-- <FeaturedSpecials></FeaturedSpecials> -->
<!-- 分页 -->
<div class="mt-[10px] flex justify-center">
<el-pagination
v-model:current-page="query.pageNo"
v-model:page-size="query.pageSize"
:page-sizes="[12, 24, 48]"
:total="result?.total"
layout="total, sizes, prev, pager, next, jumper"
@size-change="handleClickSize"
@current-change="handeClickCurrent"
/>
</div>
</div>
</template>
<script setup lang="ts">
import KlNavTab from '~/components/kl-nav-tab/index.vue'
import KlWallpaperCategory from '~/components/kl-wallpaper-category/index.vue'
import RecommendedColumnsV2 from '~/components/drawe-components/RecommendedColumnsV2.vue'
// import FeaturedSpecials from './components/FeaturedSpecials.vue'
import { useRoute } from 'vue-router'
import { reactive, watch, ref } from 'vue'
import { page } from '~/api/upnew/index'
import { getDictTree } from '~/api/home/index'
import type { pageRes, pageReq } from '~/api/upnew/types'
const route = useRoute()
const level = ref(
route.query?.valuelevel
? JSON.parse(route.query.valuelevel as string)
: [
{
id: '0',
name: '图纸库',
isChildren: false,
},
]
)
const keywords = ref((route.query?.valuekeywords as string) || '')
const query = ref<pageReq>({
pageNo: 1,
pageSize: 12,
projectType: '',
editions: '',
source: '',
type: 1,
title: keywords.value,
})
// const result = reactive<pageRes>({
// list: [],
// total: 0,
// })
// 如果id存在则设置projectType
if (level.value.length) {
query.value.projectType = level.value[level.value.length - 1].id || ''
}
const handleClickSize = (val: number) => {
query.value.pageSize = val
getPage()
}
const handeClickCurrent = (val: number) => {
query.value.pageNo = val
getPage()
}
const { data: result, refresh: getPage } = useAsyncData(
`draw-page-list-${Date.now()}`,
async () => {
const res = await page(query.value)
return res.data
},
{
immediate: true,
}
)
// const getPage = () => {
// page(query).then((res) => {
// const { data, code } = res
// if (code === 0) {
// result.list = data.list
// result.total = data.total
// }
// })
// }
watch([() => query.value.projectType, () => query.value.editions, () => query.value.source], (val) => {
if (val) {
getPage()
}
})
</script>
<style lang="scss" scoped>
:deep(.el-pagination) {
.el-input__inner {
text-align: center !important;
}
}
</style>

View File

@ -11,30 +11,16 @@
<!-- @click="handleSubmenuClick(item)" -->
{{ item.name }}
<!-- 悬浮浮窗 -->
<div
v-if="activeIndex === index"
class="submenu-panel"
:style="{ top: submenuTop + 'px' }"
@mouseenter="keepSubmenuVisible"
@mouseleave="hideSubMenu"
>
<div v-if="activeIndex === index" class="submenu-panel" :style="{ top: submenuTop + 'px' }" @mouseenter="keepSubmenuVisible" @mouseleave="hideSubMenu">
<div class="submenu-content">
<!-- <div class="text-right">更多</div> -->
<div class="submenu-group">
<template v-for="group in item.children" :key="group.id">
<div
class="submenu-group-title"
@click.stop="handleSubmenuClick(group)"
>
<div class="submenu-group-title" @click.stop="handleSubmenuClick(group)">
{{ group.name }}
</div>
<div class="submenu-group-items">
<div
v-for="sub in group.children"
:key="sub.id"
class="submenu-item"
@click.stop="handleSubmenuClick(group, sub)"
>
<div v-for="sub in group.children" :key="sub.id" class="submenu-item" @click.stop="handleSubmenuClick(sub)">
{{ sub.name }}
</div>
</div>
@ -47,134 +33,126 @@
</template>
<script setup lang="ts">
import { ref, onMounted } from "vue";
import type { ComponentPublicInstance } from "vue";
import { tab2 } from "~/api/home/index";
import type { ProjectDictNodeVO } from "~/api/home/type";
import { ref, onMounted } from 'vue'
import type { ComponentPublicInstance } from 'vue'
import { tab2 } from '~/api/home/index'
import type { ProjectDictNodeVO } from '~/api/home/type'
const activeIndex = ref(-1);
const submenuTop = ref(0);
// const submenuLeft = ref(0)
const sideMenu = ref();
const menuItemRefs = ref<HTMLElement[]>([]);
const activeIndex = ref(-1)
const submenuTop = ref(0)
// const submenuLeft = ref(0)
const sideMenu = ref()
const menuItemRefs = ref<HTMLElement[]>([])
// const menuItems = ref<ProjectDictNodeVO[]>([]);
// const menuItems = ref<ProjectDictNodeVO[]>([]);
// 等待数据加载完成再进行渲染 :courseData 对data进行别名赋值
const { data: menuItems, pending, error } = useAsyncData(
'tab2-list',
async () => {
// 等待数据加载完成再进行渲染 :courseData 对data进行别名赋值
const {
data: menuItems,
pending,
error,
} = useAsyncData('tab2-list', async () => {
const res = await tab2()
const arr = [];
for (let i = 0; i < res.data?.length; i += 2) {
arr.push({
children: res.data.slice(i, i + 2),
name: getName(res.data.slice(i, i + 2)),
});
}
const arr = []
for (let i = 0; i < res.data?.length; i += 2) {
arr.push({
children: res.data.slice(i, i + 2),
name: getName(res.data.slice(i, i + 2)),
})
}
return arr
}
)
})
const showSubMenu = (index: number) => {
// if (menuItems.value.length === index + 1) {
// return
// }
activeIndex.value = index;
const dom = menuItemRefs.value[index].getBoundingClientRect();
console.log(dom);
// submenuTop.value = window.scrollY
};
const hideSubMenu = () => {
activeIndex.value = -1;
};
const handleSubmenuClick = (
primary?: ProjectDictNodeVO,
secondary?: ProjectDictNodeVO,
tertiary?: ProjectDictNodeVO
) => {
const normal = { id: "0", name: "图纸库", isChildren: false };
const level = [primary, secondary, tertiary]
.filter(Boolean)
.map((item) => ({
id: item?.id,
name: item?.name,
isChildren: item?.children?.length ? false : true,
}));
if (primary?.id === "0") {
level[0].name = "图纸库";
} else {
level.unshift(normal);
const showSubMenu = (index: number) => {
// if (menuItems.value.length === index + 1) {
// return
// }
activeIndex.value = index
const dom = menuItemRefs.value[index].getBoundingClientRect()
console.log(dom)
// submenuTop.value = window.scrollY
}
navigateTo(`/drawe?level=${JSON.stringify(level)}`);
};
const keepSubmenuVisible = () => {
// activeIndex.value = activeIndex.value // 保持当前索引
};
const setMenuItemRef = (
el: Element | ComponentPublicInstance | null,
index: number
) => {
if (el && "offsetTop" in el) {
menuItemRefs.value[index] = el as HTMLElement;
const hideSubMenu = () => {
activeIndex.value = -1
}
};
const getName = (arr: any[]) => {
if (arr.length === 1) {
return arr[0].name;
} else {
return arr[0].name + " / " + arr[1].name;
const handleSubmenuClick = (primary: ProjectDictNodeVO) => {
// const normal = { id: "0", name: "图纸库", isChildren: false };
// const level = [primary, secondary, tertiary]
// .filter(Boolean)
// .map((item) => ({
// id: item?.id,
// name: item?.name,
// isChildren: item?.children?.length ? false : true,
// }));
// if (primary?.id === "0") {
// level[0].name = "图纸库";
// } else {
// level.unshift(normal);
// }
// navigateTo(`/drawe?level=${JSON.stringify(level)}`)
navigateTo(`/drawe/${primary.id}/1/12/-1`)
}
};
const init = () => {
// 获取标签
// getLabel()
};
const keepSubmenuVisible = () => {
// activeIndex.value = activeIndex.value // 保持当前索引
}
onMounted(() => {
// init();
});
const setMenuItemRef = (el: Element | ComponentPublicInstance | null, index: number) => {
if (el && 'offsetTop' in el) {
menuItemRefs.value[index] = el as HTMLElement
}
}
const getName = (arr: any[]) => {
if (arr.length === 1) {
return arr[0].name
} else {
return arr[0].name + ' / ' + arr[1].name
}
}
const init = () => {
// 获取标签
// getLabel()
}
onMounted(() => {
// init();
})
</script>
<style scoped>
.side-menu {
width: 221px;
background-color: #fff;
/* padding: 10px 0; */
/* box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); */
/* overflow: visible; */
box-sizing: border-box;
position: relative; /* 添加定位上下文 */
/* overflow-y: auto; */
/* 隐藏滚动条 */
scrollbar-width: none; /* Firefox */
-ms-overflow-style: none; /* IE and Edge */
z-index: 9;
/* padding-top: 10px; */
}
.side-menu {
width: 221px;
background-color: #fff;
/* padding: 10px 0; */
/* box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); */
/* overflow: visible; */
box-sizing: border-box;
position: relative; /* 添加定位上下文 */
/* overflow-y: auto; */
/* 隐藏滚动条 */
scrollbar-width: none; /* Firefox */
-ms-overflow-style: none; /* IE and Edge */
z-index: 9;
/* padding-top: 10px; */
}
/* 隐藏 Webkit 浏览器的滚动条 */
.side-menu::-webkit-scrollbar {
display: none;
}
/* 隐藏 Webkit 浏览器的滚动条 */
.side-menu::-webkit-scrollbar {
display: none;
}
/* 鼠标悬停时显示滚动条 */
.side-menu:hover {
scrollbar-width: none; /* Firefox */
-ms-overflow-style: none; /* IE and Edge */
}
/* 鼠标悬停时显示滚动条 */
.side-menu:hover {
scrollbar-width: none; /* Firefox */
-ms-overflow-style: none; /* IE and Edge */
}
/* .side-menu:hover::-webkit-scrollbar {
/* .side-menu:hover::-webkit-scrollbar {
display: block;
width: 8px !important;
}
@ -188,44 +166,44 @@ onMounted(() => {
background-color: #fff;
} */
.menu-item {
/* position: relative; */
text-align: center;
padding: 11px 24px;
cursor: pointer;
/* transition: all 0.3s ease; */
color: #333;
font-size: 14px;
border: 1px solid transparent;
z-index: 9;
}
.menu-item {
/* position: relative; */
text-align: center;
padding: 11px 24px;
cursor: pointer;
/* transition: all 0.3s ease; */
color: #333;
font-size: 14px;
border: 1px solid transparent;
z-index: 9;
}
.menu-item:hover {
background-color: #fff;
color: #1890ff;
border: 1px solid #1890ff;
border-right: transparent !important;
}
.menu-item:hover {
background-color: #fff;
color: #1890ff;
border: 1px solid #1890ff;
border-right: transparent !important;
}
.submenu-panel {
position: absolute;
left: 220px;
top: 0;
width: 957px;
background: #fff;
/* box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1); */
border: 1px solid #1890ff;
/* border-radius: 4px; */
display: flex;
padding: 20px;
z-index: -1;
box-sizing: border-box;
min-height: 480px;
overflow-y: auto;
}
.submenu-panel {
position: absolute;
left: 220px;
top: 0;
width: 957px;
background: #fff;
/* box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1); */
border: 1px solid #1890ff;
/* border-radius: 4px; */
display: flex;
padding: 20px;
z-index: -1;
box-sizing: border-box;
min-height: 480px;
overflow-y: auto;
}
.submenu-panel::before {
/* content: '';
.submenu-panel::before {
/* content: '';
position: absolute;
left: -6px;
top: 50%;
@ -236,61 +214,61 @@ onMounted(() => {
border-bottom: 8px solid transparent;
border-right: 8px solid #fff;
filter: drop-shadow(-2px 0 2px rgba(0, 0, 0, 0.1)); */
}
}
.submenu-content {
/* flex: 1; */
/* display: grid; */
/* grid-template-columns: repeat(3, 1fr); */
/* gap: 15px; */
width: 100%;
display: flex;
flex-direction: column;
.submenu-group {
.submenu-content {
/* flex: 1; */
/* display: grid; */
/* grid-template-columns: repeat(3, 1fr); */
/* gap: 15px; */
width: 100%;
display: flex;
flex-direction: column;
align-items: flex-start;
flex-wrap: wrap;
-webkit-column-break-inside: avoid; /* 兼容webkit内核 */
/* border: 1px solid #e6e8eb; */
.submenu-group-title {
font-size: 15px;
/* font-weight: 700; */
padding: 10px 16px;
color: #000;
font-weight: 600;
transition: all 0.2s;
/* border-bottom: 1px solid #e6e8eb; */
}
.submenu-group-title:hover {
color: #1890ff;
/* border-bottom: 1px solid #e6e8eb; */
}
.submenu-group-items {
display: flex !important;
flex-direction: row;
.submenu-group {
display: flex;
flex-direction: column;
align-items: flex-start;
flex-wrap: wrap;
color: #666;
padding: 0px 16px;
gap: 10px;
.submenu-item {
cursor: pointer;
-webkit-column-break-inside: avoid; /* 兼容webkit内核 */
/* border: 1px solid #e6e8eb; */
.submenu-group-title {
font-size: 15px;
/* font-weight: 700; */
padding: 10px 16px;
color: #000;
font-weight: 600;
transition: all 0.2s;
/* border-bottom: 1px solid #e6e8eb; */
}
.submenu-group-title:hover {
color: #1890ff;
/* border-bottom: 1px solid #e6e8eb; */
}
.submenu-group-items {
display: flex !important;
flex-direction: row;
align-items: flex-start;
flex-wrap: wrap;
color: #666;
padding: 0px 16px;
gap: 10px;
.submenu-item {
cursor: pointer;
}
}
}
}
}
.submenu-item {
cursor: pointer;
transition: all 0.2s;
display: inline-block; /* 改为行内块元素 */
/* padding: 8px 12px; */
padding-right: 12px;
/* padding-bottom: 8px; */
}
.submenu-item {
cursor: pointer;
transition: all 0.2s;
display: inline-block; /* 改为行内块元素 */
/* padding: 8px 12px; */
padding-right: 12px;
/* padding-bottom: 8px; */
}
.submenu-item:hover {
color: #1890ff;
}
.submenu-item:hover {
color: #1890ff;
}
</style>