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

有域名怎么建立网站北京模板网站开发

有域名怎么建立网站,北京模板网站开发,免费企业黄页查询官网,做网站金山区【引言】 在鸿蒙NEXT开发中#xff0c;文字转拼音是一个常见的需求#xff0c;本文将介绍如何利用鸿蒙系统和pinyin-pro库实现文字转拼音的功能。 【环境准备】 • 操作系统#xff1a;Windows 10 • 开发工具#xff1a;DevEco Studio NEXT Beta1 Build Version: 5.0.… 【引言】 在鸿蒙NEXT开发中文字转拼音是一个常见的需求本文将介绍如何利用鸿蒙系统和pinyin-pro库实现文字转拼音的功能。 【环境准备】 • 操作系统Windows 10 • 开发工具DevEco Studio NEXT Beta1 Build Version: 5.0.3.806 • 目标设备华为Mate60 Pro • 开发语言ArkTS • 框架ArkUI • API版本API 12 • 三方库pinyin-pro3.18.3核心算法 【开始步骤】 首先我们引入pinyin-pro库中的pinyin函数用于将中文转换为拼音。然后定义一个PinyinBean类来存储字符和其对应的拼音以便后续展示转换结果。 接着我们使用装饰器定义一个PinyinConverter组件该组件实现了文字转拼音的功能。通过用户输入文本调用convertToPinyin方法将文本转换成拼音数组并将拼音和字符对应存储在conversionResult数组中。 在UI方面我们通过鸿蒙系统提供的布局组件和样式设置构建了一个用户友好的界面。用户可以输入文本点击示例按钮填充默认文本点击清空按钮清空输入内容。转换结果会以拼音和字符的形式展示在界面上。 整个开发案例涵盖了鸿蒙NEXT开发中的组件定义、状态管理、事件处理、UI构建等方面展示了如何利用鸿蒙系统和第三方库实现文字转拼音的功能。 【完整代码】 导包 ohpm install pinyin-pro3.18.3 代码 // 引入pinyin-pro库中的pinyin函数用于将中文转换为拼音 import { pinyin } from pinyin-pro;// 定义一个类来存储字符和其对应的拼音 class PinyinBean {pinyin: string; // 拼音character: string; // 对应的汉字// 构造器初始化拼音和字符constructor(pinyin: string, character: string) {this.pinyin pinyin;this.character character;} }// 使用装饰器定义一个组件该组件用于实现文字转拼音功能 Entry Component struct PinyinConverter {// 默认的用户输入内容State private defaultInput: string 混沌未分天地乱,茫茫渺渺无人见。自从盘古破鸿蒙,开辟从兹清浊辨。;// 组件的主题颜色State private themeColor: string | Color Color.Orange;// 组件的文字颜色State private fontColor: string #2e2e2e;// 组件的边框颜色State private lineColor: string #d5d5d5;// 基础内边距值State private basePadding: number 30;// 用户输入的内容当这个状态改变时会触发convertToPinyin方法State Watch(convertToPinyin) userInput: string ;// 转换结果显示存储了转换后的拼音和对应字符State conversionResult: PinyinBean[] [];// 输入框是否获得了焦点State isInputFocused: boolean false;// 方法将用户输入的文本转换成拼音convertToPinyin() {// 使用pinyin-pro库将输入的文本转换成拼音数组const pinyinArray: string[] pinyin(this.userInput, { type: array });// 将输入的文本分割成单个字符的数组const charArray: string[] this.userInput.split();// 清空转换结果数组this.conversionResult.length 0;// 遍历拼音数组创建PinyinBean对象并将其添加到转换结果数组中for (let i 0; i pinyinArray.length; i) {this.conversionResult.push(new PinyinBean(pinyinArray[i], charArray[i]));}}// 构建UI的方法build() {// 创建一个垂直布局的容器Column() {// 添加标题栏Text(文字转拼音).fontColor(this.fontColor) // 设置字体颜色.fontSize(18) // 设置字体大小.width(100%) // 设置宽度为100%.height(50) // 设置高度为50.textAlign(TextAlign.Center) // 文本居中对齐.backgroundColor(Color.White) // 设置背景色为白色.shadow({ // 添加阴影效果radius: 2, // 阴影圆角color: this.lineColor, // 阴影颜色offsetX: 0, // X轴偏移量offsetY: 5 // Y轴偏移量});// 内部垂直布局Column() {// 示例与清空按钮行Row() {// 示例按钮Text(示例).fontColor(#5871ce) // 设置字体颜色.fontSize(18) // 设置字体大小.padding(${this.basePadding / 2}lpx) // 设置内边距.backgroundColor(#f2f1fd) // 设置背景色.borderRadius(5) // 设置圆角.clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.8 }) // 设置点击效果.onClick(() { // 点击事件处理this.userInput this.defaultInput; // 将默认输入设置为用户输入});// 空白间隔Blank();// 清空按钮Text(清空).fontColor(#e48742) // 设置字体颜色.fontSize(18) // 设置字体大小.padding(${this.basePadding / 2}lpx) // 设置内边距.clickEffect({ level: ClickEffectLevel.LIGHT, scale: 0.8 }) // 设置点击效果.backgroundColor(#ffefe6) // 设置背景色.borderRadius(5) // 设置圆角.onClick(() { // 点击事件处理this.userInput ; // 清空用户输入});}.height(45) // 设置高度.justifyContent(FlexAlign.SpaceBetween) // 子元素之间等间距分布.width(100%); // 设置宽度为100%// 用户输入框Row() {TextArea({text: $$this.userInput, // 绑定用户输入placeholder: !this.isInputFocused ? 请输入内容。如${this.defaultInput} : // 设置占位符}).backgroundColor(Color.Transparent) // 设置背景色为透明.padding(0) // 设置内边距.height(100%) // 设置高度为100%.placeholderColor(this.isInputFocused ? this.themeColor : Color.Gray) // 设置占位符颜色.fontColor(this.isInputFocused ? this.themeColor : this.fontColor) // 设置字体颜色.caretColor(this.themeColor) // 设置光标颜色.borderRadius(0) // 设置圆角.onBlur(() this.isInputFocused false) // 当失去焦点时更新状态.onFocus(() this.isInputFocused true) // 当获得焦点时更新状态.width(100%); // 设置宽度为100%}.padding(${this.basePadding / 2}lpx) // 设置内边距.backgroundColor(#f2f1fd) // 设置背景色.width(100%) // 设置宽度为100%.height(120) // 设置高度.borderWidth(1) // 设置边框宽度.borderRadius(10) // 设置圆角.borderColor(this.isInputFocused ? this.themeColor : Color.Gray) // 设置边框颜色.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.lineColor, // 阴影颜色offsetX: 0, // X轴偏移量offsetY: 0 // Y轴偏移量});// 结果显示区域Column() {Row() {Flex({ wrap: FlexWrap.Wrap }) { // 允许子元素换行ForEach(this.conversionResult, (item: PinyinBean, index: number) { // 遍历转换结果Column() {// 显示计算结果拼音Text(${item.pinyin}).fontColor(this.fontColor).fontSize(18);// 显示计算结果字符Text(${item.character}).fontColor(this.fontColor).fontSize(18);}.padding(3); // 设置内边距})}}.justifyContent(FlexAlign.SpaceBetween) // 子元素之间等间距分布.width(100%); // 设置宽度为100%}.visibility(this.conversionResult.length ! 0 ? Visibility.Visible : Visibility.None) // 根据是否有转换结果决定是否显示.alignItems(HorizontalAlign.Start) // 设置子元素水平对齐方式.width(650lpx) // 设置宽度.padding(${this.basePadding}lpx) // 设置内边距.margin({ top: ${this.basePadding}lpx }) // 设置上边距.borderRadius(10) // 设置圆角.backgroundColor(Color.White) // 设置背景色.shadow({ // 设置阴影radius: 10, // 阴影圆角color: this.lineColor, // 阴影颜色offsetX: 0, // X轴偏移量offsetY: 0 // Y轴偏移量});}.height(100%) // 设置高度为100%.width(100%) // 设置宽度为100%.backgroundColor(#f4f8fb); // 设置背景色} }
http://www.hkea.cn/news/14257619/

