index.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. <template>
  2. <view class="container" :style="{'height':height}">
  3. <!-- 提示内容 -->
  4. <view class="h-title">
  5. <text>*请输选择1张服务对象人脸影像</text>
  6. </view>
  7. <view class="h-upload-wrap">
  8. <view class="h-item-row">
  9. <view @click="uploadImg()" class="h-item">
  10. <view v-if="!facePhotoUrl" class="h-content">
  11. <image src="/static/me/u01.png" mode=""></image>
  12. <view class="h-text">
  13. <text>添加人脸影像</text>
  14. </view>
  15. </view>
  16. <view v-else class="h-upload-img">
  17. <image mode="aspectFit" class="imgBox" :src="facePhotoUrl"></image>
  18. </view>
  19. </view>
  20. </view>
  21. </view>
  22. <!-- 保存备案信息 -->
  23. <view class="uploadBox" @click="verifyFace()">
  24. <text>下一步</text>
  25. </view>
  26. </view>
  27. </template>
  28. <script>
  29. export default {
  30. components: {
  31. },
  32. data() {
  33. return {
  34. ossId:'',
  35. facePhotoUrl:'',
  36. height:'',
  37. reqParm: {
  38. auth: true,
  39. facePath: '',
  40. businessId: ''
  41. },
  42. userInfo: {},
  43. }
  44. },
  45. onReady() {
  46. },
  47. onLoad(option) {
  48. let sysInfo= uni.getSystemInfoSync()
  49. this.height = sysInfo.screenHeight + 'px'
  50. },
  51. methods: {
  52. // 连接已上传的图片地址
  53. verifyImgUpload(){
  54. if(!this.ossId){
  55. uni.showToast({
  56. title: "请上传人脸照片"
  57. })
  58. return false;
  59. }
  60. return true;
  61. },
  62. // 验证人象
  63. verifyFace(){
  64. let that = this;
  65. // 验证图片是否全上传
  66. if(!that.verifyImgUpload()){
  67. return;
  68. }
  69. uni.showLoading({
  70. title: '人脸识别中'
  71. })
  72. this.$api.verifyFace(that.reqParm).then((res)=>{
  73. uni.hideLoading();
  74. if(res.data.data.code == '500'){ //人脸不存在
  75. let serviceObject = {}
  76. serviceObject.facePhoto= this.ossId
  77. serviceObject.facePhotoUrl=this.facePhotoUrl
  78. console.log(JSON.stringify(serviceObject))
  79. uni.navigateTo({
  80. url: '/myPages/serviceObjectAllInfo/index?data='+ JSON.stringify(serviceObject),
  81. })
  82. } else { // 人脸存在
  83. res.opType = "1";
  84. res.facePhotoUrl = res.facePhoto;
  85. res.facePhotos = that.parms.facePhotos;
  86. uni.navigateTo({
  87. url: '/myPages/serviceObjectInfo/index?data=' + JSON.stringify(res),
  88. })
  89. }
  90. }).catch(() =>{
  91. uni.showToast({
  92. title: "操作失败"
  93. })
  94. });
  95. },
  96. //头像上传
  97. uploadImg() {
  98. let that = this;
  99. uni.chooseImage({
  100. count: 1,
  101. success: (chooseImageRes) => {
  102. const tempFilePaths = chooseImageRes.tempFilePaths;
  103. uni.uploadFile({
  104. url: that.$baseUrl + '/resource/oss/upload', //仅为示例,非真实的接口地址
  105. filePath: tempFilePaths[0],
  106. name: 'file',
  107. header: {
  108. 'Authorization': 'Bearer ' + uni.getStorageInfo('accessToken'),
  109. },
  110. success: (uploadFileRes) => {
  111. console.log("uploadFileRes:"+uploadFileRes)
  112. let res = JSON.parse(uploadFileRes.data)
  113. that.ossId = res.data.ossId;
  114. that.facePhotoUrl = res.data.url.replace("http", "https");
  115. that.reqParm.facePath = res.data.ossId;
  116. }
  117. });
  118. }
  119. });
  120. }
  121. }
  122. }
  123. </script>
  124. <style scoped lang="scss">
  125. .container{
  126. padding: 12px;
  127. background: #F6F6F6;
  128. }
  129. .h-title{
  130. height: 22px;
  131. font-size: 14px;
  132. font-family: PingFangSC-Regular, PingFang SC;
  133. font-weight: 400;
  134. color: #333333;
  135. line-height: 22px;
  136. }
  137. // 弹窗
  138. .h-popo-content{
  139. height: 170px;
  140. padding: 12px;
  141. width: 300px;
  142. text-align: center;
  143. font-size: 14px;
  144. font-family: PingFangSC-Semibold, PingFang SC;
  145. .h-img{
  146. display: flex;
  147. justify-content: center;
  148. }
  149. .h-text{
  150. margin-top: 12px;
  151. font-weight: 400;
  152. color: #666666;
  153. }
  154. .text{
  155. margin-top: 6px;
  156. font-weight: 400;
  157. color: #666666;
  158. }
  159. .h-btn-wrap{
  160. display: flex;
  161. justify-content: space-between;
  162. color: #333333;
  163. text-align: center;
  164. margin-top: 20px;
  165. .h-left-btn{
  166. height: 32px;
  167. line-height: 30px;
  168. background: #EEEEEE;
  169. width: 100px;
  170. text-align: center;
  171. border-radius: 16px;
  172. margin: 0 auto;
  173. }
  174. .h-right-btn{
  175. height: 32px;
  176. line-height: 30px;
  177. background: #FFE05C;
  178. width: 100px;
  179. border-radius: 16px;
  180. margin: 0 auto;
  181. }
  182. }
  183. }
  184. .h-upload-wrap{
  185. .h-item-row{
  186. width: 100%;
  187. display: flex;
  188. align-items: center;
  189. justify-content: center;
  190. margin-top: 12px;
  191. font-family: PingFangSC-Regular, PingFang SC;
  192. .h-item{
  193. background: #fff;
  194. width: 48%;
  195. text-align: center;
  196. height: 164px;
  197. display: flex;
  198. align-items: center;
  199. justify-content: center;
  200. border-radius: 6px;
  201. .h-content{
  202. image{
  203. height: 48px;
  204. width: 48px;
  205. }
  206. .h-text{
  207. margin-top: 10px;
  208. font-size: 12px;
  209. font-weight: 400;
  210. color: #999999;
  211. line-height: 20px;
  212. }
  213. }
  214. .h-upload-img{
  215. width: 100%;
  216. height: 164px;
  217. padding: 4px;
  218. .imgBox{
  219. width: 164px;
  220. height: 164px;
  221. }
  222. }
  223. }
  224. }
  225. }
  226. .uploadBox {
  227. width: 100%;
  228. margin-top: 30px;
  229. height: 42px;
  230. background: #FFE05C;
  231. border-radius: 27px;
  232. color: #333333;
  233. line-height: 42px;
  234. text-align: center;
  235. }
  236. </style>