Merge branch 'feature/task1.0.0' into feature/task1.0.0-0505-ch

merge-requests/11/head
ch 2 years ago
commit bc1c7b76aa

@ -0,0 +1,2 @@
registry=https://registry.npm.taobao.org/
sass_binary_site="https://npm.taobao.org/mirrors/node-sass"

@ -0,0 +1,12 @@
FROM node:12.13.1
WORKDIR /workload
COPY nuxt.config.js /workload/nuxt.config.js
COPY package.json /workload/package.json
COPY .nuxt /workload/.nuxt
RUN npm config set registry https://registry.npm.taobao.org \
&& npm install
EXPOSE 3000
CMD npm run start

@ -101,6 +101,27 @@ export {
@include adj(transform, translate3d(-50%, 0, 0));
}
```
## 登录相关
```javascript
// 访问token
this.$store.state.token
// 设置token
this.$store.commit('setToken')
// 退出登录
this.$store.commit('setLoginOut')
// 获取登录的用户信息
this.$store.state.userInfo
// 登录拦截
// 示例:点击购买课程前需要判断当前用户是否登录
function onPurchaseCourse() {
if (!this.$isLoginValidate()) {
return;
}
// 此处省略其他业务代码...
}
```

@ -35,3 +35,7 @@ a { text-decoration:none;
color: #333;
&:hover { text-decoration:none;}
}
.layout-box {
width: 1200px;
margin: 0 auto;
}

@ -0,0 +1,259 @@
<template>
<div class="bs-login">
<el-dialog
:visible.sync="dialogTableVisible"
:show-close="false"
:close-on-click-modal="false"
:close-on-press-escape="false"
width="20%"
>
<div class="bs-login-wrap">
<img
class="bs-login-wrap__logo"
src="@/static/images/login/icon-logo.png"
/>
<div class="bs-login-wrap__content">
<el-form :model="form" :rules="rules" ref="ruleForm">
<el-form-item prop="phone">
<el-input
v-model="form.phone"
placeholder="请输入手机号"
></el-input>
</el-form-item>
<el-form-item prop="verificationCode">
<el-input
class="input-code"
v-model="form.verificationCode"
placeholder="请输入密码"
>
<el-button slot="suffix" type="text" @click="onSendCode">
{{ codeValue }}
</el-button>
</el-input>
</el-form-item>
<el-button class="login-wrap-content__login-btn" @click="onLogin"
>登录</el-button
>
</el-form>
<div class="login-wrap-content__agreement flex felx-start">
<div
class="wrap-content-agreement-icons"
@click="onAgreementSelect"
>
<img
v-if="isAcceptAgreement"
class="icon-choose"
src="@/static/images/login/icon-accept.png"
/>
<span v-else class="icon-unchoose"></span>
</div>
<span class="wrap-content-agreement__text flex-1">
同意用户协议隐私协议首次 登陆将自动注册
</span>
</div>
</div>
<div class="bs-login-wrap__btn--close" @click="onClose">
<img src="@/static/images/login/icon-close.png" />
</div>
</div>
</el-dialog>
</div>
</template>
<script>
import { mapState } from "vuex";
import { Message } from "element-ui";
import { ApiGetCode, ApiPostLogin } from "@/plugins/api/account";
import { IsPhone } from "/plugins/utils";
const COUNT_DOWN_TIME = 60; //
export default {
name: "BsLogin",
props: {
visible: {
type: Boolean,
default: false,
},
},
data() {
const validatorPhone = (_, value, callback) => {
if (!value) {
return callback(new Error("手机号不能为空"));
}
if (!IsPhone(value)) {
return callback(new Error("请输入正确的手机号"));
}
return callback();
};
return {
form: {
phone: "",
verificationCode: "",
},
isAcceptAgreement: false, //
countDown: 0, //
rules: {
phone: [{ validator: validatorPhone, trigger: "blur" }],
verificationCode: [
{ required: true, message: "请输入验证码", trigger: "change" },
],
},
};
},
computed: {
...mapState(["token"]),
dialogTableVisible: {
get() {
return this.visible;
},
set(val) {
this.$emit("update:visible", val);
},
},
codeValue() {
return this.countDown ? `${this.countDown}s重新获取` : "获取验证码";
},
},
methods: {
onAgreementSelect() {
this.isAcceptAgreement = !this.isAcceptAgreement;
},
async onSendCode() {
if (this.countDown > 0 || !IsPhone(this.form.phone)) {
return;
}
this.countDown = COUNT_DOWN_TIME;
let time;
const { result, error } = await ApiGetCode({
phone: this.form.phone,
});
if (result) {
time = setInterval(() => {
if (this.countDown === 0) {
clearInterval(time);
return;
}
this.countDown -= 1;
}, 1e3);
return;
}
this.countDown = 0;
clearInterval(time);
Message.error(error.message || "验证码发送失败,请检查手机号是否正确");
},
onLogin() {
this.$refs.ruleForm.validate(async (valid) => {
if (valid) {
if (!this.isAcceptAgreement) {
Message.error("请勾选同意《用户协议》和《隐私协议》");
return;
}
const { result } = await ApiPostLogin({
...this.form,
clientId: 1,
systemId: 1,
});
if (result) {
this.dialogTableVisible = false;
this.$store.commit("setToken", result.token);
this.$store.dispatch("getUserInfo");
}
}
});
},
onClose() {
this.dialogTableVisible = false;
},
},
};
</script>
<style lang="scss" scoped>
.bs-login {
/deep/.el-dialog {
border-radius: 4px;
.el-dialog__header {
display: none;
}
.el-dialog__body {
padding: 38px 30px;
}
.bs-login-wrap {
.bs-login-wrap__logo {
width: 198px;
height: 32px;
margin-bottom: 44px;
}
.bs-login-wrap__content {
.el-form {
.el-form-item {
margin-bottom: 24px;
.input-code {
.el-input__inner {
padding-right: 100px;
}
}
.el-input {
.el-input__suffix {
padding-right: 16px;
.el-button {
color: #ff512b;
}
}
.el-input__inner {
border-style: none;
background: #f8f8f8;
border-radius: 4px 4px 4px 4px;
}
}
}
.login-wrap-content__login-btn {
width: 100%;
height: 42px;
border-style: none;
color: #ffffff;
font-size: 16px;
margin-top: 14px;
background: linear-gradient(270deg, #ffa25a 0%, #ff7f39 100%);
border-radius: 4px 4px 4px 4px;
}
}
.login-wrap-content__agreement {
padding: 0 33px;
color: #999999;
font-size: 12px;
margin-top: 25px;
.wrap-content-agreement-icons {
cursor: pointer;
.icon-unchoose {
display: block;
width: 16px;
height: 16px;
border: 1px solid #cccccc;
border-radius: 50%;
}
.icon-choose {
width: 16px;
height: 16px;
}
}
.wrap-content-agreement__text {
display: block;
text-align: center;
margin-left: 8px;
}
}
}
.bs-login-wrap__btn--close {
position: absolute;
left: 50%;
transform: translate(-50%, 0);
bottom: -60px;
cursor: pointer;
img {
width: 30px;
height: 30px;
}
}
}
}
}
</style>

@ -0,0 +1,8 @@
/**
* 全局常量请避免使用魔法数字
*/
const TOKEN_KEY = 'msbPcToken';
export {
TOKEN_KEY
}

@ -0,0 +1,54 @@
kind: Deployment
apiVersion: apps/v1
metadata:
labels:
app: $IMAGES
name: $IMAGES
namespace: yanxuan
spec:
progressDeadlineSeconds: 600
replicas: 1
selector:
matchLabels:
app: $IMAGES
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 25%
maxSurge: 25%
template:
metadata:
labels:
app: $IMAGES
spec:
imagePullSecrets:
- name: aliyun-docker-hub
containers:
- image: '$REGISTRY/$DOCKERHUB_NAMESPACE/$IMAGES:$BUILD_NUMBER'
name: app
ports:
- containerPort: $JAR_PORD
protocol: TCP
resources:
limits:
cpu: '0.5'
memory: 500Mi
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
dnsPolicy: ClusterFirst
restartPolicy: Always
terminationGracePeriodSeconds: 30
---
kind: Service
apiVersion: v1
metadata:
name: $IMAGES
namespace: yanxuan
spec:
ports:
- port: 3000
protocol: TCP
targetPort: 3000
selector:
app: $IMAGES
type: ClusterIP

@ -7,26 +7,34 @@
-->
<template>
<div class="layout">
<BsLogin :visible.sync="loginVisible" />
<Header />
<div class="layout-box"><Nuxt /></div>
<Nuxt />
<Footer />
</div>
</template>
<script>
import BsLogin from "@/components/BsLogin.vue";
import Header from "./module/header/index.vue";
import Footer from "./module/footer/index.vue";
export default {
name: "Layout",
components: { Header, Footer },
components: { Header, Footer, BsLogin },
computed: {
loginVisible: {
get() {
return this.$store.state.loginVisible;
},
set(val) {
this.$store.commit("setLoginVisible", val);
},
},
},
};
</script>
<style lang="scss" scoped>
.layout-box {
width: 1200px;
margin: 0 auto;
}
.layout-footer{
.layout-footer {
height: 189px;
background: #ddd;
}

@ -21,6 +21,7 @@
</template>
<script>
export default {
name: "LayoutFooter",
data() {
return {
promiseList: [

@ -6,33 +6,42 @@
<div class="header-wrap__logo">马士兵严选欢迎你</div>
<div class="header-wrap__content flex flex-middle">
<div class="header-wrap-content__login">
<el-dropdown v-if="isLogin" @visible-change="menuVisible = $event">
<!-- 已登录 -->
<el-dropdown
v-if="token"
@visible-change="menuVisible = $event"
@command="handleCommandClick"
>
<div
class="wrap-content-login__info flex flex-middle flex-center"
:class="{ 'wrap-content-login__info--hover': menuVisible }"
>
<span>你好{{ userInfo.name }}</span>
<span>你好{{ userInfo.nickname }}</span>
<img class="content-login-info__logo" :src="menuIcon" />
</div>
<el-dropdown-menu slot="dropdown" class="dropdown-menu-self">
<div class="menu-item__wrap flex flex-middle">
<img class="menu-item-wrap__avatar" />
<span>{{ userInfo.name }}</span>
<img class="menu-item-wrap__avatar" :src="userInfo.avatar" />
<span>{{ userInfo.nickname }}</span>
</div>
<div class="menu-item__line"></div>
<el-dropdown-item
class="flex flex-between flex-middle"
v-for="item in menuList"
:key="item.value"
:command="item.value"
>
<span> {{ item.label }}</span>
<img src="@/static/images/layout/icon-arrow.png" />
</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
<!-- 未登录 -->
<div v-else class="wrap-content-login__text flex">
<span>请先</span>
<span class="content-login-text--light">登录/注册</span>
<span class="content-login-text--light" @click="onLoginClick">
登录/注册
</span>
</div>
</div>
<template>
@ -58,6 +67,7 @@
</div>
</template>
<script>
import { mapState } from "vuex";
const MENU_VALUE = {
PERSONAL: 1,
ADDRESS: 2,
@ -65,12 +75,9 @@ const MENU_VALUE = {
};
export default {
name: "HeaderInfoBar",
data() {
return {
isLogin: true,
userInfo: {
name: "仙女广",
},
menuVisible: false,
menuList: [
{
@ -89,6 +96,7 @@ export default {
};
},
computed: {
...mapState(["userInfo", "token"]),
menuIcon() {
return this.menuVisible
? require("@/static/images/layout/icon-up-light.png")
@ -96,7 +104,19 @@ export default {
},
},
methods: {
onMenuClick() {},
onLoginClick() {
this.$isLoginValidate();
},
handleCommandClick(event) {
switch (event) {
case MENU_VALUE.PERSONAL:
this.$router.push('/account');
case MENU_VALUE.ADDRESS:
this.$router.push('/account');
case MENU_VALUE.LOGON_OUT:
this.$store.commit("setLoginOut");
}
},
},
};
</script>

@ -81,7 +81,7 @@
</div>
<div
v-show="categrayHoverVisible"
class="tab-category-menu__right flex flex-wrap"
class="tab-category-menu__right"
@mouseenter="categrayHoverVisible = true"
@mouseleave="categrayHoverVisible = false"
>
@ -169,16 +169,16 @@ export default {
//
async getCategroyData() {
const { result } = await ApiGetCategoryOneList();
if (result.data.length > 0) {
if (result && result.length > 0) {
this.categrayData = await Promise.all(
result.data.map(async (item) => {
const { result } = await ApiGetCategoryTwoAndGoods({
result.map(async (item) => {
const { result: resultGoods } = await ApiGetCategoryTwoAndGoods({
categoryId: item.id,
});
if (result.data.length > 0) {
if (resultGoods && resultGoods.length > 0) {
return {
...item,
list: result.data,
list: resultGoods,
};
}
})
@ -291,6 +291,7 @@ export default {
background: linear-gradient(270deg, #ffa25a 0%, #ff7f39 100%);
border-radius: 0px 8px 8px 0px;
z-index: 2;
cursor: pointer;
img {
width: 26px;
height: 26px;
@ -373,13 +374,11 @@ export default {
box-shadow: 7px 0px 10px 1px rgba(0, 0, 0, 0.10000000149011612);
border: 1px solid #eeeeee;
background: #ffffff;
.menu-right__item:last-child {
margin-bottom: 0;
}
.menu-right__item:hover {
color: #ff875b;
}
.menu-right__item {
display: inline-block;
font-size: 12px;
color: #999999;
margin-right: 20px;

@ -42,8 +42,8 @@ export default {
plugins: [
'@/plugins/element-ui',
'@/plugins/axios',
{ src: '@plugins/axiosTk.js', ssr: false },
{ src: '@plugins/storeStorage.js', ssr: false },
'@plugins/axiosTk.js',
'@plugins/vue-inject.js'
],
// Auto import components: https://go.nuxtjs.dev/config-components
@ -55,7 +55,8 @@ export default {
// Modules: https://go.nuxtjs.dev/config-modules
modules: [
'@nuxtjs/axios'
'@nuxtjs/axios',
'cookie-universal-nuxt'
],
// Build Configuration: https://go.nuxtjs.dev/config-build

16097
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -15,6 +15,7 @@
},
"dependencies": {
"@nuxtjs/axios": "^5.13.6",
"cookie-universal-nuxt": "^2.1.5",
"core-js": "^3.19.3",
"element-ui": "^2.15.8",
"js-util-all": "^1.0.6",

@ -1,23 +1,198 @@
<!--
* @Author: ch
* @Date: 2022-05-04 17:29:09
* @LastEditors: ch
* @LastEditTime: 2022-05-04 17:29:24
* @Description: file content
-->
<template>
<div>我是商品详情</div>
<div>
<nav class="nav flex flex-middle flex-center">
<p class="nav__crumbs">
全部商品
<i class="el-icon-arrow-right"></i>
开发书籍
<i class="el-icon-arrow-right"></i>
后端书籍
<i class="el-icon-arrow-right"></i>
Java从入门到项目实战
</p>
</nav>
<main class="main flex">
<aside class="main__preview">
<img class="main__preview" src="~/static/images/goods/more.png" alt="商品大图" />
</aside>
<article class="main__details">
<p class="main__details-title">
<span class="main__details-title--label">新品</span>
Java从入门到项目实战全程视频版
编程入门it计算机书籍算法java编程思想java从入门到精通java核心技术javascript
</p>
<div class="main__details-msg">
<div class="main__details-msg--price flex">
<span class="msg-txt">售价</span>
<UiMoney :money="123"></UiMoney>
</div>
<div class="hr"></div>
<div class="main__details-msg--service flex flex-middle">
<span class="msg-txt">服务</span>
<span class="msg-service"
>假一赔四 · 全国包邮 · 不支持7天无理由退换</span
>
<img
class="msg-icon"
src="~/static/images/goods/more.png"
alt="服务"
/>
</div>
</div>
<div class="main__details-option">
<div class="main__details-option--line flex flex-middle">
<span class="line-txt">规格</span>
<div class="line-btns">
<UiButton
type="yellow_line"
v-for="(item, index) in 11"
:key="index"
>123</UiButton
>
</div>
</div>
</div>
<div class="main__details-pay">
<UiButton type="yellow_line">加入购物车</UiButton>
<UiButton type="yellow_panel">立即购买</UiButton>
</div>
</article>
</main>
</div>
</template>
<script>
import UiMoney from "@/components/UiMoney.vue";
import UiButton from "@/components/UiButton.vue";
import { ApiGetGoodsDetail, ApiGetGoodsSkus } from "@/plugins/api/goods";
export default {
data(){
return {
}
}
}
componetns: { UiMoney, UiButton },
data() {
return {};
},
async created() {
let id = this.$route.params.id;
let res1 = await ApiGetGoodsDetail({ id });
let res2 = await ApiGetGoodsSkus({ productId: id });
console.log(`res1`, res1.result);
console.log(`res2`, res2.result);
},
};
</script>
<style lang="scss" scoped>
.nav {
width: 100%;
height: 40px;
background: #f2f4f6;
margin-bottom: 14px;
&__crumbs {
width: 1200px;
}
}
.main {
width: 1200px;
margin: 0 auto;
&__preview {
width: 456px;
margin-right: 30px;
}
&__details {
width: 714px;
&-title {
font-size: 16px;
font-family: Microsoft YaHei-Regular, Microsoft YaHei;
font-weight: 400;
color: #333333;
padding-bottom: 20px;
&--label {
display: inline-block;
font-size: 12px;
font-family: Microsoft YaHei-Regular, Microsoft YaHei;
font-weight: 400;
color: #3083ff;
padding: 4px 8px;
margin-right: 6px;
background: rgba(48, 131, 255, 0.1);
}
}
&-msg {
width: 714px;
height: 127px;
background: #f8f8f8;
padding: 30px 20px 0;
.msg-txt {
font-size: 14px;
font-family: Microsoft YaHei-Regular, Microsoft YaHei;
font-weight: 400;
color: #9e9e9e;
margin-right: 20px;
}
</style>
.msg-service {
font-size: 14px;
font-family: Microsoft YaHei-Regular, Microsoft YaHei;
font-weight: 400;
color: #666666;
}
.msg-icon {
margin-left: 6px;
width: 12px;
height: 12px;
}
&--price {
padding-bottom: 30px;
}
.hr {
width: 673px;
height: 1px;
background: #dddddd;
}
&--service {
padding-top: 16px;
}
}
&-option {
padding-top: 24px;
&--line {
margin-bottom: 6px;
.line-txt {
font-size: 14px;
font-family: Microsoft YaHei-Regular, Microsoft YaHei;
font-weight: 400;
color: #9e9e9e;
margin-left: 20px;
margin-right: 33px;
}
.line-btns {
width: 600px;
/deep/.ui-button__yellow_line {
background: #fff;
margin-right: 14px;
color: #666;
margin-bottom: 6px;
border-color: #ccc;
}
}
}
}
&-pay {
margin-top: 40px;
button {
width: 144px;
height: 46px;
margin-right: 30px;
font-size: 18px;
&:nth-child(1) {
background: #fff;
}
&:nth-child(2) {
border: none;
}
}
}
}
}
</style>

@ -7,17 +7,210 @@
-->
<template>
<div>我是商品列表</div>
<div class="page">
<main class="main">
<nav class="main__nav">
<p class="main__nav-crumbs">
全部商品<i class="el-icon-arrow-right"></i>开发书籍
</p>
<div class="main__nav-sort flex flex-middle">
<span class="main__nav-sort-txt">排序 :</span>
<span
class="main__nav-sort-btn"
:class="navActive == 0 ? 'main__nav-sort-active' : ''"
@click="onNavClick(0)"
>综合</span
>
<Sort
:class="navActive == 1 ? 'main__nav-sort-active' : ''"
sortText="价格"
:sortType="sortType"
@onSort="onSort"
></Sort>
<span
:class="navActive == 3 ? 'main__nav-sort-active' : ''"
class="main__nav-sort-btn"
@click="onNavClick(3)"
>上新</span
>
</div>
</nav>
<div class="main__content">
<GoodsItem
:item="item"
v-for="item in listData"
:key="item.id"
></GoodsItem>
</div>
<el-pagination
class="main__pagination flex flex-right"
@current-change="handleCurrentChange"
:current-page.sync="params.pageIndex"
:page-size="100"
layout="prev, pager, next, jumper"
:total="total"
>
</el-pagination>
</main>
</div>
</template>
<script>
import { ApiGetGoodsList } from "@/plugins/api/goods";
import Sort from "./module/SortItem.vue";
import GoodsItem from "./module/Item.vue";
export default {
data(){
return {
}
}
}
components: { Sort, GoodsItem },
data() {
return {
navActive: 0,
listData: [],
total: 0,
// 0:,1:desc,2:asc,3:
sortType: 0,
params: {
length: 20,
pageIndex: 1,
name: "",
categoryId: "",
order: "",
},
};
},
async created() {
this.getGoodsListData();
},
methods: {
onNavClick(i) {
console.log(i);
let vm = this;
vm.sortType = i;
vm.navActive = i;
vm.getGoodsListData();
},
onSort() {
let vm = this;
vm.navActive = 1;
vm.sortType < 2 ? vm.sortType++ : (vm.sortType = 1);
vm.getGoodsListData();
},
//
async getGoodsListData() {
let vm = this;
switch (vm.sortType) {
case 0:
vm.$set(vm.params, "order", "");
break;
case 1:
vm.$set(vm.params, "order", "starting_price:desc");
break;
case 2:
vm.$set(vm.params, "order", "starting_price:asc");
break;
case 3:
vm.$set(vm.params, "order", "create_time");
break;
}
let res = await ApiGetGoodsList(vm.params);
if (res.error) {
vm.$message.error(res.error.message);
return false;
}
console.log(`goodListRes`, res.result);
vm.total = res.result.total;
vm.listData = res.result.records;
},
handleCurrentChange(val) {
let vm = this;
vm.$set(vm.params, "pageIndex", val);
vm.getGoodsListData();
},
},
};
</script>
<style lang="scss" scoped>
.page {
background: #f8f8f8;
width: 100%;
min-height: 600px;
}
.main {
width: 1200px;
margin: 0 auto;
padding-top: 14px;
padding-bottom: 60px;
&__nav {
&::after {
display: block;
width: 1200px;
content: "";
height: 1px;
background: #eee;
}
&-crumbs {
.el-icon-arrow-right {
margin: 0 10px;
}
}
&-sort {
width: 100%;
height: 50px;
margin-top: 24px;
padding: 0 30px;
&-txt {
color: #999999;
margin-right: 30px;
}
&-btn {
margin-right: 50px;
cursor: pointer;
}
&-active {
color: #ff512b;
}
}
}
&__content {
margin-top: 30px;
display: grid;
width: 100%;
grid-template-columns: repeat(auto-fill, 232px);
justify-content: space-between;
grid-row-gap: 10px;
}
&__pagination {
margin-top: 60px;
/deep/.el-pager {
margin-left: 8px;
}
</style>
/deep/button,
/deep/.number,
/deep/.btn-quicknext,
/deep/.btn-quickprev {
width: 32px;
height: 32px;
text-align: center;
line-height: 32px;
margin-left: 8px;
border-radius: 2px 2px 2px 2px;
border: 1px solid rgba(0, 0, 0, 0.15);
font-size: 14px;
font-family: Microsoft YaHei-Regular, Microsoft YaHei;
font-weight: 400;
color: rgba(0, 0, 0, 0.65);
}
/deep/.active {
background: #ff512b;
color: #fff;
}
}
}
</style>
<style>
.tab-category__menu {
display: none;
}
</style>

@ -0,0 +1,92 @@
<template>
<div class="goods-item" @click="onItem">
<img class="goods-item__img" :src="item.mainPicture" alt="商品图片" />
<div class="goods-item__title">
<span class="goods-item__title-label" v-if="isLabel(item.labelList)">
{{ getLabel(item.labelList) }}
</span>
{{ item.name }}
</div>
<div class="goods-item__price">
<UiMoney :money="item.startingPrice"></UiMoney>
</div>
</div>
</template>
<script>
import UiMoney from "@/components/UiMoney.vue";
export default {
name: "GoodsItem",
componetns: { UiMoney },
props: {
item: {
type: Object,
default: () => {},
},
},
data() {
return {};
},
methods: {
isLabel(arr) {
return arr.some((item) => item.code);
},
getLabel(arr) {
let str = "";
for (let i = 0; i < arr.length; i++) {
if (arr[i].code != "miaosha") {
str = arr[i].text;
break;
}
}
return str;
},
onItem() {
this.$router.push({
path: "/goods/detail/" + this.item.id,
});
},
},
};
</script>
<style lang="scss" scoped>
.goods-item {
width: 232px;
height: 340px;
cursor: pointer;
background: #ffffff;
&__img {
width: 232px;
height: 232px;
}
&__title {
width: 200px;
height: 45px;
margin: 17px auto 10px;
font-size: 14px;
font-family: Microsoft YaHei-Regular, Microsoft YaHei;
font-weight: 400;
color: #333333;
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
&-label {
display: inline-block;
padding: 4px 8px;
background: rgba(255, 135, 91, 0.1);
font-size: 12px;
font-family: Microsoft YaHei-Regular, Microsoft YaHei;
font-weight: 400;
color: #ff875b;
text-align: center;
margin-right: 8px;
}
}
&__price {
width: 200px;
margin: 0 auto;
}
}
</style>

@ -0,0 +1,80 @@
<template>
<div class="sort-item" @click="onSort">
<span class="sort-item-txt">{{ sortText }}</span>
<div class="sort-img-box">
<img
v-if="sortType === 0 || sortType === 1"
src="~/static/images/goods/sort-t1.png"
alt="sort"
/>
<img
v-if="sortType === 2"
src="~/static/images/goods/sort-t2.png"
alt="sort"
/>
<img
v-if="sortType === 0 || sortType === 2"
src="~/static/images/goods/sort-b1.png"
alt="sort"
/>
<img
v-if="sortType === 1"
src="~/static/images/goods/sort-b2.png"
alt="sort"
/>
</div>
</div>
</template>
<script>
export default {
name: "SortItem",
props: {
sortText: {
type: String,
default: "",
},
/*
0:未选中
1:desc
2:asc
*/
sortType: {
type: Number,
default: 0,
},
},
data() {
return {};
},
methods: {
onSort() {
this.$emit("onSort");
},
},
};
</script>
<style lang="scss" scoped>
.sort-item {
margin-right: 50px;
display: flex;
align-items: center;
cursor: pointer;
.sort-item-txt {
margin-right: 6px;
display: flex;
align-items: center;
font-size: 14px;
}
.sort-img-box {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
}
img {
width: 6px;
height: 3px;
margin: 3px 0;
}
}
</style>

@ -35,5 +35,5 @@ export const ApiPostLogin = (data) => ToAsyncAwait(axios.post(`${BASE_URL}/user/
* 获取手机验证码
* @param {*} params
*/
export const ApiGetCode = (params) => ToAsyncAwait(axios.get(`${BASE_URL}/user/login/verificationCode`, params));
export const ApiGetCode = (params) => ToAsyncAwait(axios.get(`${BASE_URL}/user/login/verificationCode`, { params }));

