.traerules 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. # Trae Project Coding Rules
  2. ## 1. List Page Architecture
  3. All list pages must follow this standard structure:
  4. ```vue
  5. <template>
  6. <ele-page flex-table>
  7. <!-- 1. Search Section -->
  8. <page-search @search="reload" />
  9. <!-- 2. Table Section -->
  10. <common-table ref="pageRef" :pageConfig="pageConfig" :columns="columns" :tools="false">
  11. <!-- Custom Slots -->
  12. <template #status="{ row }">
  13. <dict-data code="user_info_status" type="tag" :model-value="row.status" />
  14. </template>
  15. <!-- Action Column -->
  16. <template #action="{ row }">
  17. <el-button link type="primary" v-permission="'module:action'" @click="handleAction(row)">
  18. [Action Name]
  19. </el-button>
  20. </template>
  21. </common-table>
  22. <!-- 3. Modals/Drawers -->
  23. <page-edit ref="editRef" @success="reload()" />
  24. </ele-page>
  25. </template>
  26. ```
  27. ## 2. Component Specifications
  28. ### A. Search Component (`components/page-search.vue`)
  29. * **Wrapper**: Must use `<ele-card :body-style="{ paddingBottom: '8px' }">`.
  30. * **Core Component**: Use `<ProSearch>` or `<ProSearch2>`.
  31. * **Configuration**:
  32. * `formItems`: Reactive array defining fields (`type`, `label`, `prop`).
  33. * `initKeys`: Object defining default values.
  34. * **Interaction**: Emit `search` event with query parameters.
  35. ### B. Table Configuration (`index.vue`)
  36. * **`pageConfig` Object**:
  37. * `pageUrl`: Backend API endpoint for pagination (Required).
  38. * `rowKey`: Unique identifier (usually `'id'`).
  39. * `fileName`: Default filename for exports.
  40. * `cacheKey`: Unique key for column caching.
  41. * **`columns` Array**:
  42. * Standard props: `label`, `prop`, `align: 'center'`, `width/minWidth`.
  43. * Action column: `{ columnKey: 'action', label: '操作', width: 200, fixed: 'right', slot: 'action' }`.
  44. ## 3. Common Patterns & Best Practices
  45. ### A. Data Dictionary
  46. * Use `<dict-data>` component for status/enum fields.
  47. * Example: `<dict-data code="dict_code" type="tag" :model-value="row.status" />`
  48. ### B. User Interface
  49. * **Avatars**: Combine `<el-avatar>` with `<ele-text>` in a flex column.
  50. * **Icons**: Import from `@/components/icons` (e.g., `DownloadOutlined`, `PlusOutlined`).
  51. ### C. Interaction Logic
  52. * **Refresh**: `pageRef.value?.reload(where)`.
  53. * **Confirmations**: Use built-in table methods:
  54. ```javascript
  55. pageRef.value?.messageBoxConfirm({
  56. message: 'Confirm text?',
  57. fetch: () => request.post('/api/path', { id: row.id })
  58. });
  59. ```
  60. * **Batch Operations**: Use `pageRef.value?.operatBatch({...})`.
  61. ## 4. Permissions
  62. * Use `v-permission` directive on all action buttons.
  63. * Format: `'module:submodule:action'` (e.g., `'customer:blacklist:remove'`).
  64. ## 5. Dependencies
  65. * **Request Utility**: `import request from '@/utils/request';`
  66. * **Common Table**: `import CommonTable from '@/components/CommonPage/CommonTable.vue';`