| | |
| | | <script setup> |
| | | import { ref, computed, nextTick } from "vue"; |
| | | import { ref, computed, nextTick, onMounted } from "vue"; |
| | | import { storeToRefs } from "pinia"; |
| | | import { useUserStore } from "@/stores/user.js"; |
| | | |
| | | const userStore = useUserStore(); |
| | | const { list } = storeToRefs(userStore); |
| | | const { list, lastUname } = storeToRefs(userStore); |
| | | // console.log("list", list.value, "============="); |
| | | const $emit = defineEmits(['set-snid', 'ok', 'cancel-remember']); |
| | | |
| | | const $emit = defineEmits(["set-snid", "ok", "cancel-remember"]); |
| | | |
| | | // 绑定的用户名 |
| | | const username = ref(""); |
| | |
| | | // 选择用户名并回写到输入框 |
| | | function selectUser(user) { |
| | | username.value = user.name; |
| | | $emit('set-snid', user.snId); |
| | | $emit("set-snid", user.snId); |
| | | showDropdown.value = false; // 关闭下拉列表 |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | function test(params) { |
| | | $emit('ok'); |
| | | $emit("ok"); |
| | | } |
| | | |
| | | function filterUsers() { |
| | | // 如果不是记住密码列表中的用户名 则取消记住密码 |
| | | if(!list.value.some(v=>v.name == username.value)) { |
| | | $emit('cancel-remember'); |
| | | if (!list.value.some((v) => v.name == username.value)) { |
| | | $emit("cancel-remember"); |
| | | } |
| | | } |
| | | defineExpose({username}); |
| | | function initUser() { |
| | | let _name = lastUname.value; |
| | | username.value = _name; |
| | | // 如果是记住密码列表中的用户名 则回写密码 |
| | | if (list.value.some((v) => v.name == _name)) { |
| | | $emit("set-snid", list.value.find((v) => v.name == _name).snId); |
| | | } |
| | | } |
| | | onMounted(() => { |
| | | initUser(); |
| | | }); |
| | | defineExpose({ username }); |
| | | </script> |
| | | |
| | | <template> |
| | |
| | | </el-input> |
| | | <div v-if="showDropdown && filteredUsers.length > 0" class="dropdown"> |
| | | <ul> |
| | | <li v-for="user in filteredUsers" :key="user.name" @click="selectUser(user)"> |
| | | <li |
| | | v-for="user in filteredUsers" |
| | | :key="user.name" |
| | | @click="selectUser(user)" |
| | | > |
| | | {{ user.name }} |
| | | </li> |
| | | </ul> |