app-goods-quick-share.vue 15 KB

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