From 3c02cb3c9613f52110e0cff4f5265fc913cfe28c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E5=8B=A4=E6=B0=91?= Date: Sat, 26 Oct 2024 19:41:15 +0800 Subject: [PATCH] =?UTF-8?q?docs(basic):=20=E6=9B=B4=E6=96=B0=20README=20?= =?UTF-8?q?=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 调整代码示例的缩进和格式,提高可读性 - 新增 RefreshView 组件的使用示例- 更新 SafeView 组件的示例代码 - 优化 HttpHelper 相关代码示例 --- README.md | 219 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 129 insertions(+), 90 deletions(-) diff --git a/README.md b/README.md index 2afb75c..d05d02f 100644 --- a/README.md +++ b/README.md @@ -58,11 +58,11 @@ PreferencesHelper.put(StorageKeys.CLIENT_ID, value) // 获取存储的数据 PreferencesHelper.get(StorageKeys.CLIENT_ID).then(res => { - console.log('>>>>>', res) + console.log('>>>>>', res) }) // 删除存储的数据 PreferencesHelper.delete(StorageKeys.CLIENT_ID).then(() => { - console.log('>>>>>') + console.log('>>>>>') }) ``` @@ -140,8 +140,8 @@ import { XWebHelper } from '@szyx/sdk_base'; const XWebview = import('../pages/XWebview'); XWebHelper.openWeb({ - url: 'https://www.baidu.com', - title: '百度一下', + url: 'https://www.baidu.com', + title: '百度一下', }) ``` @@ -158,50 +158,50 @@ Component struct MyView { - // 控制器,控制开关 - dialogController: XDialogController = {} as XDialogController + // 控制器,控制开关 + dialogController: XDialogController = {} as XDialogController - build() - { - Column() + build() { - Button - ({ buttonStyle: ButtonStyleMode.TEXTUAL }) - { - Image($r('sys.media.ohos_ic_public_more')) - .width(26).height(26) - } - . - width(65) - .onClick(() => { - if (this.dialogController != null) { - this.dialogController.open() - } - }) + Column() + { + Button + ({ buttonStyle: ButtonStyleMode.TEXTUAL }) + { + Image($r('sys.media.ohos_ic_public_more')) + .width(26).height(26) + } + . + width(65) + .onClick(() => { + if (this.dialogController != null) { + this.dialogController.open() + } + }) - XDialogList({ - // 控制器 - controller: this.dialogController, - // 标题(可选) - title: '选择您的操作', - // 选择内容列表 - values: ['刷新', '浏览器打开', '分享', '复制地址'], - // 用户选择事件 - onSelected: (index: number, value: string) => { - ToolsHelper.showMessage(`用户选择了第${index}个,内容为:${value}`) - }, - // 用户取消事件 - onCancel: () => { - ToolsHelper.showMessage('用户取消操作') - }, - // 是否可取消(点击空白处,或者物理返回键) - autoCancel: true - }) + XDialogList({ + // 控制器 + controller: this.dialogController, + // 标题(可选) + title: '选择您的操作', + // 选择内容列表 + values: ['刷新', '浏览器打开', '分享', '复制地址'], + // 用户选择事件 + onSelected: (index: number, value: string) => { + ToolsHelper.showMessage(`用户选择了第${index}个,内容为:${value}`) + }, + // 用户取消事件 + onCancel: () => { + ToolsHelper.showMessage('用户取消操作') + }, + // 是否可取消(点击空白处,或者物理返回键) + autoCancel: true + }) + } + . + width('100%').height('100%') } - . - width('100%').height('100%') - } } ``` @@ -227,29 +227,29 @@ MyView ```typescript HttpHelper.get() - .get>(url.url.startsWith('http') ? url.url : GlobalValue.getInstance().envUrl + url.url, - data ? JSON.stringify(data) : undefined, { - userId: GlobalValue.getInstance().userIds, - clientId: GlobalValue.getInstance().getClientIds(), - version: ConstantValue.VERSION, - deviceType: '01', - timeStamp: timeStamp + '', - sign: sign, - phoneModel: 'sign', - phoneVersion: 'sign', - phoneBrand: 'HarmonyOS' - }, url.apiNo) - .then((res: HttpResult) => { + .get>(url.url.startsWith('http') ? url.url : GlobalValue.getInstance().envUrl + url.url, + data ? JSON.stringify(data) : undefined, { + userId: GlobalValue.getInstance().userIds, + clientId: GlobalValue.getInstance().getClientIds(), + version: ConstantValue.VERSION, + deviceType: '01', + timeStamp: timeStamp + '', + sign: sign, + phoneModel: 'sign', + phoneVersion: 'sign', + phoneBrand: 'HarmonyOS' +}, url.apiNo) + .then((res: HttpResult) => { if (res.status === '0') { - resolve(res.data as T) + resolve(res.data as T) } else { - reject(new Error(res.message)) + reject(new Error(res.message)) } - }) - .catch((error: Error) => { +}) + .catch((error: Error) => { reject(error) - }) +}) ``` ### 3.2.postJson @@ -257,29 +257,29 @@ HttpHelper.get() ```typescript HttpHelper.get() - .post>(url.url.startsWith('http') ? url.url : GlobalValue.getInstance().envUrl + url.url, - data ? JSON.stringify(data) : undefined, { - userId: GlobalValue.getInstance().userIds, - clientId: GlobalValue.getInstance().getClientIds(), - version: ConstantValue.VERSION, - deviceType: '01', - timeStamp: timeStamp + '', - sign: sign, - phoneModel: 'sign', - phoneVersion: 'sign', - phoneBrand: 'HarmonyOS' - }, url.apiNo) - .then((res: HttpResult) => { + .post>(url.url.startsWith('http') ? url.url : GlobalValue.getInstance().envUrl + url.url, + data ? JSON.stringify(data) : undefined, { + userId: GlobalValue.getInstance().userIds, + clientId: GlobalValue.getInstance().getClientIds(), + version: ConstantValue.VERSION, + deviceType: '01', + timeStamp: timeStamp + '', + sign: sign, + phoneModel: 'sign', + phoneVersion: 'sign', + phoneBrand: 'HarmonyOS' +}, url.apiNo) + .then((res: HttpResult) => { if (res.status === '0') { - resolve(res.data as T) + resolve(res.data as T) } else { - reject(new Error(res.message)) + reject(new Error(res.message)) } - }) - .catch((error: Error) => { +}) + .catch((error: Error) => { reject(error) - }) +}) ``` ## 4.[自定义view](./src/main/ets/view) @@ -317,22 +317,61 @@ import { SafeView } from '@szyx/sdk_base' build() { SafeView({ - isLoading: this.isLoading, - titleText: '注册', - onClickLeft:{img:$r("app.media.base_back"), - onClick:()=>{} - }, - onClickRight:{ - text:'添加', - color:'#ff1d9999', - onClick:()=>{} - } + isLoading: this.isLoading, + titleText: '注册', + onClickLeft:{img:$r("app.media.base_back"), + onClick:()=>{} + }, + onClickRight:{ + text:'添加', + color:'#ff1d9999', + onClick:()=>{} + } }){ - // 自己的布局 + // 自己的布局 } } ``` +### 4.3.[RefreshView](./src/main/ets/view/RefreshView.ets) + +> 下拉刷新,上拉加载更多 + +```tsx +import { RefreshView } from '@szyx/sdk_base' + +@State isLoading: boolean = false + + +@Builder +buildItem(item: Item, index: number) { + Column() { + } + .width('100%') +} + +build() { + // ...... + RefreshView({ + isLoading: this.isLoading, + keyGenerator: (item: Item) => { + return item.id + }, + pageSize: 10, + data: this.list ?? [], + customBuilderParam: this.buildItem, + onRefresh: () => { + this.refresh() + }, + onLoadMore: (pageNum) => { + this.refresh(pageNum) + } + }) + // ...... + +} +``` + ## 5.[Windows](./src/main/ets/utils/WindowHelper.ets) ### 5.1.弹出自定义窗口