content.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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. <update-userinfonew :update-info="isUpdateInfo" :update-mobile="isUpdateMobile" v-if="isShowUpdate" @closeUpdate="closeUpdate" @updateInfo="updateInfo" @updateMobile="updateMobile"></update-userinfonew>
  51. </view>
  52. </template>
  53. <script>
  54. const app = getApp();
  55. const req = require('../../utils/request.js');
  56. const api = require('../../utils/api.js');
  57. const util = require('../../utils/util.js');
  58. import mpHtml from "../../components/mp-html/components/mp-html/mp-html";
  59. import serviceContact from "../../components/service-contact/index.vue";
  60. export default {
  61. components: {
  62. mpHtml,
  63. serviceContact
  64. },
  65. data() {
  66. return {
  67. detaile: '',
  68. type: 2, //详情类型:1 普通内容 2 自定义页面内容
  69. form: {
  70. page: 1,
  71. limit: 4,
  72. },
  73. contentList: [],
  74. viewMore: false,
  75. config: {},
  76. userInfo:{},
  77. query:{},
  78. id:null,
  79. webUrl:'',
  80. tempFilePath:'',
  81. isShowUpdate: false, //是否显示更新信息弹窗
  82. isUpdateInfo: false,//更新用户信息
  83. isUpdateMobile: false,//绑定手机号
  84. enterTime : '',//进入页面时间
  85. outTime : '',//页面卸载时间
  86. stayTime : 0//页面停留时间
  87. };
  88. },
  89. onLoad: async function(options) {
  90. this.query = options
  91. this.id = options.id;
  92. if(options.shareId) req.setStorage('shareId',options.shareId)
  93. // 朋友圈页面不调用登陆
  94. if(!this.query.isSharePYQ){
  95. await req.silenceLogin(options.userId, '');
  96. setTimeout(()=>{
  97. this.getUpdate()
  98. },500)
  99. }
  100. setTimeout(()=>{
  101. this.userInfo = req.getStorage('userInfo')
  102. },500)
  103. uni.showShareMenu({
  104. withShareTicket: true,
  105. menus: ['shareAppMessage', 'shareTimeline']
  106. });
  107. await this.getDetail();
  108. this.getContentList();
  109. // await this.monitor();
  110. },
  111. async onShow(){
  112. // 用户进入时间
  113. this.enterTime = new Date();
  114. console.log('---用户进入时间---',this.enterTime);
  115. this.getConfig()
  116. this.getBrowse();
  117. },
  118. onHide(){
  119. // 用户退出时间
  120. this.outTime = new Date();
  121. //停留时间(毫秒)
  122. this.stayTime = (this.outTime.getTime() - this.enterTime.getTime());
  123. console.log('---用户浏览---',Math.ceil(this.stayTime/1000))
  124. req.saveBehaviorNew(this.id,3,4,'','',this.query.userId,Math.ceil(this.stayTime/1000))
  125. },
  126. onUnload(){
  127. // 用户退出时间
  128. this.outTime = new Date();
  129. //停留时间(毫秒)
  130. this.stayTime = (this.outTime.getTime() - this.enterTime.getTime());
  131. console.log('---用户浏览总时长---',Math.ceil(this.stayTime/1000))
  132. req.saveBehaviorNew(this.id,3,4,'','',this.query.userId,Math.ceil(this.stayTime/1000))
  133. },
  134. onShareAppMessage() {
  135. req.saveBehaviorNew(this.id,3,6)
  136. return {
  137. title: this.detaile.title,
  138. imageUrl: this.detaile.pic,
  139. path: '/topic/content/content?id=' + this.id +'&isShare=' + true+(this.userInfo.userType==1?('&shareId='+this.userInfo.saleNo):'') + (req.getStorage('userInfo')?'&userId=' + req.getStorage('userInfo').id:'')
  140. };
  141. },
  142. onShareTimeline() {
  143. req.saveBehaviorNew(this.id,3,6)
  144. return {
  145. title: this.detaile.title,
  146. imageUrl: this.tempFilePath?this.tempFilePath:this.detaile.pic,
  147. path: '/topic/content/content',
  148. query:'id=' + this.id+'&isSharePYQ=' + true +'&isShare=' + true+(this.userInfo.userType==1?('&shareId='+this.userInfo.saleNo):'') + (req.getStorage('userInfo')?'&userId=' + req.getStorage('userInfo').id:'')
  149. };
  150. },
  151. methods: {
  152. /*获取分享图 */
  153. async getShareImg(){
  154. let tempFilePath = await new Promise((r,j)=>{
  155. try{
  156. uni.getImageInfo({
  157. src:this.detaile.pic,
  158. success: (data) => {
  159. uni.compressImage({
  160. src:data.path,
  161. quality:0.5,
  162. success:(res)=>{
  163. console.log('压缩成功',res.tempFilePath)
  164. r(res.tempFilePath)
  165. },
  166. fail: (error) => {
  167. console.log('压缩失败',error)
  168. r('')
  169. }
  170. })
  171. },
  172. fail: () => {
  173. r('')
  174. }
  175. })
  176. }catch(e){
  177. //TODO handle the exception
  178. r('')
  179. }
  180. })
  181. this.tempFilePath = tempFilePath
  182. },
  183. getConfig() {
  184. var _this = this;
  185. return new Promise((res, rej) => {
  186. req.g(
  187. '/api/other/config',
  188. data => {
  189. req.setStorage('configRes', JSON.stringify(data));
  190. this.config = data;
  191. res(data);
  192. },
  193. true
  194. );
  195. });
  196. },
  197. monitor() {
  198. let that = this;
  199. let system = uni.getSystemInfoSync();
  200. let query = uni.createSelectorQuery();
  201. query.select('.viewMore').boundingClientRect(data=>{
  202. let height = data.height;
  203. if(height > system.screenHeight) {
  204. this.viewMore = true
  205. }
  206. }).exec();
  207. },
  208. viewMores(){
  209. this.viewMore = true;
  210. },
  211. choose: function () {
  212. let freshen = false;
  213. this.$emit('freshen', {
  214. detail: freshen
  215. });
  216. },
  217. toIndex(){
  218. uni.switchTab({
  219. url: '/pages/index/index'
  220. })
  221. },
  222. getDateTimeStamp(dateStr){
  223. return util.getDateDiff(Date.parse(dateStr.replace(/-/gi,"/")));
  224. },
  225. getDetail() {
  226. let that = this;
  227. let apiUrl = '/api/content/detail';
  228. return new Promise((resolve,reject)=>{
  229. req.getRequest(apiUrl,{ id: that.id },async res => {
  230. if(res.productCategory){
  231. res.productCategory = res.productCategory.split(',')
  232. }
  233. that.detaile = res;
  234. that.getShareImg()
  235. that.webUrl = that.detaile.linkUrl?that.detaile.linkUrl:''
  236. let arr = [];
  237. if(res.productCategory && res.productCategory.length > 0){
  238. for (var i = 0; i < res.productCategory.length; i++) {
  239. await that.getProductList(res.productCategory[i], i).then(res=>{
  240. arr = arr.concat(res);
  241. that.productList = arr;
  242. console.log('相关产品=='+JSON.stringify(arr),arr.length)
  243. });
  244. }
  245. }
  246. resolve();
  247. },true);
  248. })
  249. },
  250. getBrowse(){
  251. var dataP = {};
  252. dataP.type =
  253. 4 //、产品 2、活动 3、未知 4、内容 5、课程 6、老师 7、素材 8、题目 9、资料领取 10、招聘职位 12、用户须知 13、素材 15、医院科室 16、海报 20、医生 21 新闻 23名片
  254. dataP.behavior = 4; //1、关注 2、收藏 3、点赞 4、浏览 5、确认 6、分享
  255. dataP.bindId = this.id;
  256. req.postRequestLoding('/api/v3/behavior/save', dataP, data => {
  257. });
  258. },
  259. // 用户行为
  260. userBehavior() {
  261. var dataP = {};
  262. dataP.type =
  263. 4 //、产品 2、活动 3、未知 4、内容 5、课程 6、老师 7、素材 8、题目 9、资料领取 10、招聘职位 12、用户须知 13、素材 15、医院科室 16、海报 20、医生 21 新闻 23名片
  264. dataP.behavior = 3; //1、关注 2、收藏 3、点赞 4、浏览 5、确认 6、分享
  265. dataP.bindId = this.id;
  266. req.postRequestLoding('/api/v3/behavior/save', dataP, data => {
  267. if(this.detaile.isThumbs){
  268. this.detaile.thumbsNumber = this.detaile.thumbsNumber-1
  269. }else{
  270. this.detaile.thumbsNumber = this.detaile.thumbsNumber+1
  271. }
  272. this.detaile.isThumbs = !this.detaile.isThumbs
  273. if(this.detaile.isThumbs){
  274. req.saveBehaviorNew(this.id,3,3)
  275. }else{
  276. req.saveBehaviorNew(this.id,3,11)
  277. }
  278. });
  279. },
  280. getContentList() {
  281. let form = this.form;
  282. form.cid = this.detaile.cid;
  283. if(req.getStorage("shareId")){
  284. form.shareSaleNo = req.getStorage("shareId")
  285. }
  286. req.getRequest('/api/content/list',form,res => {
  287. this.contentList = res;
  288. for (var i = 0; i < this.contentList.length; i++) {
  289. if (this.contentList[i].id == this.id){
  290. this.contentList.splice(i,1);
  291. }
  292. }
  293. });
  294. },
  295. closeUpdate(){
  296. this.isShowUpdate = false
  297. },
  298. updateInfo(e){
  299. this.isUpdateInfo = e;
  300. },
  301. updateMobile(e){
  302. this.isUpdateMobile = e;
  303. },
  304. getUpdate() {
  305. console.log('getUpdate')
  306. let userInfos = req.getStorage('userInfo')
  307. // if ((!userInfos.avatar || userInfos.avatar.indexOf('thirdwx.qlogo') > -1 || !userInfos.nickName || userInfos.nickName.indexOf('用户') > -1) ) {
  308. // console.log('没有昵称')
  309. // this.isShowUpdate = true;
  310. // this.isUpdateInfo = true;
  311. // return false;
  312. // }
  313. if(!userInfos.mobile){
  314. console.log('没有手机号')
  315. this.isShowUpdate = true
  316. this.isUpdateMobile = true
  317. return false;
  318. }
  319. return true;
  320. },
  321. },
  322. filters: {
  323. /**
  324. * 处理富文本里的图片宽度自适应
  325. * 1.去掉img标签里的style、width、height属性
  326. * 2.img标签添加style属性:max-width:100%;height:auto
  327. * 3.修改所有style里的width属性为max-width:100%
  328. * 4.去掉<br/>标签
  329. * @param html
  330. * @returns {void|string|*}
  331. */
  332. formatRichText(html) {
  333. //控制小程序中图片大小
  334. let newContent = html.replace(/<img[^>]*>/gi, function(match, capture) {
  335. match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');
  336. match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
  337. match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
  338. return match;
  339. });
  340. newContent = newContent.replace(/style="[^"]+"/gi, function(match, capture) {
  341. match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi, 'max-width:100%;');
  342. return match;
  343. });
  344. // newContent = newContent.replace(/<br[^>]*\/>/gi, '');
  345. newContent = newContent.replace(/<br[^>]*\/>/gi, '<p style="margin: 10px 0;"></p>');
  346. newContent = newContent.replace(/<br[^>]*\>/gi, '<p style="margin: 10px 0;"></p>');
  347. newContent = newContent.replace(/font-size:[^;]+;?/g,'');
  348. newContent = newContent.replace(/\<img/gi, '<img style="max-width:100%;height:auto;display:inline-block;margin:12rpx auto;"');
  349. return newContent;
  350. }
  351. }
  352. };
  353. </script>
  354. <style>
  355. @import './content.css';
  356. </style>