Password.vue 2.2 KB

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