随手备份
这个提交包含在:
父节点
5abdbe53de
当前提交
7218719f33
79
README.md
79
README.md
@ -1,4 +1,5 @@
|
||||
# 基础开发工具包
|
||||
|
||||
```shell
|
||||
ohpm install @szyx/sdk_base
|
||||
```
|
||||
@ -6,6 +7,7 @@ ohpm install @szyx/sdk_base
|
||||
## 1.[utils](./src/main/ets/utils)
|
||||
|
||||
### 1.1.[AppStorageHelper](./src/main/ets/utils/AppStorageHelper.ets)
|
||||
|
||||
> 缓存工具类,运行时存储,应用停止运行后清空
|
||||
|
||||
```typescript
|
||||
@ -21,12 +23,14 @@ AppStorageHelper.delete(StorageKeys.CLIENT_ID)
|
||||
```
|
||||
|
||||
### 1.2.[PreferencesHelper](./src/main/ets/utils/PreferencesHelper.ets)
|
||||
|
||||
> 永久存储类,应用停止后也不会清空
|
||||
> 需要验证,更新应用会不会被清理
|
||||
> 可存储类型 `number | string | boolean | Array<number> | Array<string> | Array<boolean> | Uint8Array`
|
||||
|
||||
```typescript
|
||||
import { PreferencesHelper } from '@szyx/sdk_base/Index'
|
||||
|
||||
// 存储数据
|
||||
PreferencesHelper.put(StorageKeys.CLIENT_ID, value)
|
||||
|
||||
@ -41,8 +45,10 @@ PreferencesHelper.delete(StorageKeys.CLIENT_ID).then(() => {
|
||||
```
|
||||
|
||||
### 1.3.[ToolsHelper](./src/main/ets/utils/ToolsHelper.ets)
|
||||
|
||||
> 常用方法工具栏
|
||||
> 基础方法
|
||||
|
||||
#### 1.3.1.弹出Toast提示
|
||||
|
||||
```typescript
|
||||
@ -51,31 +57,63 @@ import { ToolsHelper } from '@szyx/sdk_base';
|
||||
ToolsHelper.showMessage('Hello Word!')
|
||||
```
|
||||
|
||||
#### 1.3.2.打印日志
|
||||
|
||||
> 打印格式:`========>${顶层调用栈}::`
|
||||
|
||||
```typescript
|
||||
import { ToolsHelper } from '@szyx/sdk_base';
|
||||
|
||||
ToolsHelper.log('Hello Word!')
|
||||
```
|
||||
|
||||
#### 1.3.3.获取调用栈第一个
|
||||
|
||||
```typescript
|
||||
import { ToolsHelper } from '@szyx/sdk_base';
|
||||
|
||||
ToolsHelper.getStackKey()
|
||||
```
|
||||
|
||||
#### 1.3.4.获取设备信息
|
||||
|
||||
```typescript
|
||||
import { ToolsHelper } from '@szyx/sdk_base';
|
||||
|
||||
ToolsHelper.getDeviceInfo()
|
||||
```
|
||||
|
||||
### 1.4.[ValidatorHelper](./src/main/ets/utils/ValidatorHelper.ets)
|
||||
|
||||
> 常用正则
|
||||
|
||||
#### 1.4.1.验证手机号
|
||||
|
||||
```typescript
|
||||
import { ValidatorHelper } from '@szyx/sdk_base';
|
||||
|
||||
ValidatorHelper.isPhone('13800000000')
|
||||
```
|
||||
|
||||
### 1.5.[AlgorithmHelper](./src/main/ets/utils/AlgorithmHelper.ets)
|
||||
|
||||
> 计算相关
|
||||
|
||||
#### 1.5.1.验证手机号
|
||||
|
||||
```typescript
|
||||
import { AlgorithmHelper } from '@szyx/sdk_base';
|
||||
|
||||
AlgorithmHelper.calculateDistance(x1, y1, x2, y2)
|
||||
```
|
||||
|
||||
### 1.6.[XWebHelper](./src/main/ets/utils/XWebHelper.ets)
|
||||
|
||||
> 打开webview页面
|
||||
|
||||
```typescript
|
||||
import { XWebHelper } from '@szyx/sdk_base';
|
||||
|
||||
// 必须先引入,否则无法跳转
|
||||
const XWebview = import('../pages/XWebview');
|
||||
|
||||
@ -86,22 +124,33 @@ XWebHelper.openWeb({
|
||||
```
|
||||
|
||||
## 2.[Dialog](./src/main/ets/dialog)
|
||||
|
||||
### 2.1.弹出list选中弹窗
|
||||
|
||||
```typescript
|
||||
import { XDialogController } from '../dialog/XDialogController';
|
||||
import { XDialogList } from '../dialog/XDialogList';
|
||||
|
||||
@Component
|
||||
struct MyView {
|
||||
@
|
||||
Component
|
||||
struct
|
||||
MyView
|
||||
{
|
||||
// 控制器,控制开关
|
||||
dialogController: XDialogController = {} as XDialogController
|
||||
|
||||
build() {
|
||||
Column() {
|
||||
Button({ buttonStyle: ButtonStyleMode.TEXTUAL }) {
|
||||
build()
|
||||
{
|
||||
Column()
|
||||
{
|
||||
Button
|
||||
({ buttonStyle: ButtonStyleMode.TEXTUAL })
|
||||
{
|
||||
Image($r('sys.media.ohos_ic_public_more'))
|
||||
.width(26).height(26)
|
||||
}.width(65)
|
||||
}
|
||||
.
|
||||
width(65)
|
||||
.onClick(() => {
|
||||
if (this.dialogController != null) {
|
||||
this.dialogController.open()
|
||||
@ -127,12 +176,16 @@ struct MyView {
|
||||
autoCancel: true
|
||||
})
|
||||
|
||||
}.width('100%').height('100%')
|
||||
}
|
||||
.
|
||||
width('100%').height('100%')
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
## 3.[网络请求](./src/main/ets/http/HttpHelper.ts)
|
||||
|
||||
## 3.[网络请求](./src/main/ets/http/HttpHelper.ets)
|
||||
|
||||
> 使用时建议二次封装
|
||||
>
|
||||
> 参数定义
|
||||
@ -148,6 +201,7 @@ struct MyView {
|
||||
> ```
|
||||
|
||||
### 3.1.get请求
|
||||
|
||||
```typescript
|
||||
|
||||
HttpHelper.get()
|
||||
@ -175,7 +229,9 @@ struct MyView {
|
||||
reject(error)
|
||||
})
|
||||
```
|
||||
|
||||
### 3.2.postJson
|
||||
|
||||
```typescript
|
||||
|
||||
HttpHelper.get()
|
||||
@ -203,7 +259,9 @@ HttpHelper.get()
|
||||
reject(error)
|
||||
})
|
||||
```
|
||||
|
||||
## 4.[自定义view](./src/main/ets/view)
|
||||
|
||||
### 4.1.[LoadingView](./src/main/ets/view/LoadingView.ets)
|
||||
|
||||
> 封装了loading的根布局
|
||||
@ -225,7 +283,9 @@ build() {
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 5.[Windows](./src/main/ets/utils/WindowHelper.ets)
|
||||
|
||||
### 5.1.弹出自定义窗口
|
||||
|
||||
> 弹出自定义窗口
|
||||
@ -279,9 +339,6 @@ WindowHelper.topRectHeight()
|
||||
WindowHelper.bottomRectHeight()
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
# **** 常见问题
|
||||
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import promptAction from '@ohos.promptAction';
|
||||
import { BusinessError, deviceInfo } from '@kit.BasicServicesKit';
|
||||
import { HashMap, util } from '@kit.ArkTS';
|
||||
import { HashMap } from '@kit.ArkTS';
|
||||
import { DeviceInfo } from '../bean/DeviceInfo';
|
||||
|
||||
export interface Btn {
|
||||
@ -91,6 +91,15 @@ function customDialogBuilder<T>(option: ListOptions<T>, dialogId: number) {
|
||||
* 常用方法
|
||||
*/
|
||||
export class ToolsHelper {
|
||||
/**
|
||||
* 弹出Toast
|
||||
* @param msg
|
||||
*/
|
||||
static log(...args: ESObject[]) {
|
||||
const k = ToolsHelper.getStackKey()?.split('/')
|
||||
console.log(`========>${k?k[k.length-1].split('.')[0]:''}::`, args)
|
||||
}
|
||||
|
||||
/**
|
||||
* 弹出Toast
|
||||
* @param msg
|
||||
@ -224,6 +233,10 @@ export class ToolsHelper {
|
||||
|
||||
private static deviceInfo: DeviceInfo
|
||||
|
||||
/**
|
||||
* 获取设备信息
|
||||
* @returns {@link DeviceInfo}
|
||||
*/
|
||||
static getDeviceInfo() {
|
||||
if (!ToolsHelper.deviceInfo) {
|
||||
ToolsHelper.deviceInfo = new DeviceInfo()
|
||||
|
||||
@ -81,7 +81,7 @@ export class WindowHelper {
|
||||
WindowHelper._bottomRectHeight = avoidArea.bottomRect.height
|
||||
let avoidArea2 = WindowHelper._windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_CUTOUT);
|
||||
WindowHelper._topRectHeight = avoidArea2.topRect.height
|
||||
console.log('=====>', WindowHelper._topRectHeight)
|
||||
// console.log('=====>', WindowHelper._topRectHeight)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
正在加载...
在新工单中引用
屏蔽一个用户