faceLogin.vue 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // TODO 第一版本暂无此功能 后续优化以及更新
  2. <template>
  3. <view class="face-login">
  4. <u-cell-group>
  5. <u-cell-item class="border-top" :arrow="false" title="面容登录">
  6. <u-switch slot="right-icon" @change="faceSwitchChange" active-color="#1abc9c" size="40" v-model="checked"></u-switch>
  7. </u-cell-item>
  8. </u-cell-group>
  9. <view class="describe">开启后可使用面容认证完成快捷登录,设置仅对本机生效。</view>
  10. </view>
  11. </template>
  12. <script>
  13. import storage from "@/utils/storage.js";
  14. import { setBiolofy } from "@/api/passport.js";
  15. export default {
  16. data() {
  17. return {
  18. lightColor: this.$lightColor,
  19. checked: true,
  20. };
  21. },
  22. methods: {
  23. faceSwitchChange(value) {
  24. if (value === true) {
  25. const res = uni.getSystemInfoSync();
  26. plus.device.getInfo({
  27. success: function (e) {
  28. let params = {
  29. mobile_type: res.model,
  30. secret_key: e.uuid,
  31. };
  32. setBiolofy(params).then((res) => {
  33. if (res.statusCode === 200) {
  34. storage.setFaceLogin(true);
  35. }
  36. });
  37. },
  38. fail: function (e) {
  39. //plus.nativeUI.toast('获取设备信息错误:' + JSON.stringify(e));
  40. console.error("getDeviceInfo failed: " + JSON.stringify(e));
  41. },
  42. });
  43. } else {
  44. storage.setFaceLogin(false);
  45. }
  46. },
  47. },
  48. onLoad() {
  49. // #ifdef APP-PLUS
  50. uni.checkIsSupportSoterAuthentication({
  51. success(res) {
  52. if (!res.supportMode.find((e) => e === "facial")) {
  53. plus.nativeUI.toast("此设备不支持面部识别");
  54. uni.navigateBack();
  55. }
  56. uni.checkIsSoterEnrolledInDevice({
  57. checkAuthMode: "facial",
  58. success(_res) {
  59. if (!_res.isEnrolled) {
  60. plus.nativeUI.toast("此设备未录入面部信息");
  61. uni.navigateBack();
  62. }
  63. },
  64. fail(_err) {
  65. // plus.nativeUI.toast(JSON.stringify(_err));
  66. uni.navigateBack();
  67. },
  68. });
  69. },
  70. fail(err) {
  71. // plus.nativeUI.toast(JSON.stringify(err));
  72. uni.navigateBack();
  73. },
  74. });
  75. this.checked = storage.getFaceLogin() || false;
  76. // #endif
  77. },
  78. };
  79. </script>
  80. <style lang="scss" scoped>
  81. .face-login {
  82. }
  83. </style>