refactor(详情页): 优化代码结构并移除调试日志
移除多余的console.log调试语句 添加Tabs组件类型引用 调整滚动重置逻辑
This commit is contained in:
parent
cdc59df3db
commit
f543a7e858
|
|
@ -6,6 +6,7 @@ import { storeToRefs } from 'pinia'
|
||||||
import { toHttpsUrl } from '@/utils'
|
import { toHttpsUrl } from '@/utils'
|
||||||
// import { onLoad, onReachBottom, onShow } from '@dcloudio/uni-app'
|
// import { onLoad, onReachBottom, onShow } from '@dcloudio/uni-app'
|
||||||
import { getBorrowReturnDynamicApi, type BorrowReturnDynamicDTO, type SearchBorrowReturnDynamicQuery } from '@/api/order'
|
import { getBorrowReturnDynamicApi, type BorrowReturnDynamicDTO, type SearchBorrowReturnDynamicQuery } from '@/api/order'
|
||||||
|
import { TabsInstance } from 'wot-design-uni/components/wd-tabs/types'
|
||||||
|
|
||||||
// 定义组件接收的属性
|
// 定义组件接收的属性
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
|
|
@ -19,7 +20,9 @@ const emit = defineEmits<{
|
||||||
|
|
||||||
// 状态管理
|
// 状态管理
|
||||||
const cartStore = useCartStore()
|
const cartStore = useCartStore()
|
||||||
const { cartItems } = storeToRefs(cartStore)
|
const { cartItems } = storeToRefs(cartStore);
|
||||||
|
|
||||||
|
const tabsRef = ref<TabsInstance>();
|
||||||
|
|
||||||
// 购物车控制
|
// 购物车控制
|
||||||
const showAddCart = ref<boolean>(false)
|
const showAddCart = ref<boolean>(false)
|
||||||
|
|
@ -45,7 +48,6 @@ const scrollHeight = computed(() => {
|
||||||
const headerHeight = 60 // 顶部操作栏高度
|
const headerHeight = 60 // 顶部操作栏高度
|
||||||
const actionBarHeight = 64 // 底部操作栏高度
|
const actionBarHeight = 64 // 底部操作栏高度
|
||||||
const tabHeight = 44 // 标签栏高度
|
const tabHeight = 44 // 标签栏高度
|
||||||
console.log('scrollHeight', windowHeight, headerHeight, actionBarHeight, tabHeight)
|
|
||||||
return `${windowHeight - headerHeight - actionBarHeight - tabHeight}px`
|
return `${windowHeight - headerHeight - actionBarHeight - tabHeight}px`
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -103,8 +105,6 @@ function doShowAddCart(): boolean {
|
||||||
|
|
||||||
// 获取借还动态数据(带分页)
|
// 获取借还动态数据(带分页)
|
||||||
async function loadDynamicList(page: number = 1) {
|
async function loadDynamicList(page: number = 1) {
|
||||||
console.log('loadDynamicList', page)
|
|
||||||
console.log('props.product', props.product)
|
|
||||||
if (!props.product?.id) return
|
if (!props.product?.id) return
|
||||||
|
|
||||||
loading.value = true
|
loading.value = true
|
||||||
|
|
@ -118,7 +118,6 @@ async function loadDynamicList(page: number = 1) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await getBorrowReturnDynamicApi(query)
|
const response = await getBorrowReturnDynamicApi(query)
|
||||||
console.log('response', response)
|
|
||||||
|
|
||||||
if (response?.data?.rows) {
|
if (response?.data?.rows) {
|
||||||
if (page === 1) {
|
if (page === 1) {
|
||||||
|
|
@ -132,7 +131,6 @@ async function loadDynamicList(page: number = 1) {
|
||||||
pageNum.value = page
|
pageNum.value = page
|
||||||
|
|
||||||
// 判断是否已加载全部
|
// 判断是否已加载全部
|
||||||
console.log('dynamicList.value.length', dynamicList.value.length, 'total.value', total.value)
|
|
||||||
if (dynamicList.value.length >= total.value) {
|
if (dynamicList.value.length >= total.value) {
|
||||||
loadmoreState.value = 'finished'
|
loadmoreState.value = 'finished'
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -149,7 +147,6 @@ async function loadDynamicList(page: number = 1) {
|
||||||
|
|
||||||
// 加载更多数据
|
// 加载更多数据
|
||||||
function loadMoreData() {
|
function loadMoreData() {
|
||||||
console.log('loadMoreData', pageNum.value, loadmoreState.value, loading.value, dynamicList.value.length, total.value)
|
|
||||||
if (loadmoreState.value === 'finished' || loading.value) return
|
if (loadmoreState.value === 'finished' || loading.value) return
|
||||||
if (dynamicList.value.length >= total.value) {
|
if (dynamicList.value.length >= total.value) {
|
||||||
loadmoreState.value = 'finished'
|
loadmoreState.value = 'finished'
|
||||||
|
|
@ -160,7 +157,6 @@ function loadMoreData() {
|
||||||
|
|
||||||
// scroll-view 滚动到底部事件处理
|
// scroll-view 滚动到底部事件处理
|
||||||
function handleScrollToLower() {
|
function handleScrollToLower() {
|
||||||
console.log('handleScrollToLower', pageNum.value, loadmoreState.value, loading.value, dynamicList.value.length, total.value)
|
|
||||||
loadMoreData()
|
loadMoreData()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -178,15 +174,14 @@ const refreshDynamicList = () => {
|
||||||
loadDynamicList(1);
|
loadDynamicList(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
onShow(() => {
|
|
||||||
refreshDynamicList();
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
watch(() => props.product, () => {
|
watch(() => props.product, () => {
|
||||||
// 重置参数
|
// 重置参数
|
||||||
activeTab.value = 0;
|
// activeTab.value = 0;
|
||||||
|
wx.pageScrollTo({
|
||||||
|
scrollTop: 0,
|
||||||
|
duration: 300
|
||||||
|
});
|
||||||
|
tabsRef.value?.updateLineStyle(false);
|
||||||
quantity.value = 1;
|
quantity.value = 1;
|
||||||
showAddCart.value = false;
|
showAddCart.value = false;
|
||||||
refreshDynamicList();
|
refreshDynamicList();
|
||||||
|
|
@ -207,7 +202,7 @@ watch(() => props.product, () => {
|
||||||
<view class="content-area">
|
<view class="content-area">
|
||||||
<!-- 标签页内容 -->
|
<!-- 标签页内容 -->
|
||||||
<view class="tab-content">
|
<view class="tab-content">
|
||||||
<wd-tabs v-model="activeTab">
|
<wd-tabs v-model="activeTab" ref="tabsRef">
|
||||||
<!-- 标签1:商品信息 -->
|
<!-- 标签1:商品信息 -->
|
||||||
<wd-tab title="商品信息">
|
<wd-tab title="商品信息">
|
||||||
<!-- 商品主图 -->
|
<!-- 商品主图 -->
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue