wzDetail.vue 11 KB

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