newsygdetail.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. <template>
  2. <view class="ndetail ">
  3. <!-- 详情 -->
  4. <view class="mainbox">
  5. <view class="ndbox">
  6. <view class="plr15">
  7. <view class="tit">{{datainfo.manualTitle}}</view>
  8. <view class="time mb12">{{datainfo.publishTime}}</view>
  9. <view class="rich">
  10. <rich-text :nodes="manualContent" style="word-break: break-all;"></rich-text>
  11. </view>
  12. </view>
  13. </view>
  14. </view>
  15. <view class="ndbox mb12 plr15 comment-section" style="display:none">
  16. <view class="pltit">评论<text>(31)</text></view>
  17. <!-- 评论列表 -->
  18. <view class="pllist flex">
  19. <image :src="head" class="head"></image>
  20. <view class="flex1 overh">
  21. <view class="flext mb14 ">
  22. <view class="plname flex1 over">床前明月光</view>
  23. <view class="plrbtn flexc flex0">
  24. <!-- <image :src="niconb" class="imga"></image> -->
  25. <image :src="nicond"></image>
  26. <view>点赞</view>
  27. </view>
  28. <view class="plrbtn flexc flex0">
  29. <image :src="nicone" class="imgb"></image>
  30. <view>回复</view>
  31. </view>
  32. </view>
  33. <view class="infotxt mb15">支持!去看一下优惠政策!<view class="infotime">12-3</view></view>
  34. </view>
  35. </view>
  36. <view class="pllist flex">
  37. <image :src="head" class="head"></image>
  38. <view class="flex1 overh">
  39. <view class="flext mb14 ">
  40. <view class="plname flex1 over">疑是地上霜</view>
  41. <view class="plrbtn flexc flex0">
  42. <image :src="niconb" class="imga"></image>
  43. <!-- <image :src="nicond"></image> -->
  44. <view>点赞</view>
  45. </view>
  46. <view class="plrbtn flexc flex0">
  47. <image :src="nicone" class="imgb"></image>
  48. <view>回复</view>
  49. </view>
  50. </view>
  51. <view class="infotxt mb15">提前缴一年的物业费,可以免一个月吗?<view class="infotime">12-3</view></view>
  52. <!-- 二级回复 -->
  53. <view class="pllist flex">
  54. <image :src="head" class="head"></image>
  55. <view class="flex1 overh">
  56. <view class="flext mb14 ">
  57. <view class="plname flex1 over">幸福小区物业</view>
  58. <view class="plrbtn flexc flex0">
  59. <image :src="niconb" class="imga"></image>
  60. <!-- <image :src="nicond"></image> -->
  61. <view>点赞</view>
  62. </view>
  63. <view class="plrbtn flexc flex0">
  64. <image :src="nicone" class="imgb"></image>
  65. <view>回复</view>
  66. </view>
  67. </view>
  68. <view class="infotxt mb15">尊敬的业主朋友,您的建议我司已收到,将在内 部讨论后于物业公告中告知结果,谢谢您的宝贵 建议!<view class="infotime">12-3</view></view>
  69. </view>
  70. </view>
  71. </view>
  72. </view>
  73. <view style="height:100rpx"></view>
  74. <view class="pjfbtn">
  75. <view class="flexc pjfbox">
  76. <uni-easyinput type="textarea" autoHeight v-model="text" :inputBorder='false' placeholder="发表我的评论…" />
  77. <view class="btns">发送</view>
  78. </view>
  79. </view>
  80. </view>
  81. <!-- 评论 -->
  82. <loading></loading>
  83. </view>
  84. </template>
  85. <script>
  86. import config from '@/config'
  87. const baseUrl = config.baseUrl
  88. import { checkPermi, checkRole } from "@/utils/permission"; // 权限判断函数
  89. import {manualDet,manualPut,staffTrainTime} from "@/api/work/manage.js"
  90. export default{
  91. components:{},
  92. data(){
  93. return{
  94. nicona:require('@/manage/static/news/nicona.png'),
  95. niconb:require('@/manage/static/news/niconb.png'),
  96. niconc:require('@/manage/static/news/niconc.png'),
  97. nicond:require('@/manage/static/news/nicond.png'),
  98. nicone:require('@/manage/static/news/nicone.png'),
  99. head:require('@/manage/static/news/head.png'),
  100. showAll:true,
  101. baseUrl:config.baseUrl,
  102. text:'',
  103. id:'',
  104. datainfo:{
  105. progress:'',
  106. },
  107. manualContent:'',
  108. stayDuration: 0,
  109. pageLoadTime:0,
  110. pageHeight:0,//文章高度
  111. progress:0,// 阅读进度
  112. scrollTop:0,// 当前滚动位置
  113. commentHeight:0,//品论模块
  114. scrollflag:true,//是否计算
  115. putflag:false,//是否修改
  116. }
  117. },
  118. onUnload() {
  119. // 计算停留时长
  120. this.calculateStayDuration();
  121. },
  122. onLoad: function(e) {
  123. this.id=e.id;
  124. this.getDetailFn()
  125. // 记录页面加载时间
  126. this.pageLoadTime = Date.now();
  127. },
  128. onHide() {
  129. // 页面隐藏时计算停留时长
  130. this.calculateStayDuration();
  131. },
  132. onShow() {
  133. // 页面重新显示时重新记录加载时间
  134. this.pageLoadTime = Date.now();
  135. },
  136. mounted() {
  137. var that=this;
  138. setTimeout(function(){
  139. that.getHeightFn()
  140. },200)
  141. },
  142. onPageScroll(e) {
  143. // 获取当前滚动位置
  144. this.scrollTop = e.scrollTop;
  145. // 计算阅读进度
  146. this.calculateProgress();
  147. },
  148. methods:{
  149. checkPermi, checkRole,
  150. // 计算停留时长
  151. calculateStayDuration() {
  152. const currentTime = Date.now();
  153. var time=Math.floor((currentTime - this.pageLoadTime) / 1000); // 转换为秒
  154. var staffTime=Math.ceil(time/60);//向上取整,转换成分钟
  155. var params={
  156. staffTime:staffTime,
  157. }
  158. staffTrainTime(params).then(res=>{
  159. })
  160. var paramsput={
  161. manualId:this.id,
  162. progress:this.datainfo.progress,
  163. }
  164. manualPut(paramsput).then(res=>{
  165. if(res.code==200){
  166. }
  167. })
  168. },
  169. calculateProgress() {
  170. var progress=0;
  171. if (this.pageHeight > 0&&this.scrollflag) {
  172. var pro=this.datainfo.progress||0;
  173. // 如果滚动到评论区域,阅读进度为 100%
  174. if (this.scrollTop >= this.pageHeight) {
  175. progress = 100;
  176. } else {
  177. // 计算文章内容的阅读进度
  178. progress = ((this.scrollTop + uni.getSystemInfoSync().windowHeight) / this.pageHeight * 100).toFixed(2);
  179. if (progress > 100) {
  180. progress = 100;
  181. }
  182. }
  183. if(Number(pro)<Number(progress)){
  184. this.datainfo.progress= progress;
  185. this.putflag=true;
  186. }
  187. }
  188. },
  189. getHeightFn(){
  190. let query = uni.createSelectorQuery().in(this);
  191. var windowHeight=uni.getSystemInfoSync().windowHeight
  192. var that=this;
  193. //需要给黄色区域设置一个id标识,在这里是demo
  194. query.select('.mainbox').boundingClientRect(data => {
  195. var height=data.height;
  196. that.pageHeight=Number(height);
  197. if(height<Number(windowHeight)){
  198. this.progress=100;
  199. this.scrollflag=false;
  200. }
  201. }).exec();
  202. // 获取评论模块高度
  203. query.select('.comment-section').boundingClientRect(data => {
  204. this.commentHeight = data.height;
  205. }).exec();
  206. },
  207. getDetailFn(){
  208. manualDet(this.id).then(res=>{
  209. if(res.code==200){
  210. this.datainfo=res.data;
  211. var data=JSON.parse(JSON.stringify(res.data))
  212. if(data.manualContent){
  213. this.manualContent=this.formatRichText(data.manualContent)
  214. }
  215. }
  216. })
  217. },
  218. // getNextFn(){
  219. // this.$tab.navigateTo("/work/pages/business/add")
  220. // },
  221. //解析富文本方法
  222. formatRichText(html) {
  223. let newContent = html.replace(/<img[^>]*>/gi, function(match, capture) {
  224. match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '').replace(/style=""/gi, '');
  225. match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
  226. match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
  227. return match;
  228. });
  229. newContent = newContent.replace(/style="[^"]+"/gi, function(match, capture) {
  230. match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi, 'max-width:100%;');
  231. return match;
  232. });
  233. newContent = newContent.replace(/<br[^>]*\/>/gi, '');
  234. newContent = newContent.replace(/\<img src="/gi,
  235. '<img style="max-width:100%;height:auto;display:block;margin:10rpx auto;" src="' +this.baseUrl);
  236. return newContent;
  237. },
  238. }
  239. }
  240. </script>
  241. <style>
  242. page{background: #F3F3F0;}
  243. </style>
  244. <style lang="scss" scoped>
  245. .mainbox{padding: 20rpx 0;}
  246. .ndetail{
  247. // padding: 20rpx 18rpx 100rpx;
  248. min-height: 100vh;padding: 0rpx 18rpx;
  249. .ndbox{background: #FFFFFF;border-radius: 20rpx;padding-top: 30rpx;
  250. .tit{font-weight: bold;font-size: 32rpx;color: #272727;margin-bottom: 14rpx;text-align: center;padding-top: 4rpx;}
  251. .time{font-weight: 500;font-size: 24rpx;color: #AAAAAA;text-align: center;}
  252. .rich{border-top: 2rpx solid #E5E5E5;padding: 28rpx 0;}
  253. .ndbfox{
  254. border-top: 2rpx solid #E5E5E5;
  255. .ndbflist{width: 33.3%;min-height: 78rpx;padding: 16rpx 0;box-sizing: border-box;
  256. image{width: 26rpx;height: 26rpx;margin-right: 26rpx;}
  257. view{font-weight: 500;font-size: 26rpx;color: #666666;}
  258. }
  259. }
  260. }
  261. }
  262. .pltit{font-weight: bold;font-size: 30rpx;color: #272727;
  263. text{margin-left: 24rpx;font-size: 24rpx;color: #666666;}
  264. }
  265. .pllist{padding-top: 20rpx;margin-bottom: 16rpx;border-bottom: 2rpx solid #DADADA;
  266. &:last-child{border-bottom: none;}
  267. .head{width: 40rpx;height: 40rpx;margin-right: 18rpx;flex: 0 0 auto;}
  268. .plname{font-weight: bold;font-size: 30rpx;color: #161616;}
  269. .plrbtn{margin-left: 36rpx;
  270. image{width: 26rpx;height: 24rpx;margin-right: 16rpx;
  271. &.imga{width: 26rpx;height: 26rpx;}
  272. &.imgb{width: 26rpx;height: 22rpx;}
  273. }
  274. view{font-weight: bold;font-size: 24rpx;color: #314081;}
  275. }
  276. .infotxt{font-weight: 500;font-size: 26rpx;color: #161616;line-height: 40rpx;
  277. &:before {content: "";float: right;width: 0;height: calc(100% - 16px);background: red;}
  278. .infotime{font-weight: 500;font-size: 24rpx;color: #666666; float: right;clear: both;}
  279. }
  280. .pllist{
  281. padding-top: 0;border-bottom: none;margin-bottom: 0;
  282. }
  283. }
  284. .pjfbtn{background: #FFFFFF;position: fixed;bottom: 0;left: 0;right: 0;padding:20rpx 48rpx;box-shadow: 0px 0px 18rpx 0px rgba(159,159,159,0.47);
  285. .pjfbox{background: #E6E6E6;border-radius: 10rpx;
  286. .btns{nt-weight: bold;padding: 0 34rpx;height: 60rpx;line-height: 60rpx;flex: 0 0 auto;
  287. font-size: 26rpx;
  288. }
  289. color: #314081;}
  290. }
  291. .pjfbtn /deep/ .uni-easyinput{flex: 1;font-size: 26rpx;color: #222327;}
  292. .pjfbtn /deep/ .uni-easyinput__content-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;}
  293. </style>