content.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <template>
  2. <view v-if="detaile">
  3. <view v-if="detaile&&detaile.contentType!=3">
  4. <view class="title">{{ detaile.title }}</view>
  5. <view class="det-sta ddflex">
  6. <image style="width: 48rpx;height: 48rpx;margin-right: 10rpx;" :src="config.CONFIG_PROJECT_LOGO"></image>
  7. <view class="sitename" @click="toIndex('')">{{config.CONFIG_PROJECT_TITLE}}</view>
  8. <view class="time">{{getDateTimeStamp(detaile.time)}}</view>
  9. </view>
  10. <view class="video" v-if="detaile.resourceUri&&JSON.parse(detaile.resourceUri).uri">
  11. <video :src="JSON.parse(detaile.resourceUri).uri" :show-center-play-btn="false" :controls="true" :autoplay="true" id="myVideo" @pause="videoPause" @ended="videoEnded"></video>
  12. <view class="video-play ddflex" @click="videoPlay()" v-if="detaile.isShowPlayBtn"><image src="../../static/images/play.png"></image></view>
  13. </view>
  14. <view class="content">
  15. <view class="viewMore">
  16. <mp-html :content="detaile.text" :lazy-load="true" @imgtap="choose"></mp-html>
  17. </view>
  18. </view>
  19. <view style="font-size: 24rpx;color: #999999;line-height: 36rpx;padding: 0 30rpx;">
  20. 部分素材来源:中国人寿寿险app、国寿e店、云助理等。
  21. </view>
  22. <view class="operate dflex">
  23. <view class="zan dflex">
  24. 共{{detaile.browse}}次浏览</view>
  25. <view class="ddflex">
  26. <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>
  27. <view style="margin-left: 30rpx;">
  28. <button class="share ddflex" hover-class="none" open-type="share"><image src="/static/images/share.png"></image>分享</button>
  29. </view>
  30. </view>
  31. </view>
  32. <view class="box" v-if="contentList && contentList.length > 0">
  33. <view class="tit dflex">为您推荐</view>
  34. <view class="rec">
  35. <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">
  36. <view class="flex">
  37. <view class="rec-tit tovers">{{item.title}}</view>
  38. <view class="dflex">
  39. <!-- <view class="author ddflex"><image src="../../static/pages/images/zbgw.png" mode="aspectFill"></image>欧衡</view> -->
  40. <view class="rec-time">{{item.createDate}}</view>
  41. </view>
  42. </view>
  43. <image :src="item.pic" mode="aspectFill" class="rec-img"></image>
  44. </navigator>
  45. </view>
  46. </view>
  47. </view>
  48. <view v-if="detaile&&detaile.contentType==3">
  49. <web-view :src="webUrl" v-if="webUrl!==''"></web-view>
  50. </view>
  51. </view>
  52. </template>
  53. <script>
  54. const app = getApp();
  55. const req = require('../../utils/request.js');
  56. const util = require('../../utils/util.js');
  57. import mpHtml from "../../components/mp-html/components/mp-html/mp-html";
  58. export default {
  59. components: {
  60. mpHtml,
  61. },
  62. data() {
  63. return {
  64. detaile: '',
  65. type: 2, //详情类型:1 普通内容 2 自定义页面内容
  66. form: {
  67. page: 1,
  68. limit: 4,
  69. },
  70. contentList: [],
  71. viewMore: false,
  72. config: {},
  73. userInfo:{},
  74. query:{},
  75. id:null,
  76. webUrl:'',
  77. tempFilePath:'',
  78. isShowUpdate: false, //是否显示更新信息弹窗
  79. isUpdateInfo: false,//更新用户信息
  80. isUpdateMobile: false,//绑定手机号
  81. enterTime : '',//进入页面时间
  82. outTime : '',//页面卸载时间
  83. stayTime : 0//页面停留时间
  84. };
  85. },
  86. onLoad: async function(options) {
  87. this.query = options
  88. this.id = options.id;
  89. await this.getDetail();
  90. // this.getContentList();
  91. },
  92. async onShow(){
  93. this.getConfig()
  94. },
  95. onHide(){
  96. },
  97. methods: {
  98. getConfig() {
  99. var _this = this;
  100. return new Promise((res, rej) => {
  101. req.getRequest(
  102. '/api/other/config',{},
  103. data => {
  104. this.config = data;
  105. res(data);
  106. },
  107. true
  108. );
  109. });
  110. },
  111. monitor() {
  112. let that = this;
  113. let system = uni.getSystemInfoSync();
  114. let query = uni.createSelectorQuery();
  115. query.select('.viewMore').boundingClientRect(data=>{
  116. let height = data.height;
  117. if(height > system.screenHeight) {
  118. this.viewMore = true
  119. }
  120. }).exec();
  121. },
  122. viewMores(){
  123. this.viewMore = true;
  124. },
  125. choose: function () {
  126. let freshen = false;
  127. this.$emit('freshen', {
  128. detail: freshen
  129. });
  130. },
  131. toIndex(){
  132. // uni.switchTab({
  133. // url: '/pages/index/index'
  134. // })
  135. },
  136. getDateTimeStamp(dateStr){
  137. return util.getDateDiff(Date.parse(dateStr.replace(/-/gi,"/")));
  138. },
  139. getDetail() {
  140. let that = this;
  141. let apiUrl = '/api/content/detail';
  142. return new Promise((resolve,reject)=>{
  143. req.getRequest(apiUrl,{ id: that.id },async res => {
  144. if(res.productCategory){
  145. res.productCategory = res.productCategory.split(',')
  146. }
  147. that.detaile = res;
  148. that.webUrl = that.detaile.linkUrl?that.detaile.linkUrl:''
  149. let arr = [];
  150. if(res.productCategory && res.productCategory.length > 0){
  151. for (var i = 0; i < res.productCategory.length; i++) {
  152. await that.getProductList(res.productCategory[i], i).then(res=>{
  153. arr = arr.concat(res);
  154. that.productList = arr;
  155. console.log('相关产品=='+JSON.stringify(arr),arr.length)
  156. });
  157. }
  158. }
  159. resolve();
  160. },true);
  161. })
  162. },
  163. getContentList() {
  164. let form = this.form;
  165. form.cid = this.detaile.cid;
  166. if(req.getStorage("shareId")){
  167. form.shareSaleNo = req.getStorage("shareId")
  168. }
  169. req.getRequest('/api/content/list',form,res => {
  170. this.contentList = res;
  171. for (var i = 0; i < this.contentList.length; i++) {
  172. if (this.contentList[i].id == this.id){
  173. this.contentList.splice(i,1);
  174. }
  175. }
  176. });
  177. },
  178. },
  179. filters: {
  180. /**
  181. * 处理富文本里的图片宽度自适应
  182. * 1.去掉img标签里的style、width、height属性
  183. * 2.img标签添加style属性:max-width:100%;height:auto
  184. * 3.修改所有style里的width属性为max-width:100%
  185. * 4.去掉<br/>标签
  186. * @param html
  187. * @returns {void|string|*}
  188. */
  189. formatRichText(html) {
  190. //控制小程序中图片大小
  191. let newContent = html.replace(/<img[^>]*>/gi, function(match, capture) {
  192. match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');
  193. match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
  194. match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
  195. return match;
  196. });
  197. newContent = newContent.replace(/style="[^"]+"/gi, function(match, capture) {
  198. match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi, 'max-width:100%;');
  199. return match;
  200. });
  201. // newContent = newContent.replace(/<br[^>]*\/>/gi, '');
  202. newContent = newContent.replace(/<br[^>]*\/>/gi, '<p style="margin: 10px 0;"></p>');
  203. newContent = newContent.replace(/<br[^>]*\>/gi, '<p style="margin: 10px 0;"></p>');
  204. newContent = newContent.replace(/font-size:[^;]+;?/g,'');
  205. newContent = newContent.replace(/\<img/gi, '<img style="max-width:100%;height:auto;display:inline-block;margin:12rpx auto;"');
  206. return newContent;
  207. }
  208. }
  209. };
  210. </script>
  211. <style>
  212. @import './content.css';
  213. </style>