newsygdetail.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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. <loading></loading>
  16. </view>
  17. </template>
  18. <script>
  19. import config from '@/config'
  20. const baseUrl = config.baseUrl
  21. import { checkPermi, checkRole } from "@/utils/permission"; // 权限判断函数
  22. import {manualDet,putProgress,staffTrainTime} from "@/api/work/manage.js"
  23. export default{
  24. components:{},
  25. data(){
  26. return{
  27. nicona:require('@/manage/static/news/nicona.png'),
  28. niconb:require('@/manage/static/news/niconb.png'),
  29. niconc:require('@/manage/static/news/niconc.png'),
  30. nicond:require('@/manage/static/news/nicond.png'),
  31. nicone:require('@/manage/static/news/nicone.png'),
  32. head:require('@/manage/static/news/head.png'),
  33. showAll:true,
  34. baseUrl:config.baseUrl,
  35. text:'',
  36. id:'',
  37. datainfo:{
  38. progress:'',
  39. },
  40. manualContent:'',
  41. stayDuration: 0,
  42. pageLoadTime:0,
  43. pageHeight:0,//文章高度
  44. progress:0,// 阅读进度
  45. scrollTop:0,// 当前滚动位置
  46. commentHeight:0,//品论模块
  47. scrollflag:true,//是否计算
  48. putflag:false,//是否修改
  49. }
  50. },
  51. onUnload() {
  52. // 计算停留时长
  53. this.calculateStayDuration();
  54. },
  55. onLoad: function(e) {
  56. this.id=e.id;
  57. this.getDetailFn()
  58. // 记录页面加载时间
  59. this.pageLoadTime = Date.now();
  60. },
  61. onHide() {
  62. // 页面隐藏时计算停留时长
  63. this.calculateStayDuration();
  64. },
  65. onShow() {
  66. // 页面重新显示时重新记录加载时间
  67. this.pageLoadTime = Date.now();
  68. },
  69. mounted() {
  70. var that=this;
  71. setTimeout(function(){
  72. that.getHeightFn()
  73. },200)
  74. },
  75. onPageScroll(e) {
  76. // 获取当前滚动位置
  77. this.scrollTop = e.scrollTop;
  78. // 计算阅读进度
  79. this.calculateProgress();
  80. },
  81. methods:{
  82. checkPermi, checkRole,
  83. // 计算停留时长
  84. calculateStayDuration() {
  85. const currentTime = Date.now();
  86. var time=Math.floor((currentTime - this.pageLoadTime) / 1000); // 转换为秒
  87. // var staffTime=Math.ceil(time/60);//向上取整,转换成分钟
  88. var staffTime=Math.round(time/60);//四舍五入,转换成分钟
  89. if(staffTime>0){
  90. var params={
  91. staffTime:staffTime,
  92. }
  93. staffTrainTime(params).then(res=>{
  94. })
  95. }
  96. // 修改自己的阅读进度
  97. // var paramsput={
  98. // manualId:this.id,
  99. // progress:this.datainfo.progress,
  100. // }
  101. var paramsput=JSON.parse(JSON.stringify(this.datainfo))
  102. putProgress(paramsput).then(res=>{
  103. if(res.code==200){
  104. if(this.putflag){
  105. // uni.$emit('newsygList')
  106. }
  107. }
  108. })
  109. },
  110. calculateProgress() {
  111. var progress=0;
  112. if (this.pageHeight > 0&&this.scrollflag) {
  113. var pro=this.datainfo.progress||0;
  114. // 如果滚动到评论区域,阅读进度为 100%
  115. if (this.scrollTop >= this.pageHeight) {
  116. progress = 100;
  117. } else {
  118. // 计算文章内容的阅读进度
  119. progress = ((this.scrollTop + uni.getSystemInfoSync().windowHeight) / this.pageHeight * 100).toFixed(2);
  120. if (progress > 100) {
  121. progress = 100;
  122. }
  123. }
  124. if(Number(pro)<Number(progress)){
  125. this.datainfo.progress= progress;
  126. this.putflag=true;
  127. }
  128. }
  129. },
  130. getHeightFn(){
  131. let query = uni.createSelectorQuery().in(this);
  132. var windowHeight=uni.getSystemInfoSync().windowHeight
  133. var that=this;
  134. //需要给黄色区域设置一个id标识,在这里是demo
  135. query.select('.mainbox').boundingClientRect(data => {
  136. var height=data.height;
  137. that.pageHeight=Number(height);
  138. if(height<Number(windowHeight)){
  139. this.progress=100;
  140. this.scrollflag=false;
  141. this.datainfo.progress= 100;
  142. this.putflag=true;
  143. }
  144. }).exec();
  145. // 获取评论模块高度
  146. // query.select('.comment-section').boundingClientRect(data => {
  147. // this.commentHeight = data.height;
  148. // }).exec();
  149. },
  150. getDetailFn(){
  151. manualDet(this.id).then(res=>{
  152. if(res.code==200){
  153. this.datainfo=res.data;
  154. var data=JSON.parse(JSON.stringify(res.data))
  155. if(data.manualContent){
  156. this.manualContent=this.formatRichText(data.manualContent)
  157. }
  158. }
  159. })
  160. },
  161. // getNextFn(){
  162. // this.$tab.navigateTo("/work/pages/business/add")
  163. // },
  164. //解析富文本方法
  165. formatRichText(html) {
  166. let newContent = html.replace(/<img[^>]*>/gi, function(match, capture) {
  167. match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '').replace(/style=""/gi, '');
  168. // match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
  169. // match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
  170. return match;
  171. });
  172. newContent = newContent.replace(/style="[^"]+"/gi, function(match, capture) {
  173. match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi, 'max-width:100%;');
  174. return match;
  175. });
  176. newContent = newContent.replace(/<br[^>]*\/>/gi, '');
  177. newContent = newContent.replace(/\<img src="/gi,
  178. '<img style="max-width:100%;height:auto;display:block;margin:10rpx auto;" src="' +this.baseUrl);
  179. return newContent;
  180. },
  181. }
  182. }
  183. </script>
  184. <style>
  185. page{background: #F3F3F0;}
  186. </style>
  187. <style lang="scss" scoped>
  188. .mainbox{padding: 20rpx 0;}
  189. .ndetail{
  190. // padding: 20rpx 18rpx 100rpx;
  191. min-height: 100vh;padding: 0rpx 18rpx;
  192. .ndbox{background: #FFFFFF;border-radius: 20rpx;padding-top: 30rpx;
  193. .tit{font-weight: bold;font-size: 32rpx;color: #272727;margin-bottom: 14rpx;text-align: center;padding-top: 4rpx;}
  194. .time{font-weight: 500;font-size: 24rpx;color: #AAAAAA;text-align: center;}
  195. .rich{border-top: 2rpx solid #E5E5E5;padding: 28rpx 0;}
  196. .ndbfox{
  197. border-top: 2rpx solid #E5E5E5;
  198. .ndbflist{width: 33.3%;min-height: 78rpx;padding: 16rpx 0;box-sizing: border-box;
  199. image{width: 26rpx;height: 26rpx;margin-right: 26rpx;}
  200. view{font-weight: 500;font-size: 26rpx;color: #666666;}
  201. }
  202. }
  203. }
  204. }
  205. .pltit{font-weight: bold;font-size: 30rpx;color: #272727;
  206. text{margin-left: 24rpx;font-size: 24rpx;color: #666666;}
  207. }
  208. .pllist{padding-top: 20rpx;margin-bottom: 16rpx;border-bottom: 2rpx solid #DADADA;
  209. &:last-child{border-bottom: none;}
  210. .head{width: 40rpx;height: 40rpx;margin-right: 18rpx;flex: 0 0 auto;}
  211. .plname{font-weight: bold;font-size: 30rpx;color: #161616;}
  212. .plrbtn{margin-left: 36rpx;
  213. image{width: 26rpx;height: 24rpx;margin-right: 16rpx;
  214. &.imga{width: 26rpx;height: 26rpx;}
  215. &.imgb{width: 26rpx;height: 22rpx;}
  216. }
  217. view{font-weight: bold;font-size: 24rpx;color: #314081;}
  218. }
  219. .infotxt{font-weight: 500;font-size: 26rpx;color: #161616;line-height: 40rpx;
  220. &:before {content: "";float: right;width: 0;height: calc(100% - 16px);background: red;}
  221. .infotime{font-weight: 500;font-size: 24rpx;color: #666666; float: right;clear: both;}
  222. }
  223. .pllist{
  224. padding-top: 0;border-bottom: none;margin-bottom: 0;
  225. }
  226. }
  227. .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);
  228. .pjfbox{background: #E6E6E6;border-radius: 10rpx;
  229. .btns{nt-weight: bold;padding: 0 34rpx;height: 60rpx;line-height: 60rpx;flex: 0 0 auto;
  230. font-size: 26rpx;
  231. }
  232. color: #314081;}
  233. }
  234. .pjfbtn /deep/ .uni-easyinput{flex: 1;font-size: 26rpx;color: #222327;}
  235. .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;}
  236. </style>