UNPKG

wux-weapp

Version:

一套组件化、可复用、易扩展的微信小程序 UI 组件库

1 lines 4.3 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.convertValue=convertValue,exports.getSelectIndex=getSelectIndex,exports.getRealValue=getRealValue,exports.fillFieldNames=fillFieldNames,exports.flattenOptions=flattenOptions,exports.DEFAULT_FIELD_NAMES=exports.getNotFoundContent=exports.notFoundContent=exports.getDefaultProps=exports.POPUP_SELECTOR=void 0;var _props=require("../prompt/props");function ownKeys(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,o)}return n}function _objectSpread(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(n,!0).forEach(function(t){_defineProperty(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ownKeys(n).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function _defineProperty(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function _toConsumableArray(t){return _arrayWithoutHoles(t)||_iterableToArray(t)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance")}function _iterableToArray(t){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t))return Array.from(t)}function _arrayWithoutHoles(t){if(Array.isArray(t)){for(var e=0,n=new Array(t.length);e<t.length;e++)n[e]=t[e];return n}}function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var POPUP_SELECTOR="#wux-select";exports.POPUP_SELECTOR=POPUP_SELECTOR;var getDefaultProps=function(){return{value:{type:[String,Array],value:""},options:{type:Array,value:[]},iconPosition:{type:String,value:""},multiple:{type:Boolean,value:!1},max:{type:Number,value:-1}}};exports.getDefaultProps=getDefaultProps;var notFoundContent={icon:_props.defaultIcon,title:"",text:"暂无数据"};exports.notFoundContent=notFoundContent;var getNotFoundContent=function(t){return null!==t&&"object"===_typeof(t)?Object.assign({},notFoundContent,t):"string"==typeof t?Object.assign({},notFoundContent,{text:t}):null===t||!1===t?null:notFoundContent};function convertValue(t){return Array.isArray(t)?_toConsumableArray(t):"string"==typeof t?[t]:[]}function getSelectIndex(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:[],e=2<arguments.length&&void 0!==arguments[2]&&arguments[2],n=convertValue(1<arguments.length&&void 0!==arguments[1]?arguments[1]:""),o=t.map(function(t){return t.value||t}).filter(function(t){return!!t});return e?n.map(function(t){return o.indexOf(t)}):o.indexOf(n[0])}function getRealValue(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:[],e=2<arguments.length&&void 0!==arguments[2]&&arguments[2],n=convertValue(1<arguments.length&&void 0!==arguments[1]?arguments[1]:""),o=t.map(function(t){return t.value||t}).filter(function(t){return!!t});return e?n.filter(function(t){return o.includes(t)}):o.includes(n[0])?n[0]:""}exports.getNotFoundContent=getNotFoundContent;var DEFAULT_FIELD_NAMES={title:"title",value:"value",options:"options"};function fillFieldNames(){var t=_objectSpread({},DEFAULT_FIELD_NAMES,{},0<arguments.length&&void 0!==arguments[0]?arguments[0]:{}),e=t.title,n=t.value,o=t.options;return{title:e||DEFAULT_FIELD_NAMES.title,value:n||DEFAULT_FIELD_NAMES.value,options:o||DEFAULT_FIELD_NAMES.options}}function flattenOptions(t){var e=(1<arguments.length&&void 0!==arguments[1]?arguments[1]:{}).fieldNames,u=[],n=fillFieldNames(void 0===e?DEFAULT_FIELD_NAMES:e),a=n.title,p=n.value,s=n.options;return function i(t,l){t.forEach(function(t){var e,n=(t="string"==typeof t?(_defineProperty(e={},a,t),_defineProperty(e,p,t),e):t)[a];if(!l&&s in t){var o=n;void 0===o&&(o=t.title),u.push(_objectSpread({},t,{isGroup:!0,data:t,title:o})),i(t[s],!0)}else{var r=t[p];u.push(_objectSpread({},t,{isGroupOption:l,data:t,title:n,value:r}))}})}(t,!1),u}exports.DEFAULT_FIELD_NAMES=DEFAULT_FIELD_NAMES;