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