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(() =>{
  109. uni.showToast({
  110. title: "操作失败"
  111. })
  112. });
  113. },
  114. //头像上传
  115. uploadImg() {
  116. let that = this;
  117. uni.chooseImage({
  118. count: 1,
  119. success: (chooseImageRes) => {
  120. const tempFilePaths = chooseImageRes.tempFilePaths;
  121. uni.uploadFile({
  122. url: that.$baseUrl + '/resource/oss/upload', //仅为示例,非真实的接口地址
  123. filePath: tempFilePaths[0],
  124. name: 'file',
  125. header: {
  126. 'Authorization': 'Bearer ' + uni.getStorageInfo('accessToken'),
  127. },
  128. success: (uploadFileRes) => {
  129. console.log("uploadFileRes:"+uploadFileRes)
  130. let res = JSON.parse(uploadFileRes.data)
  131. that.ossId = res.data.ossId;
  132. that.facePhotoUrl = res.data.url.replace("http", "https");
  133. that.reqParm.facePath = res.data.ossId;
  134. }
  135. });
  136. }
  137. });
  138. }
  139. }
  140. }
  141. </script>
  142. <style scoped lang="scss">
  143. .container{
  144. padding: 12px;
  145. background: #F6F6F6;
  146. }
  147. .h-title{
  148. height: 22px;
  149. font-size: 14px;
  150. font-family: PingFangSC-Regular, PingFang SC;
  151. font-weight: 400;
  152. color: #333333;
  153. line-height: 22px;
  154. }
  155. // 弹窗
  156. .h-popo-content{
  157. height: 170px;
  158. padding: 12px;
  159. width: 300px;
  160. text-align: center;
  161. font-size: 14px;
  162. font-family: PingFangSC-Semibold, PingFang SC;
  163. .h-img{
  164. display: flex;
  165. justify-content: center;
  166. }
  167. .h-text{
  168. margin-top: 12px;
  169. font-weight: 400;
  170. color: #666666;
  171. }
  172. .text{
  173. margin-top: 6px;
  174. font-weight: 400;
  175. color: #666666;
  176. }
  177. .h-btn-wrap{
  178. display: flex;
  179. justify-content: space-between;
  180. color: #333333;
  181. text-align: center;
  182. margin-top: 20px;
  183. .h-left-btn{
  184. height: 32px;
  185. line-height: 30px;
  186. background: #EEEEEE;
  187. width: 100px;
  188. text-align: center;
  189. border-radius: 16px;
  190. margin: 0 auto;
  191. }
  192. .h-right-btn{
  193. height: 32px;
  194. line-height: 30px;
  195. background: #FFE05C;
  196. width: 100px;
  197. border-radius: 16px;
  198. margin: 0 auto;
  199. }
  200. }
  201. }
  202. .h-upload-wrap{
  203. .h-item-row{
  204. width: 100%;
  205. display: flex;
  206. align-items: center;
  207. justify-content: center;
  208. margin-top: 12px;
  209. font-family: PingFangSC-Regular, PingFang SC;
  210. .h-item{
  211. background: #fff;
  212. width: 48%;
  213. text-align: center;
  214. height: 164px;
  215. display: flex;
  216. align-items: center;
  217. justify-content: center;
  218. border-radius: 6px;
  219. .h-content{
  220. image{
  221. height: 48px;
  222. width: 48px;
  223. }
  224. .h-text{
  225. margin-top: 10px;
  226. font-size: 12px;
  227. font-weight: 400;
  228. color: #999999;
  229. line-height: 20px;
  230. }
  231. }
  232. .h-upload-img{
  233. width: 100%;
  234. height: 164px;
  235. padding: 4px;
  236. .imgBox{
  237. width: 164px;
  238. height: 164px;
  239. }
  240. }
  241. }
  242. }
  243. }
  244. .uploadBox {
  245. width: 100%;
  246. margin-top: 30px;
  247. height: 42px;
  248. background: #FFE05C;
  249. border-radius: 27px;
  250. color: #333333;
  251. line-height: 42px;
  252. text-align: center;
  253. }
  254. .btnTitle{
  255. font-size: 24rpx;
  256. font-weight: 400;
  257. color: #333333;
  258. line-height: 50px;
  259. padding-left: 32rpx;
  260. }
  261. @import '/common/css/common.css';
  262. </style>