plDetail.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. <template>
  2. <view class="content">
  3. <view class="top">
  4. <image :src="info.main_pic || ''" mode="widthFix"></image>
  5. </view>
  6. <view class="title">{{ info.title || '' }}</view>
  7. <view class="tip">{{ info.comment || '' }}</view>
  8. <view class="main" v-for="(ls, index) in info.pics" :key="index">
  9. <image :src="ls" mode="widthFix"></image>
  10. </view>
  11. <view class="navbar flex">
  12. <view class="navbar-item" @click.stop="shareLink()">
  13. <view class="navbar-icon">
  14. <image src="../../static/icon/sharejt.png" mode=""></image>
  15. </view>
  16. <view class="navbar-font">分享</view>
  17. </view>
  18. <view class="xian"></view>
  19. <view class="navbar-item" @click.stop="wzdz()">
  20. <view class="navbar-icon" v-if="info.user_good == 1">
  21. <image src="../../static/icon/zanguo.png" mode=""></image>
  22. </view>
  23. <view class="navbar-icon" v-else>
  24. <image src="../../static/icon/zan.png" mode=""></image>
  25. </view>
  26. <view class="navbar-font">{{ info.goods_count }}</view>
  27. </view>
  28. </view>
  29. <view v-if="shareShow" class="Shraremask" @click="cancel">
  30. <view class="mask-content">
  31. <scroll-view class="view-content" scroll-y>
  32. <view class="share-header">分享到</view>
  33. <view class="share-list">
  34. <view class="share-item">
  35. <button class="wechat-box" open-type="share">
  36. <image class="itemImage" src="../../static/icon/share1.png" mode=""></image>
  37. <text class="itemText">微信好友</text>
  38. </button>
  39. <view class="wechat-box" @click="navTo('/pages/zc/plshare?id=' + id)">
  40. <image class="itemImage" src="../../static/icon/share2.png" mode=""></image>
  41. <text class="itemText">朋友圈</text>
  42. </view>
  43. <view class="wechat-box" @click="copy()">
  44. <image class="itemImage" src="../../static/icon/share3.png" mode=""></image>
  45. <text class="itemText">复制链接</text>
  46. </view>
  47. <view class="wechat-box" @click="shareToFriend()">
  48. <image class="itemImage" src="../../static/icon/share4.png" mode=""></image>
  49. <text class="itemText">生成海报</text>
  50. </view>
  51. </view>
  52. </view>
  53. </scroll-view>
  54. <view class="bottomButtom b-t" @click="cancel">取消</view>
  55. </view>
  56. </view>
  57. <uni-popup ref="popupshare" type="center">
  58. <view class="share-box">
  59. <image :src="shareImage" mode="" class="box-img" @longpress="saveImg()"></image>
  60. </view>
  61. </uni-popup>
  62. </view>
  63. </template>
  64. <script>
  65. import {
  66. reply_detail,
  67. reply_good,
  68. short_link,
  69. reply_poster
  70. } from '@/api/activity.js';
  71. import uniCopy from '@/js_sdk/xb-copy/uni-copy.js';
  72. import {
  73. mapState
  74. } from 'vuex';
  75. export default {
  76. data() {
  77. return {
  78. id: '',
  79. info: {},
  80. shareShow: false,
  81. shareImage: ''
  82. };
  83. },
  84. computed: {
  85. ...mapState('user', ['hasLogin', 'userInfo'])
  86. },
  87. onLoad(option) {
  88. if (option.id) {
  89. this.id = option.id;
  90. }
  91. // #ifdef MP
  92. if (option.scene) {
  93. if (typeof option.scene == 'string') {
  94. // let scene = ('{' + option.scene + "}").replace('qr%26', '').replace(/%3D/g, ':').replace(/%26/g, ',')
  95. // .replace('id', '\"id\"').replace('pid', '\"pid\"');
  96. let scene = ('{' + option.scene + '}')
  97. .replace('qr%26', '')
  98. .replace(/%3D/g, ':')
  99. .replace(/%26/g, ',')
  100. .replace('id', '"id"')
  101. .replace('pid', '"pid"')
  102. .replace(/=/g, ':')
  103. .replace(/&/g, ',');
  104. console.log(scene, 'scene');
  105. let opt = JSON.parse(scene);
  106. console.log(opt);
  107. // 保存拼团订单id
  108. this.id = opt.id;
  109. if (opt.pid) {
  110. // 存储邀请人
  111. // this.spread = opt.pid;
  112. uni.setStorageSync('spread', opt.pid);
  113. }
  114. }
  115. }
  116. // #endif
  117. },
  118. onShow() {
  119. this.loadData();
  120. },
  121. onReachBottom() {},
  122. onReady() {},
  123. // #ifdef MP
  124. onShareAppMessage: function(res) {
  125. console.log(this.share);
  126. if (res.from === 'button') {
  127. // 来自页面内分享按钮
  128. let pages = getCurrentPages();
  129. // 获取当前页面
  130. let page = pages[pages.length - 1];
  131. let path = '/' + page.route + '?';
  132. // 保存传值
  133. for (let i in page.options) {
  134. path += i + '=' + page.options[i] + '&';
  135. }
  136. // 保存邀请人
  137. let data = {
  138. path: path,
  139. imageUrl: this.info.share_images[0],
  140. title: this.info.title
  141. };
  142. console.log('data', data);
  143. return data;
  144. }
  145. },
  146. // #endif
  147. methods: {
  148. loadData() {
  149. reply_detail({}, this.id).then(({
  150. data
  151. }) => {
  152. this.info = data;
  153. });
  154. },
  155. // 文章点赞
  156. wzdz() {
  157. reply_good({}, this.id).then(e => {
  158. if (this.info.user_good == 0) {
  159. this.info.user_good = 1;
  160. this.info.goods_count += 1;
  161. } else {
  162. this.info.user_good = 0;
  163. this.info.goods_count -= 1;
  164. }
  165. });
  166. },
  167. navTo(url) {
  168. uni.navigateTo({
  169. url
  170. });
  171. },
  172. shareLink(item) {
  173. console.log('dainjideniang');
  174. this.shareShow = true;
  175. },
  176. shareToFriend() {
  177. let obj = this;
  178. uni.showLoading({
  179. title: 'Loading...',
  180. mask: true
  181. });
  182. reply_poster({}, this.id)
  183. .then(({
  184. data
  185. }) => {
  186. obj.shareImage = data.url;
  187. console.log(obj.shareImage, '123456');
  188. uni.hideLoading();
  189. this.$refs.popupshare.open();
  190. })
  191. .catch(e => {
  192. uni.hideLoading();
  193. });
  194. },
  195. copy() {
  196. short_link({
  197. url: 'pages/zc/plDetail?id=' + this.id
  198. }).then(({
  199. data
  200. }) => {
  201. console.log(data);
  202. this.comfirm(data.link);
  203. });
  204. },
  205. comfirm(text) {
  206. console.log(text);
  207. const result = uniCopy(text);
  208. if (result === false) {
  209. uni.showToast({
  210. title: '不支持'
  211. });
  212. } else {
  213. uni.showToast({
  214. title: '复制成功',
  215. icon: 'none'
  216. });
  217. }
  218. },
  219. //取消分享
  220. cancel() {
  221. this.shareShow = false;
  222. },
  223. saveImg(w) {
  224. console.log(w);
  225. let obj = this;
  226. uni.downloadFile({
  227. //下载图片
  228. url: obj.shareImage,
  229. success: res => {
  230. console.log(res.tempFilePath);
  231. uni.saveImageToPhotosAlbum({
  232. //将图片保存在手机
  233. filePath: res.tempFilePath, //保存的位置
  234. success: res => {
  235. uni.showToast({
  236. title: '保存成功',
  237. icon: 'none'
  238. });
  239. }
  240. });
  241. }
  242. });
  243. },
  244. // 富文本视频解析
  245. getVideo(data) {
  246. let videoList = [];
  247. let videoReg = /<video.*?(?:>|\/>)/gi; //匹配到字符串中的 video 标签
  248. let srcReg = /src=[\'\"]?([^\'\"]*)[\'\"]?/i; //匹配到字符串中的 video 标签 的路径
  249. let arr = data.match(videoReg) || []; // arr 为包含所有video标签的数组
  250. let articleList = data.split('</video>'); // 把字符串 从视频标签分成数组
  251. arr.forEach((item, index) => {
  252. var src = item.match(srcReg);
  253. videoList.push(src[1]); //所要显示的字符串中 所有的video 标签 的路径
  254. });
  255. let needArticleList = [];
  256. articleList.forEach((item, index) => {
  257. if (item != '' && item != undefined) {
  258. // 常见的标签渲染
  259. needArticleList.push({
  260. type: 'rich-text',
  261. value: item + '</video>'
  262. });
  263. }
  264. let articleListLength = articleList.length; // 插入到原有video 标签位置
  265. if (index < articleListLength && videoList[index] != undefined) {
  266. needArticleList.push({
  267. type: 'video',
  268. value: videoList[index]
  269. });
  270. }
  271. });
  272. return needArticleList;
  273. }
  274. }
  275. };
  276. </script>
  277. <style lang="scss">
  278. page,
  279. .content {
  280. min-height: 100%;
  281. height: auto;
  282. }
  283. .top {
  284. width: 750rpx;
  285. image {
  286. width: 100%;
  287. }
  288. }
  289. .title {
  290. margin-top: 20rpx;
  291. text-align: center;
  292. font-size: 32rpx;
  293. font-family: PingFang SC;
  294. font-weight: 800;
  295. color: #303030;
  296. }
  297. .tip {
  298. margin-top: 20rpx;
  299. padding: 0 10rpx;
  300. font-size: 24rpx;
  301. font-family: PingFang SC;
  302. font-weight: 500;
  303. color: #969696;
  304. }
  305. .main {
  306. margin-top: 60rpx;
  307. image {
  308. width: 750rpx;
  309. }
  310. }
  311. .navbar {
  312. background: #ffffff;
  313. position: fixed;
  314. bottom: 0;
  315. left: 0;
  316. right: 0;
  317. width: 750rpx;
  318. padding: 50rpx 0;
  319. .xian {
  320. width: 2px;
  321. background: #999999;
  322. height: 36rpx;
  323. }
  324. .navbar-item {
  325. width: 50%;
  326. display: flex;
  327. justify-content: center;
  328. align-items: center;
  329. .navbar-icon {
  330. width: 36rpx;
  331. height: 36rpx;
  332. image {
  333. width: 100%;
  334. height: 100%;
  335. }
  336. }
  337. .navbar-font {
  338. margin-left: 17rpx;
  339. font-size: 22rpx;
  340. font-family: PingFang SC;
  341. font-weight: 500;
  342. color: #333333;
  343. }
  344. }
  345. }
  346. .Shraremask {
  347. position: fixed;
  348. left: 0;
  349. top: 0;
  350. right: 0;
  351. bottom: 0;
  352. display: flex;
  353. justify-content: center;
  354. align-items: flex-end;
  355. z-index: 998;
  356. transition: 0.3s;
  357. background-color: rgba(51, 51, 51, 0.6);
  358. .bottomButtom {
  359. position: absolute;
  360. left: 0;
  361. bottom: 0;
  362. display: flex;
  363. justify-content: center;
  364. align-items: center;
  365. width: 100%;
  366. height: 90rpx;
  367. background: #fff;
  368. z-index: 9;
  369. font-size: $font-base + 2rpx;
  370. color: $font-color-dark;
  371. }
  372. }
  373. .mask-content {
  374. margin-bottom: 88rpx;
  375. width: 100%;
  376. height: 380rpx;
  377. transition: 0.3s;
  378. background: #fff;
  379. &.has-bottom {
  380. padding-bottom: 90rpx;
  381. }
  382. .view-content {
  383. height: 100%;
  384. }
  385. }
  386. .share-header {
  387. height: 110rpx;
  388. font-size: $font-base + 2rpx;
  389. color: font-color-dark;
  390. display: flex;
  391. align-items: center;
  392. justify-content: center;
  393. padding-top: 10rpx;
  394. &:before,
  395. &:after {
  396. content: '';
  397. width: 240rpx;
  398. height: 0;
  399. border-top: 1px solid $border-color-base;
  400. transform: scaleY(0.5);
  401. margin-right: 30rpx;
  402. }
  403. &:after {
  404. margin-left: 30rpx;
  405. margin-right: 0;
  406. }
  407. }
  408. .share-list {
  409. display: flex;
  410. width: 80%;
  411. margin: 0rpx auto;
  412. }
  413. .share-item {
  414. min-width: 33.33%;
  415. display: flex;
  416. justify-content: center;
  417. align-items: center;
  418. height: 180rpx;
  419. width: 100%;
  420. .wechat-box {
  421. width: 50%;
  422. height: 100%;
  423. background: #ffffff;
  424. border: 0;
  425. display: flex;
  426. align-items: center;
  427. flex-direction: column;
  428. &::after {
  429. border: 0;
  430. }
  431. .itemImage {
  432. width: 80rpx;
  433. height: 80rpx;
  434. margin-bottom: 16rpx;
  435. }
  436. .itemText {
  437. font-size: $font-base;
  438. color: $font-color-base;
  439. line-height: 2;
  440. }
  441. }
  442. }
  443. .share-box {
  444. width: 600rpx;
  445. height: 1000rpx;
  446. background: red;
  447. .box-img {
  448. width: 600rpx;
  449. height: 1000rpx;
  450. }
  451. }
  452. </style>