detalis.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <template>
  2. <view>
  3. <u-navbar ></u-navbar>
  4. <view class="article">
  5. <view class="article-tit" v-text="detail.title">
  6. </view>
  7. <view class="article-row">
  8. <view class="article-time" v-text="detail.createTime" ></view>
  9. <view class="article-see">
  10. <u-icon custom-prefix="custom-icon" name="eye-line"></u-icon>
  11. <span v-text="detail.visitorsNum"> </span>
  12. </view>
  13. </view>
  14. <view class="article-con" v-html="content" >
  15. </view>
  16. <view class="article-foot" >
  17. <view class="u-flex" >
  18. <view class="article-btn" @click="fontSizeUp1()">
  19. <u-icon custom-prefix="custom-icon" name="zoom-in-line"></u-icon>
  20. <span>放大</span>
  21. </view>
  22. <view class="article-btn" @click="fontSizeDown2()">
  23. <u-icon custom-prefix="custom-icon" name="zoom-out-line"></u-icon>
  24. <span>缩小</span>
  25. </view>
  26. </view>
  27. <view class="article-btn" @click="scrollTop()">
  28. <u-icon custom-prefix="custom-icon" name="align-top"></u-icon>
  29. <span>回顶</span>
  30. </view>
  31. </view>
  32. </view>
  33. </view>
  34. </template>
  35. <script>
  36. import * as API from '@/apis/news.js'
  37. export default {
  38. data() {
  39. return {
  40. myFontSize:14,
  41. pageTitle: '文章详情',
  42. isLoading: false,
  43. id: '',
  44. content:"",
  45. detail: {
  46. title:"",
  47. createTime:"",
  48. visitorsNum:"",
  49. content:"",
  50. },
  51. }
  52. },
  53. onLoad(op) {
  54. this.id =op.id;
  55. this.getDetail();
  56. var myFontSize=this.carhelp.get("news-info-fontsize")
  57. if(myFontSize){
  58. this.myFontSize=myFontSize
  59. }
  60. },
  61. methods: {
  62. fontSizeUp1(){
  63. if(this.myFontSize>=52){
  64. uni.showToast({
  65. title: "当前已为最大字体",icon: "none"
  66. })
  67. return
  68. }
  69. this.myFontSize=this.myFontSize+10
  70. this.carhelp.set("news-info-fontsize",this.myFontSize)
  71. this.getcontent()
  72. },
  73. fontSizeDown2(){
  74. if(this.myFontSize<=12){
  75. uni.showToast({
  76. title: "当前已为最小字体",icon: "none"
  77. })
  78. return
  79. }
  80. this.myFontSize=this.myFontSize-10
  81. this.carhelp.set("news-info-fontsize",this.myFontSize)
  82. this.getcontent()
  83. },
  84. scrollTop(){
  85. uni.pageScrollTo({
  86. scrollTop: 0,
  87. duration: 300
  88. })
  89. },
  90. getcontent(){
  91. var key1="font-size"
  92. var key2="font-size:"+this.myFontSize+"px ; line-height: "+(this.myFontSize+10)+"px;test"
  93. var reg=new RegExp(key1,'gi')
  94. var content=this.detail.content.replace(reg,key2)
  95. this.content=content;
  96. },
  97. getDetail() {
  98. uni.showLoading({
  99. title: "加载中",
  100. mask: true,
  101. })
  102. API.newsdetail({id:this.id}).then(response => {
  103. this.detail = response.data;
  104. this.getcontent()
  105. uni.hideLoading()
  106. }).catch(error => {
  107. uni.showToast({
  108. title: error,icon: "none"
  109. })
  110. })
  111. },
  112. }
  113. }
  114. </script>
  115. <style lang="scss" scoped>
  116. .article{
  117. padding: 15px;
  118. .article-tit{
  119. font-size: 20px;
  120. margin-bottom:10px;
  121. }
  122. .article-row{
  123. display: flex;
  124. justify-content: space-between;
  125. align-items: center;
  126. color: #888;
  127. font-size: 12px;
  128. border-bottom: 1px solid #F1F1F1;
  129. padding-bottom: 15px;
  130. .article-time{}
  131. .article-see{
  132. span{
  133. margin-left:3px;
  134. }
  135. }
  136. }
  137. .article-con{
  138. padding: 15px 0 35px;
  139. font-size: 14px;
  140. line-height: 28px;
  141. img{
  142. width: 100%;
  143. margin: 10px 0;
  144. }
  145. }
  146. .article-foot{
  147. height: 50px;
  148. position:fixed;
  149. left: 0;
  150. right: 0;
  151. bottom: 0;
  152. background-color: #fff;
  153. border-top: 1px solid #f7f7f7;
  154. display: flex;
  155. justify-content: space-between;
  156. align-items: center;
  157. padding:0 15px;
  158. .article-btn{
  159. background: #E5E7EA;
  160. padding:6px 10px;
  161. color: #606875;
  162. border-radius: 8px;
  163. span{
  164. margin-left: 3px;
  165. }
  166. }
  167. .u-flex .article-btn{
  168. margin-right: 10px;
  169. }
  170. }
  171. }
  172. </style>