|
|
@@ -30,8 +30,12 @@
|
|
|
</button>
|
|
|
|
|
|
<div class="text-center mb-6">
|
|
|
- <h2 class="text-xl font-bold text-white/90">登录账户</h2>
|
|
|
- <p class="text-white/60 mt-1">登录后即可使用全部功能</p>
|
|
|
+ <h2 class="text-xl font-bold text-white/90">
|
|
|
+ {{ isRegister ? "注册账户" : "登录账户" }}
|
|
|
+ </h2>
|
|
|
+ <p class="text-white/60 mt-1">
|
|
|
+ {{ isRegister ? "注册后即可使用全部功能" : "登录后即可使用全部功能" }}
|
|
|
+ </p>
|
|
|
</div>
|
|
|
|
|
|
<div class="space-y-4">
|
|
|
@@ -61,22 +65,86 @@
|
|
|
/>
|
|
|
</div>
|
|
|
|
|
|
+ <!-- 注册表单额外字段 -->
|
|
|
+ <div v-if="isRegister" class="space-y-4">
|
|
|
+ <div>
|
|
|
+ <label for="email" class="block text-sm text-white/70 mb-1.5"
|
|
|
+ >邮箱(选填)</label
|
|
|
+ >
|
|
|
+ <input
|
|
|
+ type="email"
|
|
|
+ id="email"
|
|
|
+ v-model="email"
|
|
|
+ class="w-full px-4 py-2.5 rounded-lg bg-white/5 border border-white/10 text-white/90 focus:outline-none focus:ring-2 focus:ring-brand/50"
|
|
|
+ placeholder="请输入邮箱"
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div>
|
|
|
+ <label for="phone" class="block text-sm text-white/70 mb-1.5"
|
|
|
+ >手机号(选填)</label
|
|
|
+ >
|
|
|
+ <input
|
|
|
+ type="tel"
|
|
|
+ id="phone"
|
|
|
+ v-model="phone"
|
|
|
+ class="w-full px-4 py-2.5 rounded-lg bg-white/5 border border-white/10 text-white/90 focus:outline-none focus:ring-2 focus:ring-brand/50"
|
|
|
+ placeholder="请输入手机号"
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div>
|
|
|
+ <label for="code" class="block text-sm text-white/70 mb-1.5"
|
|
|
+ >邀请码(选填)</label
|
|
|
+ >
|
|
|
+ <input
|
|
|
+ type="text"
|
|
|
+ id="code"
|
|
|
+ v-model="code"
|
|
|
+ class="w-full px-4 py-2.5 rounded-lg bg-white/5 border border-white/10 text-white/90 focus:outline-none focus:ring-2 focus:ring-brand/50"
|
|
|
+ placeholder="请输入邀请码"
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
<div v-if="error" class="text-red-400 text-sm py-1">
|
|
|
{{ error }}
|
|
|
</div>
|
|
|
|
|
|
<button
|
|
|
- @click="handleLogin"
|
|
|
+ @click="handleButtonClick"
|
|
|
:disabled="isLoading"
|
|
|
class="w-full py-2.5 rounded-lg bg-brand text-slate-900 font-medium hover:bg-brand/90 transition disabled:opacity-70"
|
|
|
>
|
|
|
- {{ isLoading ? "登录中..." : "登录" }}
|
|
|
+ {{
|
|
|
+ isLoading
|
|
|
+ ? isRegister
|
|
|
+ ? "注册中..."
|
|
|
+ : "登录中..."
|
|
|
+ : isRegister
|
|
|
+ ? "注册"
|
|
|
+ : "登录"
|
|
|
+ }}
|
|
|
</button>
|
|
|
|
|
|
<div class="text-center text-sm text-white/60">
|
|
|
- <p>
|
|
|
+ <p v-if="!isRegister">
|
|
|
还没有账户?
|
|
|
- <a href="#" class="text-brand hover:underline">注册新账户</a>
|
|
|
+ <a
|
|
|
+ href="#"
|
|
|
+ @click.prevent="toggleMode"
|
|
|
+ class="text-brand hover:underline"
|
|
|
+ >注册新账户</a
|
|
|
+ >
|
|
|
+ </p>
|
|
|
+ <p v-else>
|
|
|
+ 已有账户?
|
|
|
+ <a
|
|
|
+ href="#"
|
|
|
+ @click.prevent="toggleMode"
|
|
|
+ class="text-brand hover:underline"
|
|
|
+ >立即登录</a
|
|
|
+ >
|
|
|
</p>
|
|
|
</div>
|
|
|
</div>
|
|
|
@@ -99,14 +167,31 @@ const emit = defineEmits<{
|
|
|
|
|
|
const username = ref("");
|
|
|
const password = ref("");
|
|
|
+const email = ref("");
|
|
|
+const phone = ref("");
|
|
|
+const code = ref("");
|
|
|
const error = ref("");
|
|
|
const isLoading = ref(false);
|
|
|
+const isRegister = ref(false);
|
|
|
const userStore = useUserStore();
|
|
|
|
|
|
const closeDialog = () => {
|
|
|
emit("update:modelValue", false);
|
|
|
};
|
|
|
|
|
|
+const toggleMode = () => {
|
|
|
+ isRegister.value = !isRegister.value;
|
|
|
+ error.value = "";
|
|
|
+};
|
|
|
+
|
|
|
+const handleButtonClick = () => {
|
|
|
+ if (isRegister.value) {
|
|
|
+ handleRegister();
|
|
|
+ } else {
|
|
|
+ handleLogin();
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
const handleLogin = async () => {
|
|
|
// 简单的表单验证
|
|
|
if (!username.value || !password.value) {
|
|
|
@@ -127,6 +212,34 @@ const handleLogin = async () => {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
+const handleRegister = async () => {
|
|
|
+ // 简单的表单验证
|
|
|
+ if (!username.value || !password.value) {
|
|
|
+ error.value = "用户名和密码不能为空";
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ error.value = "";
|
|
|
+ isLoading.value = true;
|
|
|
+
|
|
|
+ await userStore.register(
|
|
|
+ username.value,
|
|
|
+ password.value,
|
|
|
+ email.value || undefined,
|
|
|
+ phone.value || undefined,
|
|
|
+ code.value || undefined
|
|
|
+ );
|
|
|
+
|
|
|
+ emit("login-success");
|
|
|
+ closeDialog();
|
|
|
+ } catch (err: any) {
|
|
|
+ error.value = err.message || "注册失败,请检查输入信息";
|
|
|
+ } finally {
|
|
|
+ isLoading.value = false;
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
// 当弹窗关闭时重置表单
|
|
|
watch(
|
|
|
() => props.modelValue,
|
|
|
@@ -134,8 +247,12 @@ watch(
|
|
|
if (!newVal) {
|
|
|
username.value = "";
|
|
|
password.value = "";
|
|
|
+ email.value = "";
|
|
|
+ phone.value = "";
|
|
|
+ code.value = "";
|
|
|
error.value = "";
|
|
|
isLoading.value = false;
|
|
|
+ isRegister.value = false;
|
|
|
}
|
|
|
}
|
|
|
);
|