相关文章:

  • 建网站自学h5开发环境
  • 全球50个大网站开发语言常州百度推广代理
  • 个人可以建设网站吗还能做网站的分类
  • 自己切片视频做网站西安高端网站设计公司
  • 龙岗区做网站杭州做网站外包公司哪家好
  • 国外做mg动画的网站大全深圳企业网页制作
  • 静态网站设计与制作书籍无锡室内设计公司
  • 网站icp备案代理自己做的图片哪个网站可以出售
  • 域名空间做网站wordpress清除插件
  • 网站加速器免费永久如何优化自己的网站
  • 白银市城乡建设局网站运营网站是什么意思
  • 做网站主要用哪种语言梵克雅宝是哪个国家的牌子
  • 织梦如何做几种语言的网站网站建设与维护理解
  • 百度站长验证网站失败山西企业建站系统平台
  • 网站登录到wordpress东丽区做网站
  • 云南省红河州蒙自建设局网站做ppt做好的网站
  • 行业网站怎么建设做网站要注册公司吗
  • 小说网站的内容做信息图表网站
  • 营销型网站有那些网站怎么开公众号
  • python3 网站开发入门西安的网页设计公司
  • 做网站去哪里找客户app ui设计网站
  • 微信公众号微网站制作别人用我的身份信息建设网站
  • 哪些做园林的网站域名历史价格查询
  • 网上做结婚照的网站如何在WordPress主题中加载幻灯片
  • 沈阳企业建站系统模板火车头wordpress获取不到分类
  • 用vs2008做网站视频教程想开广告公司怎么起步
  • 酒店网站建设价格做英语网站
  • 网站建设经费预算策划书网络游戏制作软件
  • 门户网网站建设功能需求表网站专题素材
  • 专业瓷砖美缝网站怎么做拉新推广