app-special-topic-list.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. <template>
  2. <view>
  3. <view class="app-special-topic-list" v-if="catShow">
  4. <scroll-view class="auto-tab" scroll-x>
  5. <view class="dir-left-nowrap ">
  6. <text v-for="(item,index) in list"
  7. :key="index"
  8. class="app-nav-item"
  9. :class="{'app-current': tabCurrentIndex === index}"
  10. @click="tabClick(index)"
  11. >
  12. {{item.name}}
  13. </text>
  14. </view>
  15. </scroll-view>
  16. </view>
  17. <view class="app-content">
  18. <template v-if="catShow">
  19. <view class="app-content-item"
  20. v-for="(item, index) in list"
  21. :key="index"
  22. v-if="tabCurrentIndex === index"
  23. >
  24. <block v-for="(child, sub) in item.children" v-bind:key="sub" >
  25. <template v-if="child.layout === 0">
  26. <app-jump-button form :url="`../topic/topic?id=${child.id}`" open_type="navigate">
  27. <view class="app-small-frame main-between ">
  28. <view class="app-content-text dir-top-nowrap main-between">
  29. <text class="app-text t-omit-two">{{child.title}}</text>
  30. <text class="app-text-read t-omit-two">{{child.abstract}}</text>
  31. <text class="app-text-read">{{child.read_count}}</text>
  32. </view>
  33. <image lazy-load class="app-image" mode="scaleToFill" :src="child.cover_pic"></image>
  34. </view>
  35. </app-jump-button>
  36. </template>
  37. <template v-if="child.layout === 1">
  38. <app-jump-button form :url="`../topic/topic?id=${child.id}`" open_type="navigate">
  39. <view class="app-big-frame dir-top-nowrap">
  40. <text class="app-text t-omit-two">{{child.title}}</text>
  41. <text class="app-text-read t-omit-two">{{child.abstract}}</text>
  42. <image lazy-load class="app-image" mode="scaleToFill" :src="child.cover_pic"></image>
  43. <text class="app-text-read">{{child.read_count}}</text>
  44. </view>
  45. </app-jump-button>
  46. </template>
  47. <template v-if="child.layout === 2">
  48. <app-jump-button form :url="`../topic/topic?id=${child.id}`" open_type="navigate">
  49. <view class="app-more-frame dir-top-nowrap">
  50. <text class="app-text t-omit-two">{{child.title}}</text>
  51. <text class="app-text-read t-omit-two">{{child.abstract}}</text>
  52. <view class="dir-left-nowrap">
  53. <block v-for="(item, index) in child.pic_list" :key="index">
  54. <image lazy-load class="app-image box-grow-1" mode="scaleToFill" :src="item.url"></image>
  55. </block>
  56. </view>
  57. <text class="app-text-read">{{child.read_count}}</text>
  58. </view>
  59. </app-jump-button>
  60. </template>
  61. </block>
  62. </view>
  63. </template>
  64. <template v-else>
  65. <block v-for="(child, sub) in topicList" v-bind:key="sub" >
  66. <template v-if="child.layout == 0">
  67. <app-jump-button form :url="`../topic/topic?id=${child.id}`" open_type="navigate">
  68. <view class="app-small-frame main-between ">
  69. <view class="app-content-text dir-top-nowrap main-between">
  70. <text class="app-text t-omit-two">{{child.title}}</text>
  71. <text class="app-text-read t-omit-two">{{child.abstract}}</text>
  72. <text class="app-text-read">{{child.read_count}}</text>
  73. </view>
  74. <image lazy-load class="app-image" mode="scaleToFill" :src="child.cover_pic"></image>
  75. </view>
  76. </app-jump-button>
  77. </template>
  78. <template v-if="child.layout == 1">
  79. <app-jump-button form :url="`../topic/topic?id=${child.id}`" open_type="navigate">
  80. <view class="app-big-frame dir-top-nowrap">
  81. <text class="app-text t-omit-two">{{child.title}}</text>
  82. <text class="app-text-read t-omit-two">{{child.abstract}}</text>
  83. <image lazy-load class="app-image" mode="scaleToFill" :src="child.cover_pic"></image>
  84. <text class="app-text-read">{{child.read_count}}</text>
  85. </view>
  86. </app-jump-button>
  87. </template>
  88. <template v-if="child.layout == 2">
  89. <app-jump-button form :url="`../topic/topic?id=${child.id}`" open_type="navigate">
  90. <view class="app-more-frame dir-top-nowrap">
  91. <text class="app-text t-omit-two">{{child.title}}</text>
  92. <text class="app-text-read t-omit-two">{{child.abstract}}</text>
  93. <view class="dir-left-nowrap">
  94. <block v-for="(item, index) in child.pic_list" :key="index">
  95. <image lazy-load class="app-image box-grow-1" mode="scaleToFill" :src="item.url"></image>
  96. </block>
  97. </view>
  98. <text class="app-text-read">{{child.read_count}}</text>
  99. </view>
  100. </app-jump-button>
  101. </template>
  102. </block>
  103. </template>
  104. </view>
  105. </view>
  106. </template>
  107. <script>
  108. export default {
  109. props: {
  110. catShow: {
  111. type: Boolean,
  112. default: function() {
  113. return true;
  114. }
  115. },
  116. list: {
  117. type: Array,
  118. default: function() {
  119. return [
  120. ];
  121. }
  122. },
  123. topicList: {
  124. type: Array,
  125. default: function() {
  126. return [
  127. ]
  128. }
  129. }
  130. },
  131. data() {
  132. return {
  133. tabCurrentIndex: 0,
  134. touchStartX: 0,
  135. touchStartY: 0,
  136. time: 0,
  137. interval: '',
  138. touchMoveX: 0,
  139. touchMoveY: 0,
  140. }
  141. },
  142. methods: {
  143. tabClick(index) {
  144. this.tabCurrentIndex = index;
  145. },
  146. changeTab(e) {
  147. this.tabCurrentIndex = e.target.current;
  148. },
  149. touchStart(e) {
  150. this.touchStartX = e.touches[0].pageX;
  151. this.touchStartY = e.touches[0].pageY; // 获取触摸时的原点
  152. // 使用js计时器记录时间
  153. this.interval = setInterval(() => {
  154. this.time++;
  155. }, 100);
  156. },
  157. touchmove(e) {
  158. this.touchMoveX = e.touches[0].pageX;
  159. this.touchMoveY = e.touches[0].pageY;
  160. },
  161. touchend() {
  162. let moveX = this.touchMoveX - this.touchStartX;
  163. let moveY = this.touchMoveY - this.touchStartY;
  164. if (Math.sign(moveX) === -1) {
  165. moveX = moveX * -1;
  166. }
  167. if (Math.sign(moveY) === -1) {
  168. moveY = moveY * -1;
  169. }
  170. if(moveX >= moveY) {// 左右
  171. // 向左滑动
  172. if (this.touchMoveX - this.touchStartX <= -20 && this.time < 10) {
  173. if (this.tabCurrentIndex === 0 ) {
  174. this.tabCurrentIndex = this.list.length -1;
  175. } else {
  176. this.tabCurrentIndex -= 1;
  177. }
  178. }
  179. // 向右滑动
  180. if (this.touchMoveX - this.touchStartX >= 20 && this.time < 10) {
  181. if (this.tabCurrentIndex === this.list.length -1) {
  182. this.tabCurrentIndex = 0;
  183. } else {
  184. this.tabCurrentIndex += 1;
  185. }
  186. }
  187. }
  188. clearInterval(this.interval); // 清除setInterval
  189. this.time = 0;
  190. }
  191. },
  192. components: {
  193. }
  194. }
  195. </script>
  196. <style scoped lang="scss">
  197. .app-special-topic-list {
  198. height: 100%;
  199. width: #{750rpx};
  200. overflow: hidden;
  201. background-color: white;
  202. border-bottom: #{1rpx} solid #e2e2e2;
  203. }
  204. .auto-tab {
  205. height: #{88rpx};
  206. width: #{750rpx};
  207. margin-left: #{2rpx};
  208. >view {
  209. position: absolute;
  210. }
  211. }
  212. .auto-list-scroll-content{
  213. height: 100%;
  214. }
  215. .app-nav-item {
  216. display: inline-block;
  217. height: #{88rpx};
  218. line-height: #{88rpx};
  219. font-size: #{32rpx};
  220. color: #353535;
  221. margin-left: #{30rpx};
  222. margin-right: #{30rpx};
  223. border-bottom: #{4rpx} solid transparent;
  224. white-space: nowrap;
  225. }
  226. .app-current {
  227. border-bottom-color: #ff4544;
  228. }
  229. .app-content {
  230. width: #{750rpx};
  231. .app-content-item {
  232. width: #{750rpx};
  233. border-top: #{0.1rpx} solid transparent;
  234. }
  235. .app-text-read {
  236. font-size: #{24rpx};
  237. color: #919191;
  238. }
  239. .app-small-frame {
  240. background-color: #ffffff;
  241. width: #{750rpx};
  242. overflow: hidden;
  243. margin-top: #{10rpx};
  244. padding: #{20rpx} #{24rpx};
  245. .app-image {
  246. width: #{268rpx};
  247. height: #{202rpx};
  248. }
  249. .app-content-text {
  250. width: #{394rpx};
  251. height: #{190rpx};
  252. .app-text {
  253. font-size: #{32rpx};
  254. color: #353535;
  255. width: #{394rpx};
  256. }
  257. }
  258. }
  259. .app-big-frame {
  260. margin-top: #{16rpx};
  261. padding: #{32rpx} #{24rpx} #{24rpx} #{24rpx};
  262. background-color: #ffffff;
  263. .app-text {
  264. font-size: #{32rpx};
  265. width: #{750-24-24rpx};
  266. color: #353535;
  267. display: -webkit-box;
  268. -webkit-box-orient: vertical;
  269. -webkit-line-clamp: 2;
  270. overflow: hidden;
  271. }
  272. .app-image {
  273. width: #{750-24-24rpx};
  274. height: #{350rpx};
  275. margin: #{24rpx} 0;
  276. }
  277. }
  278. .app-more-frame {
  279. margin-top: #{16rpx};
  280. padding: #{32rpx} #{24rpx} #{24rpx} #{24rpx};
  281. background-color: #ffffff;
  282. .app-text {
  283. font-size: #{32rpx};
  284. width: #{750-24-24rpx};
  285. color: #353535;
  286. }
  287. .app-image {
  288. margin-top: #{16rpx};
  289. width: #{226rpx};
  290. height: #{170rpx};
  291. margin-right: #{12rpx};
  292. margin-bottom: #{16rpx};
  293. display: block;
  294. }
  295. }
  296. }
  297. </style>