mirror of
http://git.coreshop.cn/jianweie/coreshoppro.git
synced 2026-03-22 20:37:21 +08:00
uniapp【优化】(商品分类模块):离开页面时sku关闭
This commit is contained in:
@@ -1,2 +1,5 @@
|
|||||||
/** 监听首页onshow需要的常量字段 */
|
/** 监听首页onshow需要的常量字段 */
|
||||||
export const onHomePageShow = "onHomePageShow";
|
export const onHomePageShow = "onHomePageShow";
|
||||||
|
|
||||||
|
/** 监听分类onHide需要的常量字段 */
|
||||||
|
export const onClassifyPageHide = "onClassifyPageHide";
|
||||||
@@ -124,8 +124,7 @@
|
|||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { reactive, watch, ref, onMounted, getCurrentInstance, nextTick } from 'vue';
|
import { reactive, watch, ref, onMounted, getCurrentInstance, nextTick } from 'vue';
|
||||||
import { onShow } from '@dcloudio/uni-app';
|
import { advertPosition, UserToken, onClassifyPageHide } from '@/core/consts';
|
||||||
import { advertPosition, UserToken } from '@/core/consts';
|
|
||||||
import { useLoginStore } from '@/core/store';
|
import { useLoginStore } from '@/core/store';
|
||||||
import { queryGoodsPageList, queryCartNumAndMoney, queryGoodsDetailByToken, queryGoodsDetail, queryAddCart } from '@/core/api';
|
import { queryGoodsPageList, queryCartNumAndMoney, queryGoodsDetailByToken, queryGoodsDetail, queryAddCart } from '@/core/api';
|
||||||
import type { CategoriesType, Response, GoodsListType, GoodsType } from '@/core/models';
|
import type { CategoriesType, Response, GoodsListType, GoodsType } from '@/core/models';
|
||||||
@@ -209,6 +208,14 @@
|
|||||||
})
|
})
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
if (uni.getStorageSync(UserToken)) {
|
||||||
|
getCartNumAndMoney();
|
||||||
|
}
|
||||||
|
|
||||||
|
uni.$on(onClassifyPageHide, () => {
|
||||||
|
state.showSku = false;
|
||||||
|
})
|
||||||
|
|
||||||
nextTick(async () => {
|
nextTick(async () => {
|
||||||
state.bigClassifyH = ((await getDomInfo('.big-classify', instance.proxy)) as { height : number }).height;
|
state.bigClassifyH = ((await getDomInfo('.big-classify', instance.proxy)) as { height : number }).height;
|
||||||
|
|
||||||
@@ -218,12 +225,6 @@
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
onShow(() => {
|
|
||||||
if (uni.getStorageSync(UserToken)) {
|
|
||||||
getCartNumAndMoney();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// 获取商品列表数据
|
// 获取商品列表数据
|
||||||
const getGoodsPageList = async () => {
|
const getGoodsPageList = async () => {
|
||||||
uni.showLoading({
|
uni.showLoading({
|
||||||
@@ -234,7 +235,7 @@
|
|||||||
limit: 10,
|
limit: 10,
|
||||||
where: `{"catId":${state.catId}}`
|
where: `{"catId":${state.catId}}`
|
||||||
});
|
});
|
||||||
if(goodsPageList.status){
|
if (goodsPageList.status) {
|
||||||
state.totalPages = goodsPageList.data?.totalPages;
|
state.totalPages = goodsPageList.data?.totalPages;
|
||||||
state.goodsList = state.goodsList.concat(goodsPageList.data?.list);
|
state.goodsList = state.goodsList.concat(goodsPageList.data?.list);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,7 +77,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { reactive, watch } from 'vue';
|
import { reactive, watch } from 'vue';
|
||||||
import { onShow } from '@dcloudio/uni-app';
|
import { onShow } from '@dcloudio/uni-app';
|
||||||
import { UserToken, advertPosition } from '@/core/consts';
|
import { UserToken, advertPosition, onClassifyPageHide } from '@/core/consts';
|
||||||
import { queryGoodsPageList, queryCartNumAndMoney, queryGoodsDetailByToken, queryGoodsDetail, queryAddCart } from '@/core/api';
|
import { queryGoodsPageList, queryCartNumAndMoney, queryGoodsDetailByToken, queryGoodsDetail, queryAddCart } from '@/core/api';
|
||||||
import type { CategoriesType, Response, GoodsListType, GoodsType } from '@/core/models';
|
import type { CategoriesType, Response, GoodsListType, GoodsType } from '@/core/models';
|
||||||
import { handleStaticResources, handleRouteNavigateTo, handleShowToast, handleRouteSwitchTab } from '@/core/utils';
|
import { handleStaticResources, handleRouteNavigateTo, handleShowToast, handleRouteSwitchTab } from '@/core/utils';
|
||||||
@@ -144,6 +144,10 @@
|
|||||||
if (uni.getStorageSync(UserToken)) {
|
if (uni.getStorageSync(UserToken)) {
|
||||||
getCartNumAndMoney();
|
getCartNumAndMoney();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uni.$on(onClassifyPageHide, () => {
|
||||||
|
state.showSku = false;
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
/** 获取商品列表数据 */
|
/** 获取商品列表数据 */
|
||||||
@@ -156,7 +160,7 @@
|
|||||||
limit: 10,
|
limit: 10,
|
||||||
where: `{"catId":${state.catId}}`
|
where: `{"catId":${state.catId}}`
|
||||||
});
|
});
|
||||||
if(goodsPageList.status){
|
if (goodsPageList.status) {
|
||||||
state.totalPages = goodsPageList.data?.totalPages;
|
state.totalPages = goodsPageList.data?.totalPages;
|
||||||
state.goodsList = state.goodsList.concat(goodsPageList.data?.list);
|
state.goodsList = state.goodsList.concat(goodsPageList.data?.list);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,8 @@
|
|||||||
:data="state.categoriesList" :height="state.height">
|
:data="state.categoriesList" :height="state.height">
|
||||||
</classifyFour>
|
</classifyFour>
|
||||||
<classifyFive v-else-if="shopConfigStore.config.cateStyle == GoodsListEnum.five"
|
<classifyFive v-else-if="shopConfigStore.config.cateStyle == GoodsListEnum.five"
|
||||||
:data="state.categoriesList" :height="state.height" :statusBarHeight="statusBarHeight"></classifyFive>
|
:data="state.categoriesList" :height="state.height" :statusBarHeight="statusBarHeight">
|
||||||
|
</classifyFive>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</coreshop-page>
|
</coreshop-page>
|
||||||
@@ -36,10 +37,12 @@
|
|||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { onMounted, reactive, nextTick } from 'vue';
|
import { onMounted, reactive, nextTick } from 'vue';
|
||||||
|
import { onHide } from '@dcloudio/uni-app';
|
||||||
import { useShopConfigStore } from '@/core/store';
|
import { useShopConfigStore } from '@/core/store';
|
||||||
import { queryAllCategories } from '@/core/api';
|
import { queryAllCategories } from '@/core/api';
|
||||||
import { GoodsListEnum } from '@/core/enum';
|
import { GoodsListEnum } from '@/core/enum';
|
||||||
import { handleRouteNavigateTo } from '@/core/utils';
|
import { handleRouteNavigateTo } from '@/core/utils';
|
||||||
|
import { onClassifyPageHide } from '@/core/consts';
|
||||||
import type { Response, ShopConfigStoreType, CategoriesType } from '@/core/models';
|
import type { Response, ShopConfigStoreType, CategoriesType } from '@/core/models';
|
||||||
import classifyOne from './classify-page/classify-one/classify-one.vue';
|
import classifyOne from './classify-page/classify-one/classify-one.vue';
|
||||||
import classifyTwo from './classify-page/classify-two/classify-two.vue';
|
import classifyTwo from './classify-page/classify-two/classify-two.vue';
|
||||||
@@ -72,6 +75,11 @@
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
onHide(() => {
|
||||||
|
/** 触发自定义onhide事件,让后代组件监听页面是关闭 */
|
||||||
|
uni.$emit(onClassifyPageHide);
|
||||||
|
});
|
||||||
|
|
||||||
/** 获取购物车数量价格 */
|
/** 获取购物车数量价格 */
|
||||||
const getAllCategories = async () => {
|
const getAllCategories = async () => {
|
||||||
const allCategories : Response<Array<CategoriesType>> = await queryAllCategories();
|
const allCategories : Response<Array<CategoriesType>> = await queryAllCategories();
|
||||||
|
|||||||
Reference in New Issue
Block a user