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

深圳做app网站建设下载优化大师

深圳做app网站建设,下载优化大师,WordPress禁用Gutenberg,discuz 科技网站模板下载【引言】 本文将通过一个具体的案例——“字数统计”组件,来探讨如何在鸿蒙NEXT框架下实现这一功能。此组件不仅能够统计用户输入文本中的汉字、中文标点、数字、以及英文字符的数量,还具有良好的用户界面设计,使用户能够直观地了解输入文本…

【引言】

本文将通过一个具体的案例——“字数统计”组件,来探讨如何在鸿蒙NEXT框架下实现这一功能。此组件不仅能够统计用户输入文本中的汉字、中文标点、数字、以及英文字符的数量,还具有良好的用户界面设计,使用户能够直观地了解输入文本的各种统计数据。

【环境准备】

• 操作系统:Windows 10

• 开发工具:DevEco Studio NEXT Beta1 Build Version: 5.0.3.806

• 目标设备:华为Mate60 Pro

• 开发语言:ArkTS

• 框架:ArkUI

• API版本:API 12

【组件概述】

“字数统计”组件基于鸿蒙NEXT框架构建,旨在提供一个简洁而强大的文本统计工具。组件的主要功能包括:

• 文本输入:用户可以在提供的文本区域内输入或粘贴任何文本。

• 实时统计:当用户输入或修改文本时,组件会实时更新并显示文本中汉字、中文标点、数字、英文字符等的具体数量。

• 示例与清空:提供了“示例”按钮,点击后会自动填充预设的文本内容;“清空”按钮则用于清空当前的输入内容。

【技术实现】

1. 状态管理:使用@State装饰器来管理组件的状态,如输入文本、各种字符的数量统计等。通过@Watch装饰器监听输入文本的变化,触发相应的计算逻辑。

2. 文本解析:当检测到输入文本发生变化时,组件会遍历文本中的每一个字符,根据正则表达式判断字符类型,并分别统计汉字、中文标点、数字、英文字符的数量。特别地,对于汉字和中文标点,每个字符被视为两个单位进行统计。

3. 用户界面:组件的UI设计遵循了鸿蒙NEXT的设计规范,使用了Column、Row、Text、TextArea等基础组件来构建布局。通过设置字体颜色、大小、背景色、边距等属性,实现了美观且易于使用的界面。此外,组件还利用了阴影效果和圆角设计来提升视觉体验。

4. 交互设计:为了增强用户体验,组件中加入了“示例”和“清空”按钮,用户可以通过简单的点击操作快速测试组件的功能或清空输入框。同时,组件支持文本输入区域的实时更新,保证了用户操作的即时反馈。

【完整代码】

