@maxax/ui 1.1.11 → 1.1.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -7379,6 +7379,56 @@ const basicCheckboxGroupProps = {
7379
7379
  showCheckboxAll: {
7380
7380
  type: Boolean,
7381
7381
  default: true
7382
+ },
7383
+ labelField: {
7384
+ type: [String, Number, Function],
7385
+ default: "label"
7386
+ },
7387
+ valueField: {
7388
+ type: [String, Number, Function],
7389
+ default: "value"
7390
+ },
7391
+ // 立即请求接口
7392
+ immediate: {
7393
+ type: Boolean,
7394
+ default: true
7395
+ },
7396
+ // 接口请求对象
7397
+ api: {
7398
+ type: Function,
7399
+ default: void 0
7400
+ },
7401
+ // 动态请求
7402
+ dynamicApi: {
7403
+ type: Function,
7404
+ default: void 0
7405
+ },
7406
+ // 请求之前处理参数
7407
+ beforeFetch: {
7408
+ type: Function,
7409
+ default: void 0
7410
+ },
7411
+ // 自定义处理接口返回参数
7412
+ afterFetch: {
7413
+ type: Function,
7414
+ default: void 0
7415
+ },
7416
+ // 查询条件请求之前处理
7417
+ handleSearchInfoFn: {
7418
+ type: Function,
7419
+ default: void 0
7420
+ },
7421
+ // 额外的请求参数
7422
+ searchInfo: {
7423
+ type: Object,
7424
+ default: () => ({})
7425
+ },
7426
+ // 请求接口配置
7427
+ fetchSetting: {
7428
+ type: Object,
7429
+ default: () => ({
7430
+ listField: "resultList"
7431
+ })
7382
7432
  }
7383
7433
  };
