当前位置: 首页 > news >正文

ant-design 自定义选择框

效果图:
在这里插入图片描述

  useEffect(() => {getSelectBgColor();}, []);{title: '资产状态',dataIndex: 'elementStatus',align: 'center',editable: false,width: 120,renderFormItem: () => (<Selectplaceholder="请选择"defaultValue={queryElementStatus}mode="multiple"onDeselect={deleteSelect}tagRender={tagRender}>{statusSelectInfo.map((item) => (<Select.Option key={item.remark} value={item.status}>{item.remark}<divstyle={{height: '10px',width: '10px',borderRadius: '3px',marginRight: '8px',background: item.color[0],}}/></Select.Option>))}</Select>),render: (_, record) => renderElementStatusTag1(record.elementStatus),},function getSelectBgColor() {const statusObj = JSON.parse(localStorage.getItem('assetsStatus')) || {1: {remark: '未知',longRemark: '资产不属于预设的几种情况之一',},//其他的略};let statusList = convertToObjectArray(statusObj, colorObj);setStatusSelectInfo(statusList);}function convertToObjectArray(params) {if (!params) {console.log('params is undefined or null');return []; // 如果 params 是 undefined 或 null,返回空数组}const result = [];// 使用 Object.keys 来遍历 params 的键Object.keys(params).forEach((key) => {const status = parseInt(key, 10); // 将字符串键转换为整数const color = colorObj[status].split(',') || 'default'; // 尝试从 colorObj 中获取颜色,如果失败则使用默认值const { remark, longRemark } = params[key]; // 解构出 remark 和 longRemark// 将这些信息添加到结果数组中result.push({ status, color, remark, longRemark });});return result;}function removeElementStatus(arr, value) {const index = arr.indexOf(value);if (index !== -1) {arr.splice(index, 1);}}// 在筛选区域中,删除资产类型多选某一选项const deleteSelect = (str) => {let localStatus = getLocalItem('initQueryStatus');if (localStatus && localStatus?.length && localStatus?.includes(str)) {removeElementStatus(localStatus, str);setLocalItem('initQueryStatus', localStatus);}};const tagRender = (props) => {const { label, value, closable, onClose } = props;const onPreventMouseDown = (event) => {event.preventDefault();event.stopPropagation();};let item = {};if (queryElementStatus?.length) {item.color = colorObj[value].split(',');} else {item = statusSelectInfo.find((e) => e.status === value);}return (<Tagstyle={{marginInlineEnd: 4,color: item.color[0],background: item.color[1],borderColor: item.color[2],}}onMouseDown={onPreventMouseDown}closable={closable}onClose={onClose}>{label[0]}</Tag>);};const colorObj = {1: '#d46b08,#fff7e6,#ffd591', //黄色2: '#34C759,#f2ffe9,#33c97a', //绿色3: '#d46b08,#fff7e6,#ffd591',4: '#FF3B30,#fff1f0,#ffa39e', //红色5: '#ff5100,#fff2c9,#ffd857', //紫色6: '#8E8E93,#f4f4f5,#c8c9cc', //灰色7: '#8E8E93,#f4f4f5,#c8c9cc',8: '#ff5100,#fff2c9,#ffd857',10: '#409EFF,#ecf5ff,#a0cfff', //蓝色11: '#8E8E93,#f4f4f5,#c8c9cc',12: '#409EFF,#ecf5ff,#a0cfff',13: '#ff5100,#fff2c9,#ffd857',14: '#8E8E93,#f4f4f5,#c8c9cc',15: '#ff5100,#fff2c9,#ffd857',
};

http://www.mrgr.cn/news/10037.html

相关文章:

  • APACHE NIFI学习之—编码解码功能
  • 2025届八股文:计算机网络高频重点面试题
  • 在CMD运行pip指令安装python的库时
  • 电商平台 API 接入的方式
  • CSRF简单介绍
  • kali 中文设置
  • Furion+SqlSugar环境配置与项目创建
  • BeanFactoryPostProcessor 和 BeanPostProcessor
  • Python开发中,SQLAlchemy 的同步操作和异步操作封装,以及常规CRUD的处理。
  • pikachu-Cross-Site Scripting通过攻略
  • 汉服文化平台网站
  • 微信小程序记录(持续更新)
  • C++ 设计模式——外观模式
  • 新手学习打怪之编译安装LAMP和LNMP
  • Linux 软件编程 数据库
  • 分布式搜索引擎 -- 搜索结果处理以及RestClient查询文档
  • 提高客服响应率的快捷回复软件
  • 将Web应用部署到Tomcat根目录的三种方法
  • 拿下英语翻译!这四款在线翻译功不可没!
  • 【Python游戏】Joystick游戏手柄编程介绍