bindInfo.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. <template>
  2. <view class="container" v-if="imageUrl || urlVal">
  3. <view class="qrcode-box x-c">
  4. <image class="qrcode" :src="imageUrl" mode="aspectFill" show-menu-by-longpress="true"></image>
  5. </view>
  6. <view class="share-inner">
  7. <!-- #ifdef MP-WEIXIN -->
  8. <view class="share-item" @click="downImg()">
  9. <view class="img">
  10. <uni-icons type="redo" size="30" color="#222"></uni-icons>
  11. </view>
  12. <text class="text">分享</text>
  13. </view>
  14. <!-- #endif -->
  15. <!-- #ifdef APP-PLUS -->
  16. <view class="share-item" @click="wxShare(0)">
  17. <image src="/static/images/icon_wx.png" mode=""></image>
  18. <text class="text">微信</text>
  19. <button class='share-btn'></button>
  20. </view>
  21. <view class="share-item" @click="wxShare(1)">
  22. <image src="/static/images/icon_pyq.png" mode=""></image>
  23. <text class="text">朋友圈</text>
  24. <button class='share-btn' open-type="share">
  25. </button>
  26. </view>
  27. <!-- #endif -->
  28. <!-- <view class="share-item" @click="copyUrl()">
  29. <image src="/static/images/icon_copy_link.png" mode=""></image>
  30. <text class="text">复制链接</text>
  31. </view> -->
  32. <!-- #ifndef H5 -->
  33. <view class="share-item" @click="downImg()">
  34. <view class="img">
  35. <uni-icons type="arrow-down" size="30" color="#222"></uni-icons>
  36. </view>
  37. <text class="text">保存图片</text>
  38. </view>
  39. <!-- #endif -->
  40. </view>
  41. </view>
  42. <u-empty style="padding-top: 20vh;" mode="data" v-else="imgurl"
  43. icon="https://cos.his.cdwjyyh.com/fs/20240423/cf4a86b913a04341bb44e34bb4d37aa2.png" text="暂无数据"></u-empty>
  44. </template>
  45. <script>
  46. import {
  47. getBindInfo
  48. } from "@/api/companyUser.js"
  49. export default {
  50. data() {
  51. return {
  52. imageUrl: '',
  53. urlVal: '',
  54. companyUserId: ''
  55. }
  56. },
  57. onShareAppMessage(res) {
  58. return {
  59. title: '立即绑定,享受更多权益',
  60. path: '/pages_user/bindCompanyUser?companyUserId=' + this.companyUserId,
  61. imageUrl: this.imageUrl
  62. }
  63. },
  64. //分享到朋友圈
  65. onShareTimeline(res) {
  66. return {
  67. title: '立即绑定,享受更多权益',
  68. path: '/pages_user/bindCompanyUser?companyUserId=' + this.companyUserId,
  69. imageUrl: this.imageUrl
  70. }
  71. },
  72. onLoad() {
  73. this.companyUserId = uni.getStorageSync('companyUserId') || '';
  74. this.getInfo()
  75. },
  76. methods: {
  77. getInfo() {
  78. getBindInfo().then(res => {
  79. if (res.code == 200) {
  80. this.imageUrl = res.imageUrl
  81. this.urlVal = res.url
  82. } else {
  83. uni.showToast({
  84. title: res.msg,
  85. icon: 'none'
  86. })
  87. }
  88. })
  89. },
  90. wxShare(type) {
  91. // #ifdef APP-PLUS
  92. if (!plus.runtime.isAgreePrivacy()) {
  93. uni.showToast({
  94. title: "请同意隐私政策",
  95. icon: "none",
  96. position: 'top',
  97. duration: 2000
  98. })
  99. return;
  100. }
  101. let that = this;
  102. let sceneStr = type == 0 ? "WXSceneSession" : "WXSceneTimeline";
  103. // 仅支持分享微信小程序到微信聊天界面,想进入朋友圈需改为分享图片方式,在图片中包含小程序码
  104. uni.share({
  105. provider: "weixin",
  106. scene: sceneStr,
  107. type: 2,
  108. imageUrl: this.imageUrl, //分享封面图片
  109. success: function(res) {
  110. uni.showToast({
  111. title: "分享成功",
  112. icon: 'none'
  113. });
  114. },
  115. fail: function(err) {
  116. // 此处是调起微信分享失败的回调
  117. },
  118. complete: (e) => {
  119. console.log("WXSceneTimeline", e)
  120. }
  121. });
  122. // #endif
  123. },
  124. copyUrl() {
  125. uni.setClipboardData({
  126. data: this.urlVal,
  127. success: () => {
  128. uni.showToast({
  129. title: '复制成功',
  130. icon: 'none'
  131. });
  132. },
  133. fail: () => {
  134. uni.showToast({
  135. title: '复制失败',
  136. icon: 'none'
  137. });
  138. }
  139. });
  140. },
  141. downImg() {
  142. uni.showLoading({
  143. title: "图片保存中..."
  144. })
  145. uni.downloadFile({
  146. url: this.imageUrl,
  147. fail: function(res) {
  148. uni.showModal({
  149. title: '提示',
  150. content: '保存失败',
  151. })
  152. uni.hideLoading();
  153. },
  154. success: function(res) {
  155. var tempFilePath = res.tempFilePath;
  156. uni.saveImageToPhotosAlbum({
  157. filePath: tempFilePath,
  158. success: () => {
  159. uni.showToast({
  160. title: "保存成功",
  161. duration: 2000
  162. })
  163. },
  164. fail: () => {
  165. console.log("图片失败");
  166. uni.showToast({
  167. title: "图片失败",
  168. duration: 2000,
  169. icon: "error"
  170. })
  171. uni.hideLoading();
  172. },
  173. complete: function() {
  174. uni.hideLoading();
  175. }
  176. })
  177. },
  178. })
  179. }
  180. }
  181. }
  182. </script>
  183. <style scoped lang="scss">
  184. .container {
  185. padding: 40rpx 0;
  186. padding-top: 16vh;
  187. box-sizing: border-box;
  188. display: flex;
  189. flex-direction: column;
  190. align-items: center;
  191. position: relative;
  192. }
  193. .qrcode-box {
  194. width: 480rpx;
  195. height: 480rpx;
  196. box-sizing: border-box;
  197. overflow: hidden;
  198. flex-direction: column !important;
  199. border-radius: 16rpx;
  200. background-color: #fff;
  201. font-family: PingFang SC, PingFang SC;
  202. font-weight: 400;
  203. font-size: 28rpx;
  204. color: #222;
  205. .qrcode {
  206. width: 450rpx;
  207. height: 450rpx;
  208. }
  209. .qrcode-title {
  210. font-weight: bold;
  211. font-size: 32rpx;
  212. color: #222;
  213. margin-bottom: 32rpx;
  214. }
  215. .qrcode-tip {
  216. margin: 32rpx;
  217. color: #999;
  218. text-align: center;
  219. }
  220. }
  221. .downbtn {
  222. width: 160rpx;
  223. min-height: 68rpx;
  224. border: 1px solid #FF5C03 !important;
  225. color: #FF5C03 !important;
  226. background-color: #fff !important;
  227. border-radius: 168rpx;
  228. font-family: PingFang SC, PingFang SC;
  229. font-weight: 400;
  230. font-size: 28rpx;
  231. &::after {
  232. border: none;
  233. }
  234. }
  235. .share-inner {
  236. width: 100%;
  237. box-sizing: border-box;
  238. padding: 0 10%;
  239. display: flex;
  240. flex-wrap: wrap;
  241. position: absolute;
  242. bottom: 0;
  243. left: 0;
  244. .share-item {
  245. flex: 1;
  246. display: flex;
  247. flex-direction: column;
  248. align-items: center;
  249. justify-content: center;
  250. margin-bottom: 66upx;
  251. position: relative;
  252. .img {
  253. width: 80upx;
  254. height: 80upx;
  255. margin-bottom: 20upx;
  256. background-color: #fff;
  257. display: flex;
  258. align-items: center;
  259. justify-content: center;
  260. border-radius: 50%;
  261. }
  262. image {
  263. width: 80upx;
  264. height: 80upx;
  265. margin-bottom: 20upx;
  266. }
  267. .text {
  268. font-size: 28upx;
  269. font-family: PingFang SC;
  270. font-weight: 500;
  271. color: #111111;
  272. line-height: 1;
  273. }
  274. }
  275. }
  276. .share-btn {
  277. position: absolute;
  278. left: 50%;
  279. top: 0;
  280. width: 80upx;
  281. height: 100%;
  282. transform: translateX(-50%);
  283. background-color: transparent !important;
  284. &::after {
  285. border: none;
  286. }
  287. }
  288. </style>