zhuguifei
2025-04-28 442928123f63ee497d766f9a7a14f0a6ee067e25
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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("(&nbsp;)+", "&nbsp;");
            // 反向转义字符
            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];
    }
 
}