jinlin
2024-02-01 2df883fcbed176f83d8d144fd007e7f72fcb54d6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { colWrapper } from './common/htmlWrapper'
import getSimpleComponentHtml from './common/simpleComponentHtmlFactory'
 
// 创建“el-form-item”
function createFormItemHtmls(formJson, row) {
  const formItemHtmls = row.__config__.children.map(
    child => getSimpleComponentHtml(formJson, child, row, false)
  )
 
  return formItemHtmls.join('\n')
}
 
// 创建“el-row”
function createRowHtml(row, formItemHtmls) {
  const type = row.type === 'default' ? '' : `type="${row.type}"`
  const justify = row.type === 'default' ? '' : `justify="${row.justify}"`
  const align = row.type === 'default' ? '' : `align="${row.align}"`
  const gutter = row.gutter ? `:gutter="${row.gutter}"` : ''
 
  return `
    <el-row ${type} ${justify} ${align} ${gutter}>
        ${formItemHtmls}
    </el-row>
    `
}
 
/**
 * 获取“行容器”HTML
 * @param formJson 表单结构
 * @param row “行容器”组件
 * @param parent 父组件(dialog, table, row...)
 * @param isSomeSpanUnequal24 是否有的组件“span”不等于“24”
 * @returns {string} “行容器”HTML
 */
export default function getRowHtml(formJson, row, parent, isSomeSpanUnequal24) {
  // 创建“el-form-item”
  const formItemHtmls = createFormItemHtmls(formJson, row)
 
  // 创建“el-row”
  let rowHtml = createRowHtml(row, formItemHtmls)
 
  // span不为24的用“el-col”包裹“el-form-item”
  if (isSomeSpanUnequal24) {
    rowHtml = colWrapper(row, rowHtml)
  }
 
  return rowHtml
}