'House conventions for Vue 3 + Element Plus admin pages, each measured in a real 170-page back office: one action entrypoint, fixed list state names, response handling left to the interceptor, comment only the non-obvious business rule, named template handlers, null form defaults, permission codes, dict lookups, delete-and-feedback wording. Use when creating or reviewing a CRUD page, a list page with search and paging, or a modal form in an admin back office.'
Resources
1Install
npx skillscat add zehuichan/zstack/vue-admin-conventions Install via the SkillsCat registry.
Admin page conventions
These are not preferences. Each rule was counted in a production back office of 172 view files (38.7k lines) and is stated with the count that made it a rule. A rule with a low count is marked so: it is either young or being violated, and the fix is to follow the rule, not the drifting majority.
Before adding a rule here, require both: an agent gets it wrong without being told, and you can point at the code that decided it. Anything Prettier, a wrapper component, or a lint rule already enforces stays out.
One action entrypoint per page
Every button and every row action calls handleActions(type, row); the function is a single switch over a kebab-case action name. Found in 81 of 172 files, the most-repeated identifier in the codebase after res.
- Action names:
add,detail,delete,batch-delete,export,submit,audit. A batch action starts withbatch-and reads the selection. A child-object action prefixes the object:order-add. addanddetailshare a case and branch onrow?.id.- An action that needs a row resolves
const target = row ?? selectionRef.value[0]before theswitch. Guard it:ElMessage.warning('请选择数据项')thenif (!target) return. - Inside a case: validate, confirm, request, report, refresh. Never reorder the request before the confirm.
Do not add a second entrypoint beside it (handleDelete, handleSubmit). They appear in this codebase only as leftovers, and they split the page's behaviour across two functions that are read separately.
Fixed list state names
Use these names; do not invent synonyms.
| Name | Shape |
|---|---|
queryParams |
reactive({ pageNum: 1, pageSize: 50, ...fields }) |
loading |
ref(false) |
tableData / total |
ref([]) / ref(0) |
modal |
reactive({ show, id }); a second popup becomes modal.showGenerate |
refresh() |
sets pageNum = 1, then calls query() |
query() |
requests only; writes tableData and total |
query() never resets pageNum; refresh() never contains request code. Mixing them is how a paging control ends up resetting to page 1 on every page change.
The view trusts the response envelope
The request layer handles code centrally. In 172 view files, res.code appears once. Do not write if (res.code === 200), do not branch on msg, and do not toast an error the interceptor already reported.
Read only res.data (53 files), res.rows / res.total (80 files). An error message belongs in request.js; a page that also catches and toasts shows the user two messages for one failure.
A catch that only clears loading is correct here
43 files use catch, and in 30 of them the entire body resets a flag. This is deliberate, not sloppy: the interceptor owns the message, so the page's only remaining job is to stop the spinner.
Write try / finally for the reset when a finally reads more directly. Do not add a catch that re-toasts or logs. Do not swallow an error that the interceptor does not cover — a thrown error from your own code has no other reporter.
Comment the business rule, not the code
Comments of every kind are 0.72% of lines. Line comments (//) total 129 lines, spread over just 43 files — the other 129 of the 172 files carry none at all. The ones that exist cluster on the hardest page: a single file holds 31 of those 129 lines, and the framework wrapper layer holds zero.
Every comment explains why, and the why is a business rule that cannot be read off the code:
// 锁单可在本弹框「解锁提交」解决,无需提示;已审/已核销须到其他页面回退,才给入口指引
// 货物立方:取填写的值和总立方中的较大值Never comment what the next line does, never add a changelog note (// 2026-05-19 修复 xxx), and never comment a name that already says it. A page with no comments is the normal case, not an omission.
Template events are named handlers
867 named handlers against 16 inline arrow functions (98.2% named). Write @click="handleActions('add')" or @click="handleClose", not @click="() => (x = y)". A one-line arrow in a template cannot be unit-tested, cannot be found by any build check, and hides in the markup where nobody reviews it.
Form defaults are null
Form objects lean null over '' (8 objects to 1, counting only objects large enough to have a pattern). null survives the request layer's empty-value filter unchanged, and '' is what the filter exists to remove.
Build a fresh object on every open — dataForm.value = { ...defaultForm } — never hand out the shared one. defaultForm is a plain object held outside ref; the demo page and the order page both do this.
Empty is three values, not one
A cleared el-input writes '', a single el-select writes undefined, a date picker and el-input-number write null. Test for emptiness; do not compare against null. See the reasoning and the source paths in vue-pitfalls.
Permissions and dictionaries
- Permission codes are three colon-separated segments,
module:entity:action(bus:bizorder:add,system:dict:remove). Usev-auth="['perm']"(50 files) for a button,<authority :value="['a','b']">(8 files) for a block; multiple codes are OR-ed. - A dictionary value is displayed with
getDictDataLabel(dictType, value)(68 files) and selected with<api-select :api="dictData" :params="{ dictType: '...' }" />(33 files). Never hardcode a Chinese label beside a code. dictTypecarries a business prefix:bus_trans_type,bus_cargo_type,bus_dest_port,bus_currency_type,yes_or_no.
Delete and feedback wording
Fixed strings; 操作成功 appears in 107 files.
| Case | Text |
|---|---|
| Nothing selected | 请选择数据项 (warning) |
| One row | 是否确认删除此数据项? |
| Many rows | 是否确认删除所选数据项? |
| Confirm dialog title | 系统提示 |
| Success | 操作成功 |
Confirm once. A row using el-popconfirm must not confirm again inside case 'delete'; 22 files have a case 'delete' and 16 use el-popconfirm, so both shapes exist — pick one per page and keep it.
Cache names follow the route name
defineOptions({ name }) must equal the route name; KeepAlive matches on the component name and silently skips a page otherwise. The route name comes from the backend menu or from src/router/modules/*.js, so read the value there rather than inventing one.
This codebase shows the drift to avoid: 21 pages set a name in three incompatible shapes — PascalCase (Order, Dict), a route path (/finance/day), and a local entity/page (biz-order/action). The first two are backend menu values, the third is a local route; all three are correct for their own route, which is exactly why a guessed name is unreliable.
Modal and drawer events
| Event | Meaning | Bind |
|---|---|---|
@opened |
every open, after content mounts | echo the record here |
@confirm |
footer confirm | submit |
@cancel |
wrapper's own cancel event | close and reset |
@close |
passed through to the inner el-dialog |
only when you need "started closing" |
The modal wrapper declares emits: ['cancel', 'confirm'] and forwards $attrs, so @close reaches el-dialog directly. The drawer wrapper declares update:modelValue, cancel, and confirm, and maps the inner close onto cancel — on a drawer, binding both @close and @cancel reaches the handler twice. Bind @cancel on drawers only.
handleCancel must be idempotent: it runs on the close of a successful save too, because the component sets its own visibility to false. Do not prompt or request from it.
Echo on @opened, not on a watch
A modal with destroy-on-close mounts its body on every open, so @opened is the only point where the form ref and the record both exist. A watch on the visibility flag fires earlier, before the body is rendered.
The named handler for it is not standardised in this codebase — getDetail (16), handleOpened (9), initData (7). Use handleOpened in new pages; it is the only name that identifies the event rather than the thing being fetched.
Where the pieces live
| File | Holds |
|---|---|
src/api/{domain}/{entity}.js |
list / get / add / update / del{Entity}, URLs /{module}/{entity}/{action} |
views/{domain}/{entity}/index.vue |
list: search, table, paging, handleActions |
views/{domain}/{entity}/mapping.js |
getSchemas() for the search form, getColumns() for the table |
views/{domain}/{entity}/components/ActionModal.vue |
lightweight edit, emit('refresh') on save |
views/{domain}/{entity}/action.vue |
routed detail page, reads id via useUrlSearchParams('hash') |
Deletes pass ids on the path, comma-joined: /bas/ware/delete/${ids}. Never move a delete id into the body.