Skip to content

Commit

Permalink
Merge pull request #30 from besscroft/dev
Browse files Browse the repository at this point in the history
fix:修复登录 loading 问题
  • Loading branch information
besscroft authored Sep 9, 2023
2 parents 2d1d700 + 2461320 commit a4f06b8
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions heming-web/pages/login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import ky from 'ky'
const user = useUserStore()
const router = useRouter()
const loading = ref(false)
const toast = useToast()
const nuxtApp = useNuxtApp()
Expand All @@ -29,17 +30,23 @@ const handUserInfo = async () => {
}
const handleSubmitClick = async () => {
const json = await ky.post('/@fast-api/user/login', {
json: {username: loginForm.username, password: loginForm.password}
}).json();
if (json.code === 200) {
user.setToken(json.data.tokenValue)
user.setTokenName(json.data.tokenName)
toast.add({ title: '登录成功!', timeout: 1000, ui: { width: 'w-full sm:w-96' }})
await handUserInfo()
} else {
console.log(json.message)
loading.value = true
try {
const json = await ky.post('/@fast-api/user/login', {
json: {username: loginForm.username, password: loginForm.password}
}).json();
if (json.code === 200) {
user.setToken(json.data.tokenValue)
user.setTokenName(json.data.tokenName)
toast.add({ title: '登录成功!', timeout: 1000, ui: { width: 'w-full sm:w-96' }})
await handUserInfo()
} else {
console.log(json.message)
}
} catch (e) {
loading.value = false
}
loading.value = false
}
const keyDown = (e) => {
Expand Down Expand Up @@ -100,11 +107,13 @@ definePageMeta({
</div>

<div class="mt-6">
<button
@click="handleSubmitClick"
class="w-full px-4 py-2 tracking-wide text-white transition-colors duration-200 transform bg-blue-500 rounded-md hover:bg-blue-400 focus:outline-none focus:bg-blue-400 focus:ring focus:ring-blue-300 focus:ring-opacity-50">
<v-btn
:loading="loading"
@click="handleSubmitClick"
class="font-ark w-full px-4 py-2 tracking-wide text-white transition-colors duration-200 transform bg-blue-500 rounded-md hover:bg-blue-400 focus:outline-none focus:bg-blue-400 focus:ring focus:ring-blue-300 focus:ring-opacity-50">
>
登录
</button>
</v-btn>
</div>

<p class="mt-6 text-sm text-center text-gray-400">还没有帐号?<a href="#" class="text-blue-500 focus:outline-none focus:underline hover:underline">立即注册</a>.</p>
Expand Down

1 comment on commit a4f06b8

@vercel
Copy link

@vercel vercel bot commented on a4f06b8 Sep 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

heming-fast – ./

heming-fast-besscroft.vercel.app
heming-fast-git-main-besscroft.vercel.app
fast.heming.dev

Please sign in to comment.