Merge branch 'feature/task1.0.0_xg' into 'feature/task1.0.0'

feat: 首页秒杀tab显示根据是否有miao秒杀活动

See merge request yanxuan-frontend/shop-pc!39
merge-requests/40/head
肖广 3 years ago
commit 9ac2719a63

@ -19,7 +19,7 @@
<span>你好{{ userInfo.nickname }}</span> <span>你好{{ userInfo.nickname }}</span>
<img class="content-login-info__logo" :src="menuIcon" /> <img class="content-login-info__logo" :src="menuIcon" />
</div> </div>
<el-dropdown-menu slot="dropdown" class="dropdown-menu-self"> <el-dropdown-menu slot="dropdown" class="header-info-bar__dropdown">
<div class="menu-item__wrap flex flex-middle"> <div class="menu-item__wrap flex flex-middle">
<img class="menu-item-wrap__avatar" :src="userInfo.avatar" /> <img class="menu-item-wrap__avatar" :src="userInfo.avatar" />
<span>{{ userInfo.nickname }}</span> <span>{{ userInfo.nickname }}</span>
@ -52,7 +52,9 @@
> >
<img src="~/assets/img/layout/icon-message.png" /> <img src="~/assets/img/layout/icon-message.png" />
<span>消息</span> <span>消息</span>
<div class="wrap-content-message__tip">33</div> <div v-if="messageCount > 0" class="wrap-content-message__tip">
{{ messageCount }}
</div>
</div> </div>
</template> </template>
<div class="header-wrap-content--line"></div> <div class="header-wrap-content--line"></div>
@ -99,6 +101,7 @@ export default {
value: MENU_VALUE.LOGON_OUT, value: MENU_VALUE.LOGON_OUT,
}, },
], ],
messageCount: 0, //
}; };
}, },
computed: { computed: {
@ -137,7 +140,7 @@ export default {
}; };
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.dropdown-menu-self { .header-info-bar__dropdown {
width: 200px; width: 200px;
margin-top: 0 !important; margin-top: 0 !important;
padding-bottom: 0; padding-bottom: 0;
@ -164,6 +167,7 @@ export default {
height: 50px; height: 50px;
margin-right: 13px; margin-right: 13px;
border-radius: 50%; border-radius: 50%;
object-fit: cover;
} }
} }
.menu-item__line { .menu-item__line {

@ -15,7 +15,7 @@
<el-menu <el-menu
:default-active="tabPath" :default-active="tabPath"
mode="horizontal" mode="horizontal"
@select="handleTabSelect" @select="onTabSelect"
> >
<el-menu-item <el-menu-item
v-for="item in tabList" v-for="item in tabList"
@ -32,7 +32,7 @@
/> />
<div class="header-wrap-icons__shop" @click="$router.push('/cart')"> <div class="header-wrap-icons__shop" @click="$router.push('/cart')">
<img src="~/assets/img/layout/icon-shop-sticky.png" /> <img src="~/assets/img/layout/icon-shop-sticky.png" />
<span class="">3</span> <span v-if="cartCount > 0" class="">{{ cartCount }}</span>
</div> </div>
<div <div
v-if="token" v-if="token"
@ -66,6 +66,7 @@
<div class="search-input"> <div class="search-input">
<el-input <el-input
v-model="searchContent" v-model="searchContent"
clearable
placeholder="请输入商品名称" placeholder="请输入商品名称"
></el-input> ></el-input>
</div> </div>
@ -82,7 +83,9 @@
> >
<img src="~/assets/img/layout/icon-shop.png" /> <img src="~/assets/img/layout/icon-shop.png" />
<span>购物车</span> <span>购物车</span>
<div class="wrap-right-cart__tip">3</div> <div v-if="cartCount > 0" class="wrap-right-cart__tip">
{{ cartCount }}
</div>
</div> </div>
</div> </div>
</div> </div>
@ -154,7 +157,7 @@
'header-box-tab__common--light': 'header-box-tab__common--light':
item.value === $nuxt.$route.fullPath, item.value === $nuxt.$route.fullPath,
}" }"
@click="onTabSelect(item)" @click="onTabSelect(item.value)"
> >
{{ item.label }} {{ item.label }}
</div> </div>
@ -171,6 +174,7 @@ import {
ApiGetCategoryOneList, ApiGetCategoryOneList,
ApiGetCategoryTwoAndGoods, ApiGetCategoryTwoAndGoods,
} from "@/plugins/api/goods"; } from "@/plugins/api/goods";
import { ApiGetCartList } from "@/plugins/api/cart";
import { CATEGROY_LEVEL } from "@/constants"; import { CATEGROY_LEVEL } from "@/constants";
import HeaderInfoBar from "./HeaderInfoBar.vue"; import HeaderInfoBar from "./HeaderInfoBar.vue";
@ -213,25 +217,39 @@ export default {
CATEGROY_LEVEL, CATEGROY_LEVEL,
searchContent: "", searchContent: "",
tabPath: "/", tabPath: "/",
tabList: [
{ label: "首页", value: "/" },
{
label: "开发书籍",
value: `/goods/list?id=6&levelType=${CATEGROY_LEVEL.ONE}`,
},
{ label: "限时秒杀", value: "/seckill" },
],
categroyTwoVisible: false, // categroyTwoVisible: false, //
categroyVisible: false, // categroyVisible: false, //
currentCategroyId: 0, // id currentCategroyId: 0, // id
categroyData: [], categroyData: [],
cartCount: 0, //
}; };
}, },
computed: { computed: {
...mapState(["userInfo", "token"]), ...mapState(["userInfo", "token", "seckillTabVisible"]),
tabList() {
const defaultList = [
{ label: "首页", value: "/" },
{
label: "开发书籍",
value: `/goods/list?id=6&levelType=${CATEGROY_LEVEL.ONE}`,
},
];
if (this.seckillTabVisible) {
return [...defaultList, { label: "限时秒杀", value: "/seckill" }];
}
return defaultList;
},
},
watch: {
"$route.path"(val) {
if (val !== "/goods/list") {
this.searchContent = "";
}
},
}, },
mounted() { created() {
this.getCategroyData(); this.getCategroyData();
this.getCartInfo();
}, },
methods: { methods: {
onLoginClick() { onLoginClick() {
@ -264,11 +282,9 @@ export default {
handleCategoryTwoChange(val) { handleCategoryTwoChange(val) {
this.categroyTwoVisible = val; this.categroyTwoVisible = val;
}, },
handleTabSelect(value) { onTabSelect(value) {
this.$router.push({ path: value });
},
onTabSelect({ value }) {
this.tabPath = value; this.tabPath = value;
this.searchContent = "";
this.$router.push({ path: value }); this.$router.push({ path: value });
}, },
onJumpCart() { onJumpCart() {
@ -277,6 +293,14 @@ export default {
} }
this.$router.push("/cart"); this.$router.push("/cart");
}, },
//
async getCartInfo() {
const { result } = await ApiGetCartList();
if (result) {
this.cartCount = result.number;
}
},
// //
async getCategroyData() { async getCategroyData() {
const { result } = await ApiGetCategoryOneList(); const { result } = await ApiGetCategoryOneList();

@ -66,12 +66,18 @@ const NEW_COUNT = 5; // 新品上架商品数
export default { export default {
components: { Banner, Seckil, Pick, UiGoodsItem, UiPagination }, components: { Banner, Seckil, Pick, UiGoodsItem, UiPagination },
async asyncData() { async asyncData({ store }) {
// //
const { result: seckillData } = await ApiGetHomeSeckill(); let seckillData = { activityTimeVO: null };
//
let sekillGoodsList = []; let sekillGoodsList = [];
const { result: seckillDataResult } = await ApiGetHomeSeckill();
if (seckillData) {
seckillData = seckillDataResult;
}
if (seckillData.activityTimeVO) { if (seckillData.activityTimeVO) {
store.commit("setSeckillTabVisible", true);
//
const { result } = await ApiGetSeckillGoods({ const { result } = await ApiGetSeckillGoods({
pageIndex: 1, pageIndex: 1,
length: SECKILL_COUNT, length: SECKILL_COUNT,
@ -81,6 +87,7 @@ export default {
sekillGoodsList = result.records; sekillGoodsList = result.records;
} }
} }
// //
const { result: currentTime } = await ApiGetCurrentTime(); const { result: currentTime } = await ApiGetCurrentTime();
@ -101,7 +108,7 @@ export default {
currentTime, currentTime,
newData, newData,
sekillGoodsList, sekillGoodsList,
seckillData: seckillData || { activityTimeVO: null }, seckillData,
recommendData: recommendData || [], recommendData: recommendData || [],
}; };
}, },
@ -177,6 +184,9 @@ export default {
&:not(:nth-child(5n)) { &:not(:nth-child(5n)) {
margin-right: calc(5% / 4); margin-right: calc(5% / 4);
} }
img {
width: 100%;
}
} }
} }
} }

@ -239,6 +239,7 @@ export default {
this.seckillStatus === SECKILL_STATUS.GOING this.seckillStatus === SECKILL_STATUS.GOING
) { ) {
this.seckillEndVisible = true; this.seckillEndVisible = true;
this.$store.commit("setSeckillTabVisible", false);
return; return;
} }

@ -13,6 +13,7 @@ const state = () => ({
token: "", token: "",
userInfo: {}, userInfo: {},
loginVisible: false, // 是否展示登录弹窗 loginVisible: false, // 是否展示登录弹窗
seckillTabVisible: false, // 公共头是否展示秒杀tab
}); });
const mutations = { const mutations = {
setUserInfo(state, info) { setUserInfo(state, info) {
@ -33,6 +34,9 @@ const mutations = {
setLoginVisible(state, visible) { setLoginVisible(state, visible) {
state.loginVisible = visible; state.loginVisible = visible;
}, },
setSeckillTabVisible(state, visible) {
state.seckillTabVisible = visible;
},
}; };
const actions = { const actions = {
async nuxtServerInit({ state, commit, dispatch }) { async nuxtServerInit({ state, commit, dispatch }) {

Loading…
Cancel
Save