diff --git a/ETSUI/eTSUrlString/README.md b/ETSUI/eTSUrlString/README.md new file mode 100644 index 0000000000000000000000000000000000000000..48320ed7cd4d3415382a3ca830dc62986d01c870 --- /dev/null +++ b/ETSUI/eTSUrlString/README.md @@ -0,0 +1,19 @@ +# URL字符串解析 + +### 简介 + +本示例对URL字符串的查找参数进行了增删改查的一系列操作,使得读者对URL的结构用途更加明了。 + +### 使用说明 + +1.点击**插入键值对到查询字符串**按钮,会将左面文本框的参数插入到查找参数后面。 + +2.点击**删除键值对**按钮,会将指定名称的键值对删除。 + +3.点击**获取指定名称对应的第一个值**按钮,将查找参数中该参数名对应的第一个参数值,并显示出来。 + +4.点击**设置键的新值**按钮,将与名称相关联的键值对全部删除,并赋予该键名一个新值。 + +### 约束与限制 + +本示例仅支持在标准系统上运行。 \ No newline at end of file diff --git a/ETSUI/eTSUrlString/build.gradle b/ETSUI/eTSUrlString/build.gradle new file mode 100644 index 0000000000000000000000000000000000000000..c2c8bbaed13747b913f19cef893f515bc32d02a7 --- /dev/null +++ b/ETSUI/eTSUrlString/build.gradle @@ -0,0 +1,34 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. +apply plugin: 'com.huawei.ohos.app' + +//For instructions on signature configuration, see https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ide_debug_device-0000001053822404#section1112183053510 +ohos { + compileSdkVersion 7 + supportSystem "standard" +} + +buildscript { + repositories { + maven { + url 'https://repo.huaweicloud.com/repository/maven/' + } + maven { + url 'https://developer.huawei.com/repo/' + } + } + dependencies { + classpath 'com.huawei.ohos:hap:3.0.3.4' + classpath 'com.huawei.ohos:decctest:1.2.6.0' + } +} + +allprojects { + repositories { + maven { + url 'https://repo.huaweicloud.com/repository/maven/' + } + maven { + url 'https://developer.huawei.com/repo/' + } + } +} diff --git a/ETSUI/eTSUrlString/entry/build.gradle b/ETSUI/eTSUrlString/entry/build.gradle new file mode 100644 index 0000000000000000000000000000000000000000..1587dd1948941f3eaaf092ae6cae7969cb6895ff --- /dev/null +++ b/ETSUI/eTSUrlString/entry/build.gradle @@ -0,0 +1,21 @@ +apply plugin: 'com.huawei.ohos.hap' +//For instructions on signature configuration, see https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ide_debug_device-0000001053822404#section1112183053510 +ohos { + compileSdkVersion 7 + defaultConfig { + compatibleSdkVersion 7 + } + buildTypes { + release { + proguardOpt { + proguardEnabled false + rulesFiles 'proguard-rules.pro' + } + } + } +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) + testImplementation 'junit:junit:4.13.1' +} diff --git a/ETSUI/eTSUrlString/entry/src/main/config.json b/ETSUI/eTSUrlString/entry/src/main/config.json new file mode 100644 index 0000000000000000000000000000000000000000..e6ceaef27667f3a522147d4786e44f1238ce34d1 --- /dev/null +++ b/ETSUI/eTSUrlString/entry/src/main/config.json @@ -0,0 +1,66 @@ +{ + "app": { + "bundleName": "ohos.samples.etsurlstring", + "vendor": "samples", + "version": { + "code": 1000000, + "name": "1.0.0" + } + }, + "deviceConfig": {}, + "module": { + "package": "ohos.samples.etsurlstring", + "name": ".MyApplication", + "mainAbility": ".MainAbility", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "entry", + "moduleType": "entry", + "installationFree": false + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "orientation": "unspecified", + "visible": true, + "srcPath": "MainAbility", + "name": ".MainAbility", + "srcLanguage": "ets", + "icon": "$media:icon", + "description": "$string:description_mainability", + "formsEnabled": false, + "label": "$string:entry_MainAbility", + "type": "page", + "launchType": "standard" + } + ], + "js": [ + { + "mode": { + "syntax": "ets", + "type": "pageAbility" + }, + "pages": [ + "pages/index" + ], + "name": ".MainAbility", + "window": { + "designWidth": 720, + "autoDesignWidth": false + } + } + ] + } +} \ No newline at end of file diff --git a/ETSUI/eTSUrlString/entry/src/main/ets/MainAbility/app.ets b/ETSUI/eTSUrlString/entry/src/main/ets/MainAbility/app.ets new file mode 100644 index 0000000000000000000000000000000000000000..bf28e58b36cf11db491d3f00768ef2c9e41d05cf --- /dev/null +++ b/ETSUI/eTSUrlString/entry/src/main/ets/MainAbility/app.ets @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export default { + onCreate() { + console.info('Application onCreate') + }, + onDestroy() { + console.info('Application onDestroy') + }, +} \ No newline at end of file diff --git a/ETSUI/eTSUrlString/entry/src/main/ets/MainAbility/common/paramOption.ets b/ETSUI/eTSUrlString/entry/src/main/ets/MainAbility/common/paramOption.ets new file mode 100644 index 0000000000000000000000000000000000000000..0eaded4f779113185a184f202204d3ac35699993 --- /dev/null +++ b/ETSUI/eTSUrlString/entry/src/main/ets/MainAbility/common/paramOption.ets @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import url from '@ohos.url' + +var urlObject = new url.URL('https://developer.harmonyos.com/?') +var paramsObject = new url.URLSearchParams(urlObject.search.slice(1)) + +@Component +export struct FirstOption{ + private options:Resource[] = [$r('app.string.insert'), $r('app.string.delete'), + $r('app.string.getFirst'), $r('app.string.setValue')] + private nodeValue:string = 'nodeValue' + private nodeKey:string = 'node' + private nodeNum:number = 0 + + @Link outputs:string + + insertNode(){ + this.nodeNum ++ + paramsObject.append(this.nodeKey, this.nodeValue + this.nodeNum) + this.outputs = urlObject.toString() + paramsObject.toString() + } + + deleteNode(){ + if(paramsObject.has(this.nodeKey)){ + paramsObject.delete(this.nodeKey) + this.outputs = urlObject.toString() + paramsObject.toString() + this.nodeNum = 0 + } + else{ + this.outputs = "It does not exist. Please insert first" + } + } + + getFirstNode(){ + if(paramsObject.has(this.nodeKey)){ + var fod = paramsObject.get(this.nodeKey); + this.outputs = fod.toString() + } + else{ + this.outputs = "It does not exist. Please insert first" + } + } + + changeValue(){ + paramsObject.set(this.nodeKey, 'newValue') + this.nodeNum = 0 + this.outputs = urlObject.toString() + paramsObject.toString() + } + + build(){ + Column(){ + Flex({direction:FlexDirection.Row,alignItems:ItemAlign.Center,justifyContent:FlexAlign.Center,wrap:FlexWrap.Wrap}){ + ForEach(this.options,item=> { + Button() { + Text(item) + .fontSize(20) + .textAlign(TextAlign.Center) + .fontColor(Color.White) + .width('340') + } + .type(ButtonType.Capsule) + .backgroundColor('#0D9FFB') + .padding(5) + .margin({top:10 }) + .onClick(() => { + var index = this.options.indexOf(item) + switch(index) { + case 0: + this.insertNode() + break + case 1: + this.deleteNode() + break + case 2: + this.getFirstNode() + break + case 3: + this.changeValue() + break + default: + break + } + }) + },item=>JSON.stringify(item)) + }.width('100%') + }.width('100%') + } +} \ No newline at end of file diff --git a/ETSUI/eTSUrlString/entry/src/main/ets/MainAbility/pages/index.ets b/ETSUI/eTSUrlString/entry/src/main/ets/MainAbility/pages/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..a530339a594d01c20dcec1b15b2c95f640481464 --- /dev/null +++ b/ETSUI/eTSUrlString/entry/src/main/ets/MainAbility/pages/index.ets @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import {FirstOption} from '../common/paramOption' +const URL_NET: string= "https://developer.harmonyos.com/?" + +@Entry +@Component +struct Index { + @State output: string = URL_NET + + build() { + Column() { + Text($r("app.string.entry_MainAbility")) + .width('100%') + .height(50) + .backgroundColor('#0D9FFB') + .fontColor(Color.White) + .fontSize(20) + .padding({ left: 15 }) + Scroll() { + Column() { + Text(this.output) + .width('95%').height('30%') + .fontSize(15) + .padding(10) + .margin({ left: 10, right: 10, top: 10 }) + .border({ width: 2, radius: 5, color: Color.Gray }) + Text(URL_NET).fontSize(15).margin({top:15}).fontWeight(FontWeight.Bold) + FirstOption({outputs:$output}) + } + } + } + .width('100%') + .height('100%') + } +} + diff --git a/ETSUI/eTSUrlString/entry/src/main/resources/base/element/string.json b/ETSUI/eTSUrlString/entry/src/main/resources/base/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..6de6dfb2e5f421584e66ca3dd7bef18efd8dec86 --- /dev/null +++ b/ETSUI/eTSUrlString/entry/src/main/resources/base/element/string.json @@ -0,0 +1,36 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "eTSURLString" + }, + { + "name": "description_mainability", + "value": "ETS_Empty Ability" + }, + { + "name": "url", + "value": "URL:" + }, + { + "name": "insert", + "value": "Insert Key-value" + }, + { + "name": "delete", + "value": "Delete Key-value" + }, + { + "name": "getFirst", + "value": "GetFirst Key-value" + }, + { + "name": "setValue", + "value": "Set new value of key" + }, + { + "name": "pleaseInsert", + "value": "It does not exist. Please insert first" + } + ] +} \ No newline at end of file diff --git a/ETSUI/eTSUrlString/entry/src/main/resources/base/media/icon.png b/ETSUI/eTSUrlString/entry/src/main/resources/base/media/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..ce307a8827bd75456441ceb57d530e4c8d45d36c Binary files /dev/null and b/ETSUI/eTSUrlString/entry/src/main/resources/base/media/icon.png differ diff --git a/ETSUI/eTSUrlString/entry/src/main/resources/en/element/string.json b/ETSUI/eTSUrlString/entry/src/main/resources/en/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..6de6dfb2e5f421584e66ca3dd7bef18efd8dec86 --- /dev/null +++ b/ETSUI/eTSUrlString/entry/src/main/resources/en/element/string.json @@ -0,0 +1,36 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "eTSURLString" + }, + { + "name": "description_mainability", + "value": "ETS_Empty Ability" + }, + { + "name": "url", + "value": "URL:" + }, + { + "name": "insert", + "value": "Insert Key-value" + }, + { + "name": "delete", + "value": "Delete Key-value" + }, + { + "name": "getFirst", + "value": "GetFirst Key-value" + }, + { + "name": "setValue", + "value": "Set new value of key" + }, + { + "name": "pleaseInsert", + "value": "It does not exist. Please insert first" + } + ] +} \ No newline at end of file diff --git a/ETSUI/eTSUrlString/entry/src/main/resources/zh/element/string.json b/ETSUI/eTSUrlString/entry/src/main/resources/zh/element/string.json new file mode 100644 index 0000000000000000000000000000000000000000..e29a2f9a38694f6a0a3df2c3b5e70af56683eb14 --- /dev/null +++ b/ETSUI/eTSUrlString/entry/src/main/resources/zh/element/string.json @@ -0,0 +1,36 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "eTSURLString" + }, + { + "name": "description_mainability", + "value": "ETS_Empty Ability" + }, + { + "name": "url", + "value": "URL:" + }, + { + "name": "insert", + "value": "插入键值对到查询字符串" + }, + { + "name": "delete", + "value": "删除键值对" + }, + { + "name": "getFirst", + "value": "获取指定名称对应的第一个值" + }, + { + "name": "setValue", + "value": "设置键的新值" + }, + { + "name": "pleaseInsert", + "value": "不存在,请先插入" + } + ] +} \ No newline at end of file diff --git a/ETSUI/eTSUrlString/screenshot/device/screenshot.png b/ETSUI/eTSUrlString/screenshot/device/screenshot.png new file mode 100644 index 0000000000000000000000000000000000000000..7df99f7d0b01440aa20489f5b659cbbd2766814b Binary files /dev/null and b/ETSUI/eTSUrlString/screenshot/device/screenshot.png differ diff --git a/ETSUI/eTSUrlString/settings.gradle b/ETSUI/eTSUrlString/settings.gradle new file mode 100644 index 0000000000000000000000000000000000000000..4773db73233a570c2d0c01a22e75321acfbf7a07 --- /dev/null +++ b/ETSUI/eTSUrlString/settings.gradle @@ -0,0 +1 @@ +include ':entry'