EpisodeButtons.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <template>
  2. <view v-if="Object.keys(episode).length" class="episode-buttons">
  3. <!--播放数据-->
  4. <view class="view-num main-left cross-center">
  5. <u-icon name="eye-fill" :color="isCollect?$colors.primaryColor:$colors.defaultColor" size="26rpx" />
  6. <text>{{ $util.tranNumber(episode.user_watch_record_count) }}</text>
  7. </view>
  8. <!--按钮-->
  9. <view class="status-bar dir-top-wrap main-center">
  10. <!--喜欢-->
  11. <view
  12. class="item fav dir-top-wrap main-center cross-center"
  13. :class="{active: isFav}"
  14. @click="handleFavorite"
  15. >
  16. <u-icon name="heart-fill" size="58rpx" :color="isFav?$colors.primaryColor:$colors.defaultColor" />
  17. <text>{{ $util.tranNumber(episode.user_favorite_count) }}</text>
  18. </view>
  19. <!--收藏-->
  20. <view
  21. class="item collect dir-top-wrap main-center cross-center"
  22. :class="{active: isCollect}"
  23. @click="handleCollect"
  24. >
  25. <u-icon name="star-fill" size="58rpx" :color="isCollect?$colors.primaryColor:$colors.defaultColor" />
  26. <text>{{ $util.tranNumber(episode.user_collect_count) }}</text>
  27. </view>
  28. <!--分享-->
  29. <view class="item share dir-top-wrap main-center cross-center">
  30. <button open-type="share" />
  31. <u-icon name="share-fill" size="58rpx" :color="$colors.defaultColor" />
  32. <text>{{ $util.tranNumber(episode.share_count) }}</text>
  33. </view>
  34. </view>
  35. <!--toast-->
  36. <view
  37. v-if="toast.show"
  38. class="toast dir-top-wrap main-center cross-center"
  39. :class="toast.status"
  40. >
  41. <u-icon
  42. :name="toast.status === 'success' ? 'checkmark-circle' : 'close-circle'"
  43. :color="toast.status === 'success' ? $colors.primaryColor : $colors.defaultColor"
  44. size="80rpx"
  45. />
  46. <text>{{ toast.text }}</text>
  47. </view>
  48. </view>
  49. </template>
  50. <script>
  51. export default {
  52. name: 'EpisodeButtons',
  53. props: {
  54. episode: {
  55. type: Object,
  56. required: true,
  57. default() {
  58. return {}
  59. }
  60. }
  61. },
  62. data() {
  63. return {
  64. isCollect: false,
  65. isFav: false,
  66. toast: { // 收藏/喜欢 toast
  67. status: 'success',
  68. text: '收藏成功',
  69. show: false
  70. },
  71. btnLock: false
  72. }
  73. },
  74. watch: {
  75. 'toast.show'(val) {
  76. if (val) {
  77. setTimeout(() => {
  78. this.toast.show = false
  79. }, 1000)
  80. }
  81. }
  82. },
  83. created() {
  84. if (Object.keys(this.episode).length) {
  85. this.checkCollect()
  86. this.checkFavorite()
  87. }
  88. },
  89. methods: {
  90. // 检查是否收藏当前剧集
  91. checkCollect() {
  92. this.$api.user.collect.check(this.episode.id).then(res => {
  93. this.isCollect = res.data
  94. })
  95. },
  96. // 收藏相关 处理
  97. handleCollect() {
  98. if (this.btnLock) return
  99. this.btnLock = true
  100. const method = this.isCollect ? 'destroy' : 'add'
  101. const num = this.isCollect ? -1 : 1
  102. this.$api.user.collect[method](this.episode.id).then(res => {
  103. this.btnLock = false
  104. if (res.data) {
  105. this.toast.show = true
  106. this.toast.status = this.isCollect ? 'cancel' : 'success'
  107. this.toast.text = this.isCollect ? '取消收藏' : '收藏成功'
  108. this.isCollect = !this.isCollect
  109. this.$emit('change', { type: 'collect', num: num })
  110. }
  111. })
  112. },
  113. // 检查是否喜欢当前短剧
  114. checkFavorite() {
  115. this.$api.user.favorite.check(this.episode.id).then(res => {
  116. this.isFav = res.data
  117. })
  118. },
  119. // 处理 喜欢剧集
  120. handleFavorite() {
  121. if (this.btnLock) return
  122. this.btnLock = true
  123. const method = this.isFav ? 'destroy' : 'add'
  124. const num = this.isFav ? -1 : 1
  125. this.$api.user.favorite[method](this.episode.id).then(res => {
  126. this.btnLock = false
  127. if (res.data) {
  128. this.toast.show = true
  129. this.toast.status = this.isFav ? 'cancel' : 'success'
  130. this.toast.text = this.isFav ? '取消喜欢' : '喜欢成功'
  131. this.$emit('change', { type: 'fav', num: num })
  132. this.isFav = !this.isFav
  133. }
  134. })
  135. }
  136. }
  137. }
  138. </script>
  139. <style lang="scss" scoped>
  140. .episode-buttons {
  141. .view-num{
  142. position: fixed;
  143. right: 20rpx;
  144. top: 40rpx;
  145. color: #fff;
  146. font-size: 26rpx;
  147. z-index: 100;
  148. text{
  149. margin-left: 10rpx;
  150. }
  151. }
  152. .status-bar{
  153. position: fixed;
  154. bottom: 300rpx;
  155. right: 40rpx;
  156. color: $default-color;
  157. z-index: 999;
  158. .item{
  159. margin-bottom: 40rpx;
  160. &.share{
  161. position: relative;
  162. button{
  163. position: absolute;
  164. background: transparent;
  165. top: 0;
  166. left: 0;
  167. right: 0;
  168. bottom: 0;
  169. z-index: 1;
  170. &:after{
  171. content: unset;
  172. }
  173. }
  174. }
  175. &.active{
  176. color: $primary-color;
  177. }
  178. text{
  179. margin-top: 10rpx;
  180. }
  181. }
  182. }
  183. .toast{
  184. position: fixed;
  185. width: 60vw;
  186. background: rgba(0,0,0,.5);
  187. height: 300rpx;
  188. top: 30%;
  189. left: 50%;
  190. transform: translate(-50%,-50%);
  191. border-radius: 20rpx;
  192. font-size: 36rpx;
  193. color: $default-color;
  194. z-index: 999;
  195. &.success{
  196. color: $primary-color;
  197. }
  198. text{
  199. margin-top: 20rpx;
  200. }
  201. }
  202. }
  203. </style>