column.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import * as utils from '../utils/util.js';
  2. import dayjs from 'dayjs';
  3. export default function() {
  4. return {
  5. methods: {
  6. initFun() {
  7. Object.keys(utils).forEach(key => {
  8. this[key] = utils[key];
  9. });
  10. },
  11. cellEditFlag(row, column) {
  12. return row.$cellEdit && [undefined, 'select', 'input'].includes(column.type) && column.solt !== true && column.cell;
  13. },
  14. // 处理数据
  15. detail(row, column) {
  16. let result = row[column.prop || column.value] || '';
  17. if (column.type) {
  18. if (['date', 'time', 'datetime'].includes(column.type) && column.format) {
  19. const format = column.format
  20. .replace('dd', 'DD')
  21. .replace('yyyy', 'YYYY');
  22. result = dayjs(result).format(format);
  23. }
  24. if (column.dicData) {
  25. result = this.findByvalue(
  26. typeof column.dicData === 'string' ? this.DIC[column.dicData] : column.dicData,
  27. result,
  28. (column.props || this.tableOption.props)
  29. );
  30. }
  31. }
  32. if (column.formatter && typeof column.formatter === 'function') {
  33. result = column.formatter(row, row[column.prop], result, column);
  34. }
  35. return result;
  36. },
  37. }
  38. }
  39. }