content.vue 8.3 KB

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