@ -16,7 +16,7 @@ const BASE_URL = `${ENV.base_url}/mall/product`;
* @param {*} params
*/
export const ApiGetGoodsList = (params) =>
ToAsyncAwait(axios.get(`${BASE_URL}/app/product/page`, params));
ToAsyncAwait(axios.get(`${BASE_URL}/app/product/page`, {params}));
/**
* 获取推荐商品
* @param {*} params
@ -34,7 +34,7 @@ export const ApiGetGoodsDetail = (params) =>
* @param {*} productId
*/
export const ApiGetGoodsSkus = (params) =>
ToAsyncAwait(axios.get(`${BASE_URL}/app/product/sku`,params));
ToAsyncAwait(axios.get(`${BASE_URL}/app/product/sku`,{params}));
/**
* 获取首页分类导航

@ -23,7 +23,7 @@ export default function ({$axios, store}, inject) {
}
if(result.code === 'TOKEN_FAIL'){
alert('这里要弹登录')
store.commit('SET_TOKEN', '');
store.commit('setLoginOut');
return result;
}
return Promise.reject(result);

@ -1,5 +1,5 @@
import Vue from 'vue'
import Element from 'element-ui'
import locale from 'element-ui/lib/locale/lang/en'
import locale from 'element-ui/lib/locale/lang/zh-CN'
Vue.use(Element, { locale })

@ -1,14 +0,0 @@
/*
* @Author: ch
* @Date: 2022-05-04 21:15:17
* @LastEditors: ch
* @LastEditTime: 2022-05-07 22:33:57
* @Description: 服务端没有localStorage对象在Sotre中不能直接取值在plugins中统一为state做一次初始取值处理
*/
import { TOKEN } from "./config/sotrageKey";
export default ({store})=>{
// 获取storage中的token
store.commit('SET_TOKEN',localStorage.getItem(TOKEN));
}

