content.vue 8.6 KB

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