@tmagic/form 1.2.0-beta.21 → 1.2.0-beta.23

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.
@@ -3117,30 +3117,32 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
3117
3117
  let items = [];
3118
3118
  const { config } = props;
3119
3119
  const { option } = config;
3120
- let { body } = option;
3120
+ const { root = "", totalKey = "total" } = option;
3121
+ let { body = {}, url } = option;
3122
+ if (typeof url === "function") {
3123
+ url = await url(mForm, { model: props.model, formValue: mForm?.values });
3124
+ }
3121
3125
  let postOptions = {
3122
3126
  method: option.method || "POST",
3123
- url: option.url,
3127
+ url,
3124
3128
  cache: option.cache,
3125
3129
  timeout: option.timeout,
3126
3130
  mode: option.mode,
3127
3131
  headers: option.headers || {},
3128
3132
  json: option.json || false
3129
3133
  };
3130
- if (body) {
3131
- if (typeof body === "function") {
3132
- body = body(mForm, {
3133
- model: props.model,
3134
- formValue: mForm?.values,
3135
- formValues: mForm?.values,
3136
- config: props.config
3137
- });
3138
- }
3139
- body.query = query.value;
3140
- body.pgSize = pgSize.value;
3141
- body.pgIndex = pgIndex.value;
3142
- postOptions.data = body;
3134
+ if (typeof body === "function") {
3135
+ body = body(mForm, {
3136
+ model: props.model,
3137
+ formValue: mForm?.values,
3138
+ formValues: mForm?.values,
3139
+ config: props.config
3140
+ });
3143
3141
  }
3142
+ body.query = query.value;
3143
+ body.pgSize = pgSize.value;
3144
+ body.pgIndex = pgIndex.value;
3145
+ postOptions.data = body;
3144
3146
  const requestFuc = getConfig("request");
3145
3147
  if (typeof option.beforeRequest === "function") {
3146
3148
  postOptions = option.beforeRequest(mForm, postOptions, {
@@ -3160,9 +3162,13 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
3160
3162
  config: props.config
3161
3163
  });
3162
3164
  }
3163
- const optionsData = res[option.root];
3164
- if (res.total > 0) {
3165
- total.value = res.total;
3165
+ const optionsData = root.split(".").reduce((accumulator, currentValue) => accumulator[currentValue], res);
3166
+ const resTotal = globalThis.parseInt(
3167
+ totalKey.split(".").reduce((accumulator, currentValue) => accumulator[currentValue], res),
3168
+ 10
3169
+ );
3170
+ if (resTotal > 0) {
3171
+ total.value = resTotal;
3166
3172
  }
3167
3173
  remoteData.value = remoteData.value.concat(optionsData);
3168
3174
  if (optionsData) {
@@ -3211,6 +3217,8 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
3211
3217
  return [];
3212
3218
  const { config } = props;
3213
3219
  const { option } = config;
3220
+ const { root = "", initRoot = "" } = option;
3221
+ let { initBody = {} } = option;
3214
3222
  let options2 = [];
3215
3223
  let url = option.initUrl;
3216
3224
  if (!url) {
@@ -3219,22 +3227,45 @@ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
3219
3227
  if (typeof url === "function") {
3220
3228
  url = await url(mForm, { model: props.model, formValue: mForm?.values });
3221
3229
  }
3222
- const postOptions = {
3230
+ if (typeof initBody === "function") {
3231
+ initBody = initBody(mForm, {
3232
+ model: props.model,
3233
+ formValue: mForm?.values,
3234
+ formValues: mForm?.values,
3235
+ config: props.config
3236
+ });
3237
+ }
3238
+ let postOptions = {
3223
3239
  method: option.method || "POST",
3224
3240
  url,
3225
3241
  data: {
3226
- id: props.model[props.name]
3242
+ id: props.model[props.name],
3243
+ ...initBody
3227
3244
  },
3228
3245
  mode: option.mode,
3229
3246
  headers: option.headers || {},
3230
3247
  json: option.json || false
3231
3248
  };
3249
+ if (typeof option.beforeInitRequest === "function") {
3250
+ postOptions = option.beforeInitRequest(mForm, postOptions, {
3251
+ model: props.model,
3252
+ formValue: mForm?.values
3253
+ });
3254
+ }
3232
3255
  if (option.method?.toLocaleLowerCase() === "jsonp") {
3233
3256
  postOptions.jsonpCallback = option.jsonpCallback || "callback";
3234
3257
  }
3235
3258
  const requestFuc = getConfig("request");
3236
- const res = await requestFuc(postOptions);
3237
- let initData = res[option.root];
3259
+ let res = await requestFuc(postOptions);
3260
+ if (typeof option.afterRequest === "function") {
3261
+ res = option.afterRequest(mForm, res, {
3262
+ model: props.model,
3263
+ formValue: mForm?.values,
3264
+ formValues: mForm?.values,
3265
+ config: props.config
3266
+ });
3267
+ }
3268
+ let initData = (initRoot || root).split(".").reduce((accumulator, currentValue) => accumulator[currentValue], res);
3238
3269
  if (initData) {
3239
3270
  if (!Array.isArray(initData)) {
3240
3271
  initData = [initData];