添加不再提醒功能.
This commit is contained in:
@@ -3,6 +3,7 @@ package com.orion.ops.framework.redis.core.utils;
|
|||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.orion.lang.define.cache.CacheKeyDefine;
|
import com.orion.lang.define.cache.CacheKeyDefine;
|
||||||
import com.orion.lang.utils.collect.Lists;
|
import com.orion.lang.utils.collect.Lists;
|
||||||
|
import com.orion.ops.framework.common.constant.Const;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
@@ -107,6 +108,17 @@ public class RedisLists extends RedisUtils {
|
|||||||
redisTemplate.opsForList().rightPushAll(key, values);
|
redisTemplate.opsForList().rightPushAll(key, values);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* list 添加元素
|
||||||
|
*
|
||||||
|
* @param key key
|
||||||
|
* @param value value
|
||||||
|
* @param <T> T
|
||||||
|
*/
|
||||||
|
public static <T> void push(String key, String value) {
|
||||||
|
redisTemplate.opsForList().rightPush(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* list 添加元素
|
* list 添加元素
|
||||||
*
|
*
|
||||||
@@ -130,6 +142,18 @@ public class RedisLists extends RedisUtils {
|
|||||||
redisTemplate.opsForList().rightPush(key, JSON.toJSONString(value));
|
redisTemplate.opsForList().rightPush(key, JSON.toJSONString(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否包含某个值
|
||||||
|
*
|
||||||
|
* @param key key
|
||||||
|
* @param value value
|
||||||
|
* @return 是否包含
|
||||||
|
*/
|
||||||
|
public static boolean contains(String key, String value) {
|
||||||
|
Long index = redisTemplate.opsForList().indexOf(key, value);
|
||||||
|
return index != null && !Const.L_N_1.equals(index);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* list 删除元素
|
* list 删除元素
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
### 修改为已提示
|
||||||
|
PUT {{baseUrl}}/infra/tips/tipped?key=x
|
||||||
|
Authorization: {{token}}
|
||||||
|
|
||||||
|
|
||||||
|
### 获取所有已提示的 key
|
||||||
|
GET {{baseUrl}}/infra/tips/get
|
||||||
|
Authorization: {{token}}
|
||||||
|
|
||||||
|
|
||||||
|
###
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package com.orion.ops.module.infra.controller;
|
||||||
|
|
||||||
|
import com.orion.ops.framework.common.annotation.RestWrapper;
|
||||||
|
import com.orion.ops.module.infra.service.TipsService;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提示 api
|
||||||
|
*
|
||||||
|
* @author Jiahang Li
|
||||||
|
* @version 1.0.0
|
||||||
|
* @since 2023-10-8 17:52
|
||||||
|
*/
|
||||||
|
@Tag(name = "infra - 提示服务")
|
||||||
|
@Slf4j
|
||||||
|
@Validated
|
||||||
|
@RestWrapper
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/infra/tips")
|
||||||
|
@SuppressWarnings({"ELValidationInJSP", "SpringElInspection"})
|
||||||
|
public class TipsController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private TipsService tipsService;
|
||||||
|
|
||||||
|
@PutMapping("/tipped")
|
||||||
|
@Operation(summary = "修改为已提示")
|
||||||
|
@Parameter(name = "key", description = "key", required = true)
|
||||||
|
public boolean tipped(@RequestParam("key") String key) {
|
||||||
|
tipsService.tipped(key);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/get")
|
||||||
|
@Operation(summary = "获取所有已提示的 key")
|
||||||
|
public List<String> get() {
|
||||||
|
return tipsService.getTippedKeys();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package com.orion.ops.module.infra.define;
|
||||||
|
|
||||||
|
import com.orion.lang.define.cache.CacheKeyBuilder;
|
||||||
|
import com.orion.lang.define.cache.CacheKeyDefine;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* tips 服务缓存 key
|
||||||
|
*
|
||||||
|
* @author Jiahang Li
|
||||||
|
* @version 1.0.0
|
||||||
|
* @since 2023/10/8 17:58
|
||||||
|
*/
|
||||||
|
public interface TipsCacheKeyDefine {
|
||||||
|
|
||||||
|
CacheKeyDefine TIPS = new CacheKeyBuilder()
|
||||||
|
.key("user:tips:{}")
|
||||||
|
.desc("user:tips ${userId} 90天不会重复提示")
|
||||||
|
.type(String.class)
|
||||||
|
.timeout(90, TimeUnit.DAYS)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ import lombok.Builder;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -37,4 +38,7 @@ public class UserCollectInfoVO {
|
|||||||
@Schema(description = "系统偏好")
|
@Schema(description = "系统偏好")
|
||||||
private Map<String, Object> systemPreference;
|
private Map<String, Object> systemPreference;
|
||||||
|
|
||||||
|
@Schema(description = "已经提示的key")
|
||||||
|
private List<String> tippedKeys;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package com.orion.ops.module.infra.service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提示服务
|
||||||
|
*
|
||||||
|
* @author Jiahang Li
|
||||||
|
* @version 1.0.0
|
||||||
|
* @since 2023/10/8 17:53
|
||||||
|
*/
|
||||||
|
public interface TipsService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置为已提示
|
||||||
|
*
|
||||||
|
* @param tippedKey tippedKey
|
||||||
|
*/
|
||||||
|
void tipped(String tippedKey);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取所有已提示的 key
|
||||||
|
*
|
||||||
|
* @return keys
|
||||||
|
*/
|
||||||
|
List<String> getTippedKeys();
|
||||||
|
|
||||||
|
}
|
||||||
@@ -25,6 +25,7 @@ import com.orion.ops.module.infra.enums.RoleStatusEnum;
|
|||||||
import com.orion.ops.module.infra.service.PermissionService;
|
import com.orion.ops.module.infra.service.PermissionService;
|
||||||
import com.orion.ops.module.infra.service.PreferenceService;
|
import com.orion.ops.module.infra.service.PreferenceService;
|
||||||
import com.orion.ops.module.infra.service.SystemMenuService;
|
import com.orion.ops.module.infra.service.SystemMenuService;
|
||||||
|
import com.orion.ops.module.infra.service.TipsService;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -73,6 +74,9 @@ public class PermissionServiceImpl implements PermissionService {
|
|||||||
@Resource
|
@Resource
|
||||||
private PreferenceService preferenceService;
|
private PreferenceService preferenceService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private TipsService tipsService;
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
@Override
|
@Override
|
||||||
public void initPermissionCache() {
|
public void initPermissionCache() {
|
||||||
@@ -224,6 +228,8 @@ public class PermissionServiceImpl implements PermissionService {
|
|||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// 设置已提示的 key
|
||||||
|
user.setTippedKeys(tipsService.getTippedKeys());
|
||||||
// 获取异步结果
|
// 获取异步结果
|
||||||
user.setSystemPreference(systemPreference.get());
|
user.setSystemPreference(systemPreference.get());
|
||||||
// 组装数据
|
// 组装数据
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package com.orion.ops.module.infra.service.impl;
|
||||||
|
|
||||||
|
import com.orion.lang.utils.collect.Lists;
|
||||||
|
import com.orion.ops.framework.redis.core.utils.RedisLists;
|
||||||
|
import com.orion.ops.framework.security.core.utils.SecurityUtils;
|
||||||
|
import com.orion.ops.module.infra.define.TipsCacheKeyDefine;
|
||||||
|
import com.orion.ops.module.infra.service.TipsService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提示 服务实现类
|
||||||
|
*
|
||||||
|
* @author Jiahang Li
|
||||||
|
* @version 1.0.0
|
||||||
|
* @since 2023/10/8 17:57
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class TipsServiceImpl implements TipsService {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tipped(String tippedKey) {
|
||||||
|
Long userId = SecurityUtils.getLoginUserId();
|
||||||
|
String key = TipsCacheKeyDefine.TIPS.format(userId);
|
||||||
|
RedisLists.push(key, tippedKey);
|
||||||
|
RedisLists.setExpire(key, TipsCacheKeyDefine.TIPS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getTippedKeys() {
|
||||||
|
return Lists.def(RedisLists.range(TipsCacheKeyDefine.TIPS.format(SecurityUtils.getLoginUserId())));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
8
orion-ops-ui/src/api/user/tips.ts
Normal file
8
orion-ops-ui/src/api/user/tips.ts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改为已提示
|
||||||
|
*/
|
||||||
|
export function setTipsTipped(key: string) {
|
||||||
|
return axios.put('/infra/tips/tipped', null, { params: { key } });
|
||||||
|
}
|
||||||
1
orion-ops-ui/src/components/navbar/const.ts
Normal file
1
orion-ops-ui/src/components/navbar/const.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export const preferenceTipsKey = 'home:preference';
|
||||||
@@ -183,7 +183,7 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { computed, inject, ref } from 'vue';
|
import { computed, inject, ref } from 'vue';
|
||||||
import { useDark, useFullscreen, useToggle } from '@vueuse/core';
|
import { useDark, useFullscreen, useToggle } from '@vueuse/core';
|
||||||
import { useAppStore, useUserStore } from '@/store';
|
import { useAppStore, useTipsStore, useUserStore } from '@/store';
|
||||||
import { LOCALE_OPTIONS } from '@/locale';
|
import { LOCALE_OPTIONS } from '@/locale';
|
||||||
import useLocale from '@/hooks/locale';
|
import useLocale from '@/hooks/locale';
|
||||||
import useUser from '@/hooks/user';
|
import useUser from '@/hooks/user';
|
||||||
@@ -191,9 +191,10 @@
|
|||||||
import Menu from '@/components/menu/tree/index.vue';
|
import Menu from '@/components/menu/tree/index.vue';
|
||||||
import MessageBox from '../message-box/index.vue';
|
import MessageBox from '../message-box/index.vue';
|
||||||
import { openGlobalSettingKey, toggleDrawerMenuKey } from '@/types/symbol';
|
import { openGlobalSettingKey, toggleDrawerMenuKey } from '@/types/symbol';
|
||||||
|
import { preferenceTipsKey } from './const';
|
||||||
|
|
||||||
// TODO 默认值
|
const tipsStore = useTipsStore();
|
||||||
const tippedPreference = ref(true);
|
const tippedPreference = ref(tipsStore.isNotTipped(preferenceTipsKey));
|
||||||
const appStore = useAppStore();
|
const appStore = useAppStore();
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
const { logout } = useUser();
|
const { logout } = useUser();
|
||||||
@@ -256,7 +257,7 @@
|
|||||||
const closePreferenceTip = (ack: boolean) => {
|
const closePreferenceTip = (ack: boolean) => {
|
||||||
tippedPreference.value = false;
|
tippedPreference.value = false;
|
||||||
if (ack) {
|
if (ack) {
|
||||||
// TODO 修改
|
tipsStore.setTipped(preferenceTipsKey);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import useMenuStore from './modules/menu';
|
|||||||
import useUserStore from './modules/user';
|
import useUserStore from './modules/user';
|
||||||
import useTabBarStore from './modules/tab-bar';
|
import useTabBarStore from './modules/tab-bar';
|
||||||
import useCacheStore from './modules/cache';
|
import useCacheStore from './modules/cache';
|
||||||
|
import useTipsStore from './modules/tips';
|
||||||
|
|
||||||
const pinia = createPinia();
|
const pinia = createPinia();
|
||||||
|
|
||||||
@@ -13,6 +14,7 @@ export {
|
|||||||
useUserStore,
|
useUserStore,
|
||||||
useTabBarStore,
|
useTabBarStore,
|
||||||
useCacheStore,
|
useCacheStore,
|
||||||
|
useTipsStore,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default pinia;
|
export default pinia;
|
||||||
|
|||||||
28
orion-ops-ui/src/store/modules/tips/index.ts
Normal file
28
orion-ops-ui/src/store/modules/tips/index.ts
Normal 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) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
3
orion-ops-ui/src/store/modules/tips/types.ts
Normal file
3
orion-ops-ui/src/store/modules/tips/types.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
export interface TipsState {
|
||||||
|
tippedKeys: Array<string>;
|
||||||
|
}
|
||||||
@@ -4,7 +4,7 @@ import { clearToken, setToken } from '@/utils/auth';
|
|||||||
import { md5 } from '@/utils';
|
import { md5 } from '@/utils';
|
||||||
import { removeRouteListener } from '@/utils/route-listener';
|
import { removeRouteListener } from '@/utils/route-listener';
|
||||||
import { UserState } from './types';
|
import { UserState } from './types';
|
||||||
import { useAppStore, useMenuStore, useTabBarStore } from '@/store';
|
import { useAppStore, useMenuStore, useTabBarStore, useTipsStore } from '@/store';
|
||||||
|
|
||||||
export default defineStore('user', {
|
export default defineStore('user', {
|
||||||
state: (): UserState => ({
|
state: (): UserState => ({
|
||||||
@@ -43,6 +43,9 @@ export default defineStore('user', {
|
|||||||
// 设置用户偏好
|
// 设置用户偏好
|
||||||
const appStore = useAppStore();
|
const appStore = useAppStore();
|
||||||
appStore.updateSettings(data.user.systemPreference);
|
appStore.updateSettings(data.user.systemPreference);
|
||||||
|
// 设置已经提示的key
|
||||||
|
const tipsStore = useTipsStore();
|
||||||
|
tipsStore.set(data.user.tippedKeys);
|
||||||
},
|
},
|
||||||
|
|
||||||
// 登录
|
// 登录
|
||||||
|
|||||||
Reference in New Issue
Block a user