index.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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="aspectFill"></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.redirectTo({
  80. url: '/myPages/serviceObjectAllInfo/index?data='+ JSON.stringify(serviceObject),
  81. })
  82. } else { // 人脸存在
  83. let serviceObject = res.data.data
  84. serviceObject.opType = "1";
  85. serviceObject.facePhotoUrl = that.facePhotoUrl;
  86. serviceObject.facePhoto = that.reqParm.facePath;
  87. uni.redirectTo({
  88. url: '/myPages/serviceObjectInfo/index?data=' + JSON.stringify(serviceObject),
  89. })
  90. }
  91. }).catch(() =>{
  92. uni.showToast({
  93. title: "操作失败"
  94. })
  95. });
  96. },
  97. //头像上传
  98. uploadImg() {
  99. let that = this;
  100. uni.chooseImage({
  101. count: 1,
  102. success: (chooseImageRes) => {
  103. const tempFilePaths = chooseImageRes.tempFilePaths;
  104. uni.uploadFile({
  105. url: that.$baseUrl + '/resource/oss/upload', //仅为示例,非真实的接口地址
  106. filePath: tempFilePaths[0],
  107. name: 'file',
  108. header: {
  109. 'Authorization': 'Bearer ' + uni.getStorageInfo('accessToken'),
  110. },
  111. success: (uploadFileRes) => {
  112. console.log("uploadFileRes:"+uploadFileRes)
  113. let res = JSON.parse(uploadFileRes.data)
  114. that.ossId = res.data.ossId;
  115. that.facePhotoUrl = res.data.url.replace("http", "https");
  116. that.reqParm.facePath = res.data.ossId;
  117. }
  118. });
  119. }
  120. });
  121. }
  122. }
  123. }
  124. </script>
  125. <style scoped lang="scss">
  126. .container{
  127. padding: 12px;
  128. background: #F6F6F6;
  129. }
  130. .h-title{
  131. height: 22px;
  132. font-size: 14px;
  133. font-family: PingFangSC-Regular, PingFang SC;
  134. font-weight: 400;
  135. color: #333333;
  136. line-height: 22px;
  137. }
  138. // 弹窗
  139. .h-popo-content{
  140. height: 170px;
  141. padding: 12px;
  142. width: 300px;
  143. text-align: center;
  144. font-size: 14px;
  145. font-family: PingFangSC-Semibold, PingFang SC;
  146. .h-img{
  147. display: flex;
  148. justify-content: center;
  149. }
  150. .h-text{
  151. margin-top: 12px;
  152. font-weight: 400;
  153. color: #666666;
  154. }
  155. .text{
  156. margin-top: 6px;
  157. font-weight: 400;
  158. color: #666666;
  159. }
  160. .h-btn-wrap{
  161. display: flex;
  162. justify-content: space-between;
  163. color: #333333;
  164. text-align: center;
  165. margin-top: 20px;
  166. .h-left-btn{
  167. height: 32px;
  168. line-height: 30px;
  169. background: #EEEEEE;
  170. width: 100px;
  171. text-align: center;
  172. border-radius: 16px;
  173. margin: 0 auto;
  174. }
  175. .h-right-btn{
  176. height: 32px;
  177. line-height: 30px;
  178. background: #FFE05C;
  179. width: 100px;
  180. border-radius: 16px;
  181. margin: 0 auto;
  182. }
  183. }
  184. }
  185. .h-upload-wrap{
  186. .h-item-row{
  187. width: 100%;
  188. display: flex;
  189. align-items: center;
  190. justify-content: center;
  191. margin-top: 12px;
  192. font-family: PingFangSC-Regular, PingFang SC;
  193. .h-item{
  194. background: #fff;
  195. width: 48%;
  196. text-align: center;
  197. height: 164px;
  198. display: flex;
  199. align-items: center;
  200. justify-content: center;
  201. border-radius: 6px;
  202. .h-content{
  203. image{
  204. height: 48px;
  205. width: 48px;
  206. }
  207. .h-text{
  208. margin-top: 10px;
  209. font-size: 12px;
  210. font-weight: 400;
  211. color: #999999;
  212. line-height: 20px;
  213. }
  214. }
  215. .h-upload-img{
  216. width: 100%;
  217. height: 164px;
  218. padding: 4px;
  219. .imgBox{
  220. width: 164px;
  221. height: 164px;
  222. }
  223. }
  224. }
  225. }
  226. }
  227. .uploadBox {
  228. width: 100%;
  229. margin-top: 30px;
  230. height: 42px;
  231. background: #FFE05C;
  232. border-radius: 27px;
  233. color: #333333;
  234. line-height: 42px;
  235. text-align: center;
  236. }
  237. </style>