newsSquare.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. <template>
  2. <view class="content">
  3. <view class="addNewsBtn" @click="toPublishPage()" v-if="isLogin">
  4. <view class="addIcon">
  5. +
  6. </view>
  7. <view class="addText">
  8. 帮忙
  9. </view>
  10. </view>
  11. <view class="searchModal" v-show="searchModal">
  12. <div class="textTips">
  13. <text>搜索历史</text>
  14. <image src="../../static/image/del.png" class="del" @click="clearHistory()"></image>
  15. </div>
  16. <div class="serachBox">
  17. <div class="serachItem" @click="searchKey(item)" v-for="(item,index) in historySearch" :key="index">
  18. {{ item }}
  19. </div>
  20. </div>
  21. </view>
  22. <z-paging ref="paging" refresher-only @onRefresh="onRefresh" :refresher-status.sync="refresherStatus"
  23. @scrolltolower="scrolltolower" :auto-hide-loading-after-first-loaded="false" :loading-full-fixed="true"
  24. :auto-clean-list-when-reload="false">
  25. <view slot="loading">
  26. </view>
  27. <!-- 自定义下拉刷新view -->
  28. <!-- <custom-refresher slot="refresher" :status="refresherStatus"></custom-refresher> -->
  29. <view class="header">
  30. <uni-easyinput class="input" prefixIcon="search" placeholder="请输入关键字查询" @focus="inputFocus()"
  31. @confirm="inputConfirm()" v-model="keyword" :clearable="false"></uni-easyinput>
  32. <view class="myNews" @click="toMyNews">我的求助</view>
  33. <view class="closeModalBox" @click="closeSearchModal" v-show="searchModal">
  34. 取消
  35. </view>
  36. </view>
  37. <view>
  38. <uni-notice-bar @click="toLogin" v-if="!isLogin" single showIcon text="当前未登录,如需提交问题请点击此处登录~">
  39. </uni-notice-bar>
  40. <view style="z-index: 100;position: sticky;top :44px;">
  41. <tabs-view @change="tabsChange" :current="current" :items="tabList"></tabs-view>
  42. </view>
  43. <swiper class="swiper" :style="[{ height: swiperHeight + 'px' }]" :current="current"
  44. @animationfinish="animationfinish">
  45. <swiper-item class="swiper-item" v-for="(item, index) in tabList" :key="index">
  46. <news-list ref="swiperList" :tabIndex="index" :currentIndex="current" :title="title"
  47. @heightChanged="heightChanged"></news-list>
  48. </swiper-item>
  49. </swiper>
  50. </view>
  51. </z-paging>
  52. </view>
  53. </template>
  54. <script>
  55. export default {
  56. data() {
  57. return {
  58. refresherStatus: 0,
  59. swiperHeight: 0,
  60. tabList: ['发布', '热线', '嗨享'],
  61. current: 0, // tabs组件的current值,表示当前活动的tab选项
  62. searchModal: false,
  63. historySearch: [],
  64. title: '',
  65. keyword: '',
  66. isLogin: false
  67. };
  68. },
  69. onShow() {
  70. let user = null;
  71. try {
  72. user = JSON.parse(uni.getStorageSync('userInfo'));
  73. } catch (e) {
  74. //TODO handle the exception
  75. }
  76. if (!user) return
  77. this.isLogin = true
  78. },
  79. methods: {
  80. toPublishPage() {
  81. uni.navigateTo({
  82. url: '../publishNews/publishNews'
  83. })
  84. },
  85. toMyNews() {
  86. uni.navigateTo({
  87. url: '/pages/myNews/myNews'
  88. })
  89. },
  90. clearHistory() {
  91. uni.removeStorageSync('historySearch');
  92. this.historySearch = []
  93. },
  94. toLogin() {
  95. uni.navigateTo({
  96. url: '/pages/Login/Login?choose=1'
  97. });
  98. },
  99. inputConfirm(e) {
  100. this.title = e
  101. let historyArr = JSON.parse(JSON.stringify(this.historySearch))
  102. if (historyArr.length >= 8) {
  103. historyArr.pop(1)
  104. }
  105. historyArr.unshift(e)
  106. historyArr = [...new Set(historyArr)]
  107. this.historySearch = historyArr
  108. this.$nextTick(() => {
  109. this.onRefresh()
  110. })
  111. uni.setStorageSync('historySearch', JSON.stringify(this.historySearch));
  112. this.closeSearchModal()
  113. },
  114. searchKey(e) {
  115. this.title = e
  116. this.keyword = e
  117. this.$nextTick(() => {
  118. this.onRefresh()
  119. })
  120. this.closeSearchModal()
  121. },
  122. inputFocus() {
  123. try {
  124. let searchStr = uni.getStorageSync('historySearch')
  125. this.historySearch = searchStr ? JSON.parse(searchStr) : []
  126. } catch (e) {
  127. this.historySearch = []
  128. }
  129. this.searchModal = true
  130. },
  131. closeSearchModal() {
  132. this.searchModal = false
  133. },
  134. //tabs通知swiper切换
  135. tabsChange(index) {
  136. this._setCurrent(index);
  137. },
  138. //下拉刷新时,通知当前显示的列表进行reload操作
  139. onRefresh() {
  140. this.$refs.swiperList[this.current].reload(() => {
  141. this.$refs.paging.complete([]);
  142. });
  143. },
  144. //当滚动到底部时,通知当前显示的列表加载更多
  145. scrolltolower() {
  146. this.$refs.swiperList[this.current].doLoadMore();
  147. },
  148. // swiper滑动结束
  149. animationfinish(e) {
  150. let current = e.detail.current;
  151. this._setCurrent(current);
  152. },
  153. //设置swiper的高度
  154. heightChanged(height) {
  155. if (height === 0) {
  156. //默认swiper高度为屏幕可用高度-tabsView高度-slot="top"内view的高度
  157. height = uni.getSystemInfoSync().windowHeight - uni.upx2px(80);
  158. }
  159. this.swiperHeight = height;
  160. },
  161. _setCurrent(current) {
  162. if (current !== this.current) {
  163. //切换tab时,将上一个tab的数据清空
  164. this.$refs.swiperList[this.current].clear();
  165. }
  166. this.current = current;
  167. }
  168. }
  169. };
  170. </script>
  171. <style scoped lang="scss">
  172. .loadingBox {
  173. width: 100%;
  174. height: 100%;
  175. display: flex;
  176. align-items: center;
  177. justify-content: center;
  178. background-color: red;
  179. }
  180. .addNewsBtn {
  181. position: fixed;
  182. width: 56px;
  183. height: 56px;
  184. right: 15px;
  185. border-radius: 50%;
  186. background-color: #3466EB;
  187. color: #FFFFFF;
  188. display: flex;
  189. flex-direction: column;
  190. align-items: center;
  191. bottom: 150px;
  192. // background-image: url('../../static/image/addNews.png');
  193. // background-position: center;
  194. // background-repeat: no-repeat;
  195. // background-size: 120%;
  196. z-index: 150;
  197. .addIcon {
  198. font-size: 30px;
  199. line-height: 30px;
  200. }
  201. .addText {
  202. font-size: 12px;
  203. }
  204. }
  205. .searchModal {
  206. position: absolute;
  207. top: 44px;
  208. right: 0;
  209. bottom: 0;
  210. left: 0;
  211. z-index: 200;
  212. background-color: #fff;
  213. box-sizing: border-box;
  214. padding: 0 15px;
  215. .textTips {
  216. display: flex;
  217. align-items: center;
  218. justify-content: space-between;
  219. margin-top: 15px;
  220. .del {
  221. width: 32rpx;
  222. height: 32rpx;
  223. }
  224. }
  225. .serachBox {
  226. display: flex;
  227. flex-wrap: wrap;
  228. .serachItem {
  229. margin-top: 20px;
  230. padding: 8rpx 16rpx;
  231. max-width: 100%;
  232. overflow: hidden;
  233. text-overflow: ellipsis;
  234. }
  235. }
  236. }
  237. .header {
  238. width: 100%;
  239. display: flex;
  240. justify-content: space-between;
  241. align-items: center;
  242. box-sizing: border-box;
  243. padding: 0 15px;
  244. height: 44px;
  245. position: sticky;
  246. z-index: 100;
  247. background-color: #FFFFFF;
  248. top: 0;
  249. .myNews {}
  250. .closeModalBox {
  251. position: absolute;
  252. right: 15px;
  253. width: 150rpx;
  254. background-color: #fff;
  255. height: 44px;
  256. line-height: 44px;
  257. text-align: right;
  258. }
  259. .input {
  260. width: 526rpx;
  261. }
  262. }
  263. .banner-view {
  264. background-color: #007aff;
  265. color: white;
  266. display: flex;
  267. flex-direction: column;
  268. align-items: center;
  269. justify-content: center;
  270. }
  271. .paging-content {
  272. flex: 1;
  273. display: flex;
  274. flex-direction: column;
  275. }
  276. .swiper {
  277. height: 1000px;
  278. }
  279. </style>