更新记录
1.0.0(2026-05-15) 下载此版本
实现华为AGC云函数调用,示例项目结合华为登录的unionid实现云函数查询云数据库
平台兼容性
uni-app(5.01)
| Vue2 | Vue3 | Chrome | Safari | app-vue | app-nvue | Android | iOS | 鸿蒙 |
|---|---|---|---|---|---|---|---|---|
| - | - | - | - | - | - | - | - | 14 |
| 微信小程序 | 支付宝小程序 | 抖音小程序 | 百度小程序 | 快手小程序 | 京东小程序 | 鸿蒙元服务 | QQ小程序 | 飞书小程序 | 小红书小程序 | 快应用-华为 | 快应用-联盟 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| - | - | - | - | - | - | - | - | - | - | - | - |
uni-app x(5.01)
| Chrome | Safari | Android | iOS | 鸿蒙 | 微信小程序 |
|---|---|---|---|---|---|
| - | - | - | - | - | - |
lzk-HWcloudFunction
简介
lzk-HWcloudFunction 是一款专为 HarmonyOS Next (鸿蒙) 平台设计的 UTS 原生插件。它封装了华为云函数(CloudFoundationKit)的调用逻辑,简化了在 uni-app x 项目中调用云端函数的流程,支持自动处理数据类型转换和异步回调。
功能特性
- ✅ 原生性能:基于 ArkTS 开发,直接调用鸿蒙系统 API。
- ✅ 类型安全:内置完善的 TypeScript/UTS 类型定义。
- ✅ 灵活传参:支持传入
Object对象或JSON字符串作为云函数参数。 - ✅ 异常捕获:统一的错误处理机制,方便前端调试。
使用方式
安装本人发布的华为登录插件配套实现华为账号登录云函数
<template>
<view class="content">
<image class="logo" src="/static/logo.png"></image>
<text class="title">{{ title }}</text>
<button type="primary" @click="handleLogin" class="login-btn">
华为账号登录
</button>
<view v-if="userInfo" class="info-card">
<view class="info-item">
<text class="label">昵称:</text>
<text class="value">{{ userInfo.nickName }}</text>
</view>
<view class="info-item">
<text class="label">UnionID:</text>
<text class="value">{{ userInfo.unionID }}</text>
</view>
</view>
<view v-if="extraInfo" class="info-card success">
<text class="card-title">云函数返回</text>
<text class="value">{{ formatData(extraInfo) }}</text>
</view>
</view>
</template>
<script>
import { huaweiLogin } from '@/uni_modules/lzk-hwLogin'
import { callCloudFunction } from '@/uni_modules/lzk-HWcloudFunction'
export default {
data() {
return {
title: 'Hello',
userInfo: null,
extraInfo: null
}
},
methods: {
handleLogin() {
huaweiLogin({
success: (res) => {
this.userInfo = res;
this.title = `欢迎, ${res.nickName}`;
this.fetchExtraInfo(res.unionID);
},
fail: (err) => {
uni.showToast({ title: err, icon: 'none' });
}
});
},
fetchExtraInfo(unionID) {
uni.showLoading({ title: '加载中...' });
callCloudFunction({
name: 'login',
data: {
operation: "query",
records: { id: unionID }
},
success: (result) => {
uni.hideLoading();
this.extraInfo = result;
},
fail: (err) => {
uni.hideLoading();
uni.showToast({ title: err, icon: 'none' });
}
});
},
formatData(data) {
return typeof data === 'object' ? JSON.stringify(data, null, 2) : String(data);
}
}
}
</script>
<style>
.content {
display: flex;
flex-direction: column;
align-items: center;
padding: 40rpx;
}
.logo {
width: 180rpx;
height: 180rpx;
margin-bottom: 30rpx;
}
.title {
font-size: 32rpx;
color: #333;
margin-bottom: 40rpx;
}
.login-btn {
width: 80%;
margin-bottom: 30rpx;
}
.info-card {
width: 90%;
padding: 20rpx;
margin-top: 20rpx;
background: #f5f5f5;
border-radius: 10rpx;
}
.info-card.success {
background: #e8f5e9;
border: 1px solid #4caf50;
}
.card-title {
font-size: 28rpx;
font-weight: bold;
display: block;
margin-bottom: 10rpx;
}
.info-item {
display: flex;
padding: 8rpx 0;
}
.label {
font-size: 26rpx;
color: #666;
width: 140rpx;
}
.value {
font-size: 26rpx;
color: #333;
flex: 1;
word-break: break-all;
}
</style>

收藏人数:
下载插件并导入HBuilderX
赞赏(0)
下载 0
赞赏 0
下载 11935774
赞赏 1914
赞赏
京公网安备:11010802035340号