data.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. import { FormProps, BasicColumn } from '/@/components/Table';
  2. import { h } from 'vue';
  3. import { Tag } from 'ant-design-vue';
  4. import { formatToDate } from '/@/utils/dateUtil';
  5. import { FormSchema } from '/@/components/Form/index';
  6. import { adapt } from '/@/utils/adapt';
  7. import { Tinymce } from '/@/components/Tinymce/index';
  8. const adaptWidth = adapt();
  9. // const isDir = (type: string) => type === '0';
  10. // const isMenu = (type: string) => type === '1';
  11. // const isButton = (type: string) => type === '2';
  12. export const columns: BasicColumn[] = [
  13. {
  14. title: 'ID',
  15. dataIndex: 'id',
  16. editComponentProps: {
  17. prefix: '$',
  18. },
  19. width: 100,
  20. sorter: true,
  21. },
  22. {
  23. title: '标题',
  24. dataIndex: 'title',
  25. width: 130,
  26. sorter: true,
  27. },
  28. {
  29. title: '分类',
  30. dataIndex: 'type',
  31. width: 150,
  32. sorter: true,
  33. },
  34. {
  35. title: '创建时间',
  36. dataIndex: 'createtime',
  37. width: 200,
  38. customRender: ({ record }) => {
  39. const createtime = record.createtime;
  40. return formatToDate(createtime * 1000);
  41. },
  42. },
  43. {
  44. title: '更新时间',
  45. dataIndex: 'updatetime',
  46. width: 200,
  47. customRender: ({ record }) => {
  48. const updatetime = record.updatetime;
  49. return formatToDate(updatetime * 1000);
  50. },
  51. },
  52. // {
  53. // title: '状态',
  54. // dataIndex: 'status',
  55. // width: 80,
  56. // customRender: ({ record }) => {
  57. // const color = record.status ? 'green' : 'red';
  58. // const text = record.status ? '公告' : '新闻';
  59. // return h(Tag, { color: color }, () => text);
  60. // },
  61. // sorter: true,
  62. // },
  63. ];
  64. export function getFormConfig(): Partial<FormProps> {
  65. return {
  66. labelWidth: 100,
  67. schemas: [
  68. {
  69. field: `id`,
  70. label: `ID`,
  71. component: 'Input',
  72. colProps: {
  73. xl: 12,
  74. xxl: 8,
  75. },
  76. },
  77. {
  78. field: `title`,
  79. label: `标题`,
  80. component: 'Input',
  81. colProps: {
  82. xl: 12,
  83. xxl: 8,
  84. },
  85. },
  86. {
  87. field: `type`,
  88. label: `分类`,
  89. component: 'Input',
  90. colProps: {
  91. xl: 12,
  92. xxl: 8,
  93. },
  94. },
  95. ],
  96. };
  97. }
  98. // =================popup================================
  99. export const schemas: FormSchema[] = [
  100. {
  101. field: 'title',
  102. component: 'Input',
  103. label: '标题',
  104. labelWidth: adaptWidth.adminLabelWidth,
  105. colProps: {
  106. span: adaptWidth.elContainer,
  107. },
  108. required: true,
  109. },
  110. {
  111. field: 'type',
  112. component: 'Input',
  113. label: '分类',
  114. labelWidth: adaptWidth.adminLabelWidth,
  115. colProps: {
  116. span: adaptWidth.elContainer,
  117. },
  118. required: true,
  119. },
  120. {
  121. field: 'content',
  122. component: 'Input',
  123. label: '内容',
  124. labelWidth: adaptWidth.adminLabelWidth,
  125. colProps: {
  126. span: adaptWidth.elContainer,
  127. },
  128. render: ({ model, field }) => {
  129. return h(Tinymce, {
  130. value: model[field],
  131. onChange: (value: string) => {
  132. model[field] = value;
  133. },
  134. });
  135. },
  136. required: true,
  137. },
  138. ];