newsygdetail.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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,manualPut,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. var params={
  90. staffTime:staffTime,
  91. }
  92. staffTrainTime(params).then(res=>{
  93. })
  94. var paramsput={
  95. manualId:this.id,
  96. progress:this.datainfo.progress,
  97. }
  98. manualPut(paramsput).then(res=>{
  99. if(res.code==200){
  100. if(this.putflag){
  101. uni.$emit('newsygList')
  102. }
  103. }
  104. })
  105. },
  106. calculateProgress() {
  107. var progress=0;
  108. if (this.pageHeight > 0&&this.scrollflag) {
  109. var pro=this.datainfo.progress||0;
  110. // 如果滚动到评论区域,阅读进度为 100%
  111. if (this.scrollTop >= this.pageHeight) {
  112. progress = 100;
  113. } else {
  114. // 计算文章内容的阅读进度
  115. progress = ((this.scrollTop + uni.getSystemInfoSync().windowHeight) / this.pageHeight * 100).toFixed(2);
  116. if (progress > 100) {
  117. progress = 100;
  118. }
  119. }
  120. if(Number(pro)<Number(progress)){
  121. this.datainfo.progress= progress;
  122. this.putflag=true;
  123. }
  124. }
  125. },
  126. getHeightFn(){
  127. let query = uni.createSelectorQuery().in(this);
  128. var windowHeight=uni.getSystemInfoSync().windowHeight
  129. var that=this;
  130. //需要给黄色区域设置一个id标识,在这里是demo
  131. query.select('.mainbox').boundingClientRect(data => {
  132. var height=data.height;
  133. that.pageHeight=Number(height);
  134. if(height<Number(windowHeight)){
  135. this.progress=100;
  136. this.scrollflag=false;
  137. this.datainfo.progress= 100;
  138. this.putflag=true;
  139. }
  140. }).exec();
  141. // 获取评论模块高度
  142. // query.select('.comment-section').boundingClientRect(data => {
  143. // this.commentHeight = data.height;
  144. // }).exec();
  145. },
  146. getDetailFn(){
  147. manualDet(this.id).then(res=>{
  148. if(res.code==200){
  149. this.datainfo=res.data;
  150. var data=JSON.parse(JSON.stringify(res.data))
  151. if(data.manualContent){
  152. this.manualContent=this.formatRichText(data.manualContent)
  153. }
  154. }
  155. })
  156. },
  157. // getNextFn(){
  158. // this.$tab.navigateTo("/work/pages/business/add")
  159. // },
  160. //解析富文本方法
  161. formatRichText(html) {
  162. let newContent = html.replace(/<img[^>]*>/gi, function(match, capture) {
  163. match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '').replace(/style=""/gi, '');
  164. match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
  165. match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
  166. return match;
  167. });
  168. newContent = newContent.replace(/style="[^"]+"/gi, function(match, capture) {
  169. match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi, 'max-width:100%;');
  170. return match;
  171. });
  172. newContent = newContent.replace(/<br[^>]*\/>/gi, '');
  173. newContent = newContent.replace(/\<img src="/gi,
  174. '<img style="max-width:100%;height:auto;display:block;margin:10rpx auto;" src="' +this.baseUrl);
  175. return newContent;
  176. },
  177. }
  178. }
  179. </script>
  180. <style>
  181. page{background: #F3F3F0;}
  182. </style>
  183. <style lang="scss" scoped>
  184. .mainbox{padding: 20rpx 0;}
  185. .ndetail{
  186. // padding: 20rpx 18rpx 100rpx;
  187. min-height: 100vh;padding: 0rpx 18rpx;
  188. .ndbox{background: #FFFFFF;border-radius: 20rpx;padding-top: 30rpx;
  189. .tit{font-weight: bold;font-size: 32rpx;color: #272727;margin-bottom: 14rpx;text-align: center;padding-top: 4rpx;}
  190. .time{font-weight: 500;font-size: 24rpx;color: #AAAAAA;text-align: center;}
  191. .rich{border-top: 2rpx solid #E5E5E5;padding: 28rpx 0;}
  192. .ndbfox{
  193. border-top: 2rpx solid #E5E5E5;
  194. .ndbflist{width: 33.3%;min-height: 78rpx;padding: 16rpx 0;box-sizing: border-box;
  195. image{width: 26rpx;height: 26rpx;margin-right: 26rpx;}
  196. view{font-weight: 500;font-size: 26rpx;color: #666666;}
  197. }
  198. }
  199. }
  200. }
  201. .pltit{font-weight: bold;font-size: 30rpx;color: #272727;
  202. text{margin-left: 24rpx;font-size: 24rpx;color: #666666;}
  203. }
  204. .pllist{padding-top: 20rpx;margin-bottom: 16rpx;border-bottom: 2rpx solid #DADADA;
  205. &:last-child{border-bottom: none;}
  206. .head{width: 40rpx;height: 40rpx;margin-right: 18rpx;flex: 0 0 auto;}
  207. .plname{font-weight: bold;font-size: 30rpx;color: #161616;}
  208. .plrbtn{margin-left: 36rpx;
  209. image{width: 26rpx;height: 24rpx;margin-right: 16rpx;
  210. &.imga{width: 26rpx;height: 26rpx;}
  211. &.imgb{width: 26rpx;height: 22rpx;}
  212. }
  213. view{font-weight: bold;font-size: 24rpx;color: #314081;}
  214. }
  215. .infotxt{font-weight: 500;font-size: 26rpx;color: #161616;line-height: 40rpx;
  216. &:before {content: "";float: right;width: 0;height: calc(100% - 16px);background: red;}
  217. .infotime{font-weight: 500;font-size: 24rpx;color: #666666; float: right;clear: both;}
  218. }
  219. .pllist{
  220. padding-top: 0;border-bottom: none;margin-bottom: 0;
  221. }
  222. }
  223. .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);
  224. .pjfbox{background: #E6E6E6;border-radius: 10rpx;
  225. .btns{nt-weight: bold;padding: 0 34rpx;height: 60rpx;line-height: 60rpx;flex: 0 0 auto;
  226. font-size: 26rpx;
  227. }
  228. color: #314081;}
  229. }
  230. .pjfbtn /deep/ .uni-easyinput{flex: 1;font-size: 26rpx;color: #222327;}
  231. .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;}
  232. </style>