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 => {
|
PreferencesHelper.get(StorageKeys.CLIENT_ID).then(res => {
|
||||||
console.log('>>>>>', res)
|
console.log('>>>>>', res)
|
||||||
})
|
})
|
||||||
// 删除存储的数据
|
// 删除存储的数据
|
||||||
PreferencesHelper.delete(StorageKeys.CLIENT_ID).then(() => {
|
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');
|
const XWebview = import('../pages/XWebview');
|
||||||
|
|
||||||
XWebHelper.openWeb({
|
XWebHelper.openWeb({
|
||||||
url: 'https://www.baidu.com',
|
url: 'https://www.baidu.com',
|
||||||
title: '百度一下',
|
title: '百度一下',
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -158,50 +158,50 @@ Component
|
|||||||
struct
|
struct
|
||||||
MyView
|
MyView
|
||||||
{
|
{
|
||||||
// 控制器,控制开关
|
// 控制器,控制开关
|
||||||
dialogController: XDialogController = {} as XDialogController
|
dialogController: XDialogController = {} as XDialogController
|
||||||
|
|
||||||
build()
|
build()
|
||||||
{
|
|
||||||
Column()
|
|
||||||
{
|
{
|
||||||
Button
|
Column()
|
||||||
({ buttonStyle: ButtonStyleMode.TEXTUAL })
|
{
|
||||||
{
|
Button
|
||||||
Image($r('sys.media.ohos_ic_public_more'))
|
({ buttonStyle: ButtonStyleMode.TEXTUAL })
|
||||||
.width(26).height(26)
|
{
|
||||||
}
|
Image($r('sys.media.ohos_ic_public_more'))
|
||||||
.
|
.width(26).height(26)
|
||||||
width(65)
|
}
|
||||||
.onClick(() => {
|
.
|
||||||
if (this.dialogController != null) {
|
width(65)
|
||||||
this.dialogController.open()
|
.onClick(() => {
|
||||||
}
|
if (this.dialogController != null) {
|
||||||
})
|
this.dialogController.open()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
XDialogList({
|
XDialogList({
|
||||||
// 控制器
|
// 控制器
|
||||||
controller: this.dialogController,
|
controller: this.dialogController,
|
||||||
// 标题(可选)
|
// 标题(可选)
|
||||||
title: '选择您的操作',
|
title: '选择您的操作',
|
||||||
// 选择内容列表
|
// 选择内容列表
|
||||||
values: ['刷新', '浏览器打开', '分享', '复制地址'],
|
values: ['刷新', '浏览器打开', '分享', '复制地址'],
|
||||||
// 用户选择事件
|
// 用户选择事件
|
||||||
onSelected: (index: number, value: string) => {
|
onSelected: (index: number, value: string) => {
|
||||||
ToolsHelper.showMessage(`用户选择了第${index}个,内容为:${value}`)
|
ToolsHelper.showMessage(`用户选择了第${index}个,内容为:${value}`)
|
||||||
},
|
},
|
||||||
// 用户取消事件
|
// 用户取消事件
|
||||||
onCancel: () => {
|
onCancel: () => {
|
||||||
ToolsHelper.showMessage('用户取消操作')
|
ToolsHelper.showMessage('用户取消操作')
|
||||||
},
|
},
|
||||||
// 是否可取消(点击空白处,或者物理返回键)
|
// 是否可取消(点击空白处,或者物理返回键)
|
||||||
autoCancel: true
|
autoCancel: true
|
||||||
})
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
.
|
||||||
|
width('100%').height('100%')
|
||||||
}
|
}
|
||||||
.
|
|
||||||
width('100%').height('100%')
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
@ -227,29 +227,29 @@ MyView
|
|||||||
```typescript
|
```typescript
|
||||||
|
|
||||||
HttpHelper.get()
|
HttpHelper.get()
|
||||||
.get<HttpResult<T>>(url.url.startsWith('http') ? url.url : GlobalValue.getInstance().envUrl + url.url,
|
.get<HttpResult<T>>(url.url.startsWith('http') ? url.url : GlobalValue.getInstance().envUrl + url.url,
|
||||||
data ? JSON.stringify(data) : undefined, {
|
data ? JSON.stringify(data) : undefined, {
|
||||||
userId: GlobalValue.getInstance().userIds,
|
userId: GlobalValue.getInstance().userIds,
|
||||||
clientId: GlobalValue.getInstance().getClientIds(),
|
clientId: GlobalValue.getInstance().getClientIds(),
|
||||||
version: ConstantValue.VERSION,
|
version: ConstantValue.VERSION,
|
||||||
deviceType: '01',
|
deviceType: '01',
|
||||||
timeStamp: timeStamp + '',
|
timeStamp: timeStamp + '',
|
||||||
sign: sign,
|
sign: sign,
|
||||||
phoneModel: 'sign',
|
phoneModel: 'sign',
|
||||||
phoneVersion: 'sign',
|
phoneVersion: 'sign',
|
||||||
phoneBrand: 'HarmonyOS'
|
phoneBrand: 'HarmonyOS'
|
||||||
}, url.apiNo)
|
}, url.apiNo)
|
||||||
.then((res: HttpResult<T>) => {
|
.then((res: HttpResult<T>) => {
|
||||||
if (res.status === '0') {
|
if (res.status === '0') {
|
||||||
resolve(res.data as T)
|
resolve(res.data as T)
|
||||||
} else {
|
} else {
|
||||||
reject(new Error(res.message))
|
reject(new Error(res.message))
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
.catch((error: Error) => {
|
.catch((error: Error) => {
|
||||||
reject(error)
|
reject(error)
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
### 3.2.postJson
|
### 3.2.postJson
|
||||||
@ -257,29 +257,29 @@ HttpHelper.get()
|
|||||||
```typescript
|
```typescript
|
||||||
|
|
||||||
HttpHelper.get()
|
HttpHelper.get()
|
||||||
.post<HttpResult<T>>(url.url.startsWith('http') ? url.url : GlobalValue.getInstance().envUrl + url.url,
|
.post<HttpResult<T>>(url.url.startsWith('http') ? url.url : GlobalValue.getInstance().envUrl + url.url,
|
||||||
data ? JSON.stringify(data) : undefined, {
|
data ? JSON.stringify(data) : undefined, {
|
||||||
userId: GlobalValue.getInstance().userIds,
|
userId: GlobalValue.getInstance().userIds,
|
||||||
clientId: GlobalValue.getInstance().getClientIds(),
|
clientId: GlobalValue.getInstance().getClientIds(),
|
||||||
version: ConstantValue.VERSION,
|
version: ConstantValue.VERSION,
|
||||||
deviceType: '01',
|
deviceType: '01',
|
||||||
timeStamp: timeStamp + '',
|
timeStamp: timeStamp + '',
|
||||||
sign: sign,
|
sign: sign,
|
||||||
phoneModel: 'sign',
|
phoneModel: 'sign',
|
||||||
phoneVersion: 'sign',
|
phoneVersion: 'sign',
|
||||||
phoneBrand: 'HarmonyOS'
|
phoneBrand: 'HarmonyOS'
|
||||||
}, url.apiNo)
|
}, url.apiNo)
|
||||||
.then((res: HttpResult<T>) => {
|
.then((res: HttpResult<T>) => {
|
||||||
if (res.status === '0') {
|
if (res.status === '0') {
|
||||||
resolve(res.data as T)
|
resolve(res.data as T)
|
||||||
} else {
|
} else {
|
||||||
reject(new Error(res.message))
|
reject(new Error(res.message))
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
.catch((error: Error) => {
|
.catch((error: Error) => {
|
||||||
reject(error)
|
reject(error)
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
## 4.[自定义view](./src/main/ets/view)
|
## 4.[自定义view](./src/main/ets/view)
|
||||||
@ -317,22 +317,61 @@ import { SafeView } from '@szyx/sdk_base'
|
|||||||
|
|
||||||
build() {
|
build() {
|
||||||
SafeView({
|
SafeView({
|
||||||
isLoading: this.isLoading,
|
isLoading: this.isLoading,
|
||||||
titleText: '注册',
|
titleText: '注册',
|
||||||
onClickLeft:{img:$r("app.media.base_back"),
|
onClickLeft:{img:$r("app.media.base_back"),
|
||||||
onClick:()=>{}
|
onClick:()=>{}
|
||||||
},
|
},
|
||||||
onClickRight:{
|
onClickRight:{
|
||||||
text:'添加',
|
text:'添加',
|
||||||
color:'#ff1d9999',
|
color:'#ff1d9999',
|
||||||
onClick:()=>{}
|
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.[Windows](./src/main/ets/utils/WindowHelper.ets)
|
||||||
|
|
||||||
### 5.1.弹出自定义窗口
|
### 5.1.弹出自定义窗口
|
||||||
|
|||||||
正在加载...
在新工单中引用
屏蔽一个用户