index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. <template>
  2. <view v-if="detaile">
  3. <view class="top-fixed" :style="'height:' + systems.barHeight + 'rpx;'">
  4. <view class="user dflex" :style="'margin-top:' + systems.ktxStatusHeight + 'rpx;height:' + systems.navigationHeight + 'rpx;'" v-if="detaile.user">
  5. <image :src="detaile.user.avatar ? detaile.user.avatar : '../../static/images/userimg.png'" class="userimg"></image>
  6. <view class="flex">{{detaile.user.nickName}}</view>
  7. <view class="share-top" @click="showShare()"><image src="../../static/images/share1.png"></image></view>
  8. </view>
  9. </view>
  10. <view :style="'height:' + systems.barHeight + 'rpx;'"></view>
  11. <block v-if="detaile.params&&detaile.params.imageList&&detaile.params.imageList.length > 0">
  12. <view class="banner">
  13. <view class="pic-nums">{{swiperCurrent+1}}/{{detaile.params.imageList.length}}</view>
  14. <swiper class="swiper" @change="swiperChange" autoplay="true" interval="5000" duration="300">
  15. <block v-for="(item, index) in detaile.params.imageList" :key="index">
  16. <swiper-item><image lazy-load="true" :src="item.url" mode="aspectFill"></image></swiper-item>
  17. </block>
  18. </swiper>
  19. <view class="dots ddflex">
  20. <block v-for="(item, index) in detaile.params.imageList" :key="index"><view :class="['dot', index == swiperCurrent ? 'active' : '']"></view></block>
  21. </view>
  22. </view>
  23. </block>
  24. <block v-if="detaile.params&&detaile.params.product">
  25. <view class="pro dflex">
  26. <image :src="detaile.params.product.icon" mode="aspectFit" class="proimg"></image>
  27. <view class="fflex">
  28. <view class="proname">{{detaile.params.product.title}}</view>
  29. <view class="ope dflex">
  30. <view class="price dflex">
  31. ¥<text>{{detaile.params.product.money}}</text>
  32. </view>
  33. <view v-html="wxOpenTags"></view>
  34. <!-- <view class="btn">立即抢购</view> -->
  35. </view>
  36. </view>
  37. </view>
  38. </block>
  39. <view class="title">{{ detaile.title }}</view>
  40. <view class="content">
  41. <view :class="'viewMore' + (viewMoress?' con-vheight':'')" :style="'max-height:' + height">
  42. <mp-html :content="detaile.text" :lazy-load="true" @imgtap="choose"></mp-html>
  43. </view>
  44. <view class="view-more" @tap="viewMores()" v-if="viewMoress">查看全文</view>
  45. </view>
  46. <view class="operate ddflex">
  47. <view class="time">编辑于{{getDateTimeStamp(detaile.createDate)}}</view>
  48. <view class="flex dflex">
  49. <view class="zan ddflex"><image src="../static/images/view.png"></image>{{detaile.browseCount}}</view>
  50. <view class="zan ddflex" @click="thumbs()"><image :src="'../../static/images/' + (detaile.isThumbs ? 'like1_h.png' : 'like1.png')"></image>{{detaile.thumbsCount}}</view>
  51. </view>
  52. <view class="share ddflex" @click="showShare()"><image src="../static/images/share.png"></image>分享</view>
  53. </view>
  54. <view class="box" v-if="contentList && contentList.length > 0">
  55. <view class="tit ddflex">为您推荐</view>
  56. <view class="rec">
  57. <navigator :url="'/other/content/index?code=' + item.code + '&rootCode=' + rootCode" hover-class="none" class="li ddflex" v-for="(item,index) in contentList" :key="index" v-if="index < 3">
  58. <view class="fflex">
  59. <view class="rec-tit tovers">{{item.title}}</view>
  60. <view class="ddflex">
  61. <!-- <view class="author ddflex"><image src="../../static/pages/images/zbgw.png" mode="aspectFill"></image>欧衡</view> -->
  62. <view class="rec-time">{{item.createDate}}</view>
  63. </view>
  64. </view>
  65. <image :src="item.pic" mode="aspectFill" class="rec-img"></image>
  66. </navigator>
  67. </view>
  68. </view>
  69. <share-group :is-show-share="isShowShare" :bottom-positon="bottomPositon" :material-params="detaile" @hidePop="hideShare"></share-group>
  70. </view>
  71. </template>
  72. <script>
  73. const app = getApp();
  74. const req = require('../../utils/request.js');
  75. const api = require('../../utils/api.js');
  76. const util = require('../../utils/util.js');
  77. import mpHtml from "../../components/mp-html/components/mp-html/mp-html";
  78. export default {
  79. components: {
  80. mpHtml,
  81. },
  82. data() {
  83. return {
  84. systems: {},
  85. code: '',
  86. rootCode: '',
  87. detaile: '',
  88. type: 2, //详情类型:1 普通内容 2 自定义页面内容
  89. form: {
  90. page: 1,
  91. limit: 4,
  92. },
  93. contentList: [],
  94. height: 'initial',
  95. viewMoress: false,
  96. productList: [],
  97. merchant: {},
  98. bannerList: [],
  99. swiperCurrent: 0,
  100. isShowShare: false,
  101. bottomPositon: '-100%',
  102. wxOpenTags: ''
  103. };
  104. },
  105. onLoad: async function(options) {
  106. if(options.detail){
  107. let params = JSON.parse(decodeURIComponent(options.detail));
  108. console.log('params==',params)
  109. this.code = params.code;
  110. this.shareCode = params.shareCode
  111. this.rootCode = params.rootCode
  112. if(params.appId){
  113. req.setStorage('appId',params.appId)
  114. }
  115. // if(params.userId){
  116. // req.setStorage('pidCode', params.userId);
  117. // }
  118. }
  119. if(options.x_code_id){
  120. console.log('options==',options)
  121. this.sceneId = options.x_code_id
  122. await this.loadCodeParams()
  123. }
  124. await this.getDetail();
  125. this.getContentList();
  126. if(this.detaile.text){
  127. setTimeout(async res=>{
  128. await this.monitor();
  129. },500)
  130. }
  131. if(this.detaile.product){
  132. this.getWxConfig();
  133. }
  134. },
  135. onShow(){
  136. },
  137. methods: {
  138. getWxConfig(){
  139. let that = this;
  140. if (uni.getSystemInfoSync().platform == 'ios') {
  141. var href = window.location.href.split('#')[0] || window.location.href
  142. } else {
  143. var href = window.location.href
  144. }
  145. // 这里要换成自己的api接口,返回公众号配置
  146. req.getRequest(api.getWeiXinJsApiInfo, {
  147. url: href
  148. }).then(response => {
  149. jWeixin.config({
  150. debug: response.debug,
  151. appId: response.appId,
  152. timestamp: response.timestamp,
  153. nonceStr: response.nonceStr,
  154. signature: response.signature,
  155. jsApiList: response.jsApiList,
  156. openTagList:[
  157. 'wx-open-launch-weapp'//打开小程序
  158. ]
  159. })
  160. jWeixin.ready(() => {
  161. setTimeout(()=>{
  162. // 这里的username代表小程序的原始id,需要到小程序后台去看,和appid不同,需要换成自己的小城id
  163. that.wxOpenTags=`<wx-open-launch-weapp path="pages/index/index" id="launch-wxapp" username="gh_6ff3f1da728a">
  164. <template>
  165. <style>
  166. .btn-open-weapp{
  167. background: linear-gradient(to right, #ffd52e 0%, #ffef93 50%, #ffd52e 100%);
  168. border: 0;
  169. color: #424242;
  170. text-shadow: 0px 1px 1px #fff;
  171. border-radius: 50px;
  172. text-align: center;
  173. width: 120px;
  174. height: 35px;
  175. line-height: 35px;
  176. outline:none;
  177. }
  178. </style>
  179. <button class="btn-open-weapp">立即抢购</button >
  180. </template>
  181. </wx-open-launch-weapp>`;
  182. },1000);
  183. })
  184. }).catch(error => {
  185. console.log(error)
  186. })
  187. },
  188. monitor() {
  189. let that = this;
  190. let system = uni.getSystemInfoSync();
  191. let query = uni.createSelectorQuery();
  192. query.select('.viewMore').boundingClientRect(data=>{
  193. if(data){
  194. let height = data.height;
  195. if(height > system.windowHeight*2) {
  196. that.height = system.windowHeight *1.8 + 'px';
  197. that.viewMoress = true
  198. }
  199. }
  200. }).exec();
  201. },
  202. viewMores(){
  203. this.height = 'initial';
  204. this.viewMoress = false;
  205. },
  206. choose: function () {
  207. let freshen = false;
  208. this.$emit('freshen', {
  209. detail: freshen
  210. });
  211. },
  212. toIndex(){
  213. uni.switchTab({
  214. url: '/pages/index/index'
  215. })
  216. },
  217. getDateTimeStamp(dateStr){
  218. return util.getDateDiff(Date.parse(dateStr.replace(/-/gi,"/")));
  219. },
  220. getDetail() {
  221. let that = this;
  222. let apiUrl = api.api_material_detail;
  223. return new Promise((resolve,reject)=>{
  224. req.getRequest(apiUrl,{ code: that.code },async res => {
  225. that.detaile = res;
  226. resolve();
  227. },true);
  228. })
  229. },
  230. getContentList() {
  231. let form = this.form;
  232. form.rootCode = this.rootCode;
  233. req.getRequest(api.api_material_library,form,res => {
  234. this.contentList = res.list;
  235. for (var i = 0; i < this.contentList.length; i++) {
  236. if (this.contentList[i].code == this.code){
  237. this.contentList.splice(i,1);
  238. }
  239. }
  240. });
  241. },
  242. getBannerList() {
  243. let that = this;
  244. req.getRequest('/api/banner', {
  245. groupId: '1196269897935630413'
  246. }, data => {
  247. that.bannerList = data;
  248. });
  249. },
  250. swiperChange(e) {
  251. this.swiperCurrent = e.detail.current;
  252. },
  253. clickBanner(item) {
  254. let url = '';
  255. if (item.type * 1 == 2 && item.content != "") {
  256. url = "product/detail/detail?id=" + item.content;
  257. } else if (item.type * 1 == 5) {
  258. url = "product/coupon/coupon";
  259. } else if (item.type * 1 == 6) {
  260. url = "service/live/live";
  261. } else if (item.type * 1 == 9 && item.content != "") {
  262. url = "product/list/list?id=" + item.content;
  263. } else if (item.type * 1 == 10) {
  264. url = "plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id=" + item.content;
  265. // console.log(
  266. // url); // url=`plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id=${dt.content}`
  267. } else if (item.type * 1 == 19 && item.content != "") {//文章内容
  268. url = "topic/content/content?id=" + item.content;//1为普通文章内容
  269. } else {
  270. url = "";
  271. }
  272. if (item.type * 1 == 6) app.globalData.switchTab(url);
  273. else app.globalData.openPage(url);
  274. },
  275. thumbs(){
  276. req.postRequest(api.api_material_thumbs,{code: this.detaile.code},data=>{
  277. if(this.detaile.isThumbs){
  278. this.detaile.isThumbs = false
  279. this.detaile.thumbsCount--
  280. }else{
  281. this.detaile.isThumbs = true
  282. this.detaile.thumbsCount++
  283. }
  284. })
  285. },
  286. showShare(){
  287. console.log('点击显示分享')
  288. this.isShowShare = true
  289. this.bottomPositon = 0
  290. this.$forceUpdate()
  291. },
  292. hideShare(){
  293. this.isShowShare = false
  294. this.bottomPositon = '-100%'
  295. },
  296. },
  297. created() {
  298. const systemInfo = uni.getSystemInfoSync();
  299. // px转换到rpx的比例
  300. let pxToRpxScale = 750 / systemInfo.windowWidth;
  301. let systems = {
  302. ktxStatusHeight: systemInfo.statusBarHeight * pxToRpxScale, // 状态栏的高度
  303. navigationHeight: 44 * pxToRpxScale // 导航栏的高度
  304. };
  305. systems.barHeight = systems.ktxStatusHeight + systems.navigationHeight;
  306. this.systems = systems;
  307. },
  308. filters: {
  309. /**
  310. * 处理富文本里的图片宽度自适应
  311. * 1.去掉img标签里的style、width、height属性
  312. * 2.img标签添加style属性:max-width:100%;height:auto
  313. * 3.修改所有style里的width属性为max-width:100%
  314. * 4.去掉<br/>标签
  315. * @param html
  316. * @returns {void|string|*}
  317. */
  318. formatRichText(html) {
  319. //控制小程序中图片大小
  320. let newContent = html.replace(/<img[^>]*>/gi, function(match, capture) {
  321. match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');
  322. match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
  323. match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
  324. return match;
  325. });
  326. newContent = newContent.replace(/style="[^"]+"/gi, function(match, capture) {
  327. match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi, 'max-width:100%;');
  328. return match;
  329. });
  330. // newContent = newContent.replace(/<br[^>]*\/>/gi, '');
  331. newContent = newContent.replace(/<br[^>]*\/>/gi, '<p style="margin: 10px 0;"></p>');
  332. newContent = newContent.replace(/<br[^>]*\>/gi, '<p style="margin: 10px 0;"></p>');
  333. newContent = newContent.replace(/font-size:[^;]+;?/g,'');
  334. newContent = newContent.replace(/\<img/gi, '<img style="max-width:100%;height:auto;display:inline-block;margin:12rpx auto;"');
  335. return newContent;
  336. }
  337. }
  338. };
  339. </script>
  340. <style>
  341. @import './index.css';
  342. </style>