newssqdetail.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. <template>
  2. <view class="ndetail " @click="getComflag">
  3. <image :src="nonews" v-if="datainfo.status==2" class="noimg"></image>
  4. <block v-else>
  5. <!-- 详情 -->
  6. <view class="ndbox mb12">
  7. <view class="plr15">
  8. <view class="tit">{{datainfo.communityTitle}}</view>
  9. <view class="time mb12">{{datainfo.publishTime}}</view>
  10. <view class="rich">
  11. <rich-text :nodes="communityContent" style="word-break: break-all;"></rich-text>
  12. </view>
  13. </view>
  14. </view>
  15. <view class="ndbox mb12 plr15">
  16. <view class="flext mb15">
  17. <view class="pltit flex0">评论<text>({{commenttotal||0}})</text></view>
  18. <view class="flex1"></view>
  19. <view class="pltitnum"><text>{{datainfo.userLikes}}</text>赞<text class="line">|</text><text>{{datainfo.userShare}}</text> 分享</view>
  20. </view>
  21. <!-- 评论列表 -->
  22. <box-list :datainfo="commentlist" type="comment" @getZhanFn="getZhanFn" @getShouFn="getShouFn" @getDzFn="getplDzFn" @getHfFn="getplHfFn" @getDelFn="getDelFn"></box-list>
  23. </view>
  24. <!-- 评论 -->
  25. <view class="pjfbtn" @click.stop="btns" :style="{bottom: `${bottom}px`}">
  26. <view class="mb10 plr20">
  27. <view class="flexc pjfbox ">
  28. <textarea :placeholder="placeholder" :adjust-position="adjustpos" :focus="isfocus" v-model="text" :auto-height="autoHeight" :cursor-spacing='curspac' fixed="true" :show-confirm-bar="confirmBar" ></textarea>
  29. <view class="btns" @click.stop="getPinLunFn">发送</view>
  30. </view>
  31. </view>
  32. <view class="ndbfox flexc">
  33. <view class="flexcc ndbflist" @click.stop="getshareFn">
  34. <image :src="share"></image>
  35. <view>{{datainfo.userShare}}</view>
  36. </view>
  37. <view class="flexcc ndbflist" @click.stop="getHfFna">
  38. <image :src="nicona"></image>
  39. <view>{{commenttotal||0}}</view>
  40. </view>
  41. <view class="flexcc ndbflist" @click.stop="getDzFn('1')">
  42. <image :src="nicond" v-if="datainfo.isLike=='Y'"></image>
  43. <image :src="niconb" v-else></image>
  44. <view>{{datainfo.userLikes}}</view>
  45. </view>
  46. <view class="flexcc ndbflist" @click.stop="getScFn('1')">
  47. <image :src="starb" v-if="datainfo.isStar=='Y'"></image>
  48. <image :src="niconc" v-else></image>
  49. <view>{{datainfo.userStars}}</view>
  50. </view>
  51. </view>
  52. </view>
  53. </block>
  54. <loading></loading>
  55. </view>
  56. </template>
  57. <script>
  58. import config from '@/config'
  59. const baseUrl = config.baseUrl
  60. import { checkPermi, checkRole } from "@/utils/permission"; // 权限判断函数
  61. import boxList from "@/manage/components/car/list.vue"
  62. import {getRootComment,getParentComment,commentIndex,giveTheThumbs,getStars,commentContentPut,deletepl,newsDet,setShare} from "@/api/work/manage.js"
  63. export default{
  64. components:{boxList},
  65. data(){
  66. return{
  67. nicona:require('@/manage/static/news/nicona.png'),
  68. niconb:require('@/manage/static/news/niconb.png'),
  69. niconc:require('@/manage/static/news/niconc.png'),
  70. nicond:require('@/manage/static/news/nicond.png'),
  71. nicone:require('@/manage/static/news/nicone.png'),
  72. head:require('@/manage/static/news/head.png'),
  73. starb:require('@/manage/static/news/starb.png'),
  74. nonews:require('@/manage/static/news/nonews.png'),
  75. share:require('@/manage/static/news/share.png'),
  76. baseUrl:config.baseUrl,
  77. shareurl:config.shareurl,
  78. autoHeight:true,
  79. confirmBar:false,
  80. adrfixed:true,
  81. adjustpos:false,
  82. curspac:0,//光标和键盘距离
  83. placeholder:'发表我的评论',
  84. datainfo:{
  85. },
  86. communityContent:'',
  87. text:'',
  88. id:"",
  89. commentlist:[],//评论列表
  90. commenttotal:"0",
  91. pageSize: 10,
  92. pageNum: 1,
  93. userId:this.$store.state.user.userId,
  94. nickName:this.$store.state.user.nickName,
  95. avatar:this.$store.state.user.avatar,
  96. isRoot:'1',//isRoot,根评论id 1:根评论 2:子评论
  97. isfocus:false,
  98. plinfo:'',//二级评论信息
  99. bottom:0,
  100. tenantId:this.$store.state.user.tenantId,
  101. }
  102. },
  103. onLoad: function(e) {
  104. this.id=e.id;
  105. this.getDetailFn();
  106. this.getRootComment();
  107. // #ifndef H5
  108. uni.onKeyboardHeightChange(res=> { //监听键盘高度变化
  109. const res_keyboard = uni.getSystemInfoSync();
  110. // let key_height = res.height - (res_keyboard.screenHeight - res_keyboard.windowHeight)
  111. this.bottom = `${ res.height>0 ? res.height : 0}`;
  112. // if(this.bottom==0){
  113. // this.isfocus=false;
  114. // }
  115. })
  116. // #endif
  117. },
  118. // 上拉触底加载更多触发事件
  119. onReachBottom() {
  120. if (this.reachflag) {
  121. this.pageNum++
  122. this.getDataFn()
  123. }
  124. },
  125. onPageScroll(e) {
  126. this.isfocus=false;
  127. },
  128. methods:{
  129. checkPermi, checkRole,
  130. //评论
  131. getComflag(){
  132. if(this.isfocus){
  133. this.isfocus=false;
  134. this.placeholder="发表我的评论"
  135. this.isRoot='1'
  136. }
  137. },
  138. // 分享
  139. getshareFn(){
  140. var that=this;
  141. uni.share({
  142. provider: "weixin",
  143. scene: "WXSceneSession",
  144. type: 0,
  145. href: this.shareurl+'/news/pages/news/detail?id='+this.id,
  146. title: this.datainfo.communityTitle,
  147. summary: "社区资讯",
  148. imageUrl: "https://zxyzhsq.qs163.cn/prod-api/profile/upload/2025/06/11/applogo_20250611033931A020.png",
  149. success: function (res) {
  150. var params={
  151. communityId:that.id,
  152. tenantId:that.tenantId
  153. }
  154. setShare(params).then(res=>{
  155. if(res.code==200){
  156. // that.$toast("分享成功")
  157. that.datainfo.userShare++
  158. }
  159. })
  160. },
  161. fail: function (err) {
  162. console.log("fail:" + JSON.stringify(err));
  163. }
  164. });
  165. },
  166. btns(){
  167. },
  168. getDetailFn(){
  169. newsDet(this.id).then(res=>{
  170. if(res.code==200){
  171. this.datainfo=res.data;
  172. var data=JSON.parse(JSON.stringify(res.data))
  173. if(data.communityContent){
  174. this.communityContent=this.formatRichText(data.communityContent)
  175. }
  176. }
  177. })
  178. },
  179. // 删除
  180. getDelFn(id){
  181. var that=this;
  182. // var info=JSON.parse(JSON.stringify(data))
  183. // var type=info.type;
  184. // var pid=info.pid;
  185. deletepl(id).then(res=>{
  186. if(res.code==200){
  187. this.$toast("删除成功");
  188. uni.$emit('partyNewsList')
  189. setTimeout(function(){
  190. // 删除数据
  191. that.getRootComment()
  192. },1500)
  193. }
  194. })
  195. },
  196. getZhanFn(obj){
  197. // 获取自己
  198. var obj=JSON.parse(JSON.stringify(obj));
  199. var idx=obj.idx;
  200. var list=JSON.parse(JSON.stringify(this.commentlist))[idx]
  201. var params={
  202. parentId:list.id,
  203. pageSize:list.pageSize,
  204. pageNum: list.pageNum,
  205. tenantId:this.tenantId
  206. }
  207. getParentComment(params).then(res=>{
  208. if(res.code==200){
  209. var reachflag=true;
  210. if (res.rows.length < obj.pageSize) {
  211. list.reachflag = false
  212. } else {
  213. var num = parseInt(res.rows.length) + parseInt(obj.pageSize) * parseInt(obj.pageNum - 1)
  214. if (num < obj.childrenListCount) {
  215. list.reachflag = true
  216. } else {
  217. list.reachflag = false
  218. }
  219. }
  220. list.childrenList=list.childrenList.concat(res.rows)
  221. list.pageNum=obj.pageNum++
  222. this.commentlist.splice(idx,1,list)
  223. }
  224. })
  225. },
  226. // 点赞
  227. getDzFn(type,info){
  228. var params={
  229. userId:this.userId,
  230. nickName:this.nickName,
  231. avatar:this.avatar,
  232. targetType:type,
  233. communityId:this.id,
  234. tenantId:this.tenantId
  235. }
  236. if(type==1){
  237. params.targetId=this.id;
  238. params.targetTitle=this.datainfo.communityTitle;
  239. }else {
  240. params.targetId=info.id;
  241. params.targetTitle=info.content;
  242. }
  243. giveTheThumbs(params).then(res=>{
  244. if(res.code==200){
  245. uni.$emit('partyNewsList')
  246. if(type==1){
  247. if(this.datainfo.isLike=='Y'){
  248. this.$toast("取消点赞成功");
  249. this.datainfo.isLike='N';
  250. this.datainfo.userLikes--;
  251. }else{
  252. this.$toast("点赞成功");
  253. this.datainfo.isLike='Y';
  254. this.datainfo.userLikes++;
  255. }
  256. }else{
  257. var idx=info.idx;
  258. var aidx=info.aidx;
  259. var atype=info.atype;
  260. var obj=JSON.parse(JSON.stringify(this.commentlist))[idx];
  261. if(atype&&atype=='ejdz'){
  262. var erobj=obj.childrenList[aidx];
  263. if(erobj.isLike=='Y'){
  264. this.$toast("取消点赞成功");
  265. erobj.isLike='N';
  266. erobj.likeCount--;
  267. }else{
  268. this.$toast("点赞成功");
  269. erobj.isLike='Y';
  270. erobj.likeCount++;
  271. }
  272. obj.childrenList[aidx]=JSON.parse(JSON.stringify(erobj))
  273. this.commentlist.splice(idx,1,obj)
  274. }else{
  275. if(obj.isLike=='Y'){
  276. this.$toast("取消点赞成功");
  277. obj.isLike='N';
  278. obj.likeCount--;
  279. }else{
  280. this.$toast("点赞成功");
  281. obj.isLike='Y';
  282. obj.likeCount++;
  283. }
  284. this.commentlist.splice(idx,1,obj)
  285. }
  286. }
  287. }
  288. })
  289. },
  290. getplDzFn(data){
  291. var info=JSON.parse(JSON.stringify(data))
  292. this.getDzFn('2',info)
  293. },
  294. // 收藏
  295. getScFn(type){
  296. var params={
  297. userId:this.userId,
  298. nickName:this.nickName,
  299. avatar:this.avatar,
  300. targetType:'1',//目标类型(1:社区 2:党建 )
  301. tenantId:this.tenantId
  302. }
  303. params.targetId=this.id;
  304. params.targetTitle=this.datainfo.communityTitle;
  305. getStars(params).then(res=>{
  306. if(res.code==200){
  307. uni.$emit('partyNewsList')
  308. if(this.datainfo.isStar=='Y'){
  309. this.$toast("取消收藏成功");
  310. this.datainfo.isStar='N';
  311. this.datainfo.userStars--;
  312. }else{
  313. this.$toast("收藏成功");
  314. this.datainfo.isStar='Y';
  315. this.datainfo.userStars++
  316. }
  317. }
  318. })
  319. },
  320. // 评论回复
  321. getHfFna(data){
  322. var that=this;
  323. this.isRoot='1';
  324. this.placeholder='发表我的评论'
  325. this.isfocus=true;
  326. },
  327. getplHfFn(data){
  328. this.isfocus=false;
  329. var that=this;
  330. this.plinfo=JSON.parse(JSON.stringify(data))
  331. this.placeholder='回复:'+data.toNickName
  332. this.isRoot='2';
  333. this.isfocus=true;
  334. },
  335. getPinLunFn(){
  336. var params={
  337. userId:this.userId,
  338. nickName:this.nickName,
  339. avatar:this.avatar,
  340. isRoot:this.isRoot,
  341. communityId:this.id,
  342. communityType:this.datainfo.communityType,
  343. communityTitle:this.datainfo.communityTitle,
  344. commentContent:this.text,
  345. tenantId:this.tenantId
  346. }
  347. if(this.isRoot==2){
  348. var info=JSON.parse(JSON.stringify(this.plinfo))
  349. if(info.type=='ejhf'){
  350. params.toRoot='Y';
  351. }
  352. params.parentId=info.parentId;
  353. params.toUserId=info.toUserId;
  354. params.toNickName=info.toNickName;
  355. params.toAvatar=info.toAvatar;
  356. }
  357. commentIndex(params).then(res=>{
  358. if(res.code==200){
  359. this.$toast('评论成功,等待审核')
  360. this.text='';
  361. this.isfocus=false;
  362. }
  363. })
  364. },
  365. getShouFn(idx){
  366. var list=JSON.parse(JSON.stringify(this.commentlist))[idx];
  367. list.childrenList=[];
  368. list.pageNum=1;
  369. list.reachflag=true;
  370. this.commentlist.splice(idx,1,list)
  371. },
  372. getRootComment(){
  373. var that=this;
  374. var params={
  375. communityId:this.id,
  376. pageSize:this.pageSize,
  377. pageNum: this.pageNum,
  378. tenantId:this.tenantId
  379. }
  380. // userid,头像,nickname,标题(或者评论对象的内容) 点赞收藏评论,
  381. getRootComment(params).then(res=>{
  382. if(res.code==200){
  383. this.commenttotal=res.total;
  384. if (res.rows.length < this.pageSize) {
  385. this.reachflag = false
  386. this.wtdt = '到底了~';
  387. } else {
  388. var num = parseInt(res.rows.length) + parseInt(this.pageSize) * parseInt(this.pageNum - 1)
  389. if (num < res.total) {
  390. this.reachflag = true
  391. this.wtdt = ''
  392. } else {
  393. this.reachflag = false
  394. this.wtdt = '到底了~';
  395. }
  396. }
  397. var newArr=JSON.parse(JSON.stringify(res.rows))
  398. newArr.forEach(ite=>{
  399. ite.pageSize=1
  400. ite.pageNum=10
  401. ite.reachflag=true
  402. })
  403. if (this.pageNum == 1) {
  404. this.commentlist = newArr;
  405. } else {
  406. this.commentlist = this.list.concat(newArr)
  407. }
  408. }
  409. })
  410. },
  411. //解析富文本方法
  412. formatRichText(html) {
  413. let newContent = html.replace(/<img[^>]*>/gi, function(match, capture) {
  414. match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '').replace(/style=""/gi, '');
  415. // match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
  416. // match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
  417. return match;
  418. });
  419. newContent = newContent.replace(/style="[^"]+"/gi, function(match, capture) {
  420. match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi, 'max-width:100%;');
  421. return match;
  422. });
  423. newContent = newContent.replace(/<br[^>]*\/>/gi, '');
  424. newContent = newContent.replace(/\<img src="/gi,
  425. '<img style="max-width:100%;height:auto;display:block;margin:10rpx auto;" src="' +baseUrl);
  426. return newContent;
  427. },
  428. }
  429. }
  430. </script>
  431. <style>
  432. page{background: #F3F3F0;}
  433. </style>
  434. <style lang="scss" scoped>
  435. .ndetail{
  436. min-height: 100vh;padding: 20rpx 18rpx 260rpx;
  437. .ndbox{background: #FFFFFF;border-radius: 20rpx;padding-top: 30rpx;padding-bottom: 20rpx;
  438. .tit{font-weight: bold;font-size: 32rpx;color: #272727;margin-bottom: 14rpx;text-align: center;padding-top: 4rpx;}
  439. .time{font-weight: 500;font-size: 24rpx;color: #AAAAAA;text-align: center;}
  440. .rich{padding: 28rpx 0;}
  441. //border-top: 2rpx solid #E5E5E5;
  442. }
  443. }
  444. .pltitnum{font-weight: 500;font-size: 26rpx;color: #AAAAAA;
  445. text{display: inline-block;margin-right:10rpx;
  446. &.line{margin: 0 12rpx;}
  447. }
  448. }
  449. .pltit{font-weight: bold;font-size: 30rpx;color: #272727;
  450. text{margin-left: 24rpx;font-size: 24rpx;color: #666666;}
  451. }
  452. .plr20{padding: 0 40rpx;}
  453. .pjfbtn{background: #FFFFFF;position: fixed;bottom: 0;left: 0;right: 0;padding:26rpx 0rpx 20rpx;box-shadow: 0px 0px 18rpx 0px rgba(159,159,159,0.47);
  454. .pjfbox{background: #E6E6E6;border-radius: 10rpx;
  455. textarea{flex: 1;font-size: 26rpx;color: #222327;min-height: 100rpx;font-size: 26rpx;margin: 0;background: #E6E6E6;box-sizing: border-box;padding: 10rpx 0 10rpx 36rpx;border-radius:10rpx 0 0 10rpx;}
  456. .btns{nt-weight: bold;padding: 0 34rpx;height: 60rpx;line-height: 60rpx;flex: 0 0 auto;
  457. font-size: 26rpx;
  458. }
  459. color: #314081;}
  460. }
  461. .ndbfox{
  462. // border-top: 2rpx solid #E5E5E5;
  463. .ndbflist{width: 33.3%;padding: 20rpx 0;box-sizing: border-box;
  464. image{width: 26rpx;height: 26rpx;margin-right: 26rpx;}
  465. view{font-weight: 500;font-size: 26rpx;color: #666666;}
  466. }
  467. }
  468. // .pjfbtn /deep/ .uni-easyinput{flex: 1;font-size: 26rpx;color: #222327;}
  469. // .pjfbtn /deep/ .uni-textarea-textarea{min-height: 40rpx;font-size: 26rpx;margin: 0;background: #E6E6E6;box-sizing: border-box;padding: 10rpx 0 10rpx 36rpx;border-radius:10rpx 0 0 10rpx;}
  470. </style>