Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: logic of login #34

Merged
merged 5 commits into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions packages/comment-widget/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,12 @@
"./dist/style.css": "./dist/style.css"
},
"dependencies": {
"@halo-dev/api-client": "^2.4.0",
"@halo-dev/components": "^1.3.0",
"@halo-dev/api-client": "^2.6.0",
"@halo-dev/components": "^1.5.0",
"@vueuse/components": "8.9.4",
"@vueuse/core": "8.9.4",
"jsencrypt": "^3.3.2",
"emoji-mart-vue-fast": "^12.0.1",
"lodash.clonedeep": "^4.5.0",
"qs": "^6.11.0",
"uuid": "^9.0.0"
"lodash.clonedeep": "^4.5.0"
},
"devDependencies": {
"@iconify-json/mdi": "^1.1.47",
Expand Down
28 changes: 19 additions & 9 deletions packages/comment-widget/src/components/Form.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script lang="ts" setup>
import { VButton, VAvatar, VLoading } from "@halo-dev/components";
import LoginModal from "./LoginModal.vue";
import MdiStickerEmoji from "~icons/mdi/sticker-emoji";
import MdiSendCircleOutline from "~icons/mdi/send-circle-outline";
import type {
Expand Down Expand Up @@ -51,8 +50,6 @@ const allowAnonymousComments = inject<Ref<boolean | undefined>>(
"allowAnonymousComments"
);

const loginModal = ref(false);

const raw = ref("");
const allowNotification = ref(true);
const saving = ref(false);
Expand Down Expand Up @@ -243,6 +240,20 @@ watchEffect(() => {
handleSubmit();
}
});

// login

const parentDomId = `#comment-${[group?.replaceAll(".", "-"), kind, name]
.join("-")
.replaceAll(/-+/g, "-")}`;

const loginUrl = `/console/login?redirect_uri=${encodeURIComponent(
window.location.href + parentDomId
)}`;

function handleOpenLoginPage() {
window.location.href = loginUrl;
}
</script>

<template>
Expand Down Expand Up @@ -280,12 +291,12 @@ watchEffect(() => {
placeholder="网站"
/>

<div
class="cursor-pointer select-none text-xs text-gray-600 transition-all hover:text-gray-900 dark:text-slate-200 dark:hover:text-slate-400"
@click="loginModal = true"
<a
class="select-none text-xs text-gray-600 transition-all hover:text-gray-900 dark:text-slate-200 dark:hover:text-slate-400"
:href="loginUrl"
>
(已有该站点的账号)
</div>
</a>
</div>

<div class="flex items-center justify-between">
Expand All @@ -303,7 +314,7 @@ watchEffect(() => {
<VButton size="sm" @click="handleLogout">注销</VButton>
</template>
<template v-if="!currentUser && !allowAnonymousComments">
<VButton size="sm" @click="loginModal = true">登录</VButton>
<VButton size="sm" @click="handleOpenLoginPage">登录</VButton>
</template>
</div>
<div class="flex flex-row items-center gap-3">
Expand Down Expand Up @@ -349,6 +360,5 @@ watchEffect(() => {
</div>
</div>
</div>
<LoginModal v-model:visible="loginModal" />
</div>
</template>
115 changes: 0 additions & 115 deletions packages/comment-widget/src/components/LoginModal.vue

This file was deleted.

1 change: 1 addition & 0 deletions packages/comment-widget/tsconfig.app.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"exclude": ["src/**/__tests__/*"],
"compilerOptions": {
"composite": true,
"lib": ["esnext"],
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
Expand Down
Loading