searchArt.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. <template>
  2. <view class="content">
  3. <!--搜索 start-->
  4. <view class="Search-box" @click="">
  5. <view class="Search-box-size">
  6. <image class="box-img" src="../../static/img/img01.png"></image>
  7. <input type="text" class="box-word" placeholder="请输入关键字" v-model="keyword" />
  8. </view>
  9. <view class="Search-box-sort" @click="getList('click')">搜索</view>
  10. </view>
  11. <!-- 搜索 end-->
  12. <!-- 补位 -->
  13. <view class="" style="height: 100rpx;"></view>
  14. <!-- 文章列表 start-->
  15. <view class="art-list">
  16. <template v-for="item in list">
  17. <!-- 文章图片为一 -->
  18. <view class="art-item-one flex art-item" v-if="item.image_input.length == 1"
  19. @click="goToDetail(item.id)">
  20. <view class="art-left flex">
  21. <view class="art-tit clamp2">
  22. {{item.title}}
  23. </view>
  24. <view class="art-time">
  25. <image src="../../static/icon/hot.png" mode="" class="hot" v-if="item.is_hot == 1"></image>
  26. <text class="store-name">{{item.mername}}</text><text
  27. class="pl">{{item.comment}}评论</text><text
  28. class="creat-time">{{item.add_time | showTime}}</text>
  29. </view>
  30. </view>
  31. <view class="art-right">
  32. <image :src="item.image_input" mode=""></image>
  33. </view>
  34. </view>
  35. <!-- 文章图片为零 -->
  36. <view class="art-item-zero flex art-item" v-if="item.image_input.length == 0"
  37. @click="goToDetail(item.id)">
  38. <view class="art-tit clamp2">
  39. {{item.title}}
  40. </view>
  41. <view class="art-time">
  42. <image src="../../static/icon/hot.png" mode="" class="hot"></image><text
  43. class="store-name">{{item.mername}}</text><text class="pl">{{item.comment}}评论</text><text
  44. class="creat-time">{{item.add_time | showTime}}</text>
  45. </view>
  46. </view>
  47. <!-- 文章图片大于一 -->
  48. <view class="art-item-three art-item flex" v-if="item.image_input.length > 1"
  49. @click="goToDetail(item.id)">
  50. <view class="art-tit clamp2">
  51. {{item.title}}
  52. </view>
  53. <view class="art-img-list">
  54. <image :src="imgitem" mode="" v-for="imgitem in item.image_input"></image>
  55. </view>
  56. <view class="art-time">
  57. <image src="../../static/icon/hot.png" mode="" class="hot"></image><text
  58. class="store-name">{{item.mername}}</text><text class="pl">{{item.comment}}评论</text><text
  59. class="creat-time">{{item.add_time | showTime}}</text>
  60. </view>
  61. </view>
  62. </template>
  63. </view>
  64. <!-- 文章列表 start-->
  65. <!-- <empty v-if=" list.length === 0"></empty> -->
  66. </view>
  67. </template>
  68. <script>
  69. import {
  70. searchArt
  71. } from '@/api/art.js'
  72. import empty from '@/components/empty';
  73. import {
  74. timeComputed
  75. } from '@/utils/rocessor.js';
  76. export default {
  77. components: {
  78. // uniLoadMore,
  79. empty
  80. },
  81. data() {
  82. return {
  83. list: [],
  84. page: 1,
  85. limit: 20,
  86. loadingType: 'more',
  87. keyword: '',
  88. }
  89. },
  90. onReachBottom() {
  91. this.getList()
  92. },
  93. filters: {
  94. showTime(val) {
  95. let str = ''
  96. if (val) {
  97. let time = timeComputed(val * 1000);
  98. console.log(time)
  99. if (time.day > 0) {
  100. return str = time.day + '天前'
  101. } else if (time.hour > 0) {
  102. return str = time.hour + '小时前'
  103. } else if (time.minutes > 0) {
  104. return str = time.minutes + '分钟前'
  105. } else {
  106. return str = time.seconds + '秒前'
  107. }
  108. }
  109. return str
  110. }
  111. },
  112. methods: {
  113. goToDetail(id) {
  114. uni.navigateTo({
  115. url: '/pages/user/article?id=' + id
  116. })
  117. },
  118. navTo(url) {
  119. uni.navigateTo({
  120. url
  121. })
  122. },
  123. getList(type) {
  124. let obj = this
  125. if (type == 'click') {
  126. obj.list = []
  127. obj.page = 1
  128. obj.loadingType = 'more'
  129. }
  130. if (obj.loadingType == 'loading' || obj.loadingType == 'noMore') {
  131. return
  132. }
  133. obj.loadingType = 'loading'
  134. searchArt({
  135. page: obj.page,
  136. rows: 20,
  137. search: obj.keyword
  138. }).then(res => {
  139. console.log(res)
  140. obj.list = obj.list.concat(res.data.list)
  141. obj.page++
  142. if (obj.limit = res.data.list) {
  143. obj.loadingType = 'more'
  144. } else {
  145. obj.loadingType = 'noMore'
  146. }
  147. })
  148. },
  149. }
  150. }
  151. </script>
  152. <style lang="scss" scoped>
  153. .content {
  154. background-color: #fff;
  155. }
  156. .Search-box {
  157. position: absolute;
  158. top: 0;
  159. width: 750rpx;
  160. padding-left: 20rpx;
  161. padding-right: 20rpx;
  162. height: 100rpx;
  163. background: #ffffff;
  164. display: flex;
  165. justify-content: space-around;
  166. align-items: center;
  167. .Search-box-sort {
  168. font-size: 30rpx;
  169. flex-shrink: 0;
  170. font-weight: 500;
  171. color: rgba(102, 102, 102, 1);
  172. .sort-text {
  173. width: 57rpx;
  174. height: 29rpx;
  175. font-size: 30rpx;
  176. font-weight: 500;
  177. color: rgba(51, 51, 51, 1);
  178. line-height: 58rpx;
  179. margin-right: 19rpx;
  180. }
  181. .sort-img {
  182. width: 21rpx;
  183. height: 11rpx;
  184. margin-bottom: 4rpx;
  185. }
  186. }
  187. .Search-box-size {
  188. width: 605rpx;
  189. height: 65rpx;
  190. border-radius: 32rpx;
  191. background-color: #f1f1f1;
  192. padding-left: 36rpx;
  193. display: flex;
  194. align-items: center;
  195. .box-img {
  196. height: 32rpx;
  197. width: 32rpx;
  198. margin-right: 16rpx;
  199. }
  200. .box-word {
  201. width: 100%;
  202. font-size: 22rpx;
  203. font-weight: 500;
  204. color: rgba(205, 203, 203, 1);
  205. line-height: 55rpx;
  206. color: #000000;
  207. }
  208. }
  209. }
  210. .dy-wrap {
  211. width: 707rpx;
  212. background: #fff;
  213. margin: auto;
  214. border-bottom: #E9E9E9 solid 1px;
  215. padding: 20rpx 0;
  216. .user-logo {
  217. flex-shrink: 0;
  218. height: 100rpx;
  219. width: 100rpx;
  220. border-radius: 50%;
  221. image {
  222. width: 100%;
  223. height: 100%;
  224. border-radius: 50%;
  225. }
  226. }
  227. .user-num {
  228. flex-grow: 1;
  229. padding-left: 10rpx;
  230. font-size: 24rpx;
  231. font-weight: 500;
  232. color: #999999;
  233. .user-name {
  234. font-size: 34rpx;
  235. font-weight: 600;
  236. color: #333333;
  237. padding-right: 20rpx;
  238. padding: 0 20rpx 20rpx 0;
  239. }
  240. }
  241. .dy-btn {
  242. flex-shrink: 0;
  243. text-align: center;
  244. width: 136rpx;
  245. line-height: 66rpx;
  246. border-radius: 10rpx;
  247. font-size: 28rpx;
  248. font-weight: 500;
  249. background: #E6645F;
  250. color: #fff;
  251. }
  252. .dying {
  253. color: #999999;
  254. background: #E9E9E9;
  255. }
  256. }
  257. .art-list {
  258. background-color: #fff;
  259. width: 750rpx;
  260. font-size: 31rpx;
  261. font-weight: 500;
  262. color: #323232;
  263. // font-weight: bold;
  264. }
  265. .art-item {
  266. width: 691rpx;
  267. border-bottom: #E1E1E1 1px solid;
  268. margin: auto;
  269. }
  270. .art-item-zero {
  271. height: 153rpx;
  272. flex-direction: column;
  273. justify-content: space-between;
  274. align-items: flex-start;
  275. padding: 20rpx 0;
  276. border-bottom: #E1E1E1 1px solid;
  277. }
  278. .art-item-one {
  279. height: 195rpx;
  280. margin: auto;
  281. padding: 30rpx 0 20rpx;
  282. .art-left {
  283. height: 100%;
  284. flex-direction: column;
  285. justify-content: space-between;
  286. align-items: flex-start;
  287. padding-right: 40rpx;
  288. }
  289. .art-right {
  290. width: 227rpx;
  291. height: 145rpx;
  292. border-radius: 10rpx;
  293. flex-shrink: 0;
  294. image {
  295. width: 100%;
  296. height: 100%;
  297. border-radius: 10rpx;
  298. }
  299. }
  300. }
  301. .art-item-three {
  302. height: 345rpx;
  303. flex-direction: column;
  304. justify-content: space-between;
  305. align-items: flex-start;
  306. padding: 30rpx 0;
  307. .art-img-list {
  308. width: 100%;
  309. height: 145rpx;
  310. // background-color: #bfa;
  311. // border-radius: 10px;
  312. image {
  313. width: 220rpx;
  314. height: 145rpx;
  315. border-radius: 10rpx;
  316. margin-right: 15rpx;
  317. &:last-child {
  318. margin-right: 0;
  319. }
  320. }
  321. }
  322. }
  323. .hot {
  324. width: 22rpx;
  325. height: 22rpx;
  326. margin-right: 10rpx;
  327. }
  328. .art-time {
  329. display: inline-block;
  330. font-size: 24rpx;
  331. font-weight: 500;
  332. color: #7F8699;
  333. text {
  334. margin-right: 10rpx;
  335. }
  336. }
  337. </style>