index.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. <template>
  2. <view class="container" :style="{'height':'100vh'}">
  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 class="btnTitle flex-row">
  27. <u-icon v-if="selectIcon" name="checkmark-circle-fill" color="#FFE52C" size="18" @click="selectChange"></u-icon>
  28. <u-icon v-else name="/static/order/ud9.png" color="#FFE52C" size="18" @click="selectChange"></u-icon>
  29. <text :style="{'margin-left':'10rpx'}">请阅读并同意</text>
  30. <text :style="{'color':'red'}" @click="goTermsOfService">《人脸识别服务协议》</text>
  31. </view>
  32. </view>
  33. </template>
  34. <script>
  35. export default {
  36. components: {
  37. },
  38. data() {
  39. return {
  40. selectIcon:false,
  41. ossId:'',
  42. facePhotoUrl:'',
  43. height:'',
  44. reqParm: {
  45. auth: true,
  46. facePath: '',
  47. businessId: ''
  48. },
  49. userInfo: {},
  50. }
  51. },
  52. onReady() {
  53. },
  54. onLoad(option) {
  55. },
  56. methods: {
  57. goTermsOfService(){
  58. uni.navigateTo({
  59. url:'/myPages/TermsOfService/index?name='+'人脸识别服务协议'+'&type=' + 6
  60. })
  61. },
  62. selectChange(){
  63. this.selectIcon = !this.selectIcon
  64. },
  65. // 连接已上传的图片地址
  66. verifyImgUpload(){
  67. if(!this.ossId){
  68. uni.showToast({
  69. title: "请上传人脸照片"
  70. })
  71. return false;
  72. }
  73. return true;
  74. },
  75. // 验证人象
  76. verifyFace(){
  77. let that = this;
  78. if(!this.selectIcon){
  79. uni.$u.toast('请阅读并同意《人脸识别服务协议》')
  80. return;
  81. }
  82. // 验证图片是否全上传
  83. if(!that.verifyImgUpload()){
  84. return;
  85. }
  86. uni.showLoading({
  87. title: '人脸识别中'
  88. })
  89. this.$api.verifyFace(that.reqParm).then((res)=>{
  90. uni.hideLoading();
  91. if(res.data.data.code == '500'){ //人脸不存在
  92. let serviceObject = {}
  93. serviceObject.facePhoto= this.ossId
  94. serviceObject.facePhotoUrl=this.facePhotoUrl
  95. console.log(JSON.stringify(serviceObject))
  96. uni.redirectTo({
  97. url: '/myPages/serviceObjectAllInfo/index?data='+ JSON.stringify(serviceObject),
  98. })
  99. } else { // 人脸存在
  100. let serviceObject = res.data.data
  101. serviceObject.opType = "1";
  102. serviceObject.facePhotoUrl = that.facePhotoUrl;
  103. serviceObject.facePhoto = that.reqParm.facePath;
  104. uni.redirectTo({
  105. url: '/myPages/serviceObjectInfo/index?data=' + JSON.stringify(serviceObject),
  106. })
  107. }
  108. }).catch((err) =>{
  109. uni.$u.toast('识别失败,请重新上传照片')
  110. });
  111. },
  112. //头像上传
  113. uploadImg() {
  114. let that = this;
  115. uni.chooseImage({
  116. count: 1,
  117. success: (chooseImageRes) => {
  118. const tempFilePaths = chooseImageRes.tempFilePaths;
  119. uni.uploadFile({
  120. url: that.$baseUrl + '/resource/oss/upload', //仅为示例,非真实的接口地址
  121. filePath: tempFilePaths[0],
  122. name: 'file',
  123. header: {
  124. 'Authorization': 'Bearer ' + uni.getStorageInfo('accessToken'),
  125. },
  126. success: (uploadFileRes) => {
  127. console.log("uploadFileRes:"+uploadFileRes)
  128. let res = JSON.parse(uploadFileRes.data)
  129. that.ossId = res.data.ossId;
  130. that.facePhotoUrl = res.data.url.replace("http", "https");
  131. that.reqParm.facePath = res.data.ossId;
  132. }
  133. });
  134. }
  135. });
  136. }
  137. }
  138. }
  139. </script>
  140. <style scoped lang="scss">
  141. .container{
  142. padding: 12px;
  143. background: #F6F6F6;
  144. }
  145. .h-title{
  146. height: 22px;
  147. font-size: 14px;
  148. font-family: PingFangSC-Regular, PingFang SC;
  149. font-weight: 400;
  150. color: #333333;
  151. line-height: 22px;
  152. }
  153. // 弹窗
  154. .h-popo-content{
  155. height: 170px;
  156. padding: 12px;
  157. width: 300px;
  158. text-align: center;
  159. font-size: 14px;
  160. font-family: PingFangSC-Semibold, PingFang SC;
  161. .h-img{
  162. display: flex;
  163. justify-content: center;
  164. }
  165. .h-text{
  166. margin-top: 12px;
  167. font-weight: 400;
  168. color: #666666;
  169. }
  170. .text{
  171. margin-top: 6px;
  172. font-weight: 400;
  173. color: #666666;
  174. }
  175. .h-btn-wrap{
  176. display: flex;
  177. justify-content: space-between;
  178. color: #333333;
  179. text-align: center;
  180. margin-top: 20px;
  181. .h-left-btn{
  182. height: 32px;
  183. line-height: 30px;
  184. background: #EEEEEE;
  185. width: 100px;
  186. text-align: center;
  187. border-radius: 16px;
  188. margin: 0 auto;
  189. }
  190. .h-right-btn{
  191. height: 32px;
  192. line-height: 30px;
  193. background: #FFE05C;
  194. width: 100px;
  195. border-radius: 16px;
  196. margin: 0 auto;
  197. }
  198. }
  199. }
  200. .h-upload-wrap{
  201. .h-item-row{
  202. width: 100%;
  203. display: flex;
  204. align-items: center;
  205. justify-content: center;
  206. margin-top: 12px;
  207. font-family: PingFangSC-Regular, PingFang SC;
  208. .h-item{
  209. background: #fff;
  210. width: 48%;
  211. text-align: center;
  212. height: 164px;
  213. display: flex;
  214. align-items: center;
  215. justify-content: center;
  216. border-radius: 6px;
  217. .h-content{
  218. image{
  219. height: 48px;
  220. width: 48px;
  221. }
  222. .h-text{
  223. margin-top: 10px;
  224. font-size: 12px;
  225. font-weight: 400;
  226. color: #999999;
  227. line-height: 20px;
  228. }
  229. }
  230. .h-upload-img{
  231. width: 100%;
  232. height: 164px;
  233. padding: 4px;
  234. .imgBox{
  235. width: 164px;
  236. height: 164px;
  237. }
  238. }
  239. }
  240. }
  241. }
  242. .uploadBox {
  243. width: 100%;
  244. margin-top: 30px;
  245. height: 42px;
  246. background: #FFE05C;
  247. border-radius: 27px;
  248. color: #333333;
  249. line-height: 42px;
  250. text-align: center;
  251. }
  252. .btnTitle{
  253. font-size: 24rpx;
  254. font-weight: 400;
  255. color: #333333;
  256. line-height: 50px;
  257. padding-left: 32rpx;
  258. }
  259. @import '/common/css/common.css';
  260. </style>