index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  1. <template>
  2. <view class="content">
  3. <view class="top-content">
  4. <view class="search-box">
  5. <view class="inner">
  6. <image src="/static/images/icon_search.png" mode=""></image>
  7. <input type="text" v-model="searchValue" @confirm="doSearch" placeholder="输入关键字搜索" placeholder-class="placeholder">
  8. </view>
  9. </view>
  10. <view class="tag-box">
  11. <scroll-view scroll-x="true" >
  12. <view class="tag-scroll">
  13. <view v-for="(item,index) in cates" :key="index" @click="choseCate(item)" :class="choseCateId == item.cateId?'tag active':'tag'" >{{ item.cateName }}</view>
  14. </view>
  15. </scroll-view>
  16. </view>
  17. </view>
  18. <!-- 数据列表 -->
  19. <view class="prom-list">
  20. <mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
  21. <view class="item" v-for="(item,index) in dataList" :key="index">
  22. <view class="info-box" @click="showDetail(item)">
  23. <view class="info-text">
  24. <view class="title">{{ item.title }}</view>
  25. <view class="time">{{item.publishTime}}</view>
  26. </view>
  27. <image class="img" :src="item.imageUrl" mode="aspectFill"></image>
  28. </view>
  29. <view class="hand-box" >
  30. <view class="left" @click="showDetail(item)">
  31. <view class="head-box" v-if="item.viewsList!=null&&item.viewsList.length>0">
  32. <view class="head-item" v-for="(subitem,j) in item.viewsList" :key="j">
  33. <image class="img" :src="getImgSrc(subitem)" mode=""></image>
  34. </view>
  35. </view>
  36. <view class="hand-item">
  37. <image class="eyes" src="/static/images/icon_eyes.png" mode=""></image>
  38. <text class="text">{{item.views}}</text>
  39. </view>
  40. <view class="hand-item">
  41. <image class="share" src="/static/images/icon_share_gray.png" mode=""></image>
  42. <text class="text">0</text>
  43. </view>
  44. </view>
  45. <view class="share-btn" @click="openShare(item)">立即分享</view>
  46. </view>
  47. </view>
  48. </mescroll-body>
  49. </view>
  50. <!-- 分享弹窗 -->
  51. <u-popup :show="show" @close="closeShare" >
  52. <view class="share-content">
  53. <view class="share-inner">
  54. <view class="share-item" @click="wxShare">
  55. <image src="/static/images/icon_wx.png" mode=""></image>
  56. <text class="text">微信</text>
  57. </view>
  58. <view class="share-item" @click="wxLineShare">
  59. <image src="/static/images/icon_pyq.png" mode=""></image>
  60. <text class="text">朋友圈</text>
  61. </view>
  62. <!-- <view class="share-item">
  63. <image src="/static/images/icon_xcxhb.png" mode=""></image>
  64. <text class="text">小程序海报</text>
  65. </view>
  66. <view class="share-item">
  67. <image src="/static/images/icon_xccard.png" mode=""></image>
  68. <text class="text">小程序卡片</text>
  69. </view>
  70. <view class="share-item">
  71. <image src="/static/images/icon_code.png" mode=""></image>
  72. <text class="text">二维码</text>
  73. </view> -->
  74. <view class="share-item">
  75. <image src="/static/images/icon_copy_link.png" mode=""></image>
  76. <text class="text">复制链接</text>
  77. </view>
  78. </view>
  79. <view class="cancel-btn" @click="closeShare">取消</view>
  80. </view>
  81. </u-popup>
  82. </view>
  83. </template>
  84. <script>
  85. import { getArticleCate,getArticleList } from '@/api/article'
  86. import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
  87. import { qconfig } from '@/utils/config';
  88. export default {
  89. mixins: [MescrollMixin],
  90. data() {
  91. return {
  92. show:false,
  93. shareItem:null,
  94. cates:[],
  95. choseCateId:0,
  96. searchValue: '',
  97. mescroll:null,
  98. //下拉刷新
  99. downOption: {
  100. use:true,
  101. auto: true // 不自动加载 (mixin已处理第一个tab触发downCallback)
  102. },
  103. // 上拉加载的配置
  104. upOption: {
  105. onScroll:true,
  106. use: true, // 是否启用上拉加载; 默认true
  107. page: {
  108. num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
  109. size: 10 // 每页数据的数量,默认10
  110. },
  111. noMoreSize: 10, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
  112. empty: {
  113. icon:'/static/images/no_data.png',
  114. tip: '暂无数据'
  115. },
  116. textNoMore:'已经到底了'
  117. },
  118. // 列表数据
  119. dataList: [],
  120. defImg:"../../static/images/detault_head.jpg",
  121. }
  122. },
  123. onShow() {
  124. this.getArticleCate();
  125. },
  126. methods: {
  127. openShare(item) {
  128. this.show = true
  129. this.shareItem=item;
  130. },
  131. closeShare() {
  132. this.show = false
  133. },
  134. doSearch(){
  135. this.mescroll.resetUpScroll()
  136. },
  137. getArticleCate(){
  138. var that=this;
  139. let data = {};
  140. getArticleCate(data).then(
  141. res => {
  142. if(res.code==200){
  143. this.cates=res.data;
  144. }else{
  145. uni.showToast({
  146. icon:'none',
  147. title: "请求失败",
  148. });
  149. }
  150. },
  151. rej => {}
  152. );
  153. },
  154. mescrollInit(mescroll) {
  155. this.mescroll = mescroll;
  156. },
  157. /*下拉刷新的回调 */
  158. downCallback(mescroll) {
  159. mescroll.resetUpScroll()
  160. },
  161. upCallback(page) {
  162. //联网加载数据
  163. var that = this;
  164. var data = {
  165. keyword:this.searchValue,
  166. cateId:this.choseCateId,
  167. page: page.num,
  168. pageSize: page.size
  169. };
  170. getArticleList(data).then(res => {
  171. if(res.code==200){
  172. //设置列表数据
  173. if (page.num == 1) {
  174. that.dataList = res.data.list;
  175. } else {
  176. that.dataList = that.dataList.concat(res.data.list);
  177. }
  178. that.mescroll.endBySize(res.data.list.length, res.data.total);
  179. }else{
  180. uni.showToast({
  181. icon:'none',
  182. title: "请求失败",
  183. });
  184. that.dataList = null;
  185. that.mescroll.endErr();
  186. }
  187. });
  188. },
  189. // 关键词选择
  190. choseCate(item) {
  191. this.choseCateId = item.cateId;
  192. this.mescroll.resetUpScroll()
  193. },
  194. // 查看详情
  195. showDetail(item) {
  196. uni.navigateTo({
  197. url: './detail?articleId=' + item.articleId
  198. });
  199. },
  200. wxShare(){
  201. // #ifdef APP-PLUS
  202. if(!plus.runtime.isAgreePrivacy()) {
  203. uni.showToast({
  204. title: "请同意隐私政策",
  205. icon: "none",
  206. position: 'top',
  207. duration: 2000
  208. })
  209. return;
  210. }
  211. // #endif
  212. uni.share({
  213. provider: "weixin",
  214. scene: "WXSceneSession",
  215. type: 5,
  216. imageUrl: this.shareItem.imageUrl, //分享封面图片
  217. title: this.shareItem.title, // 分享标题
  218. //summary: "微信分享示例", // 分享内容文字
  219. miniProgram:{
  220. id:qconfig.miniProgramId,
  221. path:"pages/healthy/detail?articleId="+this.shareItem.articleId,
  222. type:0,//0-正式版; 1-测试版; 2-体验版。 默认值为0。
  223. webUrl:"https://uniapp.dcloud.io"
  224. },
  225. success: function(res) {
  226. uni.showToast({
  227. title: "分享成功",
  228. icon: 'none'
  229. });
  230. },
  231. fail: function(err) {
  232. // 此处是调起微信分享失败的回调
  233. }
  234. });
  235. },
  236. wxLineShare(){
  237. },
  238. getImgSrc(item){
  239. var imgSrc=this.defImg;
  240. if(item!=null && item.avatar!=null){
  241. imgSrc=item.avatar;
  242. }
  243. return imgSrc;
  244. }
  245. }
  246. }
  247. </script>
  248. <style lang="scss">
  249. page{
  250. background-color: #F7F7F7;
  251. }
  252. </style>
  253. <style scoped lang="scss">
  254. .top-content{
  255. width: 100%;
  256. position: fixed;
  257. top: 0;
  258. left: 0;
  259. z-index: 11;
  260. background: #FFFFFF;
  261. .search-box{
  262. height: 104upx;
  263. padding: 0 30upx;
  264. display: flex;
  265. align-items: center;
  266. .inner{
  267. box-sizing: border-box;
  268. width: 100%;
  269. height: 72upx;
  270. background: #F7F7F7;
  271. border-radius: 36upx;
  272. display: flex;
  273. align-items: center;
  274. padding: 0 30upx;
  275. image{
  276. width: 28upx;
  277. height: 28upx;
  278. margin-right: 20upx;
  279. }
  280. input{
  281. font-size: 28upx;
  282. font-family: PingFang SC;
  283. font-weight: 500;
  284. flex: 1;
  285. }
  286. .placeholder{
  287. font-size: 28upx;
  288. font-family: PingFang SC;
  289. font-weight: 500;
  290. color: #BBBBBB;
  291. }
  292. }
  293. }
  294. .tag-box{
  295. height: 106upx;
  296. padding: 0 30upx;
  297. .tag-scroll{
  298. height: 106upx;
  299. display: flex;
  300. align-items: center;
  301. .tag{
  302. flex-shrink: 0;
  303. height: 58upx;
  304. line-height: 56upx;
  305. padding: 0 24upx;
  306. background: #F5FFFE;
  307. border: 2upx solid #8AD5CE;
  308. border-radius: 14upx;
  309. font-size: 28upx;
  310. font-family: PingFang SC;
  311. font-weight: 500;
  312. color: #FF5C03;
  313. margin-right: 20upx;
  314. &:last-child{
  315. margin-right: 0;
  316. }
  317. &.active{
  318. color: #FFFFFF;
  319. background: #2BC7B9;
  320. border: 1px solid #2BC7B9;
  321. }
  322. }
  323. }
  324. }
  325. }
  326. .prom-list{
  327. padding: 230upx 20upx 20upx;
  328. .item{
  329. background: #FFFFFF;
  330. border-radius: 16upx;
  331. margin-bottom: 20upx;
  332. padding: 40upx 30upx;
  333. &:last-child{
  334. margin-bottom: 0;
  335. }
  336. .info-box{
  337. display: flex;
  338. align-items: center;
  339. justify-content: space-between;
  340. .info-text{
  341. width: calc(100% - 254upx);
  342. height: 170upx;
  343. display: flex;
  344. flex-direction: column;
  345. justify-content: space-between;
  346. .title{
  347. font-size: 32upx;
  348. font-family: PingFang SC;
  349. font-weight: bold;
  350. color: #111111;
  351. line-height: 50upx;
  352. overflow: hidden;
  353. text-overflow: ellipsis;
  354. display: -webkit-box;
  355. -webkit-line-clamp: 2;
  356. -webkit-box-orient: vertical;
  357. }
  358. .time{
  359. font-size: 24upx;
  360. font-family: PingFang SC;
  361. font-weight: 500;
  362. color: #999999;
  363. line-height: 1;
  364. }
  365. }
  366. .img{
  367. width: 224upx;
  368. height: 171upx;
  369. background: #E0E0E0;
  370. border-radius: 16upx;
  371. overflow: hidden;
  372. }
  373. }
  374. .hand-box{
  375. margin-top: 50upx;
  376. display: flex;
  377. align-items: center;
  378. justify-content: space-between;
  379. .left{
  380. display: flex;
  381. align-items: center;
  382. .head-box{
  383. display: flex;
  384. margin-right: 26upx;
  385. .head-item{
  386. width: 48upx;
  387. height: 48upx;
  388. background: #F6F7FB;
  389. border: 2upx solid #FFFFFF;
  390. border-radius: 50%;
  391. overflow: hidden;
  392. margin-left: -10upx;
  393. &:first-child{
  394. margin-left: 0;
  395. }
  396. .img{
  397. width: 100%;
  398. height: 100%;
  399. }
  400. }
  401. }
  402. .hand-item{
  403. display: flex;
  404. align-items: center;
  405. margin-right: 40upx;
  406. &:last-child{
  407. margin-right: 0;
  408. }
  409. .eyes{
  410. width: 27upx;
  411. height: 22upx;
  412. margin-right: 18upx;
  413. }
  414. .share{
  415. width: 24upx;
  416. height: 24upx;
  417. margin-right: 12upx;
  418. }
  419. .text{
  420. font-size: 24upx;
  421. font-family: PingFang SC;
  422. font-weight: 500;
  423. color: #999999;
  424. line-height: 1;
  425. }
  426. }
  427. }
  428. .share-btn{
  429. padding: 0 25upx;
  430. height: 60upx;
  431. line-height: 60upx;
  432. background: #FF5C03;
  433. border-radius: 12upx;
  434. font-size: 26upx;
  435. font-family: PingFang SC;
  436. font-weight: 500;
  437. color: #FFFFFF;
  438. }
  439. }
  440. }
  441. }
  442. .share-content{
  443. background-color: #FFF;
  444. border-radius: 40upx 40upx 0px 0px;
  445. .share-inner{
  446. padding: 70upx 0 0 0;
  447. display: flex;
  448. flex-wrap: wrap;
  449. .share-item{
  450. width: 25%;
  451. display: flex;
  452. flex-direction: column;
  453. align-items: center;
  454. justify-content: center;
  455. margin-bottom: 66upx;
  456. image{
  457. width: 80upx;
  458. height: 80upx;
  459. margin-bottom: 20upx;
  460. }
  461. .text{
  462. font-size: 28upx;
  463. font-family: PingFang SC;
  464. font-weight: 500;
  465. color: #111111;
  466. line-height: 1;
  467. }
  468. }
  469. }
  470. .cancel-btn{
  471. height: 96upx;
  472. line-height: 96upx;
  473. text-align: center;
  474. font-size: 32upx;
  475. font-family: PingFang SC;
  476. font-weight: 500;
  477. color: #111111;
  478. border-top: 2upx solid #E8E8E8;
  479. background-color: #FFF;
  480. }
  481. }
  482. </style>