index.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. <template>
  2. <view>
  3. <tui-popup show mode="fade" style="background-color: rgba(0,0,0,0.4);">
  4. <view class="warp">
  5. <view class="rect" @tap.stop>
  6. <!-- 关闭按钮 -->
  7. <view class="guanbiView">
  8. <!-- #ifdef MP-WEIXIN -->
  9. <tui-icon
  10. name="close" :size="30" color="#ffffff" margin="0 0 0 -23upx"
  11. style="position: absolute;top: -80rpx;left: 50%;" @click="showcos"
  12. ></tui-icon>
  13. <!-- #endif -->
  14. <!-- #ifdef H5 || APP-PLUS -->
  15. <tui-icon
  16. name="close" :size="30" color="#ffffff" margin="0 0 0 -23upx"
  17. style="position: absolute;top: -80rpx;left: 50%;" @click="showcos"
  18. ></tui-icon>
  19. <!-- #endif -->
  20. </view>
  21. <!-- 内容 -->
  22. <view class="imgBox">
  23. <view
  24. v-if="shareType == 1" class="boxInner imgBoxShop"
  25. :style="{ 'backgroundImage': 'url(' + erweima + ')' }"
  26. ></view>
  27. <view v-else class="boxInner imgBoxProduct" :style="{ 'backgroundImage': 'url(' + erweima + ')' }">
  28. </view>
  29. </view>
  30. <!-- 分享 -->
  31. </view>
  32. </view>
  33. <view class="fenx" :style="{ 'height': (isIphone === true ? 140 : 130) + 'rpx' }">
  34. <view class="shareBox width100" hover-class="btn-click" @click="WXfenx">
  35. <view style="flex: 1;text-align: center;display: flex;align-items: center;">
  36. <view style="margin-left: 120rpx;">
  37. <tui-icon name="pic-fill" :size="32" color="#7dc932"></tui-icon>
  38. </view>
  39. <view style="margin-left: 10rpx;font-size: 28rpx;color: #333333">保存到本地</view>
  40. </view>
  41. </view>
  42. <view class="linkBtnBox" hover-class="btn-click" @click="FZlianj">
  43. <view style="flex: 1;text-align: center;display: flex;align-items: center;">
  44. <view
  45. class="linkBox"
  46. style="width: fit-content;height: fit-content;padding: 14upx;background-color: #f3b44b;border-radius: 50%;line-height: 1;"
  47. >
  48. <tui-icon name="link" :size="18" color="#ffffff"></tui-icon>
  49. </view>
  50. <view style="margin-left: 10rpx;">
  51. 复制链接
  52. </view>
  53. </view>
  54. </view>
  55. </view>
  56. </tui-popup>
  57. </view>
  58. </template>
  59. <script>
  60. import { A_TF_MAIN } from '../../../config'
  61. export default {
  62. name: 'ShareProduct',
  63. data() {
  64. return {
  65. shareType: 1,
  66. salesId: null,
  67. shopId: null,
  68. productId: null,
  69. skuId: 0,
  70. isIphone: false,
  71. erweima: ''
  72. }
  73. },
  74. onLoad(options) {
  75. this.isIphone = getApp().globalData.isIphone
  76. if (options.shareType) {
  77. this.shareType = Number(options.shareType) // 1店铺(shopId、shareImg),2商品(shopId、productId、skuId、shareImg)
  78. }
  79. if (options.salesId) {
  80. this.salesId = options.salesId
  81. }
  82. if (options.productId) {
  83. this.productId = options.productId
  84. }
  85. if (options.skuId) {
  86. this.skuId = options.skuId
  87. }
  88. if (options.shopId) {
  89. this.shopId = options.shopId
  90. }
  91. this.erweima = options.shareImg
  92. },
  93. methods: {
  94. showcos() {
  95. uni.navigateBack({
  96. delta: 1
  97. })
  98. },
  99. // 保存图片到本地
  100. WXfenx() {
  101. // #ifdef APP || MP-WEIXIN || MP-ALIPAY
  102. // uni.showLoading({
  103. // title: '图片保存中...'
  104. // })
  105. // #endif
  106. // #ifdef APP
  107. uni.downloadFile({
  108. url: this.erweima,
  109. success: (res) => {
  110. if (res.statusCode === 200) {
  111. uni.saveImageToPhotosAlbum({
  112. filePath: res.tempFilePath,
  113. success() {
  114. uni.hideLoading()
  115. uni.showToast({
  116. title: '保存成功'
  117. })
  118. },
  119. fail() {
  120. uni.hideLoading()
  121. uni.showToast({
  122. title: '保存失败',
  123. icon: 'none'
  124. })
  125. }
  126. })
  127. }
  128. }
  129. })
  130. // #endif
  131. // #ifdef MP-WEIXIN || MP-ALIPAY
  132. uni.getImageInfo({
  133. src: this.erweima,
  134. success(image) {
  135. uni.saveImageToPhotosAlbum({
  136. filePath: image.path,
  137. success() {
  138. uni.hideLoading()
  139. uni.showToast({
  140. title: '图片保存成功'
  141. })
  142. },
  143. fail() {
  144. uni.hideLoading()
  145. uni.showModal({
  146. title: '图片保存失败',
  147. content: '请确认是否已开启授权',
  148. confirmText: '开启授权',
  149. success(res) {
  150. if (res
  151. .confirm
  152. ) {
  153. uni.openSetting({
  154. success(settingdata) {
  155. if (settingdata
  156. .authSetting[
  157. 'scope.writePhotosAlbum'
  158. ]
  159. ) {
  160. uni.showToast({
  161. title: '授权成功,请重试哦~',
  162. icon: 'none'
  163. })
  164. } else {
  165. uni.showToast({
  166. title: '请确定已打开保存权限',
  167. icon: 'none'
  168. })
  169. }
  170. }
  171. })
  172. }
  173. }
  174. })
  175. }
  176. })
  177. },
  178. fail(err) { }
  179. })
  180. // #endif
  181. // #ifdef H5
  182. var oA = document.createElement('a')
  183. oA.download = '' // 设置下载的文件名,默认是’下载’
  184. oA.href = this.erweima
  185. document.body.appendChild(oA)
  186. oA.click()
  187. oA.remove() // 下载之后把创建的元素删除
  188. // #endif
  189. },
  190. // 复制链接
  191. FZlianj() {
  192. let link
  193. if (this.salesId) {
  194. link = `${A_TF_MAIN}/#/pages/jump/jump?userId=&type=bindingSalesCustomer&code=${this.shareType}~${this.shopId}~${this.productId}~${this.skuId}~${this.salesId}`
  195. } else if (this.shareType === 1) {
  196. link = `${A_TF_MAIN}/#/another-tf/another-user/shop/shop-detail?storeId=${this.shopId}`
  197. } else if (this.shareType === 2) {
  198. link = `${A_TF_MAIN}/#/another-tf/another-serve/goodsDetails/index?shopId=${this.shopId}&productId=${this.productId}&skuId=${this.skuId}`
  199. }
  200. // #ifdef MP-WEIXIN || MP-ALIPAY || APP-PLUS
  201. uni.setClipboardData({
  202. data: link,
  203. success: (res) => {
  204. uni.showToast({
  205. title: '复制成功',
  206. icon: 'none',
  207. duration: 2000 // 时间
  208. })
  209. }
  210. })
  211. // #endif
  212. // #ifdef H5
  213. const textarea = document.createElement('textarea')
  214. textarea.value = link
  215. textarea.readOnly = 'readOnly'
  216. document.body.appendChild(textarea)
  217. textarea.select() // 选中文本内容
  218. textarea.setSelectionRange(0, link.length) // 设置选定区的开始和结束点
  219. uni.showToast({
  220. title: '复制成功'
  221. })
  222. const result = document.execCommand('copy') // 将当前选中区复制到剪贴板
  223. textarea.remove()
  224. // #endif
  225. }
  226. }
  227. }
  228. </script>
  229. <style lang="less" scoped>
  230. .warp {
  231. display: flex;
  232. align-items: center;
  233. justify-content: center;
  234. height: 100%;
  235. }
  236. .rect {
  237. background-color: #fff;
  238. position: relative;
  239. margin-top: -20rpx;
  240. .imgBox {
  241. .boxInner {
  242. display: inline-block;
  243. background-size: contain !important;
  244. background-position: center top !important;
  245. background-repeat: no-repeat !important;
  246. }
  247. .imgBoxShop {
  248. min-height: 814upx;
  249. min-width: 426upx;
  250. }
  251. .imgBoxProduct {
  252. min-height: 700upx;
  253. min-width: 426upx;
  254. }
  255. }
  256. }
  257. .fenx {
  258. position: fixed;
  259. bottom: 101rpx;
  260. z-index: 10001;
  261. background-color: #F7F7F7;
  262. width: 100%;
  263. display: flex;
  264. align-items: center;
  265. color: #343434;
  266. view {
  267. line-height: 98rpx;
  268. }
  269. image {
  270. width: 50rpx;
  271. height: 50rpx !important;
  272. display: inline-block;
  273. margin-top: 25rpx;
  274. }
  275. }
  276. .shareBox {
  277. width: 100%;
  278. }
  279. .linkBtnBox {
  280. flex: 1;
  281. width: 50%;
  282. text-align: center;
  283. display: flex;
  284. .linkBox {
  285. margin-left: 70rpx;
  286. }
  287. }
  288. .width100 {
  289. width: 50%;
  290. }
  291. </style>