// 定义一个组件,用于数字和文本统计
@Entry
@Component
struct NumberToChineseConverter {// 定义一个状态变量,存储示例数字字符串@State private exampleNumber: string = '自从盘古破鸿蒙,开辟从兹清浊辨。\nare you ok?\n1234\n+-*/';// 定义文本颜色的状态变量@State private textColor: string = "#2e2e2e";// 定义阴影边框颜色的状态变量@State private shadowColor: string = "#d5d5d5";// 定义基础内边距的状态变量@State private basePadding: number = 30;// 定义汉字数量的状态变量@State private chineseCharCount: string = "0";// 定义中文标点数量的状态变量@State private chinesePunctuationCount: string = "0";// 定义汉字加中文标点总数的状态变量@State private totalChineseCount: string = "0";// 定义英文字符数量的状态变量@State private englishCharCount: string = "0";// 定义数字数量的状态变量@State private digitCount: string = "0";// 定义总字符数的状态变量@State private charTotalCount: string = "0";// 定义监听输入文本变化的状态变量@State @Watch('inputChanged') private inputText: string = "";// 当输入文本发生变化时调用的方法inputChanged() {// 初始化计数器let chineseChars = 0; // 汉字数量let chinesePunctuation = 0; // 中文标点数量let englishChars = 0; // 英文字符数量let digits = 0; // 数字数量let count = 0; // 总字符数// 遍历输入文本的每个字符for (let i = 0; i < this.inputText.length; i++) {let char = this.inputText.charAt(i); // 获取当前字符count++; // 计数器加一// 如果字符是数字,则数字计数器加一if (/\d/.test(char)) {digits++;}// 如果字符是汉字,则汉字计数器加一,同时总字符数加二if (/[\u4e00-\u9fa5]/.test(char)) {chineseChars++;count++; // 汉字和中文标点算两个字符,所以这里多+1}// 如果字符是中文标点,则中文标点计数器加一,同时总字符数加二if (/[\u3001-\u3002\uff01-\uff1a]/.test(char)) {chinesePunctuation++;count++; // 汉字和中文标点算两个字符,所以这里多+1}// 如果字符是英文字符或英文标点,则英文字符计数器加一if (/[a-zA-Z0-9\s!-/:-@[-`{-~]/.test(char)) {englishChars++;}}// 更新状态变量this.chineseCharCount = `${chineseChars}`;this.chinesePunctuationCount = `${chinesePunctuation}`;this.totalChineseCount = `${chineseChars + chinesePunctuation}`;this.englishCharCount = `${englishChars}`;this.digitCount = `${digits}`;this.charTotalCount = `${count}`;}// 构建UI界面的方法build() {// 创建一个列布局容器Column() {// 添加标题Text('字数统计').fontColor(this.textColor) // 设置字体颜色.fontSize(18) // 设置字体大小.width('100%') // 设置宽度为100%.height(50) // 设置高度为50.textAlign(TextAlign.Center) // 设置文本居中对齐.backgroundColor(Color.White) // 设置背景色为白色.shadow({ // 设置阴影效果radius: 2, // 阴影半径color: this.shadowColor, // 阴影颜色offsetX: 0, // X轴偏移量offsetY: 5 // Y轴偏移量});// 创建可滚动的容器Scroll() {// 在可滚动容器内部创建列布局Column() {// 添加工具介绍Column() {Text('工具介绍').fontSize(18).fontWeight(600).fontColor(this.textColor);Text('本工具能够快速统计输入文本中的汉字、中文标点、数字、英文字符等的数量。具体规则如下:\n•汉字和中文标点各算作两个字符。\n•数字、空格、英文字母及英文标点各算作一个字符。').textAlign(TextAlign.JUSTIFY) // 设置文本两端对齐.fontSize(13) // 设置字体大小.fontColor(this.textColor) // 设置字体颜色.margin({ top: `${this.basePadding / 2}lpx` }); // 设置上边距}// 设置样式.alignItems(HorizontalAlign.Start) // 设置水平对齐方式.width('650lpx') // 设置宽度.padding(`${this.basePadding}lpx`) // 设置内边距.margin({ top: `${this.basePadding}lpx` }) // 设置外边距.borderRadius(10) // 设置圆角.backgroundColor(Color.White) // 设置背景色.shadow({ // 设置阴影效果radius: 10, // 阴影半径color: this.shadowColor, // 阴影颜色offsetX: 0, // X轴偏移量offsetY: 0 // Y轴偏移量});// 添加示例和清空按钮Column() {Row() {Text('示例').fontColor("#5871ce") // 设置字体颜色.fontSize(16) // 设置字体大小.padding(`${this.basePadding / 2}lpx`) // 设置内边距.backgroundColor("#f2f1fd") // 设置背景色.borderRadius(5) // 设置圆角.clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.8 }) // 设置点击效果.onClick(() => { // 设置点击事件this.inputText = this.exampleNumber; // 将示例文本赋值给输入框});Blank(); // 添加空白间隔Text('清空').fontColor("#e48742") // 设置字体颜色.fontSize(16) // 设置字体大小.padding(`${this.basePadding / 2}lpx`) // 设置内边距.clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.8 }) // 设置点击效果.backgroundColor("#ffefe6") // 设置背景色.borderRadius(5) // 设置圆角.onClick(() => { // 设置点击事件this.inputText = ""; // 清空输入框});}.height(45) // 设置高度.justifyContent(FlexAlign.SpaceBetween) // 设置子项之间间距均匀分布.width('100%'); // 设置宽度Divider(); // 添加分割线// 添加文本输入区域TextArea({ text: $$this.inputText, placeholder: `请输入内容` }).width(`${650 - this.basePadding * 2}lpx`) // 设置宽度.height(100) // 设置高度.fontSize(16) // 设置字体大小.caretColor(this.textColor) // 设置光标颜色.fontColor(this.textColor) // 设置字体颜色.margin({ top: `${this.basePadding}lpx` }) // 设置上边距.padding(0) // 设置内边距.backgroundColor(Color.Transparent) // 设置背景色.borderRadius(0) // 设置圆角.textAlign(TextAlign.JUSTIFY); // 设置文本两端对齐}// 设置样式.alignItems(HorizontalAlign.Start) // 设置水平对齐方式.width('650lpx') // 设置宽度.padding(`${this.basePadding}lpx`) // 设置内边距.margin({ top: `${this.basePadding}lpx` }) // 设置外边距.borderRadius(10) // 设置圆角.backgroundColor(Color.White) // 设置背景色.shadow({ // 设置阴影效果radius: 10, // 阴影半径color: this.shadowColor, // 阴影颜色offsetX: 0, // X轴偏移量offsetY: 0 // Y轴偏移量});// 添加统计结果展示Column() {// 汉字数量Row() {Text() {Span(`汉字:`)Span(`${this.chineseCharCount} `).fontColor(Color.Red) // 汉字数量以红色显示Span('个')}.fontColor(this.textColor) // 设置字体颜色.fontSize(16) // 设置字体大小.layoutWeight(1); // 设置布局权重}.constraintSize({ minHeight: 45 }) // 设置最小高度.justifyContent(FlexAlign.SpaceBetween) // 设置子项之间间距均匀分布.width('100%'); // 设置宽度Divider(); // 添加分割线// 中文标点数量Row() {Text() {Span(`中文标点:`)Span(`${this.chinesePunctuationCount} `).fontColor(Color.Red) // 中文标点数量以红色显示Span('个')}.fontColor(this.textColor) // 设置字体颜色.fontSize(16) // 设置字体大小.layoutWeight(1); // 设置布局权重}.constraintSize({ minHeight: 45 }) // 设置最小高度.justifyContent(FlexAlign.SpaceBetween) // 设置子项之间间距均匀分布.width('100%'); // 设置宽度Divider(); // 添加分割线// 汉字加中文标点总数Row() {Text() {Span(`汉字+中文标点:`)Span(`${this.totalChineseCount} `).fontColor(Color.Red) // 汉字加中文标点总数以红色显示Span('个')}.fontColor(this.textColor) // 设置字体颜色.fontSize(16) // 设置字体大小.layoutWeight(1); // 设置布局权重}.constraintSize({ minHeight: 45 }) // 设置最小高度.justifyContent(FlexAlign.SpaceBetween) // 设置子项之间间距均匀分布.width('100%'); // 设置宽度Divider(); // 添加分割线// 英文字符数量Row() {Text() {Span(`英文:`)Span(`${this.englishCharCount} `).fontColor(Color.Red) // 英文字符数量以红色显示Span('个')Span('(含英文状态下的数字、符号、标点)').fontSize(13) // 附加说明}.fontColor(this.textColor) // 设置字体颜色.fontSize(16) // 设置字体大小.layoutWeight(1); // 设置布局权重}.constraintSize({ minHeight: 45 }) // 设置最小高度.justifyContent(FlexAlign.SpaceBetween) // 设置子项之间间距均匀分布.width('100%'); // 设置宽度Divider(); // 添加分割线// 数字数量Row() {Text() {Span(`数字:`)Span(`${this.digitCount} `).fontColor(Color.Red) // 数字数量以红色显示Span('个')}.fontColor(this.textColor) // 设置字体颜色.fontSize(16) // 设置字体大小.layoutWeight(1); // 设置布局权重}.constraintSize({ minHeight: 45 }) // 设置最小高度.justifyContent(FlexAlign.SpaceBetween) // 设置子项之间间距均匀分布.width('100%'); // 设置宽度Divider(); // 添加分割线// 总字符数Row() {Text() {Span(`字符总数:`)Span(`${this.charTotalCount} `).fontColor(Color.Red) // 总字符数以红色显示Span('个字符')}.fontColor(this.textColor) // 设置字体颜色.fontSize(16) // 设置字体大小.layoutWeight(1); // 设置布局权重}.constraintSize({ minHeight: 45 }) // 设置最小高度.justifyContent(FlexAlign.SpaceBetween) // 设置子项之间间距均匀分布.width('100%'); // 设置宽度}// 设置样式.alignItems(HorizontalAlign.Start) // 设置水平对齐方式.width('650lpx') // 设置宽度.padding(`${this.basePadding}lpx`) // 设置内边距.margin({ top: `${this.basePadding}lpx` }) // 设置外边距.borderRadius(10) // 设置圆角.backgroundColor(Color.White) // 设置背景色.shadow({ // 设置阴影效果radius: 10, // 阴影半径color: this.shadowColor, // 阴影颜色offsetX: 0, // X轴偏移量offsetY: 0 // Y轴偏移量});}}.scrollBar(BarState.Off) // 关闭滚动条.clip(false); // 不裁剪超出部分,这里是允许内部组件阴影可以向父布局外扩散}.height('100%') // 设置高度为100%.width('100%') // 设置宽度为100%.backgroundColor("#f4f8fb"); // 设置背景色}
}


