Skip to content

Commit a9c80b6

Browse files
authored
refactor: logic of login (halo-dev#34)
移除登录组件,改为使用 Console 的登录页面,因为目前 Halo 在 2.6 中已经支持了登录之后重定向到某个页面。 /kind improvement 可测试插件:[plugin-comment-widget-1.5.0-SNAPSHOT.jar.zip](https://github.com/halo-sigs/plugin-comment-widget/files/11622679/plugin-comment-widget-1.5.0-SNAPSHOT.jar.zip) ```release-note 重构登录的逻辑,改为统一使用 Console 的登录页面。 ```
1 parent b8bd067 commit a9c80b6

File tree

8 files changed

+52
-400
lines changed

8 files changed

+52
-400
lines changed

Diff for: packages/comment-widget/package.json

+3-6
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,12 @@
3131
"./dist/style.css": "./dist/style.css"
3232
},
3333
"dependencies": {
34-
"@halo-dev/api-client": "^2.4.0",
35-
"@halo-dev/components": "^1.3.0",
34+
"@halo-dev/api-client": "^2.6.0",
35+
"@halo-dev/components": "^1.5.0",
3636
"@vueuse/components": "8.9.4",
3737
"@vueuse/core": "8.9.4",
38-
"jsencrypt": "^3.3.2",
3938
"emoji-mart-vue-fast": "^12.0.1",
40-
"lodash.clonedeep": "^4.5.0",
41-
"qs": "^6.11.0",
42-
"uuid": "^9.0.0"
39+
"lodash.clonedeep": "^4.5.0"
4340
},
4441
"devDependencies": {
4542
"@iconify-json/mdi": "^1.1.47",

Diff for: packages/comment-widget/src/components/Form.vue

+19-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<script lang="ts" setup>
22
import { VButton, VAvatar, VLoading } from "@halo-dev/components";
3-
import LoginModal from "./LoginModal.vue";
43
import MdiStickerEmoji from "~icons/mdi/sticker-emoji";
54
import MdiSendCircleOutline from "~icons/mdi/send-circle-outline";
65
import type {
@@ -51,8 +50,6 @@ const allowAnonymousComments = inject<Ref<boolean | undefined>>(
5150
"allowAnonymousComments"
5251
);
5352
54-
const loginModal = ref(false);
55-
5653
const raw = ref("");
5754
const allowNotification = ref(true);
5855
const saving = ref(false);
@@ -243,6 +240,20 @@ watchEffect(() => {
243240
handleSubmit();
244241
}
245242
});
243+
244+
// login
245+
246+
const parentDomId = `#comment-${[group?.replaceAll(".", "-"), kind, name]
247+
.join("-")
248+
.replaceAll(/-+/g, "-")}`;
249+
250+
const loginUrl = `/console/login?redirect_uri=${encodeURIComponent(
251+
window.location.href + parentDomId
252+
)}`;
253+
254+
function handleOpenLoginPage() {
255+
window.location.href = loginUrl;
256+
}
246257
</script>
247258

248259
<template>
@@ -280,12 +291,12 @@ watchEffect(() => {
280291
placeholder="网站"
281292
/>
282293

283-
<div
284-
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"
285-
@click="loginModal = true"
294+
<a
295+
class="select-none text-xs text-gray-600 transition-all hover:text-gray-900 dark:text-slate-200 dark:hover:text-slate-400"
296+
:href="loginUrl"
286297
>
287298
(已有该站点的账号)
288-
</div>
299+
</a>
289300
</div>
290301

291302
<div class="flex items-center justify-between">
@@ -303,7 +314,7 @@ watchEffect(() => {
303314
<VButton size="sm" @click="handleLogout">注销</VButton>
304315
</template>
305316
<template v-if="!currentUser && !allowAnonymousComments">
306-
<VButton size="sm" @click="loginModal = true">登录</VButton>
317+
<VButton size="sm" @click="handleOpenLoginPage">登录</VButton>
307318
</template>
308319
</div>
309320
<div class="flex flex-row items-center gap-3">
@@ -349,6 +360,5 @@ watchEffect(() => {
349360
</div>
350361
</div>
351362
</div>
352-
<LoginModal v-model:visible="loginModal" />
353363
</div>
354364
</template>

Diff for: packages/comment-widget/src/components/LoginModal.vue

-115
This file was deleted.

Diff for: packages/comment-widget/tsconfig.app.json

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"exclude": ["src/**/__tests__/*"],
55
"compilerOptions": {
66
"composite": true,
7+
"lib": ["esnext"],
78
"baseUrl": ".",
89
"paths": {
910
"@/*": ["./src/*"]

0 commit comments

Comments
 (0)