index.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <template>
  2. <view class="bg-white scroll-height fingerprint-container">
  3. <view class="content-area">
  4. <text class="content-area-icon iconfont ucicon-zhiwen"></text>
  5. <view class="content-area-text">启用指纹登录,让登录更便捷</view>
  6. <view class="content-area-center">启用后,可通过设备本地的指纹验证方式快速登录。</view>
  7. <u-button type="primary" :plain="false" text="开启指纹登录" color="#2a98ff" @click="fingerprint()"></u-button>
  8. </view>
  9. </view>
  10. <u-modal :show="modalShow" confirmText="取消" @confirm="modalConfirm">
  11. <view class="slot-content">
  12. <text class="content-area-icon iconfont ucicon-zhiwen"></text>
  13. <view
  14. style="font-size: 15px; text-align: center"
  15. :style="{
  16. color: modalContent === '请验证指纹' || modalContent === '正在验证指纹...' ? '#000' : 'red',
  17. }"
  18. >
  19. {{ modalContent }}
  20. </view>
  21. </view>
  22. </u-modal>
  23. </template>
  24. <script setup>
  25. import { onLoad, onShow, onReady, onHide, onLaunch, onNavigationBarButtonTap, onPageScroll } from "@dcloudio/uni-app";
  26. import { ref, reactive, computed, getCurrentInstance, toRefs, inject } from "vue";
  27. import { useStores, commonStores } from "@/store/modules/index";
  28. import { loginLogList } from "@/api/mine/secure/loginLog.js";
  29. const useStore = useStores();
  30. const { proxy } = getCurrentInstance();
  31. const modalShow = ref(false);
  32. const modalContent = ref("");
  33. function modalConfirm() {
  34. // #ifdef APP-PLUS
  35. modalShow.value = false;
  36. plus.fingerprint.cancel();
  37. // #endif
  38. }
  39. function fingerprint() {
  40. // #ifdef APP-PLUS
  41. modalShow.value = true;
  42. modalContent.value = "请验证指纹";
  43. plus.fingerprint.authenticate(
  44. function () {
  45. modalContent.value = "正在验证指纹...";
  46. setTimeout(() => {
  47. modalShow.value = false;
  48. }, 1000);
  49. },
  50. function (e) {
  51. switch (e.code) {
  52. case e.AUTHENTICATE_MISMATCH:
  53. modalContent.value = "指纹匹配失败,请重新输入";
  54. break;
  55. case e.AUTHENTICATE_OVERLIMIT:
  56. plus.nativeUI.closeWaiting(); //兼容Android平台关闭等待框
  57. modalContent.value = "指纹识别失败次数超出限制,请使用其它方式进行认证";
  58. break;
  59. case e.CANCEL:
  60. plus.nativeUI.toast("已取消识别");
  61. break;
  62. default:
  63. plus.nativeUI.closeWaiting(); //兼容Android平台关闭等待框
  64. modalContent.value = "指纹识别失败,请重试";
  65. break;
  66. }
  67. }
  68. );
  69. // #endif
  70. // #ifdef MP-WEIXIN
  71. wx.startSoterAuthentication({
  72. requestAuthModes: ["fingerPrint"],
  73. challenge: "123456",
  74. authContent: "请用指纹解锁",
  75. success(res) {
  76. uni.showToast({
  77. title: "识别成功",
  78. mask: false,
  79. duration: 1500,
  80. });
  81. },
  82. });
  83. // #endif
  84. }
  85. onLoad((options) => {});
  86. onReady(() => {});
  87. // 自定义导航事件
  88. onNavigationBarButtonTap((e) => {});
  89. </script>
  90. <style lang="scss" scoped>
  91. .fingerprint-container {
  92. .content-area {
  93. padding: 150px 50px 0px;
  94. &-icon {
  95. display: flex;
  96. justify-content: center;
  97. font-size: 50px;
  98. margin-bottom: 30px;
  99. color: #2a98ff;
  100. }
  101. &-text {
  102. display: flex;
  103. justify-content: center;
  104. font-weight: 600;
  105. margin-bottom: 10px;
  106. color: #000;
  107. font-size: 16px;
  108. }
  109. &-center {
  110. display: flex;
  111. justify-content: center;
  112. margin-bottom: 30px;
  113. color: #96a6b5;
  114. font-size: 15px;
  115. }
  116. }
  117. }
  118. </style>