UNPKG

tdesign-mobile-vue

Version:
1,005 lines (961 loc) 40.9 kB
/** * tdesign v1.9.3 * (c) 2025 TDesign Group * @license MIT */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray'); var _asyncToGenerator = require('@babel/runtime/helpers/asyncToGenerator'); var _defineProperty = require('@babel/runtime/helpers/defineProperty'); var vue = require('vue'); var _regeneratorRuntime = require('@babel/runtime/regenerator'); var tdesignIconsVueNext = require('tdesign-icons-vue-next'); var form_formModel = require('./form-model.js'); var form_formItemProps = require('./form-item-props.js'); var form_const = require('./const.js'); var config = require('../config.js'); var hooks_tnode = require('../hooks/tnode.js'); var hooks_useClass = require('../hooks/useClass.js'); var isNil = require('../_chunks/dep-42b4b669.js'); var isNumber = require('../_chunks/dep-ff4786c0.js'); var isBoolean = require('../_chunks/dep-d5bc9590.js'); var get = require('../_chunks/dep-7fa39e6f.js'); var configProvider_useConfig = require('../_chunks/dep-21f18d3b.js'); var isArray = require('../_chunks/dep-757b152c.js'); var set = require('../_chunks/dep-42ca7568.js'); var _initCloneObject = require('../_chunks/dep-85204fa0.js'); var configProvider_context = require('../_chunks/dep-b9642a56.js'); var _overRest = require('../_chunks/dep-0e05e959.js'); var isArrayLikeObject = require('../_chunks/dep-060bf1cf.js'); var _baseGetTag = require('../_chunks/dep-2f809ed9.js'); var isObjectLike = require('../_chunks/dep-5be9198d.js'); var _arrayMap = require('../_chunks/dep-ae809b86.js'); var eq = require('../_chunks/dep-49f0a63e.js'); var _isIterateeCall = require('../_chunks/dep-324da301.js'); var _baseClone = require('../_chunks/dep-da6dc2cf.js'); var _createCompounder = require('../_chunks/dep-3d4c38f1.js'); var toString = require('../_chunks/dep-afa9f3f2.js'); var isString = require('../_chunks/dep-c3cb976c.js'); require('../_chunks/dep-57aa1aa0.js'); require('../_chunks/dep-ef223206.js'); require('@babel/runtime/helpers/typeof'); require('../_chunks/dep-675798b4.js'); require('../_chunks/dep-ccc9ad3d.js'); require('../_chunks/dep-d950aa21.js'); require('../_chunks/dep-a697b1b9.js'); require('../_chunks/dep-88fe047a.js'); require('../_chunks/dep-4dfb9b9c.js'); require('../_chunks/dep-7c911ba3.js'); require('../hooks/render-tnode.js'); require('../_chunks/dep-a7319409.js'); require('../_chunks/dep-288156c7.js'); require('../_chunks/dep-6df33aaf.js'); require('../_common/js/utils/general.js'); require('../_chunks/dep-0528a76d.js'); require('../_chunks/dep-2b08c0a6.js'); require('../_chunks/dep-94eeec5a.js'); require('../_chunks/dep-61dfd347.js'); require('../_chunks/dep-f6b14f80.js'); require('../_chunks/dep-a8d60643.js'); require('../_chunks/dep-c65deed7.js'); require('../_common/js/global-config/mobile/default-config.js'); require('../_common/js/global-config/mobile/locale/zh_CN.js'); require('../_chunks/dep-28b1e09d.js'); require('dayjs'); function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } var _toConsumableArray__default = /*#__PURE__*/_interopDefaultLegacy(_toConsumableArray); var _asyncToGenerator__default = /*#__PURE__*/_interopDefaultLegacy(_asyncToGenerator); var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty); var _regeneratorRuntime__default = /*#__PURE__*/_interopDefaultLegacy(_regeneratorRuntime); /** * This method is like `_.assignIn` except that it accepts `customizer` * which is invoked to produce the assigned values. If `customizer` returns * `undefined`, assignment is handled by the method instead. The `customizer` * is invoked with five arguments: (objValue, srcValue, key, object, source). * * **Note:** This method mutates `object`. * * @static * @memberOf _ * @since 4.0.0 * @alias extendWith * @category Object * @param {Object} object The destination object. * @param {...Object} sources The source objects. * @param {Function} [customizer] The function to customize assigned values. * @returns {Object} Returns `object`. * @see _.assignWith * @example * * function customizer(objValue, srcValue) { * return _.isUndefined(objValue) ? srcValue : objValue; * } * * var defaults = _.partialRight(_.assignInWith, customizer); * * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 }); * // => { 'a': 1, 'b': 2 } */ var assignInWith = configProvider_context.createAssigner(function (object, source, srcIndex, customizer) { _initCloneObject.copyObject(source, _initCloneObject.keysIn(source), object, customizer); }); var extendWith = assignInWith; /** `Object#toString` result references. */ var domExcTag = '[object DOMException]', errorTag = '[object Error]'; /** * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`, * `SyntaxError`, `TypeError`, or `URIError` object. * * @static * @memberOf _ * @since 3.0.0 * @category Lang * @param {*} value The value to check. * @returns {boolean} Returns `true` if `value` is an error object, else `false`. * @example * * _.isError(new Error); * // => true * * _.isError(Error); * // => false */ function isError(value) { if (!isObjectLike.isObjectLike(value)) { return false; } var tag = _baseGetTag.baseGetTag(value); return tag == errorTag || tag == domExcTag || typeof value.message == 'string' && typeof value.name == 'string' && !_initCloneObject.isPlainObject(value); } /** * Attempts to invoke `func`, returning either the result or the caught error * object. Any additional arguments are provided to `func` when it's invoked. * * @static * @memberOf _ * @since 3.0.0 * @category Util * @param {Function} func The function to attempt. * @param {...*} [args] The arguments to invoke `func` with. * @returns {*} Returns the `func` result or error object. * @example * * // Avoid throwing errors for invalid selectors. * var elements = _.attempt(function(selector) { * return document.querySelectorAll(selector); * }, '>_>'); * * if (_.isError(elements)) { * elements = []; * } */ var attempt = isArrayLikeObject.baseRest(function (func, args) { try { return _overRest.apply(func, undefined, args); } catch (e) { return isError(e) ? e : new Error(e); } }); var attempt$1 = attempt; /** Used to map characters to HTML entities. */ var htmlEscapes = { '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }; /** * Used by `_.escape` to convert characters to HTML entities. * * @private * @param {string} chr The matched character to escape. * @returns {string} Returns the escaped character. */ var escapeHtmlChar = _createCompounder.basePropertyOf(htmlEscapes); var escapeHtmlChar$1 = escapeHtmlChar; /** Used to match HTML entities and HTML characters. */ var reUnescapedHtml = /[&<>"']/g, reHasUnescapedHtml = RegExp(reUnescapedHtml.source); /** * Converts the characters "&", "<", ">", '"', and "'" in `string` to their * corresponding HTML entities. * * **Note:** No other characters are escaped. To escape additional * characters use a third-party library like [_he_](https://mths.be/he). * * Though the ">" character is escaped for symmetry, characters like * ">" and "/" don't need escaping in HTML and have no special meaning * unless they're part of a tag or unquoted attribute value. See * [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands) * (under "semi-related fun fact") for more details. * * When working with HTML you should always * [quote attribute values](http://wonko.com/post/html-escaping) to reduce * XSS vectors. * * @static * @since 0.1.0 * @memberOf _ * @category String * @param {string} [string=''] The string to escape. * @returns {string} Returns the escaped string. * @example * * _.escape('fred, barney, & pebbles'); * // => 'fred, barney, &amp; pebbles' */ function escape(string) { string = toString.toString(string); return string && reHasUnescapedHtml.test(string) ? string.replace(reUnescapedHtml, escapeHtmlChar$1) : string; } /** * The base implementation of `_.values` and `_.valuesIn` which creates an * array of `object` property values corresponding to the property names * of `props`. * * @private * @param {Object} object The object to query. * @param {Array} props The property names to get values for. * @returns {Object} Returns the array of property values. */ function baseValues(object, props) { return _arrayMap.arrayMap(props, function (key) { return object[key]; }); } /** Used for built-in method references. */ var objectProto$1 = Object.prototype; /** Used to check objects for own properties. */ var hasOwnProperty$1 = objectProto$1.hasOwnProperty; /** * Used by `_.defaults` to customize its `_.assignIn` use to assign properties * of source objects to the destination object for all destination properties * that resolve to `undefined`. * * @private * @param {*} objValue The destination value. * @param {*} srcValue The source value. * @param {string} key The key of the property to assign. * @param {Object} object The parent object of `objValue`. * @returns {*} Returns the value to assign. */ function customDefaultsAssignIn(objValue, srcValue, key, object) { if (objValue === undefined || eq.eq(objValue, objectProto$1[key]) && !hasOwnProperty$1.call(object, key)) { return srcValue; } return objValue; } /** Used to escape characters for inclusion in compiled string literals. */ var stringEscapes = { '\\': '\\', "'": "'", '\n': 'n', '\r': 'r', "\u2028": 'u2028', "\u2029": 'u2029' }; /** * Used by `_.template` to escape characters for inclusion in compiled string literals. * * @private * @param {string} chr The matched character to escape. * @returns {string} Returns the escaped character. */ function escapeStringChar(chr) { return '\\' + stringEscapes[chr]; } /** Used to match template delimiters. */ var reInterpolate = /<%=([\s\S]+?)%>/g; var reInterpolate$1 = reInterpolate; /** Used to match template delimiters. */ var reEscape = /<%-([\s\S]+?)%>/g; var reEscape$1 = reEscape; /** Used to match template delimiters. */ var reEvaluate = /<%([\s\S]+?)%>/g; var reEvaluate$1 = reEvaluate; /** * By default, the template delimiters used by lodash are like those in * embedded Ruby (ERB) as well as ES2015 template strings. Change the * following template settings to use alternative delimiters. * * @static * @memberOf _ * @type {Object} */ var templateSettings = { /** * Used to detect `data` property values to be HTML-escaped. * * @memberOf _.templateSettings * @type {RegExp} */ 'escape': reEscape$1, /** * Used to detect code to be evaluated. * * @memberOf _.templateSettings * @type {RegExp} */ 'evaluate': reEvaluate$1, /** * Used to detect `data` property values to inject. * * @memberOf _.templateSettings * @type {RegExp} */ 'interpolate': reInterpolate$1, /** * Used to reference the data object in the template text. * * @memberOf _.templateSettings * @type {string} */ 'variable': '', /** * Used to import variables into the compiled template. * * @memberOf _.templateSettings * @type {Object} */ 'imports': { /** * A reference to the `lodash` function. * * @memberOf _.templateSettings.imports * @type {Function} */ '_': { 'escape': escape } } }; var templateSettings$1 = templateSettings; /** Error message constants. */ var INVALID_TEMPL_VAR_ERROR_TEXT = 'Invalid `variable` option passed into `_.template`'; /** Used to match empty string literals in compiled template source. */ var reEmptyStringLeading = /\b__p \+= '';/g, reEmptyStringMiddle = /\b(__p \+=) '' \+/g, reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g; /** * Used to validate the `validate` option in `_.template` variable. * * Forbids characters which could potentially change the meaning of the function argument definition: * - "()," (modification of function parameters) * - "=" (default value) * - "[]{}" (destructuring of function parameters) * - "/" (beginning of a comment) * - whitespace */ var reForbiddenIdentifierChars = /[()=,{}\[\]\/\s]/; /** * Used to match * [ES template delimiters](http://ecma-international.org/ecma-262/7.0/#sec-template-literal-lexical-components). */ var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g; /** Used to ensure capturing order of template delimiters. */ var reNoMatch = /($^)/; /** Used to match unescaped characters in compiled string literals. */ var reUnescapedString = /['\n\r\u2028\u2029\\]/g; /** Used for built-in method references. */ var objectProto = Object.prototype; /** Used to check objects for own properties. */ var hasOwnProperty = objectProto.hasOwnProperty; /** * Creates a compiled template function that can interpolate data properties * in "interpolate" delimiters, HTML-escape interpolated data properties in * "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data * properties may be accessed as free variables in the template. If a setting * object is given, it takes precedence over `_.templateSettings` values. * * **Note:** In the development build `_.template` utilizes * [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl) * for easier debugging. * * For more information on precompiling templates see * [lodash's custom builds documentation](https://lodash.com/custom-builds). * * For more information on Chrome extension sandboxes see * [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval). * * @static * @since 0.1.0 * @memberOf _ * @category String * @param {string} [string=''] The template string. * @param {Object} [options={}] The options object. * @param {RegExp} [options.escape=_.templateSettings.escape] * The HTML "escape" delimiter. * @param {RegExp} [options.evaluate=_.templateSettings.evaluate] * The "evaluate" delimiter. * @param {Object} [options.imports=_.templateSettings.imports] * An object to import into the template as free variables. * @param {RegExp} [options.interpolate=_.templateSettings.interpolate] * The "interpolate" delimiter. * @param {string} [options.sourceURL='templateSources[n]'] * The sourceURL of the compiled template. * @param {string} [options.variable='obj'] * The data object variable name. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. * @returns {Function} Returns the compiled template function. * @example * * // Use the "interpolate" delimiter to create a compiled template. * var compiled = _.template('hello <%= user %>!'); * compiled({ 'user': 'fred' }); * // => 'hello fred!' * * // Use the HTML "escape" delimiter to escape data property values. * var compiled = _.template('<b><%- value %></b>'); * compiled({ 'value': '<script>' }); * // => '<b>&lt;script&gt;</b>' * * // Use the "evaluate" delimiter to execute JavaScript and generate HTML. * var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>'); * compiled({ 'users': ['fred', 'barney'] }); * // => '<li>fred</li><li>barney</li>' * * // Use the internal `print` function in "evaluate" delimiters. * var compiled = _.template('<% print("hello " + user); %>!'); * compiled({ 'user': 'barney' }); * // => 'hello barney!' * * // Use the ES template literal delimiter as an "interpolate" delimiter. * // Disable support by replacing the "interpolate" delimiter. * var compiled = _.template('hello ${ user }!'); * compiled({ 'user': 'pebbles' }); * // => 'hello pebbles!' * * // Use backslashes to treat delimiters as plain text. * var compiled = _.template('<%= "\\<%- value %\\>" %>'); * compiled({ 'value': 'ignored' }); * // => '<%- value %>' * * // Use the `imports` option to import `jQuery` as `jq`. * var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>'; * var compiled = _.template(text, { 'imports': { 'jq': jQuery } }); * compiled({ 'users': ['fred', 'barney'] }); * // => '<li>fred</li><li>barney</li>' * * // Use the `sourceURL` option to specify a custom sourceURL for the template. * var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' }); * compiled(data); * // => Find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector. * * // Use the `variable` option to ensure a with-statement isn't used in the compiled template. * var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' }); * compiled.source; * // => function(data) { * // var __t, __p = ''; * // __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!'; * // return __p; * // } * * // Use custom template delimiters. * _.templateSettings.interpolate = /{{([\s\S]+?)}}/g; * var compiled = _.template('hello {{ user }}!'); * compiled({ 'user': 'mustache' }); * // => 'hello mustache!' * * // Use the `source` property to inline compiled templates for meaningful * // line numbers in error messages and stack traces. * fs.writeFileSync(path.join(process.cwd(), 'jst.js'), '\ * var JST = {\ * "main": ' + _.template(mainText).source + '\ * };\ * '); */ function template(string, options, guard) { // Based on John Resig's `tmpl` implementation // (http://ejohn.org/blog/javascript-micro-templating/) // and Laura Doktorova's doT.js (https://github.com/olado/doT). var settings = templateSettings$1.imports._.templateSettings || templateSettings$1; if (guard && _isIterateeCall.isIterateeCall(string, options, guard)) { options = undefined; } string = toString.toString(string); options = extendWith({}, options, settings, customDefaultsAssignIn); var imports = extendWith({}, options.imports, settings.imports, customDefaultsAssignIn), importsKeys = _baseClone.keys(imports), importsValues = baseValues(imports, importsKeys); var isEscaping, isEvaluating, index = 0, interpolate = options.interpolate || reNoMatch, source = "__p += '"; // Compile the regexp to match each delimiter. var reDelimiters = RegExp((options.escape || reNoMatch).source + '|' + interpolate.source + '|' + (interpolate === reInterpolate$1 ? reEsTemplate : reNoMatch).source + '|' + (options.evaluate || reNoMatch).source + '|$', 'g'); // Use a sourceURL for easier debugging. // The sourceURL gets injected into the source that's eval-ed, so be careful // to normalize all kinds of whitespace, so e.g. newlines (and unicode versions of it) can't sneak in // and escape the comment, thus injecting code that gets evaled. var sourceURL = hasOwnProperty.call(options, 'sourceURL') ? '//# sourceURL=' + (options.sourceURL + '').replace(/\s/g, ' ') + '\n' : ''; string.replace(reDelimiters, function (match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) { interpolateValue || (interpolateValue = esTemplateValue); // Escape characters that can't be included in string literals. source += string.slice(index, offset).replace(reUnescapedString, escapeStringChar); // Replace delimiters with snippets. if (escapeValue) { isEscaping = true; source += "' +\n__e(" + escapeValue + ") +\n'"; } if (evaluateValue) { isEvaluating = true; source += "';\n" + evaluateValue + ";\n__p += '"; } if (interpolateValue) { source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'"; } index = offset + match.length; // The JS engine embedded in Adobe products needs `match` returned in // order to produce the correct `offset` value. return match; }); source += "';\n"; // If `variable` is not specified wrap a with-statement around the generated // code to add the data object to the top of the scope chain. var variable = hasOwnProperty.call(options, 'variable') && options.variable; if (!variable) { source = 'with (obj) {\n' + source + '\n}\n'; } // Throw an error if a forbidden character was found in `variable`, to prevent // potential command injection attacks. else if (reForbiddenIdentifierChars.test(variable)) { throw new Error(INVALID_TEMPL_VAR_ERROR_TEXT); } // Cleanup code by stripping empty strings. source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source).replace(reEmptyStringMiddle, '$1').replace(reEmptyStringTrailing, '$1;'); // Frame code as the function body. source = 'function(' + (variable || 'obj') + ') {\n' + (variable ? '' : 'obj || (obj = {});\n') + "var __t, __p = ''" + (isEscaping ? ', __e = _.escape' : '') + (isEvaluating ? ', __j = Array.prototype.join;\n' + "function print() { __p += __j.call(arguments, '') }\n" : ';\n') + source + 'return __p\n}'; var result = attempt$1(function () { return Function(importsKeys, sourceURL + 'return ' + source).apply(undefined, importsValues); }); // Provide the compiled function's source by its `toString` method or // the `source` property as a convenience for inlining compiled templates. result.source = source; if (isError(result)) { throw result; } return result; } function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty__default["default"](e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } var prefix = config["default"].prefix; var _FormItem = vue.defineComponent({ name: "".concat(prefix, "-form-item"), props: form_formItemProps["default"], setup: function setup(props2, _ref) { var slots = _ref.slots; var renderTNodeJSX = hooks_tnode.useTNodeJSX(); var formClass = hooks_useClass.usePrefixClass("form"); var formItemClass = hooks_useClass.usePrefixClass("form__item"); var _toRefs = vue.toRefs(props2), name = _toRefs.name; var form = vue.inject(form_const.FormInjectionKey, void 0); var extraNode = vue.computed(function () { var _list$; var list = errorList.value; if (showErrorMessage.value && (_list$ = list[0]) !== null && _list$ !== void 0 && _list$.message) { var _list$2; return (_list$2 = list[0]) === null || _list$2 === void 0 ? void 0 : _list$2.message; } if (successList.value.length) { return successList.value[0].message; } return null; }); var formItemClasses = vue.computed(function () { return [formItemClass.value, "".concat(formItemClass.value, "--bordered"), "".concat(formClass.value, "--").concat(labelAlign.value), "".concat(formClass.value, "-item__").concat(props2.name)]; }); var needRequiredMark = vue.computed(function () { var _props2$requiredMark; var requiredMark = (_props2$requiredMark = props2.requiredMark) !== null && _props2$requiredMark !== void 0 ? _props2$requiredMark : form === null || form === void 0 ? void 0 : form.requiredMark; var isRequired = innerRules.value.filter(function (rule) { return rule.required; }).length > 0; return requiredMark !== null && requiredMark !== void 0 ? requiredMark : isRequired; }); var hasLabel = vue.computed(function () { return slots.label || props2.label; }); var hasColon = vue.computed(function () { return !!(form !== null && form !== void 0 && form.colon && hasLabel.value); }); var labelClass = "".concat(formClass.value, "__label"); var labelAlign = vue.computed(function () { return isNil.isNil(props2.labelAlign) ? form === null || form === void 0 ? void 0 : form.labelAlign : props2.labelAlign; }); var labelWidth = vue.computed(function () { return isNil.isNil(props2.labelWidth) ? form === null || form === void 0 ? void 0 : form.labelWidth : props2.labelWidth; }); var contentAlign = vue.computed(function () { return isNil.isNil(props2.contentAlign) ? form === null || form === void 0 ? void 0 : form.contentAlign : props2.contentAlign; }); var labelClasses = vue.computed(function () { return [labelClass, _defineProperty__default["default"](_defineProperty__default["default"](_defineProperty__default["default"](_defineProperty__default["default"](_defineProperty__default["default"]({}, "".concat(labelClass, "--required"), needRequiredMark.value), "".concat(labelClass, "--colon"), hasColon.value), "".concat(labelClass, "--top"), hasLabel.value && (labelAlign.value === "top" || !labelWidth.value)), "".concat(labelClass, "--left"), labelAlign.value === "left" && labelWidth.value), "".concat(labelClass, "--right"), labelAlign.value === "right" && labelWidth.value)]; }); var labelStyle = vue.computed(function () { if (labelWidth.value && labelAlign.value !== "top") { return isNumber.isNumber(labelWidth.value) ? { width: "".concat(labelWidth.value, "px") } : { width: labelWidth.value }; } return {}; }); var freeShowErrorMessage = vue.ref(false); var showErrorMessage = vue.computed(function () { if (isBoolean.isBoolean(freeShowErrorMessage.value)) return freeShowErrorMessage.value; if (isBoolean.isBoolean(props2.showErrorMessage)) return props2.showErrorMessage; return form === null || form === void 0 ? void 0 : form.showErrorMessage; }); var errorClasses = vue.computed(function () { if (!showErrorMessage.value) return ""; if (!errorList.value.length) return ""; var type = errorList.value[0].type || "error"; return type === "error" ? "".concat(formItemClass.value, "--error") : "".concat(formItemClass.value, "--warning"); }); var contentClasses = vue.computed(function () { return ["".concat(formClass.value, "__controls"), errorClasses.value]; }); var contentSlotClasses = vue.computed(function () { return ["".concat(formClass.value, "__controls-content"), "".concat(formClass.value, "__controls--").concat(contentAlign.value)]; }); var contentStyle = vue.computed(function () { var contentStyle2 = {}; if (labelWidth.value && labelAlign.value !== "top") { if (isNumber.isNumber(labelWidth.value)) { contentStyle2 = { marginLeft: "".concat(labelWidth.value, "px") }; } else { contentStyle2 = { marginLeft: labelWidth.value }; } } return contentStyle2; }); var errorList = vue.ref([]); var successList = vue.ref([]); var verifyStatus = vue.ref(form_const.ValidateStatus.TO_BE_VALIDATED); var resetValidating = vue.ref(false); var needResetField = vue.ref(false); var resetHandler = function resetHandler() { needResetField.value = false; errorList.value = []; successList.value = []; verifyStatus.value = form_const.ValidateStatus.TO_BE_VALIDATED; }; var getEmptyValue = function getEmptyValue() { var type = Object.prototype.toString.call(get.get(form === null || form === void 0 ? void 0 : form.data, "".concat(props2.name))); var emptyValue; if (type === "[object String]") { emptyValue = ""; } if (type === "[object Array]") { emptyValue = []; } if (type === "[object Object]") { emptyValue = {}; } return emptyValue; }; var resetField = /*#__PURE__*/function () { var _ref3 = _asyncToGenerator__default["default"](/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee() { var resetType, _args = arguments; return _regeneratorRuntime__default["default"].wrap(function (_context) { while (1) switch (_context.prev = _context.next) { case 0: resetType = _args.length > 0 && _args[0] !== undefined ? _args[0] : form === null || form === void 0 ? void 0 : form.resetType; if (props2.name) { _context.next = 1; break; } return _context.abrupt("return", null); case 1: if (resetType === "empty") { set.set(form === null || form === void 0 ? void 0 : form.data, props2.name, getEmptyValue()); } else if (resetType === "initial") { set.set(form === null || form === void 0 ? void 0 : form.data, props2.name, initialValue.value); } _context.next = 2; return vue.nextTick(); case 2: if (resetValidating.value) { needResetField.value = true; } else { resetHandler(); } case 3: case "end": return _context.stop(); } }, _callee); })); return function resetField() { return _ref3.apply(this, arguments); }; }(); var errorMessages = vue.computed(function () { return (form === null || form === void 0 ? void 0 : form.errorMessage) || {}; }); var innerRules = vue.computed(function () { var _props2$rules; if ((_props2$rules = props2.rules) !== null && _props2$rules !== void 0 && _props2$rules.length) return props2.rules; if (!props2.name) return []; var index = "".concat(props2.name).lastIndexOf(".") || -1; var pRuleName = "".concat(props2.name).slice(index + 1); return get.get(form === null || form === void 0 ? void 0 : form.rules, props2.name) || get.get(form === null || form === void 0 ? void 0 : form.rules, pRuleName) || []; }); var analysisValidateResult = /*#__PURE__*/function () { var _ref4 = _asyncToGenerator__default["default"](/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee2(trigger) { var _result$rules; var result; return _regeneratorRuntime__default["default"].wrap(function (_context2) { while (1) switch (_context2.prev = _context2.next) { case 0: result = { successList: [], errorList: [], rules: [], resultList: [], allowSetValue: false }; result.rules = trigger === "all" ? innerRules.value : innerRules.value.filter(function (item) { return (item.trigger || "change") === trigger; }); if (!(innerRules.value.length && !((_result$rules = result.rules) !== null && _result$rules !== void 0 && _result$rules.length))) { _context2.next = 1; break; } return _context2.abrupt("return", result); case 1: result.allowSetValue = true; _context2.next = 2; return form_formModel.validate(value.value, result.rules); case 2: result.resultList = _context2.sent; result.errorList = result.resultList.filter(function (item) { return item.result !== true; }).map(function (item) { Object.keys(item).forEach(function (key) { if (!item.message && errorMessages.value[key]) { var compiled = template(errorMessages.value[key]); var name2 = isString.isString(props2.label) ? props2.label : props2.name; item.message = compiled({ name: name2, validate: item[key] }); } }); return item; }); result.successList = result.resultList.filter(function (item) { return item.result === true && item.message && item.type === "success"; }); return _context2.abrupt("return", result); case 3: case "end": return _context2.stop(); } }, _callee2); })); return function analysisValidateResult(_x) { return _ref4.apply(this, arguments); }; }(); var validateHandler = /*#__PURE__*/function () { var _ref5 = _asyncToGenerator__default["default"](/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee3(trigger, showErrorMessage2) { var _yield$analysisValida, innerSuccessList, innerErrorList, rules, resultList, allowSetValue; return _regeneratorRuntime__default["default"].wrap(function (_context3) { while (1) switch (_context3.prev = _context3.next) { case 0: resetValidating.value = true; freeShowErrorMessage.value = showErrorMessage2; _context3.next = 1; return analysisValidateResult(trigger); case 1: _yield$analysisValida = _context3.sent; innerSuccessList = _yield$analysisValida.successList; innerErrorList = _yield$analysisValida.errorList; rules = _yield$analysisValida.rules; resultList = _yield$analysisValida.resultList; allowSetValue = _yield$analysisValida.allowSetValue; if (allowSetValue) { successList.value = innerSuccessList || []; errorList.value = innerErrorList || []; } if (rules.length) { verifyStatus.value = innerErrorList !== null && innerErrorList !== void 0 && innerErrorList.length ? form_const.ValidateStatus.FAIL : form_const.ValidateStatus.SUCCESS; } if (needResetField.value) { resetHandler(); } resetValidating.value = false; return _context3.abrupt("return", _defineProperty__default["default"]({}, "".concat(name.value), (innerErrorList === null || innerErrorList === void 0 ? void 0 : innerErrorList.length) === 0 ? true : resultList)); case 2: case "end": return _context3.stop(); } }, _callee3); })); return function validateHandler(_x2, _x3) { return _ref5.apply(this, arguments); }; }(); var validateOnly = /*#__PURE__*/function () { var _ref7 = _asyncToGenerator__default["default"](/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee4(trigger) { var _yield$analysisValida2, innerErrorList, resultList; return _regeneratorRuntime__default["default"].wrap(function (_context4) { while (1) switch (_context4.prev = _context4.next) { case 0: _context4.next = 1; return analysisValidateResult(trigger); case 1: _yield$analysisValida2 = _context4.sent; innerErrorList = _yield$analysisValida2.errorList; resultList = _yield$analysisValida2.resultList; return _context4.abrupt("return", _defineProperty__default["default"]({}, props2.name, innerErrorList.length === 0 ? true : resultList)); case 2: case "end": return _context4.stop(); } }, _callee4); })); return function validateOnly(_x4) { return _ref7.apply(this, arguments); }; }(); var setValidateMessage = function setValidateMessage(validateMessage) { if (!validateMessage && !isArray.isArray(validateMessage)) return; if (validateMessage.length === 0) { errorList.value = []; verifyStatus.value = form_const.ValidateStatus.SUCCESS; } errorList.value = validateMessage.map(function (item) { return _objectSpread(_objectSpread({}, item), {}, { result: false }); }); verifyStatus.value = form_const.ValidateStatus.FAIL; }; var value = vue.computed(function () { return (form === null || form === void 0 ? void 0 : form.data) && get.get(form === null || form === void 0 ? void 0 : form.data, "".concat(name.value)); }); var initialValue = vue.ref(void 0); var context = vue.reactive({ name: name, resetHandler: resetHandler, resetField: resetField, validate: validateHandler, validateOnly: validateOnly, setValidateMessage: setValidateMessage }); vue.onMounted(function () { initialValue.value = configProvider_useConfig.cloneDeep(value.value); form === null || form === void 0 || form.children.push(context); }); vue.onBeforeUnmount(function () { if (form) form.children = form === null || form === void 0 ? void 0 : form.children.filter(function (ctx) { return ctx !== context; }); }); vue.watch(value, /*#__PURE__*/_asyncToGenerator__default["default"](/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee5() { return _regeneratorRuntime__default["default"].wrap(function (_context5) { while (1) switch (_context5.prev = _context5.next) { case 0: _context5.next = 1; return validateHandler("change"); case 1: case "end": return _context5.stop(); } }, _callee5); })), { deep: true }); vue.watch(function () { return [props2.name, JSON.stringify(props2.rules)].join(","); }, function () { validateHandler("change"); }); var handleBlur = /*#__PURE__*/function () { var _ref0 = _asyncToGenerator__default["default"](/*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee6() { return _regeneratorRuntime__default["default"].wrap(function (_context6) { while (1) switch (_context6.prev = _context6.next) { case 0: _context6.next = 1; return validateHandler("blur"); case 1: case "end": return _context6.stop(); } }, _callee6); })); return function handleBlur() { return _ref0.apply(this, arguments); }; }(); vue.provide(form_const.FormItemInjectionKey, { handleBlur: handleBlur }); return function () { var renderRightIconContent = function renderRightIconContent() { if (!props2.arrow) { return null; } return vue.createVNode(tdesignIconsVueNext.ChevronRightIcon, { "size": "24px", "style": { color: "rgba(0, 0, 0, .4)" } }, null); }; var renderLabelContent = function renderLabelContent() { if (Number(labelWidth.value) === 0) { return null; } return renderTNodeJSX("label"); }; var renderHelpNode = function renderHelpNode() { var helpNode = renderTNodeJSX("help"); if (!helpNode) { return null; } return vue.createVNode("div", { "class": ["".concat(formItemClass.value, "-help"), "".concat(formClass.value, "__controls--").concat(contentAlign.value)] }, [helpNode]); }; var renderExtraNode = function renderExtraNode() { if (!extraNode.value) { return null; } return vue.createVNode("div", { "class": ["".concat(formItemClass.value, "-extra"), "".concat(formClass.value, "__controls--").concat(contentAlign.value)] }, [extraNode.value]); }; return vue.createVNode("div", { "class": [].concat(_toConsumableArray__default["default"](formItemClasses.value), [renderHelpNode() ? "".concat(formClass.value, "__item-with-help") : ""]) }, [vue.createVNode("div", { "class": ["".concat(formItemClass.value, "-wrap"), "".concat(formItemClass.value, "--").concat(labelAlign.value)] }, [vue.createVNode("div", { "class": labelClasses.value, "style": labelStyle.value }, [vue.createVNode("label", { "for": props2.for }, [renderLabelContent()])]), vue.createVNode("div", { "class": contentClasses.value, "style": contentStyle.value }, [vue.createVNode("div", { "class": contentSlotClasses.value }, [renderTNodeJSX("default")]), renderHelpNode(), renderExtraNode()])]), renderRightIconContent()]); }; } }); exports["default"] = _FormItem; //# sourceMappingURL=form-item.js.map