代码拉取完成,页面将自动刷新
同步操作将从 OpenHarmony-SIG/xutils_bak 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
网络、文件、数据库操作工具库。
npm install @ohos/xutils --save
OpenHarmony npm环境配置等更多内容,请参考 如何安装OpenHarmony npm包 。
import { HttpUtils } from '@ohos/xutils/'
import { HttpMethod } from '@ohos/xutils/'
import { RequestCallBack } from '@ohos/xutils/'
import { RequestParams } from '@ohos/xutils/'
import { ResponseInfo } from '@ohos/xutils/'
import { DbUtils } from '@ohos/xutils/'
import { DaoConfig } from '@ohos/xutils/'
import { QueryCallBack } from '@ohos/xutils/'
import { Selector } from '@ohos/xutils/'
import { BitmapUtils } from '@ohos/xutils/'
import { BitmapLoadCallBack } from '@ohos/xutils/'
//添加Header
@State requestParams: RequestParams = new RequestParams();
this.requestParams.addHeader("Content-Type", "application/json");
//添加传递参数
this.requestParams.addQueryStringParameter("key", "397c9db4cb0621ad0313123dab416668");
this.requestParams.addQueryStringParameter("city", "北京");
//GET请求
new HttpUtils().send(HttpMethod.GET,
"http://apis.juhe.cn/simpleWeather/query?key=397c9db4cb0621ad0313123dab416668&city=北京",
new HttpCallBack())
//POST请求
new HttpUtils().sendParams(HttpMethod.POST,
"http://apis.juhe.cn/simpleWeather/query",
this.requestParams,
new HttpCallBack())
new HttpUtils().download('https://count.liqucn.com/d.php?id=725672&urlos=android&from_type=web',
'xUtils/hsh.apk', null)
//创建数据库
this.db = DbUtils.create(this.config);
//创建表
this.config.setDbName(this.dbName)
this.config.setTableName(this.tableName)
this.config.setCreateTableSql("ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT NOT NULL, AGE INTEGER, SALARY REAL, CODES BLOB")
this.db.createTableIfNotExist();
//插入数据
const valueBucket = {
"NAME": "Lisa",
"AGE": 18,
"SALARY": 100.5,
// @ts-ignore
"CODES": new Uint8Array([1, 2, 3, 4, 5]),
};
this.db.save(valueBucket)
//查询数据
this.db.findAll(Selector.from(this.tableName, this.queryColumns), new DbCallBack());
this.db.findAll(Selector.from(this.tableName, this.queryColumns)
.where("NAME", "equalTo", "Lisa").and("AGE", "equalTo", 18), new DbCallBack());
this.db.findFirst(Selector.from(this.tableName, this.queryColumns)
.where("NAME", "equalTo", "Rose"), new DbCallBack());
//更新数据
this.db.update(valueBucket, Selector.from(this.tableName, this.queryColumns)
.where("NAME", "equalTo", "Rose"));
//删除数据
this.db.delete(Selector.from(this.tableName, this.queryColumns)
.where("NAME", "equalTo", "Rose"));
//删除数据库
this.db.dropDb();
HttpUtils.send()
HttpUtils.sendParams()
HttpUtils.download()
DaoConfig.setDbName()
DaoConfig.setTableName()
DbUtils.findAll()
DbUtils.update()
支持 OpenHarmony API version 8 及以上版本。
|---- xutils
|---- entry # 示例代码文件夹
|---- xutils # xutils库文件夹
|----src
|----main
|----ets
|---- bitmap # 图片操作实现
|---- cache # 缓存实现
|---- db # 数据库操作实现
|---- http # 网络请求操作实现
|---- task # 任务实现
|---- ts-md5 # 加密实现
|---- util # 工具类实现
|---- BitmapUtils.ets # 图片缓存对外类
|---- DbUtils.ets # 数据库操作对外类
|---- HttpUtils.ets # 网络请求操作对外类
|---- index.ets # 对外接口
|---- README.md # 安装使用方法
使用过程中发现任何问题都可以提 Issue 给我们,当然,我们也非常欢迎你给我们发 PR 。
本项目基于 Apache License 2.0 ,请自由地享受和参与开源。
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。