jinlin
2024-02-23 1772fc5e211f9e9e0ab4cdc6c29b436aac178c2a
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
import { getVModelHtml, formItemWrapper, colWrapper } from './common/htmlWrapper'
 
// 创建“el-input”
function createInputHtml(formJson, oneText, parent) {
  const vModel = getVModelHtml(formJson, oneText, parent)
  const placeholder = oneText.placeholder ? `placeholder="${oneText.placeholder}"` : ''
  const width = oneText.style && oneText.style.width ? ':style="{width: \'100%\'}"' : ''
  const disabled = oneText.disabled ? ':disabled=\'true\'' : ''
  const maxlength = oneText.maxlength ? `:maxlength="${oneText.maxlength}"` : ''
  const readonly = oneText.readonly ? 'readonly' : ''
 
  return `<el-input ${vModel} ${placeholder} ${maxlength} ${readonly} ${disabled} ${width}></el-input>`
}
 
/**
 * 获取“单行文本”HTML
 * @param formJson 表单结构
 * @param oneText “单行文本”组件
 * @param parent 父组件(dialog, table...)
 * @param isSomeSpanUnequal24 是否有的组件“span”不等于“24”
 * @returns {string} “单行文本”HTML
 */
export default function getOneTextHtml(formJson, oneText, parent, isSomeSpanUnequal24) {
  // 创建“el-input”
  let oneTextHtml = createInputHtml(formJson, oneText, parent)
 
  // 用“el-form-item”包裹“el-input”
  if (parent === null || parent.FComponentType !== 'table') {
    oneTextHtml = formItemWrapper(formJson, oneText, oneTextHtml)
  }
 
  // span不为24的用“el-col”包裹“el-form-item”
  if (isSomeSpanUnequal24) {
    oneTextHtml = colWrapper(oneText, oneTextHtml)
  }
 
  return oneTextHtml
}