48f823047323a56caab0d95410642d1f295f6b7eb186d20d4097b7cf8a8ad29b7a63010c16d1b5b3308c600be2e2a86961a9bb612d1883c02322fd2da71dba 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { watch, nextTick, toRefs, computed } from 'vue';
  2. import { pick } from 'lodash-unified';
  3. import { ElSelect } from '../../select/index.mjs';
  4. import { useNamespace } from '../../../hooks/use-namespace/index.mjs';
  5. import { UPDATE_MODEL_EVENT } from '../../../constants/event.mjs';
  6. const useSelect = (props, { attrs, emit }, {
  7. select,
  8. tree,
  9. key
  10. }) => {
  11. const ns = useNamespace("tree-select");
  12. watch(() => props.data, () => {
  13. if (props.filterable) {
  14. nextTick(() => {
  15. var _a, _b;
  16. (_b = tree.value) == null ? void 0 : _b.filter((_a = select.value) == null ? void 0 : _a.states.inputValue);
  17. });
  18. }
  19. }, { flush: "post" });
  20. const result = {
  21. ...pick(toRefs(props), Object.keys(ElSelect.props)),
  22. ...attrs,
  23. class: computed(() => attrs.class),
  24. style: computed(() => attrs.style),
  25. "onUpdate:modelValue": (value) => emit(UPDATE_MODEL_EVENT, value),
  26. valueKey: key,
  27. popperClass: computed(() => {
  28. const classes = [ns.e("popper")];
  29. if (props.popperClass)
  30. classes.push(props.popperClass);
  31. return classes.join(" ");
  32. }),
  33. filterMethod: (keyword = "") => {
  34. var _a;
  35. if (props.filterMethod) {
  36. props.filterMethod(keyword);
  37. } else if (props.remoteMethod) {
  38. props.remoteMethod(keyword);
  39. } else {
  40. (_a = tree.value) == null ? void 0 : _a.filter(keyword);
  41. }
  42. }
  43. };
  44. return result;
  45. };
  46. export { useSelect };
  47. //# sourceMappingURL=select.mjs.map