faceImage.vue 4.4 KB

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