face.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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="getSumit">提交</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 permijs 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: 'longyoung-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. },
  66. {
  67. value: 'HeadRight',
  68. name: '向右转头'
  69. },
  70. {
  71. value: 'HeadLeftOrRight',
  72. name: '左右摇头'
  73. },
  74. {
  75. value: 'HeadUp',
  76. name: '缓慢抬头'
  77. },
  78. {
  79. value: 'HeadDown',
  80. name: '缓慢低头'
  81. }
  82. ],
  83. isLivenessRandom: 0,
  84. isSound: 1,
  85. txtColor:'#3987FD',
  86. bgColor:'#2F2F33',
  87. roundColor:'#3987FD',
  88. resultStr: "",
  89. imgBase64Str: ""
  90. }
  91. },
  92. onLoad() {
  93. //权限
  94. // #ifdef APP-PLUS
  95. if (uni.getSystemInfoSync().platform == "ios") {
  96. // this.judgeIosPermission('camera');//相机
  97. this.licenseIDStr = "longyoung-face-ios";
  98. } else if (uni.getSystemInfoSync().platform == "android") {
  99. this.requestAndroidPermission('android.permission.CAMERA'); //相机
  100. // this.requestAndroidPermission('android.permission.READ_EXTERNAL_STORAGE');//外部存储(含相册)读取权限
  101. // this.requestAndroidPermission('android.permission.WRITE_EXTERNAL_STORAGE');//外部存储(含相册)写入权限
  102. this.licenseIDStr = "longyoung-face-android";
  103. }
  104. // #endif
  105. },
  106. methods:{
  107. checkPermi, checkRole,
  108. getSumit(){
  109. // this.$tab.navigateTo("/work/pages/prove/addqy")
  110. },
  111. //刷脸
  112. onScanFace() {
  113. console.error("tagg.onScanFace");
  114. self = this;
  115. var ary = [];
  116. for (var i = 0; i < this.items.length; i++) {
  117. var item = this.items[i];
  118. if (item.checked) {
  119. ary[i] = item.value;
  120. }
  121. }
  122. if (uni.getSystemInfoSync().platform == "android") {//安卓
  123. lyBDFaceAuth.scanFace({
  124. licenseID: this.licenseIDStr,
  125. actionAry: ary, //不传无动作
  126. isLivenessRandom: this.isLivenessRandom, //不传默认有序,0有序,1随机
  127. isSound: this.isSound, //不传默认有声音,0无声,1有声
  128. txtColor:this.txtColor,//文字颜色
  129. bgColor:this.bgColor,//背景颜色
  130. roundColor:this.roundColor//圆的颜色
  131. }, result => {
  132. console.log('file://' + result.imgPath);
  133. self.resultStr = "返回结果:\n" + JSON.stringify(result);
  134. //图片上传服务器
  135. uni.uploadFile({
  136. url: 'http://api.longyoung.com/api/open/common/uploadImgTemp', //图片上传地址
  137. filePath: 'file://' + result.imgPath, //图片本地路径,上传服务器需要加这个头'file://'
  138. method: 'post',
  139. name: 'imgFile', //上传图片参数名
  140. success: (res) => {
  141. var data = res.data;
  142. }
  143. });
  144. //***有些同学,后台强烈要求传base64,下面是图片转base64的方法,没此需求的可以无视。
  145. var bitmapT = new plus.nativeObj.Bitmap("test"); //test标识随便取
  146. // 从本地加载Bitmap图片
  147. bitmapT.load(result.imgPath, function() {
  148. console.log('加载图片成功');
  149. var base4 = bitmapT.toBase64Data();
  150. console.log('lygg.base64=' + base4);
  151. self.resultStr = self.resultStr + "\n======base64字符串(太长,截取前100字符):\n" + base4.substring(0, 100);
  152. self.imgBase64Str = base4.replace(/[\r\n]/g, ""); //显示图片
  153. }, function(e) {
  154. console.log('加载图片失败:' + JSON.stringify(e));
  155. });
  156. //***有些同学,后台强烈要求传base64,下面是图片转base64的方法,没此需求的可以无视。
  157. });
  158. } else if (uni.getSystemInfoSync().platform == "ios") {//苹果
  159. lyBDFaceAuthIOS.scanFace({
  160. licenseID: this.licenseIDStr,
  161. actionAry: ary, //不传无动作
  162. isLivenessRandom: this.isLivenessRandom, //不传默认有序,0有序,1随机
  163. isSound: this.isSound, //不传默认有声音,0无声,1有声
  164. }, result => {
  165. console.log('result=' + result);
  166. self.resultStr = "返回结果(太长,截取前100字符):\n" + JSON.stringify(result).substring(0, 100);
  167. self.resultStr = self.resultStr + "\n======base64字符串(太长,截取前100字符):\n" + result.bestImgBase64.substring(0, 100);
  168. self.imgBase64Str = "data:image/png;base64," + result.bestImgBase64.replace(/[\r\n]/g, ""); //显示图片
  169. });
  170. }
  171. },
  172. //权限
  173. async requestAndroidPermission(permisionID) {
  174. var result = await permijs.requestAndroidPermission(permisionID);
  175. var strStatus;
  176. if (result == 1) {
  177. strStatus = "已获得授权";
  178. } else if (result == 0) {
  179. strStatus = "未获得授权";
  180. uni.showToast({
  181. title: "请打开权限,否则无法使用",
  182. icon: 'none'
  183. });
  184. } else {
  185. strStatus = "被永久拒绝权限";
  186. permijs.gotoAppPermissionSetting();
  187. uni.showToast({
  188. title: '请打开权限,否则无法使用',
  189. icon: 'none'
  190. });
  191. }
  192. console.log("lygg.strStatus=" + strStatus + ",result=" + result);
  193. },
  194. }
  195. }
  196. </script>
  197. <style lang="scss" scoped>
  198. page{
  199. background:#ffffff;
  200. }
  201. .rzbox{padding: 78rpx 34rpx 76rpx;}
  202. // 面容
  203. .facea{width: 100%;margin:0 auto 16rpx;position: relative;width: 450rpx;height: 450rpx;
  204. image{width: 450rpx;height: 450rpx;display:block;margin: 0 auto;}
  205. .faceb{
  206. width: 376rpx;height: 376rpx;border-radius: 50%;position: absolute;top: 36rpx;left: 36rpx;border-radius: 50%;background-color: red;
  207. overflow: hidden;
  208. .factip{font-weight: bold;text-align: center;position: absolute;left: 0;top: 0;right: 0;height: 72rpx;line-height: 72rpx;
  209. font-size: 24rpx;color: #FFFFFF;background-color: rgba(0, 0, 0, 0.5);}
  210. }
  211. }
  212. .facetip{text-align: center;font-weight: 500;font-size: 26rpx;color: #666666;margin-bottom: 78rpx;
  213. text{color: $com-cd3;font-weight: 500;padding: 0 4rpx;}
  214. }
  215. .facetips{width: 214rpx;
  216. image{width: 100rpx;height: 100rpx;margin-bottom: 14rpx;}
  217. view{font-weight: 500;font-size: 24rpx;color: #B0B0B0;}
  218. }
  219. .phobox{display: flex;flex-direction: column;align-items: center;margin-top: 200rpx;margin-bottom: 92rpx;
  220. view{font-weight: 500;font-size: 26rpx;color: #00A9F0;margin-bottom: 34rpx;}
  221. image{width: 72rpx;height: 116rpx;}
  222. }
  223. </style>