优化首页商品卡顿
This commit is contained in:
@@ -18,6 +18,7 @@
|
|||||||
"element-plus": "^2.4.3",
|
"element-plus": "^2.4.3",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"pinia": "^2.1.7",
|
"pinia": "^2.1.7",
|
||||||
|
"swiper": "^11.1.1",
|
||||||
"vue": "^3.3.8",
|
"vue": "^3.3.8",
|
||||||
"vue-router": "^4.2.5"
|
"vue-router": "^4.2.5"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -34,11 +34,13 @@
|
|||||||
@click="changeShopListType"></el-button>
|
@click="changeShopListType"></el-button>
|
||||||
</div>
|
</div>
|
||||||
<div class="shop_list" :class="{ img: shopListType == 'img' }" v-loading="loading">
|
<div class="shop_list" :class="{ img: shopListType == 'img' }" v-loading="loading">
|
||||||
<div class="item_wrap" v-for="item in goodsList" :key="item.id" @click="showSkuHandle(item)">
|
<swiper class="swiper_box" direction="vertical" @slideChange="onSlideChange">
|
||||||
|
<swiper-slide class="slide_item" v-for="(goods, index) in goodsList" :key="index">
|
||||||
|
<div class="item_wrap" v-for="item in goods" :key="item.id" @click="showSkuHandle(item)">
|
||||||
<div class="item">
|
<div class="item">
|
||||||
<div class="dot" v-if="item.orderCount">{{ item.orderCount }}</div>
|
<div class="dot" v-if="item.orderCount">{{ item.orderCount }}</div>
|
||||||
<div class="cover" v-if="shopListType == 'img'">
|
<div class="cover" v-if="shopListType == 'img'">
|
||||||
<el-image :src="item.coverImg" class="el_img" fit="cover" lazy></el-image>
|
<el-image :src="item.coverImg" class="el_img" fit="cover"></el-image>
|
||||||
</div>
|
</div>
|
||||||
<div class="name"><el-text line-clamp="2">{{ item.name }}</el-text></div>
|
<div class="name"><el-text line-clamp="2">{{ item.name }}</el-text></div>
|
||||||
<div class="item_empty" v-if="shopListType == 'text'"></div>
|
<div class="item_empty" v-if="shopListType == 'text'"></div>
|
||||||
@@ -47,6 +49,8 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</swiper-slide>
|
||||||
|
</swiper>
|
||||||
</div>
|
</div>
|
||||||
<div class="empty">
|
<div class="empty">
|
||||||
<el-empty description="空空如也~" v-if="!goodsList.length" />
|
<el-empty description="空空如也~" v-if="!goodsList.length" />
|
||||||
@@ -64,6 +68,11 @@ import skuModal from '@/components/skuModal.vue'
|
|||||||
|
|
||||||
import { queryCategory, productqueryCommodityInfo, queryProductSku } from '@/api/product'
|
import { queryCategory, productqueryCommodityInfo, queryProductSku } from '@/api/product'
|
||||||
import { useUser } from "@/store/user.js"
|
import { useUser } from "@/store/user.js"
|
||||||
|
|
||||||
|
import { Swiper, SwiperSlide } from 'swiper/vue'
|
||||||
|
import "swiper/swiper-bundle.css";
|
||||||
|
|
||||||
|
|
||||||
const store = useUser()
|
const store = useUser()
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
@@ -77,7 +86,7 @@ const emit = defineEmits(['success'])
|
|||||||
|
|
||||||
const skuModalRef = ref(null)
|
const skuModalRef = ref(null)
|
||||||
|
|
||||||
const shopListType = ref('text')
|
const shopListType = ref('img')
|
||||||
|
|
||||||
const categorys = ref([])
|
const categorys = ref([])
|
||||||
const categorysActive = ref(0)
|
const categorysActive = ref(0)
|
||||||
@@ -86,11 +95,24 @@ const commdityName = ref('')
|
|||||||
|
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
const goodsList = ref([])
|
const goodsList = ref([])
|
||||||
|
const goodsPage = ref(1)
|
||||||
|
const goodsPageSize = ref(12)
|
||||||
|
const finish = ref(false) // 是否加载完
|
||||||
|
const currentGoodsIndex = ref(0)
|
||||||
|
const loopMax = ref(0)
|
||||||
|
const loopTimer = ref(null)
|
||||||
|
|
||||||
const showPopover = ref(false)
|
const showPopover = ref(false)
|
||||||
|
|
||||||
const inputChange = _.debounce(function () {
|
const inputChange = _.debounce(function () {
|
||||||
productqueryCommodityInfoAjax()
|
goodsList.value = []
|
||||||
|
goodsPage.value = 1
|
||||||
|
finish.value = false
|
||||||
|
currentGoodsIndex.value = 0
|
||||||
|
loopMax.value = 0
|
||||||
|
loopTimer.value = null
|
||||||
|
|
||||||
|
updataGoods()
|
||||||
}, 500)
|
}, 500)
|
||||||
|
|
||||||
// 确认选择规格回调
|
// 确认选择规格回调
|
||||||
@@ -156,7 +178,14 @@ function changeCategory(index) {
|
|||||||
|
|
||||||
useStorage.set('categorysActive', index)
|
useStorage.set('categorysActive', index)
|
||||||
|
|
||||||
productqueryCommodityInfoAjax()
|
goodsList.value = []
|
||||||
|
goodsPage.value = 1
|
||||||
|
finish.value = false
|
||||||
|
currentGoodsIndex.value = 0
|
||||||
|
loopMax.value = 0
|
||||||
|
loopTimer.value = null
|
||||||
|
|
||||||
|
updataGoods()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 从本地更新已选择的选项
|
// 从本地更新已选择的选项
|
||||||
@@ -191,37 +220,104 @@ async function queryCategoryAjax() {
|
|||||||
// 查询商品信息
|
// 查询商品信息
|
||||||
async function productqueryCommodityInfoAjax() {
|
async function productqueryCommodityInfoAjax() {
|
||||||
try {
|
try {
|
||||||
loading.value = true
|
// loading.value = true
|
||||||
const res = await productqueryCommodityInfo({
|
const res = await productqueryCommodityInfo({
|
||||||
shopId: store.userInfo.shopId,
|
shopId: store.userInfo.shopId,
|
||||||
categoryId: categorys.value[categorysActive.value].id,
|
categoryId: categorys.value[categorysActive.value].id,
|
||||||
commdityName: commdityName.value,
|
commdityName: commdityName.value,
|
||||||
page: 1,
|
page: goodsPage.value,
|
||||||
pageSize: 500,
|
pageSize: goodsPageSize.value,
|
||||||
masterId: props.masterId
|
masterId: props.masterId
|
||||||
})
|
})
|
||||||
goodsList.value = res
|
if (res.list.length < goodsPageSize.value) {
|
||||||
loading.value = false
|
finish.value = true
|
||||||
|
}
|
||||||
|
// loading.value = false
|
||||||
|
|
||||||
|
if (res.total > (goodsPageSize.value * 2)) {
|
||||||
|
// 启动循环任务
|
||||||
|
loopMax.value = parseInt(res.total / goodsPageSize.value)
|
||||||
|
loopGetGoods()
|
||||||
|
}
|
||||||
|
return res.list
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
loading.value = false
|
loading.value = false
|
||||||
console.log(error)
|
console.log(error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 循环获取商品
|
||||||
|
function loopGetGoods() {
|
||||||
|
loopTimer.value = setInterval(async () => {
|
||||||
|
goodsPage.value++
|
||||||
|
if (goodsPage.value > loopMax.value) {
|
||||||
|
clearInterval(loopTimer.value)
|
||||||
|
loopTimer.value = null
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const res = await productqueryCommodityInfoAjax()
|
||||||
|
goodsList.value.push(res)
|
||||||
|
}, 2000)
|
||||||
|
}
|
||||||
|
|
||||||
// 更新商品数据
|
// 更新商品数据
|
||||||
async function updateData() {
|
async function updateData() {
|
||||||
localUpdateShopListType()
|
localUpdateShopListType()
|
||||||
await updateCategoryActive()
|
await updateCategoryActive()
|
||||||
await queryCategoryAjax()
|
await queryCategoryAjax()
|
||||||
await productqueryCommodityInfoAjax()
|
updataGoods()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function updataGoods() {
|
||||||
|
if (!goodsList.value.length) {
|
||||||
|
const res = await productqueryCommodityInfoAjax()
|
||||||
|
goodsList.value.push(res)
|
||||||
|
|
||||||
|
if (res.length >= goodsPageSize.value) {
|
||||||
|
goodsPage.value++
|
||||||
|
const res2 = await productqueryCommodityInfoAjax()
|
||||||
|
goodsList.value.push(res2)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
goodsPage.value = currentGoodsIndex.value + 1
|
||||||
|
goodsList.value[currentGoodsIndex.value] = await productqueryCommodityInfoAjax()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 轮播图开始滑动
|
||||||
|
const onSlideChange = _.debounce(async function (e) {
|
||||||
|
if (e.activeIndex == e.previousIndex || finish.value) return
|
||||||
|
if (e.activeIndex > e.previousIndex) {
|
||||||
|
// console.log('向下滑动');
|
||||||
|
goodsPage.value++
|
||||||
|
const res = await productqueryCommodityInfoAjax()
|
||||||
|
goodsList.value.push(res)
|
||||||
|
// goodsList.value.shift()
|
||||||
|
} else {
|
||||||
|
// console.log('向上滑动');
|
||||||
|
// goodsPage.value--
|
||||||
|
// const res = await productqueryCommodityInfoAjax()
|
||||||
|
// goodsList.value.unshift(res)
|
||||||
|
// goodsList.value.pop()
|
||||||
|
}
|
||||||
|
currentGoodsIndex.value = e.activeIndex
|
||||||
|
}, 500)
|
||||||
|
|
||||||
defineExpose({
|
defineExpose({
|
||||||
updateData
|
updateData
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped lang="scss">
|
<style scoped lang="scss">
|
||||||
|
.swiper_box {
|
||||||
|
height: 100%;
|
||||||
|
|
||||||
|
.slide_item {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.loading_wrap {
|
.loading_wrap {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
@@ -325,10 +421,11 @@ defineExpose({
|
|||||||
}
|
}
|
||||||
|
|
||||||
.shop_list {
|
.shop_list {
|
||||||
max-height: calc(100vh - 40px - 80px - 40px);
|
// max-height: calc(100vh - 40px - 80px - 40px);
|
||||||
overflow-y: auto;
|
height: calc(100vh - 40px - 80px - 28px);
|
||||||
display: flex;
|
// overflow-y: auto;
|
||||||
flex-wrap: wrap;
|
// display: flex;
|
||||||
|
// flex-wrap: wrap;
|
||||||
padding: 0 10px;
|
padding: 0 10px;
|
||||||
|
|
||||||
&.img {
|
&.img {
|
||||||
@@ -338,11 +435,14 @@ defineExpose({
|
|||||||
}
|
}
|
||||||
|
|
||||||
.item_wrap {
|
.item_wrap {
|
||||||
|
float: left;
|
||||||
width: 20%;
|
width: 20%;
|
||||||
|
height: 33.333%;
|
||||||
padding: 0 5px;
|
padding: 0 5px;
|
||||||
padding-bottom: 10px;
|
padding-bottom: 10px;
|
||||||
|
|
||||||
.item {
|
.item {
|
||||||
|
height: 100%;
|
||||||
border: 1px solid #ececec;
|
border: 1px solid #ececec;
|
||||||
border-radius: 10px;
|
border-radius: 10px;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
@@ -366,7 +466,7 @@ defineExpose({
|
|||||||
|
|
||||||
.cover {
|
.cover {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
padding-bottom: 100%;
|
height: 60%;
|
||||||
position: relative;
|
position: relative;
|
||||||
|
|
||||||
.el_img {
|
.el_img {
|
||||||
@@ -381,8 +481,10 @@ defineExpose({
|
|||||||
|
|
||||||
.name {
|
.name {
|
||||||
padding: 0 10px;
|
padding: 0 10px;
|
||||||
height: 40px;
|
height: 20%;
|
||||||
margin-top: 20px;
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
// margin-top: 20px;
|
||||||
|
|
||||||
span {
|
span {
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
@@ -394,6 +496,7 @@ defineExpose({
|
|||||||
}
|
}
|
||||||
|
|
||||||
.price {
|
.price {
|
||||||
|
height: 20%;
|
||||||
padding: 6px 10px;
|
padding: 6px 10px;
|
||||||
background-color: var(--primary-color);
|
background-color: var(--primary-color);
|
||||||
|
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ export default defineConfig({
|
|||||||
server: {
|
server: {
|
||||||
proxy: {
|
proxy: {
|
||||||
'/api': {
|
'/api': {
|
||||||
target: 'https://cashierclient.sxczgkj.cn/cashier-client', // 线上
|
// target: 'https://cashierclient.sxczgkj.cn/cashier-client', // 线上
|
||||||
// target: 'http://192.168.2.27:10587/cashier-client', // 国成
|
target: 'http://192.168.2.116:10587/cashier-client', // 国成
|
||||||
// target: 'http://192.168.2.128:10587/cashier-client',
|
// target: 'http://192.168.2.128:10587/cashier-client',
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
rewrite: (path) => path.replace(/^\/api/, '')
|
rewrite: (path) => path.replace(/^\/api/, '')
|
||||||
|
|||||||
Reference in New Issue
Block a user