diff --git a/.gitignore b/.gitignore index e3c661c6297447b9dbfcab66d652e29248003886..fdc0c4a65db238be4186f16e1e0911b1d61fbf31 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,3 @@ /entry/.preview .cxx /node_modules -.idea diff --git a/README.md b/README.md index 738f799028644dc9401b157d48a530872a91c053..60d5e3677bb6ccf931821a2a7feb3569c90007ad 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,10 @@ -## 简介 -### 当前可运行SDK版本号为:Version 7及以上 -### 当前可运行IDE版本号为:DevEco Studio 3.1 Beta及以上 -Arouter主要用于在各种应用或页面间的跳转和页面间的数据传递,其中包含跳转拦截和状态回调等功能,使用简单,操作灵活。 +## 简介 +Arouter主要是对页面与页面之间以及应用之间的路由跳转,可以用来进行不同页面之间的跳转,同时进行参数的传递, +将参数回调于上一个页面。在此基础上增加了拦截器,可以选择是否跳转至下一页面,以及预处理,通过判断是否进行 +是否跳转。 +##效果图 +![img.gif](img.gif) ## 目录 ``` /entry/src/ @@ -68,14 +70,14 @@ Arouter主要用于在各种应用或页面间的跳转和页面间的数据传 ```javascript import {Arouter} from "../arouter/arouter"; Arouter.getInstance() - .build("--/--") + .build("--/--") //需要跳转的地址 .navigation() ``` 2, 路由传参:如需传参则在build之后使用withParams方法进行传参 ```javascript import {Arouter} from "../arouter/arouter"; Arouter.getInstance() - .build("--/--") + .build("--/--") //需要跳转的地址 .withParams({index:"--"}) .navigation() ``` @@ -107,7 +109,13 @@ postcard.getNavigationCallbcak().onActivityResult(params) ``` 在页面1中onActivityResult()中获取回调的参数 -4, 路由拦截(全局路由拦截):使用拦截器先引入 Postcard 类和 InterceptorCallback 接口,实现 IInterceptor 拦截接口,在 +4.路由拦截 +4.1 开启拦截器:先引入registerInterceptor方法,然后传入iInterceptor(4 实现的)接口,在事件或生命周期中添加该方法。 +```javascript +import {registerInterceptor} from '../arouter/interceptor'; +registerInterceptor(iInterceptor) +``` +4.2 路由拦截(全局路由拦截):使用拦截器先引入 Postcard 类和 InterceptorCallback 接口,实现 IInterceptor 拦截接口,在 process 方法中实现页面拦截,选择 onContinue 继续跳转或 onInterrupt 中断跳转。(需要开启拦截器) ```typescript import {Postcard} from '../arouter/postcard'; @@ -143,28 +151,20 @@ var iInterceptor:IInterceptor= { } } ``` -效果: - -![img.png](img.png) -5, 开启拦截器:先引入registerInterceptor方法,然后传入iInterceptor(4 实现的)接口,在事件或生命周期中添加该方法。 -```javascript -import {registerInterceptor} from '../arouter/interceptor'; -registerInterceptor(iInterceptor) -``` -6, 关闭拦截器:先引入unregisterInterceptor方法,在事件或生命周期中添加该方法,直接调用即可。 +4.3 关闭拦截器:先引入unregisterInterceptor方法,在事件或生命周期中添加该方法,直接调用即可。 ```javascript import {unregisterInterceptor} from '../arouter/interceptor'; unregisterInterceptor() ``` -7, 绿色通道:在跳转前使用setGreenChannel方法跳过拦截(true:跳过拦截)。 +4.4 绿色通道:在跳转前使用setGreenChannel方法跳过拦截(true:跳过拦截)。 ```javascript Arouter.getInstance() .build("--/--") .setGreenChannel(true) .navigation() ``` -8, 预处理:实现 PretreatmentService 接口中 onPretreatment 方法,并返回一个Boolean值(true:继续跳转,false:不跳转)。 +4.5 预处理:实现 PretreatmentService 接口中 onPretreatment 方法,并返回一个Boolean值(true:继续跳转,false:不跳转)。 ```typescript var pretreatmentService:PretreatmentService = { onPretreatment(postcard:Postcard):boolean{ @@ -180,3 +180,28 @@ Arouter.getInstance() .setPretreatmentService(pretreatmentService) .navigationWithCallback(callback) ``` +##安装 +``` +npm config set @ohos:registry=https://repo.harmonyos.com/npm/ +npm install "@ohos/arouteronactivityresult" +``` +##导入类 +``` +import {arouters} from "@ohos/arouteronactivityresult"; +import {interceptorService} from "@ohos/arouteronactivityresult"; +import router from "@system.router"; +import {logisticsXeter} from "@ohos/arouteronactivityresult"; +import {navigationCallback} from "@ohos/arouteronactivityresult"; +import {postcard} from "@ohos/arouteronactivityresult"; +import {pretreatmenService} from "@ohos/arouteronactivityresult"; +``` +##兼容性 +``` +要求DevEco studio 3.1 Beta及以上 ,SDK版本号为Version 7以上。 +``` +##License +``` +Copyright(c) 2021 Huawei Device +Licensed under the Apache 2.0 License +``` + diff --git a/build.gradle b/build.gradle index 924a888a108e0af16c918e3b049937f48089a7bf..f350f30a90f962897ebab2c31e5bbf3e4868a578 100644 --- a/build.gradle +++ b/build.gradle @@ -3,9 +3,10 @@ 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 + compileSdkVersion 8 + supportSystem "standard" } - + buildscript { repositories { maven { diff --git a/entry/build.gradle b/entry/build.gradle index 0f0156791bf6048a230e13abccb9d631170209dc..cef7b37de8f320938458ca42edde1462669836d2 100644 --- a/entry/build.gradle +++ b/entry/build.gradle @@ -1,8 +1,7 @@ apply plugin: 'com.huawei.ohos.hap' -apply plugin: 'com.huawei.ohos.decctest' //For instructions on signature configuration, see https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ide_debug_device-0000001053822404#section1112183053510 ohos { - compileSdkVersion 7 + compileSdkVersion 8 defaultConfig { compatibleSdkVersion 7 } @@ -19,8 +18,4 @@ ohos { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) testImplementation 'junit:junit:4.13.1' - ohosTestImplementation 'com.huawei.ohos.testkit:runner:2.0.0.200' -} -decc { - supportType = ['html','xml'] } diff --git a/entry/src/main/config.json b/entry/src/main/config.json index 066dd93d2249bfe6b799e33d31dc554009d6cdc3..625fa926e79f23d59ec57ee6f943d00aa769d916 100644 --- a/entry/src/main/config.json +++ b/entry/src/main/config.json @@ -1,7 +1,7 @@ { "app": { - "bundleName": "com.example.router222", - "vendor": "arouter", + "bundleName": "com.huawei.arouter", + "vendor": "apache", "version": { "code": 1000000, "name": "1.0.0" @@ -9,13 +9,12 @@ }, "deviceConfig": {}, "module": { - "package": "com.huawei.arouter", + "package": "org.apache.myapplication", "name": ".MyApplication", - "mainAbility": "com.huawei.arouter.MainAbility", + "mainAbility": ".MainAbility", + "srcPath": "", "deviceType": [ - "phone", - "tablet", - "car" + "phone" ], "distro": { "deliveryWithInstall": true, @@ -35,10 +34,14 @@ ] } ], + "orientation": "unspecified", "visible": true, - "name": "com.huawei.arouter.MainAbility", + "srcPath": "MainAbility", + "name": ".MainAbility", + "srcLanguage": "ets", "icon": "$media:icon", - "description": "$string:mainability_description", + "description": "$string:description_mainability", + "formsEnabled": false, "label": "$string:entry_MainAbility", "type": "page", "launchType": "standard" @@ -55,7 +58,7 @@ "pages/transit", "pages/returnTo" ], - "name": "default", + "name": ".MainAbility", "window": { "designWidth": 720, "autoDesignWidth": false diff --git a/entry/src/main/ets/default/api/arouter.d.ts b/entry/src/main/ets/MainAbility/api/arouter.d.ts similarity index 100% rename from entry/src/main/ets/default/api/arouter.d.ts rename to entry/src/main/ets/MainAbility/api/arouter.d.ts diff --git a/entry/src/main/ets/default/api/interceptorService.d.ts b/entry/src/main/ets/MainAbility/api/interceptorService.d.ts similarity index 100% rename from entry/src/main/ets/default/api/interceptorService.d.ts rename to entry/src/main/ets/MainAbility/api/interceptorService.d.ts diff --git a/entry/src/main/ets/default/api/logisticsCenter.d.ts b/entry/src/main/ets/MainAbility/api/logisticsCenter.d.ts similarity index 100% rename from entry/src/main/ets/default/api/logisticsCenter.d.ts rename to entry/src/main/ets/MainAbility/api/logisticsCenter.d.ts diff --git a/entry/src/main/ets/default/api/navigationCallback.d.ts b/entry/src/main/ets/MainAbility/api/navigationCallback.d.ts similarity index 100% rename from entry/src/main/ets/default/api/navigationCallback.d.ts rename to entry/src/main/ets/MainAbility/api/navigationCallback.d.ts diff --git a/entry/src/main/ets/default/api/postcard.d.ts b/entry/src/main/ets/MainAbility/api/postcard.d.ts similarity index 100% rename from entry/src/main/ets/default/api/postcard.d.ts rename to entry/src/main/ets/MainAbility/api/postcard.d.ts diff --git a/entry/src/main/ets/default/api/pretreatmenService.d.ts b/entry/src/main/ets/MainAbility/api/pretreatmenService.d.ts similarity index 100% rename from entry/src/main/ets/default/api/pretreatmenService.d.ts rename to entry/src/main/ets/MainAbility/api/pretreatmenService.d.ts diff --git a/entry/src/main/ets/default/app.ets b/entry/src/main/ets/MainAbility/app.ets similarity index 100% rename from entry/src/main/ets/default/app.ets rename to entry/src/main/ets/MainAbility/app.ets diff --git a/entry/src/main/ets/default/arouter/arouter.ets b/entry/src/main/ets/MainAbility/arouter/arouter.ets similarity index 100% rename from entry/src/main/ets/default/arouter/arouter.ets rename to entry/src/main/ets/MainAbility/arouter/arouter.ets diff --git a/entry/src/main/ets/default/arouter/interceptorService.ets b/entry/src/main/ets/MainAbility/arouter/interceptorService.ets similarity index 100% rename from entry/src/main/ets/default/arouter/interceptorService.ets rename to entry/src/main/ets/MainAbility/arouter/interceptorService.ets diff --git a/entry/src/main/ets/default/arouter/logisticsCeter.ets b/entry/src/main/ets/MainAbility/arouter/logisticsCeter.ets similarity index 100% rename from entry/src/main/ets/default/arouter/logisticsCeter.ets rename to entry/src/main/ets/MainAbility/arouter/logisticsCeter.ets diff --git a/entry/src/main/ets/default/arouter/navigationCallback.ets b/entry/src/main/ets/MainAbility/arouter/navigationCallback.ets similarity index 100% rename from entry/src/main/ets/default/arouter/navigationCallback.ets rename to entry/src/main/ets/MainAbility/arouter/navigationCallback.ets diff --git a/entry/src/main/ets/default/arouter/postcard.ets b/entry/src/main/ets/MainAbility/arouter/postcard.ets similarity index 100% rename from entry/src/main/ets/default/arouter/postcard.ets rename to entry/src/main/ets/MainAbility/arouter/postcard.ets diff --git a/entry/src/main/ets/default/arouter/pretreatmenService.ets b/entry/src/main/ets/MainAbility/arouter/pretreatmenService.ets similarity index 100% rename from entry/src/main/ets/default/arouter/pretreatmenService.ets rename to entry/src/main/ets/MainAbility/arouter/pretreatmenService.ets diff --git a/entry/src/main/ets/default/pages/index.ets b/entry/src/main/ets/MainAbility/pages/index.ets similarity index 100% rename from entry/src/main/ets/default/pages/index.ets rename to entry/src/main/ets/MainAbility/pages/index.ets diff --git a/entry/src/main/ets/default/pages/returnTo.ets b/entry/src/main/ets/MainAbility/pages/returnTo.ets similarity index 100% rename from entry/src/main/ets/default/pages/returnTo.ets rename to entry/src/main/ets/MainAbility/pages/returnTo.ets diff --git a/entry/src/main/ets/default/pages/transit.ets b/entry/src/main/ets/MainAbility/pages/transit.ets similarity index 100% rename from entry/src/main/ets/default/pages/transit.ets rename to entry/src/main/ets/MainAbility/pages/transit.ets diff --git a/entry/src/main/java/com/huawei/arouter/MainAbility.java b/entry/src/main/java/com/huawei/arouter/MainAbility.java deleted file mode 100644 index 432f98447d6ec4bd93e0ddae1ac5b289d892d481..0000000000000000000000000000000000000000 --- a/entry/src/main/java/com/huawei/arouter/MainAbility.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.huawei.arouter; - -import ohos.aafwk.content.Intent; -import ohos.ace.ability.AceAbility; - -public class MainAbility extends AceAbility { - @Override - public void onStart(Intent intent) { - super.onStart(intent); - } - - @Override - public void onStop() { - super.onStop(); - } -} diff --git a/entry/src/main/java/com/huawei/arouter/MyApplication.java b/entry/src/main/java/com/huawei/arouter/MyApplication.java deleted file mode 100644 index 7123e814e776fa3316991bfa60df337edaab0f70..0000000000000000000000000000000000000000 --- a/entry/src/main/java/com/huawei/arouter/MyApplication.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.huawei.arouter; - -import ohos.aafwk.ability.AbilityPackage; - -public class MyApplication extends AbilityPackage { - @Override - public void onInitialize() { - super.onInitialize(); - } -} diff --git a/entry/src/main/java/org/apache/myapplication/MainAbility.java b/entry/src/main/java/org/apache/myapplication/MainAbility.java deleted file mode 100644 index 58ab0639aee9b6cb598a66ce98e906957a3a8cf5..0000000000000000000000000000000000000000 --- a/entry/src/main/java/org/apache/myapplication/MainAbility.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.apache.myapplication; - -import ohos.ace.ability.AceAbility; -import ohos.aafwk.content.Intent; - -public class MainAbility extends AceAbility { - @Override - public void onStart(Intent intent) { - super.onStart(intent); - } - - @Override - public void onStop() { - super.onStop(); - } -} diff --git a/entry/src/main/java/org/apache/myapplication/MyApplication.java b/entry/src/main/java/org/apache/myapplication/MyApplication.java deleted file mode 100644 index c2e5cfc1007cf73f50d6fcc1076b4d43bdd2d3e2..0000000000000000000000000000000000000000 --- a/entry/src/main/java/org/apache/myapplication/MyApplication.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.apache.myapplication; - -import ohos.aafwk.ability.AbilityPackage; - -public class MyApplication extends AbilityPackage { - @Override - public void onInitialize() { - super.onInitialize(); - } -} diff --git a/entry/src/main/resources/base/element/string.json b/entry/src/main/resources/base/element/string.json index 14277b0900368e562461cc78aed81b6729298341..b93f540e29265a34f883a977c442fa85349b94ca 100644 --- a/entry/src/main/resources/base/element/string.json +++ b/entry/src/main/resources/base/element/string.json @@ -5,8 +5,8 @@ "value": "entry_MainAbility" }, { - "name": "mainability_description", - "value": "ETS_Empty Ability" + "name": "description_mainability", + "value": "eTS_Empty Ability" } ] } \ No newline at end of file diff --git a/entry/src/main/resources/rawfile/first.jpg b/entry/src/main/resources/rawfile/first.jpg deleted file mode 100644 index b003cf6b3c7ad947543793d81be92cd227da4fbc..0000000000000000000000000000000000000000 Binary files a/entry/src/main/resources/rawfile/first.jpg and /dev/null differ diff --git a/entry/src/ohosTest/ets/default/app.ets b/entry/src/ohosTest/ets/default/app.ets deleted file mode 100644 index 8658c07ca25e8955158335fe74f49a74a52b72fd..0000000000000000000000000000000000000000 --- a/entry/src/ohosTest/ets/default/app.ets +++ /dev/null @@ -1,11 +0,0 @@ -export default { - onCreate() { - console.info('Application onCreate') - }, - onShow() { - console.info('Application onShow') - }, - onDestroy() { - console.info('Application onDestroy') - }, -} diff --git a/entry/src/ohosTest/ets/default/i18n/en-US.json b/entry/src/ohosTest/ets/default/i18n/en-US.json deleted file mode 100644 index 55561b83737c3c31d082fbfa11e5fc987a351104..0000000000000000000000000000000000000000 --- a/entry/src/ohosTest/ets/default/i18n/en-US.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "strings": { - "hello": "Hello", - "world": "World" - }, - "Files": { - } -} \ No newline at end of file diff --git a/entry/src/ohosTest/ets/default/i18n/zh-CN.json b/entry/src/ohosTest/ets/default/i18n/zh-CN.json deleted file mode 100644 index cce1af06761a42add0cac1a0567aa3237eda8cb4..0000000000000000000000000000000000000000 --- a/entry/src/ohosTest/ets/default/i18n/zh-CN.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "strings": { - "hello": "您好", - "world": "世界" - }, - "Files": { - } -} \ No newline at end of file diff --git a/entry/src/ohosTest/ets/default/pages/index/index.ets b/entry/src/ohosTest/ets/default/pages/index/index.ets deleted file mode 100644 index 2bfa0eff1e790f2545358c9bc1c479f750b9fd7d..0000000000000000000000000000000000000000 --- a/entry/src/ohosTest/ets/default/pages/index/index.ets +++ /dev/null @@ -1,49 +0,0 @@ -import {Core, ExpectExtend, InstrumentLog} from "deccjsunit/index" -import testsuite from "../../../test/List.test.ets" -import featureAbility from "@ohos.ability.featureAbility" - -@Entry -@Component -struct MyComponent { - aboutToAppear() { - console.info("start run testcase!!!!") - featureAbility.getWant() - .then((Want) => { - const core = Core.getInstance() - const expectExtend = new ExpectExtend({ - 'id': 'extend' - }) - const instrumentLog = new InstrumentLog({ - 'id': 'report', 'unity': 'true' - }) - core.addService('expect', expectExtend) - core.addService('report', instrumentLog) - core.init() - core.subscribeEvent('spec', instrumentLog) - core.subscribeEvent('suite', instrumentLog) - core.subscribeEvent('task', instrumentLog) - const configService = core.getDefaultService('config') - configService.setConfig(Want.parameters) - testsuite() - core.execute() - console.info('Operation successful. Data: ' + JSON.stringify(Want)); - }) - .catch((error) => { - console.error('Operation failed. Cause: ' + JSON.stringify(error)); - }) - } - - build() { - Flex({ - direction: FlexDirection.Column, - alignItems: ItemAlign.Center, - justifyContent: FlexAlign.Center - }) { - Text('Hello World') - .fontSize(50) - .fontWeight(FontWeight.Bold) - } - .width('100%') - .height('100%') - } -} \ No newline at end of file diff --git a/entry/src/ohosTest/ets/test/ExampleJsunit.test.ets b/entry/src/ohosTest/ets/test/ExampleJsunit.test.ets deleted file mode 100644 index 018aba5e774064d954d53b8fbb3e1ed34f52590d..0000000000000000000000000000000000000000 --- a/entry/src/ohosTest/ets/test/ExampleJsunit.test.ets +++ /dev/null @@ -1,12 +0,0 @@ -import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from "deccjsunit/index" -import app from '@system.app' - -export default function exampleJsunit() { - describe('appInfoTest', function () { - it('app_info_test_001', 0, function () { - var info = app.getInfo() - expect("1.0").assertEqual('1.0') - expect(info.versionCode).assertEqual('3') - }) - }) -} \ No newline at end of file diff --git a/entry/src/ohosTest/ets/test/List.test.ets b/entry/src/ohosTest/ets/test/List.test.ets deleted file mode 100644 index c96221152225c7d3d4bc64859deed72bbee774c0..0000000000000000000000000000000000000000 --- a/entry/src/ohosTest/ets/test/List.test.ets +++ /dev/null @@ -1,5 +0,0 @@ -import exampleJsunit from "../test/ExampleJsunit.test.ets" - -export default function testsuite() { - exampleJsunit() -} \ No newline at end of file diff --git a/entry/src/ohosTest/java/org/apache/myapplication/ExampleOhosTest.java b/entry/src/ohosTest/java/org/apache/myapplication/ExampleOhosTest.java deleted file mode 100644 index ac99fd98819b0218ba6e77ff26fd3637cda9a9c4..0000000000000000000000000000000000000000 --- a/entry/src/ohosTest/java/org/apache/myapplication/ExampleOhosTest.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.apache.myapplication; - -import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -public class ExampleOhosTest { - @Test - public void testBundleName() { - final String actualBundleName = AbilityDelegatorRegistry.getArguments().getTestBundleName(); - assertEquals("org.apache.myapplication", actualBundleName); - } -} \ No newline at end of file diff --git a/entry/src/ohosTest/resources/base/element/string.json b/entry/src/ohosTest/resources/base/element/string.json deleted file mode 100644 index 4388f588a5a0d0c4870e009ac8757faf51598432..0000000000000000000000000000000000000000 --- a/entry/src/ohosTest/resources/base/element/string.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "string": [ - { - "name": "app_name", - "value": "MyApplication" - }, - { - "name": "mainability_description", - "value": "hap sample empty page" - } - ] -} diff --git a/entry/src/ohosTest/resources/base/media/icon.png b/entry/src/ohosTest/resources/base/media/icon.png deleted file mode 100644 index ce307a8827bd75456441ceb57d530e4c8d45d36c..0000000000000000000000000000000000000000 Binary files a/entry/src/ohosTest/resources/base/media/icon.png and /dev/null differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index f59159e865d4b59feb1b8c44b001f62fc5d58df4..63c817f17998697c0097fa6399106b99591c77b9 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://repo.huaweicloud.com/gradle/gradle-6.3-bin.zip +distributionUrl=https\://repo.huaweicloud.com/gradle/gradle-7.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/img.gif b/img.gif new file mode 100644 index 0000000000000000000000000000000000000000..84fb5ac267c28ec3ddb4b11223a2dda196e86110 Binary files /dev/null and b/img.gif differ diff --git a/img.png b/img.png deleted file mode 100644 index c23fe29b72819ef266c11ffbd705b396c19fe570..0000000000000000000000000000000000000000 Binary files a/img.png and /dev/null differ