Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 12x 4x 8x 4x 4x 4x 2x 2x 2x 4x 9x 9x 9x 4x 4x 2x 8x 4x 8x 4x 2x 12x 12x 9x | <script setup lang="ts">
import { computed, ref } from "vue";
import { RouterLink } from "vue-router";
import {
PjButton,
PjField,
PjPageContainer,
PjStatusNotice,
PjSurface,
} from "@plain-journal/ui";
import { useSessionStore } from "../model/session";
const props = defineProps<{
mode: "login" | "register";
returnTo: string;
}>();
const emit = defineEmits<{
authenticated: [];
}>();
const session = useSessionStore();
const displayName = ref("");
const email = ref("");
const password = ref("");
const registering = computed(() => props.mode === "register");
const eyebrow = computed(() => registering.value ? "新账户" : "账户");
const heading = computed(() => registering.value
? "只留下必要的信息。"
: "继续你的素简记。");
const lead = computed(() => registering.value
? "密码至少 10 位,并同时包含字母和数字。注册成功后会立即建立会话。"
: "登录后会恢复账户会话,并尝试把当前设备购物袋安全合并到账户。");
const submitLabel = computed(() => {
if (session.busy) {
return registering.value ? "正在创建…" : "正在确认…";
}
return registering.value ? "创建账户 →" : "登录 →";
});
const alternateRoute = computed(() => registering.value ? "login" : "register");
async function submit() {
try {
if (registering.value) {
await session.registerAndLogin({
displayName: displayName.value,
email: email.value,
password: password.value,
});
} else {
await session.login({
email: email.value,
password: password.value,
});
}
emit("authenticated");
} catch {
// The session feature keeps the explicit backend or transport failure.
}
}
</script>
<template>
<PjPageContainer as="section" size="reading" class="identity-page">
<header class="identity-intro">
<p class="identity-context">{{ eyebrow }}</p>
<h1>{{ heading }}</h1>
<p class="identity-lead">{{ lead }}</p>
</header>
<PjSurface as="div" tone="plain" padding="medium" class="identity-panel">
<form class="identity-form" @submit.prevent="submit">
<PjField
v-if="registering"
v-slot="{ describedBy, invalid }"
label="称呼"
for-id="display-name"
required
>
<input
id="display-name"
v-model.trim="displayName"
class="pj-control"
type="text"
autocomplete="name"
minlength="2"
maxlength="50"
:aria-describedby="describedBy"
:aria-invalid="invalid"
required
/>
</PjField>
<PjField v-slot="{ describedBy, invalid }" label="邮箱" for-id="email" required>
<input
id="email"
v-model.trim="email"
class="pj-control"
type="email"
autocomplete="email"
maxlength="190"
:aria-describedby="describedBy"
:aria-invalid="invalid"
required
/>
</PjField>
<PjField
v-slot="{ describedBy, invalid }"
label="密码"
for-id="password"
:hint="registering ? '至少 10 位,并同时包含字母和数字。' : '使用当前账户密码继续。'"
required
>
<input
id="password"
v-model="password"
class="pj-control"
type="password"
:autocomplete="registering ? 'new-password' : 'current-password'"
:minlength="registering ? 10 : undefined"
:maxlength="registering ? 64 : 128"
:pattern="registering ? '(?=.*[A-Za-z])(?=.*\\d).+' : undefined"
:aria-describedby="describedBy"
:aria-invalid="invalid"
required
/>
</PjField>
<PjStatusNotice
v-if="session.error"
tone="danger"
assertive
:title="registering ? '账户未创建' : '登录未完成'"
>
<p>{{ session.error }}</p>
</PjStatusNotice>
<PjButton type="submit" :loading="session.busy" block>
{{ submitLabel }}
</PjButton>
</form>
<p class="identity-switch">
{{ registering ? "已有账户?" : "还没有账户?" }}
<RouterLink :to="{ name: alternateRoute, query: { returnTo } }">
{{ registering ? "登录" : "注册" }}
</RouterLink>
</p>
</PjSurface>
</PjPageContainer>
</template>
<style scoped>
.identity-page {
display: grid;
min-height: calc(100vh - 10rem);
align-content: center;
gap: var(--pj-space-6);
padding-block: var(--pj-space-8);
}
.identity-intro {
max-width: 38rem;
}
.identity-context {
margin: 0 0 var(--pj-space-3);
color: var(--pj-text-secondary);
font-size: var(--pj-font-size-xs);
font-weight: 650;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.identity-intro h1 {
margin: 0;
max-width: 12ch;
font-size: var(--pj-font-size-xl);
font-weight: 520;
letter-spacing: -0.04em;
line-height: var(--pj-line-height-tight);
}
.identity-lead,
.identity-switch {
color: var(--pj-text-secondary);
}
.identity-lead {
max-width: 36rem;
margin: var(--pj-space-4) 0 0;
}
.identity-form {
display: grid;
gap: var(--pj-space-5);
}
.identity-switch {
margin-top: var(--pj-space-6);
}
.identity-switch a {
color: var(--pj-brand-primary-hover);
font-weight: 650;
}
@media (max-width: 32rem) {
.identity-page {
min-height: auto;
padding-block: var(--pj-space-7);
}
}
</style>
|