1/5/1404
This commit is contained in:
@@ -0,0 +1,702 @@
|
||||
import { defineComponent, unref, mergeProps, useSSRContext, computed, ref, watch, createVNode, reactive, shallowRef, toRaw, nextTick } from 'vue';
|
||||
import { ssrRenderAttrs } from 'vue/server-renderer';
|
||||
import { _ as _imports_0 } from './close_light-DbrEdRZI.mjs';
|
||||
import { a as useConfigStore, J as initDefaultProps, C as useConfigInject, ba as useProviderSize, bb as useProviderDisabled, bc as useInjectGlobalForm, F as classNames, V as functionType, X as booleanType, W as stringType, aA as someType, L as anyType, K as objectType, P as PropTypes, M as tuple } from './server.mjs';
|
||||
import _objectSpread from '@babel/runtime/helpers/esm/objectSpread2';
|
||||
import _extends from '@babel/runtime/helpers/esm/extends';
|
||||
import { _ as __nuxt_component_1, d as defaultValidateMessages, a as useStyle, b as useProvideForm, c as cloneByNamePathList, t as toArray$1, g as getNamePath, e as containsNamePath, v as validateRules } from './FormItem-DY7uTw8_.mjs';
|
||||
import isEqual from 'lodash-es/isEqual.js';
|
||||
import compute from 'compute-scroll-into-view';
|
||||
import cloneDeep from 'lodash-es/cloneDeep.js';
|
||||
import intersection from 'lodash-es/intersection.js';
|
||||
import debounce from 'lodash-es/debounce.js';
|
||||
import omit from 'lodash-es/omit.js';
|
||||
import { u as useInjectFormItemContext, a as FormItemRest } from './FormItemContext-CDDW52IT.mjs';
|
||||
|
||||
const _imports_1 = "data:image/svg+xml,%3c?xml%20version='1.0'%20encoding='utf-8'?%3e%3csvg%20version='1.1'%20id='Layer_1'%20xmlns='http://www.w3.org/2000/svg'%20xmlns:xlink='http://www.w3.org/1999/xlink'%20x='0px'%20y='0px'%20width='122.878px'%20height='122.88px'%20viewBox='0%200%20122.878%20122.88'%20enable-background='new%200%200%20122.878%20122.88'%20xml:space='preserve'%3e%3cg%3e%3cpath%20d='M1.426,8.313c-1.901-1.901-1.901-4.984,0-6.886c1.901-1.902,4.984-1.902,6.886,0l53.127,53.127l53.127-53.127%20c1.901-1.902,4.984-1.902,6.887,0c1.901,1.901,1.901,4.985,0,6.886L68.324,61.439l53.128,53.128c1.901,1.901,1.901,4.984,0,6.886%20c-1.902,1.902-4.985,1.902-6.887,0L61.438,68.326L8.312,121.453c-1.901,1.902-4.984,1.902-6.886,0%20c-1.901-1.901-1.901-4.984,0-6.886l53.127-53.128L1.426,8.313L1.426,8.313z'/%3e%3c/g%3e%3c/svg%3e";
|
||||
const _sfc_main = /* @__PURE__ */ defineComponent({
|
||||
__name: "close",
|
||||
__ssrInlineRender: true,
|
||||
setup(__props) {
|
||||
const config = useConfigStore();
|
||||
return (_ctx, _push, _parent, _attrs) => {
|
||||
if (unref(config).isNightStore) {
|
||||
_push(`<img${ssrRenderAttrs(mergeProps({
|
||||
src: _imports_0,
|
||||
alt: "comment",
|
||||
"cursor-pointer": ""
|
||||
}, _attrs))}>`);
|
||||
} else {
|
||||
_push(`<img${ssrRenderAttrs(mergeProps({
|
||||
src: _imports_1,
|
||||
alt: "comment",
|
||||
"cursor-pointer": ""
|
||||
}, _attrs))}>`);
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
const _sfc_setup = _sfc_main.setup;
|
||||
_sfc_main.setup = (props, ctx) => {
|
||||
const ssrContext = useSSRContext();
|
||||
(ssrContext.modules || (ssrContext.modules = /* @__PURE__ */ new Set())).add("assets/img/icons/close.vue");
|
||||
return _sfc_setup ? _sfc_setup(props, ctx) : void 0;
|
||||
};
|
||||
|
||||
function isOptionsObject(options) {
|
||||
return options === Object(options) && Object.keys(options).length !== 0;
|
||||
}
|
||||
function defaultBehavior(actions, behavior) {
|
||||
if (behavior === void 0) {
|
||||
behavior = 'auto';
|
||||
}
|
||||
var canSmoothScroll = ('scrollBehavior' in document.body.style);
|
||||
actions.forEach(function (_ref) {
|
||||
var el = _ref.el,
|
||||
top = _ref.top,
|
||||
left = _ref.left;
|
||||
if (el.scroll && canSmoothScroll) {
|
||||
el.scroll({
|
||||
top: top,
|
||||
left: left,
|
||||
behavior: behavior
|
||||
});
|
||||
} else {
|
||||
el.scrollTop = top;
|
||||
el.scrollLeft = left;
|
||||
}
|
||||
});
|
||||
}
|
||||
function getOptions(options) {
|
||||
if (options === false) {
|
||||
return {
|
||||
block: 'end',
|
||||
inline: 'nearest'
|
||||
};
|
||||
}
|
||||
if (isOptionsObject(options)) {
|
||||
return options;
|
||||
}
|
||||
return {
|
||||
block: 'start',
|
||||
inline: 'nearest'
|
||||
};
|
||||
}
|
||||
function scrollIntoView(target, options) {
|
||||
var isTargetAttached = target.isConnected || target.ownerDocument.documentElement.contains(target);
|
||||
if (isOptionsObject(options) && typeof options.behavior === 'function') {
|
||||
return options.behavior(isTargetAttached ? compute(target, options) : []);
|
||||
}
|
||||
if (!isTargetAttached) {
|
||||
return;
|
||||
}
|
||||
var computeOptions = getOptions(options);
|
||||
return defaultBehavior(compute(target, computeOptions), computeOptions.behavior);
|
||||
}
|
||||
|
||||
function allPromiseFinish(promiseList) {
|
||||
let hasError = false;
|
||||
let count = promiseList.length;
|
||||
const results = [];
|
||||
if (!promiseList.length) {
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
promiseList.forEach((promise, index) => {
|
||||
promise.catch((e) => {
|
||||
hasError = true;
|
||||
return e;
|
||||
}).then((result) => {
|
||||
count -= 1;
|
||||
results[index] = result;
|
||||
if (count > 0) {
|
||||
return;
|
||||
}
|
||||
if (hasError) {
|
||||
reject(results);
|
||||
}
|
||||
resolve(results);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
function isRequired(rules) {
|
||||
let isRequired2 = false;
|
||||
if (rules && rules.length) {
|
||||
rules.every((rule) => {
|
||||
if (rule.required) {
|
||||
isRequired2 = true;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
return isRequired2;
|
||||
}
|
||||
function toArray(value) {
|
||||
if (value === void 0 || value === null) {
|
||||
return [];
|
||||
}
|
||||
return Array.isArray(value) ? value : [value];
|
||||
}
|
||||
function getPropByPath(obj, path, strict) {
|
||||
let tempObj = obj;
|
||||
path = path.replace(/\[(\w+)\]/g, ".$1");
|
||||
path = path.replace(/^\./, "");
|
||||
const keyArr = path.split(".");
|
||||
let i = 0;
|
||||
for (let len = keyArr.length; i < len - 1; ++i) {
|
||||
if (!tempObj && !strict) break;
|
||||
const key = keyArr[i];
|
||||
if (key in tempObj) {
|
||||
tempObj = tempObj[key];
|
||||
} else {
|
||||
if (strict) {
|
||||
throw new Error("please transfer a valid name path to validate!");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return {
|
||||
o: tempObj,
|
||||
k: keyArr[i],
|
||||
v: tempObj ? tempObj[keyArr[i]] : null,
|
||||
isValid: tempObj && keyArr[i] in tempObj
|
||||
};
|
||||
}
|
||||
function useForm(modelRef) {
|
||||
let rulesRef = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : ref({});
|
||||
let options = arguments.length > 2 ? arguments[2] : void 0;
|
||||
const initialModel = cloneDeep(unref(modelRef));
|
||||
const validateInfos = reactive({});
|
||||
const rulesKeys = shallowRef([]);
|
||||
const resetFields = (newValues) => {
|
||||
_extends(unref(modelRef), _extends(_extends({}, cloneDeep(initialModel)), newValues));
|
||||
nextTick(() => {
|
||||
Object.keys(validateInfos).forEach((key) => {
|
||||
validateInfos[key] = {
|
||||
autoLink: false,
|
||||
required: isRequired(unref(rulesRef)[key])
|
||||
};
|
||||
});
|
||||
});
|
||||
};
|
||||
const filterRules = function() {
|
||||
let rules = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
|
||||
let trigger = arguments.length > 1 ? arguments[1] : void 0;
|
||||
if (!trigger.length) {
|
||||
return rules;
|
||||
} else {
|
||||
return rules.filter((rule) => {
|
||||
const triggerList = toArray(rule.trigger || "change");
|
||||
return intersection(triggerList, trigger).length;
|
||||
});
|
||||
}
|
||||
};
|
||||
let lastValidatePromise = null;
|
||||
const validateFields = function(names) {
|
||||
let option = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
||||
let strict = arguments.length > 2 ? arguments[2] : void 0;
|
||||
const promiseList = [];
|
||||
const values = {};
|
||||
for (let i = 0; i < names.length; i++) {
|
||||
const name = names[i];
|
||||
const prop = getPropByPath(unref(modelRef), name, strict);
|
||||
if (!prop.isValid) continue;
|
||||
values[name] = prop.v;
|
||||
const rules = filterRules(unref(rulesRef)[name], toArray(option && option.trigger));
|
||||
if (rules.length) {
|
||||
promiseList.push(validateField(name, prop.v, rules, option || {}).then(() => ({
|
||||
name,
|
||||
errors: [],
|
||||
warnings: []
|
||||
})).catch((ruleErrors) => {
|
||||
const mergedErrors = [];
|
||||
const mergedWarnings = [];
|
||||
ruleErrors.forEach((_ref) => {
|
||||
let {
|
||||
rule: {
|
||||
warningOnly
|
||||
},
|
||||
errors
|
||||
} = _ref;
|
||||
if (warningOnly) {
|
||||
mergedWarnings.push(...errors);
|
||||
} else {
|
||||
mergedErrors.push(...errors);
|
||||
}
|
||||
});
|
||||
if (mergedErrors.length) {
|
||||
return Promise.reject({
|
||||
name,
|
||||
errors: mergedErrors,
|
||||
warnings: mergedWarnings
|
||||
});
|
||||
}
|
||||
return {
|
||||
name,
|
||||
errors: mergedErrors,
|
||||
warnings: mergedWarnings
|
||||
};
|
||||
}));
|
||||
}
|
||||
}
|
||||
const summaryPromise = allPromiseFinish(promiseList);
|
||||
lastValidatePromise = summaryPromise;
|
||||
const returnPromise = summaryPromise.then(() => {
|
||||
if (lastValidatePromise === summaryPromise) {
|
||||
return Promise.resolve(values);
|
||||
}
|
||||
return Promise.reject([]);
|
||||
}).catch((results) => {
|
||||
const errorList = results.filter((result) => result && result.errors.length);
|
||||
return errorList.length ? Promise.reject({
|
||||
values,
|
||||
errorFields: errorList,
|
||||
outOfDate: lastValidatePromise !== summaryPromise
|
||||
}) : Promise.resolve(values);
|
||||
});
|
||||
returnPromise.catch((e) => e);
|
||||
return returnPromise;
|
||||
};
|
||||
const validateField = function(name, value, rules) {
|
||||
let option = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
|
||||
const promise = validateRules([name], value, rules, _extends({
|
||||
validateMessages: defaultValidateMessages
|
||||
}, option), !!option.validateFirst);
|
||||
if (!validateInfos[name]) {
|
||||
return promise.catch((e) => e);
|
||||
}
|
||||
validateInfos[name].validateStatus = "validating";
|
||||
promise.catch((e) => e).then(function() {
|
||||
let results = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
|
||||
var _a;
|
||||
if (validateInfos[name].validateStatus === "validating") {
|
||||
const res = results.filter((result) => result && result.errors.length);
|
||||
validateInfos[name].validateStatus = res.length ? "error" : "success";
|
||||
validateInfos[name].help = res.length ? res.map((r) => r.errors) : null;
|
||||
(_a = options === null || options === void 0 ? void 0 : options.onValidate) === null || _a === void 0 ? void 0 : _a.call(options, name, !res.length, res.length ? toRaw(validateInfos[name].help[0]) : null);
|
||||
}
|
||||
});
|
||||
return promise;
|
||||
};
|
||||
const validate = (names, option) => {
|
||||
let keys = [];
|
||||
let strict = true;
|
||||
if (!names) {
|
||||
strict = false;
|
||||
keys = rulesKeys.value;
|
||||
} else if (Array.isArray(names)) {
|
||||
keys = names;
|
||||
} else {
|
||||
keys = [names];
|
||||
}
|
||||
const promises = validateFields(keys, option || {}, strict);
|
||||
promises.catch((e) => e);
|
||||
return promises;
|
||||
};
|
||||
const clearValidate = (names) => {
|
||||
let keys = [];
|
||||
if (!names) {
|
||||
keys = rulesKeys.value;
|
||||
} else if (Array.isArray(names)) {
|
||||
keys = names;
|
||||
} else {
|
||||
keys = [names];
|
||||
}
|
||||
keys.forEach((key) => {
|
||||
validateInfos[key] && _extends(validateInfos[key], {
|
||||
validateStatus: "",
|
||||
help: null
|
||||
});
|
||||
});
|
||||
};
|
||||
const mergeValidateInfo = (items) => {
|
||||
const info = {
|
||||
autoLink: false
|
||||
};
|
||||
const help = [];
|
||||
const infos = Array.isArray(items) ? items : [items];
|
||||
for (let i = 0; i < infos.length; i++) {
|
||||
const arg = infos[i];
|
||||
if ((arg === null || arg === void 0 ? void 0 : arg.validateStatus) === "error") {
|
||||
info.validateStatus = "error";
|
||||
arg.help && help.push(arg.help);
|
||||
}
|
||||
info.required = info.required || (arg === null || arg === void 0 ? void 0 : arg.required);
|
||||
}
|
||||
info.help = help;
|
||||
return info;
|
||||
};
|
||||
let oldModel = initialModel;
|
||||
let isFirstTime = true;
|
||||
const modelFn = (model) => {
|
||||
const names = [];
|
||||
rulesKeys.value.forEach((key) => {
|
||||
const prop = getPropByPath(model, key, false);
|
||||
const oldProp = getPropByPath(oldModel, key, false);
|
||||
const isFirstValidation = isFirstTime && (options === null || options === void 0 ? void 0 : options.immediate) && prop.isValid;
|
||||
if (isFirstValidation || !isEqual(prop.v, oldProp.v)) {
|
||||
names.push(key);
|
||||
}
|
||||
});
|
||||
validate(names, {
|
||||
trigger: "change"
|
||||
});
|
||||
isFirstTime = false;
|
||||
oldModel = cloneDeep(toRaw(model));
|
||||
};
|
||||
const debounceOptions = options === null || options === void 0 ? void 0 : options.debounce;
|
||||
let first = true;
|
||||
watch(rulesRef, () => {
|
||||
rulesKeys.value = rulesRef ? Object.keys(unref(rulesRef)) : [];
|
||||
if (!first && options && options.validateOnRuleChange) {
|
||||
validate();
|
||||
}
|
||||
first = false;
|
||||
}, {
|
||||
deep: true,
|
||||
immediate: true
|
||||
});
|
||||
watch(rulesKeys, () => {
|
||||
const newValidateInfos = {};
|
||||
rulesKeys.value.forEach((key) => {
|
||||
newValidateInfos[key] = _extends({}, validateInfos[key], {
|
||||
autoLink: false,
|
||||
required: isRequired(unref(rulesRef)[key])
|
||||
});
|
||||
delete validateInfos[key];
|
||||
});
|
||||
for (const key in validateInfos) {
|
||||
if (Object.prototype.hasOwnProperty.call(validateInfos, key)) {
|
||||
delete validateInfos[key];
|
||||
}
|
||||
}
|
||||
_extends(validateInfos, newValidateInfos);
|
||||
}, {
|
||||
immediate: true
|
||||
});
|
||||
watch(modelRef, debounceOptions && debounceOptions.wait ? debounce(modelFn, debounceOptions.wait, omit(debounceOptions, ["wait"])) : modelFn, {
|
||||
immediate: options && !!options.immediate,
|
||||
deep: true
|
||||
});
|
||||
return {
|
||||
modelRef,
|
||||
rulesRef,
|
||||
initialModel,
|
||||
validateInfos,
|
||||
resetFields,
|
||||
validate,
|
||||
validateField,
|
||||
mergeValidateInfo,
|
||||
clearValidate
|
||||
};
|
||||
}
|
||||
const formProps = () => ({
|
||||
layout: PropTypes.oneOf(tuple("horizontal", "inline", "vertical")),
|
||||
labelCol: objectType(),
|
||||
wrapperCol: objectType(),
|
||||
colon: booleanType(),
|
||||
labelAlign: stringType(),
|
||||
labelWrap: booleanType(),
|
||||
prefixCls: String,
|
||||
requiredMark: someType([String, Boolean]),
|
||||
/** @deprecated Will warning in future branch. Pls use `requiredMark` instead. */
|
||||
hideRequiredMark: booleanType(),
|
||||
model: PropTypes.object,
|
||||
rules: objectType(),
|
||||
validateMessages: objectType(),
|
||||
validateOnRuleChange: booleanType(),
|
||||
// 提交失败自动滚动到第一个错误字段
|
||||
scrollToFirstError: anyType(),
|
||||
onSubmit: functionType(),
|
||||
name: String,
|
||||
validateTrigger: someType([String, Array]),
|
||||
size: stringType(),
|
||||
disabled: booleanType(),
|
||||
onValuesChange: functionType(),
|
||||
onFieldsChange: functionType(),
|
||||
onFinish: functionType(),
|
||||
onFinishFailed: functionType(),
|
||||
onValidate: functionType()
|
||||
});
|
||||
function isEqualName(name1, name2) {
|
||||
return isEqual(toArray$1(name1), toArray$1(name2));
|
||||
}
|
||||
const Form = defineComponent({
|
||||
compatConfig: {
|
||||
MODE: 3
|
||||
},
|
||||
name: "AForm",
|
||||
inheritAttrs: false,
|
||||
props: initDefaultProps(formProps(), {
|
||||
layout: "horizontal",
|
||||
hideRequiredMark: false,
|
||||
colon: true
|
||||
}),
|
||||
Item: __nuxt_component_1,
|
||||
useForm,
|
||||
// emits: ['finishFailed', 'submit', 'finish', 'validate'],
|
||||
setup(props, _ref) {
|
||||
let {
|
||||
emit,
|
||||
slots,
|
||||
expose,
|
||||
attrs
|
||||
} = _ref;
|
||||
const {
|
||||
prefixCls,
|
||||
direction,
|
||||
form: contextForm,
|
||||
size,
|
||||
disabled
|
||||
} = useConfigInject("form", props);
|
||||
const requiredMark = computed(() => props.requiredMark === "" || props.requiredMark);
|
||||
const mergedRequiredMark = computed(() => {
|
||||
var _a;
|
||||
if (requiredMark.value !== void 0) {
|
||||
return requiredMark.value;
|
||||
}
|
||||
if (contextForm && ((_a = contextForm.value) === null || _a === void 0 ? void 0 : _a.requiredMark) !== void 0) {
|
||||
return contextForm.value.requiredMark;
|
||||
}
|
||||
if (props.hideRequiredMark) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
useProviderSize(size);
|
||||
useProviderDisabled(disabled);
|
||||
const mergedColon = computed(() => {
|
||||
var _a, _b;
|
||||
return (_a = props.colon) !== null && _a !== void 0 ? _a : (_b = contextForm.value) === null || _b === void 0 ? void 0 : _b.colon;
|
||||
});
|
||||
const {
|
||||
validateMessages: globalValidateMessages
|
||||
} = useInjectGlobalForm();
|
||||
const validateMessages = computed(() => {
|
||||
return _extends(_extends(_extends({}, defaultValidateMessages), globalValidateMessages.value), props.validateMessages);
|
||||
});
|
||||
const [wrapSSR, hashId] = useStyle(prefixCls);
|
||||
const formClassName = computed(() => classNames(prefixCls.value, {
|
||||
[`${prefixCls.value}-${props.layout}`]: true,
|
||||
[`${prefixCls.value}-hide-required-mark`]: mergedRequiredMark.value === false,
|
||||
[`${prefixCls.value}-rtl`]: direction.value === "rtl",
|
||||
[`${prefixCls.value}-${size.value}`]: size.value
|
||||
}, hashId.value));
|
||||
const lastValidatePromise = ref();
|
||||
const fields = {};
|
||||
const addField = (eventKey, field) => {
|
||||
fields[eventKey] = field;
|
||||
};
|
||||
const removeField = (eventKey) => {
|
||||
delete fields[eventKey];
|
||||
};
|
||||
const getFieldsByNameList = (nameList) => {
|
||||
const provideNameList = !!nameList;
|
||||
const namePathList = provideNameList ? toArray$1(nameList).map(getNamePath) : [];
|
||||
if (!provideNameList) {
|
||||
return Object.values(fields);
|
||||
} else {
|
||||
return Object.values(fields).filter((field) => namePathList.findIndex((namePath) => isEqualName(namePath, field.fieldName.value)) > -1);
|
||||
}
|
||||
};
|
||||
const resetFields = (name) => {
|
||||
if (!props.model) {
|
||||
return;
|
||||
}
|
||||
getFieldsByNameList(name).forEach((field) => {
|
||||
field.resetField();
|
||||
});
|
||||
};
|
||||
const clearValidate = (name) => {
|
||||
getFieldsByNameList(name).forEach((field) => {
|
||||
field.clearValidate();
|
||||
});
|
||||
};
|
||||
const handleFinishFailed = (errorInfo) => {
|
||||
const {
|
||||
scrollToFirstError
|
||||
} = props;
|
||||
emit("finishFailed", errorInfo);
|
||||
if (scrollToFirstError && errorInfo.errorFields.length) {
|
||||
let scrollToFieldOptions = {};
|
||||
if (typeof scrollToFirstError === "object") {
|
||||
scrollToFieldOptions = scrollToFirstError;
|
||||
}
|
||||
scrollToField(errorInfo.errorFields[0].name, scrollToFieldOptions);
|
||||
}
|
||||
};
|
||||
const validate = function() {
|
||||
return validateField(...arguments);
|
||||
};
|
||||
const scrollToField = function(name) {
|
||||
let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
||||
const fields2 = getFieldsByNameList(name ? [name] : void 0);
|
||||
if (fields2.length) {
|
||||
const fieldId = fields2[0].fieldId.value;
|
||||
const node = fieldId ? (void 0).getElementById(fieldId) : null;
|
||||
if (node) {
|
||||
scrollIntoView(node, _extends({
|
||||
scrollMode: "if-needed",
|
||||
block: "nearest"
|
||||
}, options));
|
||||
}
|
||||
}
|
||||
};
|
||||
const getFieldsValue = function() {
|
||||
let nameList = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : true;
|
||||
if (nameList === true) {
|
||||
const allNameList = [];
|
||||
Object.values(fields).forEach((_ref2) => {
|
||||
let {
|
||||
namePath
|
||||
} = _ref2;
|
||||
allNameList.push(namePath.value);
|
||||
});
|
||||
return cloneByNamePathList(props.model, allNameList);
|
||||
} else {
|
||||
return cloneByNamePathList(props.model, nameList);
|
||||
}
|
||||
};
|
||||
const validateFields = (nameList, options) => {
|
||||
if (!props.model) {
|
||||
return Promise.reject("Form `model` is required for validateFields to work.");
|
||||
}
|
||||
const provideNameList = !!nameList;
|
||||
const namePathList = provideNameList ? toArray$1(nameList).map(getNamePath) : [];
|
||||
const promiseList = [];
|
||||
Object.values(fields).forEach((field) => {
|
||||
var _a;
|
||||
if (!provideNameList) {
|
||||
namePathList.push(field.namePath.value);
|
||||
}
|
||||
if (!((_a = field.rules) === null || _a === void 0 ? void 0 : _a.value.length)) {
|
||||
return;
|
||||
}
|
||||
const fieldNamePath = field.namePath.value;
|
||||
if (!provideNameList || containsNamePath(namePathList, fieldNamePath)) {
|
||||
const promise = field.validateRules(_extends({
|
||||
validateMessages: validateMessages.value
|
||||
}, options));
|
||||
promiseList.push(promise.then(() => ({
|
||||
name: fieldNamePath,
|
||||
errors: [],
|
||||
warnings: []
|
||||
})).catch((ruleErrors) => {
|
||||
const mergedErrors = [];
|
||||
const mergedWarnings = [];
|
||||
ruleErrors.forEach((_ref3) => {
|
||||
let {
|
||||
rule: {
|
||||
warningOnly
|
||||
},
|
||||
errors
|
||||
} = _ref3;
|
||||
if (warningOnly) {
|
||||
mergedWarnings.push(...errors);
|
||||
} else {
|
||||
mergedErrors.push(...errors);
|
||||
}
|
||||
});
|
||||
if (mergedErrors.length) {
|
||||
return Promise.reject({
|
||||
name: fieldNamePath,
|
||||
errors: mergedErrors,
|
||||
warnings: mergedWarnings
|
||||
});
|
||||
}
|
||||
return {
|
||||
name: fieldNamePath,
|
||||
errors: mergedErrors,
|
||||
warnings: mergedWarnings
|
||||
};
|
||||
}));
|
||||
}
|
||||
});
|
||||
const summaryPromise = allPromiseFinish(promiseList);
|
||||
lastValidatePromise.value = summaryPromise;
|
||||
const returnPromise = summaryPromise.then(() => {
|
||||
if (lastValidatePromise.value === summaryPromise) {
|
||||
return Promise.resolve(getFieldsValue(namePathList));
|
||||
}
|
||||
return Promise.reject([]);
|
||||
}).catch((results) => {
|
||||
const errorList = results.filter((result) => result && result.errors.length);
|
||||
return Promise.reject({
|
||||
values: getFieldsValue(namePathList),
|
||||
errorFields: errorList,
|
||||
outOfDate: lastValidatePromise.value !== summaryPromise
|
||||
});
|
||||
});
|
||||
returnPromise.catch((e) => e);
|
||||
return returnPromise;
|
||||
};
|
||||
const validateField = function() {
|
||||
return validateFields(...arguments);
|
||||
};
|
||||
const handleSubmit = (e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
emit("submit", e);
|
||||
if (props.model) {
|
||||
const res = validateFields();
|
||||
res.then((values) => {
|
||||
emit("finish", values);
|
||||
}).catch((errors) => {
|
||||
handleFinishFailed(errors);
|
||||
});
|
||||
}
|
||||
};
|
||||
expose({
|
||||
resetFields,
|
||||
clearValidate,
|
||||
validateFields,
|
||||
getFieldsValue,
|
||||
validate,
|
||||
scrollToField
|
||||
});
|
||||
useProvideForm({
|
||||
model: computed(() => props.model),
|
||||
name: computed(() => props.name),
|
||||
labelAlign: computed(() => props.labelAlign),
|
||||
labelCol: computed(() => props.labelCol),
|
||||
labelWrap: computed(() => props.labelWrap),
|
||||
wrapperCol: computed(() => props.wrapperCol),
|
||||
vertical: computed(() => props.layout === "vertical"),
|
||||
colon: mergedColon,
|
||||
requiredMark: mergedRequiredMark,
|
||||
validateTrigger: computed(() => props.validateTrigger),
|
||||
rules: computed(() => props.rules),
|
||||
addField,
|
||||
removeField,
|
||||
onValidate: (name, status, errors) => {
|
||||
emit("validate", name, status, errors);
|
||||
},
|
||||
validateMessages
|
||||
});
|
||||
watch(() => props.rules, () => {
|
||||
if (props.validateOnRuleChange) {
|
||||
validateFields();
|
||||
}
|
||||
});
|
||||
return () => {
|
||||
var _a;
|
||||
return wrapSSR(createVNode("form", _objectSpread(_objectSpread({}, attrs), {}, {
|
||||
"onSubmit": handleSubmit,
|
||||
"class": [formClassName.value, attrs.class]
|
||||
}), [(_a = slots.default) === null || _a === void 0 ? void 0 : _a.call(slots)]));
|
||||
};
|
||||
}
|
||||
});
|
||||
Form.useInjectFormItemContext = useInjectFormItemContext;
|
||||
Form.ItemRest = FormItemRest;
|
||||
Form.install = function(app) {
|
||||
app.component(Form.name, Form);
|
||||
app.component(Form.Item.name, Form.Item);
|
||||
app.component(FormItemRest.name, FormItemRest);
|
||||
return app;
|
||||
};
|
||||
|
||||
export { Form as F, _sfc_main as _ };
|
||||
//# sourceMappingURL=index-DwUxJCFD.mjs.map
|
||||
Reference in New Issue
Block a user