1+ import { Color, HPRichTextV2, type NodeInfo, RichTextOptionModelV2 } from '@ohasasugar/hp-richtext';
2+ import { imgUrl } from '../constant';
3+
4+ @Entry
5+ @Component
6+ struct Index {
7+ richTextModel: RichTextOptionModelV2 = new RichTextOptionModelV2();
8+
9+ aboutToAppear() {
10+ this.richTextModel.richTextOption = {
11+ content: `
12+ <h1>h1标签</h1>
13+ <h2>h2标签</h2>
14+ <h3>h3标签</h3>
15+ <h4>h4标签</h4>
16+ <h5>h5标签</h5>
17+ <h6>h6标签</h6>
18+ <div>div标签</div>
19+ <p>p标签</p>
20+ <div>
21+ <font color="red" size="60px">font标签</font>
22+ <strong>strong标签</strong>
23+ <b>b标签</b>
24+ <i>i标签</i>
25+ <u>u标签</u>
26+ <s>s标签</s>
27+ <strike>strike标签</strike>
28+ <del>del标签</del>
29+ <big>big标签</big>
30+ <small>small标签</small>
31+ <a href="http://www.baidu.com">a标签</a>
32+ <span>带换行符号或者空格符号的文本:
33+ 【0乳糖,特添优质冷榨生椰浆】使用IIAC大赛金奖咖啡豆,现萃香醇Espresso,遇见鲜椰冷榨生椰浆,椰香浓郁,香甜清爽,带给你不一样的拿铁体验!\r\n\r\n主要原料:浓缩咖啡、冷冻椰浆/椰浆饮品、原味调味糖浆\r\n\r\n图片及包装仅供参考,请以实物为准。\r\n尽快享用风味更佳哦~
34+ </span>
35+ </div>
36+ <input style="color:red" placeholder="请输入..." type="number" maxlength="2" value="我是input标签"/>
37+ <textarea rows="10" cols="30">
38+ 我是一个文本框
39+ </textarea>
40+ <p style="margin: 10px;border: 5px solid #000;">带实线边框样式的</p>
41+ <p style="margin: 10px;border: 5px dashed #000;">带虚线边框样式的</p>
42+ <p style="margin: 10px;border: 5px dotted #000;">带点状边框样式的</p>
43+ <h1 style="overflow: hidden;text-overflow:ellipsis;white-space: nowrap;">单行文本显示省略号单行文本显示省略号单行文本显示省略号单行文本显示省略号</h1>
44+ <h1 style="-webkit-line-clamp: 2;overflow: hidden;text-overflow:ellipsis;white-space: nowrap;">多行文本显示省略号多行文本显示省略号多行文本显示省略号多行文本显示省略号多行文本显示省略号</h1>
45+ <img width="500px" src="${imgUrl}" />
46+ <img width="500px" resource="1" src="app.media.icon" />
47+ <video height="500px" loop muted autoplay src="https://www.w3school.com.cn/i/video/shanghai.mp4" />
48+ `,
49+ imageProp: {
50+ webp: true,
51+ copyEnable: true
52+ },
53+ customHandler: {
54+ start: (node: NodeInfo) => {
55+ },
56+ end: (node: NodeInfo) => {
57+ if (node.tag === 'a' && node.artUIStyleObject) {
58+ node.artUIStyleObject.fontColor = Color.Red;
59+ node.artUIStyleObject.decoration = {
60+ type: 0,
61+ }
62+ }
63+ },
64+ chars: null,
65+ }
66+ }
67+ this.richTextModel.needScroll = true;
68+ this.richTextModel.onLinkPress = (e) => {
69+ return e;
70+ };
71+ // 增加复制功能
72+ this.richTextModel.copyEnable = true;
73+ this.richTextModel.onCopyPress = (e) => {
74+ console.log('复制的内容', e.text)
75+ }
76+ }
77+
78+ build() {
79+ Column() {
80+ Button('改变数据').onClick(() => {
81+ this.richTextModel.richTextOption = {
82+ baseFontSize: 50,
83+ baseFontColor: '#ecd88d',
84+ content: '我是改变之后的数据,如通过ajax请求返回的数据'
85+ }
86+ })
87+ HPRichTextV2({
88+ richTextModel: this.richTextModel,
89+
90+ })
91+ }
92+ }
93+ }
0 commit comments