# harmonyTools **Repository Path**: ChuckHai/harmony-tools ## Basic Information - **Project Name**: harmonyTools - **Description**: Tools是一个辅助开发的工具类集合 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-04-12 - **Last Updated**: 2024-11-23 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Tools Tools是一个辅助开发的工具类集合 ## 开发环境 DevEco Studio NEXT Developer Preview1,Build Version: 4.1.3.500 Api版本:11 hvigorVersion:4.0.2 ## 安装 ``` ohpm install @chuck/tools ``` ## 基础类 | 模块 | 介绍 | | --------------- | -------------------------------------------- | | preferencesUtil | 首选项封装util | | permissionUtil | 权限申请封装,支持多个权限判断和申请 | | MyDataSource | LazyForEach的IDataSource页面数据优化的封装类 | | .... | ...... | ## 使用 - preferencesUtil ```javascript /** * 存入数据 */ preferencesUtil.saveData("key", "hello harmonyOS") /** * 取数据 */ preferencesUtil.getData("key", "") /** * 订阅数据变更,订阅的数据发生变更后,在执行flush方法后,触发callback回调。 */ preferencesUtil.on((value)=>{}) /** * 取消订阅数据变更 */ preferencesUtil.off((value)=>{}) ``` - permissionUtil ```javascript /** * 判断权限 */ let permissionStatus = await permissionUtil.checkPermission(["ohos.permission.WRITE_MEDIA","ohos.permission.CAMERA"]) if (permissionStatus[0] == abilityAccessCtrl.GrantStatus.PERMISSION_GRANTED && permissionStatus[1] == abilityAccessCtrl.GrantStatus.PERMISSION_GRANTED) { promptAction.showToast({ message: "已授权" }) } /** * 申请权限 */ permissionUtil.applyPermission(this.context, ["ohos.permission.WRITE_MEDIA", "ohos.permission.CAMERA"], () => { promptAction.showToast({ message: "已授权" }) }) ``` - MyDataSource ```javascript private arr: MyDataSource = new MyDataSource() List({ space: 10 }) { LazyForEach(this.arr, (item: string) => { ListItem() { this.itemBuild(item) } }, (item: string, index: number) => { return JSON.stringify(item) + index }) } /** * 设置数据 * @param dataArray */ this.arr.setData(tmp) /** * 添加数据 * @param items */ this.arr.addData(...items: T[]) /** * 插入一条数据 * @param index * @param items */ this.arr.insertData(index: number, item: T) /** * 删除一条数据 * @param index */ this.arr.delData(index: number) /** * 变更一条数据 * @param index * @param items */ this.arr.updateData(index: number, item: T) ``` ## License ```java Copyright (C) AbnerMing, HarmonyOsTab Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ```