faceImage.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <!-- 身份验证 -->
  2. <template>
  3. <view id="faceImage">
  4. <view class="max-box">
  5. <view>添加照片</view>
  6. <img v-if="!imgUrl" class="img-add" src="@/images/basicsModules/icon_07.png" @click="selectImage">
  7. <img v-if="imgUrl" mode="widthFix" class="img-box" :src="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. imgUrl:"",
  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. var self = this;
  51. uni.showLoading({
  52. title: '上传中',
  53. mask: true
  54. });
  55. uni.uploadFile({
  56. url: config.base_url+'/base/app/lab/api/commit/face', //仅为示例,非真实的接口地址
  57. header:{'Authorization':uni.getStorageSync('token')},
  58. filePath: tempFilePaths,
  59. name: 'file',
  60. formData: {
  61. 'file': 'test'
  62. },
  63. success: (uploadFileRes) => {
  64. let res = JSON.parse(uploadFileRes.data);
  65. if(res.code == 200){
  66. this.imgUrl = res.data.cardUrl
  67. uni.showToast({
  68. title: "识别成功",
  69. icon:"none",
  70. mask:true,
  71. duration: 2000
  72. });
  73. setTimeout(function(){
  74. uni.navigateBack();
  75. },2000);
  76. }else{
  77. uni.showToast({
  78. title: '您上传的身份验证无法识别,请重新上传其他照片',
  79. icon:"none",
  80. mask:true,
  81. duration: 2000
  82. });
  83. }
  84. // let res = JSON.parse(uploadFileRes.data);
  85. // self.imgUrl = res.data.url;
  86. // self.commitFace();
  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. display block;
  121. margin:5rpx auto;
  122. }
  123. }
  124. .button-box{
  125. width:650rpx;
  126. line-height:80rpx;
  127. text-align center;
  128. border-radius:10rpx;
  129. background #007AFF;
  130. color:#fff;
  131. margin:50rpx auto;
  132. }
  133. .up-data-button{
  134. position absolute
  135. bottom:0;
  136. left:0;
  137. width: 750rpx;
  138. height: 120rpx;
  139. background: #0183FA;
  140. line-height:120rpx;
  141. text-align center
  142. color:#fff;
  143. font-size: 30rpx;
  144. }
  145. }
  146. </style>