为count-modify组件增加登录判断

This commit is contained in:
TOP糯米 2023-04-09 22:42:11 +08:00
parent 68f0622384
commit 0c0d35dff7
1 changed files with 38 additions and 22 deletions

View File

@ -1,16 +1,17 @@
<template>
<view class="component-widget-count-modify" :class="[number > 0 ? 'between' : 'end']">
<view v-if="number > 0" class="btn sub" @click="sub">
<view v-if="number > 0" class="btn sub" @click="calc(0)">
<text class="iconfont icon-jianhao"></text>
</view>
<view v-if="number > 0" class="num">{{ number }}</view>
<view class="btn add" @click="add">
<view class="btn add" @click="calc(1)">
<text class="iconfont icon-jiahao-"></text>
</view>
</view>
</template>
<script>
import { mapGetters } from "vuex";
export default {
name: "component-widget-count-modify",
data() {
@ -19,6 +20,10 @@ export default {
};
},
props: {
auth: {
type: Boolean,
default: false,
},
min: {
type: [Number, String],
default: 0,
@ -33,6 +38,11 @@ export default {
},
},
components: {},
computed: {
...mapGetters({
isLogin: "user/isLogin",
}),
},
created() {
this.number = this.init;
},
@ -41,30 +51,36 @@ export default {
watch: {
init(value) {
this.number = value;
}
},
},
methods: {
sub() {
if (this.number > this.min) {
this.number--;
calc(type) {
let event = {};
if (!this.auth || (this.auth && this.isLogin)) {
if (type == 1) {
if (this.max == 0 || this.number < this.max) {
this.number++;
} else {
this.number = this.max;
}
} else {
if (this.number > this.min) {
this.number--;
} else {
this.number = this.min;
}
}
event = {
type: type == 1 ? "add" : "sub",
value: this.number,
};
} else {
this.number = this.min;
event = {
type: "nologin",
value: 0,
};
}
this.$emit("change", {
type: "sub",
value: this.number,
});
},
add() {
if (this.max == 0 || this.number < this.max) {
this.number++;
} else {
this.number = this.max;
}
this.$emit("change", {
type: "add",
value: this.number,
});
this.$emit("change", event);
},
},
};