content.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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. req.saveBehaviorNew(this.id,3,6)
  103. return {
  104. title: this.detaile.title,
  105. imageUrl: this.detaile.pic,
  106. path: '/topic/content/content?id=' + this.id +'&isShare=' + true+(this.userInfo.userType==1?('&shareId='+this.userInfo.saleNo):'')
  107. };
  108. },
  109. onShareTimeline() {
  110. req.saveBehaviorNew(this.id,3,6)
  111. return {
  112. title: this.detaile.title,
  113. imageUrl: this.detaile.pic,
  114. path: '/topic/content/content?id=' + this.id +'&isShareTimeline=' + true+(this.userInfo.userType==1?('&userId='+this.userInfo.saleNo):'')
  115. };
  116. },
  117. methods: {
  118. getConfig() {
  119. var _this = this;
  120. return new Promise((res, rej) => {
  121. req.g(
  122. '/api/other/config',
  123. data => {
  124. req.setStorage('configRes', JSON.stringify(data));
  125. this.config = data;
  126. res(data);
  127. },
  128. true
  129. );
  130. });
  131. },
  132. monitor() {
  133. let that = this;
  134. let system = uni.getSystemInfoSync();
  135. let query = uni.createSelectorQuery();
  136. query.select('.viewMore').boundingClientRect(data=>{
  137. let height = data.height;
  138. if(height > system.screenHeight) {
  139. this.viewMore = true
  140. }
  141. }).exec();
  142. },
  143. viewMores(){
  144. this.viewMore = true;
  145. },
  146. choose: function () {
  147. let freshen = false;
  148. this.$emit('freshen', {
  149. detail: freshen
  150. });
  151. },
  152. toIndex(){
  153. uni.switchTab({
  154. url: '/pages/index/index'
  155. })
  156. },
  157. getDateTimeStamp(dateStr){
  158. return util.getDateDiff(Date.parse(dateStr.replace(/-/gi,"/")));
  159. },
  160. getDetail() {
  161. let that = this;
  162. let apiUrl = '/api/content/detail';
  163. return new Promise((resolve,reject)=>{
  164. req.getRequest(apiUrl,{ id: that.id },async res => {
  165. if(res.productCategory){
  166. res.productCategory = res.productCategory.split(',')
  167. }
  168. that.detaile = res;
  169. that.webUrl = that.detaile.linkUrl?that.detaile.linkUrl:''
  170. let arr = [];
  171. if(res.productCategory && res.productCategory.length > 0){
  172. for (var i = 0; i < res.productCategory.length; i++) {
  173. await that.getProductList(res.productCategory[i], i).then(res=>{
  174. arr = arr.concat(res);
  175. that.productList = arr;
  176. console.log('相关产品=='+JSON.stringify(arr),arr.length)
  177. });
  178. }
  179. }
  180. resolve();
  181. },true);
  182. })
  183. },
  184. getBrowse(){
  185. var dataP = {};
  186. dataP.type =
  187. 4 //、产品 2、活动 3、未知 4、内容 5、课程 6、老师 7、素材 8、题目 9、资料领取 10、招聘职位 12、用户须知 13、素材 15、医院科室 16、海报 20、医生 21 新闻 23名片
  188. dataP.behavior = 4; //1、关注 2、收藏 3、点赞 4、浏览 5、确认 6、分享
  189. dataP.bindId = this.id;
  190. req.postRequestLoding('/api/v3/behavior/save', dataP, data => {
  191. req.saveBehaviorNew(this.id,3,4)
  192. });
  193. },
  194. // 用户行为
  195. userBehavior() {
  196. var dataP = {};
  197. dataP.type =
  198. 4 //、产品 2、活动 3、未知 4、内容 5、课程 6、老师 7、素材 8、题目 9、资料领取 10、招聘职位 12、用户须知 13、素材 15、医院科室 16、海报 20、医生 21 新闻 23名片
  199. dataP.behavior = 3; //1、关注 2、收藏 3、点赞 4、浏览 5、确认 6、分享
  200. dataP.bindId = this.id;
  201. req.postRequestLoding('/api/v3/behavior/save', dataP, data => {
  202. if(this.detaile.isThumbs){
  203. this.detaile.thumbsNumber = this.detaile.thumbsNumber-1
  204. }else{
  205. this.detaile.thumbsNumber = this.detaile.thumbsNumber+1
  206. }
  207. this.detaile.isThumbs = !this.detaile.isThumbs
  208. if(this.detaile.isThumbs){
  209. req.saveBehaviorNew(this.id,3,3)
  210. }else{
  211. req.saveBehaviorNew(this.id,3,11)
  212. }
  213. });
  214. },
  215. getContentList() {
  216. let form = this.form;
  217. form.cid = this.detaile.cid;
  218. if(req.getStorage("shareId")){
  219. form.shareSaleNo = req.getStorage("shareId")
  220. }
  221. req.getRequest('/api/content/list',form,res => {
  222. this.contentList = res;
  223. for (var i = 0; i < this.contentList.length; i++) {
  224. if (this.contentList[i].id == this.id){
  225. this.contentList.splice(i,1);
  226. }
  227. }
  228. });
  229. },
  230. },
  231. filters: {
  232. /**
  233. * 处理富文本里的图片宽度自适应
  234. * 1.去掉img标签里的style、width、height属性
  235. * 2.img标签添加style属性:max-width:100%;height:auto
  236. * 3.修改所有style里的width属性为max-width:100%
  237. * 4.去掉<br/>标签
  238. * @param html
  239. * @returns {void|string|*}
  240. */
  241. formatRichText(html) {
  242. //控制小程序中图片大小
  243. let newContent = html.replace(/<img[^>]*>/gi, function(match, capture) {
  244. match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');
  245. match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
  246. match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
  247. return match;
  248. });
  249. newContent = newContent.replace(/style="[^"]+"/gi, function(match, capture) {
  250. match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi, 'max-width:100%;');
  251. return match;
  252. });
  253. // newContent = newContent.replace(/<br[^>]*\/>/gi, '');
  254. newContent = newContent.replace(/<br[^>]*\/>/gi, '<p style="margin: 10px 0;"></p>');
  255. newContent = newContent.replace(/<br[^>]*\>/gi, '<p style="margin: 10px 0;"></p>');
  256. newContent = newContent.replace(/font-size:[^;]+;?/g,'');
  257. newContent = newContent.replace(/\<img/gi, '<img style="max-width:100%;height:auto;display:inline-block;margin:12rpx auto;"');
  258. return newContent;
  259. }
  260. }
  261. };
  262. </script>
  263. <style>
  264. @import './content.css';
  265. </style>