@ -0,0 +1,17 @@
import Vue from "vue";
import { TOKEN_KEY } from "@/constants";
const injectOptions = {
// 是否需要登录拦截
$isLoginValidate() {
if (this.$cookies.get(TOKEN_KEY)) {
return true;
}
this.$store.commit("setLoginVisible", true);
return false;
},
};
for (let key in injectOptions) {
Vue.prototype[key] = injectOptions[key];
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 369 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 374 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 375 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 134 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 133 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 135 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 135 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 706 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

@ -5,16 +5,49 @@
* @LastEditTime: 2022-05-07 22:33:28
* @Description: file content
*/
import { TOKEN_KEY } from "@/constants";
import { ApiGetCurrentUser } from "@/plugins/api/account";
const ONE_DAY = 86400000; // 一天的毫秒数 24 * 60 * 60 * 1000;
import { TOKEN } from "@/plugins/config/sotrageKey";
const state = () => ({
token: "",
userInfo: {},
loginVisible: false, // 是否展示登录弹窗
});
const mutations = {
setUserInfo(state, info) {
state.userInfo = info;
},
setToken(state, token) {
state.token = token;
this.$cookies.set(TOKEN_KEY, token, {
path: "/",
maxAge: ONE_DAY,
});
},
setLoginOut(state) {
state.token = "";
state.userInfo = {};
this.$cookies.remove(TOKEN_KEY);
},
setLoginVisible(state, visible) {
state.loginVisible = visible;
},
};
const actions = {
async nuxtServerInit({ state, commit, dispatch }) {
const token = this.$cookies.get(TOKEN_KEY);
if (!state.token && token) {
commit("setToken", token);
await dispatch("getUserInfo");
}
},
async getUserInfo({ commit }) {
const { result } = await ApiGetCurrentUser();
if (result) {
commit("setUserInfo", result);
}
},
};
export const state = () => ({
token: ''
})
export const mutations = {
SET_TOKEN (state, token = ''){
state.token = token;
token ? localStorage.setItem(TOKEN, token) : localStorage.removeItem(TOKEN);
}
}
export { state, mutations, actions };

Loading…
Cancel
Save