qrcode.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. <template>
  2. <share-poster ref="poster">
  3. <view class="page">
  4. <uni-nav-bar leftText="" :statusBar="true" backgroundColor="transparent" :border="false">
  5. <template v-slot:left v-if="!load_image">
  6. <view class="icon-center" @click="backUser">
  7. <image class="back-icon" src="/static/share/nav_icon_back_black.png" mode="widthFix"></image>
  8. </view>
  9. </template>
  10. <template v-slot:default v-if="!load_image">
  11. <view class="nav-bar">
  12. <text class="title">我的二维码</text>
  13. </view>
  14. </template>
  15. <template class="" v-slot:right v-if="!load_image">
  16. <view class="icon-center" @click="refreshData">
  17. <image class="refresh-icon" :class="{refresh:loading}" src="/static/share/refresh.png"
  18. mode="widthFix"></image>
  19. </view>
  20. </template>
  21. </uni-nav-bar>
  22. <view class="qr-box">
  23. <view class="qr-box-title">
  24. <image class="qr-box-avatar" :lazy-load="true" :src="myPhoto" mode="widthFix"></image>
  25. <view class="qr-box-tip">
  26. <text class="black">{{my_data.nickname}}</text>
  27. <text class="gray">易趣号:{{my_data.username}}</text>
  28. </view>
  29. </view>
  30. <view class="qrimg">
  31. <tki-qrcode ref="qrcode" :val="qrData" :onval="true" :size="300" unit="upx" background="#ffffff"
  32. foreground="#000000" pdground="#000000" :loadMake="true" :showLoading="true"
  33. loadingText="加载中..." @result="qrR" />
  34. </view>
  35. <text class="text_font">使用易趣APP扫描二维码,加我为好友</text>
  36. <view class="btn-group" v-if="!load_image">
  37. <view class="btn" @click="savePoster">
  38. <image src="/static/share/album_down_save.webp" mode="widthFix"></image>
  39. <text>保存</text>
  40. </view>
  41. <!-- <view class="btn" @click="createPoster">
  42. <image src="/static/share/album_share_friend.webp" mode="widthFix"></image>
  43. <text>分享</text>
  44. </view> -->
  45. </view>
  46. </view>
  47. <view class="share" v-if="load_image">
  48. <image class="share_icon" src="@/static/share_icon.png" mode="widthFix"></image>
  49. </view>
  50. </view>
  51. </share-poster>
  52. </template>
  53. <script>
  54. import uniList from '../../components/uni-list/uni-list.vue';
  55. import uniListItem from '../../components/uni-list-item/uni-list-item.vue';
  56. import _page from '../../common/common';
  57. import _hook from '../../common/_hook';
  58. import _data from '../../common/_data';
  59. import tkiQrcode from "../../components/tki-qrcode/tki-qrcode";
  60. import uniNavBar from '@/components/uni-ui/uni-nav-bar/uni-nav-bar.vue'
  61. export default {
  62. components: {
  63. uniList,
  64. uniListItem,
  65. tkiQrcode,
  66. uniNavBar,
  67. },
  68. data() {
  69. return {
  70. my_data: {
  71. id: 0
  72. },
  73. img_path: '',
  74. loading: false,
  75. resultImg: '',
  76. load_image: false,
  77. }
  78. },
  79. onShow() {
  80. this.initData();
  81. },
  82. onLoad() {
  83. },
  84. onUnload() {
  85. uni.$off('data_user_info');
  86. },
  87. computed: {
  88. qrPhoto() {
  89. return _data.data('cache').local_photo;
  90. },
  91. myPhoto() {
  92. return _data.staticPhoto() + this.my_data.photo;
  93. },
  94. qrData() {
  95. let qr = _page.qrAction.chatAdd({
  96. user_id: this.my_data.id
  97. });
  98. console.log("qr", qr);
  99. return qr;
  100. },
  101. },
  102. methods: {
  103. // app截图保存、分享
  104. capture(type) {
  105. const _this = this;
  106. var pages = getCurrentPages();
  107. var page = pages[pages.length - 1];
  108. var bitmap = null;
  109. var currentWebview = page.$getAppWebview();
  110. bitmap = new plus.nativeObj.Bitmap('amway_img');
  111. currentWebview.draw(bitmap, function() {
  112. console.log("绘制截图成功");
  113. bitmap.save("_doc/a.jpg", {}, function(i) {
  114. console.log("保存图片成功", JSON.stringify(i));
  115. uni.saveImageToPhotosAlbum({
  116. filePath: i.target,
  117. success: function() {
  118. bitmap.clear(); //销毁缓存图片
  119. if (type == 'save') {
  120. uni.showToast({
  121. icon: 'none',
  122. title: '保存成功',
  123. })
  124. }
  125. if (type == "share") {
  126. uni.shareWithSystem({
  127. type: 'image',
  128. imageUrl: i.target,
  129. })
  130. }
  131. _this.load_image = false;
  132. uni.hideLoading();
  133. }
  134. })
  135. }, function(err) {
  136. _this.load_image = false;
  137. uni.hideLoading();
  138. console.log("保存失败", JSON.stringify(err))
  139. })
  140. }, function(err) {
  141. _this.load_image = false;
  142. uni.hideLoading();
  143. console.log("绘制截图失败", JSON.stringify(err))
  144. })
  145. },
  146. // 生成海报
  147. createPoster() {
  148. // #ifdef H5
  149. uni.showToast({
  150. icon: 'none',
  151. title: '请截图分享'
  152. })
  153. // #endif
  154. // #ifdef APP-PLUS
  155. this.createImage('share');
  156. // #endif
  157. },
  158. // 生成海报
  159. createImage(type) {
  160. this.load_image = true;
  161. uni.showLoading({
  162. title: '正在生成...'
  163. });
  164. setTimeout(() => {
  165. this.capture(type);
  166. }, 300)
  167. },
  168. // 保存海报
  169. savePoster() {
  170. // #ifdef H5
  171. uni.showToast({
  172. icon: 'none',
  173. title: '请截图保存'
  174. })
  175. // #endif
  176. // #ifdef APP-PLUS
  177. this.createImage('save');
  178. // #endif
  179. },
  180. initData() {
  181. _hook.routeTabBarHook();
  182. let _this = this;
  183. /** 监听新的个人数据 */
  184. uni.$on('data_user_info', function(data) {
  185. _this.my_data = data;
  186. });
  187. _this.my_data = _data.data('user_info');
  188. setTimeout(() => {
  189. this.loading = false;
  190. }, 1000)
  191. },
  192. refreshData() {
  193. this.loading = true;
  194. this.initData();
  195. },
  196. backUser() {
  197. uni.switchTab({
  198. url: '/pages/my/index'
  199. })
  200. },
  201. qrR(ref) {
  202. this.img_path = ref;
  203. },
  204. },
  205. watch: {
  206. },
  207. }
  208. </script>
  209. <style lang="scss" scoped>
  210. .share {
  211. display: flex;
  212. justify-content: center;
  213. align-items: center;
  214. height: 80rpx;
  215. margin: 30rpx;
  216. .share_icon {
  217. width: 200rpx;
  218. }
  219. }
  220. .btn-group {
  221. width: 400rpx;
  222. height: 120rpx;
  223. display: flex;
  224. // justify-content: space-between;
  225. justify-content:center;
  226. align-items: center;
  227. margin: 20rpx auto;
  228. .btn {
  229. display: flex;
  230. flex-direction: column;
  231. align-items: center;
  232. justify-content: center;
  233. image {
  234. width: 58rpx;
  235. height: 58rpx;
  236. }
  237. text {
  238. color: #0e131c;
  239. font-size: 32rpx;
  240. font-weight: bold;
  241. }
  242. }
  243. }
  244. .qr-box {
  245. width: 650rpx;
  246. margin: 120rpx auto 0;
  247. // border-radius: 50rpx;
  248. // height: 1040rpx;
  249. // overflow: hidden;
  250. // box-shadow: 0 0 10rpx 0rpx rgba(0, 0, 0, .1);
  251. // background: #fff;
  252. background: url('@/static/bg.png') no-repeat;
  253. background-size: 100% 100%;
  254. box-sizing: border-box;
  255. padding: 30rpx;
  256. .qr-box-title {
  257. display: flex;
  258. flex-direction: column;
  259. align-items: center;
  260. margin-bottom: 60rpx;
  261. .qr-box-avatar {
  262. width: 160rpx;
  263. height: 160rpx;
  264. border-radius: 50%;
  265. box-shadow: 0 10px 30rpx 6rpx rgba(0, 0, 0, .1);
  266. margin-bottom: 30rpx;
  267. margin-top: 60rpx;
  268. }
  269. .qr-box-tip {
  270. display: flex;
  271. flex-direction: column;
  272. align-items: center;
  273. text {
  274. font-size: 30rpx;
  275. }
  276. .gray {
  277. color: #d2d3d6;
  278. }
  279. .black {
  280. color: #353941;
  281. }
  282. }
  283. }
  284. }
  285. .page {
  286. background: url('@/static/share/im_group_qr_bg_big.png') no-repeat;
  287. background-size: 100% auto;
  288. }
  289. .icon-center {
  290. width: 100%;
  291. height: 100%;
  292. display: flex;
  293. justify-content: center;
  294. align-items: center;
  295. }
  296. .back-icon {
  297. width: 44rpx;
  298. height: 44rpx;
  299. flex-shrink: 0;
  300. }
  301. .refresh-icon {
  302. width: 50rpx;
  303. height: 50rpx;
  304. flex-shrink: 0;
  305. }
  306. @keyframes round {
  307. 0% {
  308. transform: rotate(0);
  309. }
  310. 0% {
  311. transform: rotate(-360deg);
  312. }
  313. }
  314. .refresh {
  315. animation: round 1s linear infinite;
  316. }
  317. .nav-bar {
  318. display: flex;
  319. justify-content: center;
  320. align-items: center;
  321. height: 100%;
  322. margin-left: -30rpx;
  323. .title {
  324. font-weight: bold;
  325. font-size: 30rpx;
  326. }
  327. }
  328. .qrimg {
  329. text-align: center;
  330. background: #FFFFFF;
  331. padding-bottom: 40upx;
  332. }
  333. .bode_main {
  334. margin: 150upx 35upx 0 35upx;
  335. width: 680upx;
  336. height: 900upx;
  337. border-radius: 50upx;
  338. overflow: hidden;
  339. }
  340. .photo {
  341. width: 110upx;
  342. height: 110upx;
  343. margin-left: 30upx;
  344. margin-right: 30upx;
  345. }
  346. .my_padding {
  347. padding-bottom: 20px;
  348. }
  349. .my_padding:before {
  350. background-color: white;
  351. }
  352. .my_padding:before {
  353. background-color: white;
  354. }
  355. .my_padding:after {
  356. background-color: white;
  357. }
  358. .text_font {
  359. color: #8f8f94;
  360. display: flex;
  361. justify-content: center;
  362. align-items: center;
  363. }
  364. </style>