Password.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <template>
  2. <div class="passwordcon" v-if="show">
  3. <img :src="metadata.icon" alt="" />
  4. <ui-window
  5. @ok="onOk"
  6. :okText="$t('common.confirm')"
  7. :title="$t('common.tips')"
  8. :showCloseIcon="false"
  9. :showCancelButton="false"
  10. >
  11. <template v-slot:content>
  12. <div class="wrapper">
  13. <ui-input
  14. type="password"
  15. :placeholder="$t('common.passwordTips')"
  16. maxlength="20"
  17. v-model.trim="password"
  18. width="100%"
  19. autocomplete="new-password"
  20. @input="onPasswordChange"
  21. @keyup.enter="onOk"
  22. />
  23. <span class="error">{{ error }}</span>
  24. </div>
  25. </template>
  26. </ui-window>
  27. </div>
  28. </template>
  29. <script setup>
  30. import { ref, onMounted, computed, watch, nextTick } from "vue";
  31. import { useI18n, getLocale } from "@/i18n";
  32. import { useStore } from "vuex";
  33. import { getApp } from "@/app";
  34. const store = useStore();
  35. const { t } = useI18n({ useScope: "global" });
  36. const error = ref("");
  37. const show = ref(false);
  38. const password = ref("");
  39. const passwordkey = computed(() => store.getters["scene/password"]);
  40. const metadata = computed(() => store.getters["scene/metadata"]);
  41. const onOk = () => {
  42. let app = getApp();
  43. error.value = "";
  44. if (!password.value) {
  45. return (error.value = t("toast.inputPassword"));
  46. }
  47. if (password.value === passwordkey.value) {
  48. show.value = false;
  49. app.Scene.unlock();
  50. } else {
  51. error.value = t("common.passwordError");
  52. }
  53. };
  54. const onPasswordChange = (e) => {
  55. password.value = e.target.value.replace(/[^\w]/g, "").replace(/_/g, "");
  56. };
  57. watch(passwordkey, () => {
  58. if (passwordkey.value) {
  59. show.value = true;
  60. } else {
  61. getApp().Scene.unlock();
  62. }
  63. });
  64. </script>
  65. <style lang="scss" scoped>
  66. .passwordcon {
  67. width: 100%;
  68. height: 100%;
  69. position: fixed;
  70. top: 0;
  71. left: 0;
  72. right: 0;
  73. bottom: 0;
  74. background-color: rgba(0, 0, 0, 0.5);
  75. z-index: 9;
  76. > img {
  77. width: 100%;
  78. height: 100%;
  79. filter: blur(15px);
  80. z-index: -1;
  81. }
  82. }
  83. .wrapper {
  84. width: 100%;
  85. display: flex;
  86. flex-direction: column;
  87. justify-content: center;
  88. }
  89. .error {
  90. height: 18px;
  91. margin-top: 10px;
  92. color: red;
  93. text-align: left;
  94. width: 100%;
  95. }
  96. </style>