content.vue 9.2 KB

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