添加不再提醒功能.

This commit is contained in:
lijiahang
2023-10-08 18:42:06 +08:00
parent 66b2539630
commit 7a26e6f89c
15 changed files with 232 additions and 5 deletions

View File

@@ -0,0 +1,8 @@
import axios from 'axios';
/**
* 修改为已提示
*/
export function setTipsTipped(key: string) {
return axios.put('/infra/tips/tipped', null, { params: { key } });
}

View File

@@ -0,0 +1 @@
export const preferenceTipsKey = 'home:preference';

View File

@@ -183,7 +183,7 @@
<script lang="ts" setup>
import { computed, inject, ref } from 'vue';
import { useDark, useFullscreen, useToggle } from '@vueuse/core';
import { useAppStore, useUserStore } from '@/store';
import { useAppStore, useTipsStore, useUserStore } from '@/store';
import { LOCALE_OPTIONS } from '@/locale';
import useLocale from '@/hooks/locale';
import useUser from '@/hooks/user';
@@ -191,9 +191,10 @@
import Menu from '@/components/menu/tree/index.vue';
import MessageBox from '../message-box/index.vue';
import { openGlobalSettingKey, toggleDrawerMenuKey } from '@/types/symbol';
import { preferenceTipsKey } from './const';
// TODO 默认值
const tippedPreference = ref(true);
const tipsStore = useTipsStore();
const tippedPreference = ref(tipsStore.isNotTipped(preferenceTipsKey));
const appStore = useAppStore();
const userStore = useUserStore();
const { logout } = useUser();
@@ -256,7 +257,7 @@
const closePreferenceTip = (ack: boolean) => {
tippedPreference.value = false;
if (ack) {
// TODO 修改
tipsStore.setTipped(preferenceTipsKey);
}
};

View File

@@ -4,6 +4,7 @@ import useMenuStore from './modules/menu';
import useUserStore from './modules/user';
import useTabBarStore from './modules/tab-bar';
import useCacheStore from './modules/cache';
import useTipsStore from './modules/tips';
const pinia = createPinia();
@@ -13,6 +14,7 @@ export {
useUserStore,
useTabBarStore,
useCacheStore,
useTipsStore,
};
export default pinia;

View File

@@ -0,0 +1,28 @@
import { defineStore } from 'pinia';
import { TipsState } from './types';
import { setTipsTipped } from '@/api/user/tips';
export default defineStore('tips', {
state: (): TipsState => ({
tippedKeys: []
}),
actions: {
set(keys: Array<string>) {
this.tippedKeys = keys;
},
isTipped(key: string): boolean {
return this.tippedKeys.includes(key);
},
isNotTipped(key: string): boolean {
return !this.tippedKeys.includes(key);
},
async setTipped(key: string) {
try {
await setTipsTipped(key);
this.tippedKeys.push(key);
} catch (e) {
}
}
},
});

View File

@@ -0,0 +1,3 @@
export interface TipsState {
tippedKeys: Array<string>;
}

View File

@@ -4,7 +4,7 @@ import { clearToken, setToken } from '@/utils/auth';
import { md5 } from '@/utils';
import { removeRouteListener } from '@/utils/route-listener';
import { UserState } from './types';
import { useAppStore, useMenuStore, useTabBarStore } from '@/store';
import { useAppStore, useMenuStore, useTabBarStore, useTipsStore } from '@/store';
export default defineStore('user', {
state: (): UserState => ({
@@ -43,6 +43,9 @@ export default defineStore('user', {
// 设置用户偏好
const appStore = useAppStore();
appStore.updateSettings(data.user.systemPreference);
// 设置已经提示的key
const tipsStore = useTipsStore();
tipsStore.set(data.user.tippedKeys);
},
// 登录