package org.jeecg.common.util; import org.apache.commons.lang3.StringUtils; import org.springframework.web.util.HtmlUtils; import java.util.Random; /** * HTML 工具类 */ public class HTMLUtils { /** * 获取HTML内的文本,不包含标签 * * @param html HTML 代码 */ public static String getInnerText(String html) { if (StringUtils.isNotBlank(html)) { //去掉 html 的标签 String content = html.replaceAll("]+>", ""); // 将多个空格合并成一个空格 content = content.replaceAll("( )+", " "); // 反向转义字符 content = HtmlUtils.htmlUnescape(content); return content.trim(); } return ""; } /** * 获取十六进制的颜色代码.例如 "#6E36B4" , For HTML , * * @return String */ public static String getRandColorCode() { String r, g, b; Random random = new Random(); r = Integer.toHexString(random.nextInt(256)).toUpperCase(); g = Integer.toHexString(random.nextInt(256)).toUpperCase(); b = Integer.toHexString(random.nextInt(256)).toUpperCase(); r = r.length() == 1 ? "0" + r : r; g = g.length() == 1 ? "0" + g : g; b = b.length() == 1 ? "0" + b : b; return "#" + r + g + b; } /** * @param index * @return */ public static String getColor(int index) { String colors[] = {"#1890ff", "#05aa87", "#EF5362", "#FE6D4B", "#FFCF47", "#9FD661", "#3FD0AD", "#AC8FEF", "#EE85C1", "#31BDF3"}; if (index >= colors.length) index = index % 10; return colors[index]; } }