hap-view-plugin
Facilitates Mingdao HAP plugin development with scaffolding, debugging tools, and best practice workflows.
Install
mkdir -p .claude/skills/hap-view-plugin && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/12247" && unzip -o skill.zip -d .claude/skills/hap-view-plugin && rm skill.zipInstalls to .claude/skills/hap-view-plugin
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
创建和开发明道云 HAP 自定义视图插件的技能。**立即触发条件**:用户提到"HAP 视图插件"、"自定义视图"、"mdye"、"视图开发"、"插件开发"、"初始化视图项目"、"启动视图调试"。提供完整的开发工作流程、API 使用指南和最佳实践。Key capabilities
- →Install the `mdye-cli` tool globally.
- →Initialize a local project using a React basic example template.
- →Install project dependencies using `npm i`.
- →Start the development environment with hot reloading and live preview.
- →Provide API usage guidance for environment variables, configuration, data fetching, and data manipulation.
How it works
The skill guides the user through the development workflow for Mingdao Cloud HAP custom view plugins, from installing the CLI tool and initializing a project to starting the development environment and using provided APIs.
Inputs & outputs
When to use hap-view-plugin
- →Building HAP plugins
- →Debugging custom views
- →Initializing plugin project
About this skill
HAP 自定义视图插件开发技能
此技能提供创建和开发明道云 HAP 自定义视图插件的完整工作流程和开发规范。
关于此技能
此技能专门用于开发明道云 HAP(High-performance Application Platform)自定义视图插件。通过集成的脚手架工具,可以快速创建 React 基础示例模板项目,安装依赖并启动开发环境。
前置条件
在使用此技能前,确保:
- 已安装 16.20 或更高版本的 Node.js
- 拥有明道云开发者账号和插件开发权限
- 了解基本的 React 开发知识
开发环境配置
Cursor 编辑器配置
下载 mdye-cursorrules.md 文件并复制其中内容到视图开发项目根目录下的 .cursorrules 文件中,即可在 Cursor 编辑器中获得明道云视图插件开发的智能提示和代码规范检查。
教学 DEMO
请下载明道云视图插件开发教学 DEMO,此插件为开发者提供直观、可交互的 API 使用实例。
核心功能
1. 安装 mdye-cli 工具
- 全局安装插件开发专用的命令行工具
- 验证工具安装是否成功
2. 初始化本地项目
- 创建唯一的插件项目文件夹
- 使用 React 基础示例模板
- 生成项目配置文件
3. 安装项目依赖
- 安装项目所需的 npm 依赖包
- 配置开发环境
4. 启动开发环境
- 启动本地开发服务器
- 支持热重载和实时预览
- 提供线上调试能力
开发工作流程
步骤 1:检查并安装 mdye-cli 工具
首先检查是否已安装:
mdye --version
如果显示版本号,说明已安装,可以跳过安装步骤。
如果未安装,根据系统安装:
Mac OS 用户:
sudo npm install -g mdye-cli
Windows/Linux 用户:
npm install -g mdye-cli
验证安装:
mdye --version
步骤 2:初始化本地项目
创建项目命令:
mdye init view --id 693d2fed8474b99be3d3c12e-69563e5df03728c888c04f05 --template React
参数说明:
--id: 插件 ID(示例 ID,实际使用时需要替换)--template React: 使用 React 基础示例模板
项目结构:
mdye_view_69563e5df03728c888c04f05/
├── package.json
├── mdye.json
├── src/
│ ├── index.jsx
│ ├── App.jsx
│ └── styles.less
└── .gitignore
步骤 3:进入项目目录并安装依赖
进入项目目录:
cd mdye_view_69563e5df03728c888c04f05
安装依赖:
npm i
步骤 4:启动开发环境
启动命令:
mdye start
启动后:
- 开发服务器将在
http://localhost:3000/启动 - 将调试地址
http://localhost:3000/bundle.js粘贴到明道云视图配置开发调试输入框 - 支持实时编辑和热重载
API 使用指南
1. 环境变量及配置获取
1.1 获取 env 环境变量
// 使用辅助函数安全获取env中的配置项
function getEnvValue(env, key, defaultValue = null) {
if (!env || !key) return defaultValue;
const value = env[key];
// 处理数组类型(字段选择器)
if (Array.isArray(value)) {
return value.length > 0 ? value[0] : defaultValue;
}
// 处理普通值
return value !== undefined ? value : defaultValue;
}
// 使用示例
const titleFieldId = getEnvValue(env, 'title');
const maxRecords = getEnvValue(env, 'maxRecords', '50');
1.2 获取 config 配置
import { config } from "mdye";
// 获取应用、工作表、视图的ID
const { appId, worksheetId, viewId, controls } = config;
// 获取字段控件信息
const fieldControl = _.find(controls, { controlId: fieldId });
2. 数据获取 API
2.1 获取工作表数据 (getFilterRows)
import { api } from "mdye";
async function loadRecords() {
const result = await api.getFilterRows({
worksheetId, // 必填-工作表ID
viewId, // 必填-视图ID
pageIndex: 1, // 可选-页码
pageSize: 50, // 可选-每页记录数
sortId: "fieldId", // 可选-排序字段
isAsc: true, // 可选-升序排序
// 获取关联字段数据
requestParams: {
plugin_detail_control: relationFieldId
}
});
return result.data; // 记录数组
}
2.2 获取记录详情 (getRowDetail)
async function getRecordDetail(rowId) {
const result = await api.getRowDetail({
appId,
worksheetId,
viewId,
rowId
});
return result.data;
}
2.3 获取关联记录 (getRowRelationRows)
async function loadRelationRows({ controlId, rowId }) {
const result = await api.getRowRelationRows({
worksheetId,
controlId, // 关联字段ID
rowId, // 主记录ID
pageIndex: 1,
pageSize: 10
});
return result.data;
}
3. 数据操作 API
3.1 新增记录 (addWorksheetRow)
async function addRecord(fieldsData) {
const response = await api.addWorksheetRow({
appId,
worksheetId,
receiveControls: [
{
controlId: "fieldId1",
type: 2,
value: "测试文本"
}
]
});
return response;
}
3.2 更新记录 (updateWorksheetRow)
async function updateRecord(rowId, fieldId, newValue) {
const response = await api.updateWorksheetRow({
appId,
worksheetId,
rowId,
newOldControl: [
{
controlId: fieldId,
type: 2,
value: newValue
}
]
});
return response;
}
3.3 删除记录 (deleteWorksheetRow)
async function deleteRecord(rowId) {
const response = await api.deleteWorksheetRow({
appId,
worksheetId,
rowIds: [rowId]
});
return response;
}
4. 工具函数 (utils)
4.1 打开记录详情(推荐使用!)
使用 utils.openRecordInfo 打开明道云原生行记录组件是最佳实践:
优势:
- ✅ 原生体验,与明道云界面一致
- ✅ 功能完整:支持编辑、删除、讨论、日志、附件等所有功能
- ✅ 自动处理权限验证
- ✅ 无需自己开发弹窗 UI
- ✅ 返回操作结果,方便进行数据同步
基础用法:
import { utils } from "mdye";
// 打开记录详情
const handleRecordClick = async (recordId) => {
try {
const result = await utils.openRecordInfo({
appId,
worksheetId,
viewId,
recordId
});
// 处理返回结果
if (result) {
console.log('操作结果:', result);
// 根据操作类型处理
switch (result.action) {
case 'update':
// 记录被更新,刷新数据
console.log('记录已更新:', result.value);
loadRecords(); // 重新加载数据
break;
case 'delete':
// 记录被删除,刷新列表
console.log('记录已删除');
loadRecords(); // 重新加载数据
break;
case 'close':
// 用户关闭弹窗(无修改)
console.log('用户关闭了弹窗');
break;
}
}
} catch (error) {
console.error('打开记录详情失败:', error);
}
};
返回值说明:
{
action: 'update' | 'delete' | 'close', // 操作类型
value: object | null // 更新后的记录数据(仅 action='update' 时)
}
完整的 React Hook 示例(包含自动刷新):
import React, { useEffect, useState } from 'react';
import { config, api, utils } from 'mdye';
function RecordsList() {
const { appId, worksheetId, viewId } = config;
const [records, setRecords] = useState([]);
const [loading, setLoading] = useState(false);
// 加载记录列表
const loadRecords = async () => {
try {
setLoading(true);
const result = await api.getFilterRows({
worksheetId,
viewId,
pageSize: 100,
pageIndex: 1
});
setRecords(result.data || []);
} catch (error) {
console.error('加载记录失败:', error);
} finally {
setLoading(false);
}
};
// 打开记录详情
const handleRecordClick = async (recordId) => {
try {
const result = await utils.openRecordInfo({
appId,
worksheetId,
viewId,
recordId
});
// 自动刷新列表
if (result?.action === 'update' || result?.action === 'delete') {
loadRecords(); // 刷新数据
}
} catch (error) {
console.error('打开记录详情失败:', error);
}
};
// 初始加载
useEffect(() => {
loadRecords();
}, []);
return (
<div>
{loading ? (
<div>加载中...</div>
) : (
<div>
{records.map(record => (
<div
key={record.rowid}
onClick={() => handleRecordClick(record.rowid)}
style={{ cursor: 'pointer' }}
>
{record.title}
</div>
))}
</div>
)}
</div>
);
}
性能优化建议:
// 1. 使用 useCallback 避免重复创建函数
const handleRecordClick = useCallback(async (recordId) => {
const result = await utils.openRecordInfo({
appId, worksheetId, viewId, recordId
});
if (result?.action === 'update' || result?.action === 'delete') {
loadRecords();
}
}, [appId, worksheetId, viewId]);
// 2. 只在需要时刷新
const handleRecordClick = async (recordId) => {
const result = await utils.openRecordInfo({
appId, worksheetId, viewId, recordId
});
// 根据具体操作决定是否刷新
if (result?.action === 'update') {
// 局部更新(性能更好)
setRecords(prev =>
prev.map(r => r.rowid === recordId ? result.value : r)
);
} else if (result?.action === 'delete') {
// 从列表中移除
setRecords(prev => prev.filter(r => r.rowid !== recordId));
}
};
4.2 打开新建记录窗口
utils.openNewRecord({
appId,
worksheetId
}).then(newRecord => {
if (newRecord) {
addLocalRecord(newRecord);
}
});
4.3 选择用户
const users = await utils.selectUsers({
projectId: "orgId1",
unique: false // 是否单选
});
4.4 选择部门
const departments = await utils.selectDepartments({
projectId: "orgId1",
unique: false
});
4.5 选择位置
const location = await utils.selectLocation({
distance: 1000,
defaultPosition: { lat: 39.915, lng: 116.404 },
multiple: false
});
4.6 选择记录
const records = await utils.selectRecord({
projectId: "orgId1",
relateSheetId: "worksheetId1",
multiple: true
});
5. 事件监听
5.1 筛选条件变更事件
import { md_emitter } from "mdye";
useEffect(() => {
const handleFiltersUpdate = (newFilters) => {
console.log('筛选条件已更新:', newFilters);
// 重新获取数据
};
md_emitter.addListener('filters-update', handleFiltersUpdate);
return () => {
md_emitter.removeListener('filters-update', handleFiltersUpdate);
};
}, []);
5.2 新增记录事件
useEffect(() => {
const handleNewRecord = (newRecord) => {
console.log('新增记录:', newRecord);
setRecords(prev => [...prev, newRecord]);
};
md_emitter.addListener('new-record', handleNewRecord);
return () => {
md_emitter.removeListener('new-record', handleNewRecord);
};
}, []);
特殊字段类型处理
⚠️ 重要提示:字段类型编号
明道云字段类型编号与文档中的枚举值不完全一致,开发时务必注意:
根据明道云 API V3 版本的实际字段类型定义:
- Type 9 = 单选 (SingleSelect) ⚠️ 注意不是 type 11
- Type 10 = 多选 (MultipleSelect)
- Type 11 = 下拉 (Dropdown)
完整字段类型对照表(V3 实用版)
| 类型编号 | 枚举名称 | 字段类型 | API 创建 | API 返回 |
|---|---|---|---|---|
| 2 | Text | 文本框 | ✅ | ✅ |
| 3 | PhoneNumber | 手机 | ❌ | ✅ |
| 4 | LandlinePhone | 座机 | ❌ | ✅ |
| 5 | 邮箱 | ❌ | ✅ | |
| 6 | Number | 数值 | ✅ | ✅ |
| 7 | Certificate | 证件 | ❌ | ✅ |
| 8 | Currency | 金额 | ❌ | ✅ |
| 9 | SingleSelect | 单选 | ✅ | ✅ |
| 10 | MultipleSelect | 多选 | ✅ | ✅ |
| 11 | Dropdown | 下拉 | ❌ | ✅ |
| 14 | Attachment | 附件 | ✅ | ✅ |
| 15 | Date | 日期 | ✅ | ✅ |
| 16 | DateTime | 时间 | ✅ | ✅ |
| 19/23/24 | Re |
Content truncated.
When not to use it
- →When the user is not developing a Mingdao Cloud HAP custom view plugin.
- →When the user does not have Node.js 16.20 or higher installed.
- →When the user does not have a Mingdao Cloud developer account or plugin development permissions.
Prerequisites
Limitations
- →Requires Node.js 16.20 or higher.
- →Requires a Mingdao Cloud developer account and plugin development permissions.
- →The skill is specific to HAP custom view plugin development.
How it compares
This skill provides a complete, guided workflow specifically for Mingdao Cloud HAP custom view plugin development, including tool installation, project initialization with a React template, and API usage, which is more specialized than gene
Compared to similar skills
hap-view-plugin side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| hap-view-plugin (this skill) | 0 | 6mo | Review | Intermediate |
| webf-quickstart | 1 | 7mo | Review | Beginner |
| app_runner | 0 | 5mo | Review | Beginner |
| run-wwtt-website | 0 | 1mo | Review | Intermediate |
Try saying
Example prompts that trigger this skill in your AI assistant.
You might also like
webf-quickstart
openwebf
Get started with WebF development - setup WebF Go, create a React/Vue/Svelte project with Vite, and load your first app. Use when starting a new WebF project, onboarding new developers, or setting up development environment.
app_runner
k4ilham
A skill to run the backend (Go Fiber) and frontend (React/Vite) applications. It includes pre-run checks to clear the required ports (8080 and 5173) if they are already in use.
run-wwtt-website
WanderWave-Travel-and-Tours
Run, start, build, screenshot, or test the WanderWave Travel & Tours website (React/Vite frontend + Node/Express backend). Use when asked to run the app, verify a change works visually, take a screenshot, or check a route.
magicpath
tanglg
Search, preview, inspect, and install MagicPath UI components with the magicpath-ai CLI. Use when the user mentions MagicPath, wants to browse or search MagicPath components, preview one, or add one to their project. Also use when the user wants to create a new MagicPath project (workspace for desig
react-email
resend
Use when creating HTML email templates with React components - welcome emails, password resets, notifications, order confirmations, newsletters, or transactional emails.
web-development
TencentCloudBase
Web frontend project development rules. Use this skill when developing web frontend pages, deploying static hosting, and integrating CloudBase Web SDK.