index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. <template>
  2. <view>
  3. <view class="top-fixed" :style="'height:'+systems.barHeight+'rpx;'">
  4. <view :style="'height: '+systems.ktxStatusHeight+'rpx;'"></view>
  5. <view class="ddflex">
  6. <view class="back ddflex"
  7. :style="'height: '+systems.navigationHeight+'rpx;line-height: '+systems.navigationHeight+'rpx;'"
  8. @click="toBack">
  9. <image src="../static/images/back_black.png" mode="aspectFit"></image>
  10. </view>
  11. <view class="fflex" style="text-align: center;margin-left: rpx;"></view>
  12. </view>
  13. </view>
  14. <view :style="'height:'+systems.barHeight+'rpx;'"></view>
  15. <view class="ceng" v-if="isShowAdd" @click="isShowAdd = false"></view>
  16. <view v-if="detaile">
  17. <view style="background-color: #fff;padding: 40rpx 0;">
  18. <view class="title">{{ detaile.title }}</view>
  19. <view class="det-sta ddflex">
  20. <view class="sort" v-if="detaile.cateName">{{detaile.cateName}}</view>
  21. <view class="sort-line" v-if="detaile.cateName"></view>
  22. <view class="time" style="color: #5B698F;">
  23. {{detaile.user&&detaile.user.nickName?detaile.user.nickName:config.CONFIG_PROJECT_TITLE}}
  24. </view>
  25. <view class="time" style="margin-left: 10rpx;">
  26. {{formatTime(detaile.createDate)}}
  27. </view>
  28. </view>
  29. <view class="pro" v-if="detaile.params&&detaile.params.product">
  30. <view class="li ddflex" @click="jumpUrl('/product/detail/detail?id='+detaile.params.product.id)">
  31. <image :src="detaile.params.product.icon" mode="aspectFill" class="proimg"></image>
  32. <view class="fflex">
  33. <view class="proname fflex tovers">{{detaile.params.product.title}}</view>
  34. <view class="proprice">¥{{detaile.params.product.money}}</view>
  35. <view class="ope dflex">
  36. <view class="ope-btn ddflex">购买</view>
  37. </view>
  38. </view>
  39. </view>
  40. </view>
  41. <view class="content">
  42. <view :class="'viewMore' + (viewMoress?' con-vheight':'')" :style="'max-height:' + height">
  43. <mp-html :content="detaile.text" :lazy-load="true" @imgtap="choose"></mp-html>
  44. </view>
  45. <view class="view-more" @tap="viewMores()" v-if="viewMoress">查看全文</view>
  46. <!-- <view :class="'viewMore' + (viewMore?'':' con-vheight')">
  47. <mp-html :content="detaile.text" :lazy-load="true" @imgtap="choose"></mp-html>
  48. </view>
  49. <view class="view-more" @tap="viewMores()" v-if="!viewMore">查看全文</view> -->
  50. </view>
  51. <view class="bottom-info">
  52. <view class="bottom-info-browse">浏览 {{detaile.browseCount}}</view>
  53. <view style="margin-top: 20rpx;">
  54. <view class="ddflex">
  55. <image class="bottom-info-logo" :src="config.CONFIG_PROJECT_LOGO"></image>
  56. <view class="fflex">{{config.CONFIG_PROJECT_TITLE}}</view>
  57. <view class="bottom-info-option" @click="showShare()">
  58. <image style="width: 32rpx;height: 32rpx;margin: auto;" src="../static/images/share.png"></image>
  59. <view>分享</view>
  60. </view>
  61. <view class="bottom-info-option" style="margin-left: 50rpx;">
  62. <image v-if="!detaile.isThumbs" style="width: 32rpx;height: 32rpx;margin: auto;" src="../static/images/dz.png" @click="thumbs(true)"></image>
  63. <image v-if="detaile.isThumbs" style="width: 32rpx;height: 32rpx;margin: auto;" src="../static/images/dz_h.png" @click="thumbs(false)"></image>
  64. <view>{{detaile.thumbsCount?detaile.thumbsCount:0}}</view>
  65. </view>
  66. </view>
  67. </view>
  68. </view>
  69. </view>
  70. <view class="guwen ddflex" v-if="cardInfo" @click="jumpUrl('/card/index/index?cardId='+cardInfo.id)">
  71. <image :src="picUrlss+'lvluo/home_guwen.png'" class="guwen-img"></image>
  72. <view class="fflex">
  73. <view class="ddflex">
  74. <image :src="cardInfo.imageMap?cardInfo.imageMap:picUrlss+'lvluo/hulei.png'" class="guwen-user"></image>
  75. <view class="fflex">
  76. <view class="guwen-name ddflex">{{cardInfo&&cardInfo.realName?cardInfo.realName:'胡雷'}}</view>
  77. <text class="guwen-tag">{{cardInfo&&cardInfo.job?cardInfo.job:'绿萝云-诊所私域专家'}}</text>
  78. <view class="guwen-mobile">{{cardInfo&&cardInfo.phone?cardInfo.phone:'15173158288'}}</view>
  79. </view>
  80. </view>
  81. </view>
  82. <view class="guwen-ewm">
  83. <image :src="cardInfo.qrCode?cardInfo.qrCode:picUrlss+'lvluo/wechat.png'" show-menu-by-longpress="true"></image>
  84. <view>长按扫码添加微信</view>
  85. </view>
  86. </view>
  87. </view>
  88. <!-- #ifdef H5 -->
  89. <view class="share-pop" @click="hideSharePop" v-if="isShowSharePop">
  90. <image src="../static/images/fx-tip1.png"></image>
  91. </view>
  92. <wx-share ref="wxshare" />
  93. <!-- #endif -->
  94. </view>
  95. </template>
  96. <script>
  97. const app = getApp();
  98. const req = require('../../utils/request.js');
  99. const api = require('../../utils/api.js');
  100. const util = require('../../utils/util.js');
  101. import mpHtml from "../../components/mp-html/components/mp-html/mp-html";
  102. export default {
  103. components: {
  104. mpHtml,
  105. },
  106. data() {
  107. return {
  108. picUrlss: req.public.picUrls,
  109. systems: {},
  110. isTop: 0,
  111. isShowAdd: false,
  112. options:{},
  113. code: '',
  114. rootCode: '',
  115. detaile: '',
  116. type: 2, //详情类型:1 普通内容 2 自定义页面内容
  117. form: {
  118. page: 1,
  119. limit: 4,
  120. },
  121. height: 'initial',
  122. viewMoress: false,
  123. productList: [],
  124. merchant: {},
  125. bannerList: [],
  126. swiperCurrent: 0,
  127. isShowShare: false,
  128. bottomPositon: '-100%',
  129. config:{},
  130. cardInfo:'',
  131. hideShare: true,
  132. isShowSharePop: false,
  133. first:true
  134. };
  135. },
  136. onLoad: async function(options) {
  137. this.options = options
  138. if (options.appId) req.setStorage('appId', options.appId);
  139. if (options.x_code_id){
  140. options = await this.loadCodeParams(options.x_code_id)
  141. }
  142. this.PAGE_DATA_INIT_FN({
  143. BIND_ID:this.options.code
  144. })
  145. await req.silenceLogin(this.options.userId);
  146. this.code = options.code;
  147. this.rootCode = options.rootCode
  148. if(options.userId){
  149. req.setStorage('pidCode', options.userId);
  150. }
  151. this.getConfig()
  152. await this.getDetail();
  153. setTimeout(async res=>{
  154. await this.monitor();
  155. },500)
  156. if(this.options.userId)
  157. this.getCardInfo()
  158. },
  159. onShow(){
  160. if(this.options.userId){
  161. this.getCardInfo()
  162. }
  163. if(!this.first){
  164. this.getDetail();
  165. }
  166. },
  167. onShareAppMessage: async function(options) {
  168. var content = await this.onShareMessage();
  169. this.SEND_SHARE_FN()
  170. return content;
  171. },
  172. onReady() {
  173. // #ifdef H5
  174. var that = this;
  175. //初始化分享内容
  176. setTimeout(async function() {
  177. var shareContent = await that.onShareMessage();
  178. if (shareContent) {
  179. shareContent.path = window.location.origin + shareContent.path;
  180. }
  181. that.$refs.wxshare.init(shareContent);
  182. }, 4 * 1000);
  183. // #endif
  184. },
  185. methods: {
  186. toBack() {
  187. let pages = getCurrentPages();
  188. if (pages.length > 1) {
  189. uni.navigateBack()
  190. }else{
  191. uni.switchTab({
  192. url:'/pages/tabBar/index'
  193. })
  194. }
  195. },
  196. async onShareMessage(options) {
  197. let isSolution = '';
  198. let path = '';
  199. // #ifndef H5
  200. isSolution = req.env[req.env.NODE_ENV].isSolution;
  201. // #endif
  202. // #ifdef H5
  203. isSolution = false;
  204. // #endif
  205. let userInfo = req.getStorage('userInfo');
  206. if (isSolution) {
  207. path = '/share/home/index?appId=' + req.getStorage('appId') + '&userId=' + req.getStorage(
  208. 'userInfo').id;
  209. } else {
  210. let page = getCurrentPages()
  211. let pageCurrent = page[page.length-1]
  212. path = pageCurrent.route+'?code=' + this.code + '&rootCode=' + this.rootCode + '&isShare=' + true + '&appId=' + req
  213. .getStorage('appId');
  214. // console.log(!req.getStorage('userInfo').id);
  215. if (!userInfo.id) {} else {
  216. path += '&userId=' + userInfo.id;
  217. }
  218. path = this.SHARE_BEHAVIOR_FN({path:path,sendShare:false}).path
  219. }
  220. console.log({
  221. title: this.detaile.title,
  222. imageUrl: this.detaile.pic,
  223. path: path
  224. })
  225. return {
  226. title: this.detaile.title,
  227. imageUrl: this.detaile.pic,
  228. path: path
  229. };
  230. },
  231. showShare() {
  232. // console.log(11111,this.hideShare)
  233. // #ifdef H5
  234. this.hideShare = false;
  235. this.showSharePop();
  236. console.log('引导分享==')
  237. // #endif
  238. },
  239. showSharePop() {
  240. this.isShowSharePop = true;
  241. },
  242. hideSharePop() {
  243. this.isShowSharePop = false;
  244. },
  245. closePop(){
  246. this.isShowAdd = false
  247. },
  248. jumpUrl(url){
  249. this.isShowAdd = false
  250. uni.navigateTo({
  251. url:url
  252. })
  253. },
  254. getConfig() {
  255. req.getRequest('/api/config', {}, res => {
  256. this.config = res
  257. })
  258. },
  259. loadCodeParams(scene) {
  260. let _ts = this;
  261. return new Promise((resolve, reject) => {
  262. let form = {
  263. scene: scene
  264. };
  265. if (!scene) {
  266. resolve();
  267. return false;
  268. }
  269. req.getRequest('/api/code/params', form, data => {
  270. let res = JSON.parse(data.scene)
  271. for(let key in res){
  272. this.options[key] = res[key]
  273. }
  274. resolve(res);
  275. });
  276. });
  277. },
  278. monitor() {
  279. let that = this;
  280. let system = uni.getSystemInfoSync();
  281. let query = uni.createSelectorQuery();
  282. query.select('.viewMore').boundingClientRect(data=>{
  283. if(data){
  284. let height = data.height;
  285. if(height > system.windowHeight*2) {
  286. that.height = system.windowHeight *1.8 + 'px';
  287. that.viewMoress = true
  288. }
  289. }
  290. }).exec();
  291. },
  292. viewMores(){
  293. this.height = 'initial';
  294. this.viewMoress = false;
  295. },
  296. choose: function () {
  297. let freshen = false;
  298. this.$emit('freshen', {
  299. detail: freshen
  300. });
  301. },
  302. toIndex(){
  303. uni.switchTab({
  304. url: '/pages/index/index'
  305. })
  306. },
  307. getDateTimeStamp(dateStr){
  308. return util.getDateDiff(Date.parse(dateStr.replace(/-/gi,"/")));
  309. },
  310. getDetail() {
  311. let that = this;
  312. let apiUrl = '/api/v3/material/library/detail';
  313. return new Promise((resolve,reject)=>{
  314. req.getRequest(apiUrl,{ code: that.code },async res => {
  315. that.detaile = res;
  316. this.first = false
  317. resolve();
  318. },true);
  319. })
  320. },
  321. thumbs(type){
  322. if(req.isLogins(true)){
  323. if(type){//点赞
  324. this.SEND_COLLECT_FN({IS_THUMBS:true})
  325. this.detaile.isThumbs = true
  326. this.detaile.thumbsCount++
  327. }else{//取消点赞
  328. this.SEND_COLLECT_FN({IS_THUMBS:false})
  329. this.detaile.isThumbs = false
  330. this.detaile.thumbsCount--
  331. }
  332. }
  333. },
  334. hasAppAuthPermissions(key) {
  335. return req.hasAppAuthPermissions(key)
  336. },
  337. toCard() {
  338. this.jumpUrl('/card/index/index');
  339. },
  340. getCardInfo() {
  341. var url = '';
  342. var dataP = {};
  343. url = '/api/v3/visiting/card/user';
  344. dataP.userId = this.options.userId;
  345. req.getRequest(url, dataP, data => {
  346. this.cardInfo = data;
  347. }, false);
  348. },
  349. formatTime(time){
  350. let date = new Date(time.replace(/-/g,'/'))
  351. return util.formatTimeComm(date,'Y.M.D h:m')
  352. },
  353. },
  354. filters: {
  355. /**
  356. * 处理富文本里的图片宽度自适应
  357. * 1.去掉img标签里的style、width、height属性
  358. * 2.img标签添加style属性:max-width:100%;height:auto
  359. * 3.修改所有style里的width属性为max-width:100%
  360. * 4.去掉<br/>标签
  361. * @param html
  362. * @returns {void|string|*}
  363. */
  364. formatRichText(html) {
  365. //控制小程序中图片大小
  366. let newContent = html.replace(/<img[^>]*>/gi, function(match, capture) {
  367. match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');
  368. match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
  369. match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
  370. return match;
  371. });
  372. newContent = newContent.replace(/style="[^"]+"/gi, function(match, capture) {
  373. match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi, 'max-width:100%;');
  374. return match;
  375. });
  376. // newContent = newContent.replace(/<br[^>]*\/>/gi, '');
  377. newContent = newContent.replace(/<br[^>]*\/>/gi, '<p style="margin: 10px 0;"></p>');
  378. newContent = newContent.replace(/<br[^>]*\>/gi, '<p style="margin: 10px 0;"></p>');
  379. newContent = newContent.replace(/font-size:[^;]+;?/g,'');
  380. newContent = newContent.replace(/\<img/gi, '<img style="max-width:100%;height:auto;display:inline-block;margin:12rpx auto;"');
  381. return newContent;
  382. }
  383. },
  384. mounted() {
  385. const systemInfo = uni.getSystemInfoSync();
  386. // px转换到rpx的比例
  387. let pxToRpxScale = 750 / systemInfo.windowWidth;
  388. let systems = {
  389. ktxStatusHeight: systemInfo.statusBarHeight * pxToRpxScale, // 状态栏的高度
  390. navigationHeight: 44 * pxToRpxScale // 导航栏的高度
  391. };
  392. systems.barHeight = systems.ktxStatusHeight + systems.navigationHeight;
  393. this.systems = systems;
  394. },
  395. };
  396. </script>
  397. <style>
  398. @import './index.css';
  399. </style>