face.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <template>
  2. <view class="rzbox">
  3. <view class="facea">
  4. <image :src="faceimg" class="faceimg"></image>
  5. <view class="faceb">
  6. <view class="factip">请保持不动</view>
  7. </view>
  8. </view>
  9. <view class="facetip">面容认证仅能由<text>林涵宇</text>本人完成</view>
  10. <view class="flexcc">
  11. <view class="flexccc facetips">
  12. <image :src="ftipa"></image>
  13. <view>避免遮挡</view>
  14. </view>
  15. <view class="flexccc facetips">
  16. <image :src="ftipb"></image>
  17. <view>光线充足</view>
  18. </view>
  19. <view class="flexccc facetips">
  20. <image :src="ftipc"></image>
  21. <view>正对手机</view>
  22. </view>
  23. </view>
  24. <view class="phobox">
  25. <view>请把脸移入框内并保持不动</view>
  26. <image :src="phoimg"></image>
  27. </view>
  28. <view class="rzbtn" @click="onScanFace">提交</view>
  29. </view>
  30. </template>
  31. <script>
  32. import config from '@/config'
  33. const baseUrl = config.baseUrl
  34. import {uploadmore} from '@/utils/common.js'
  35. import { checkPermi, checkRole } from "@/utils/permission"; // 权限判断函数
  36. import {requestAndroidPermission} from '@/utils/permission.js'
  37. // #ifdef APP-PLUS
  38. const lyBDFaceAuth = uni.requireNativePlugin('longyoung-BDFaceAuth'); //android
  39. // #endif
  40. export default{
  41. components:{},
  42. data(){
  43. return{
  44. faceimg:require('@/work/static/images/prove/faceimg.png'),
  45. phoimg:require('@/work/static/images/prove/phoimg.png'),
  46. ftipa:require('@/work/static/images/prove/ftipa.png'),
  47. ftipb:require('@/work/static/images/prove/ftipb.png'),
  48. ftipc:require('@/work/static/images/prove/ftipc.png'),
  49. user:{
  50. },
  51. licenseIDStr: 'rongzidanbao-face-android',
  52. items: [{
  53. value: 'Eye',
  54. name: '眨眨眼',
  55. checked: 'true'
  56. },
  57. {
  58. value: 'Mouth',
  59. name: '张张嘴',
  60. checked: 'true'
  61. },
  62. {
  63. value: 'HeadLeft',
  64. name: '向左转头',
  65. checked: 'true'
  66. },
  67. {
  68. value: 'HeadRight',
  69. name: '向右转头',
  70. checked: 'true'
  71. },
  72. {
  73. value: 'HeadLeftOrRight',
  74. name: '左右摇头'
  75. },
  76. {
  77. value: 'HeadUp',
  78. name: '缓慢抬头'
  79. },
  80. {
  81. value: 'HeadDown',
  82. name: '缓慢低头'
  83. }
  84. ],
  85. isLivenessRandom: 0,
  86. isSound: 1,
  87. txtColor:'#3987FD',
  88. bgColor:'#2F2F33',
  89. roundColor:'#3987FD',
  90. resultStr: "",
  91. imgBase64Str: ""
  92. }
  93. },
  94. onLoad() {
  95. //权限
  96. // #ifdef APP-PLUS
  97. if (uni.getSystemInfoSync().platform == "ios") {
  98. // this.judgeIosPermission('camera');//相机
  99. this.licenseIDStr = "longyoung-face-ios";
  100. } else if (uni.getSystemInfoSync().platform == "android") {
  101. this.requestAndroidPermission('android.permission.CAMERA'); //相机
  102. // this.requestAndroidPermission('android.permission.READ_EXTERNAL_STORAGE');//外部存储(含相册)读取权限
  103. // this.requestAndroidPermission('android.permission.WRITE_EXTERNAL_STORAGE');//外部存储(含相册)写入权限
  104. // this.licenseIDStr = "longyoung-face-android";
  105. this.licenseIDStr = "rongzidanbao-face-android";
  106. }
  107. // #endif
  108. },
  109. methods:{
  110. checkPermi, checkRole,
  111. getSumit(){
  112. // this.$tab.navigateTo("/work/pages/prove/addqy")
  113. },
  114. //刷脸
  115. onScanFace() {
  116. console.error("tagg.onScanFace");
  117. self = this;
  118. var ary = [];
  119. for (var i = 0; i < this.items.length; i++) {
  120. var item = this.items[i];
  121. if (item.checked) {
  122. ary[i] = item.value;
  123. }
  124. }
  125. if (uni.getSystemInfoSync().platform == "android") {//安卓
  126. console.log(lyBDFaceAuth,1)
  127. lyBDFaceAuth.scanFace({
  128. licenseID: this.licenseIDStr,
  129. actionAry: ["Eye", "Mouth",], //不传无动作
  130. isLivenessRandom: this.isLivenessRandom, //不传默认有序,0有序,1随机
  131. isSound: this.isSound, //不传默认有声音,0无声,1有声
  132. txtColor:this.txtColor,//文字颜色
  133. bgColor:this.bgColor,//背景颜色
  134. roundColor:this.roundColor//圆的颜色
  135. }, result => {
  136. console.log('file://' + result.imgPath);
  137. self.resultStr = "返回结果:\n" + JSON.stringify(result);
  138. //图片上传服务器
  139. uni.uploadFile({
  140. url: 'http://api.longyoung.com/api/open/common/uploadImgTemp', //图片上传地址
  141. filePath: 'file://' + result.imgPath, //图片本地路径,上传服务器需要加这个头'file://'
  142. method: 'post',
  143. name: 'imgFile', //上传图片参数名
  144. success: (res) => {
  145. var data = res.data;
  146. }
  147. });
  148. //***有些同学,后台强烈要求传base64,下面是图片转base64的方法,没此需求的可以无视。
  149. var bitmapT = new plus.nativeObj.Bitmap("test"); //test标识随便取
  150. // 从本地加载Bitmap图片
  151. bitmapT.load(result.imgPath, function() {
  152. console.log('加载图片成功');
  153. var base4 = bitmapT.toBase64Data();
  154. console.log('lygg.base64=' + base4);
  155. self.resultStr = self.resultStr + "\n======base64字符串(太长,截取前100字符):\n" + base4.substring(0, 100);
  156. self.imgBase64Str = base4.replace(/[\r\n]/g, ""); //显示图片
  157. }, function(e) {
  158. console.log('加载图片失败:' + JSON.stringify(e));
  159. });
  160. //***有些同学,后台强烈要求传base64,下面是图片转base64的方法,没此需求的可以无视。
  161. });
  162. } else if (uni.getSystemInfoSync().platform == "ios") {//苹果
  163. lyBDFaceAuthIOS.scanFace({
  164. licenseID: this.licenseIDStr,
  165. actionAry: ary, //不传无动作
  166. isLivenessRandom: this.isLivenessRandom, //不传默认有序,0有序,1随机
  167. isSound: this.isSound, //不传默认有声音,0无声,1有声
  168. }, result => {
  169. console.log('result=' + result);
  170. self.resultStr = "返回结果(太长,截取前100字符):\n" + JSON.stringify(result).substring(0, 100);
  171. self.resultStr = self.resultStr + "\n======base64字符串(太长,截取前100字符):\n" + result.bestImgBase64.substring(0, 100);
  172. self.imgBase64Str = "data:image/png;base64," + result.bestImgBase64.replace(/[\r\n]/g, ""); //显示图片
  173. });
  174. }
  175. },
  176. //权限
  177. async requestAndroidPermission(permisionID) {
  178. var result = await requestAndroidPermission(permisionID);
  179. var strStatus;
  180. console.log(result)
  181. if (result == 1) {
  182. strStatus = "已获得授权";
  183. } else if (result == 0) {
  184. strStatus = "未获得授权";
  185. uni.showToast({
  186. title: "请打开权限,否则无法使用",
  187. icon: 'none'
  188. });
  189. } else {
  190. strStatus = "被永久拒绝权限";
  191. permijs.gotoAppPermissionSetting();
  192. uni.showToast({
  193. title: '请打开权限,否则无法使用',
  194. icon: 'none'
  195. });
  196. }
  197. console.log("lygg.strStatus=" + strStatus + ",result=" + result);
  198. },
  199. }
  200. }
  201. </script>
  202. <style lang="scss" scoped>
  203. page{
  204. background:#ffffff;
  205. }
  206. .rzbox{padding: 78rpx 34rpx 76rpx;}
  207. // 面容
  208. .facea{width: 100%;margin:0 auto 16rpx;position: relative;width: 450rpx;height: 450rpx;
  209. image{width: 450rpx;height: 450rpx;display:block;margin: 0 auto;}
  210. .faceb{
  211. width: 376rpx;height: 376rpx;border-radius: 50%;position: absolute;top: 36rpx;left: 36rpx;border-radius: 50%;background-color: red;
  212. overflow: hidden;
  213. .factip{font-weight: bold;text-align: center;position: absolute;left: 0;top: 0;right: 0;height: 72rpx;line-height: 72rpx;
  214. font-size: 24rpx;color: #FFFFFF;background-color: rgba(0, 0, 0, 0.5);}
  215. }
  216. }
  217. .facetip{text-align: center;font-weight: 500;font-size: 26rpx;color: #666666;margin-bottom: 78rpx;
  218. text{color: $com-cd3;font-weight: 500;padding: 0 4rpx;}
  219. }
  220. .facetips{width: 214rpx;
  221. image{width: 100rpx;height: 100rpx;margin-bottom: 14rpx;}
  222. view{font-weight: 500;font-size: 24rpx;color: #B0B0B0;}
  223. }
  224. .phobox{display: flex;flex-direction: column;align-items: center;margin-top: 200rpx;margin-bottom: 92rpx;
  225. view{font-weight: 500;font-size: 26rpx;color: #00A9F0;margin-bottom: 34rpx;}
  226. image{width: 72rpx;height: 116rpx;}
  227. }
  228. </style>