cascader.uvue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  1. <template>
  2. <cl-page>
  3. <view class="p-3">
  4. <demo-item :label="t('基础用法')">
  5. <cl-cascader v-model="form.cascader1" :options="options"></cl-cascader>
  6. </demo-item>
  7. <demo-item :label="t('带索引、地区选择')">
  8. <cl-cascader v-model="form.cascader2" :options="options2"></cl-cascader>
  9. </demo-item>
  10. <demo-item :label="t('自定义')">
  11. <cl-cascader
  12. v-model="form.cascader3"
  13. :options="options"
  14. :disabled="isDisabled"
  15. :text-separator="isSeparator ? ' / ' : ' - '"
  16. :height="isHeight ? 500 : 800"
  17. ></cl-cascader>
  18. <cl-list
  19. border
  20. :pt="{
  21. className: 'mt-3'
  22. }"
  23. >
  24. <cl-list-item :label="t('换个分隔符')">
  25. <cl-switch v-model="isSeparator"></cl-switch>
  26. </cl-list-item>
  27. <cl-list-item :label="t('列表高度小一点')">
  28. <cl-switch v-model="isHeight"></cl-switch>
  29. </cl-list-item>
  30. <cl-list-item :label="t('禁用')">
  31. <cl-switch v-model="isDisabled"></cl-switch>
  32. </cl-list-item>
  33. </cl-list>
  34. </demo-item>
  35. </view>
  36. </cl-page>
  37. </template>
  38. <script lang="ts" setup>
  39. import { reactive, ref } from "vue";
  40. import DemoItem from "../components/item.uvue";
  41. import { useCascader, type ClCascaderOption } from "@/uni_modules/cool-ui";
  42. import { t } from "@/locale";
  43. import pca from "@/data/pca.json";
  44. type Form = {
  45. cascader1: string[];
  46. cascader2: string[];
  47. cascader3: string[];
  48. };
  49. const form = reactive<Form>({
  50. cascader1: [],
  51. cascader2: [],
  52. cascader3: []
  53. });
  54. const isDisabled = ref(false);
  55. const isSeparator = ref(false);
  56. const isHeight = ref(false);
  57. const options = ref<ClCascaderOption[]>([
  58. {
  59. label: "电子产品",
  60. value: "1",
  61. children: [
  62. {
  63. label: "手机",
  64. value: "1-1",
  65. children: [
  66. {
  67. label: "苹果",
  68. value: "1-1-1",
  69. children: [
  70. {
  71. label: "iPhone 15 Pro Max",
  72. value: "1-1-1-1"
  73. },
  74. {
  75. label: "iPhone 15 Pro",
  76. value: "1-1-1-2"
  77. },
  78. {
  79. label: "iPhone 15",
  80. value: "1-1-1-3"
  81. },
  82. {
  83. label: "iPhone 14 Pro Max",
  84. value: "1-1-1-4"
  85. },
  86. {
  87. label: "iPhone 14",
  88. value: "1-1-1-5"
  89. }
  90. ]
  91. },
  92. {
  93. label: "华为",
  94. value: "1-1-2",
  95. children: [
  96. {
  97. label: "Mate 60 Pro+",
  98. value: "1-1-2-1"
  99. },
  100. {
  101. label: "Mate 60 Pro",
  102. value: "1-1-2-2"
  103. },
  104. {
  105. label: "Mate 60",
  106. value: "1-1-2-3"
  107. },
  108. {
  109. label: "P60 Pro",
  110. value: "1-1-2-4"
  111. },
  112. {
  113. label: "P60",
  114. value: "1-1-2-5"
  115. }
  116. ]
  117. },
  118. {
  119. label: "小米",
  120. value: "1-1-3",
  121. children: [
  122. {
  123. label: "小米14 Pro",
  124. value: "1-1-3-1"
  125. },
  126. {
  127. label: "小米14",
  128. value: "1-1-3-2"
  129. },
  130. {
  131. label: "Redmi K70 Pro",
  132. value: "1-1-3-3"
  133. },
  134. {
  135. label: "Redmi K70",
  136. value: "1-1-3-4"
  137. }
  138. ]
  139. }
  140. ]
  141. },
  142. {
  143. label: "电脑",
  144. value: "1-2",
  145. children: [
  146. {
  147. label: "笔记本",
  148. value: "1-2-1",
  149. children: [
  150. {
  151. label: "MacBook Pro 16",
  152. value: "1-2-1-1"
  153. },
  154. {
  155. label: "MacBook Pro 14",
  156. value: "1-2-1-2"
  157. },
  158. {
  159. label: "MacBook Air 15",
  160. value: "1-2-1-3"
  161. },
  162. {
  163. label: "ThinkPad X1",
  164. value: "1-2-1-4"
  165. },
  166. {
  167. label: "ROG 魔霸新锐",
  168. value: "1-2-1-5"
  169. },
  170. {
  171. label: "拯救者 Y9000P",
  172. value: "1-2-1-6"
  173. }
  174. ]
  175. },
  176. {
  177. label: "台式机",
  178. value: "1-2-2",
  179. children: [
  180. {
  181. label: "iMac 24寸",
  182. value: "1-2-2-1"
  183. },
  184. {
  185. label: "Mac Studio",
  186. value: "1-2-2-2"
  187. },
  188. {
  189. label: "Mac Pro",
  190. value: "1-2-2-3"
  191. },
  192. {
  193. label: "外星人",
  194. value: "1-2-2-4"
  195. },
  196. {
  197. label: "惠普暗影精灵",
  198. value: "1-2-2-5"
  199. }
  200. ]
  201. }
  202. ]
  203. },
  204. {
  205. label: "平板",
  206. value: "1-3",
  207. children: [
  208. {
  209. label: "iPad",
  210. value: "1-3-1",
  211. children: [
  212. {
  213. label: "iPad Pro 12.9",
  214. value: "1-3-1-1"
  215. },
  216. {
  217. label: "iPad Pro 11",
  218. value: "1-3-1-2"
  219. },
  220. {
  221. label: "iPad Air",
  222. value: "1-3-1-3"
  223. },
  224. {
  225. label: "iPad mini",
  226. value: "1-3-1-4"
  227. }
  228. ]
  229. },
  230. {
  231. label: "安卓平板",
  232. value: "1-3-2",
  233. children: [
  234. {
  235. label: "小米平板6 Pro",
  236. value: "1-3-2-1"
  237. },
  238. {
  239. label: "华为MatePad Pro",
  240. value: "1-3-2-2"
  241. },
  242. {
  243. label: "三星Galaxy Tab S9",
  244. value: "1-3-2-3"
  245. }
  246. ]
  247. }
  248. ]
  249. }
  250. ]
  251. },
  252. {
  253. label: "服装",
  254. value: "2",
  255. children: [
  256. {
  257. label: "男装",
  258. value: "2-1",
  259. children: [
  260. {
  261. label: "上衣",
  262. value: "2-1-1",
  263. children: [
  264. {
  265. label: "短袖T恤",
  266. value: "2-1-1-1"
  267. },
  268. {
  269. label: "长袖T恤",
  270. value: "2-1-1-2"
  271. },
  272. {
  273. label: "衬衫",
  274. value: "2-1-1-3"
  275. },
  276. {
  277. label: "卫衣",
  278. value: "2-1-1-4"
  279. },
  280. {
  281. label: "夹克",
  282. value: "2-1-1-5"
  283. },
  284. {
  285. label: "毛衣",
  286. value: "2-1-1-6"
  287. }
  288. ]
  289. },
  290. {
  291. label: "裤装",
  292. value: "2-1-2",
  293. children: [
  294. {
  295. label: "牛仔裤",
  296. value: "2-1-2-1"
  297. },
  298. {
  299. label: "休闲裤",
  300. value: "2-1-2-2"
  301. },
  302. {
  303. label: "运动裤",
  304. value: "2-1-2-3"
  305. },
  306. {
  307. label: "西裤",
  308. value: "2-1-2-4"
  309. },
  310. {
  311. label: "短裤",
  312. value: "2-1-2-5"
  313. }
  314. ]
  315. },
  316. {
  317. label: "外套",
  318. value: "2-1-3",
  319. children: [
  320. {
  321. label: "羽绒服",
  322. value: "2-1-3-1"
  323. },
  324. {
  325. label: "大衣",
  326. value: "2-1-3-2"
  327. },
  328. {
  329. label: "夹克",
  330. value: "2-1-3-3"
  331. },
  332. {
  333. label: "西装",
  334. value: "2-1-3-4"
  335. }
  336. ]
  337. }
  338. ]
  339. },
  340. {
  341. label: "女装",
  342. value: "2-2",
  343. children: [
  344. {
  345. label: "裙装",
  346. value: "2-2-1",
  347. children: [
  348. {
  349. label: "连衣裙",
  350. value: "2-2-1-1"
  351. },
  352. {
  353. label: "半身裙",
  354. value: "2-2-1-2"
  355. },
  356. {
  357. label: "A字裙",
  358. value: "2-2-1-3"
  359. },
  360. {
  361. label: "包臀裙",
  362. value: "2-2-1-4"
  363. },
  364. {
  365. label: "百褶裙",
  366. value: "2-2-1-5"
  367. }
  368. ]
  369. },
  370. {
  371. label: "上装",
  372. value: "2-2-2",
  373. children: [
  374. {
  375. label: "衬衫",
  376. value: "2-2-2-1"
  377. },
  378. {
  379. label: "T恤",
  380. value: "2-2-2-2"
  381. },
  382. {
  383. label: "毛衣",
  384. value: "2-2-2-3"
  385. },
  386. {
  387. label: "卫衣",
  388. value: "2-2-2-4"
  389. },
  390. {
  391. label: "雪纺衫",
  392. value: "2-2-2-5"
  393. }
  394. ]
  395. },
  396. {
  397. label: "外套",
  398. value: "2-2-3",
  399. children: [
  400. {
  401. label: "风衣",
  402. value: "2-2-3-1"
  403. },
  404. {
  405. label: "羽绒服",
  406. value: "2-2-3-2"
  407. },
  408. {
  409. label: "大衣",
  410. value: "2-2-3-3"
  411. },
  412. {
  413. label: "西装",
  414. value: "2-2-3-4"
  415. },
  416. {
  417. label: "皮衣",
  418. value: "2-2-3-5"
  419. }
  420. ]
  421. }
  422. ]
  423. }
  424. ]
  425. },
  426. {
  427. label: "食品",
  428. value: "3",
  429. children: [
  430. {
  431. label: "水果",
  432. value: "3-1",
  433. children: [
  434. {
  435. label: "苹果",
  436. value: "3-1-1"
  437. },
  438. {
  439. label: "香蕉",
  440. value: "3-1-2"
  441. },
  442. {
  443. label: "橘子",
  444. value: "3-1-3"
  445. }
  446. ]
  447. },
  448. {
  449. label: "蔬菜",
  450. value: "3-2",
  451. children: [
  452. {
  453. label: "西红柿",
  454. value: "3-2-1"
  455. },
  456. {
  457. label: "黄瓜",
  458. value: "3-2-2"
  459. },
  460. {
  461. label: "胡萝卜",
  462. value: "3-2-3"
  463. }
  464. ]
  465. }
  466. ]
  467. },
  468. {
  469. label: "饮料",
  470. value: "4",
  471. children: [
  472. {
  473. label: "果汁",
  474. value: "4-1",
  475. children: [
  476. {
  477. label: "苹果汁",
  478. value: "4-1-1"
  479. },
  480. {
  481. label: "橙汁",
  482. value: "4-1-2"
  483. },
  484. {
  485. label: "葡萄汁",
  486. value: "4-1-3"
  487. },
  488. {
  489. label: "西瓜汁",
  490. value: "4-1-4"
  491. }
  492. ]
  493. }
  494. ]
  495. }
  496. ]);
  497. const options2 = useCascader(pca);
  498. </script>