ChildrenTable 通用子表组件,该组件主要用于被主表嵌套使用

可能使用的业务场景

  1. 主表一条数据,挂载了子表的多条数据,这样的模式就可以在一个界面编辑,在业务逻辑关系上思路非常紧凑.
  2. 如下的一个主表和子表同时操作的示例界面.

通用子表组件 - 图1

使用指南

  1. // 1.引用组件
  2. import ChildrenTable from '@/components/common/children_table.vue'
  3. // 2.子表组件相关的配置参数一览
  4. // 2.1 在页面使用子表组件
  5. <ChildrenTable :propChildrenTable="childrenTable"/>
  6. // 2.2 子表组件属性(配置)介绍
  7. childrenTable: {
  8. action: propCreateEdit.value.curdFormData.action, // 子表组件使用的场景动作参数:insert、update.
  9. allRows: [], // 结果存储数组
  10. deletedButtonIds: '', // 子表 被删除的id文本格式,例如:1,2,3,4
  11. //定义一行(条)记录所需要的字段
  12. rowField: {
  13. id: 0,
  14. fr_auth_system_menu_id: 0,
  15. fr_auth_button_cn_en_id: 0,
  16. button_name: '',
  17. request_url: '/',
  18. request_method: "*",
  19. short_path: "",
  20. remark: ''
  21. },
  22. // 定义表的一行需要展示的全部字段格式
  23. rowFieldFormat: [
  24. {
  25. name: '按钮名称',//表单名称
  26. type: "dialog",//类型{弹出框}
  27. field: 'button_name',//字段名
  28. // 1.被选择的公共组件必须放置在 ChildrenTable 组件同目录
  29. // 2.命名必须是以 select开头,否则子表找不到组件。
  30. componentPath: './select_button.vue',
  31. width: 3,//宽度,参考 elementPlus 的row、col布局,一个 row 由24个column构成,但是系统会使用一个 col,作为删除按钮列,内容区域最多只能配置23个col
  32. // modalWidth: '900px', // 弹出框宽度
  33. //字段与弹出框组件字段的映射
  34. map: {
  35. fr_auth_button_cn_en_id: 'id',
  36. button_name: 'cn_name',
  37. request_method: 'allow_method'
  38. }
  39. },
  40. {
  41. name: '接口地址',
  42. type: "string",
  43. field: 'request_url',
  44. width: 6,
  45. },
  46. {
  47. name: '接口允许请求方式',
  48. type: "selectOption",
  49. field: 'request_method',
  50. width: 4,
  51. options: [
  52. {
  53. label: "*",
  54. value: "*",
  55. },
  56. {
  57. label: "GET",
  58. value: "GET",
  59. },
  60. {
  61. label: "POST",
  62. value: "POST",
  63. },
  64. ]
  65. },
  66. {
  67. name: '备注',
  68. type: "string",
  69. field: 'remark',
  70. width: 4,
  71. },
  72. {
  73. name: '上传文件',
  74. type: "upload",
  75. field: 'short_path',
  76. width: 5,
  77. },
  78. {
  79. name: '删除',
  80. type: "action",
  81. field: 'action',
  82. width: 2,
  83. },
  84. ],
  85. // 新增界面可以设置默认填充的值
  86. defaultListForCreate: [
  87. {
  88. id: 0,
  89. fr_auth_system_menu_id: 0,
  90. fr_auth_button_cn_en_id: 1,
  91. button_name: '新增',
  92. request_url: '/',
  93. request_method: "POST",
  94. remark: '',
  95. short_path: "",
  96. },
  97. {
  98. id: 0,
  99. fr_auth_system_menu_id: 0,
  100. fr_auth_button_cn_en_id: 2,
  101. button_name: '删除',
  102. request_url: '/',
  103. request_method: "POST",
  104. remark: '',
  105. short_path: "",
  106. },
  107. {
  108. id: 0,
  109. fr_auth_system_menu_id: 0,
  110. fr_auth_button_cn_en_id: 3,
  111. button_name: '修改',
  112. request_url: '/',
  113. request_method: "POST",
  114. remark: '',
  115. short_path: "",
  116. },
  117. {
  118. id: 0,
  119. fr_auth_system_menu_id: 0,
  120. fr_auth_button_cn_en_id: 4,
  121. button_name: '查询',
  122. request_url: '/',
  123. request_method: "GET",
  124. remark: '',
  125. short_path: "",
  126. }
  127. ]
  128. }

最终主表、子表提交的数据格式

  1. # 主表数据
  2. {
  3. "action": "insert",
  4. "fid": 41,
  5. "ftitle": "基础数据",
  6. "title": "测试菜单",
  7. "status": 1,
  8. "sort": 102,
  9. "remark": "测试菜单",
  10. "button_array": [
  11. {
  12. "id": 0,
  13. "fr_auth_system_menu_id": 0,
  14. "fr_auth_button_cn_en_id": 1,
  15. "button_name": "新增",
  16. "request_url": "/test/insert",
  17. "request_method": "POST",
  18. "remark": "",
  19. "short_path": "/public/storage/uploaded/2022_06/9d2e958044648753cb6373b458b1dcfe.jpg"
  20. },
  21. {
  22. "id": 0,
  23. "fr_auth_system_menu_id": 0,
  24. "fr_auth_button_cn_en_id": 2,
  25. "button_name": "删除",
  26. "request_url": "/test/del",
  27. "request_method": "POST",
  28. "remark": "",
  29. "short_path": "/public/storage/uploaded/2022_06/9ab7e0a6743c906a19d4a4e4e915c628.png"
  30. },
  31. {
  32. "id": 0,
  33. "fr_auth_system_menu_id": 0,
  34. "fr_auth_button_cn_en_id": 3,
  35. "button_name": "修改",
  36. "request_url": "/test/edit",
  37. "request_method": "POST",
  38. "remark": "",
  39. "short_path": ""
  40. },
  41. {
  42. "id": 0,
  43. "fr_auth_system_menu_id": 0,
  44. "fr_auth_button_cn_en_id": 4,
  45. "button_name": "查询",
  46. "request_url": "/test/seletc",
  47. "request_method": "GET",
  48. "remark": "",
  49. "short_path": "/public/storage/uploaded/2022_06/daf6fce92b1b2331225655c85988d24a.png"
  50. }
  51. ],
  52. "button_delete": "",
  53. "name": "test_menu"
  54. }

其他说明

  • 主表、子表模式提交的数据比较复杂,需要以json方式提交, 红色标注在提交数据时需要格外关注。

通用子表组件 - 图2