articleDetails.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. <template>
  2. <view>
  3. <u-navbar></u-navbar>
  4. <share-server ref="share" ></share-server>
  5. <!-- 新闻内容 -->
  6. <view class="content">
  7. <view class="title">
  8. {{info.title}}
  9. </view>
  10. <view class="infos">
  11. <view class="date">
  12. {{info.createTime}}
  13. </view>
  14. <view class="pageview" >
  15. <view class="icon">
  16. <u-icon name="eye" size="32"></u-icon>
  17. </view>
  18. <view class="number">
  19. {{info.hits}}
  20. </view>
  21. </view>
  22. </view>
  23. <view class="text news-content" v-html="info.content">
  24. </view>
  25. <view class="picture" v-if="info.pic">
  26. <img :src="info.pic" style="width: 100%;" alt="">
  27. </view>
  28. </view>
  29. <!-- 评论 -->
  30. <view class="comment" v-if="info.title&&info.listComment&&info.listComment.length" >
  31. <view class="title">
  32. 精华评论
  33. </view>
  34. <view class="comment-item" v-for="(item,i) in info.listComment" :key="i" >
  35. <view class="photo">
  36. <img v-if="item.headImg" :src="item.headImg" alt="">
  37. <u-avatar v-else size="80" ></u-avatar>
  38. </view>
  39. <view class="details">
  40. <view class="name-date">
  41. <view class="name" :class="{
  42. red:!item.name
  43. }" >
  44. {{item.name?item.name:'用户异常'}}
  45. </view>
  46. <view class="date">
  47. {{item.date}}
  48. </view>
  49. </view>
  50. <view class="comment-content">
  51. {{item.content}}
  52. <view class="mine" v-if="item.isMine">
  53. <view class="my-comment">
  54. 我的评论
  55. </view>
  56. <view class="delete" @click="newsCommentsdelete(item.id)">
  57. 删除
  58. </view>
  59. </view>
  60. </view>
  61. </view>
  62. </view>
  63. </view>
  64. <view class="bottom" v-if="userInfo" >
  65. <view class="input" @click="showMessage=true">
  66. <view class="inputT">发表评论</view>
  67. </view>
  68. <view class="like" :class="{
  69. red:info.iLike
  70. }" @click="changeLikes()">
  71. <view class="icon">
  72. <u-icon name="thumb-up" size="32"></u-icon>
  73. </view>
  74. <view class="number">
  75. {{info.likesNum}}
  76. </view>
  77. </view>
  78. </view>
  79. <view class="bottom" v-else >
  80. <view class="input" @click="issueMethod()">
  81. <view class="inputT">未登录,前往登录</view>
  82. </view>
  83. <view class="like" :class="{
  84. red:info.iLike
  85. }" >
  86. <view class="icon">
  87. <u-icon name="thumb-up" size="32"></u-icon>
  88. </view>
  89. <view class="number">
  90. {{info.likesNum}}
  91. </view>
  92. </view>
  93. </view>
  94. <u-popup v-model="showMessage" border-radius="34" mode="bottom" >
  95. <view class="showMessage">
  96. <view class="showMessage1"><h3>发表评论({{content.length}}/50)</h3></view>
  97. <view class="showMessage2">
  98. <textarea name="" id="" style=" width:100%"
  99. v-model="content" maxlength="50"
  100. cols="30" rows="5" placeholder="填写内容"></textarea>
  101. </view>
  102. <view class="showMessage3">
  103. <u-button type="primary" @click="submitMessage()">提交</u-button>
  104. </view>
  105. </view>
  106. </u-popup>
  107. </view>
  108. </template>
  109. <script>
  110. import * as API from '@/apis/pagejs/news.js'
  111. import ShareServer from '@/components/ShareServer.vue'
  112. export default {
  113. components: {
  114. ShareServer
  115. },
  116. data() {
  117. return {
  118. id:"",
  119. content:"",
  120. info:{},
  121. showMessage:false,
  122. userInfo:null,
  123. list:[],
  124. recordsTotal:0,
  125. }
  126. },
  127. onLoad(op){
  128. this.id=op.id
  129. this.userInfo=this.carhelp.getPersonInfo()
  130. this.getInfo(true)
  131. },
  132. methods: {
  133. issueMethod(){
  134. uni.showModal({
  135. title:"提示",
  136. content:"未登录,登录后参与评论",
  137. confirmText:"前往登录",
  138. showCancel:true,
  139. success: function (res) {
  140. if(res.confirm){
  141. uni.navigateTo({
  142. url:'/pages/login/index'
  143. })
  144. }
  145. }
  146. })
  147. },
  148. newsCommentsdelete(id){
  149. uni.showModal({
  150. title: '提示',
  151. content: '是否删除评论?',
  152. success: res=>{
  153. if (res.confirm) {
  154. this.newsCommentsdeletemethods(id)
  155. } else if (res.cancel) {
  156. //('用户点击取消');
  157. }
  158. }
  159. });
  160. },
  161. newsCommentsdeletemethods(id){
  162. uni.showLoading({
  163. title: "加载中",
  164. mask: true,
  165. })
  166. API.newsCommentsdelete(id).then((res) => {
  167. uni.showToast({
  168. title: "删除成功",
  169. icon: "none"
  170. })
  171. this.getInfo();
  172. }).catch(error => {
  173. uni.showToast({
  174. title: error,
  175. icon: "none"
  176. })
  177. })
  178. },
  179. submitMessage(){
  180. if(!this.content){
  181. uni.showToast({
  182. title: "请填写内容",
  183. icon: "none"
  184. })
  185. return
  186. }
  187. uni.showLoading({
  188. title: "加载中",
  189. mask: true,
  190. })
  191. API.commentNews({
  192. newsId:this.id,
  193. content:this.content,
  194. }).then((res) => {
  195. this.content=""
  196. uni.showToast({
  197. title: "提交成功",
  198. icon: "none"
  199. })
  200. this.showMessage=false
  201. this.getInfo();
  202. }).catch(error => {
  203. uni.showToast({
  204. title: error,
  205. icon: "none"
  206. })
  207. })
  208. },
  209. changeLikes(){
  210. uni.showLoading({
  211. title: "加载中",
  212. mask: true,
  213. })
  214. API.changeLikes({
  215. newsId:this.id
  216. }).then((res) => {
  217. uni.hideLoading();
  218. this.getInfo()
  219. }).catch(error => {
  220. uni.showToast({
  221. title: error,
  222. icon: "none"
  223. })
  224. })
  225. },
  226. getInfo(bl){
  227. if(bl){
  228. uni.showLoading({
  229. title: "加载中",
  230. mask: true,
  231. })
  232. }
  233. var userId=null
  234. if(this.userInfo){
  235. userId=this.userInfo.id
  236. }
  237. API.detail({
  238. id:this.id,
  239. userId:userId
  240. }).then((res) => {
  241. if(bl){
  242. uni.hideLoading();
  243. }
  244. this.info=res.data;
  245. this.$refs.share.setUrl("/pages/news/articleDetails?id="+this.id);
  246. this.$refs.share.setTitle(this.info.title,this.id);
  247. this.$nextTick(()=>{
  248. var list =document.getElementsByClassName("news-content")[0].getElementsByTagName("img");
  249. for(var i=0;i<list.length;i++){
  250. list[i].style='width: 100%;height: 100%;'
  251. }
  252. })
  253. }).catch(error => {
  254. uni.showToast({
  255. title: error,
  256. icon: "none"
  257. })
  258. })
  259. }
  260. }
  261. }
  262. </script>
  263. <style lang="scss" scoped>
  264. page{
  265. padding-bottom:100px;
  266. font-family: 'Regular';
  267. }
  268. // 新闻内容
  269. .content{
  270. padding: 32rpx 32rpx 48rpx 32rpx;
  271. background-color: #fff;
  272. .title{
  273. color: rgba(16, 16, 16, 1);
  274. font-size: 20px;
  275. text-align: justify;
  276. font-weight: 550;
  277. font-family: 'SemiBold';
  278. }
  279. .infos{
  280. display: flex;
  281. justify-content: space-between;
  282. padding: 24rpx 0 32rpx 0;
  283. border-bottom: 1px solid rgba(241, 241, 241, 1);
  284. color: rgba(119, 119, 119, 1);
  285. font-size: 12px;
  286. .pageview{
  287. display: flex;
  288. }
  289. .icon{
  290. margin-right:8rpx ;
  291. }
  292. }
  293. .text{
  294. margin-top: 40rpx;
  295. line-height: 28px;
  296. color: rgba(51, 51, 51, 1);
  297. }
  298. .picture{
  299. margin-top: 40rpx;
  300. img{
  301. width: 100%;
  302. height: 155px;
  303. }
  304. .pic-title{
  305. margin-top: 7px;
  306. color: rgba(119, 119, 119, 1);
  307. font-size: 12px;
  308. text-align: center;
  309. }
  310. }
  311. }
  312. .showMessage{
  313. padding: 60rpx 50rpx ;
  314. .showMessage2{
  315. background-color: #E5E7EA;
  316. margin: 40rpx 0;
  317. textarea{
  318. padding: 8rpx;
  319. border-radius:34px;
  320. }
  321. }
  322. }
  323. // 评论
  324. .comment{
  325. margin-top:24rpx;
  326. background-color: #fff;
  327. padding: 32rpx 32rpx 48rpx 32rpx;
  328. .title{
  329. color: rgba(51, 51, 51, 1);
  330. font-size: 18px;
  331. }
  332. .comment-item:last-of-type{
  333. .comment-content{
  334. border: none;
  335. }
  336. }
  337. .comment-item{
  338. display: flex;
  339. padding-top: 58rpx;
  340. .photo{
  341. margin-top: -12px;
  342. img{
  343. width: 80rpx;
  344. height: 80rpx;
  345. border-radius: 50px;
  346. }
  347. }
  348. .details{
  349. margin-left: 24rpx;
  350. width: 100%;
  351. .name-date{
  352. display: flex;
  353. justify-content: space-between;
  354. .name{
  355. color: rgba(51, 51, 51, 1);
  356. font-size: 16px;
  357. }
  358. .date{
  359. color: rgba(119, 119, 119, 1);
  360. font-size: 12px;
  361. }
  362. }
  363. }
  364. .comment-content{
  365. margin-top: 16rpx;
  366. color: rgba(51, 51, 51, 1);
  367. line-height: 20px;
  368. border-bottom: 1px solid rgba(232, 232, 232, 1);
  369. padding-bottom: 40rpx;
  370. .mine{
  371. margin-top: 16rpx;
  372. display: flex;
  373. justify-content: space-between;
  374. line-height: 20px;
  375. .my-comment{
  376. color: rgba(119, 119, 119, 1);
  377. font-size: 12px;
  378. border: 1px solid rgba(153, 153, 153, 1);
  379. padding: 0rpx 12rpx;
  380. border-radius: 4px;
  381. }
  382. .delete{
  383. color: rgba(119, 119, 119, 1);
  384. font-size: 12px;
  385. }
  386. }
  387. }
  388. }
  389. }
  390. .red{
  391. color: red !important;
  392. }
  393. .bottom{
  394. position: fixed;
  395. left: 0;
  396. right: 0;
  397. bottom: 0;
  398. background-color: #fff;
  399. padding: 16rpx 32rpx;
  400. display: flex;
  401. justify-content: space-between;
  402. align-items: center;
  403. .input{
  404. background-color: rgba(229, 231, 234, 1);
  405. height: 32px;
  406. line-height: 32px;
  407. border-radius: 8rpx;
  408. width: 520rpx;
  409. padding-left: 16rpx;
  410. }
  411. /deep/.uni-input-placeholder{
  412. text-indent: 28rpx;
  413. }
  414. /deep/.uni-input-input{
  415. text-indent: 28rpx;
  416. }
  417. .like{
  418. display: flex;
  419. .number{
  420. margin-left: 16rpx;
  421. }
  422. }
  423. }
  424. </style>