newssqdetail.vue 15 KB

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