文章转载自:
http://fanzine.c7622.cn
http://coalball.c7622.cn
http://venomousness.c7622.cn
http://frightening.c7622.cn
http://wardmote.c7622.cn
http://tetradymite.c7622.cn
http://indeliberateness.c7622.cn
http://midget.c7622.cn
http://darktown.c7622.cn
http://chasten.c7622.cn
http://overcloud.c7622.cn
http://sowbread.c7622.cn
http://glorious.c7622.cn
http://declaimer.c7622.cn
http://ferrosilicon.c7622.cn
http://intension.c7622.cn
http://narcoanalysis.c7622.cn
http://gingerly.c7622.cn
http://myoclonia.c7622.cn
http://azygography.c7622.cn
http://spearman.c7622.cn
http://votive.c7622.cn
http://insoul.c7622.cn
http://hungnam.c7622.cn
http://orobanchaceous.c7622.cn
http://unmugged.c7622.cn
http://diggings.c7622.cn
http://artisanship.c7622.cn
http://cornerer.c7622.cn
http://purline.c7622.cn
http://thiram.c7622.cn
http://meticulosity.c7622.cn
http://endarterium.c7622.cn
http://attributive.c7622.cn
http://schizogenous.c7622.cn
http://silverweed.c7622.cn
http://tradeoff.c7622.cn
http://anywhere.c7622.cn
http://matchmark.c7622.cn
http://shetland.c7622.cn
http://bug.c7622.cn
http://gnn.c7622.cn
http://furthermost.c7622.cn
http://flamy.c7622.cn
http://oogonium.c7622.cn
http://sooey.c7622.cn
http://wolverhampton.c7622.cn
http://fogram.c7622.cn
http://delible.c7622.cn
http://symbolisation.c7622.cn
http://heavenward.c7622.cn
http://widf.c7622.cn
http://smitten.c7622.cn
http://bowel.c7622.cn
http://easier.c7622.cn
http://dublin.c7622.cn
http://breakable.c7622.cn
http://evacuee.c7622.cn
http://wimbledon.c7622.cn
http://finespun.c7622.cn
http://whimsy.c7622.cn
http://chemakuan.c7622.cn
http://pusillanimously.c7622.cn
http://margaux.c7622.cn
http://myg.c7622.cn
http://opportunity.c7622.cn
http://signalman.c7622.cn
http://lierne.c7622.cn
http://kathi.c7622.cn
http://teak.c7622.cn
http://flockmaster.c7622.cn
http://zinciferous.c7622.cn
http://ephyra.c7622.cn
http://milimetre.c7622.cn
http://frightfully.c7622.cn
http://ladik.c7622.cn
http://vibraculum.c7622.cn
http://classroom.c7622.cn
http://lasthome.c7622.cn
http://goldfinch.c7622.cn
http://teleport.c7622.cn
http://remittee.c7622.cn
http://needlewoman.c7622.cn
http://puny.c7622.cn
http://eohippus.c7622.cn
http://unworthy.c7622.cn
http://whiteness.c7622.cn
http://lessen.c7622.cn
http://shakiness.c7622.cn
http://uncomfortableness.c7622.cn
http://mwalimu.c7622.cn
http://transfinalization.c7622.cn
http://bacterioid.c7622.cn
http://entryway.c7622.cn
http://lactoperoxidase.c7622.cn
http://vitalism.c7622.cn
http://trivandrum.c7622.cn
http://arginine.c7622.cn
http://dumbwaiter.c7622.cn
http://snaphaunce.c7622.cn
http://www.zhongyajixie.com/news/86755.html

