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