-
Notifications
You must be signed in to change notification settings - Fork 758
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
081f5bd
commit 61149eb
Showing
8 changed files
with
202 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,3 @@ | ||
# Client | ||
|
||
|
||
## 开发规范 | ||
|
||
1. 不要解构 pinia 的 store | ||
- 解构会导致响应式丢失问题(ref 类型也会变成普通类型) | ||
- 使用 storeToRefs 非常的麻烦 | ||
- 带上 store 代码可读性也会更好一点 一眼就能知道数据的来源是哪里 | ||
我是前端前端前端 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,22 @@ | ||
<template> | ||
<NuxtLayout> | ||
<n-message-provider> | ||
<NuxtPage /> | ||
<HttpErrorProvider> | ||
<NuxtPage /> | ||
</HttpErrorProvider> | ||
</n-message-provider> | ||
</NuxtLayout> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
<script setup lang="tsx"> | ||
import "vfonts/Lato.css"; | ||
import { useUserStore } from "~/store/user"; | ||
const userStore = useUserStore(); | ||
useRestoreUser(); | ||
function useRestoreUser() { | ||
const userStore = useUserStore(); | ||
userStore.restoreUser(); | ||
} | ||
userStore.restoreUser(); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<template> | ||
<slot></slot> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { | ||
injectApiCodeErrorHandler, | ||
injectHttpStatusErrorHandler, | ||
} from "~/api/http"; | ||
useHttpStatusError(); | ||
useApiCodeError(); | ||
function useApiCodeError() { | ||
const message = useMessage(); | ||
injectApiCodeErrorHandler((msg) => { | ||
message.error(msg); | ||
}); | ||
} | ||
function useHttpStatusError() { | ||
const message = useMessage(); | ||
const router = useRouter(); | ||
injectHttpStatusErrorHandler(async (errMessage, statusCode) => { | ||
switch (statusCode) { | ||
case 400: | ||
message.error(errMessage); | ||
break; | ||
case 401: | ||
message.error(errMessage, { | ||
duration: 500, | ||
onLeave() { | ||
const callback = window.location.pathname; | ||
router.push(`/auth/login?callback=${callback}`); | ||
}, | ||
}); | ||
break; | ||
} | ||
}); | ||
} | ||
</script> | ||
|
||
<style scoped></style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1,100 @@ | ||
<template> | ||
<div className="flex min-h-full flex-1 flex-col justify-center px-6 py-12 lg:px-8"> | ||
<div className="sm:mx-auto sm:w-full sm:max-w-sm"> | ||
<img className="mx-auto h-10 w-auto" src="/logo.png" alt="earthworm" /> | ||
<h2 className="mt-10 text-center text-2xl font-bold leading-9 tracking-tight text-gray-900"> | ||
Log in to your account | ||
</h2> | ||
</div> | ||
<div | ||
className="flex min-h-full flex-1 flex-col justify-center px-6 py-12 lg:px-8" | ||
> | ||
<div className="sm:mx-auto sm:w-full sm:max-w-sm"> | ||
<img className="mx-auto h-10 w-auto" src="/logo.png" alt="earthworm" /> | ||
<h2 | ||
className="mt-10 text-center text-2xl font-bold leading-9 tracking-tight text-gray-900" | ||
> | ||
Log in to your account | ||
</h2> | ||
</div> | ||
|
||
<div className="mt-10 sm:mx-auto sm:w-full sm:max-w-sm"> | ||
<n-form ref="formEl" :rules="rules" :model="model"> | ||
<n-form-item path="phone" label="Phone" required> | ||
<n-input v-model:value="model.phone" @keydown.enter.prevent /> | ||
</n-form-item> | ||
<n-form-item path="password" label="Password" required> | ||
<n-input v-model:value="model.password" type="password" @keydown.enter.prevent /> | ||
</n-form-item> | ||
<n-button type="primary" size="large" block @click="handleLogin"> | ||
Log in | ||
</n-button> | ||
</n-form> | ||
<div className="mt-10 sm:mx-auto sm:w-full sm:max-w-sm"> | ||
<n-form ref="formEl" :rules="rules" :model="model"> | ||
<n-form-item path="phone" label="Phone" required> | ||
<n-input v-model:value="model.phone" @keydown.enter.prevent /> | ||
</n-form-item> | ||
<n-form-item path="password" label="Password" required> | ||
<n-input | ||
v-model:value="model.password" | ||
type="password" | ||
@keydown.enter.prevent | ||
/> | ||
</n-form-item> | ||
<n-button type="primary" size="large" block @click="handleLogin"> | ||
Log in | ||
</n-button> | ||
</n-form> | ||
|
||
<p className="mt-10 text-center text-sm text-gray-500"> | ||
Not a account? | ||
<NuxtLink href="/auth/signup" className="font-semibold leading-6 text-indigo-600 hover:text-indigo-500"> | ||
Sign up | ||
</NuxtLink> | ||
</p> | ||
</div> | ||
<p className="mt-10 text-center text-sm text-gray-500"> | ||
Not a account? | ||
<NuxtLink | ||
href="/auth/signup" | ||
className="font-semibold leading-6 text-indigo-600 hover:text-indigo-500" | ||
> | ||
Sign up | ||
</NuxtLink> | ||
</p> | ||
</div> | ||
</div> | ||
</template> | ||
<script setup lang="ts"> | ||
import { type FormInst, type FormRules } from "naive-ui"; | ||
import { useAuth } from "~/composables/auth"; | ||
import { delay } from '~/utils'; | ||
import { delay } from "~/utils"; | ||
interface ModelType { | ||
phone: string | null; | ||
password: string | null; | ||
phone: string | null; | ||
password: string | null; | ||
} | ||
const { login } = useAuth(); | ||
const formEl = ref<FormInst | null>(null); | ||
const model = ref<ModelType>({ | ||
phone: null, | ||
password: null, | ||
phone: null, | ||
password: null, | ||
}); | ||
const rules: FormRules = { | ||
phone: [ | ||
{ required: true, message: "Please input your phone number" }, | ||
{ | ||
pattern: /^1[3456789]\d{9}$/, | ||
message: "Please input correct phone number", | ||
}, | ||
], | ||
password: [ | ||
{ required: true, message: "Please input your password" }, | ||
{ min: 6, message: "Password length must be greater than 6" }, | ||
], | ||
phone: [ | ||
{ required: true, message: "Please input your phone number" }, | ||
{ | ||
pattern: /^1[3456789]\d{9}$/, | ||
message: "Please input correct phone number", | ||
}, | ||
], | ||
password: [ | ||
{ required: true, message: "Please input your password" }, | ||
{ min: 6, message: "Password length must be greater than 6" }, | ||
], | ||
}; | ||
const message = useMessage(); | ||
const router = useRouter(); | ||
const route = useRoute(); | ||
async function gotoPreviousPage() { | ||
await delay(500); | ||
const handleLogin = () => { | ||
function gotoPreviousPage() { | ||
router.replace(route.query.callback?.toString() ?? "/"); | ||
} | ||
} | ||
const handleLogin = () => { | ||
formEl.value?.validate(async (errors) => { | ||
if (!errors) { | ||
await login({ | ||
phone: model.value.phone ?? "", | ||
password: model.value.password ?? "", | ||
}); | ||
formEl.value?.validate(async (errors) => { | ||
if (!errors) { | ||
await login({ | ||
phone: model.value.phone ?? "", | ||
password: model.value.password ?? "", | ||
}); | ||
message.success("login success"); | ||
await gotoPreviousPage() | ||
} | ||
}); | ||
message.success("login success", { | ||
duration: 500, | ||
onLeave() { | ||
gotoPreviousPage(); | ||
}, | ||
}); | ||
} | ||
}); | ||
}; | ||
</script> |
Oops, something went wrong.