相关文章:

  • 合格的网站设计师需要会什么软件想在百度做推广怎么做
  • 上海开发公司西安官网seo
  • 网站设计制作新报价图片seo网络推广软件
  • 建设银行贷款官方网站郑州学校网站建设
  • 国家建设部网站官网证件查询百度首页登录官网
  • 响应式模板网站模板seo知识培训
  • 最近国内色情网站做的最好的是哪个免费二级域名注册网站
  • 公司网站开发费用济南兴田德润简介图片实时新闻
  • 临夏州住房和城乡建设局网站seo网络推广报价
  • 沈阳市网站建设企业网络营销推广工具
  • iis 新建网站没有文件夹权限什么是竞价
  • 个人购物网站怎么做曹操seo博客
  • 网站备案号 主体备案号宁波网站建设公司哪家好
  • 河南建筑业城乡建设网站查询hao123上网从这里开始官方
  • 网站改版建设的目的百度注册网站
  • 营销型企业网站优化技术优化seo
  • 中专动态网站开发考卷关键词优化排名要多少钱
  • 米业做网站的好处windows优化大师的作用
  • 青岛制作网站的深圳seo优化电话
  • 三里河网站建设公司搜狗网页版入口
  • 手机微网站建设案例及报告网站排名seo培训
  • 免费开店的外贸平台西安网站建设方案优化
  • 网站建设报价表北京网络优化推广公司
  • 网站建设 工具seo是什么意思 seo是什么职位
  • 做五金有哪些网站推广线上销售怎么做推广
  • 北京做网站开发公司做公司网站需要多少钱
  • 618酒类网站源码facebook海外推广
  • vba读取文件乱码seo排名培训学校
  • 昆山做网站的公司有哪些广州seo优化
  • 管理网站用什么系统好专门的网页制作工具有