TableUtils.js 6.4 KB
Newer Older
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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
/**
 * 同步列表,可以同步新增、修改、删除
 * @author sunjianlei
 * */
export function syncAllTable(vm, table1) {
  vm.$refs.editableTable.resetScrollTop()
  let deleteIds = table1.$refs.editableTable.getDeleteIds()
  let table1Value
  table1.$refs.editableTable.getValuesPromise(false).then((values) => {
    table1Value = values
    return vm.$refs.editableTable.getValuesPromise(false)
  }).then((values) => {

    table1Value.forEach(value => {
      let flag = false
      values.forEach((thisValue) => {
        if (value.id === thisValue.id) {

          // 判断是否修改了值
          let dbFieldName = thisValue['dbFieldName']
          let dbFieldTxt = thisValue['dbFieldTxt']

          // return

          if (value.dbFieldName !== dbFieldName
            || value.dbFieldTxt !== dbFieldTxt) {

            // 修改了
            vm.$refs.editableTable.setValues([{
              rowKey: thisValue.id,
              values: {
                dbFieldName: value.dbFieldName,
                dbFieldTxt: value.dbFieldTxt
              }
            }])

          }
          flag = true
        } else {
          // id不匹配则有可能是新增也有可能是删除了的
          // 遍历传进来的 deleteIds 进行对比
          deleteIds.forEach(delId => {
            // 对比成功,则删除该条数据
            if (delId === thisValue.id) {
              vm.$refs.editableTable.removeRows(vm.$refs.editableTable.caseId + delId)
              flag = true
            }
          })
        }
      })
      // return
      // 判断是否操作了该条数据,若没有操作则代表要执行新增操作
      if (!flag) {
        let record = Object.assign({}, value)
        vm.columns.forEach(column => {
          if (
            column.dataIndex !== 'dbFieldName' &&
            column.dataIndex !== 'dbFieldTxt'
          ) {
            record[column.dataIndex] = column.defaultValue
          }
        })
        vm.$refs.editableTable.push(record)
      }
    })
  })

}

/**
 * 将数据分类并Set进dataSource
 * @author sunjianlei
 **/
export function setDataSource(vm, queryData) {
  let dataSource = []
  // 遍历查询出来的数据
  queryData.forEach(value => {

    let data = { id: value['id'] }
    vm.columns.forEach(column => {
      let key = column.key
      if (key) {
        data[key] = value[key]

        // 由于多选下拉框返回的是一个数组,所以需要改成 [1,2,3] 数组的形式,否则组件不识别
        // if (key === 'indexField') {
        //   data[key] = value[key].split(',')
        // }

      }
    })
    dataSource.push(data)
  })
  vm.dataSource = dataSource
}

/** 获取主表的初始化数据 */
export function getMasterTableInitialData() {
  return [
    {
      dbFieldName: 'id',
      dbFieldTxt: '主键',
      dbLength: 36,
      dbPointLength: 0,
      dbDefaultVal: '',
      dbType: 'string',
      dbIsKey: '1',
      dbIsNull: '0',
      // table2
      isShowForm: '0',
      isShowList: '0',
      fieldShowType: 'text',
      fieldLength: '120',
      queryMode: 'single',
      orderNum: 1
    },
    {
      dbFieldName: 'create_by',
      dbFieldTxt: '创建人',
      dbLength: 50,
      dbPointLength: 0,
      dbDefaultVal: '',
      dbType: 'string',
      dbIsKey: '0',
      dbIsNull: '1',
      // table2
      isShowForm: '0',
      isShowList: '0',
      fieldShowType: 'text',
      fieldLength: '120',
      queryMode: 'single',
      orderNum: 2
    },
    {
      dbFieldName: 'create_time',
      dbFieldTxt: '创建日期',
      dbLength: 20,
      dbPointLength: 0,
      dbDefaultVal: '',
      dbType: 'Date',
      dbIsKey: '0',
      dbIsNull: '1',
      // table2
      isShowForm: '0',
      isShowList: '0',
      fieldShowType: 'datetime',
      fieldLength: '120',
      queryMode: 'single',
      orderNum: 3
    },
    {
      dbFieldName: 'update_by',
      dbFieldTxt: '更新人',
      dbLength: 50,
      dbPointLength: 0,
      dbDefaultVal: '',
      dbType: 'string',
      dbIsKey: '0',
      dbIsNull: '1',
      // table2
      isShowForm: '0',
      isShowList: '0',
      fieldShowType: 'text',
      fieldLength: '120',
      queryMode: 'single',
      orderNum: 4
    },
    {
      dbFieldName: 'update_time',
      dbFieldTxt: '更新日期',
      dbLength: 20,
      dbPointLength: 0,
      dbDefaultVal: '',
      dbType: 'Date',
      dbIsKey: '0',
      dbIsNull: '1',
      // table2
      isShowForm: '0',
      isShowList: '0',
      fieldShowType: 'datetime',
      fieldLength: '120',
      queryMode: 'single',
      orderNum: 5
    },{
      dbFieldName: 'sys_org_code',
      dbFieldTxt: '所属部门',
      dbLength: 64,
      dbPointLength: 0,
      dbDefaultVal: '',
      dbType: 'string',
      dbIsKey: '0',
      dbIsNull: '1',
      // table2
      isShowForm: '0',
      isShowList: '0',
      fieldShowType: 'text',
      fieldLength: '120',
      queryMode: 'single',
      orderNum: 6
    }
    // {
    //   dbFieldName: 'sys_org_code',
    //   dbFieldTxt: '所属部门',
    //   dbLength: 50,
    //   dbPointLength: 0,
    //   dbDefaultVal: '',
    //   dbType: 'string',
    //   dbIsKey: false,
    //   dbIsNull: true
    // }, {
    //   dbFieldName: 'sys_company_code',
    //   dbFieldTxt: '所属公司',
    //   dbLength: 50,
    //   dbPointLength: 0,
    //   dbDefaultVal: '',
    //   dbType: 'string',
    //   dbIsKey: false,
    //   dbIsNull: true
    // }, {
    //   dbFieldName: 'bpm_status',
    //   dbFieldTxt: '流程状态',
    //   dbLength: 32,
    //   dbPointLength: 0,
    //   dbDefaultVal: '',
    //   dbType: 'string',
    //   dbIsKey: false,
    //   dbIsNull: true
    // }
  ]
}
/** 获取树的初始化数据 */
export function getTreeNeedFields() {
  return [{
    dbFieldName: 'pid',
    dbFieldTxt: '父级节点',
    dbLength: 32,
    dbPointLength: 0,
    dbDefaultVal: '',
    dbType: 'string',
    dbIsKey: '0',
    dbIsNull: '1',
    // table2
    isShowForm: '1',
    isShowList: '0',
    fieldShowType: 'text',
    fieldLength: '120',
    queryMode: 'single',
    orderNum: 7
  },{
    dbFieldName: 'has_child',
    dbFieldTxt: '是否有子节点',
    dbLength: 3,
    dbPointLength: 0,
    dbDefaultVal: '',
    dbType: 'string',
    dbIsKey: '0',
    dbIsNull: '1',
    // table2
    isShowForm: '0',
    isShowList: '0',
    fieldShowType: 'list',
    fieldLength: '120',
    queryMode: 'single',
    orderNum: 8,
    // table3
    dictField:"yn"
  }]
}