¶Ô±ÈÐÂÎļþ |
| | |
| | | <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 ? contentFav : contentDefault }}</text> |
| | | </view> |
| | | </template> |
| | | |
| | | <script> |
| | | |
| | | /** |
| | | * Fav æ¶èæé® |
| | | * @description ç¨äºæ¶èåè½ï¼å¯ç¹å»åæ¢éä¸ãä¸éä¸çç¶æ |
| | | * @tutorial https://ext.dcloud.net.cn/plugin?id=864 |
| | | * @property {Boolean} star = [true|false] æé®æ¯å¦å¸¦ææ |
| | | * @property {String} bgColor æªæ¶èæ¶çèæ¯è² |
| | | * @property {String} bgColorChecked å·²æ¶èæ¶çèæ¯è² |
| | | * @property {String} fgColor æªæ¶èæ¶çæåé¢è² |
| | | * @property {String} fgColorChecked å·²æ¶èæ¶çæåé¢è² |
| | | * @property {Boolean} circle = [true|false] æ¯å¦ä¸ºåè§ |
| | | * @property {Boolean} checked = [true|false] æ¯å¦ä¸ºå·²æ¶è |
| | | * @property {Object} contentText = [true|false] æ¶èæé®æå |
| | | * @property {Boolean} stat æ¯å¦å¼å¯ç»è®¡åè½ |
| | | * @event {Function} click ç¹å» favæé®è§¦åäºä»¶ |
| | | * @example <uni-fav :checked="true"/> |
| | | */ |
| | | |
| | | import { |
| | | initVueI18n |
| | | } from '@dcloudio/uni-i18n' |
| | | import messages from './i18n/index.js' |
| | | const { t } = initVueI18n(messages) |
| | | |
| | | export default { |
| | | name: "UniFav", |
| | | // TODO å
¼å®¹ vue3ï¼éè¦æ³¨åäºä»¶ |
| | | emits: ['click'], |
| | | 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: "" |
| | | }; |
| | | } |
| | | }, |
| | | stat:{ |
| | | type: Boolean, |
| | | default: false |
| | | } |
| | | }, |
| | | computed: { |
| | | contentDefault() { |
| | | return this.contentText.contentDefault || t("uni-fav.collect") |
| | | }, |
| | | contentFav() { |
| | | return this.contentText.contentFav || t("uni-fav.collected") |
| | | }, |
| | | }, |
| | | watch: { |
| | | checked() { |
| | | if (uni.report && this.stat) { |
| | | if (this.checked) { |
| | | uni.report("æ¶è", "æ¶è"); |
| | | } else { |
| | | uni.report("åæ¶æ¶è", "åæ¶æ¶è"); |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | methods: { |
| | | onClick() { |
| | | this.$emit("click"); |
| | | } |
| | | } |
| | | }; |
| | | </script> |
| | | |
| | | <style lang="scss" > |
| | | $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; |
| | | /* #ifdef H5 */ |
| | | cursor: pointer; |
| | | /* #endif */ |
| | | } |
| | | |
| | | .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: 12px; |
| | | } |
| | | </style> |