tableData.tsx 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. import { optionsListApi } from '/@/api/demo/select';
  2. import { FormProps, FormSchema } from '/@/components/Table';
  3. import { BasicColumn } from '/@/components/Table/src/types/table';
  4. import { VxeFormItemProps, VxeGridPropTypes } from '/@/components/VxeTable';
  5. import { ref } from 'vue';
  6. import { Input } from 'ant-design-vue';
  7. export function getBasicColumns(): BasicColumn[] {
  8. return [
  9. {
  10. title: 'ID',
  11. dataIndex: 'id',
  12. fixed: 'left',
  13. width: 200,
  14. },
  15. {
  16. title: '姓名',
  17. dataIndex: 'name',
  18. width: 150,
  19. filters: [
  20. { text: 'Male', value: 'male' },
  21. { text: 'Female', value: 'female' },
  22. ],
  23. },
  24. {
  25. title: '地址',
  26. dataIndex: 'address',
  27. },
  28. {
  29. title: '编号',
  30. dataIndex: 'no',
  31. width: 150,
  32. sorter: true,
  33. defaultHidden: true,
  34. },
  35. {
  36. title: '开始时间',
  37. width: 150,
  38. sorter: true,
  39. dataIndex: 'beginTime',
  40. },
  41. {
  42. title: '结束时间',
  43. width: 150,
  44. sorter: true,
  45. dataIndex: 'endTime',
  46. },
  47. ];
  48. }
  49. export function getBasicShortColumns(): BasicColumn[] {
  50. return [
  51. {
  52. title: 'ID',
  53. width: 150,
  54. dataIndex: 'id',
  55. sorter: true,
  56. sortOrder: 'ascend',
  57. },
  58. {
  59. title: '姓名',
  60. dataIndex: 'name',
  61. width: 120,
  62. },
  63. {
  64. title: '地址',
  65. dataIndex: 'address',
  66. },
  67. {
  68. title: '编号',
  69. dataIndex: 'no',
  70. width: 80,
  71. },
  72. ];
  73. }
  74. export function getMultipleHeaderColumns(): BasicColumn[] {
  75. const testRef = ref('姓名:');
  76. return [
  77. {
  78. title: 'ID',
  79. dataIndex: 'id',
  80. width: 200,
  81. },
  82. {
  83. title: '姓名',
  84. customHeaderRender() {
  85. return (
  86. <Input placeholder="输入值 更新 自定义title" size="small" v-model:value={testRef.value} />
  87. );
  88. },
  89. dataIndex: 'name',
  90. width: 120,
  91. },
  92. {
  93. title: '地址',
  94. dataIndex: 'address',
  95. sorter: true,
  96. children: [
  97. {
  98. title: '编号',
  99. customHeaderRender(column) {
  100. // 【自定义渲染的】
  101. return (
  102. <div>
  103. _ <span style="background: #f00; color: #fff;">{testRef.value}</span> _
  104. {column.customTitle}
  105. </div>
  106. );
  107. },
  108. dataIndex: 'no',
  109. width: 120,
  110. filters: [
  111. { text: 'Male', value: 'male', children: [] },
  112. { text: 'Female', value: 'female', children: [] },
  113. ],
  114. },
  115. {
  116. title: '开始时间',
  117. dataIndex: 'beginTime',
  118. width: 120,
  119. },
  120. {
  121. title: '结束时间',
  122. dataIndex: 'endTime',
  123. width: 120,
  124. },
  125. ],
  126. },
  127. ];
  128. }
  129. export function getCustomHeaderColumns(): BasicColumn[] {
  130. return [
  131. {
  132. title: 'ID',
  133. dataIndex: 'id',
  134. helpMessage: 'headerHelpMessage方式1',
  135. width: 200,
  136. },
  137. {
  138. // title: '姓名',
  139. dataIndex: 'name',
  140. width: 120,
  141. // slots: { title: 'customTitle' },
  142. },
  143. {
  144. // title: '地址',
  145. dataIndex: 'address',
  146. width: 120,
  147. // slots: { title: 'customAddress' },
  148. sorter: true,
  149. },
  150. {
  151. title: '编号',
  152. dataIndex: 'no',
  153. width: 120,
  154. filters: [
  155. { text: 'Male', value: 'male', children: [] },
  156. { text: 'Female', value: 'female', children: [] },
  157. ],
  158. },
  159. {
  160. title: '开始时间',
  161. dataIndex: 'beginTime',
  162. width: 120,
  163. },
  164. {
  165. title: '结束时间',
  166. dataIndex: 'endTime',
  167. width: 120,
  168. },
  169. ];
  170. }
  171. const cellContent = (_, index) => ({
  172. colSpan: index === 9 ? 0 : 1,
  173. });
  174. export function getMergeHeaderColumns(): BasicColumn[] {
  175. return [
  176. {
  177. title: 'ID',
  178. dataIndex: 'id',
  179. width: 300,
  180. customCell: (_, index) => ({
  181. colSpan: index === 9 ? 6 : 1,
  182. }),
  183. },
  184. {
  185. title: '姓名',
  186. dataIndex: 'name',
  187. width: 300,
  188. customCell: cellContent,
  189. },
  190. {
  191. title: '地址',
  192. dataIndex: 'address',
  193. colSpan: 2,
  194. width: 120,
  195. sorter: true,
  196. customCell: (_, index) => ({
  197. rowSpan: index === 2 ? 2 : 1,
  198. colSpan: index === 3 || index === 9 ? 0 : 1,
  199. }),
  200. },
  201. {
  202. title: '编号',
  203. dataIndex: 'no',
  204. colSpan: 0,
  205. filters: [
  206. { text: 'Male', value: 'male', children: [] },
  207. { text: 'Female', value: 'female', children: [] },
  208. ],
  209. customCell: cellContent,
  210. },
  211. {
  212. title: '开始时间',
  213. dataIndex: 'beginTime',
  214. width: 200,
  215. customCell: cellContent,
  216. },
  217. {
  218. title: '结束时间',
  219. dataIndex: 'endTime',
  220. width: 200,
  221. customCell: cellContent,
  222. },
  223. ];
  224. }
  225. export const getAdvanceSchema = (itemNumber = 6): FormSchema[] => {
  226. const arr: any = [];
  227. for (let index = 0; index < itemNumber; index++) {
  228. arr.push({
  229. field: `field${index}`,
  230. label: `字段${index}`,
  231. component: 'Input',
  232. colProps: {
  233. xl: 12,
  234. xxl: 8,
  235. },
  236. });
  237. }
  238. return arr;
  239. };
  240. export function getFormConfig(): Partial<FormProps> {
  241. return {
  242. labelWidth: 100,
  243. schemas: [
  244. ...getAdvanceSchema(5),
  245. {
  246. field: `field11`,
  247. label: `Slot示例`,
  248. component: 'Select',
  249. slot: 'custom',
  250. colProps: {
  251. xl: 12,
  252. xxl: 8,
  253. },
  254. },
  255. ],
  256. };
  257. }
  258. export function getBasicData() {
  259. return (() => {
  260. const arr: any = [];
  261. for (let index = 0; index < 40; index++) {
  262. arr.push({
  263. id: `${index}`,
  264. name: 'John Brown',
  265. age: `1${index}`,
  266. no: `${index + 10}`,
  267. address: 'New York No. 1 Lake ParkNew York No. 1 Lake Park',
  268. beginTime: new Date().toLocaleString(),
  269. endTime: new Date().toLocaleString(),
  270. });
  271. }
  272. return arr;
  273. })();
  274. }
  275. export function getTreeTableData() {
  276. return (() => {
  277. const arr: any = [];
  278. for (let index = 0; index < 40; index++) {
  279. arr.push({
  280. id: `${index}`,
  281. name: 'John Brown',
  282. age: `1${index}`,
  283. no: `${index + 10}`,
  284. address: 'New York No. 1 Lake ParkNew York No. 1 Lake Park',
  285. beginTime: new Date().toLocaleString(),
  286. endTime: new Date().toLocaleString(),
  287. children: [
  288. {
  289. id: `l2-${index}`,
  290. name: 'John Brown',
  291. age: `1${index}`,
  292. no: `${index + 10}`,
  293. address: 'New York No. 1 Lake ParkNew York No. 1 Lake Park',
  294. beginTime: new Date().toLocaleString(),
  295. endTime: new Date().toLocaleString(),
  296. },
  297. ],
  298. });
  299. }
  300. return arr;
  301. })();
  302. }
  303. export const vxeTableColumns: VxeGridPropTypes.Columns = [
  304. {
  305. title: '序号',
  306. type: 'seq',
  307. fixed: 'left',
  308. width: '50',
  309. align: 'center',
  310. },
  311. {
  312. title: '固定列',
  313. field: 'name',
  314. width: 150,
  315. showOverflow: 'tooltip',
  316. fixed: 'left',
  317. },
  318. {
  319. title: '自适应列',
  320. field: 'address',
  321. },
  322. {
  323. title: '自定义列(自定义导出)',
  324. field: 'no',
  325. width: 200,
  326. showOverflow: 'tooltip',
  327. align: 'center',
  328. slots: {
  329. default: ({ row }) => {
  330. const text = `自定义${row.no}`;
  331. return [<div class="text-red-500">{text}</div>];
  332. },
  333. },
  334. exportMethod: ({ row }) => {
  335. return `自定义${row.no}导出`;
  336. },
  337. },
  338. {
  339. title: '自定义编辑',
  340. width: 150,
  341. field: 'name1',
  342. align: 'center',
  343. editRender: {
  344. name: 'AInput',
  345. placeholder: '请点击输入',
  346. },
  347. },
  348. {
  349. title: '开始时间',
  350. width: 150,
  351. field: 'beginTime',
  352. showOverflow: 'tooltip',
  353. align: 'center',
  354. },
  355. {
  356. title: '结束时间',
  357. width: 150,
  358. field: 'endTime',
  359. showOverflow: 'tooltip',
  360. align: 'center',
  361. },
  362. {
  363. width: 160,
  364. title: '操作',
  365. align: 'center',
  366. slots: { default: 'action' },
  367. fixed: 'right',
  368. },
  369. ];
  370. export const vxeTableFormSchema: VxeFormItemProps[] = [
  371. {
  372. field: 'field0',
  373. title: 'field0',
  374. itemRender: {
  375. name: 'AInput',
  376. },
  377. span: 6,
  378. },
  379. {
  380. field: 'field1',
  381. title: 'field1',
  382. itemRender: {
  383. name: 'AApiSelect',
  384. props: {
  385. api: optionsListApi,
  386. resultField: 'list',
  387. labelField: 'name',
  388. valueField: 'id',
  389. },
  390. },
  391. span: 6,
  392. },
  393. {
  394. span: 12,
  395. align: 'right',
  396. className: '!pr-0',
  397. itemRender: {
  398. name: 'AButtonGroup',
  399. children: [
  400. {
  401. props: { type: 'primary', content: '查询', htmlType: 'submit' },
  402. attrs: { class: 'mr-2' },
  403. },
  404. { props: { type: 'default', htmlType: 'reset', content: '重置' } },
  405. ],
  406. },
  407. },
  408. ];