兼兼街公众号代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

214 lines
5.2 KiB

  1. <template>
  2. <view class="my-pages" @click="toImg" >
  3. <view class="top-box">
  4. <view class="head">
  5. <u--image shape="circle" :src="userInfo?userInfo.headImage:''" width="169rpx" height="169rpx"></u--image>
  6. <view style="padding: 56rpx; font-size: 45rpx; font-weight: bold;">{{userInfo?userInfo.nickName : '�����¼����'}}</view>
  7. </view>
  8. </view>
  9. <view class="contnet-box" id="poster">
  10. <view class="cell-box" id="poster">
  11. <view class="cell-item flex justify-between align-center">
  12. <view class="flex align-center">
  13. <canvas canvas-id="qrcode" class="qrcode"/>
  14. </view>
  15. </view>
  16. </view>
  17. </view>
  18. </view>
  19. </template>
  20. <script>
  21. import html2canvas from 'html2canvas';
  22. import uQRCode from '@/common/uqrcode.js'
  23. export default{
  24. data(){
  25. return{
  26. userInfo:null,
  27. role:0,
  28. cellList: [],
  29. base64: ''
  30. }
  31. },
  32. onShow() {
  33. this.getmyInfo()
  34. },
  35. onReady() {
  36. this.$com.displayNav()
  37. },
  38. methods:{
  39. getmyInfo(){
  40. this.$api('myInfo')
  41. .then(res=>{
  42. if(res.code == 200){
  43. this.role = res.result.role;
  44. this.userInfo = res.result;
  45. this.$store.commit('set_userInfo',res.result)
  46. this.qrFun('https://xinxiong.java996.icu/pages/my/login-kehu?vid=' + this.userInfo.id)
  47. }else{
  48. this.userInfo = null
  49. }
  50. })
  51. },
  52. toUrl(url,name){
  53. if(name==''){
  54. uni.navigateTo({
  55. url
  56. })
  57. }else{
  58. this.$Toast('')
  59. }
  60. },
  61. toLogin(){
  62. if(!this.userInfo){
  63. uni.navigateTo({
  64. url:"/pages/my/login-kehu"
  65. })
  66. }else{
  67. uni.navigateTo({
  68. url:'/pages/my/edit-user'
  69. })
  70. }
  71. },
  72. qrFun: function(text) {
  73. this.qrShow = true
  74. uQRCode.make({
  75. canvasId: 'qrcode',
  76. componentInstance: this,
  77. text: text,
  78. size: 300,
  79. margin: 0,
  80. backgroundColor: '#FFFFFF',
  81. foregroundColor: '#000000',
  82. fileType: 'png',
  83. errorCorrectLevel: uQRCode.errorCorrectLevel.H,
  84. success: res => {}
  85. })
  86. },
  87. saveHeadImgFile(base64) {
  88. const bitmap = new plus.nativeObj.Bitmap("test");
  89. bitmap.loadBase64Data(base64, function() {
  90. const url = "_doc/" + new Date().getTime() + ".png"; // urlΪʱ���������ʽ
  91. console.log('saveHeadImgFile', url)
  92. bitmap.save(url, {
  93. overwrite: true, // �Ƿ񸲸�
  94. // quality: 'quality' // ͼƬ������
  95. }, (i) => {
  96. uni.saveImageToPhotosAlbum({
  97. filePath: url,
  98. success: function() {
  99. uni.showToast({
  100. title: 'ͼƬ����ɹ�',
  101. icon: 'none'
  102. })
  103. bitmap.clear()
  104. }
  105. });
  106. }, (e) => {
  107. uni.showToast({
  108. title: 'ͼƬ����ʧ��',
  109. icon: 'none'
  110. })
  111. bitmap.clear()
  112. });
  113. }, (e) => {
  114. uni.showToast({
  115. title: 'ͼƬ����ʧ��',
  116. icon: 'none'
  117. })
  118. bitmap.clear()
  119. });
  120. },
  121. toImg() {
  122. // ����ͼƬ�������⣬��̨����һ���ӿڣ���Ҫ������ͼƬ����ת��base64���Լ����ӿڣ����Ͳ�д�ˡ�
  123. let dom = document.querySelector('#poster'); // ��ȡdomԪ��
  124. html2canvas(dom, {
  125. width: dom.clientWidth, //dom ԭʼ���
  126. height: dom.clientHeight,
  127. scrollY: 0,// html2canvasĬ�ϻ�����ͼ�ڵ�ҳ�棬��Ҫ��scrollY��scrollX����Ϊ0
  128. scrollX: 0,
  129. useCORS: true,//֧�ֿ��򣬵�����ûʲô��
  130. }).then((canvas) => {
  131. this.base64 = canvas.toDataURL('image/png', 1);
  132. console.log(this.base64)
  133. this.saveHeadImgFile(this.base64);
  134. uni.showToast({
  135. icon: 'success',
  136. title: '�����',
  137. });
  138. // this.$http.post("/api/upload/image_by_base64", {
  139. // image: this.base64
  140. // }).then(res => {
  141. // if (res.status == 200) {
  142. // this.downImg = res.data.data;
  143. // uni.showToast({
  144. // icon: 'success',
  145. // mask: true,
  146. // title: '�����',
  147. // });
  148. // }
  149. // })
  150. });
  151. },
  152. }
  153. }
  154. </script>
  155. <style lang="scss" scoped>
  156. .qrcode {
  157. width: 600rpx;
  158. height: 600rpx;
  159. margin: 50rpx auto;
  160. }
  161. .head {
  162. display: flex;
  163. justify-items: center;
  164. height: 168rpx;
  165. padding: 60rpx 20rpx 20rpx 40rpx;
  166. background-color: #00CCCC;
  167. }
  168. .my-pages {
  169. .top-box {
  170. height: 372rpx;
  171. background-color: #00CCCC;
  172. background-size: 100% 100%;
  173. }
  174. .contnet-box {
  175. height: 907rpx;
  176. background: #ffffff;
  177. border-radius: 79rpx 79rpx 0px 0px;
  178. box-shadow: 0px 3rpx 6rpx 0px rgba(0,0,0,0.16);
  179. margin: -80rpx 26rpx 0;
  180. position: relative;
  181. .user-box {
  182. font-size: 32rpx;
  183. color: #000000;
  184. font-weight: 700;
  185. position: absolute;
  186. left: 50%;
  187. top: -100rpx;
  188. transform: translate(-50% , 0);
  189. .user-name {
  190. text-align: center;
  191. margin-top: 20rpx;
  192. }
  193. }
  194. .cell-box {
  195. padding: 20rpx 34rpx 34rpx;
  196. }
  197. }
  198. }
  199. </style>