index.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <template>
  2. <view class="container">
  3. <check-login />
  4. <template v-if="isLogin">
  5. <!--search-->
  6. <view class="search-box main-center cross-center">
  7. <u-input
  8. v-model="keywords"
  9. placeholder="请输入剧名"
  10. color="#fff"
  11. border="none"
  12. prefix-icon="search"
  13. :prefix-icon-style="{
  14. color: $colors.primaryColor,
  15. fontSize: '50rpx',
  16. fontWeight: 500,
  17. lineHeight: '50rpx'
  18. }"
  19. :custom-style="{
  20. backgroundColor: $colors.bgOpColor,
  21. padding: '14rpx 30rpx',
  22. width: '700rpx',
  23. borderRadius: '36rpx',
  24. color: '#fff'
  25. }"
  26. @confirm="handleSearch"
  27. />
  28. </view>
  29. <!--swpier-->
  30. <swiper-box />
  31. <!--栏目分类-->
  32. <nav-bar />
  33. <!--分类-->
  34. <episode-box
  35. v-for="(item,index) in homeColumn"
  36. :key="index"
  37. :title="item.name"
  38. :type="item.type"
  39. />
  40. <!--tab bar-->
  41. <tab-bar />
  42. <!--最近播放-->
  43. <recent />
  44. </template>
  45. </view>
  46. </template>
  47. <script>
  48. import SwiperBox from '../../components/SwiperBox/index'
  49. import EpisodeBox from './components/EpisodeBox'
  50. import TabBar from '../../components/TabBar/index'
  51. import NavBar from '../../components/NavBar/index'
  52. import Recent from './components/Recent'
  53. import CheckLogin from '../../components/CheckLogin/index'
  54. import { mapState } from 'vuex'
  55. import Cache from '../../utils/cache'
  56. export default {
  57. components: { CheckLogin, Recent, NavBar, TabBar, EpisodeBox, SwiperBox },
  58. data() {
  59. return {
  60. keywords: '',
  61. homeColumnType: {
  62. 1: 'recommend',
  63. 2: 'todayRecommend',
  64. 3: 'news',
  65. 4: 'rank'
  66. },
  67. homeColumn: [],
  68. parent_id: 0,
  69. scene_code: ''
  70. }
  71. },
  72. computed: {
  73. isLogin() {
  74. return this.$api.user.isLogin()
  75. },
  76. ...mapState({
  77. userInfo: seate => seate.user.info
  78. })
  79. },
  80. onLoad(options) {
  81. // 直接传递user_id
  82. if (typeof options.user_id !== 'undefined' && options.user_id) {
  83. Cache.set('parent_id', options.user_id)
  84. }
  85. // 微信小程序 对应的二维码是 scene_code
  86. if (typeof options.scene !== 'undefined' && options.scene) {
  87. Cache.set('parent_id', options.scene)
  88. }
  89. console.log('-->index data', options)
  90. this.isLogin && this.getHomeColumn()
  91. this.isLogin && this.bindParent()
  92. },
  93. methods: {
  94. handleSearch() {
  95. if (!this.keywords) {
  96. this.$u.toast('请输入剧集名称')
  97. return
  98. }
  99. this.$u.route({
  100. url: '/pages/index/search',
  101. params: {
  102. keywords: this.keywords
  103. }
  104. })
  105. },
  106. getHomeColumn() {
  107. this.$api.setting.homeColumn().then(res => {
  108. this.homeColumn = res.data
  109. this.homeColumn.forEach(obj => {
  110. obj.type = this.homeColumnType[obj.type]
  111. })
  112. })
  113. },
  114. bindParent() {
  115. const parentId = Cache.get('parent_id')
  116. if (parentId && !this.userInfo.parent_id) {
  117. this.$api.user.bind(parentId).then(res => {
  118. console.log('-->bind success')
  119. this.$store.dispatch('user/info', res.data)
  120. Cache.remove('parent_id')
  121. })
  122. }
  123. }
  124. },
  125. onShareAppMessage() {
  126. return this.$util.shareMessage(this.userInfo)
  127. }
  128. }
  129. </script>
  130. <style lang="scss" scoped>
  131. .container{
  132. padding: 30rpx 20rpx 160px;
  133. .search-box{
  134. /*margin-top: 30rpx;*/
  135. }
  136. .category-box{
  137. .category-item{
  138. flex: 1;
  139. font-size: 32rpx;
  140. .icon{
  141. image{
  142. width: 100rpx;
  143. height: 100rpx;
  144. }
  145. }
  146. text{
  147. color: #fff;
  148. }
  149. }
  150. }
  151. }
  152. </style>