EpisodeButtons.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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>{{ 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>{{ 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>{{ 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>{{ episode.sahre_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. }
  72. },
  73. watch: {
  74. 'toast.show'(val) {
  75. if (val) {
  76. setTimeout(() => {
  77. this.toast.show = false
  78. }, 1000)
  79. }
  80. }
  81. },
  82. created() {
  83. if (Object.keys(this.episode).length) {
  84. this.checkCollect()
  85. this.checkFavorite()
  86. }
  87. },
  88. methods: {
  89. // 检查是否收藏当前剧集
  90. checkCollect() {
  91. this.$api.user.collect.check(this.episode.id).then(res => {
  92. this.isCollect = res.data
  93. })
  94. },
  95. // 收藏相关 处理
  96. handleCollect() {
  97. const method = this.isCollect ? 'destroy' : 'add'
  98. const num = this.isCollect ? -1 : 1
  99. this.$api.user.collect[method](this.episode.id).then(res => {
  100. if (res.data) {
  101. this.toast.show = true
  102. this.toast.status = this.isCollect ? 'cancel' : 'success'
  103. this.toast.text = this.isCollect ? '取消收藏' : '收藏成功'
  104. this.isCollect = !this.isCollect
  105. this.$emit('change', { type: 'collect', num: num })
  106. }
  107. })
  108. },
  109. // 检查是否喜欢当前短剧
  110. checkFavorite() {
  111. this.$api.user.favorite.check(this.episode.id).then(res => {
  112. this.isFav = res.data
  113. })
  114. },
  115. // 处理 喜欢剧集
  116. handleFavorite() {
  117. const method = this.isFav ? 'destroy' : 'add'
  118. const num = this.isFav ? -1 : 1
  119. this.$api.user.favorite[method](this.episode.id).then(res => {
  120. if (res.data) {
  121. this.toast.show = true
  122. this.toast.status = this.isFav ? 'cancel' : 'success'
  123. this.toast.text = this.isFav ? '取消喜欢' : '喜欢成功'
  124. this.$emit('change', { type: 'fav', num: num })
  125. this.isFav = !this.isFav
  126. }
  127. })
  128. }
  129. }
  130. }
  131. </script>
  132. <style lang="scss" scoped>
  133. .episode-buttons {
  134. .view-num{
  135. position: fixed;
  136. right: 20rpx;
  137. top: 40rpx;
  138. color: #fff;
  139. font-size: 26rpx;
  140. z-index: 100;
  141. text{
  142. margin-left: 10rpx;
  143. }
  144. }
  145. .status-bar{
  146. position: fixed;
  147. bottom: 300rpx;
  148. right: 40rpx;
  149. color: $default-color;
  150. z-index: 999;
  151. .item{
  152. margin-bottom: 40rpx;
  153. &.share{
  154. position: relative;
  155. button{
  156. position: absolute;
  157. background: transparent;
  158. top: 0;
  159. left: 0;
  160. right: 0;
  161. bottom: 0;
  162. z-index: 1;
  163. &:after{
  164. content: unset;
  165. }
  166. }
  167. }
  168. &.active{
  169. color: $primary-color;
  170. }
  171. text{
  172. margin-top: 10rpx;
  173. }
  174. }
  175. }
  176. .toast{
  177. position: fixed;
  178. width: 60vw;
  179. background: rgba(0,0,0,.5);
  180. height: 300rpx;
  181. top: 30%;
  182. left: 50%;
  183. transform: translate(-50%,-50%);
  184. border-radius: 20rpx;
  185. font-size: 36rpx;
  186. color: $default-color;
  187. z-index: 999;
  188. &.success{
  189. color: $primary-color;
  190. }
  191. text{
  192. margin-top: 20rpx;
  193. }
  194. }
  195. }
  196. </style>