forum.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <template>
  2. <view class="index">
  3. <view class="search">
  4. <view class="item">
  5. <text class="icon">&#xe628;</text>
  6. <input type="text" v-model="map.keywords" confirm-type="search" @confirm="search" placeholder="输入文章标题或用户昵称" placeholder-class="inupt_p" />
  7. </view>
  8. <text class="icon" @tap="navigateTo('/pages/forum/addForum', true)">&#xe60e;</text>
  9. </view>
  10. <view class="new" v-for="(v, i) in info.data" @tap="navigateTo('/pages/forum/articleDetails?message_id=' + v.id)" :key="i">
  11. <view class="title">{{ v.title }}</view>
  12. <view class="user">
  13. <image :src="v.user.avatar" mode=""></image>
  14. <text class="t1">{{ v.user.nickname }}</text>
  15. <text class="t2">{{ v.createtime | date }}</text>
  16. </view>
  17. <view class="info">{{ v.content }}</view>
  18. <view class="images" v-if="v.images"><image mode="widthFix" v-for="(val, index) in v.images" :src="host + val" :key="index"></image></view>
  19. </view>
  20. </view>
  21. </template>
  22. <script>
  23. import helper from '../../common/helper.js';
  24. import api from '../../common/api.js';
  25. export default {
  26. data() {
  27. return {
  28. host: helper.host,
  29. map: {
  30. keywords: '',
  31. page: 1
  32. },
  33. messageSwitch: false,
  34. info: {
  35. data: []
  36. }
  37. };
  38. },
  39. filters: {
  40. date: value => {
  41. let date = new Date(value * 1000);
  42. let y = date.getFullYear();
  43. let m = date.getMonth() + 1;
  44. let d = date.getDate();
  45. return y + '-' + (m > 9 ? m : '0' + m) + '-' + (d > 9 ? d : '0' + d);
  46. }
  47. },
  48. onShow() {
  49. this.getList();
  50. },
  51. methods: {
  52. search() {
  53. this.map.page = 1;
  54. this.getList();
  55. },
  56. async getList() {
  57. let res = await api.getMessageList(this.map);
  58. if (this.map.page == 1) {
  59. this.info = res.data;
  60. } else {
  61. for (let i in res.data.data) {
  62. this.info.data.push(res.data.data[i]);
  63. }
  64. }
  65. uni.stopPullDownRefresh();
  66. },
  67. onPullDownRefresh() {
  68. this.map.page = 1;
  69. this.getList();
  70. },
  71. onReachBottom() {
  72. if (this.info.last_page > this.info.current_page) {
  73. this.getList();
  74. }
  75. },
  76. navigateTo(url, isAuth) {
  77. if (isAuth && !helper.hasLogin()) {
  78. uni.navigateTo({
  79. url: '../login/login?url=' + url
  80. });
  81. return false;
  82. }
  83. uni.navigateTo({
  84. url: url
  85. });
  86. }
  87. }
  88. };
  89. </script>
  90. <style lang="scss" scoped>
  91. .icon {
  92. font-size: 32upx;
  93. }
  94. .index {
  95. background-color: #f6f6f6;
  96. }
  97. .search {
  98. width: 100%;
  99. padding: 0 5%;
  100. background-color: #ffffff;
  101. display: flex;
  102. padding: 30upx 0;
  103. align-items: center;
  104. justify-content: center;
  105. input{
  106. width: 100%;
  107. }
  108. .item {
  109. display: flex;
  110. width: 76%;
  111. align-items: center;
  112. background-color: #f7f7f7;
  113. border: 1px solid #e8e8e8;
  114. border-radius: 40upx;
  115. padding: 10upx;
  116. padding-left: 20upx;
  117. .icon {
  118. margin-right: 10upx;
  119. }
  120. .inupt_p {
  121. color: #101010;
  122. font-size: 28upx;
  123. }
  124. }
  125. text {
  126. width: 10%;
  127. text-align: center;
  128. }
  129. }
  130. .new {
  131. padding: 30upx 5%;
  132. background-color: #ffffff;
  133. margin-bottom: 20upx;
  134. .title {
  135. font-size: 32upx;
  136. font-weight: 800;
  137. }
  138. .user {
  139. display: flex;
  140. padding: 22upx 0;
  141. align-items: center;
  142. image {
  143. width: 60upx;
  144. height: 60upx;
  145. border-radius: 50%;
  146. }
  147. .t1 {
  148. margin-left: 20upx;
  149. font-size: 28upx;
  150. color: #666666;
  151. font-weight: 800;
  152. }
  153. .t2 {
  154. margin-left: 20upx;
  155. font-size: 22upx;
  156. color: #999999;
  157. }
  158. }
  159. .info {
  160. font-size: 22upx;
  161. color: #555555;
  162. line-height: 48upx;
  163. display: -webkit-box;
  164. -webkit-line-clamp: 3;
  165. overflow: hidden;
  166. text-overflow: ellipsis;
  167. -webkit-box-orient: vertical;
  168. }
  169. }
  170. .images {
  171. text-align: center;
  172. image {
  173. max-width: 100%;
  174. }
  175. }
  176. </style>