app-goods-quick-share.vue 14 KB

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