tableData.tsx 6.6 KB

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