Skip to content
Closed
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
45 changes: 41 additions & 4 deletions src/components/List/CommentList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,10 @@ import { isLogin } from "@/utils/auth";
import { openUserLogin } from "@/utils/modal";
import emoji from "@/assets/data/emoji.json";
import { commentLike, hugComment, getCommentHugList } from "@/api/comment";
import { useDataStore } from "@/stores";
import { useDataStore, useSettingStore } from "@/stores";

const userStore = useDataStore();
const settingStore = useSettingStore();

const props = defineProps<{
data: CommentType[];
Expand Down Expand Up @@ -164,13 +165,49 @@ const likeComment = debounce(async (data: CommentType) => {
}, 300);

// 双击抱一抱
let hugTipDismissed = false;
watch(() => settingStore.enableCommentHug, (v) => {
if (v) hugTipDismissed = false;
});
const handleDoubleClick = debounce(async (item: CommentType) => {
if (!settingStore.enableCommentHug) return;
// 首次双击提示
if (!settingStore.showedCommentHugTip) {
window.$dialog.warning({
title: "抱一抱",
content: "双击评论会向评论者发送「抱一抱」,是否继续?",
positiveText: "继续",
negativeText: hugTipDismissed ? "取消且不再提示" : "取消",
onPositiveClick: () => {
settingStore.showedCommentHugTip = true;
executeHug(item);
},
onNegativeClick: () => {
if (hugTipDismissed) {
settingStore.showedCommentHugTip = true;
settingStore.enableCommentHug = false;
}
hugTipDismissed = true;
},
Comment on lines 172 to +191
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

为了实现状态持久化,这里应使用 store 中的 hugTipDismissed 状态,而不是组件内的局部变量。请在应用此建议后,手动移除第 168 行的 let hugTipDismissed = false;

const handleDoubleClick = debounce(async (item: CommentType) => {
  if (!settingStore.enableCommentHug) return;
  // 首次双击提示
  if (!settingStore.showedCommentHugTip) {
    window.$dialog.warning({
      title: "抱一抱",
      content: "双击评论会向评论者发送「抱一抱」,是否继续?",
      positiveText: "继续",
      negativeText: settingStore.hugTipDismissed ? "取消且不再提示" : "取消",
      onPositiveClick: () => {
        settingStore.showedCommentHugTip = true;
        executeHug(item);
      },
      onNegativeClick: () => {
        if (settingStore.hugTipDismissed) {
          settingStore.showedCommentHugTip = true;
          settingStore.enableCommentHug = false;
        }
        settingStore.hugTipDismissed = true;
      },
    });

});
return;
}
executeHug(item);
}, 300);

// 执行抱一抱
const executeHug = async (item: CommentType) => {
if (!isLogin()) {
openUserLogin();
return;
}
// 本地歌曲不支持抱一抱
if (typeof props.resId !== "number") return;
// 仅歌曲评论支持抱一抱
if (typeof props.resId !== "number" || props.type !== 0) {
if (typeof props.resId === "number") {
window.$message.warning("仅歌曲评论支持抱一抱");
}
return;
}
try {
const result = await hugComment(userStore.userData.userId, item.id, props.resId);
if (result.code === 200) {
Expand Down Expand Up @@ -207,7 +244,7 @@ const handleDoubleClick = debounce(async (item: CommentType) => {
console.error("Hug comment error:", error);
window.$message.error("抱一抱失败");
}
}, 300);
};
</script>

<style lang="scss" scoped>
Expand Down
13 changes: 13 additions & 0 deletions src/components/Setting/config/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,19 @@ export const useGeneralSettings = (): SettingConfig => {
{
title: "其他设置",
items: [
{
key: "enableCommentHug",
label: "评论区抱一抱",
type: "switch",
description: "开启后双击评论即可向评论者发送抱一抱",
value: computed({
get: () => settingStore.enableCommentHug,
set: (v) => {
settingStore.enableCommentHug = v;
if (v) settingStore.showedCommentHugTip = false;
Comment on lines +373 to +374
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

当用户重新开启「抱一抱」功能时,也应该重置 hugTipDismissed 状态,以便用户能重新看到标准的“取消”提示,而不是“取消且不再提示”。

                settingStore.enableCommentHug = v;
                if (v) {
                  settingStore.showedCommentHugTip = false;
                  settingStore.hugTipDismissed = false;
                }

},
}),
},
{
key: "shareUrlFormat",
label: "分享链接格式",
Expand Down
6 changes: 6 additions & 0 deletions src/stores/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ export interface SettingState {
taskbarLyricUseThemeColor: boolean;
/** 是否使用在线服务 */
useOnlineService: boolean;
/** 评论区抱一抱 */
enableCommentHug: boolean;
/** 是否已显示过抱一抱提示 */
showedCommentHugTip: boolean;
Comment on lines +53 to +54
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

为了让「抱一抱」功能的取消提示状态能在组件销毁后依然保持,建议将 hugTipDismissed 状态也加入到 store 中。这能确保用户在整个应用中的体验一致性。

Suggested change
/** 是否已显示过抱一抱提示 */
showedCommentHugTip: boolean;
/** 是否已显示过抱一抱提示 */
showedCommentHugTip: boolean;
/** 是否已提示过“不再提示”选项 */
hugTipDismissed: boolean;

/** 分享链接格式 */
shareUrlFormat: "web" | "mobile";
/** 启动时检查更新 */
Expand Down Expand Up @@ -500,6 +504,8 @@ export const useSettingStore = defineStore("setting", {
routeAnimation: "slide",
playerExpandAnimation: "up",
useOnlineService: true,
enableCommentHug: true,
showedCommentHugTip: false,
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

请在这里初始化新的 hugTipDismissed 状态。

Suggested change
showedCommentHugTip: false,
showedCommentHugTip: false,
hugTipDismissed: false,

shareUrlFormat: "web",
showCloseAppTip: true,
closeAppMethod: "hide",
Expand Down