index.vue 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. <template>
  2. <app-layout>
  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 v-if="is_video" class="text">视频已保存到相册</cover-view>
  12. <cover-view v-else class="text">图片已保存到相册</cover-view>
  13. </cover-view>
  14. </cover-view>
  15. </cover-view>
  16. <view>
  17. <text id="opacity-hide" class="opacity-hide">
  18. 第一行
  19. 第二行
  20. 第三行
  21. 第四行
  22. 第五行
  23. </text>
  24. <view class="fixed">
  25. <view class="share-head-margin">
  26. <view class="share-head dir-left-nowrap">
  27. <view class="box-grow-1 main-center cross-center"
  28. :class="[`goods`, tab===`goods`? `${tab}-active`: '']"
  29. @click="tabChange(`goods`)">商品
  30. </view>
  31. <view class="box-grow-1 main-center cross-center"
  32. :class="[`dynamic`, tab===`dynamic`? `${tab}-active`: '']"
  33. @click="tabChange(`dynamic`)">动态
  34. </view>
  35. </view>
  36. </view>
  37. <view class="share-center dir-left-nowrap" v-if="tab === `goods`">
  38. <view class="dir-left-nowrap cross-center value">
  39. <view @click="sortChange(sort===1?2:1)" :class="[sort===1 || sort===2 ? `active`: ``]">最新商品
  40. </view>
  41. <icon v-if="sort === 1" class="sort-plus"></icon>
  42. <icon v-else-if="sort === 2" class="sort-less"></icon>
  43. <icon v-else class="sort-default"></icon>
  44. </view>
  45. <view class="dir-left-nowrap cross-center value">
  46. <view @click="sortChange(sort===3?4:3)" :class="[sort===3 || sort===4 ? `active`: ``]">最新素材
  47. </view>
  48. <icon v-if="sort === 3" class="sort-plus"></icon>
  49. <icon v-else-if="sort === 4" class="sort-less"></icon>
  50. <icon v-else class="sort-default"></icon>
  51. </view>
  52. <view class="dir-left-nowrap cross-center value">
  53. <view @click="sortChange(sort===5?6:5)" :class="[sort===5 || sort===6 ? `active`: ``]">销量
  54. </view>
  55. <icon v-if="sort === 5" class="sort-plus"></icon>
  56. <icon v-else-if="sort === 6" class="sort-less"></icon>
  57. <icon v-else class="sort-default"></icon>
  58. </view>
  59. </view>
  60. </view>
  61. <view :class="tab + `-margin`">
  62. <view class="share-goods" v-for="(item,index) in list" :key="index">
  63. <view v-if="item.is_top" class="goods-top dir-left-nowrap">
  64. <icon class="top box-grow-0"></icon>
  65. <view>置顶</view>
  66. </view>
  67. <view class="goods-head dir-left-nowrap">
  68. <view class="dir-top-nowrap">
  69. <view class="t-omit goods-name">{{item.mall_name}}</view>
  70. <view class="goods-time">{{item.format_time}}</view>
  71. </view>
  72. <view v-if="tab === `goods`" @click="navDetail(item)"
  73. class="goods-detail main-center box-grow-0 cross-center">商品详情
  74. </view>
  75. </view>
  76. <view class="goods-text">
  77. <text class="opacity-hide" space="nbsp" :id="`all_hide_text_` + index"
  78. v-text="item.share_text"></text>
  79. <text class="share-text" :class="{'limit': allTextList.indexOf(index) === -1}"
  80. space="nbsp" v-text="item.share_text"></text>
  81. <view v-if="item.is_all_btn" class="all" @click="showText(index)">
  82. <block v-if="allTextList.indexOf(index) === -1">全文</block>
  83. <block v-else>收起</block>
  84. </view>
  85. </view>
  86. <view v-if="item.goods_id ===0 && item.material_video_url" class="goods-video">
  87. <video :src="item.material_video_url" show-mute-btn
  88. :poster="item.material_cover_url"></video>
  89. </view>
  90. <view v-else class="goods-image dir-left-wrap">
  91. <view v-for="(item1,index1) in item.share_pic" :key="index1">
  92. <image @click="previewImage(item.share_pic, index1)" :src="item1.pic_url" lazy-load></image>
  93. </view>
  94. </view>
  95. <view class="goods-set cross-center dir-left-nowrap">
  96. <view class="box-grow-1 main-center">
  97. <!-- #ifdef MP-BAIDU || MP-ALIPAY -->
  98. <view class="box-grow-1 main-center" @click="copyText(item)">复制文本</view>
  99. <!-- #endif -->
  100. <!-- #ifndef MP-BAIDU || MP-ALIPAY -->
  101. <view class="box-grow-1 main-center" @click="copyText(item)">复制文本</view>
  102. <!-- #endif -->
  103. <!-- #ifdef MP-WEIXIN -->
  104. <view class="box-grow-1 main-center" @click="saveImage(item)"
  105. v-if="item.goods_id ===0 && item.material_video_url">下载视频
  106. </view>
  107. <view class="box-grow-1 main-center" v-else @click="saveImage(item)">保存图片</view>
  108. <!-- #endif -->
  109. <!-- #ifndef MP-WEIXIN -->
  110. <view class="box-grow-1 main-center" v-if="item.goods_id !==0 || !item.material_video_url" @click="saveImage(item)">保存图片</view>
  111. <!-- #endif -->
  112. <!-- #ifndef MP-BAIDU -->
  113. <view class="box-grow-1 main-center" @click="setPoster(item)">生成海报</view>
  114. <!-- #endif -->
  115. </view>
  116. <view class="line"></view>
  117. <view class="box-grow-0">分享到</view>
  118. <image @click="batchCopy(item)" class="friend box-grow-0"></image>
  119. <view style="width: 50rpx">
  120. <app-jump-button open_type="share">
  121. <image @click="shareCard(item)" class="card"></image>
  122. </app-jump-button>
  123. </view>
  124. </view>
  125. </view>
  126. </view>
  127. <view class="box" :class="{'app-show-hidden': posterShow}">
  128. <app-goods-preview-poster
  129. v-model="posterShow" @close="posterShow = false" :url="posterUrl"
  130. ></app-goods-preview-poster>
  131. </view>
  132. </view>
  133. </app-layout>
  134. </template>
  135. <script>
  136. import appGoodsPreviewPoster from '../../../components/page-component/goods/app-goods-preview-poster';
  137. export default {
  138. name: "index",
  139. components: {
  140. appGoodsPreviewPoster,
  141. },
  142. data() {
  143. return {
  144. friendModel: false,
  145. is_video: false,
  146. tab: 'goods',
  147. sort: 1,
  148. page: 1,
  149. args: false,
  150. load: false,
  151. list: [],
  152. allTextList: [],
  153. shareData: {},
  154. posterShow: false,
  155. posterUrl: '',
  156. }
  157. },
  158. onReachBottom: function () {
  159. const self = this;
  160. if (self.args || self.load)
  161. return;
  162. self.load = true;
  163. let page = self.page + 1;
  164. self.$request({
  165. url: self.$api.quick_share.goods,
  166. data: {
  167. type: self.tab,
  168. sort: self.sort,
  169. page,
  170. }
  171. }).then(info => {
  172. if (info.code === 0) {
  173. //todo
  174. info.data.list.forEach(v => {
  175. v.is_all_btn = false;
  176. });
  177. [self.page, self.args, self.list] = [page, info.data.list.length === 0, self.list.concat(info.data.list)];
  178. self.formatList();
  179. }
  180. self.load = false;
  181. });
  182. },
  183. onLoad: function (options) {
  184. this.loadData();
  185. },
  186. onShareAppMessage(params) {
  187. if (params.from === 'button') {
  188. return this.$shareAppMessage(this.shareData);
  189. }
  190. },
  191. methods: {
  192. navDetail(column) {
  193. uni.navigateTo({url: `/pages/goods/goods?id=` + column.goods_id});
  194. },
  195. previewImage(list, index) {
  196. const urls = list.map(item => {
  197. return item.pic_url;
  198. });
  199. uni.previewImage({
  200. urls: urls,
  201. current: index,
  202. });
  203. },
  204. showText(index) {
  205. let key = this.allTextList.indexOf(index);
  206. if (key === -1) {
  207. this.allTextList.splice(-1, 0, index);
  208. } else {
  209. this.allTextList.splice(key, 1);
  210. }
  211. },
  212. sortChange(sort) {
  213. [this.list, this.allTextList] = [[], []];
  214. [this.page, this.args, this.sort] = [1, false, sort];
  215. this.loadData();
  216. },
  217. tabChange(tab) {
  218. [this.list, this.allTextList] = [[], []];
  219. [this.page, this.args, this.tab] = [1, false, tab];
  220. this.loadData();
  221. },
  222. loadData() {
  223. const self = this;
  224. self.$showLoading({text: '加载中'});
  225. self.$request({
  226. url: self.$api.quick_share.goods,
  227. data: {
  228. page: 1,
  229. type: self.tab,
  230. sort: self.sort,
  231. }
  232. }).then(info => {
  233. self.$hideLoading();
  234. if (info.code === 0) {
  235. info.data.list.forEach(v => {
  236. v.is_all_btn = false;
  237. })
  238. self.list = info.data.list;
  239. self.formatList();
  240. }
  241. }).catch(info => {
  242. self.$hideLoading();
  243. })
  244. },
  245. formatList() {
  246. const self = this;
  247. setTimeout(() => {
  248. let list = JSON.parse(JSON.stringify(self.list));
  249. const query = uni.createSelectorQuery().in(this);
  250. query.select('#opacity-hide').boundingClientRect(item => {
  251. list.forEach((v, k) => {
  252. let key = uni.createSelectorQuery().in(self);
  253. key.select(`#all_hide_text_` + k).boundingClientRect(item1 => {
  254. v.is_all_btn = item1.height + 1 >= item.height;
  255. }).exec();
  256. });
  257. self.list = list;
  258. }).exec();
  259. })
  260. },
  261. saveImage(column, customize_success = false) {
  262. let self = this;
  263. self.is_video = column.goods_id === 0 && column.material_video_url;
  264. const customize_a = function () {
  265. uni.showToast({title: '保存成功'});
  266. };
  267. const customize_b = function () {
  268. self.friendModel = true;
  269. setTimeout(() => {
  270. self.friendModel = false;
  271. }, 1500)
  272. };
  273. if (self.is_video) {
  274. const share_video = column.material_video_url;
  275. self.$utils.batchSave(share_video, 'video').then(result => {
  276. customize_success ? customize_b() : customize_a();
  277. });
  278. } else {
  279. uni.showLoading({title: `图片保存中`});
  280. self.$request({
  281. url: self.$api.quick_share.poster_list,
  282. data: {
  283. id: column.id,
  284. }
  285. }).then(info => {
  286. if (info.code === 0) {
  287. let urls = column.share_pic.map(item => {
  288. return item.pic_url;
  289. })
  290. urls.splice(-1, 1, info.data.pic_url);
  291. self.$utils.batchSave(urls, 'image').then(result => {
  292. customize_success ? customize_b() : customize_a();
  293. });
  294. }
  295. }).catch(e => {
  296. uni.hideLoading();
  297. })
  298. }
  299. },
  300. setPoster(column) {
  301. if(this.tab === 'dynamic') {
  302. this.posterUrl = this.$api.quick_share.poster + `&id=` + column.id;
  303. this.posterShow = true;
  304. } else {
  305. const posterConfig = this.$api.quick_share.poster_config + '&id=' + column.id;
  306. const posterGenerate = this.$api.quick_share.poster_generate + '&id=' + column.id;
  307. uni.navigateTo({
  308. url: `/pages/poster/goods?poster_config=${escape(posterConfig)}&poster_generate=${escape(posterGenerate)}`
  309. });
  310. }
  311. },
  312. copyText(column) {
  313. uni.setClipboardData({
  314. data: column.share_text,
  315. success() {
  316. //#ifndef MP-WEIXIN
  317. uni.showToast({title: '复制成功'});
  318. // #endif
  319. }
  320. });
  321. },
  322. batchCopy(column) {
  323. this.copyText(column);
  324. this.saveImage(column, true);
  325. },
  326. shareCard(column) {
  327. const title = column.app_share_title ? column.app_share_title : column.share_text;
  328. let imageUrl = '';
  329. if (column.share_pic[0].pic_url) {
  330. imageUrl = column.share_pic[0].pic_url;
  331. }
  332. if (column.app_share_pic) {
  333. imageUrl = column.app_share_pic;
  334. }
  335. this.shareData = {
  336. title: title,
  337. imageUrl: imageUrl,
  338. path: column.goods_id === 0 ? '/pages/index/index' : '/pages/goods/goods',
  339. params: column.goods_id === 0 ? {} : {id: column.goods_id},
  340. }
  341. }
  342. }
  343. }
  344. </script>
  345. <style scoped lang="scss">
  346. .friend-box {
  347. position: fixed;
  348. top: #{563rpx};
  349. width: 100%;
  350. left: 0;
  351. .info > cover-view:first-child {
  352. margin-bottom: #{30rpx};
  353. }
  354. .info {
  355. width: #{413rpx};
  356. height: #{209rpx};
  357. color: #ffffff;
  358. font-size: #{28rpx};
  359. border-radius: #{16rpx};
  360. margin: 0 auto;
  361. background: rgba(0, 0, 0, 0.8);
  362. cover-view {
  363. background: rgba(0, 0, 0, 0);
  364. }
  365. .text {
  366. padding-left: #{13rpx};
  367. }
  368. .icon {
  369. display: block;
  370. height: #{28rpx};
  371. width: #{28rpx};
  372. }
  373. }
  374. }
  375. .opacity-hide {
  376. position: fixed;
  377. top: 0;
  378. z-index: -10;
  379. opacity: 0;
  380. word-break: break-all;
  381. text-overflow: ellipsis;
  382. display: -webkit-box;
  383. -webkit-box-orient: vertical;
  384. overflow: hidden;
  385. white-space: normal !important;
  386. -webkit-line-clamp: 5;
  387. }
  388. .fixed {
  389. position: fixed;
  390. top: var(--window-top);
  391. width: 100%;
  392. z-index: 10;
  393. .share-head-margin {
  394. padding: #{23rpx} 0;
  395. background: #ffffff;
  396. .share-head {
  397. text-align: center;
  398. width: #{323rpx};
  399. margin: 0 auto;
  400. font-size: #{28rpx};
  401. height: #{56rpx};
  402. color: #666666;
  403. .goods {
  404. border-top-left-radius: #{30rpx};
  405. border-bottom-left-radius: #{30rpx};
  406. border-top: 1px solid #446dfd;
  407. border-bottom: 1px solid #446dfd;
  408. border-left: 1px solid #446dfd;
  409. }
  410. .dynamic {
  411. border-top-right-radius: #{30rpx};
  412. border-bottom-right-radius: #{30rpx};
  413. border-top: 1px solid #446dfd;
  414. border-bottom: 1px solid #446dfd;
  415. border-right: 1px solid #446dfd;
  416. }
  417. .dynamic-active, .goods-active {
  418. background: #446dfd;
  419. color: #ffffff;
  420. }
  421. }
  422. }
  423. .share-center {
  424. padding: 0 #{60rpx};
  425. height: #{96rpx};
  426. font-size: #{28rpx};
  427. background: #FFFFFF;
  428. justify-content: space-between;
  429. .value > view {
  430. margin-right: #{9rpx};
  431. }
  432. .active {
  433. color: #446dfd;
  434. }
  435. icon {
  436. background-repeat: no-repeat;
  437. background-size: 100% 100%;
  438. width: #{16upx};
  439. height: #{26upx};
  440. }
  441. .sort-default {
  442. background-image: url("../image/sort-blue-default.png");
  443. }
  444. .sort-less {
  445. background-image: url("../image/sort-blue-less.png");
  446. }
  447. .sort-plus {
  448. background-image: url("../image/sort-blue-plus.png");
  449. }
  450. }
  451. }
  452. .goods-margin {
  453. margin-top: #{196rpx};
  454. }
  455. .dynamic-margin {
  456. margin-top: #{100rpx};
  457. }
  458. .box {
  459. position: fixed;
  460. z-index: 1700;
  461. left: 0;
  462. bottom: 0;
  463. width: #{750rpx};
  464. opacity: 0;
  465. visibility: hidden;
  466. height: 100%;
  467. background-color: rgba(153, 153, 153, 0.5);
  468. }
  469. .app-show-hidden {
  470. opacity: 1;
  471. visibility: visible;
  472. }
  473. .share-goods {
  474. background: #FFFFFF;
  475. margin-bottom: #{15rpx};
  476. .goods-top {
  477. background: #FFFFFF;
  478. padding: #{14rpx} #{24rpx};
  479. font-size: #{26rpx};
  480. color: #ff4544;
  481. .top {
  482. background-repeat: no-repeat;
  483. background-size: 100% 100%;
  484. background-image: url("../image/goods-top.png");
  485. height: #{32rpx};
  486. width: #{28rpx};
  487. display: block;
  488. margin-right: #{12rpx};
  489. }
  490. }
  491. .goods-head {
  492. padding: #{40rpx} #{24rpx} 0 #{24rpx};
  493. .goods-name {
  494. color: #212121;
  495. font-size: #{34rpx};
  496. max-width: #{540rpx};
  497. line-height: 1;
  498. }
  499. .goods-time {
  500. margin-top: #{20rpx};
  501. color: #a0a0a0;
  502. font-size: #{24rpx};
  503. line-height: 1;
  504. }
  505. .goods-detail {
  506. color: #446dfd;
  507. font-size: #{26rpx};
  508. border: 1px solid #446dfd;
  509. border-radius: #{6rpx};
  510. height: #{50rpx};
  511. width: #{135rpx};
  512. margin-left: auto;
  513. }
  514. }
  515. .goods-text {
  516. padding: 0 #{24rpx};
  517. font-size: #{32rpx};
  518. color: #212121;
  519. margin-top: #{40rpx};
  520. .share-text {
  521. word-break: break-all;
  522. text-overflow: ellipsis;
  523. display: -webkit-box;
  524. -webkit-box-orient: vertical;
  525. overflow: hidden;
  526. white-space: normal !important;
  527. }
  528. .share-text.limit {
  529. -webkit-line-clamp: 4;
  530. }
  531. .all {
  532. padding-top: #{10rpx};
  533. color: #5b6a91;
  534. }
  535. }
  536. .goods-video {
  537. padding-top: #{15rpx};
  538. padding-bottom: #{30rpx};
  539. video {
  540. width: 100%;
  541. height: #{422rpx};
  542. }
  543. }
  544. .goods-image {
  545. padding: #{10rpx} #{18rpx} #{30rpx} #{18rpx};
  546. view {
  547. height: #{226rpx};
  548. width: #{226rpx};
  549. margin: #{6rpx};
  550. }
  551. image {
  552. height: 100%;
  553. width: 100%;
  554. display: block;
  555. }
  556. }
  557. .goods-set {
  558. color: #a0a0a0;
  559. font-size: #{28rpx};
  560. border-top: #{1rpx} solid #e2e2e2;
  561. padding: #{15rpx} #{24rpx} #{15rpx} 0;
  562. .margin {
  563. margin: 0 auto;
  564. }
  565. .line {
  566. height: #{60rpx};
  567. width: #{1px};
  568. margin-right: #{26rpx};
  569. background: #dcdfe6;
  570. }
  571. image {
  572. background-repeat: no-repeat;
  573. background-size: 100% 100%;
  574. height: #{50rpx};
  575. width: #{50rpx};
  576. }
  577. .friend {
  578. margin-right: #{15rpx};
  579. margin-left: #{20rpx};
  580. background-image: url("../image/friend.png");
  581. }
  582. .card {
  583. background-image: url("../image/wechat.png");
  584. }
  585. }
  586. }
  587. </style>