tableData.tsx 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. import { FormProps, FormSchema } from '/@/components/Table';
  2. import { BasicColumn } from '/@/components/Table/src/types/table';
  3. export function getBasicColumns(): BasicColumn[] {
  4. return [
  5. {
  6. title: 'ID',
  7. dataIndex: 'id',
  8. fixed: 'left',
  9. width: 200,
  10. },
  11. {
  12. title: '姓名',
  13. dataIndex: 'name',
  14. width: 150,
  15. filters: [
  16. { text: 'Male', value: 'male' },
  17. { text: 'Female', value: 'female' },
  18. ],
  19. },
  20. {
  21. title: '地址',
  22. dataIndex: 'address',
  23. },
  24. {
  25. title: '编号',
  26. dataIndex: 'no',
  27. width: 150,
  28. sorter: true,
  29. defaultHidden: true,
  30. },
  31. {
  32. title: '开始时间',
  33. width: 150,
  34. sorter: true,
  35. dataIndex: 'beginTime',
  36. },
  37. {
  38. title: '结束时间',
  39. width: 150,
  40. sorter: true,
  41. dataIndex: 'endTime',
  42. },
  43. ];
  44. }
  45. export function getBasicShortColumns(): BasicColumn[] {
  46. return [
  47. {
  48. title: 'ID',
  49. width: 150,
  50. dataIndex: 'id',
  51. sorter: true,
  52. sortOrder: 'ascend',
  53. },
  54. {
  55. title: '姓名',
  56. dataIndex: 'name',
  57. width: 120,
  58. },
  59. {
  60. title: '地址',
  61. dataIndex: 'address',
  62. },
  63. {
  64. title: '编号',
  65. dataIndex: 'no',
  66. width: 80,
  67. },
  68. ];
  69. }
  70. export function getMultipleHeaderColumns(): BasicColumn[] {
  71. return [
  72. {
  73. title: 'ID',
  74. dataIndex: 'id',
  75. width: 200,
  76. },
  77. {
  78. title: '姓名',
  79. dataIndex: 'name',
  80. width: 120,
  81. },
  82. {
  83. title: '地址',
  84. dataIndex: 'address',
  85. sorter: true,
  86. children: [
  87. {
  88. title: '编号',
  89. dataIndex: 'no',
  90. width: 120,
  91. filters: [
  92. { text: 'Male', value: 'male', children: [] },
  93. { text: 'Female', value: 'female', children: [] },
  94. ],
  95. },
  96. {
  97. title: '开始时间',
  98. dataIndex: 'beginTime',
  99. width: 120,
  100. },
  101. {
  102. title: '结束时间',
  103. dataIndex: 'endTime',
  104. width: 120,
  105. },
  106. ],
  107. },
  108. ];
  109. }
  110. export function getCustomHeaderColumns(): BasicColumn[] {
  111. return [
  112. {
  113. title: 'ID',
  114. dataIndex: 'id',
  115. width: 200,
  116. },
  117. {
  118. // title: '姓名',
  119. dataIndex: 'name',
  120. width: 120,
  121. slots: { title: 'customTitle' },
  122. },
  123. {
  124. // title: '地址',
  125. dataIndex: 'address',
  126. width: 120,
  127. slots: { title: 'customAddress' },
  128. sorter: true,
  129. },
  130. {
  131. title: '编号',
  132. dataIndex: 'no',
  133. width: 120,
  134. filters: [
  135. { text: 'Male', value: 'male', children: [] },
  136. { text: 'Female', value: 'female', children: [] },
  137. ],
  138. },
  139. {
  140. title: '开始时间',
  141. dataIndex: 'beginTime',
  142. width: 120,
  143. },
  144. {
  145. title: '结束时间',
  146. dataIndex: 'endTime',
  147. width: 120,
  148. },
  149. ];
  150. }
  151. const renderContent = ({ text, index }: { text: any; index: number }) => {
  152. const obj: any = {
  153. children: text,
  154. attrs: {},
  155. };
  156. if (index === 9) {
  157. obj.attrs.colSpan = 0;
  158. }
  159. return obj;
  160. };
  161. export function getMergeHeaderColumns(): BasicColumn[] {
  162. return [
  163. {
  164. title: 'ID',
  165. dataIndex: 'id',
  166. width: 300,
  167. customRender: renderContent,
  168. },
  169. {
  170. title: '姓名',
  171. dataIndex: 'name',
  172. width: 300,
  173. customRender: renderContent,
  174. },
  175. {
  176. title: '地址',
  177. dataIndex: 'address',
  178. colSpan: 2,
  179. width: 120,
  180. sorter: true,
  181. customRender: ({ text, index }: { text: any; index: number }) => {
  182. const obj: any = {
  183. children: text,
  184. attrs: {},
  185. };
  186. if (index === 2) {
  187. obj.attrs.rowSpan = 2;
  188. }
  189. if (index === 3) {
  190. obj.attrs.colSpan = 0;
  191. }
  192. return obj;
  193. },
  194. },
  195. {
  196. title: '编号',
  197. dataIndex: 'no',
  198. colSpan: 0,
  199. filters: [
  200. { text: 'Male', value: 'male', children: [] },
  201. { text: 'Female', value: 'female', children: [] },
  202. ],
  203. customRender: renderContent,
  204. },
  205. {
  206. title: '开始时间',
  207. dataIndex: 'beginTime',
  208. width: 200,
  209. customRender: renderContent,
  210. },
  211. {
  212. title: '结束时间',
  213. dataIndex: 'endTime',
  214. width: 200,
  215. customRender: renderContent,
  216. },
  217. ];
  218. }
  219. export const getAdvanceSchema = (itemNumber = 6): FormSchema[] => {
  220. const arr: any = [];
  221. for (let index = 0; index < itemNumber; index++) {
  222. arr.push({
  223. field: `field${index}`,
  224. label: `字段${index}`,
  225. component: 'Input',
  226. colProps: {
  227. xl: 12,
  228. xxl: 8,
  229. },
  230. });
  231. }
  232. return arr;
  233. };
  234. export function getFormConfig(): Partial<FormProps> {
  235. return {
  236. labelWidth: 100,
  237. schemas: [
  238. ...getAdvanceSchema(5),
  239. {
  240. field: `field11`,
  241. label: `Slot示例`,
  242. component: 'Select',
  243. slot: 'custom',
  244. colProps: {
  245. xl: 12,
  246. xxl: 8,
  247. },
  248. },
  249. ],
  250. };
  251. }
  252. export function getBasicData() {
  253. const data: any = (() => {
  254. const arr: any = [];
  255. for (let index = 0; index < 40; index++) {
  256. arr.push({
  257. id: `${index}`,
  258. name: 'John Brown',
  259. age: `1${index}`,
  260. no: `${index + 10}`,
  261. address: 'New York No. 1 Lake ParkNew York No. 1 Lake Park',
  262. beginTime: new Date().toLocaleString(),
  263. endTime: new Date().toLocaleString(),
  264. });
  265. }
  266. return arr;
  267. })();
  268. return data;
  269. }
  270. export function getTreeTableData() {
  271. const data: any = (() => {
  272. const arr: any = [];
  273. for (let index = 0; index < 40; index++) {
  274. arr.push({
  275. id: `${index}`,
  276. name: 'John Brown',
  277. age: `1${index}`,
  278. no: `${index + 10}`,
  279. address: 'New York No. 1 Lake ParkNew York No. 1 Lake Park',
  280. beginTime: new Date().toLocaleString(),
  281. endTime: new Date().toLocaleString(),
  282. children: [
  283. {
  284. id: `l2-${index}`,
  285. name: 'John Brown',
  286. age: `1${index}`,
  287. no: `${index + 10}`,
  288. address: 'New York No. 1 Lake ParkNew York No. 1 Lake Park',
  289. beginTime: new Date().toLocaleString(),
  290. endTime: new Date().toLocaleString(),
  291. },
  292. ],
  293. });
  294. }
  295. return arr;
  296. })();
  297. return data;
  298. }