diff --git a/ETSUI/EtsUrlString/README.md b/ETSUI/EtsUrlString/README.md new file mode 100644 index 0000000000000000000000000000000000000000..8f2f8d928aacc71207c1ba31910dcb71d9f4ad19 --- /dev/null +++ b/ETSUI/EtsUrlString/README.md @@ -0,0 +1,25 @@ +# URL字符串解析 + +### 简介 + +本示例对URL字符串的查找参数进行了增删改查的一系列操作,使得读者对URL的结构用途更加明了。 + +### 使用说明 + +1.点击**URLSearchParamsConstruct**按钮,文本框会呈现出URL查找参数的四种构造方法。 + +2.点击**Insert**按钮,会将左面文本框的参数插入到查找参数后面。 + +3.点击**delete**按钮,会将同参数名相关参数全部删除于查找参数之中,并输出在文本框中。 + +4.点击**getAll**按钮,会将查找参数中所有同名的参数值依次排列显示。 + +5.点击**getFirst**按钮,会将查找参数中该参数名的第一个参数值显示出来。 + +6.点击**setValue**按钮,将与名称关联的URL搜索参数对象中的值进行重新赋值。如果存在名称为name的键值对,请将第一个键值对的值重新赋值并删除所有其他值。如果不是,则将键值对附加到查询字符串。 + +7.点击**Sort**按钮,对包含在此对象中的所有键值对进行排序。排序顺序是根据键的Unicode代码点。该方法使用稳定的排序算法 (即,将保留具有相等键的键值对之间的相对顺序)。 + +### 约束与限制 + +本示例仅支持在标准系统上运行。 \ 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..e9704babd2cdfa2e49d5a24364eecd5f71d905d8 --- /dev/null +++ b/ETSUI/EtsUrlString/entry/src/main/config.json @@ -0,0 +1,66 @@ +{ + "app": { + "bundleName": "ohos.samples.urlstring", + "vendor": "samples", + "version": { + "code": 1000000, + "name": "1.0.0" + } + }, + "deviceConfig": {}, + "module": { + "package": "ohos.samples.urlstring", + "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/pages/index.ets b/ETSUI/EtsUrlString/entry/src/main/ets/MainAbility/pages/index.ets new file mode 100644 index 0000000000000000000000000000000000000000..9ea55ae63d75d21fa96db0ebbbda83e37a22a877 --- /dev/null +++ b/ETSUI/EtsUrlString/entry/src/main/ets/MainAbility/pages/index.ets @@ -0,0 +1,281 @@ +/* + * 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/?fod=1&bard=2') +var paramsObject = new Url.URLSearchParams(urlObject.search.slice(1)) + +@Entry +@Component +struct Index { + + @State urlNet:string= "https://developer.harmonyos.com/?fod=1&bard=2" + + @State OutPut:string='' + @State params:string='' + @State value:string='' + + + build() { + Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Start }) { + Text($r("app.string.URL_String_Parsing")) + .width('100%').height(50) + .backgroundColor('#0D9FFB') + .fontSize(30) + .fontWeight(FontWeight.Bold) + .padding({left:20,top:5}) + Scroll(){ + Column(){ + Text(this.OutPut) + .width('95%').height('35%') + .fontSize(15) + .margin({left:10,right:10,top:10}) + .lineHeight(25) + .maxLines(20) + .border({width:2,radius:5,color:"#0D9FFB"}) + Button(){ + Text($r("app.string.URLSearchParamsConstruct")).fontSize(20) + } + .type(ButtonType.Capsule) + .width(300) + .margin({ + top: 10 + }) + .backgroundColor('#0D9FFB') + .onClick(() => { + var objectParams = new Url.URLSearchParams([ ['user1', 'abc1'], ['query2', 'first2'], ['query3', 'second3'] ]); + var objectParams1 = new Url.URLSearchParams({"fod" : "1" , "bard" : "2"}); + var objectParams2 = new Url.URLSearchParams('?fod=1&bard=2'); + var urlObject = new Url.URL(this.urlNet); + var params = new Url.URLSearchParams(urlObject .search); + + this.OutPut = "URLSearchParams([ ['user1', 'abc1'], ['query2', 'first2'], ['query3', 'second3'] ]):\n "+objectParams.toString() + +"\n\n URLSearchParams({'fod' : '1' , 'bard' : '2'}):\n "+objectParams1.toString() + +"\n\n URLSearchParams('?fod=1&bard=2'):\n "+objectParams2.toString() + +"\n\n URLSearchParams(urlObject .search):\n "+params.toString() + }) + Text($r("app.string.ParamsOption")).width('100%').backgroundColor('#0D9FFB').margin({top:30}).textAlign(TextAlign.Center).fontSize(20) + + Text($r("app.string.url")+this.urlNet).fontSize(15).margin({top:15}).fontWeight(FontWeight.Bold) + + Row(){ + Text($r("app.string.fod")) + .width(90).height(30) + .layoutWeight(1) + .flexBasis(1) + .fontSize(15) + .border({width:2,radius:5,color:'#0D9FFB'}) + .margin({left:5}) + .textAlign(TextAlign.Center) + Button(){ + Text($r("app.string.insert")).fontSize(15).textAlign(TextAlign.Center) + } + .layoutWeight(1) + .flexBasis(1) + .width(70).height(30) + .backgroundColor('#0D9FFB') + .margin({left:5}) + .onClick(()=>{ + paramsObject.append('fod', '3') + this.OutPut = paramsObject.toString() + }) + Button(){ + Text($r("app.string.delete")).fontSize(15).textAlign(TextAlign.Center) + } + .layoutWeight(1) + .flexBasis(1) + .width(70).height(30) + .backgroundColor('#0D9FFB') + .margin({left:5}) + .onClick(()=>{ + if(paramsObject.has('fod')){ + paramsObject.delete('fod') + this.OutPut = paramsObject.toString() + } + else{ + this.OutPut = "不存在,请先插入" + } + + }) + Button(){ + Text($r('app.string.getAll')).fontSize(15).textAlign(TextAlign.Center) + } + .layoutWeight(1) + .flexBasis(1) + .width(70).height(30) + .backgroundColor('#0D9FFB') + .margin({left:5}) + .onClick(()=>{ + if(paramsObject.has('fod')) { + let params = paramsObject.getAll('fod') + this.OutPut = params.toString() + } + else{ + this.OutPut = "不存在,请先插入" + } + + }) + Button(){ + Text($r('app.string.getFirst')).fontSize(15).textAlign(TextAlign.Center) + } + .layoutWeight(1) + .flexBasis(1) + .width(70).height(30) + .backgroundColor('#0D9FFB') + .margin({left:5}) + .onClick(()=>{ + var paramsOject1 = new Url.URLSearchParams(urlObject.search.substring(1)); + if(paramsObject.has('fod')){ + var fod = paramsOject1.get("fod"); + this.OutPut = fod.toString() + } + else{ + this.OutPut = "不存在,请先插入" + } + }) + Button(){ + Text($r('app.string.setValue')).fontSize(15).textAlign(TextAlign.Center) + } + .layoutWeight(1) + .flexBasis(1) + .width(70).height(30) + .backgroundColor('#0D9FFB') + .margin({left:5}) + .onClick(()=>{ + if (paramsObject.has('fod')) { + paramsObject.set('fod', '9') + this.OutPut = paramsObject.toString() + }else{ + paramsObject.append('fod', '1') + this.OutPut = paramsObject.toString() + } + }) + } + .width('100%') + .margin({left:10,right:10,top:10}) + + Row(){ + Text($r("app.string.bard")) + .width(90).height(30) + .layoutWeight(1) + .flexBasis(1) + .fontSize(15) + .border({width:2,radius:5,color:'#0D9FFB'}) + .margin({left:5}) + .textAlign(TextAlign.Center) + Button(){ + Text($r('app.string.insert')).fontSize(15).textAlign(TextAlign.Center) + } + .layoutWeight(1) + .flexBasis(1) + .width(70).height(30) + .backgroundColor('#0D9FFB') + .margin({left:5}) + .onClick(()=>{ + paramsObject.append('bard','4') + this.OutPut = paramsObject.toString() + }) + Button(){ + Text($r("app.string.delete")).fontSize(15).textAlign(TextAlign.Center) + } + .layoutWeight(1) + .flexBasis(1) + .width(70).height(30) + .backgroundColor('#0D9FFB') + .margin({left:5}) + .onClick(()=>{ + if (paramsObject.has('bard')){ + paramsObject.delete('bard') + this.OutPut = paramsObject.toString() + } + else{ + this.OutPut = "不存在,请先插入" + } + }) + Button(){ + Text($r('app.string.getAll')).fontSize(15).textAlign(TextAlign.Center) + } + .layoutWeight(1) + .flexBasis(1) + .width(70).height(30) + .backgroundColor('#0D9FFB') + .margin({left:5}) + .onClick(()=>{ + if (paramsObject.has('bard')){ + let params = paramsObject.getAll('bard') + this.OutPut = params.toString() + } + else{ + this.OutPut = "不存在,请先插入" + } + }) + Button(){ + Text($r('app.string.getFirst')).fontSize(15).textAlign(TextAlign.Center) + } + .layoutWeight(1) + .flexBasis(1) + .width(70).height(30) + .backgroundColor('#0D9FFB') + .margin({left:5}) + .onClick(()=>{ + if (paramsObject.has('bard')){ + var paramsOject = new Url.URLSearchParams(urlObject.search.substring(1)); + var bard = parseInt(paramsOject.get("bard"), 10); + this.OutPut = bard.toString() + } + else{ + this.OutPut = "不存在,请先插入" + } + }) + Button(){ + Text($r("app.string.setValue")).fontSize(15).textAlign(TextAlign.Center) + } + .layoutWeight(1) + .flexBasis(1) + .width(70).height(30) + .backgroundColor('#0D9FFB') + .margin({left:5}) + .onClick(()=>{ + if (paramsObject.has('bard')) { + paramsObject.set('bard', '9') + this.OutPut = paramsObject.toString() + }else{ + paramsObject.append('bard', '2') + this.OutPut = paramsObject.toString() + } + }) + } + .width('100%') + .margin({left:10,right:10,top:10}) + + Button(){ + Text($r("app.string.sort")).fontSize(15).textAlign(TextAlign.Center) + } + .width(300) + .backgroundColor('#0D9FFB') + .margin({left:5,top:20}) + .onClick(()=>{ + var searchParamsObject = new Url.URLSearchParams(paramsObject.toString()); // Create a test URLSearchParams object + searchParamsObject.sort(); // Sort the key/value pairs + this.OutPut = searchParamsObject.toString() + }) + } + } + } + .width('100%') + .height('100%') + } +} \ No newline at end of file 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..ed9a9489c646b8a8c7a5593f8ca8bd186e3fc26b --- /dev/null +++ b/ETSUI/EtsUrlString/entry/src/main/resources/base/element/string.json @@ -0,0 +1,76 @@ +{ + "string": [ + { + "name": "entry_MainAbility", + "value": "URLString" + }, + { + "name": "description_mainability", + "value": "ETS_Empty Ability" + }, + { + "name": "fod", + "value": "fod:3" + }, + { + "name": "URL_String_Parsing", + "value": "URL字符串解析" + }, + { + "name": "URLSearchParamsConstruct", + "value": "URLSearchParamsConstruct" + }, + { + "name":"ParamsOption", + "value": "查询字符串的增删改查" + }, + { + "name": "url", + "value": "URL:" + }, + { + "name": "insert", + "value": "Insert" + }, + { + "name": "delete", + "value": "delete" + }, + { + "name": "getAll", + "value": "getAll" + }, + { + "name": "getFirst", + "value": "getFirst" + }, + { + "name": "setValue", + "value": "setValue" + }, + { + "name": "fodisHere", + "value": "fod的值存在:" + }, + { + "name": "fodnotHere", + "value": "fod的值不存在:" + }, + { + "name": "bard", + "value": "bard:4" + }, + { + "name": "bardisHere", + "value": "bard的值存在:" + }, + { + "name": "bardnotHere", + "value": "bard的值存在:" + }, + { + "name": "sort", + "value": "Sort" + } + ] +} \ 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/screenshot/image.png b/ETSUI/EtsUrlString/screenshot/image.png new file mode 100644 index 0000000000000000000000000000000000000000..a5cc8272d4a40e06fb2962ee4acd241867036dca Binary files /dev/null and b/ETSUI/EtsUrlString/screenshot/image.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'