7384
7434
  function _isSlot$2(s) {
@@ -7412,19 +7462,33 @@ const BasicCheckboxGroup = /* @__PURE__ */ vue.defineComponent({
7412
7462
  const {
7413
7463
  disabled
7414
7464
  } = vue.toRefs(props);
7465
+ const loading = vue.ref(false);
7466
+ const dataSourceRef = vue.ref([]);
7467
+ const rawDataSourceRef = vue.ref({});
7468
+ const searchInfoRef = vue.ref({});
7415
7469
  const $value = vue.ref(props.defaultValue);
7416
7470
  const computedValue = vue.computed(() => utils.isArray(props.value) ? props.value : $value.value);
7417
7471
  const isMaxed = vue.computed(() => props.max === void 0 ? false : computedValue.value.length >= props.max);
7418
7472
  const options = vue.computed(() => {
7419
7473
  var _a;
7420
- return ((_a = props.options) != null ? _a : []).map((option) => {
7474
+ const {
7475
+ labelField,
7476
+ valueField
7477
+ } = props;
7478
+ const source = (_a = dataSourceRef.value && dataSourceRef.value.length > 0 ? dataSourceRef.value : props.options) != null ? _a : [];
7479
+ return source.map((option) => {
7421
7480
  if (utils.isString(option) || utils.isNumber(option)) {
7422
7481
  return {
7423
7482
  label: option,
7424
7483
  value: option
7425
7484
  };
7426
7485
  }
7427
- return option;
7486
+ const opt = option;
7487
+ return {
7488
+ ...opt,
7489
+ label: utils.getValueKey(labelField, opt),
7490
+ value: utils.getValueKey(valueField, opt)
7491
+ };
7428
7492
  });
7429
7493
  });
7430
7494
  const allChecked = vue.ref(false);
@@ -7449,6 +7513,52 @@ const BasicCheckboxGroup = /* @__PURE__ */ vue.defineComponent({
7449
7513
  emit("all-change", newValue, e);
7450
7514
  };
7451
7515
  const cls = vue.computed(() => [b(), is(`direction-${props.direction}`)]);
7516
+ vue.watch(() => props.searchInfo, () => {
7517
+ fetch2();
7518
+ }, {
7519
+ deep: true,
7520
+ immediate: props.immediate
7521
+ });
7522
+ async function fetch2(opt) {
7523
+ const {
7524
+ api,
7525
+ dynamicApi,
7526
+ searchInfo,
7527
+ fetchSetting,
7528
+ beforeFetch,
7529
+ afterFetch,
7530
+ handleSearchInfoFn
7531
+ } = props;
7532
+ if (!api && !dynamicApi || loading.value) return;
7533
+ try {
7534
+ loading.value = true;
7535
+ const {
7536
+ listField
7537
+ } = {
7538
+ listField: "resultList",
7539
+ ...fetchSetting
7540
+ };
7541
+ const searchInfoParams = handleSearchInfoFn ? handleSearchInfoFn() : {};
7542
+ let params = lodashEs.merge(searchInfoParams, searchInfo, opt != null ? opt : {});
7543
+ if (beforeFetch && utils.isFunction(beforeFetch)) {
7544
+ params = await beforeFetch(params) || params;
7545
+ }
7546
+ searchInfoRef.value = params;
7547
+ const apiFn = api || (dynamicApi == null ? void 0 : dynamicApi(params));
7548
+ const res = await (apiFn == null ? void 0 : apiFn(params));
7549
+ rawDataSourceRef.value = res.data;
7550
+ const isArrayResult = Array.isArray(res.data);
7551
+ let resultItems = isArrayResult ? res.data : lodashEs.get(res.data, listField);
7552
+ if (afterFetch && utils.isFunction(afterFetch)) {
7553
+ resultItems = await afterFetch(resultItems) || resultItems;
7554
+ }
7555
+ dataSourceRef.value = resultItems;
7556
+ } catch (error) {
7557
+ console.error(error);
7558
+ } finally {
7559
+ loading.value = false;
7560
+ }
7561
+ }
7452
7562
  vue.watch(() => props.value, (curValue) => {
7453
7563
  if (utils.isArray(curValue)) {
7454
7564
  $value.value = [...curValue];
@@ -8683,6 +8793,56 @@ const basicRadioGroupProps = {
8683
8793
  type: Array,
8684
8794
  default: () => []
8685
8795
  },
8796
+ labelField: {
8797
+ type: [String, Number, Function],
8798
+ default: "label"
8799
+ },
8800
+ valueField: {
8801
+ type: [String, Number, Function],
8802
+ default: "value"
8803
+ },
8804
+ // 立即请求接口
8805
+ immediate: {
8806
+ type: Boolean,
8807
+ default: true
8808
+ },
8809
+ // 接口请求对象
8810
+ api: {
8811
+ type: Function,
8812
+ default: void 0
8813
+ },
8814
+ // 动态请求
8815
+ dynamicApi: {
8816
+ type: Function,
8817
+ default: void 0
8818
+ },
8819
+ // 请求之前处理参数
8820
+ beforeFetch: {
8821
+ type: Function,
8822
+ default: void 0
8823
+ },
8824
+ // 自定义处理接口返回参数
8825
+ afterFetch: {
8826
+ type: Function,
8827
+ default: void 0
8828
+ },
8829
+ // 查询条件请求之前处理
8830
+ handleSearchInfoFn: {
8831
+ type: Function,
8832
+ default: void 0
8833
+ },
8834
+ // 额外的请求参数
8835
+ searchInfo: {
8836
+ type: Object,
8837
+ default: () => ({})
8838
+ },
8839
+ // 请求接口配置
8840
+ fetchSetting: {
8841
+ type: Object,
8842
+ default: () => ({
8843
+ listField: "resultList"
8844
+ })
8845
+ },
8686
8846
  "onUpdate:value": {
8687
8847
  type: Function,
8688
8848
  default: void 0
@@ -8706,6 +8866,10 @@ const BasicRadioGroup = /* @__PURE__ */ vue.defineComponent({
8706
8866
  b,
8707
8867
  m
8708
8868
  } = useNamespace("basic-radio-group");
8869
+ const loading = vue.ref(false);
8870
+ const dataSourceRef = vue.ref([]);
8871
+ const rawDataSourceRef = vue.ref({});
8872
+ const searchInfoRef = vue.ref({});
8709
8873
  const uncontrolledValueRef = vue.ref(props.defaultValue);
8710
8874
  const controlledValueRef = vue.toRef(props, "value");
8711
8875
  const mergedValueRef = hooks.useMergedState(controlledValueRef, uncontrolledValueRef);
@@ -8714,20 +8878,76 @@ const BasicRadioGroup = /* @__PURE__ */ vue.defineComponent({
8714
8878
  } = vue.toRefs(props);
8715
8879
  const options = vue.computed(() => {
8716
8880
  var _a;
8717
- return ((_a = props.options) != null ? _a : []).map((option) => {
8881
+ const {
8882
+ labelField,
8883
+ valueField
8884
+ } = props;
8885
+ const source = (_a = dataSourceRef.value && dataSourceRef.value.length > 0 ? dataSourceRef.value : props.options) != null ? _a : [];
8886
+ return source.map((option) => {
8718
8887
  if (utils.isString(option) || utils.isNumber(option)) {
8719
8888
  return {
8720
8889
  label: option,
8721
8890
  value: option
8722
8891
  };
8723
8892
  }
8724
- return option;
8893
+ const opt = option;
8894
+ return {
8895
+ ...opt,
8896
+ label: utils.getValueKey(labelField, opt),
8897
+ value: utils.getValueKey(valueField, opt)
8898
+ };
8725
8899
  });
8726
8900
  });
8727
8901
  const cls = vue.computed(() => [`${b()}`, {
8728
8902
  [`${m(props.size)}`]: props.size,
8729
8903
  [`${m("disabled")}`]: disabled.value
8730
8904
  }]);
8905
+ vue.watch(() => props.searchInfo, () => {
8906
+ fetch2();
8907
+ }, {
8908
+ deep: true,
8909
+ immediate: props.immediate
8910
+ });
8911
+ async function fetch2(opt) {
8912
+ const {
8913
+ api,
8914
+ dynamicApi,
8915
+ searchInfo,
8916
+ fetchSetting,
8917
+ beforeFetch,
8918
+ afterFetch,
8919
+ handleSearchInfoFn
8920
+ } = props;
8921
+ if (!api && !dynamicApi || loading.value) return;
8922
+ try {
8923
+ loading.value = true;
8924
+ const {
8925
+ listField
8926
+ } = {
8927
+ listField: "resultList",
8928
+ ...fetchSetting
8929
+ };
8930
+ const searchInfoParams = handleSearchInfoFn ? handleSearchInfoFn() : {};
8931
+ let params = lodashEs.merge(searchInfoParams, searchInfo, opt != null ? opt : {});
8932
+ if (beforeFetch && utils.isFunction(beforeFetch)) {
8933
+ params = await beforeFetch(params) || params;
8934
+ }
8935
+ searchInfoRef.value = params;
8936
+ const apiFn = api || (dynamicApi == null ? void 0 : dynamicApi(params));
8937
+ const res = await (apiFn == null ? void 0 : apiFn(params));
8938
+ rawDataSourceRef.value = res.data;
8939
+ const isArrayResult = Array.isArray(res.data);
8940
+ let resultItems = isArrayResult ? res.data : lodashEs.get(res.data, listField);
8941
+ if (afterFetch && utils.isFunction(afterFetch)) {
8942
+ resultItems = await afterFetch(resultItems) || resultItems;
8943
+ }
8944
+ dataSourceRef.value = resultItems;
8945
+ } catch (error) {
8946
+ console.error(error);
8947
+ } finally {
8948
+ loading.value = false;
8949
+ }
8950
+ }
8731
8951
  const handleChange = (value) => {
8732
8952
  if (props.disabled) return;
8733
8953
  const {
@@ -8784,8 +9004,8 @@ const _sfc_main$p = /* @__PURE__ */ vue.defineComponent({
8784
9004
  valueField: { type: [String, Number, Function], default: "value" },
8785
9005
  disabled: { type: Boolean },
8786
9006
  immediate: { type: Boolean, default: true },
8787
- api: {},
8788
- dynamicApi: {},
9007
+ api: { type: Function, default: void 0 },
9008
+ dynamicApi: { type: Function, default: void 0 },
8789
9009
  beforeFetch: {},
8790
9010
  afterFetch: {},
8791
9011
  handleSearchInfoFn: {},