wzDetail.vue 9.9 KB

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