UploadPhoto.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <template>
  2. <div>
  3. <common @asynCallBack="asynCallBack"></common>
  4. <top-header :pageTitle="pageTitle"></top-header>
  5. <div class="mui-content">
  6. <div class="mui-content-padded">
  7. <div class="mui-content-padded">
  8. <h5>请上传照片</h5>
  9. <div class="mui-h5 color999">
  10. 照片将用于人脸识别设备,请上传清晰的免冠登记照或肩部以上近照。
  11. </div>
  12. </div>
  13. <div class="mui-content-padded vongi-photo" @click="chooseImage">
  14. <div class="faceaifyy-content-region" :style="subForm.faceImageUrl?'background:none':''">
  15. <a v-if="!subForm.faceImageUrl"><span class="mui-icon iconfont icon-weibiaoti1"></span></a>
  16. <img v-if="subForm.faceImageUrl" :src="subForm.faceImageUrl" width="100%" />
  17. </div>
  18. </div>
  19. </div>
  20. </div>
  21. <div class="fyy-footer">
  22. <div class="bindfyy-btn"><button type="submit" class="mui-btn mui-btn-primary" @click="submit">提交</button></div>
  23. </div>
  24. <!--图片裁剪-->
  25. <cropper :cwidth="cropperWidth" :cheight="cropperHeight" :visible="cropperVisible" :field="cropperField" :cropper="cropper"
  26. @cropperFinish="cropperFinish" @cropperCancel="cropperCancel"></cropper>
  27. </div>
  28. </template>
  29. <script>
  30. import * as API_Person from '@/apis/person'
  31. import Common from '$project/components/Common.vue'
  32. import Loading from '$project/components/Loading.vue'
  33. import TopHeader from '$project/components/TopHeader.vue'
  34. import {
  35. mapGetters,
  36. mapMutations
  37. } from 'vuex'
  38. import Cropper from '$project/components/Cropper.vue'
  39. import * as WxJsApi from '$project/utils/wxJsApi'
  40. export default {
  41. name: 'UploadPhoto',
  42. components: {
  43. Common,
  44. Loading,
  45. TopHeader,
  46. Cropper
  47. },
  48. data() {
  49. return {
  50. pageTitle: '上传登记照',
  51. isLoading: false,
  52. subForm: {
  53. personId: this.$route.query.personId,
  54. openId: '',
  55. faceImageUrl: ''
  56. },
  57. cropperVisible: '',
  58. cropperField: '',
  59. cropperWidth: 250,
  60. cropperHeight: 350,
  61. cropper: {
  62. img: '',
  63. info: true,
  64. size: 1,
  65. outputType: 'jpeg',
  66. canScale: false,
  67. autoCrop: false,
  68. // 只有自动截图开启 宽度高度才生效
  69. autoCropWidth: 250,
  70. autoCropHeight: 350,
  71. fixed: true,
  72. // 真实的输出宽高
  73. infoTrue: true,
  74. fixedNumber: [5, 7]
  75. },
  76. }
  77. },
  78. created() {
  79. this.subForm.openId = this.openId;
  80. },
  81. methods: {
  82. //微信选择图片
  83. chooseImage() {
  84. WxJsApi.chooseImage().then(res => {
  85. var localData = res.localData;
  86. if (localData.indexOf('data:image') != 0) {
  87. //判断是否有这样的头部
  88. localData = 'data:image/jpeg;base64,' + localData
  89. }
  90. localData = localData.replace(/\r|\n/g, '').replace('data:image/jgp', 'data:image/jpeg')
  91. this.imgBase64 = localData;
  92. //显示裁剪图片
  93. this.showCropper('faceImageUrl');
  94. //this.uploadpic();
  95. }).catch(error => {
  96. mui.toast(error);
  97. })
  98. },
  99. //显示裁剪图片
  100. showCropper(field) {
  101. this.cropper.img = this.imgBase64;
  102. this.cropperField = field;
  103. this.cropperVisible = true;
  104. },
  105. //裁剪图片
  106. cropperFinish(obj) {
  107. console.log(obj);
  108. this.imgBase64 = obj.data;
  109. this.uploadpic(obj.field);
  110. this.cropperVisible = false;
  111. },
  112. //隐藏裁剪图片
  113. cropperCancel() {
  114. this.cropperVisible = false;
  115. },
  116. //上传图片
  117. uploadpic() {
  118. this.isLoading = true;
  119. WxJsApi.uploadPic(this.imgBase64).then(response => {
  120. this.isLoading = false;
  121. this.subForm.faceImageUrl = response;
  122. }).catch(error => {
  123. this.isLoading = false;
  124. mui.toast(error);
  125. })
  126. },
  127. //表单检测
  128. checkFrom() {
  129. if (!this.subForm.personId) {
  130. mui.toast('用户id未定义');
  131. return false;
  132. } else if (!this.subForm.openId) {
  133. mui.toast('openId未获取到');
  134. return false;
  135. } else if (!this.subForm.faceImageUrl) {
  136. mui.toast('请上传人脸照片');
  137. return false;
  138. } else {
  139. return true;
  140. }
  141. },
  142. //提交
  143. submit() {
  144. if (this.checkFrom()) {
  145. this.isLoading = true;
  146. API_Person.save(this.subForm).then(response => {
  147. this.isLoading = false;
  148. //场景之前选过,这里直接去选择角色,第一次注册也要传递project
  149. this.$router.push({
  150. name: 'Role',
  151. query: {
  152. project: this.$route.query.project
  153. }
  154. })
  155. }).catch(error => {
  156. this.isLoading = false;
  157. mui.toast(error);
  158. })
  159. }
  160. },
  161. asynCallBack() {
  162. },
  163. },
  164. mounted() {
  165. //获取微信配置
  166. WxJsApi.getWxConfig();
  167. },
  168. destroyed() {},
  169. computed: {
  170. ...mapGetters({
  171. openId: 'wx_openid',
  172. token: 'token',
  173. })
  174. }
  175. }
  176. </script>
  177. <style scoped src="$project/assets/css/xpwyfyy.css"></style>
  178. <style src="$project/assets/css/iconfont.css"></style>
  179. <style>
  180. </style>