articleDetails.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. <template>
  2. <view class="container">
  3. <view class="contents">
  4. <view class="flex align-center margin-bottom-sm" style="color: #FBC600;" @click="callback">
  5. <image style="width: 50rpx;height: 50rpx;margin-right: 10rpx;" src="../../static/index/callback.png" mode=""></image>返回首页
  6. </view>
  7. <view class="article">
  8. <view class="article-title">{{articleDetail.title}}</view>
  9. <view class="article-browse">
  10. <text class="text-left">
  11. {{articleDetail.virtual_view + articleDetail.view}}人浏览
  12. </text>
  13. <text class="text-right">
  14. {{articleDetail.created_at}}
  15. </text>
  16. </view>
  17. <view class="article-content">
  18. <fengparse :content="articleDetail.content == null? '暂无文章数据' : articleDetail.content" @preview="preview" @navigate="navigate"
  19. className="articleDetailContent" />
  20. </view>
  21. <view class="article-view">
  22. </view>
  23. </view>
  24. </view>
  25. <!-- 底部tab -->
  26. <view class="article-foot">
  27. <button class="article-foot-item" @click="collect">
  28. <view class="foot-item-img">
  29. <image class="item-img" :src="collectStatu == 0 ? '../../static/index/collect.png':'../../static/index/collect-active.png'" />
  30. </view>
  31. <view class="foot-item-title">
  32. {{collectStatu == 0 ? '收藏':'已收藏'}}
  33. </view>
  34. </button>
  35. <button class="article-foot-item" v-if="isshare()" @click="shareartic">
  36. <view class="foot-item-img">
  37. <image class="item-img" src="../../static/index/share.png" />
  38. </view>
  39. <view class="foot-item-title">转发</view>
  40. </button>
  41. </view>
  42. <!-- 获取微信信息弹窗框 -->
  43. <view class="cu-modal" :class="modalName == 'WxModal' ? 'show' : ''">
  44. <view class="cu-dialog">
  45. <view class="cu-bar bg-white justify-end">
  46. <view class="content">您还未登录</view>
  47. <view class="action" @tap="modalName = ''">
  48. <text class="cuIcon-close yellow" />
  49. </view>
  50. </view>
  51. <view class="padding-xl">
  52. <view class="top-title" style="">
  53. <!-- <text class="top-title1">您还未登录</text></br> -->
  54. <text class="top-title1">请先登录再进行操作</text>
  55. </view>
  56. <view class="flex justify-around">
  57. <button type="primary" @tap="modalName = ''" class="cu-btn round greyBg lg">暂不登录</button>
  58. <button type="primary" @click="gotologin" class="cu-btn round yellowBg lg" hover-class="btn-hover">立刻登录</button>
  59. </view>
  60. </view>
  61. </view>
  62. </view>
  63. <view class="app_share" v-if="isshow">
  64. <view class="app_arrow">
  65. </view>
  66. <view class="app_item">
  67. <image src="../../static/index/fork_white.png" style="width: 72rpx;height: 72rpx;" @click="isshow=false" mode=""></image>
  68. <view class="app_title">
  69. 点击右上角选择发送给朋友
  70. </view>
  71. </view>
  72. </view>
  73. </view>
  74. </template>
  75. <script>
  76. var user = require('../../common/user.js');
  77. import {
  78. mapState,
  79. mapMutations,
  80. mapGetters,
  81. mapActions
  82. } from 'vuex';
  83. import fengparse from '@/components/feng-parse/parse.vue'
  84. export default {
  85. name: 'articleDetails',
  86. components: {
  87. // uParse
  88. fengparse
  89. },
  90. data() {
  91. return {
  92. modalName: null,
  93. collectStatu: 0, // 收藏状态
  94. articleDetail: {},
  95. articleDetailId: null, //文章id
  96. isshow: false,
  97. artictitle: ""
  98. }
  99. },
  100. // // 页面分享
  101. // onShareAppMessage: function() {
  102. // let that = this;
  103. // return {
  104. // title: that.articleDetail.title,
  105. // desc: that.articleDetail.title,
  106. // path: '/pages/index/index?articleId=' + this.articleDetailId + '&up_id=' + this.user.id
  107. // };
  108. // },
  109. onLoad(options) {
  110. this.articleDetailId = options.id;
  111. this.articleDetailInfo(this.articleDetailId)
  112. //#ifdef H5
  113. if (window.location.href.split("&")[1] != undefined) {
  114. let id = window.location.href.split("&")[1].split("=")[1]
  115. console.log(parseInt(id))
  116. uni.setStorageSync('up_id', id)
  117. }
  118. //#endif
  119. },
  120. computed: {
  121. ...mapGetters({
  122. hasLogin: 'verifyJwt'
  123. }),
  124. ...mapState(['user'])
  125. },
  126. mounted() {
  127. },
  128. methods: {
  129. ...mapActions({
  130. getUser: 'getUser' // 将 `this.getUser()` 映射为 `this.$store.dispatch('getUser')`
  131. }),
  132. callback(){
  133. uni.switchTab({
  134. url:"/pages/index/index"
  135. })
  136. },
  137. articleDetailInfo(id) {
  138. this.$request.get('/api/Article/articleDetail?id=' + id).then(res => {
  139. if (res.code == 200) {
  140. this.articleDetail = res.data
  141. console.log(this.articleDetail)
  142. this.articleDetail.content = this.articleDetail.content.replace(
  143. /<span style="font-family: "Source Sans Pro", "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 14px;">/ig,
  144. '<span>')
  145. this.collectStatu = res.data.favorite
  146. this.sharefun(res.data.title, this.user.id)
  147. } else {
  148. uni.showToast({
  149. icon: 'none',
  150. title: res.message
  151. });
  152. }
  153. });
  154. },
  155. shareartic() {
  156. if (!this.hasLogin) {
  157. uni.navigateTo({
  158. url: "../login/login",
  159. fail: (err) => {
  160. console.log(err)
  161. }
  162. })
  163. return;
  164. }
  165. this.isshow = true
  166. },
  167. sharefun(artictitle, id) {
  168. if (!this.hasLogin) {
  169. return false;
  170. }
  171. if (this.$wechat.is_weixin()) {
  172. this.$wechat.share({
  173. title: artictitle,
  174. desc: '点击查看详情',
  175. imgUrl: "https://zhengda.oss-cn-chengdu.aliyuncs.com/juyin/static/index/20201222144544.png",
  176. }, window.location.href, id, false)
  177. }
  178. },
  179. isshare() {
  180. if (this.$util.is_weixin()) {
  181. return true
  182. } else {
  183. return false
  184. }
  185. },
  186. // 收藏
  187. async collect() {
  188. if (!this.hasLogin) {
  189. uni.navigateTo({
  190. url: "../login/login",
  191. fail: (err) => {
  192. console.log(err)
  193. }
  194. })
  195. return;
  196. }
  197. let url = ''
  198. if (this.collectStatu == 0) {
  199. url = '/api/Article/addfavorite?id=' + this.articleDetailId
  200. } else {
  201. url = '/api/article/deleteFavroite?id=' + this.articleDetailId
  202. }
  203. let res = await this.$request.get(url);
  204. console.log(res)
  205. if (res.code == 200) {
  206. uni.showToast({
  207. title: res.messaged
  208. })
  209. this.articleDetailInfo(this.articleDetailId)
  210. } else {
  211. uni.showToast({
  212. icon: 'none',
  213. title: res.message
  214. })
  215. }
  216. },
  217. share: function() {
  218. if (!this.hasLogin) {
  219. uni.navigateTo({
  220. url: "../login/login",
  221. fail: (err) => {
  222. console.log(err)
  223. }
  224. })
  225. return;
  226. }
  227. },
  228. gotologin() {
  229. this.modalName = '';
  230. uni.navigateTo({
  231. url: "../login/login",
  232. fail: (err) => {
  233. console.log(err)
  234. }
  235. })
  236. }
  237. // wxLogin: function(e) {
  238. // console.log(e)
  239. // if (e.detail.userInfo == undefined) {
  240. // uni.showToast({
  241. // title: '微信登录失败'
  242. // });
  243. // return;
  244. // }
  245. // this.modalName = ''
  246. // user.loginByWeixin(e.detail.userInfo)
  247. // .then(res => {
  248. // this.getUser(true);
  249. // })
  250. // .catch(res => {
  251. // console.info(res)
  252. // uni.showToast({
  253. // title: '微信登录失败'
  254. // });
  255. // });
  256. // }
  257. }
  258. }
  259. </script>
  260. <style lang="scss">
  261. @import url("@/components/feng-parse/parse.css");
  262. .app_share {
  263. background-color: #000000;
  264. opacity: 1;
  265. border-radius: 15px;
  266. position: fixed;
  267. z-index: 9999;
  268. top: 16rpx;
  269. right: 6rpx;
  270. height: 72rpx;
  271. }
  272. .app_arrow {
  273. width: 0;
  274. height: 0;
  275. border-right: 16rpx solid transparent;
  276. border-left: 16rpx solid transparent;
  277. position: absolute;
  278. top: -11rpx;
  279. right: 45rpx;
  280. border-bottom: 6px solid #000000;
  281. opacity: 1;
  282. }
  283. .app_item {
  284. display: flex;
  285. align-items: center;
  286. flex-direction: row;
  287. flex-wrap: nowrap;
  288. }
  289. .app_title {
  290. color: #ffffff;
  291. margin: 0 28rpx;
  292. font-size: 28rpx;
  293. display: flex;
  294. align-items: center;
  295. }
  296. .greyBg {
  297. background: grey !important;
  298. }
  299. .container {
  300. width: 100vw;
  301. background: #FFFFFF;
  302. .contents {
  303. padding: 5vw;
  304. .article {
  305. background: #fff;
  306. border-radius: 5px;
  307. .article-title {
  308. font-size: 20px;
  309. margin-bottom: 15px;
  310. }
  311. .article-img {
  312. display: flex;
  313. justify-content: center;
  314. align-items: center;
  315. }
  316. .article-browse {
  317. display: flex;
  318. justify-content: space-between;
  319. color: #999999;
  320. border-bottom: 1px solid;
  321. }
  322. .article-content {
  323. margin: 10px 0;
  324. text-align: center;
  325. .articleDetailContent {
  326. text-align: left;
  327. }
  328. }
  329. .article-view {
  330. width: 100%;
  331. height: 150rpx;
  332. }
  333. }
  334. }
  335. .article-foot {
  336. display: flex;
  337. justify-content: space-around;
  338. position: fixed;
  339. left: 0;
  340. bottom: 0;
  341. z-index: 9;
  342. background: #fff;
  343. width: 100%;
  344. height: 50px;
  345. border-top: 1px solid #eee;
  346. .article-foot-item {
  347. width: 90px;
  348. heigth: 50px;
  349. margin: 0;
  350. padding: 0;
  351. color: #999;
  352. font-size: 15px;
  353. background: #fff;
  354. &:after {
  355. border: none;
  356. }
  357. .foot-item-img {
  358. padding: 3px 0;
  359. display: flex;
  360. justify-content: center;
  361. align-items: center;
  362. .item-img {
  363. width: 50rpx;
  364. height: 50rpx;
  365. }
  366. }
  367. .foot-item-title {
  368. width: 100%;
  369. height: 15px;
  370. line-height: 15px;
  371. text-align: center;
  372. font-size: 14px;
  373. color: #a2a2a2;
  374. }
  375. }
  376. }
  377. .yellow {
  378. color: #f5cc57;
  379. }
  380. .yellowBg {
  381. background: #f5cc57 !important;
  382. }
  383. .top-title {
  384. margin-bottom: 15px;
  385. }
  386. .top-title .top-title1 {
  387. font-size: 19px;
  388. color: #000000;
  389. margin-top: 10px;
  390. }
  391. }
  392. </style>