Files
SPlayer/src/components/Modal/Login/LoginUID.vue
imsyy a3e8931460 feat: 新增 UID 登录模式
- 修复未登录状态下动态封面报错 #274
- 修复海外手机号无法登录 #273
2024-10-14 15:05:14 +08:00

62 lines
1.6 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<div class="login-uid">
<n-alert :bordered="false" title="如何获取 UID">
<template #icon>
<SvgIcon name="Help" />
</template>
可前往
<n-a href="https://music.163.com/" target="_blank">网易云音乐</n-a>
官网登录并前往个人中心即可从地址栏获取到 UID也可在客户端分享链接中获取 UID
</n-alert>
<n-input-number v-model:value="uid" :show-button="false" laceholder="请输入 UID" />
<n-button :loading="!!loadingMsg" type="primary" @click="login">登录</n-button>
</div>
</template>
<script setup lang="ts">
import type { MessageReactive } from "naive-ui";
import type { LoginType } from "@/types/main";
import { userDetail } from "@/api/user";
const emit = defineEmits<{
close: [];
saveLogin: [any, LoginType];
}>();
const uid = ref<number>();
const loadingMsg = ref<MessageReactive | null>(null);
// UID 登录
const login = async () => {
if (!uid.value) {
window.$message.warning("请输入 UID");
return;
}
// 检查用户
loadingMsg.value = window.$message.loading("正在尝试登录", { duration: 0 });
try {
const result = await userDetail(uid.value);
window.$message.success("登录成功");
// 保存登录信息
emit("saveLogin", result, "uid");
emit("close");
} catch (error) {
window.$message.error("登录失败,请重试");
console.error("UID 登录出错:", error);
} finally {
loadingMsg.value?.destroy();
loadingMsg.value = null;
}
};
</script>
<style lang="scss" scoped>
.login-uid {
.n-input-number,
.n-button {
width: 100%;
margin-top: 20px;
}
}
</style>