123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- <template>
- <view :class="[circle === true || circle === 'true' ? 'uni-fav--circle' : '']" :style="[{ backgroundColor: checked ? bgColorChecked : bgColor }]"
- @click="onClick" class="uni-fav">
- <!-- #ifdef MP-ALIPAY -->
- <view class="uni-fav-star" v-if="!checked && (star === true || star === 'true')">
- <uni-icons :color="fgColor" :style="{color: checked ? fgColorChecked : fgColor}" size="14" type="star-filled" />
- </view>
- <!-- #endif -->
- <!-- #ifndef MP-ALIPAY -->
- <uni-icons :color="fgColor" :style="{color: checked ? fgColorChecked : fgColor}" class="uni-fav-star" size="14" type="star-filled"
- v-if="!checked && (star === true || star === 'true')" />
- <!-- #endif -->
- <text :style="{color: checked ? fgColorChecked : fgColor}" class="uni-fav-text">{{ checked ? contentText.contentFav : contentText.contentDefault }}</text>
- </view>
- </template>
- <script>
- import uniIcons from "../uni-icons/uni-icons.vue";
- export default {
- name: "UniFav",
- components: {
- uniIcons
- },
- props: {
- star: {
- type: [Boolean, String],
- default: true
- },
- bgColor: {
- type: String,
- default: "#eeeeee"
- },
- fgColor: {
- type: String,
- default: "#666666"
- },
- bgColorChecked: {
- type: String,
- default: "#007aff"
- },
- fgColorChecked: {
- type: String,
- default: "#FFFFFF"
- },
- circle: {
- type: [Boolean, String],
- default: false
- },
- checked: {
- type: Boolean,
- default: false
- },
- contentText: {
- type: Object,
- default () {
- return {
- contentDefault: "收藏",
- contentFav: "已收藏"
- };
- }
- }
- },
- watch: {
- checked() {
- if (uni.report) {
- if (this.checked) {
- uni.report("收藏", "收藏");
- } else {
- uni.report("取消收藏", "取消收藏");
- }
- }
- }
- },
- methods: {
- onClick() {
- this.$emit("click");
- }
- }
- };
- </script>
- <style lang="scss" scoped>
- $fav-height: 25px;
- .uni-fav {
- /* #ifndef APP-NVUE */
- display: flex;
- /* #endif */
- flex-direction: row;
- align-items: center;
- justify-content: center;
- width: 60px;
- height: $fav-height;
- line-height: $fav-height;
- text-align: center;
- border-radius: 3px;
- }
- .uni-fav--circle {
- border-radius: 30px;
- }
- .uni-fav-star {
- /* #ifndef APP-NVUE */
- display: flex;
- /* #endif */
- height: $fav-height;
- line-height: 24px;
- margin-right: 3px;
- align-items: center;
- justify-content: center;
- }
- .uni-fav-text {
- /* #ifndef APP-NVUE */
- display: flex;
- /* #endif */
- height: $fav-height;
- line-height: $fav-height;
- align-items: center;
- justify-content: center;
- font-size: $uni-font-size-base;
- }
- </style>
|