giveVarcharLength.js 835 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
export default function giveVarcharRules({
                                           dataColumn = {},
                                           json = {},
                                           required = false,
                                           title = '',
                                         }) {
  const res =
    Array.isArray(json.vlds) && json.vlds.length > 0
      ? json.vlds
      : [
        {
          required: required,
          message: '请输入' + title,
        },
      ];
16
  if (dataColumn?.type === 'VARCHAR' && dataColumn.length && res.length < 2) {
17 18 19 20
    // console.log(dataColumn.length);
    res.push({
      max: dataColumn.length,
      message: `不能超过${dataColumn.length}个字符`,
21 22 23
      transform: function(value){
        return value + '';
      },
24 25 26 27
    });
  }
  return res;
}