|
@@ -12,17 +12,17 @@ ohpm install @szyx/sdk_base
|
|
// 初始化
|
|
// 初始化
|
|
import { WindowHelper } from '@szyx/sdk_base';
|
|
import { WindowHelper } from '@szyx/sdk_base';
|
|
export default class AppAbility extends UIAbility {
|
|
export default class AppAbility extends UIAbility {
|
|
- onWindowStageCreate(windowStage: window.WindowStage): void {
|
|
|
|
-
|
|
|
|
- windowStage.loadContent('pages/Index', (err) => {
|
|
|
|
- if (err.code) {
|
|
|
|
- hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- // 这行代码
|
|
|
|
- GlobalContext.setContext(this.context)
|
|
|
|
- }
|
|
|
|
|
|
+ onWindowStageCreate(windowStage: window.WindowStage): void {
|
|
|
|
+
|
|
|
|
+ windowStage.loadContent('pages/Index', (err) => {
|
|
|
|
+ if (err.code) {
|
|
|
|
+ hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ // 这行代码
|
|
|
|
+ GlobalContext.setContext(this.context)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
```
|
|
```
|
|
|
|
|
|
@@ -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('>>>>>')
|
|
})
|
|
})
|
|
```
|
|
```
|
|
|
|
|
|
@@ -157,7 +157,7 @@ ToolsHelper.showAlertDialog({
|
|
msg: '提示信息',
|
|
msg: '提示信息',
|
|
action: {
|
|
action: {
|
|
onClick: () => {
|
|
onClick: () => {
|
|
-
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|
|
})
|
|
})
|
|
@@ -174,8 +174,6 @@ ToolsHelper.showAlertDialog({
|
|
>
|
|
>
|
|
> `注意,传入参数(options: AlertBean)是固定的`
|
|
> `注意,传入参数(options: AlertBean)是固定的`
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
### 1.4.[ValidatorHelper](./src/main/ets/utils/ValidatorHelper.ets)
|
|
### 1.4.[ValidatorHelper](./src/main/ets/utils/ValidatorHelper.ets)
|
|
|
|
|
|
> 常用正则
|
|
> 常用正则
|
|
@@ -219,8 +217,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',
|
|
|
|
- title: '百度一下',
|
|
|
|
|
|
+ url: 'https://www.baidu.com',
|
|
|
|
+ title: '百度一下',
|
|
})
|
|
})
|
|
```
|
|
```
|
|
|
|
|
|
@@ -328,6 +326,20 @@ import { TimeHelper } from '@szyx/sdk_base'
|
|
TimeHelper.getMonthDays()
|
|
TimeHelper.getMonthDays()
|
|
```
|
|
```
|
|
|
|
|
|
|
|
+### 1.8.[ImageHelper](./src/main/ets/utils/ImageHelper.ets)
|
|
|
|
+
|
|
|
|
+#### 1.8.1 压缩图片到指定大小
|
|
|
|
+
|
|
|
|
+```tsx
|
|
|
|
+import { ImageHelper } from '@szyx/sdk_base'
|
|
|
|
+
|
|
|
|
+ImageHelper.compressedImage(pixelMap, this.maxCompressedImageSize).then((data: ArrayBuffer) => {
|
|
|
|
+ // 压缩后到图片数据
|
|
|
|
+}).catch((err: BusinessError) => {
|
|
|
|
+ ToolsHelper.showMessage(err.message)
|
|
|
|
+})
|
|
|
|
+```
|
|
|
|
+
|
|
## 2.[Dialog](./src/main/ets/dialog)
|
|
## 2.[Dialog](./src/main/ets/dialog)
|
|
|
|
|
|
### 2.1.弹出list选中弹窗
|
|
### 2.1.弹出list选中弹窗
|
|
@@ -338,50 +350,50 @@ import { XDialogList } from '../dialog/XDialogList';
|
|
|
|
|
|
@Component
|
|
@Component
|
|
struct MyView{
|
|
struct MyView{
|
|
- // 控制器,控制开关
|
|
|
|
- dialogController: XDialogController = {} as XDialogController
|
|
|
|
|
|
+ // 控制器,控制开关
|
|
|
|
+ dialogController: XDialogController = {} as XDialogController
|
|
|
|
|
|
- build()
|
|
|
|
|
|
+ build()
|
|
|
|
+ {
|
|
|
|
+ Column()
|
|
{
|
|
{
|
|
- 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
|
|
|
|
- })
|
|
|
|
-
|
|
|
|
|
|
+ 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()
|
|
}
|
|
}
|
|
- .
|
|
|
|
- width('100%').height('100%')
|
|
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ XDialogList({
|
|
|
|
+ // 控制器
|
|
|
|
+ controller: this.dialogController,
|
|
|
|
+ // 标题(可选)
|
|
|
|
+ title: '选择您的操作',
|
|
|
|
+ // 选择内容列表
|
|
|
|
+ values: ['刷新', '浏览器打开', '分享', '复制地址'],
|
|
|
|
+ // 用户选择事件
|
|
|
|
+ onSelected: (index: number, value: string) => {
|
|
|
|
+ ToolsHelper.showMessage(`用户选择了第${index}个,内容为:${value}`)
|
|
|
|
+ },
|
|
|
|
+ // 用户取消事件
|
|
|
|
+ onCancel: () => {
|
|
|
|
+ ToolsHelper.showMessage('用户取消操作')
|
|
|
|
+ },
|
|
|
|
+ // 是否可取消(点击空白处,或者物理返回键)
|
|
|
|
+ autoCancel: true
|
|
|
|
+ })
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
+ .
|
|
|
|
+ width('100%').height('100%')
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
```
|
|
```
|