@tmagic/form 1.2.0-beta.22 → 1.2.0-beta.24

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