You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.4 KiB

  1. import { Cascader, CascaderProps } from '@/components/cascader'
  2. import { useAtomValue } from 'jotai/index'
  3. import { departTreeAtom } from '@/store/system/department.ts'
  4. import { usePageStoreOptions } from '@/store'
  5. import { Spin } from 'antd'
  6. import { useTranslation } from '@/i18n.ts'
  7. export interface DepartmentCascaderProps extends Omit<CascaderProps<any>, 'options'> {
  8. onChange?: (value: any) => void
  9. }
  10. const displayRender = (labels: string[]) => labels[labels.length - 1]
  11. export const DepartmentCascader = (props: DepartmentCascaderProps) => {
  12. const { t } = useTranslation()
  13. const { data = [], isLoading } = useAtomValue(departTreeAtom, usePageStoreOptions())
  14. const onChange = (value) => {
  15. props?.onChange?.(value[value.length - 1])
  16. }
  17. return (
  18. <Spin spinning={isLoading} size={'small'}>
  19. <Cascader changeOnSelect={true} {...props as any}
  20. fieldNames={{
  21. label: 'name',
  22. value: 'id',
  23. }}
  24. placeholder={t('component.DepartmentCascader.placeholder', '请选择部门')}
  25. onChange={onChange}
  26. displayRender={displayRender}
  27. showCheckedStrategy={Cascader.SHOW_CHILD}
  28. options={data as any}>
  29. </Cascader>
  30. </Spin>
  31. )
  32. }