docs(basic): 更新 README 文档
- 调整代码示例的缩进和格式,提高可读性 - 新增 RefreshView 组件的使用示例- 更新 SafeView 组件的示例代码 - 优化 HttpHelper 相关代码示例
这个提交包含在:
父节点
6e5dfee898
当前提交
3c02cb3c96
219
README.md
219
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<HttpResult<T>>(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<T>) => {
|
||||
.get<HttpResult<T>>(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<T>) => {
|
||||
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<HttpResult<T>>(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<T>) => {
|
||||
.post<HttpResult<T>>(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<T>) => {
|
||||
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.弹出自定义窗口
|
||||
|
||||
正在加载...
在新工单中引用
屏蔽一个用户