faceImage.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <!-- 身份验证 -->
  2. <template>
  3. <view id="faceImage">
  4. <view class="max-box">
  5. <view>添加照片</view>
  6. <img v-if="!imgUrl" class="img-add" :src="imagesUrl('commonality/icon_07.png')" @click="selectImage">
  7. <img v-if="imgUrl" mode="widthFix" class="img-box" :src="baseUrl+imgUrl">
  8. </view>
  9. <view v-if="imgUrl" class="button-box" @click="selectImage">重新上传</view>
  10. </view>
  11. </template>
  12. <script>
  13. import { config } from '@/api/request/config.js'
  14. export default {
  15. data() {
  16. return {
  17. baseUrl:config.base_url,
  18. imgUrl:uni.getStorageSync('faceImg'),
  19. }
  20. },
  21. onLoad() {
  22. },
  23. onShow(){
  24. //this.mystudent();
  25. },
  26. methods: {
  27. // 获取上传头像
  28. async mystudent(){
  29. const {data} = await mystudent();
  30. if(data.code == 200){
  31. if(data.data){
  32. this.imgUrl = config.base_url+data.data.faceImg;
  33. }
  34. }
  35. },
  36. // 图片上传
  37. selectImage() {
  38. let self = this;
  39. wx.chooseImage({
  40. count: 1,
  41. sizeType: ["original", "compressed"],
  42. sourceType: ["album", "camera"],
  43. success: function(res) {
  44. let tempFilePaths = res.tempFilePaths[0];
  45. self.uploadImg(tempFilePaths);
  46. }
  47. });
  48. },
  49. async uploadImg(tempFilePaths){
  50. console.log(tempFilePaths)
  51. var self = this;
  52. uni.showLoading({
  53. title: '上传中',
  54. mask: true
  55. });
  56. uni.uploadFile({
  57. url: config.base_url+'/system/mine/user/face',
  58. header:{
  59. 'Authorization':uni.getStorageSync('token'),
  60. },
  61. filePath: tempFilePaths,
  62. name: 'file',
  63. formData: {
  64. 'file': 'test',
  65. 'userId': uni.getStorageSync('userId'),
  66. },
  67. success: (uploadFileRes) => {
  68. let res = JSON.parse(uploadFileRes.data);
  69. if(res.code == 200){
  70. uni.showToast({
  71. title: "识别成功",
  72. icon:"none",
  73. mask:true,
  74. duration: 2000
  75. });
  76. setTimeout(function(){
  77. uni.navigateBack();
  78. },2000);
  79. }else{
  80. uni.showToast({
  81. title: '您上传的身份验证无法识别,请重新上传其他照片',
  82. icon:"none",
  83. mask:true,
  84. duration: 2000
  85. });
  86. }
  87. },
  88. fail: err => {},
  89. complete: () => {
  90. setTimeout(function(){
  91. uni.hideLoading()
  92. },2000);
  93. }
  94. });
  95. },
  96. }
  97. }
  98. </script>
  99. <style lang="stylus" scoped>
  100. #faceImage{
  101. height:100%;
  102. width:100%;
  103. .max-box{
  104. // height:550rpx;
  105. padding-bottom:40rpx;
  106. background #fff
  107. view{
  108. line-height :95rpx;
  109. font-size:28rpx;
  110. color:#333333;
  111. margin-left:20rpx;
  112. }
  113. .img-add{
  114. margin:5rpx auto;
  115. height:360rpx;
  116. width:360rpx;
  117. /*margin:5rpx 0 0 30rpx;*/
  118. }
  119. .img-box{
  120. // height:360rpx;
  121. width:360rpx;
  122. display block;
  123. margin:5rpx auto;
  124. }
  125. }
  126. .button-box{
  127. width:650rpx;
  128. line-height:80rpx;
  129. text-align center;
  130. border-radius:10rpx;
  131. background #007AFF;
  132. color:#fff;
  133. margin:50rpx auto;
  134. }
  135. .up-data-button{
  136. position absolute
  137. bottom:0;
  138. left:0;
  139. width: 750rpx;
  140. height: 120rpx;
  141. background: #0183FA;
  142. line-height:120rpx;
  143. text-align center
  144. color:#fff;
  145. font-size: 30rpx;
  146. }
  147. }
  148. </style>