content.vue 8.9 KB

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