content.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <template>
  2. <view v-if="detaile">
  3. <view class="title">{{ detaile.title }}</view>
  4. <view class="det-sta ddflex">
  5. <image style="width: 48rpx;height: 48rpx;margin-right: 10rpx;" :src="config.CONFIG_PROJECT_LOGO"></image>
  6. <view class="sitename" @click="toIndex('')">{{config.CONFIG_PROJECT_TITLE}}</view>
  7. <view class="time">{{getDateTimeStamp(detaile.time)}}</view>
  8. </view>
  9. <view class="content">
  10. <view class="viewMore">
  11. <mp-html :content="detaile.text" :lazy-load="true" @imgtap="choose"></mp-html>
  12. </view>
  13. </view>
  14. <view style="font-size: 24rpx;color: #999999;line-height: 36rpx;padding: 0 30rpx;">
  15. 本文仅代表作者观点,版权归原创者所有,如需转载请在文中注明来源及作者名字。
  16. </view>
  17. <view class="operate dflex">
  18. <view class="zan dflex">
  19. 共{{detaile.browse}}次浏览</view>
  20. <view class="ddflex">
  21. <button style="margin-right: 20rpx !important;" class="share ddflex" hover-class="none" @click="userBehavior()"><image :src="detaile.isThumbs?'/static/images/like_h.png':'/static/images/like.png'"></image>{{detaile.thumbsNumber}}</button>
  22. <button class="share ddflex" hover-class="none" open-type="share"><image src="/static/images/share.png"></image>分享</button>
  23. </view>
  24. </view>
  25. <view class="box" v-if="contentList && contentList.length > 0">
  26. <view class="tit dflex">为您推荐</view>
  27. <view class="rec">
  28. <navigator :url="'/topic/content/content?id=' + item.id" hover-class="none" class="li dflex" v-for="(item,index) in contentList" :key="index" v-if="index < 3">
  29. <view class="flex">
  30. <view class="rec-tit tovers">{{item.title}}</view>
  31. <view class="dflex">
  32. <!-- <view class="author ddflex"><image src="../../static/pages/images/zbgw.png" mode="aspectFill"></image>欧衡</view> -->
  33. <view class="rec-time">{{item.createDate}}</view>
  34. </view>
  35. </view>
  36. <image :src="item.pic" mode="aspectFill" class="rec-img"></image>
  37. </navigator>
  38. </view>
  39. </view>
  40. <serviceContact></serviceContact>
  41. </view>
  42. </template>
  43. <script>
  44. const app = getApp();
  45. const req = require('../../utils/request.js');
  46. const api = require('../../utils/api.js');
  47. const util = require('../../utils/util.js');
  48. import mpHtml from "../../components/mp-html/components/mp-html/mp-html";
  49. import serviceContact from "../../components/service-contact/index.vue";
  50. export default {
  51. components: {
  52. mpHtml,
  53. serviceContact
  54. },
  55. data() {
  56. return {
  57. detaile: '',
  58. type: 2, //详情类型:1 普通内容 2 自定义页面内容
  59. form: {
  60. page: 1,
  61. limit: 4,
  62. },
  63. contentList: [],
  64. viewMore: false,
  65. config: {},
  66. };
  67. },
  68. onLoad: async function(options) {
  69. uni.showShareMenu({
  70. withShareTicket: true,
  71. menus: ['shareAppMessage', 'shareTimeline']
  72. });
  73. this.id = options.id;
  74. await this.getDetail();
  75. this.getContentList();
  76. // await this.monitor();
  77. },
  78. onShow(){
  79. this.config = JSON.parse(req.getStorage('configRes'))
  80. this.getBrowse();
  81. },
  82. onShareAppMessage() {
  83. return {
  84. title: this.detaile.title,
  85. imageUrl: this.detaile.pic,
  86. path: '/topic/content/content?id=' + this.id +'&isShare=' + true
  87. };
  88. },
  89. onShareTimeline() {
  90. return {
  91. title: this.detaile.title,
  92. imageUrl: this.detaile.pic,
  93. path: '/topic/content/content?id=' + this.id +'&isShareTimeline=' + true
  94. };
  95. },
  96. methods: {
  97. monitor() {
  98. let that = this;
  99. let system = uni.getSystemInfoSync();
  100. let query = uni.createSelectorQuery();
  101. query.select('.viewMore').boundingClientRect(data=>{
  102. let height = data.height;
  103. if(height > system.screenHeight) {
  104. this.viewMore = true
  105. }
  106. }).exec();
  107. },
  108. viewMores(){
  109. this.viewMore = true;
  110. },
  111. choose: function () {
  112. let freshen = false;
  113. this.$emit('freshen', {
  114. detail: freshen
  115. });
  116. },
  117. toIndex(){
  118. uni.switchTab({
  119. url: '/pages/index/index'
  120. })
  121. },
  122. getDateTimeStamp(dateStr){
  123. return util.getDateDiff(Date.parse(dateStr.replace(/-/gi,"/")));
  124. },
  125. getDetail() {
  126. let that = this;
  127. let apiUrl = '/api/content/detail';
  128. return new Promise((resolve,reject)=>{
  129. req.getRequest(apiUrl,{ id: that.id },async res => {
  130. if(res.productCategory){
  131. res.productCategory = res.productCategory.split(',')
  132. }
  133. that.detaile = res;
  134. let arr = [];
  135. if(res.productCategory && res.productCategory.length > 0){
  136. for (var i = 0; i < res.productCategory.length; i++) {
  137. await that.getProductList(res.productCategory[i], i).then(res=>{
  138. arr = arr.concat(res);
  139. that.productList = arr;
  140. console.log('相关产品=='+JSON.stringify(arr),arr.length)
  141. });
  142. }
  143. }
  144. resolve();
  145. },true);
  146. })
  147. },
  148. getBrowse(){
  149. var dataP = {};
  150. dataP.type =
  151. 4 //、产品 2、活动 3、未知 4、内容 5、课程 6、老师 7、素材 8、题目 9、资料领取 10、招聘职位 12、用户须知 13、素材 15、医院科室 16、海报 20、医生 21 新闻 23名片
  152. dataP.behavior = 4; //1、关注 2、收藏 3、点赞 4、浏览 5、确认 6、分享
  153. dataP.bindId = this.id;
  154. req.postRequestLoding('/api/v3/behavior/save', dataP, data => {
  155. });
  156. },
  157. // 用户行为
  158. userBehavior() {
  159. var dataP = {};
  160. dataP.type =
  161. 4 //、产品 2、活动 3、未知 4、内容 5、课程 6、老师 7、素材 8、题目 9、资料领取 10、招聘职位 12、用户须知 13、素材 15、医院科室 16、海报 20、医生 21 新闻 23名片
  162. dataP.behavior = 3; //1、关注 2、收藏 3、点赞 4、浏览 5、确认 6、分享
  163. dataP.bindId = this.id;
  164. req.postRequestLoding('/api/v3/behavior/save', dataP, data => {
  165. if(this.detaile.isThumbs){
  166. this.detaile.thumbsNumber = this.detaile.thumbsNumber-1
  167. }else{
  168. this.detaile.thumbsNumber = this.detaile.thumbsNumber+1
  169. }
  170. this.detaile.isThumbs = !this.detaile.isThumbs
  171. });
  172. },
  173. getContentList() {
  174. let form = this.form;
  175. form.code = this.detaile.PCode;
  176. req.getRequest('/api/content/list',form,res => {
  177. this.contentList = res;
  178. for (var i = 0; i < this.contentList.length; i++) {
  179. if (this.contentList[i].id == this.id){
  180. this.contentList.splice(i,1);
  181. }
  182. }
  183. });
  184. },
  185. },
  186. filters: {
  187. /**
  188. * 处理富文本里的图片宽度自适应
  189. * 1.去掉img标签里的style、width、height属性
  190. * 2.img标签添加style属性:max-width:100%;height:auto
  191. * 3.修改所有style里的width属性为max-width:100%
  192. * 4.去掉<br/>标签
  193. * @param html
  194. * @returns {void|string|*}
  195. */
  196. formatRichText(html) {
  197. //控制小程序中图片大小
  198. let newContent = html.replace(/<img[^>]*>/gi, function(match, capture) {
  199. match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');
  200. match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
  201. match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
  202. return match;
  203. });
  204. newContent = newContent.replace(/style="[^"]+"/gi, function(match, capture) {
  205. match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi, 'max-width:100%;');
  206. return match;
  207. });
  208. // newContent = newContent.replace(/<br[^>]*\/>/gi, '');
  209. newContent = newContent.replace(/<br[^>]*\/>/gi, '<p style="margin: 10px 0;"></p>');
  210. newContent = newContent.replace(/<br[^>]*\>/gi, '<p style="margin: 10px 0;"></p>');
  211. newContent = newContent.replace(/font-size:[^;]+;?/g,'');
  212. newContent = newContent.replace(/\<img/gi, '<img style="max-width:100%;height:auto;display:inline-block;margin:12rpx auto;"');
  213. return newContent;
  214. }
  215. }
  216. };
  217. </script>
  218. <style>
  219. @import './content.css';
  220. </style>