bd-quick-share.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. <template>
  2. <view class="app-goods-quick-share">
  3. <cover-view v-if="friendModel" class="friend-box">
  4. <cover-view class="info main-center cross-center dir-top-nowrap">
  5. <cover-view class="dir-left-nowrap cross-center">
  6. <cover-image src="/static/image/icon/friend-v.png" class="icon"></cover-image>
  7. <cover-view class="text">文本已复制到剪贴板</cover-view>
  8. </cover-view>
  9. <cover-view class="dir-left-nowrap cross-center" style="margin-top: 30rpx">
  10. <cover-image src="/static/image/icon/friend-v.png" class="icon"></cover-image>
  11. <cover-view class="text">图片已保存到相册</cover-view>
  12. </cover-view>
  13. </cover-view>
  14. </cover-view>
  15. <text id="opacity-hide" class="opacity-hide">
  16. 第一行
  17. 第二行
  18. 第三行
  19. 第四行
  20. 第五行
  21. </text>
  22. <view v-if="value" class="box">
  23. <view v-if="posterShow">
  24. <app-goods-preview-poster
  25. v-model="posterShow" @close="close" :url="posterUrl"
  26. ></app-goods-preview-poster>
  27. </view>
  28. <view v-else class="quick-center">
  29. <view class="head">
  30. <view class="t-omit name">{{extraQuickShare.mall_name}}</view>
  31. <view class="time">{{extraQuickShare.format_time}}</view>
  32. <view class="close" @click.stop="close">
  33. <icon></icon>
  34. </view>
  35. </view>
  36. <scroll-view scroll-y class="scrollbar">
  37. <view class="goods-text">
  38. <text class="opacity-hide" space="nbsp" id="all_hide_text_0"
  39. v-text="extraQuickShare.share_text"></text>
  40. <text class="share-text"
  41. :class="{'limit': is_limit}" space="nbsp"
  42. v-text="extraQuickShare.share_text"></text>
  43. <view v-if="is_all_btn" class="all" @click.stop="showText">
  44. <block v-if="is_limit">全文</block>
  45. <block v-else>收起</block>
  46. </view>
  47. </view>
  48. <view class="goods-image dir-left-wrap">
  49. <view v-for="(item,index) in extraQuickShare.share_pic" :key="index">
  50. <image @click.stop="previewImage(index)" :src="item.pic_url" lazy-load></image>
  51. </view>
  52. </view>
  53. </scroll-view>
  54. <view class="goods-set cross-center dir-left-nowrap">
  55. <!-- #ifdef MP-BAIDU -->
  56. <view class="box-grow-0" style="margin-left: auto" @click="copyText">复制文本</view>
  57. <!-- #endif -->
  58. <!-- #ifndef MP-BAIDU -->
  59. <view class="box-grow-0" @click="copyText">复制文本</view>
  60. <!-- #endif -->
  61. <view class="box-grow-0 margin" @click="saveImage(false)">保存图片</view>
  62. <!-- #ifndef MP-BAIDU -->
  63. <view class="box-grow-0" @click="open">生成海报</view>
  64. <!-- #endif -->
  65. <view class="line"></view>
  66. <view class="box-grow-0">分享到</view>
  67. <image @click="batchCopy" class="friend box-grow-0"></image>
  68. <view style="width: 50rpx">
  69. <app-jump-button open_type="share">
  70. <image @click="shareCard" class="card"></image>
  71. </app-jump-button>
  72. </view>
  73. </view>
  74. </view>
  75. </view>
  76. </view>
  77. </template>
  78. <script>
  79. import appGoodsPreviewPoster from '../goods/app-goods-preview-poster.vue';
  80. export default {
  81. name: 'bd-quick-share',
  82. components: {
  83. appGoodsPreviewPoster,
  84. },
  85. props: {
  86. value: {
  87. type: Boolean,
  88. default() {
  89. return false;
  90. }
  91. },
  92. goodsId: Number,
  93. extraQuickShare: Object,
  94. appSharePic: String,
  95. appShareTitle: String
  96. },
  97. data() {
  98. return {
  99. friendModel: false,
  100. posterUrl: '',
  101. is_all_btn: false,
  102. is_limit: true,
  103. shareData: null,
  104. posterShow: false,
  105. }
  106. },
  107. watch: {
  108. value(newInfo, oldInfo) {
  109. if (newInfo) {
  110. let self = this;
  111. const query = uni.createSelectorQuery().in(self);
  112. query.select('#opacity-hide').boundingClientRect(item => {
  113. const key = uni.createSelectorQuery().in(self);
  114. key.select('#all_hide_text_0').boundingClientRect(item1 => {
  115. self.is_all_btn = item1.height + 1 >= item.height;
  116. }).exec();
  117. }).exec();
  118. }
  119. }
  120. },
  121. methods: {
  122. showText() {
  123. this.is_limit = !this.is_limit;
  124. },
  125. close() {
  126. this.$emit('input', false);
  127. this.posterShow = false;
  128. },
  129. open() {
  130. const posterConfig = this.$api.quick_share.poster_config + '&goods_id=' + this.goodsId;
  131. const posterGenerate = this.$api.quick_share.poster_generate + '&goods_id=' + this.goodsId;
  132. uni.navigateTo({
  133. url: `/pages/poster/goods?poster_config=${escape(posterConfig)}&poster_generate=${escape(posterGenerate)}`
  134. });
  135. // this.posterShow = true;
  136. },
  137. batchCopy() {
  138. this.copyText();
  139. this.saveImage(true);
  140. },
  141. copyText() {
  142. uni.setClipboardData({
  143. data: this.extraQuickShare.share_text,
  144. success() {
  145. //#ifndef MP-WEIXIN
  146. uni.showToast({title: '复制成功'});
  147. // #endif
  148. },
  149. });
  150. },
  151. saveImage(customize_success = false) {
  152. let self = this;
  153. if (!self.extraQuickShare.share_pic) {
  154. return '';
  155. }
  156. uni.showLoading({title: `图片保存中`});
  157. self.$request({
  158. url: self.$api.quick_share.poster_list,
  159. data: {
  160. goods_id: self.goodsId,
  161. }
  162. }).then(info => {
  163. if (info.code === 0) {
  164. let urls = self.extraQuickShare.share_pic.map(item => {
  165. return item.pic_url;
  166. });
  167. urls.splice(-1, 1, info.data.pic_url);
  168. self.$utils.batchSave(urls, 'image').then(result => {
  169. const customize_a = function () {
  170. uni.showToast({title: '保存成功'});
  171. };
  172. const customize_b = function () {
  173. self.friendModel = true;
  174. setTimeout(() => {
  175. self.friendModel = false;
  176. }, 1500)
  177. };
  178. customize_success ? customize_b() : customize_a();
  179. });
  180. }
  181. }).catch(e => {
  182. uni.hideLoading();
  183. });
  184. },
  185. shareCard() {
  186. const title = this.appShareTitle ? this.appShareTitle : this.extraQuickShare.share_text;
  187. let imageUrl = '';
  188. if (this.extraQuickShare.share_pic[0].pic_url) {
  189. imageUrl = this.extraQuickShare.share_pic[0].pic_url;
  190. }
  191. if (this.appSharePic) {
  192. imageUrl = this.appSharePic;
  193. }
  194. this.$emit('quickShare', {
  195. title: title,
  196. imageUrl: imageUrl,
  197. path: this.goodsId === 0 ? '/pages/index/index' : '/pages/goods/goods',
  198. params: this.goodsId === 0 ? {} : {id: this.goodsId},
  199. });
  200. },
  201. previewImage(index) {
  202. if (!this.extraQuickShare.share_pic) {
  203. return '';
  204. }
  205. const urls = this.extraQuickShare.share_pic.map(item => {
  206. return item.pic_url;
  207. });
  208. uni.previewImage({
  209. urls: urls,
  210. current: index
  211. });
  212. },
  213. }
  214. }
  215. </script>
  216. <style scoped lang="scss">
  217. .friend-box {
  218. position: fixed;
  219. top: #{563rpx};
  220. width: 100%;
  221. left: 0;
  222. z-index: 1701;
  223. .info > cover-view:first-child {
  224. margin-bottom: #{30rpx};
  225. }
  226. .info {
  227. width: #{413rpx};
  228. height: #{209rpx};
  229. color: #ffffff;
  230. font-size: #{28rpx};
  231. border-radius: #{16rpx};
  232. margin: 0 auto;
  233. background: rgba(0, 0, 0, 0.8);
  234. cover-view {
  235. background: rgba(0, 0, 0, 0);
  236. }
  237. .text {
  238. padding-left: #{13rpx};
  239. }
  240. .icon {
  241. height: #{28rpx};
  242. width: #{28rpx};
  243. }
  244. }
  245. }
  246. .opacity-hide {
  247. position: fixed;
  248. top: 0;
  249. z-index: -10;
  250. opacity: 0;
  251. word-break: break-all;
  252. text-overflow: ellipsis;
  253. display: -webkit-box;
  254. -webkit-box-orient: vertical;
  255. overflow: hidden;
  256. white-space: normal !important;
  257. -webkit-line-clamp: 5;
  258. }
  259. .share-text {
  260. word-break: break-all;
  261. text-overflow: ellipsis;
  262. display: -webkit-box;
  263. -webkit-box-orient: vertical;
  264. overflow: hidden;
  265. white-space: normal !important;
  266. }
  267. .share-text.limit {
  268. -webkit-line-clamp: 2;
  269. }
  270. .app-goods-quick-share {
  271. .box {
  272. position: fixed;
  273. z-index: 1700;
  274. left: 0;
  275. bottom: 0;
  276. width: #{750rpx};
  277. opacity: 1;
  278. visibility: visible;
  279. height: 100%;
  280. background-color: rgba(153, 153, 153, 0.5);
  281. }
  282. .quick-center {
  283. background: #ffffff;
  284. border-top-left-radius: #{16rpx};
  285. border-top-right-radius: #{16rpx};
  286. position: absolute;
  287. width: 100%;
  288. height: auto;
  289. left: 0;
  290. bottom: 0;
  291. z-index: 111;
  292. }
  293. }
  294. .app-center {
  295. width: calc(100% - #{80rpx});
  296. padding-top: #{100rpx};
  297. padding-bottom: #{77rpx};
  298. border-radius: #{8rpx};
  299. background-color: white;
  300. position: absolute;
  301. top: 50%;
  302. left: 50%;
  303. transform: translate(-50%, -50%);
  304. .app-close {
  305. width: #{30rpx};
  306. height: #{30rpx};
  307. background-size: cover;
  308. background-repeat: no-repeat;
  309. background-image: url("../../../static/image/icon/close.png");
  310. position: absolute;
  311. top: #{28rpx};
  312. right: #{24rpx};
  313. }
  314. .app-image-iframe {
  315. width: #{440rpx};
  316. height: #{783rpx};
  317. position: relative;
  318. box-shadow: #{2rpx} #{2rpx} #{10rpx} #d9d9d9;
  319. .text {
  320. text-align: center;
  321. color: #888;
  322. }
  323. }
  324. .app-button {
  325. width: #{500rpx};
  326. height: #{80rpx};
  327. margin-top: #{38rpx};
  328. margin-bottom: #{24rpx};
  329. }
  330. .app-text {
  331. font-size: #{24rpx};
  332. color: #999999;
  333. }
  334. }
  335. .head {
  336. padding: 0 #{24rpx};
  337. .name {
  338. padding-top: #{30rpx};
  339. color: #212121;
  340. font-size: #{34rpx};
  341. max-width: 80%;
  342. }
  343. .time {
  344. font-size: #{24rpx};
  345. color: #a0a0a0;
  346. padding-top: #{10rpx};
  347. padding-bottom: #{20rpx};
  348. }
  349. .close {
  350. position: absolute;
  351. top: #{12rpx};
  352. right: #{12rpx};
  353. padding: #{12rpx};
  354. z-index: 111;
  355. icon {
  356. background-image: url("../../../plugins/quick_share/image/close.png");
  357. background-repeat: no-repeat;
  358. background-size: 100% 100%;
  359. height: #{30rpx};
  360. width: #{30rpx};
  361. }
  362. }
  363. }
  364. .scrollbar {
  365. max-height: #{876rpx};
  366. }
  367. .goods-text {
  368. padding: 0 #{24rpx};
  369. font-size: #{32rpx};
  370. color: #212121;
  371. .share-text {
  372. word-break: break-all;
  373. text-overflow: ellipsis;
  374. display: -webkit-box;
  375. -webkit-box-orient: vertical;
  376. overflow: hidden;
  377. white-space: normal !important;
  378. }
  379. .share-text.limit {
  380. -webkit-line-clamp: 4;
  381. }
  382. .all {
  383. padding-top: #{10rpx};
  384. color: #5b6a91;
  385. }
  386. }
  387. .goods-image {
  388. padding: #{10rpx} #{24rpx - 8rpx} #{30rpx} #{24rpx - 8rpx};
  389. view {
  390. height: #{227rpx};
  391. width: #{227rpx};
  392. margin: #{6rpx};
  393. }
  394. image {
  395. height: 100%;
  396. width: 100%;
  397. display: block;
  398. }
  399. }
  400. .goods-set {
  401. color: #a0a0a0;
  402. font-size: #{28rpx};
  403. border-top: #{1rpx} solid #e2e2e2;
  404. padding: #{20rpx} #{24rpx} #{53rpx};
  405. .margin {
  406. margin: 0 auto;
  407. }
  408. .line {
  409. height: #{50rpx};
  410. width: #{1px};
  411. margin: 0 #{26rpx};
  412. background: #dcdfe6;
  413. }
  414. image {
  415. background-repeat: no-repeat;
  416. background-size: 100% 100%;
  417. height: #{50rpx};
  418. width: #{50rpx};
  419. }
  420. .friend {
  421. margin-right: #{15rpx};
  422. margin-left: #{20rpx};
  423. background-image: url("../../../plugins/quick_share/image/friend.png");
  424. }
  425. .card {
  426. background-image: url("../../../plugins/quick_share/image/wechat.png");
  427. }
  428. }
  429. </style>