newlifex/newlife.cube/modal-organize
Claude Code and agent skill by newlifex/newlife.cube
- community
Checking that the SKILL.md file is still in the repository.
命令式弹窗的代码组织规范与最佳实践。 当用户问"弹窗怎么组织"、"弹窗放哪"、"弹窗目录结构"、"弹窗代码规范"、"新增弹窗怎么写"、"重构弹窗结构"时使用。 核心原则:Vue 组件 + openXxx.ts 打开函数作为"一对"放在一起,按业务归属就近放置。
Install
npx vskill@latest install newlifex/newlife.cube/modal-organizeSKILL.md
命令式弹窗代码组织规范
什么时候用
当需要新增弹窗、重构弹窗结构、或询问弹窗代码应该放在哪里时使用。
核心原则
每个弹窗 = 一个文件夹 = Vue 组件 + openXxx.ts 打开函数
高内聚、易维护、按业务归属就近放置。
推荐结构:页面内部聚合
假设页面是 UserManagement,有新增、编辑、详情、分配角色等弹窗。
文件内容示例
1. 打开函数(openUserForm.ts)
2. 表单组件(UserForm.vue)
3. 主页面调用(index.vue)
为什么这样组织?
| 优势 | 说明 | |
|---|---|---|
| 高内聚 | 弹窗的 UI(.vue)和调用入口(.ts)紧密耦合,修改一个弹窗只需在一个文件夹内完成 | |
| 易定位 | 看到 openAddUser,直接在同级文件夹找 UserForm.vue,不用满项目搜索 | |
| 按页面隔离 | 不同页面的弹窗互不干扰,删除页面直接连 modals/ 一起删除,无残留 | |
| 按需复用 | 如果多个页面共用同一个弹窗(如确认删除),可以将其提升到 src/components/modals/ 公共区域 | |
| 无全局污染 | 弹窗组件不会注册到全局,命令式调用函数也只是普通的 TS 导出,树摇友好 |
跨页面复用:提升到公共组件
当弹窗需要在多个页面使用时,将其提升为公共弹窗组件:
调用时从公共路径导入即可:
Promise 化 vs 回调式
两种调用风格都支持,根据场景选择:
Promise 化(推荐)
适合简单的确认/表单场景,调用方代码更简洁:
回调式
适合复杂场景(需要实时控制弹窗状态、loading 等):
命名约定
| 项目 | 约定 | 示例 | |
|---|---|---|---|
| 文件夹 | kebab-case,描述弹窗用途 | add-edit-user/、user-detail/ | |
| Vue 组件 | PascalCase,描述内容 | UserForm.vue、UserDetail.vue | |
| 打开函数文件 | open + 组件名(小驼峰) | openUserForm.ts | |
| 打开函数名 | open + 用途(小驼峰) | openAddUser()、openEditUser() |
三种内容模式
useModal 支持三种内容模式,按复杂度选择:
| 模式 | 适用场景 | 示例 | |
|---|---|---|---|
component | 复杂表单/交互,独立的 Vue 组件 | 新增/编辑用户表单 | |
config | 简单表单,字段配置化即可 | 简单的新增弹窗 | |
render | 完全自定义渲染逻辑 | 特殊的交互式弹窗 |
component 模式(最常用)
config 模式(简单表单)
支持的组件类型:input、select、textarea(input + type)、switch、inputNumber、radioGroup、checkboxGroup、datePicker
检查清单
新增/重构弹窗时,确认以下几点:
- ✅ 弹窗放在最近的业务归属目录下(页面内 modals/ 或 components/modals/)
- ✅ 每个弹窗有自己的文件夹,包含 .vue 和 openXxx.ts
- ✅ 主页面只导入 openXxx 函数,不直接引用弹窗组件
- ✅ 表单数据类型从 Vue 组件导出,打开函数复用类型
- ✅ 返回 Promise 的函数,取消/关闭时 resolve(null)
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingNewLife.Cube.Vue/skills/modal-organize/SKILL.md
Popularity
- Repository stars
- 629
- Repository forks
- 167
- 7-day trend score
- 32
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/newlifex/newlife.cube/modal-organize)