Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

AddOrUpdateConfig.md 7.2 KiB

před 2 roky
před 2 roky
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. # Add Or Update Dialog Configs
  2. > 通过传入合理的配置项来使用 addOrUpdate Dialog
  3. ## 用途
  4. 通过给对话框传递配置项,并自动根据这些配置项来初始化对话框的功能
  5. ## props
  6. - configs 对象
  7. ```
  8. <my-dialog :configs="SomeConfigs" ... />
  9. type Operation = {
  10. name: 'add' | 'edit' | 'detail' | 'delete' | ...,
  11. url: string, /** 该操作需要的接口地址,如删除接口 */
  12. showAlways: boolean,
  13. showOnEdit: boolean,
  14. permission: string,
  15. }
  16. type SubTableConfig = {
  17. [_:string]: any,
  18. title: string, /** 表格的名称 */
  19. url: string, /** 涉及的接口 */
  20. tableConfigs: {
  21. [_:string]: any,
  22. type?: 'index' | ...,
  23. prop: string,
  24. name: string,
  25. rules?: any[],
  26. fixed?: string,
  27. width?: string,
  28. subcomponent: VueComponent,
  29. options: any[],
  30. formField: boolean, /** 是否在新增编辑子表单里出现该字段 */
  31. }[], /** 表格prop配置数组,参考 components/base-table 组件和 element-ui 文档 */
  32. }
  33. type ExtraComponent = {
  34. name: string,
  35. label: string,
  36. hasModel: boolean, /** 是否需要为该组件设置 v-model */
  37. component: VueComponent, /** 动态加载的 vue 组件 */
  38. props: {
  39. [_:string]: string | object
  40. extraParams?: { /** 上传组件使用 */
  41. typeCode: string
  42. }
  43. }[]
  44. }
  45. type Field = {
  46. [_:string]: string | boolean | object | object[],
  47. name: string,
  48. type?: 'input' | 'select' | ...,
  49. options?: any[], /** 设置 type 为 select 时的选项数据 */
  50. label?: string, /** 没有时会用 name 替代 */
  51. placeholder?: string, /** 没有时会生成默认占位符 */
  52. api?: string, /** 如果有该字段,就自动从api地址获取数据并填充到对应的输入框里,一般为 getCode 的接口 */
  53. relatedField?: string, /** 关联字段,当设置此字段时,意味着需要在对话框组件上监听 select-change 事件,并当该字段数据被改变时刷新 relatedField 的列表,一般是像选择产线时更新工段列表这样的场景使用 */,
  54. required?: boolean, /** 验证规则的简写,只需要限制必填项时,不需要其他验证规则时使用 */
  55. rules?: object[], /** 规则设置参考 element-ui 的表单验证配置 */
  56. }
  57. type Configs = {
  58. type: 'dialog',
  59. infoUrl: string, /** 编辑时获取信息的接口地址 */
  60. fields: Field[],
  61. extraComponents?: ExtraComponent[],
  62. subtable?: SubTableConfig[],
  63. operations?: Operation[]
  64. }
  65. ```
  66. ## 示例
  67. ```js
  68. const addOrUpdateConfigs = {
  69. type: 'dialog', // dialog | drawer | page
  70. infoUrl: '/monitoring/product',
  71. fields: [
  72. 'name',
  73. {
  74. name: 'code',
  75. api: '/monitoring/product/getCode'
  76. },
  77. {
  78. name: 'processTime',
  79. label: '加工时间',
  80. placeholder: '请输入加工时间',
  81. type: 'number', // type: number(input+number) | default(input) | textarea | select(options在父组件里获取) | datetime
  82. required: true,
  83. rules: [
  84. // 除了required之外的验证规则
  85. {
  86. type: 'number',
  87. trigger: 'blur',
  88. transform: val => Number(val),
  89. message: '必须输入数字'
  90. }
  91. ]
  92. },
  93. 'remark',
  94. 'specifications',
  95. {
  96. name: 'typeDictValue',
  97. rules: [{ required: true, trigger: 'blur' }],
  98. label: '产品类型', // 对于非常见属性,最好自己指定label
  99. type: 'select',
  100. options: [
  101. // 动态获取
  102. ]
  103. },
  104. {
  105. name: 'unitDictValue',
  106. label: '单位',
  107. type: 'select',
  108. placeholder: '请选择单位',
  109. options: [
  110. // 动态获取
  111. ]
  112. }
  113. ],
  114. operations: [
  115. // { name: 'reset', url: true },
  116. { name: 'cancel', url: true, showAlways: true },
  117. { name: 'save', url: '/monitoring/product', permission: '', showOnEdit: false },
  118. { name: 'update', url: '/monitoring/product', permission: '', showOnEdit: true }
  119. ],
  120. subtable: {
  121. // for i18n
  122. title: '动态属性',
  123. url: '/monitoring/productArrt',
  124. tableConfigs: [
  125. { type: 'index', name: '序号' },
  126. { prop: 'createTime', name: '添加时间', filter: val => (val ? moment(val).format('YYYY-MM-DD hh:mm:ss') : '-') },
  127. { prop: 'name', name: '属性名', formField: true, rules: [{ required: true, message: '必填', trigger: 'blur' }] },
  128. { prop: 'code', name: '属性值', formField: true },
  129. { prop: 'operations', name: '操作', fixed: 'right', width: 180, subcomponent: TableOperateComponent, options: ['edit', 'delete'] }
  130. ]
  131. },
  132. extraComponents: [
  133. {
  134. name: 'CompName',
  135. label: 'markdown编辑器',
  136. component: () => import('xx.vue')
  137. }
  138. ]
  139. }
  140. ```
  141. ## 配置项解释
  142. <br>
  143. ### type
  144. 类型: string
  145. 值:dialog | drawer | page
  146. 含义:对话框、抽屉、新页面
  147. ### infoUrl
  148. 类型:string
  149. 含义:详情的接口,如 `/monitoring/product`
  150. ### fields
  151. 含义:设置新增、编辑时的字段
  152. 类型:`Array<string | object>`
  153. - 当类型为 string 时,默认渲染 `<input>`
  154. - 当类型为 object 时,有如下选项:
  155. - name: 字段名
  156. - label: 字段的 label
  157. - api: 如果设置了该属性,则该字段会自动从服务器获取值,一般为 code 字段需要
  158. - placeholder
  159. - type: 渲染何种类型的组件,默认值: 'input'
  160. - options: 当上一条 type 值为 'select' 时,需要自行动态获取并加载 options 列表
  161. - required: 是否是必须填写的字段(或可用过 rules 做更加具体的设定,设定方式参考 async-validator )
  162. - rules: 验证规则数组,如果只有"必填"的需求,可直接用上一条
  163. ### operations
  164. 含义:设置对话框等组件里,需要哪些按钮
  165. 类型:`Array<object>`
  166. 属性:
  167. - name,按钮的类型,决定按钮的文字和颜色
  168. - url,按钮操作的接口地址,不需要的可以给 null 或 true
  169. - permission,该操作需要的权限,如 "sys:xxx:add" 形式
  170. - showOnEdit: boolean,是否编辑页面展示,不设置则始终展示
  171. 示例:
  172. ```js
  173. operations: [
  174. { name: 'reset', url: true },
  175. { name: 'cancel', url: true, showAlways: true },
  176. { name: 'save', url: '/monitoring/product', permission: '', showOnEdit: false },
  177. { name: 'update', url: '/monitoring/product', permission: '', showOnEdit: true }
  178. ],
  179. ```
  180. ### subtable
  181. 含义:有些对话框里需要额外的表格来展示更深层次的数据,如“产品属性”
  182. 类型:object
  183. 选项:
  184. - title, 内嵌表格的标题
  185. - url, 内嵌表格的数据地址
  186. - tableConfigs,内嵌表格的配置选项
  187. - 类型:`Array<object>`
  188. - 配置:
  189. - type: 同 element-ui 的 table 属性的 type
  190. - fixed: 同 element-ui 的 table 属性的 fixed
  191. - width: 同 element-ui 的 table 属性的 width
  192. - name: 表头显示的内容
  193. - filter: 一般用于转换时间
  194. - prop: 字段
  195. - formField: boolean, 是否用于表单的填写
  196. - rules: 表单验证规则,详见:async-validator
  197. - subcomponent: 同 base-table 的 subcomponent
  198. - options: 表格操作列需要哪些操作
  199. - 值:`edit` | `delete` | `detail`,需要其他可自行添加(修改 base-table 组件)
  200. ### extraComponents
  201. 含义: 需要在对话框里使用的自定义组件列表
  202. 类型: Array<object>
  203. 对象选项:
  204. - name: 该组件对应的 dataForm 字段(需要参照后端文档来指定)
  205. - hasModel: boolean, 上传组件一般设置为 false,设置是否和 dataForm 关联
  206. - label
  207. - fieldType: 设置该组件的数据将以什么数据类型形式来保存
  208. - component: 组件
  209. - props 传给组件的配置