special.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <template>
  2. <view class="diy-special" v-if="listData.length>0">
  3. <view class="special-left">
  4. <image :src="itemData.style.image" mode="aspectFill"></image>
  5. </view>
  6. <view class="right-shadow"></view>
  7. <view class="special-content" :class="'display_' + itemData.style.display">
  8. <view class="special-content-list" :style="'transform: translate(0,'+styleValue+'px);'">
  9. <view class="content-item text-ellipsis" v-for="(item, index) in listData" :key="index" @click="gotoPageFunc(item)">
  10. <text>{{ item.article_title }}</text>
  11. </view>
  12. </view>
  13. </view>
  14. <view class="special-more" @click="gotoPageFunc()"><text class="iconfont icon-jiantou"></text></view>
  15. </view>
  16. </template>
  17. <script>
  18. export default {
  19. data() {
  20. return {
  21. /*数据列表*/
  22. listData: [],
  23. /*样式*/
  24. styleValue: '',
  25. /*当前角标*/
  26. index_num: 0,
  27. /*高度*/
  28. lineHeight: 0,
  29. /*最大数*/
  30. maxSize: 0,
  31. /*时间*/
  32. timer: null
  33. };
  34. },
  35. props: ['itemData'],
  36. created() {
  37. this.listData = this.itemData.data;
  38. this.init();
  39. },
  40. methods: {
  41. /*初始化*/
  42. init() {
  43. let self = this;
  44. if ((this.itemData.style.display == 1 && this.listData.length > 1) || (this.itemData.style.display == 2 && this.listData
  45. .length > 2)) {
  46. uni.getSystemInfo({
  47. success(res) {
  48. self.lineHeight = res.windowWidth / 750 * 30;
  49. self.maxSize = self.listData.length
  50. if (self.itemData.style.display == 2) {
  51. self.lineHeight = self.lineHeight * 2;
  52. self.maxSize = self.maxSize / 2;
  53. }
  54. self.timer = setInterval(function() {
  55. self.animation();
  56. }, 3000);
  57. }
  58. });
  59. }
  60. },
  61. /*动画*/
  62. animation() {
  63. let self = this;
  64. self.index_num++;
  65. if (self.index_num >= self.maxSize) {
  66. self.index_num = 0;
  67. }
  68. this.styleValue = -self.lineHeight * self.index_num;
  69. },
  70. /*跳转页面*/
  71. gotoPageFunc(e) {
  72. let url = null;
  73. if (e && typeof e != 'undefined') {
  74. url = 'pages/article/detail/detail?article_id=' + e.article_id;
  75. } else {
  76. url = 'pages/article/list/list';
  77. }
  78. this.gotoPage(url);
  79. }
  80. }
  81. };
  82. </script>
  83. <style>
  84. .diy-special {
  85. background-color: #FFFFFF;
  86. padding: 0 20rpx 0 24rpx;
  87. margin: 20rpx;
  88. display: flex;
  89. justify-content: space-between;
  90. align-items: center;
  91. overflow: hidden;
  92. }
  93. .diy-special .special-left {
  94. width: 136rpx;
  95. height: 33rpx;
  96. }
  97. .diy-special .special-left image {
  98. width: 100%;
  99. height: 100%;
  100. }
  101. .diy-special .special-more .icon-jiantou {
  102. font-size: 24rpx;
  103. }
  104. .diy-special .special-content {
  105. flex: 1;
  106. margin: 0 20rpx;
  107. overflow: hidden;
  108. }
  109. .diy-special .special-content-list {
  110. transition: transform .4s;
  111. }
  112. .diy-special .content-item {
  113. height: 30rpx;
  114. line-height: 30rpx;
  115. }
  116. .diy-special .special-content.display_1 {
  117. height: 30rpx;
  118. }
  119. .diy-special .special-content.display_2 {
  120. height: 60rpx;
  121. }
  122. .right-shadow {
  123. width: 15rpx;
  124. height: 90rpx;
  125. background: linear-gradient(90deg, #E4E4E4 0%, rgba(255, 255, 255, 0) 100%);
  126. margin-left: 30rpx;
  127. }
  128. </style>