index.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <script lang="ts" setup>
  2. import { ApiComponent } from '@vben/common-ui';
  3. import { Cascader } from 'ant-design-vue';
  4. const treeData: Record<string, any> = [
  5. {
  6. label: '浙江',
  7. value: 'zhejiang',
  8. children: [
  9. {
  10. value: 'hangzhou',
  11. label: '杭州',
  12. children: [
  13. {
  14. value: 'xihu',
  15. label: '西湖',
  16. },
  17. {
  18. value: 'sudi',
  19. label: '苏堤',
  20. },
  21. ],
  22. },
  23. {
  24. value: 'jiaxing',
  25. label: '嘉兴',
  26. children: [
  27. {
  28. value: 'wuzhen',
  29. label: '乌镇',
  30. },
  31. {
  32. value: 'meihuazhou',
  33. label: '梅花洲',
  34. },
  35. ],
  36. },
  37. {
  38. value: 'zhoushan',
  39. label: '舟山',
  40. children: [
  41. {
  42. value: 'putuoshan',
  43. label: '普陀山',
  44. },
  45. {
  46. value: 'taohuadao',
  47. label: '桃花岛',
  48. },
  49. ],
  50. },
  51. ],
  52. },
  53. {
  54. label: '江苏',
  55. value: 'jiangsu',
  56. children: [
  57. {
  58. value: 'nanjing',
  59. label: '南京',
  60. children: [
  61. {
  62. value: 'zhonghuamen',
  63. label: '中华门',
  64. },
  65. {
  66. value: 'zijinshan',
  67. label: '紫金山',
  68. },
  69. {
  70. value: 'yuhuatai',
  71. label: '雨花台',
  72. },
  73. ],
  74. },
  75. ],
  76. },
  77. ];
  78. /**
  79. * 模拟请求接口
  80. */
  81. function fetchApi(): Promise<Record<string, any>> {
  82. return new Promise((resolve) => {
  83. setTimeout(() => {
  84. resolve(treeData);
  85. }, 1000);
  86. });
  87. }
  88. </script>
  89. <template>
  90. <ApiComponent
  91. :api="fetchApi"
  92. :component="Cascader"
  93. :immediate="false"
  94. children-field="children"
  95. loading-slot="suffixIcon"
  96. visible-event="onDropdownVisibleChange"
  97. />
  98. </template>