mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-09-10 20:57:14 +08:00
refactor: 优化枚举字典处理,增加颜色类型
1.重构 useDict 方法,同时支持枚举和查询字典,对应后端接口增加缓存处理 2.优化 BaseEnum 处理,增加 color 字段可用于设置对应枚举背景颜色(同字典背景颜色)
This commit is contained in:
@@ -30,12 +30,21 @@ import com.baomidou.mybatisplus.annotation.IEnum;
|
||||
* @author Charles7c
|
||||
* @since 2023/2/5 20:44
|
||||
*/
|
||||
public interface BaseEnum<V extends Serializable, D extends Serializable> extends IEnum<V> {
|
||||
public interface BaseEnum<V extends Serializable> extends IEnum<V> {
|
||||
|
||||
/**
|
||||
* 枚举描述
|
||||
*
|
||||
* @return 枚举描述
|
||||
*/
|
||||
D getDescription();
|
||||
String getDescription();
|
||||
|
||||
/**
|
||||
* 颜色
|
||||
*
|
||||
* @return 颜色
|
||||
*/
|
||||
default String getColor() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@@ -35,7 +35,7 @@ import top.charles7c.cnadmin.common.constant.StringConsts;
|
||||
* @author Charles7c
|
||||
* @since 2023/2/5 19:29
|
||||
*/
|
||||
public class ExcelBaseEnumConverter implements Converter<BaseEnum<Integer, String>> {
|
||||
public class ExcelBaseEnumConverter implements Converter<BaseEnum<Integer>> {
|
||||
|
||||
@Override
|
||||
public Class<BaseEnum> supportJavaTypeKey() {
|
||||
@@ -60,8 +60,8 @@ public class ExcelBaseEnumConverter implements Converter<BaseEnum<Integer, Strin
|
||||
* 转换为 Excel 数据(写入 Excel)
|
||||
*/
|
||||
@Override
|
||||
public WriteCellData<String> convertToExcelData(BaseEnum<Integer, String> value,
|
||||
ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
|
||||
public WriteCellData<String> convertToExcelData(BaseEnum<Integer> value, ExcelContentProperty contentProperty,
|
||||
GlobalConfiguration globalConfiguration) {
|
||||
if (null == value) {
|
||||
return new WriteCellData<>(StringConsts.EMPTY);
|
||||
}
|
||||
@@ -77,11 +77,11 @@ public class ExcelBaseEnumConverter implements Converter<BaseEnum<Integer, Strin
|
||||
* 描述
|
||||
* @return 对应枚举 ,获取不到时为 {@code null}
|
||||
*/
|
||||
private BaseEnum<Integer, String> getEnum(Class<?> enumType, String description) {
|
||||
private BaseEnum<Integer> getEnum(Class<?> enumType, String description) {
|
||||
Object[] enumConstants = enumType.getEnumConstants();
|
||||
for (Object enumConstant : enumConstants) {
|
||||
if (ClassUtil.isAssignable(BaseEnum.class, enumType)) {
|
||||
BaseEnum<Integer, String> baseEnum = (BaseEnum<Integer, String>)enumConstant;
|
||||
BaseEnum<Integer> baseEnum = (BaseEnum<Integer>)enumConstant;
|
||||
if (baseEnum.getDescription().equals(description)) {
|
||||
return baseEnum;
|
||||
}
|
||||
|
@@ -53,6 +53,11 @@ public class CacheConsts {
|
||||
*/
|
||||
public static final String MENU_KEY_PREFIX = "MENU";
|
||||
|
||||
/**
|
||||
* 字典缓存键前缀
|
||||
*/
|
||||
public static final String DICT_KEY_PREFIX = "DICT";
|
||||
|
||||
/**
|
||||
* 仪表盘缓存键前缀
|
||||
*/
|
||||
|
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.charles7c.cnadmin.common.constant;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* UI 相关常量
|
||||
*
|
||||
* @author Charles7c
|
||||
* @since 2023/9/17 14:12
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class UIConsts {
|
||||
|
||||
/**
|
||||
* 主色(极致蓝)
|
||||
*/
|
||||
public static final String COLOR_PRIMARY = "arcoblue";
|
||||
|
||||
/**
|
||||
* 成功色(仙野绿)
|
||||
*/
|
||||
public static final String COLOR_SUCCESS = "green";
|
||||
|
||||
/**
|
||||
* 警告色(活力橙)
|
||||
*/
|
||||
public static final String COLOR_WARNING = "orangered";
|
||||
|
||||
/**
|
||||
* 错误色(浪漫红)
|
||||
*/
|
||||
public static final String COLOR_ERROR = "red";
|
||||
|
||||
/**
|
||||
* 默认色(中性灰)
|
||||
*/
|
||||
public static final String COLOR_DEFAULT = "gray";
|
||||
}
|
@@ -29,7 +29,7 @@ import top.charles7c.cnadmin.common.base.BaseEnum;
|
||||
*/
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public enum DataScopeEnum implements BaseEnum<Integer, String> {
|
||||
public enum DataScopeEnum implements BaseEnum<Integer> {
|
||||
|
||||
/** 全部数据权限 */
|
||||
ALL(1, "全部数据权限"),
|
||||
@@ -43,8 +43,8 @@ public enum DataScopeEnum implements BaseEnum<Integer, String> {
|
||||
/** 仅本人数据权限 */
|
||||
SELF(4, "仅本人数据权限"),
|
||||
|
||||
/** 自定数据权限 */
|
||||
CUSTOM(5, "自定数据权限"),;
|
||||
/** 自定义数据权限 */
|
||||
CUSTOM(5, "自定义数据权限"),;
|
||||
|
||||
private final Integer value;
|
||||
private final String description;
|
||||
|
@@ -20,6 +20,7 @@ import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import top.charles7c.cnadmin.common.base.BaseEnum;
|
||||
import top.charles7c.cnadmin.common.constant.UIConsts;
|
||||
|
||||
/**
|
||||
* 数据类型枚举
|
||||
@@ -29,14 +30,15 @@ import top.charles7c.cnadmin.common.base.BaseEnum;
|
||||
*/
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public enum DataTypeEnum implements BaseEnum<Integer, String> {
|
||||
public enum DataTypeEnum implements BaseEnum<Integer> {
|
||||
|
||||
/** 系统内置 */
|
||||
SYSTEM(1, "系统内置"),
|
||||
SYSTEM(1, "系统内置", UIConsts.COLOR_ERROR),
|
||||
|
||||
/** 自定义 */
|
||||
CUSTOM(2, "自定义"),;
|
||||
CUSTOM(2, "自定义", UIConsts.COLOR_PRIMARY),;
|
||||
|
||||
private final Integer value;
|
||||
private final String description;
|
||||
private final String color;
|
||||
}
|
||||
|
@@ -29,7 +29,7 @@ import top.charles7c.cnadmin.common.base.BaseEnum;
|
||||
*/
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public enum DisEnableStatusEnum implements BaseEnum<Integer, String> {
|
||||
public enum DisEnableStatusEnum implements BaseEnum<Integer> {
|
||||
|
||||
/** 启用 */
|
||||
ENABLE(1, "启用"),
|
||||
|
@@ -29,7 +29,7 @@ import top.charles7c.cnadmin.common.base.BaseEnum;
|
||||
*/
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public enum GenderEnum implements BaseEnum<Integer, String> {
|
||||
public enum GenderEnum implements BaseEnum<Integer> {
|
||||
|
||||
/** 未知 */
|
||||
UNKNOWN(0, "未知"),
|
||||
|
@@ -29,7 +29,7 @@ import top.charles7c.cnadmin.common.base.BaseEnum;
|
||||
*/
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public enum MenuTypeEnum implements BaseEnum<Integer, String> {
|
||||
public enum MenuTypeEnum implements BaseEnum<Integer> {
|
||||
|
||||
/** 目录 */
|
||||
DIR(1, "目录"),
|
||||
|
@@ -29,7 +29,7 @@ import top.charles7c.cnadmin.common.base.BaseEnum;
|
||||
*/
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public enum QueryTypeEnum implements BaseEnum<Integer, String> {
|
||||
public enum QueryTypeEnum implements BaseEnum<Integer> {
|
||||
|
||||
/**
|
||||
* 等值查询,例如:WHERE `age` = 18
|
||||
|
@@ -20,6 +20,7 @@ import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import top.charles7c.cnadmin.common.base.BaseEnum;
|
||||
import top.charles7c.cnadmin.common.constant.UIConsts;
|
||||
|
||||
/**
|
||||
* 成功/失败状态枚举
|
||||
@@ -29,14 +30,15 @@ import top.charles7c.cnadmin.common.base.BaseEnum;
|
||||
*/
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public enum SuccessFailureStatusEnum implements BaseEnum<Integer, String> {
|
||||
public enum SuccessFailureStatusEnum implements BaseEnum<Integer> {
|
||||
|
||||
/** 成功 */
|
||||
SUCCESS(1, "成功"),
|
||||
SUCCESS(1, "成功", UIConsts.COLOR_SUCCESS),
|
||||
|
||||
/** 失败 */
|
||||
FAILURE(2, "失败"),;
|
||||
FAILURE(2, "失败", UIConsts.COLOR_ERROR),;
|
||||
|
||||
private final Integer value;
|
||||
private final String description;
|
||||
private final String color;
|
||||
}
|
||||
|
Reference in New Issue
Block a user