app-special-topic-list.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. <template>
  2. <view>
  3. <view class="app-special-topic-list" :class="theme" 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="tabCurrentIndex === index ? theme+ '-m-border ' + theme: 'app-current'"
  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. theme: String
  131. },
  132. data() {
  133. return {
  134. tabCurrentIndex: 0,
  135. touchStartX: 0,
  136. touchStartY: 0,
  137. time: 0,
  138. interval: '',
  139. touchMoveX: 0,
  140. touchMoveY: 0,
  141. }
  142. },
  143. methods: {
  144. tabClick(index) {
  145. this.tabCurrentIndex = index;
  146. },
  147. touchStart(e) {
  148. this.touchStartX = e.touches[0].pageX;
  149. this.touchStartY = e.touches[0].pageY; // 获取触摸时的原点
  150. // 使用js计时器记录时间
  151. this.interval = setInterval(() => {
  152. this.time++;
  153. }, 100);
  154. },
  155. touchmove(e) {
  156. this.touchMoveX = e.touches[0].pageX;
  157. this.touchMoveY = e.touches[0].pageY;
  158. },
  159. touchend() {
  160. let moveX = this.touchMoveX - this.touchStartX;
  161. let moveY = this.touchMoveY - this.touchStartY;
  162. if (Math.sign(moveX) === -1) {
  163. moveX = moveX * -1;
  164. }
  165. if (Math.sign(moveY) === -1) {
  166. moveY = moveY * -1;
  167. }
  168. if(moveX >= moveY) {// 左右
  169. // 向左滑动
  170. if (this.touchMoveX - this.touchStartX <= -20 && this.time < 10) {
  171. if (this.tabCurrentIndex === 0 ) {
  172. this.tabCurrentIndex = this.list.length -1;
  173. } else {
  174. this.tabCurrentIndex -= 1;
  175. }
  176. }
  177. // 向右滑动
  178. if (this.touchMoveX - this.touchStartX >= 20 && this.time < 10) {
  179. if (this.tabCurrentIndex === this.list.length -1) {
  180. this.tabCurrentIndex = 0;
  181. } else {
  182. this.tabCurrentIndex += 1;
  183. }
  184. }
  185. }
  186. clearInterval(this.interval); // 清除setInterval
  187. this.time = 0;
  188. }
  189. }
  190. }
  191. </script>
  192. <style scoped lang="scss">
  193. .app-special-topic-list {
  194. height: 100%;
  195. width: #{750rpx};
  196. overflow: hidden;
  197. background-color: white;
  198. border-bottom: #{1rpx} solid #e2e2e2;
  199. }
  200. .auto-tab {
  201. height: #{88rpx};
  202. width: #{750rpx};
  203. margin-left: #{2rpx};
  204. >view {
  205. position: absolute;
  206. }
  207. }
  208. .auto-list-scroll-content{
  209. height: 100%;
  210. }
  211. .app-nav-item {
  212. display: inline-block;
  213. height: #{88rpx};
  214. line-height: #{88rpx};
  215. font-size: #{32rpx};
  216. color: #353535;
  217. margin-left: #{30rpx};
  218. margin-right: #{30rpx};
  219. border-bottom: #{4rpx} solid;
  220. white-space: nowrap;
  221. }
  222. .app-current {
  223. border-bottom-color: transparent;
  224. }
  225. .app-content {
  226. width: #{750rpx};
  227. margin-top: #{-16rpx};
  228. .app-content-item {
  229. width: #{750rpx};
  230. border-top: #{0.1rpx} solid transparent;
  231. }
  232. .app-text-read {
  233. font-size: #{24rpx};
  234. color: #919191;
  235. }
  236. .app-small-frame {
  237. background-color: #ffffff;
  238. width: #{750rpx};
  239. overflow: hidden;
  240. margin-top: #{16rpx};
  241. padding: #{20rpx} #{24rpx};
  242. .app-image {
  243. width: #{268rpx};
  244. height: #{202rpx};
  245. }
  246. .app-content-text {
  247. width: #{394rpx};
  248. height: #{190rpx};
  249. .app-text {
  250. font-size: #{32rpx};
  251. color: #353535;
  252. width: #{394rpx};
  253. }
  254. }
  255. }
  256. .app-big-frame {
  257. margin-top: #{16rpx};
  258. padding: #{32rpx} #{24rpx} #{24rpx} #{24rpx};
  259. background-color: #ffffff;
  260. .app-text {
  261. font-size: #{32rpx};
  262. width: #{750-24-24rpx};
  263. color: #353535;
  264. display: -webkit-box;
  265. -webkit-box-orient: vertical;
  266. -webkit-line-clamp: 2;
  267. overflow: hidden;
  268. }
  269. .app-image {
  270. width: #{750-24-24rpx};
  271. height: #{350rpx};
  272. margin: #{24rpx} 0;
  273. }
  274. }
  275. .app-more-frame {
  276. margin-top: #{16rpx};
  277. padding: #{32rpx} #{24rpx} #{24rpx} #{24rpx};
  278. background-color: #ffffff;
  279. .app-text {
  280. font-size: #{32rpx};
  281. width: #{750-24-24rpx};
  282. color: #353535;
  283. }
  284. .app-image {
  285. margin-top: #{16rpx};
  286. width: #{226rpx};
  287. height: #{170rpx};
  288. margin-right: #{12rpx};
  289. margin-bottom: #{16rpx};
  290. display: block;
  291. }
  292. }
  293. }
  294. </style>