您的位置:首页 > 文旅 > 美景 > 智慧树网页设计与制作作业答案_怎么搭建自己公司网站_seo咨询_泰安网站优化公司

智慧树网页设计与制作作业答案_怎么搭建自己公司网站_seo咨询_泰安网站优化公司

2025/2/13 23:58:12 来源:https://blog.csdn.net/joke_xiaoli/article/details/144296520  浏览:    关键词:智慧树网页设计与制作作业答案_怎么搭建自己公司网站_seo咨询_泰安网站优化公司
智慧树网页设计与制作作业答案_怎么搭建自己公司网站_seo咨询_泰安网站优化公司
@Entry
@Component
struct Index {@State result: string[] = ['0']setParams(pattern: string) {const operators: string = '+-*/.'if (this.result.length == 1 && this.result[0] == '0') {if ('*/'.includes(pattern)) returnthis.result = [pattern]} else {const len = this.result.lengthconst last = this.result.lastIndexOf('.')const slice = this.result.slice(last + 1)if (last != -1 && pattern == '.' && /^\d+$/.test(slice.join(''))) returnif(!(operators.includes(this.result[len-1]) && operators.includes(pattern))){this.result.push(pattern)}}}calc() {let res = 0const dd = this.result.join('').match(/[\-\+]?\d+(\.\d+)?([\/\*]\d+(\.?\d+)?)*/g)dd.forEach(item => {if (/^[\+\-]?\d+(\.\d+)?$/.test(item)) {res += +item} else {let rr = 0let isj = falselet operator: string = "*"let rrr = item.match(/[\/\*]|(\d+(\.\d+)?)/g)for (let index = 0; index < rrr.length; index++) {const element = rrr[index];if (element == '-') {isj = true} else if ('*/'.includes(element)) {operator = element} else {if (rr == 0) {rr = +elementcontinue}if (operator == '*') {rr *= +element} else {rr /= +element}}if (isj) {rr = 0 - rr}}res += rr}})this.result = [res + '']}build() {Grid() {GridItem() {Text(this.result.join('')).padding(10).height('100%').width('100%').fontColor('#000000').textAlign(TextAlign.End).fontSize(50)}.columnStart(1).columnEnd(4).backgroundColor('#FFC0CB')GridItem() {Button('CE').type(ButtonType.Normal).height('100%').width('100%').fontColor('#000000').backgroundColor('#FFC0CB').onClick(() => {if (this.result.length == 1) {if (this.result[0] == '0') returnthis.result = ['0']return}this.result.pop()})}GridItem() {Button('C').type(ButtonType.Normal).height('100%').width('100%').fontColor('#000000').backgroundColor('#FFC0CB').onClick(() => {this.result = ['0']})}GridItem() {Button('/').type(ButtonType.Normal).height('100%').width('100%').fontColor('#000000').backgroundColor('#FFC0CB').onClick(() => {this.setParams('/')})}.backgroundColor('#FFC0CB')GridItem() {Button('*').type(ButtonType.Normal).height('100%').width('100%').fontColor('#000000').backgroundColor('#FFC0CB').onClick(() => {this.setParams('*')})}ForEach(['7', '8', '9'], (item: string) => {GridItem() {Button(item).type(ButtonType.Normal).height('100%').width('100%').fontColor('#000000').backgroundColor('#FFC0CB').onClick(() => {this.setParams(item)})}}, item => item)GridItem() {Button('-').type(ButtonType.Normal).height('100%').width('100%').fontColor('#000000').backgroundColor('#FFC0CB').onClick(() => {this.setParams('-')})}ForEach(['4', '5', '6'], (item: string) => {GridItem() {Button(item).type(ButtonType.Normal).height('100%').width('100%').fontColor('#000000').backgroundColor('#FFC0CB').onClick(() => {this.setParams(item)})}}, item => item)GridItem() {Button('+').type(ButtonType.Normal).height('100%').width('100%').fontColor('#000000').backgroundColor('#FFC0CB').onClick(() => {this.setParams('+')})}ForEach(['1', '2', '3'], (item: string) => {GridItem() {Button(item).type(ButtonType.Normal).height('100%').width('100%').fontColor('#000000').backgroundColor('#FFC0CB').onClick(() => {this.setParams(item)})}}, item => item)GridItem() {Button('=').type(ButtonType.Normal).height('100%').width('100%').fontColor('#000000').backgroundColor('#FFC0CB').onClick(() => {this.calc()})}.rowStart(5).rowEnd(6).backgroundColor('#FFC0CB')GridItem() {Button('0').type(ButtonType.Normal).height('100%').width('100%').fontColor('#000000').backgroundColor('#FFC0CB').onClick(() => {this.setParams('0')})}.columnStart(1).columnEnd(2)GridItem() {Button('.').type(ButtonType.Normal).height('100%').width('100%').fontColor('#000000').backgroundColor('#FFC0CB').onClick(() => {this.setParams('.')})}}.columnsGap(10).rowsGap(10).padding(10).rowsTemplate('2fr 1fr 1fr 1fr 1fr 1fr').columnsTemplate('1fr 1fr 1fr 1fr').backgroundColor('#FFFFFF')}
}

效果图:

编辑器为Dev Eco

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com