content.vue 11 KB

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