column.js 2.0 KB

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