Skip to content

Commit

Permalink
提交1.0.8版本
Browse files Browse the repository at this point in the history
  • Loading branch information
AbnerMing committed Aug 13, 2024
1 parent 598e231 commit aaf150b
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 20 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ modelVersion:5.0.0

## 主要功能点

<p align="center">当前版本:<i><span style="color:#ff0000;">1.0.7</span></i></p>
<p align="center">当前版本:<i><span style="color:#ff0000;">1.0.8</span></i></p>

- 1、**支持全局初始化**
- 2、 **支持统一的BaseUrl**
Expand Down Expand Up @@ -49,14 +49,14 @@ ohpm install @abner/net
方式二:在工程的oh-package.json5中设置三方包依赖,配置示例如下:

```
"dependencies": { "@abner/net": "^1.0.7"}
"dependencies": { "@abner/net": "^1.0.8"}
```

<p align="center"><img src="https://vipandroid-image.oss-cn-beijing.aliyuncs.com/harmony/net/net_243_001.png" width="300"></p>

### 2、本地静态共享包har包使用【不推荐】

<p>首先,下载har包,<a href="https://vipandroid-image.oss-cn-beijing.aliyuncs.com/harmony/net/net-1.0.7.har">点击下载</a></p>
<p>首先,下载har包,<a href="https://vipandroid-image.oss-cn-beijing.aliyuncs.com/harmony/net/net-1.0.8.har">点击下载</a></p>
<p>下载之后,把har包复制项目中,目录自己创建,如下,我创建了一个libs目录,复制进去</p>
<p><img src="https://vipandroid-image.oss-cn-beijing.aliyuncs.com/harmony/net/net_243_002.png"></p>
<p>引入之后,进行同步项目,点击Sync Now即可,当然了你也可以,将鼠标放置在报错处会出现提示,在提示框中点击Run 'ohpm install'。</p>
Expand Down Expand Up @@ -109,6 +109,7 @@ Net.getInstance().init({
| httpContext | Context | 使用缓存时,传递的上下文,用缓存时必填 |
| cacheBundleName | string | 包名, 用缓存时必填 |
| loadingDialog | WrappedBuilder\<[]\> | 全局的dialog |
| closeLog | boolean | 是否关闭日志 |

### 设置请求头拦截

Expand Down
Binary file removed entry/libs/net-1.0.7.har
Binary file not shown.
Binary file added entry/libs/net-1.0.8.har
Binary file not shown.
8 changes: 4 additions & 4 deletions entry/oh-package-lock.json5

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion entry/oh-package.json5
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"author": "",
"license": "",
"dependencies": {
"@abner/net": "file:./libs/net-1.0.7.har"
"@abner/net": "file:./libs/net-1.0.8.har"
}
}

3 changes: 2 additions & 1 deletion entry/src/main/ets/pages/App.ets
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Net } from '@abner/net'
import { Net, NetLog } from '@abner/net'
import { AbilityStage } from '@kit.AbilityKit'
import { CustomNetPlugin } from './CustomNetPlugin'

Expand All @@ -13,5 +13,6 @@ export default class App extends AbilityStage {
resultTag: ["items"]
})
//Net.getInstance().addNetPlugins(new CustomNetPlugin())

}
}
8 changes: 7 additions & 1 deletion entry/src/main/ets/pages/CustomNetPlugin.ets
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* DATE:2023/10/24
* INTRODUCE:网络库插件 处理接口加密,动态获取header
* */
import { BaseNetPlugin, NetRequest } from '@abner/net';
import { BaseNetPlugin, NetError, NetRequest } from '@abner/net';
import http from '@ohos.net.http';

export class CustomNetPlugin extends BaseNetPlugin {
Expand All @@ -15,13 +15,19 @@ export class CustomNetPlugin extends BaseNetPlugin {

}

error(request: NetRequest, response: http.HttpResponse, error: NetError): void {

}

prepareRequest(request: NetRequest): Promise<NetRequest> {
return new Promise((resolve: Function) => {
resolve(request)
});
}


processResult(request: NetRequest, result: http.HttpResponse): Promise<http.HttpResponse> {

return new Promise((resolve: Function) => {
resolve(result)
});
Expand Down
18 changes: 8 additions & 10 deletions entry/src/main/ets/pages/Index.ets
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ struct Index {
.fontSize(50)
.fontWeight(FontWeight.Bold)
.onClick(() => {
this.doHttp()
// Net.get("cert/AbnerGetIndexBanner.php")
// .showDialogLoading()
// .request<ItemBean[]>((data) => {
// console.log("=====" + data.length)
// }, (error) => {
// console.log("=====" + JSON.stringify(error))
// })
// this.doHttp()
Net.get("cert/AbnerGetIndexBanner.ph")
.showDialogLoading()
.request<ItemBean[]>((data) => {
console.log("=====" + data.length)
}, (error) => {
console.log("=====" + JSON.stringify(error))
})

// let json = "{\"code\":0,\"message\":\"你好\"}"
// let testBean = JSON.parse(json) as TestBean
Expand Down Expand Up @@ -88,8 +88,6 @@ struct Index {
return undefined
}



down() {
Net.downLoadFile("http://10.47.26.83:8088/json/14_151_2_8_1719217390000.mp4")
.setContext(EntryAbility.cx!)
Expand Down

0 comments on commit aaf150b

Please sign in to comment.