select.js 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423
  1. module.exports =
  2. /******/ (function(modules) { // webpackBootstrap
  3. /******/ // The module cache
  4. /******/ var installedModules = {};
  5. /******/ // The require function
  6. /******/ function __webpack_require__(moduleId) {
  7. /******/ // Check if module is in cache
  8. /******/ if(installedModules[moduleId])
  9. /******/ return installedModules[moduleId].exports;
  10. /******/ // Create a new module (and put it into the cache)
  11. /******/ var module = installedModules[moduleId] = {
  12. /******/ exports: {},
  13. /******/ id: moduleId,
  14. /******/ loaded: false
  15. /******/ };
  16. /******/ // Execute the module function
  17. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  18. /******/ // Flag the module as loaded
  19. /******/ module.loaded = true;
  20. /******/ // Return the exports of the module
  21. /******/ return module.exports;
  22. /******/ }
  23. /******/ // expose the modules object (__webpack_modules__)
  24. /******/ __webpack_require__.m = modules;
  25. /******/ // expose the module cache
  26. /******/ __webpack_require__.c = installedModules;
  27. /******/ // __webpack_public_path__
  28. /******/ __webpack_require__.p = "/dist/";
  29. /******/ // Load entry module and return exports
  30. /******/ return __webpack_require__(0);
  31. /******/ })
  32. /************************************************************************/
  33. /******/ ({
  34. /***/ 0:
  35. /***/ function(module, exports, __webpack_require__) {
  36. module.exports = __webpack_require__(260);
  37. /***/ },
  38. /***/ 3:
  39. /***/ function(module, exports) {
  40. module.exports = function normalizeComponent (
  41. rawScriptExports,
  42. compiledTemplate,
  43. scopeId,
  44. cssModules
  45. ) {
  46. var esModule
  47. var scriptExports = rawScriptExports = rawScriptExports || {}
  48. // ES6 modules interop
  49. var type = typeof rawScriptExports.default
  50. if (type === 'object' || type === 'function') {
  51. esModule = rawScriptExports
  52. scriptExports = rawScriptExports.default
  53. }
  54. // Vue.extend constructor export interop
  55. var options = typeof scriptExports === 'function'
  56. ? scriptExports.options
  57. : scriptExports
  58. // render functions
  59. if (compiledTemplate) {
  60. options.render = compiledTemplate.render
  61. options.staticRenderFns = compiledTemplate.staticRenderFns
  62. }
  63. // scopedId
  64. if (scopeId) {
  65. options._scopeId = scopeId
  66. }
  67. // inject cssModules
  68. if (cssModules) {
  69. var computed = options.computed || (options.computed = {})
  70. Object.keys(cssModules).forEach(function (key) {
  71. var module = cssModules[key]
  72. computed[key] = function () { return module }
  73. })
  74. }
  75. return {
  76. esModule: esModule,
  77. exports: scriptExports,
  78. options: options
  79. }
  80. }
  81. /***/ },
  82. /***/ 9:
  83. /***/ function(module, exports) {
  84. module.exports = require("element-ui/lib/input");
  85. /***/ },
  86. /***/ 10:
  87. /***/ function(module, exports) {
  88. module.exports = require("element-ui/lib/utils/clickoutside");
  89. /***/ },
  90. /***/ 13:
  91. /***/ function(module, exports) {
  92. module.exports = require("element-ui/lib/utils/vue-popper");
  93. /***/ },
  94. /***/ 14:
  95. /***/ function(module, exports) {
  96. module.exports = require("element-ui/lib/mixins/emitter");
  97. /***/ },
  98. /***/ 15:
  99. /***/ function(module, exports) {
  100. module.exports = require("element-ui/lib/scrollbar");
  101. /***/ },
  102. /***/ 46:
  103. /***/ function(module, exports) {
  104. module.exports = require("throttle-debounce/debounce");
  105. /***/ },
  106. /***/ 47:
  107. /***/ function(module, exports) {
  108. module.exports = require("element-ui/lib/utils/resize-event");
  109. /***/ },
  110. /***/ 60:
  111. /***/ function(module, exports) {
  112. module.exports = require("element-ui/lib/mixins/locale");
  113. /***/ },
  114. /***/ 61:
  115. /***/ function(module, exports) {
  116. module.exports = require("element-ui/lib/locale");
  117. /***/ },
  118. /***/ 117:
  119. /***/ function(module, exports) {
  120. module.exports = require("element-ui/lib/utils/dom");
  121. /***/ },
  122. /***/ 211:
  123. /***/ function(module, exports, __webpack_require__) {
  124. var Component = __webpack_require__(3)(
  125. /* script */
  126. __webpack_require__(212),
  127. /* template */
  128. __webpack_require__(213),
  129. /* scopeId */
  130. null,
  131. /* cssModules */
  132. null
  133. )
  134. module.exports = Component.exports
  135. /***/ },
  136. /***/ 212:
  137. /***/ function(module, exports, __webpack_require__) {
  138. 'use strict';
  139. exports.__esModule = true;
  140. var _emitter = __webpack_require__(14);
  141. var _emitter2 = _interopRequireDefault(_emitter);
  142. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  143. exports.default = {
  144. mixins: [_emitter2.default],
  145. name: 'ElOption',
  146. componentName: 'ElOption',
  147. props: {
  148. value: {
  149. required: true
  150. },
  151. label: [String, Number],
  152. created: Boolean,
  153. disabled: {
  154. type: Boolean,
  155. default: false
  156. }
  157. },
  158. data: function data() {
  159. return {
  160. index: -1,
  161. groupDisabled: false,
  162. visible: true,
  163. hitState: false
  164. };
  165. },
  166. computed: {
  167. currentLabel: function currentLabel() {
  168. return this.label || (typeof this.value === 'string' || typeof this.value === 'number' ? this.value : '');
  169. },
  170. currentValue: function currentValue() {
  171. return this.value || this.label || '';
  172. },
  173. parent: function parent() {
  174. var result = this.$parent;
  175. while (!result.isSelect) {
  176. result = result.$parent;
  177. }
  178. return result;
  179. },
  180. itemSelected: function itemSelected() {
  181. if (!this.parent.multiple) {
  182. return this.value === this.parent.value;
  183. } else {
  184. return this.parent.value.indexOf(this.value) > -1;
  185. }
  186. },
  187. limitReached: function limitReached() {
  188. if (this.parent.multiple) {
  189. return !this.itemSelected && this.parent.value.length >= this.parent.multipleLimit && this.parent.multipleLimit > 0;
  190. } else {
  191. return false;
  192. }
  193. }
  194. },
  195. watch: {
  196. currentLabel: function currentLabel() {
  197. if (!this.created && !this.parent.remote) this.dispatch('ElSelect', 'setSelected');
  198. },
  199. value: function value() {
  200. if (!this.created && !this.parent.remote) this.dispatch('ElSelect', 'setSelected');
  201. }
  202. },
  203. methods: {
  204. handleGroupDisabled: function handleGroupDisabled(val) {
  205. this.groupDisabled = val;
  206. },
  207. hoverItem: function hoverItem() {
  208. if (!this.disabled && !this.groupDisabled) {
  209. this.parent.hoverIndex = this.parent.options.indexOf(this);
  210. }
  211. },
  212. selectOptionClick: function selectOptionClick() {
  213. if (this.disabled !== true && this.groupDisabled !== true) {
  214. this.dispatch('ElSelect', 'handleOptionClick', this);
  215. }
  216. },
  217. queryChange: function queryChange(query) {
  218. // query 里如果有正则中的特殊字符,需要先将这些字符转义
  219. var parsedQuery = String(query).replace(/(\^|\(|\)|\[|\]|\$|\*|\+|\.|\?|\\|\{|\}|\|)/g, '\\$1');
  220. this.visible = new RegExp(parsedQuery, 'i').test(this.currentLabel) || this.created;
  221. if (!this.visible) {
  222. this.parent.filteredOptionsCount--;
  223. }
  224. },
  225. resetIndex: function resetIndex() {
  226. var _this = this;
  227. this.$nextTick(function () {
  228. _this.index = _this.parent.options.indexOf(_this);
  229. });
  230. }
  231. },
  232. created: function created() {
  233. this.parent.options.push(this);
  234. this.parent.cachedOptions.push(this);
  235. this.parent.optionsCount++;
  236. this.parent.filteredOptionsCount++;
  237. this.index = this.parent.options.indexOf(this);
  238. this.$on('queryChange', this.queryChange);
  239. this.$on('handleGroupDisabled', this.handleGroupDisabled);
  240. this.$on('resetIndex', this.resetIndex);
  241. },
  242. beforeDestroy: function beforeDestroy() {
  243. this.dispatch('ElSelect', 'onOptionDestroy', this);
  244. }
  245. }; //
  246. //
  247. //
  248. //
  249. //
  250. //
  251. //
  252. //
  253. //
  254. //
  255. //
  256. //
  257. //
  258. //
  259. //
  260. //
  261. //
  262. /***/ },
  263. /***/ 213:
  264. /***/ function(module, exports) {
  265. module.exports={render:function (){var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;
  266. return _c('li', {
  267. directives: [{
  268. name: "show",
  269. rawName: "v-show",
  270. value: (_vm.visible),
  271. expression: "visible"
  272. }],
  273. staticClass: "el-select-dropdown__item",
  274. class: {
  275. 'selected': _vm.itemSelected,
  276. 'is-disabled': _vm.disabled || _vm.groupDisabled || _vm.limitReached,
  277. 'hover': _vm.parent.hoverIndex === _vm.index
  278. },
  279. on: {
  280. "mouseenter": _vm.hoverItem,
  281. "click": function($event) {
  282. $event.stopPropagation();
  283. _vm.selectOptionClick($event)
  284. }
  285. }
  286. }, [_vm._t("default", [_c('span', [_vm._v(_vm._s(_vm.currentLabel))])])], 2)
  287. },staticRenderFns: []}
  288. /***/ },
  289. /***/ 260:
  290. /***/ function(module, exports, __webpack_require__) {
  291. 'use strict';
  292. exports.__esModule = true;
  293. var _select = __webpack_require__(261);
  294. var _select2 = _interopRequireDefault(_select);
  295. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  296. /* istanbul ignore next */
  297. _select2.default.install = function (Vue) {
  298. Vue.component(_select2.default.name, _select2.default);
  299. };
  300. exports.default = _select2.default;
  301. /***/ },
  302. /***/ 261:
  303. /***/ function(module, exports, __webpack_require__) {
  304. var Component = __webpack_require__(3)(
  305. /* script */
  306. __webpack_require__(262),
  307. /* template */
  308. __webpack_require__(267),
  309. /* scopeId */
  310. null,
  311. /* cssModules */
  312. null
  313. )
  314. module.exports = Component.exports
  315. /***/ },
  316. /***/ 262:
  317. /***/ function(module, exports, __webpack_require__) {
  318. 'use strict';
  319. exports.__esModule = true;
  320. var _emitter = __webpack_require__(14);
  321. var _emitter2 = _interopRequireDefault(_emitter);
  322. var _locale = __webpack_require__(60);
  323. var _locale2 = _interopRequireDefault(_locale);
  324. var _input = __webpack_require__(9);
  325. var _input2 = _interopRequireDefault(_input);
  326. var _selectDropdown = __webpack_require__(263);
  327. var _selectDropdown2 = _interopRequireDefault(_selectDropdown);
  328. var _option = __webpack_require__(211);
  329. var _option2 = _interopRequireDefault(_option);
  330. var _tag = __webpack_require__(266);
  331. var _tag2 = _interopRequireDefault(_tag);
  332. var _scrollbar = __webpack_require__(15);
  333. var _scrollbar2 = _interopRequireDefault(_scrollbar);
  334. var _debounce = __webpack_require__(46);
  335. var _debounce2 = _interopRequireDefault(_debounce);
  336. var _clickoutside = __webpack_require__(10);
  337. var _clickoutside2 = _interopRequireDefault(_clickoutside);
  338. var _dom = __webpack_require__(117);
  339. var _resizeEvent = __webpack_require__(47);
  340. var _locale3 = __webpack_require__(61);
  341. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  342. //
  343. //
  344. //
  345. //
  346. //
  347. //
  348. //
  349. //
  350. //
  351. //
  352. //
  353. //
  354. //
  355. //
  356. //
  357. //
  358. //
  359. //
  360. //
  361. //
  362. //
  363. //
  364. //
  365. //
  366. //
  367. //
  368. //
  369. //
  370. //
  371. //
  372. //
  373. //
  374. //
  375. //
  376. //
  377. //
  378. //
  379. //
  380. //
  381. //
  382. //
  383. //
  384. //
  385. //
  386. //
  387. //
  388. //
  389. //
  390. //
  391. //
  392. //
  393. //
  394. //
  395. //
  396. //
  397. //
  398. //
  399. //
  400. //
  401. //
  402. //
  403. //
  404. //
  405. //
  406. //
  407. //
  408. //
  409. //
  410. //
  411. //
  412. //
  413. //
  414. //
  415. //
  416. //
  417. //
  418. //
  419. //
  420. //
  421. //
  422. //
  423. //
  424. //
  425. //
  426. //
  427. //
  428. //
  429. //
  430. //
  431. //
  432. //
  433. //
  434. var sizeMap = {
  435. 'large': 42,
  436. 'small': 30,
  437. 'mini': 22
  438. };
  439. exports.default = {
  440. mixins: [_emitter2.default, _locale2.default],
  441. name: 'ElSelect',
  442. componentName: 'ElSelect',
  443. computed: {
  444. iconClass: function iconClass() {
  445. var criteria = this.clearable && !this.disabled && this.inputHovering && !this.multiple && this.value !== undefined && this.value !== '';
  446. return criteria ? 'circle-close is-show-close' : this.remote && this.filterable ? '' : 'caret-top';
  447. },
  448. debounce: function debounce() {
  449. return this.remote ? 300 : 0;
  450. },
  451. emptyText: function emptyText() {
  452. if (this.loading) {
  453. return this.loadingText || this.t('el.select.loading');
  454. } else {
  455. if (this.remote && this.query === '' && this.options.length === 0) return false;
  456. if (this.filterable && this.options.length > 0 && this.filteredOptionsCount === 0) {
  457. return this.noMatchText || this.t('el.select.noMatch');
  458. }
  459. if (this.options.length === 0) {
  460. return this.noDataText || this.t('el.select.noData');
  461. }
  462. }
  463. return null;
  464. },
  465. showNewOption: function showNewOption() {
  466. var _this = this;
  467. var hasExistingOption = this.options.filter(function (option) {
  468. return !option.created;
  469. }).some(function (option) {
  470. return option.currentLabel === _this.query;
  471. });
  472. return this.filterable && this.allowCreate && this.query !== '' && !hasExistingOption;
  473. }
  474. },
  475. components: {
  476. ElInput: _input2.default,
  477. ElSelectMenu: _selectDropdown2.default,
  478. ElOption: _option2.default,
  479. ElTag: _tag2.default,
  480. ElScrollbar: _scrollbar2.default
  481. },
  482. directives: { Clickoutside: _clickoutside2.default },
  483. props: {
  484. name: String,
  485. value: {},
  486. size: String,
  487. disabled: Boolean,
  488. clearable: Boolean,
  489. filterable: Boolean,
  490. allowCreate: Boolean,
  491. loading: Boolean,
  492. popperClass: String,
  493. remote: Boolean,
  494. loadingText: String,
  495. noMatchText: String,
  496. noDataText: String,
  497. remoteMethod: Function,
  498. filterMethod: Function,
  499. multiple: Boolean,
  500. multipleLimit: {
  501. type: Number,
  502. default: 0
  503. },
  504. placeholder: {
  505. type: String,
  506. default: function _default() {
  507. return (0, _locale3.t)('el.select.placeholder');
  508. }
  509. }
  510. },
  511. data: function data() {
  512. return {
  513. options: [],
  514. cachedOptions: [],
  515. createdLabel: null,
  516. createdSelected: false,
  517. selected: this.multiple ? [] : {},
  518. isSelect: true,
  519. inputLength: 20,
  520. inputWidth: 0,
  521. cachedPlaceHolder: '',
  522. optionsCount: 0,
  523. filteredOptionsCount: 0,
  524. dropdownUl: null,
  525. visible: false,
  526. selectedLabel: '',
  527. hoverIndex: -1,
  528. query: '',
  529. bottomOverflow: 0,
  530. topOverflow: 0,
  531. optionsAllDisabled: false,
  532. inputHovering: false,
  533. currentPlaceholder: ''
  534. };
  535. },
  536. watch: {
  537. placeholder: function placeholder(val) {
  538. this.cachedPlaceHolder = this.currentPlaceholder = val;
  539. },
  540. value: function value(val) {
  541. if (this.multiple) {
  542. this.resetInputHeight();
  543. if (val.length > 0 || this.$refs.input && this.query !== '') {
  544. this.currentPlaceholder = '';
  545. } else {
  546. this.currentPlaceholder = this.cachedPlaceHolder;
  547. }
  548. }
  549. this.setSelected();
  550. if (this.filterable && !this.multiple) {
  551. this.inputLength = 20;
  552. }
  553. this.$emit('change', val);
  554. this.dispatch('ElFormItem', 'el.form.change', val);
  555. },
  556. query: function query(val) {
  557. var _this2 = this;
  558. this.$nextTick(function () {
  559. if (_this2.visible) _this2.broadcast('ElSelectDropdown', 'updatePopper');
  560. });
  561. this.hoverIndex = -1;
  562. if (this.multiple && this.filterable) {
  563. this.inputLength = this.$refs.input.value.length * 15 + 20;
  564. this.managePlaceholder();
  565. this.resetInputHeight();
  566. }
  567. if (this.remote && typeof this.remoteMethod === 'function') {
  568. this.hoverIndex = -1;
  569. this.remoteMethod(val);
  570. this.broadcast('ElOption', 'resetIndex');
  571. } else if (typeof this.filterMethod === 'function') {
  572. this.filterMethod(val);
  573. this.broadcast('ElOptionGroup', 'queryChange');
  574. } else {
  575. this.filteredOptionsCount = this.optionsCount;
  576. this.broadcast('ElOption', 'queryChange', val);
  577. this.broadcast('ElOptionGroup', 'queryChange');
  578. }
  579. },
  580. visible: function visible(val) {
  581. var _this3 = this;
  582. if (!val) {
  583. this.$refs.reference.$el.querySelector('input').blur();
  584. this.handleIconHide();
  585. this.broadcast('ElSelectDropdown', 'destroyPopper');
  586. if (this.$refs.input) {
  587. this.$refs.input.blur();
  588. }
  589. this.query = '';
  590. this.selectedLabel = '';
  591. this.inputLength = 20;
  592. this.resetHoverIndex();
  593. this.$nextTick(function () {
  594. if (_this3.$refs.input && _this3.$refs.input.value === '' && _this3.selected.length === 0) {
  595. _this3.currentPlaceholder = _this3.cachedPlaceHolder;
  596. }
  597. });
  598. if (!this.multiple) {
  599. this.getOverflows();
  600. if (this.selected) {
  601. if (this.filterable && this.allowCreate && this.createdSelected && this.createdOption) {
  602. this.selectedLabel = this.createdLabel;
  603. } else {
  604. this.selectedLabel = this.selected.currentLabel;
  605. }
  606. if (this.filterable) this.query = this.selectedLabel;
  607. }
  608. }
  609. } else {
  610. this.handleIconShow();
  611. this.broadcast('ElSelectDropdown', 'updatePopper');
  612. if (this.filterable) {
  613. this.query = this.selectedLabel;
  614. if (this.multiple) {
  615. this.$refs.input.focus();
  616. } else {
  617. if (!this.remote) {
  618. this.broadcast('ElOption', 'queryChange', '');
  619. this.broadcast('ElOptionGroup', 'queryChange');
  620. }
  621. this.broadcast('ElInput', 'inputSelect');
  622. }
  623. }
  624. }
  625. this.$emit('visible-change', val);
  626. },
  627. options: function options(val) {
  628. if (this.$isServer) return;
  629. this.optionsAllDisabled = val.length === val.filter(function (item) {
  630. return item.disabled === true;
  631. }).length;
  632. if (this.multiple) {
  633. this.resetInputHeight();
  634. }
  635. var inputs = this.$el.querySelectorAll('input');
  636. if ([].indexOf.call(inputs, document.activeElement) === -1) {
  637. this.setSelected();
  638. }
  639. }
  640. },
  641. methods: {
  642. handleIconHide: function handleIconHide() {
  643. var icon = this.$el.querySelector('.el-input__icon');
  644. if (icon) {
  645. (0, _dom.removeClass)(icon, 'is-reverse');
  646. }
  647. },
  648. handleIconShow: function handleIconShow() {
  649. var icon = this.$el.querySelector('.el-input__icon');
  650. if (icon && !(0, _dom.hasClass)(icon, 'el-icon-circle-close')) {
  651. (0, _dom.addClass)(icon, 'is-reverse');
  652. }
  653. },
  654. handleMenuEnter: function handleMenuEnter() {
  655. if (!this.dropdownUl) {
  656. this.dropdownUl = this.$refs.popper.$el.querySelector('.el-select-dropdown__wrap');
  657. this.getOverflows();
  658. }
  659. if (!this.multiple && this.dropdownUl) {
  660. this.resetMenuScroll();
  661. }
  662. },
  663. getOverflows: function getOverflows() {
  664. if (this.dropdownUl && this.selected && this.selected.$el) {
  665. var selectedRect = this.selected.$el.getBoundingClientRect();
  666. var popperRect = this.$refs.popper.$el.getBoundingClientRect();
  667. this.bottomOverflow = selectedRect.bottom - popperRect.bottom;
  668. this.topOverflow = selectedRect.top - popperRect.top;
  669. }
  670. },
  671. resetMenuScroll: function resetMenuScroll() {
  672. if (this.bottomOverflow > 0) {
  673. this.dropdownUl.scrollTop += this.bottomOverflow;
  674. } else if (this.topOverflow < 0) {
  675. this.dropdownUl.scrollTop += this.topOverflow;
  676. }
  677. },
  678. getOption: function getOption(value) {
  679. var option = void 0;
  680. for (var i = this.cachedOptions.length - 1; i >= 0; i--) {
  681. var cachedOption = this.cachedOptions[i];
  682. if (cachedOption.value === value) {
  683. option = cachedOption;
  684. break;
  685. }
  686. }
  687. if (option) return option;
  688. var label = typeof value === 'string' || typeof value === 'number' ? value : '';
  689. var newOption = {
  690. value: value,
  691. currentLabel: label
  692. };
  693. if (this.multiple) {
  694. newOption.hitState = false;
  695. }
  696. return newOption;
  697. },
  698. setSelected: function setSelected() {
  699. var _this4 = this;
  700. if (!this.multiple) {
  701. var option = this.getOption(this.value);
  702. if (option.created) {
  703. this.createdLabel = option.currentLabel;
  704. this.createdSelected = true;
  705. } else {
  706. this.createdSelected = false;
  707. }
  708. this.selectedLabel = option.currentLabel;
  709. this.selected = option;
  710. if (this.filterable) this.query = this.selectedLabel;
  711. return;
  712. }
  713. var result = [];
  714. if (Array.isArray(this.value)) {
  715. this.value.forEach(function (value) {
  716. result.push(_this4.getOption(value));
  717. });
  718. }
  719. this.selected = result;
  720. this.$nextTick(function () {
  721. _this4.resetInputHeight();
  722. });
  723. },
  724. handleFocus: function handleFocus() {
  725. this.visible = true;
  726. },
  727. handleIconClick: function handleIconClick(event) {
  728. if (this.iconClass.indexOf('circle-close') > -1) {
  729. this.deleteSelected(event);
  730. } else {
  731. this.toggleMenu();
  732. }
  733. },
  734. handleMouseDown: function handleMouseDown(event) {
  735. if (event.target.tagName !== 'INPUT') return;
  736. if (this.visible) {
  737. this.handleClose();
  738. event.preventDefault();
  739. }
  740. },
  741. doDestroy: function doDestroy() {
  742. this.$refs.popper && this.$refs.popper.doDestroy();
  743. },
  744. handleClose: function handleClose() {
  745. this.visible = false;
  746. },
  747. toggleLastOptionHitState: function toggleLastOptionHitState(hit) {
  748. if (!Array.isArray(this.selected)) return;
  749. var option = this.selected[this.selected.length - 1];
  750. if (!option) return;
  751. if (hit === true || hit === false) {
  752. option.hitState = hit;
  753. return hit;
  754. }
  755. option.hitState = !option.hitState;
  756. return option.hitState;
  757. },
  758. deletePrevTag: function deletePrevTag(e) {
  759. if (e.target.value.length <= 0 && !this.toggleLastOptionHitState()) {
  760. this.value.pop();
  761. }
  762. },
  763. managePlaceholder: function managePlaceholder() {
  764. if (this.currentPlaceholder !== '') {
  765. this.currentPlaceholder = this.$refs.input.value ? '' : this.cachedPlaceHolder;
  766. }
  767. },
  768. resetInputState: function resetInputState(e) {
  769. if (e.keyCode !== 8) this.toggleLastOptionHitState(false);
  770. this.inputLength = this.$refs.input.value.length * 15 + 20;
  771. this.resetInputHeight();
  772. },
  773. resetInputHeight: function resetInputHeight() {
  774. var _this5 = this;
  775. this.$nextTick(function () {
  776. if (!_this5.$refs.reference) return;
  777. var inputChildNodes = _this5.$refs.reference.$el.childNodes;
  778. var input = [].filter.call(inputChildNodes, function (item) {
  779. return item.tagName === 'INPUT';
  780. })[0];
  781. input.style.height = Math.max(_this5.$refs.tags.clientHeight + 6, sizeMap[_this5.size] || 36) + 'px';
  782. if (_this5.visible && _this5.emptyText !== false) {
  783. _this5.broadcast('ElSelectDropdown', 'updatePopper');
  784. }
  785. });
  786. },
  787. resetHoverIndex: function resetHoverIndex() {
  788. var _this6 = this;
  789. setTimeout(function () {
  790. if (!_this6.multiple) {
  791. _this6.hoverIndex = _this6.options.indexOf(_this6.selected);
  792. } else {
  793. if (_this6.selected.length > 0) {
  794. _this6.hoverIndex = Math.min.apply(null, _this6.selected.map(function (item) {
  795. return _this6.options.indexOf(item);
  796. }));
  797. } else {
  798. _this6.hoverIndex = -1;
  799. }
  800. }
  801. }, 300);
  802. },
  803. handleOptionSelect: function handleOptionSelect(option) {
  804. if (!this.multiple) {
  805. this.$emit('input', option.value);
  806. this.visible = false;
  807. } else {
  808. var optionIndex = -1;
  809. this.value.forEach(function (item, index) {
  810. if (item === option.value) {
  811. optionIndex = index;
  812. }
  813. });
  814. if (optionIndex > -1) {
  815. this.value.splice(optionIndex, 1);
  816. } else if (this.multipleLimit <= 0 || this.value.length < this.multipleLimit) {
  817. this.value.push(option.value);
  818. }
  819. if (option.created) {
  820. this.query = '';
  821. this.inputLength = 20;
  822. }
  823. if (this.filterable) this.$refs.input.focus();
  824. }
  825. },
  826. toggleMenu: function toggleMenu() {
  827. if (this.filterable && this.query === '' && this.visible) {
  828. return;
  829. }
  830. if (!this.disabled) {
  831. this.visible = !this.visible;
  832. }
  833. },
  834. navigateOptions: function navigateOptions(direction) {
  835. if (!this.visible) {
  836. this.visible = true;
  837. return;
  838. }
  839. if (this.options.length === 0 || this.filteredOptionsCount === 0) return;
  840. if (!this.optionsAllDisabled) {
  841. if (direction === 'next') {
  842. this.hoverIndex++;
  843. if (this.hoverIndex === this.options.length) {
  844. this.hoverIndex = 0;
  845. }
  846. this.resetScrollTop();
  847. if (this.options[this.hoverIndex].disabled === true || this.options[this.hoverIndex].groupDisabled === true || !this.options[this.hoverIndex].visible) {
  848. this.navigateOptions('next');
  849. }
  850. }
  851. if (direction === 'prev') {
  852. this.hoverIndex--;
  853. if (this.hoverIndex < 0) {
  854. this.hoverIndex = this.options.length - 1;
  855. }
  856. this.resetScrollTop();
  857. if (this.options[this.hoverIndex].disabled === true || this.options[this.hoverIndex].groupDisabled === true || !this.options[this.hoverIndex].visible) {
  858. this.navigateOptions('prev');
  859. }
  860. }
  861. }
  862. },
  863. resetScrollTop: function resetScrollTop() {
  864. var bottomOverflowDistance = this.options[this.hoverIndex].$el.getBoundingClientRect().bottom - this.$refs.popper.$el.getBoundingClientRect().bottom;
  865. var topOverflowDistance = this.options[this.hoverIndex].$el.getBoundingClientRect().top - this.$refs.popper.$el.getBoundingClientRect().top;
  866. if (bottomOverflowDistance > 0) {
  867. this.dropdownUl.scrollTop += bottomOverflowDistance;
  868. }
  869. if (topOverflowDistance < 0) {
  870. this.dropdownUl.scrollTop += topOverflowDistance;
  871. }
  872. },
  873. selectOption: function selectOption() {
  874. if (this.options[this.hoverIndex]) {
  875. this.handleOptionSelect(this.options[this.hoverIndex]);
  876. }
  877. },
  878. deleteSelected: function deleteSelected(event) {
  879. event.stopPropagation();
  880. this.$emit('input', '');
  881. this.visible = false;
  882. },
  883. deleteTag: function deleteTag(event, tag) {
  884. var index = this.selected.indexOf(tag);
  885. if (index > -1 && !this.disabled) {
  886. this.value.splice(index, 1);
  887. this.$emit('remove-tag', tag);
  888. }
  889. event.stopPropagation();
  890. },
  891. onInputChange: function onInputChange() {
  892. if (this.filterable) {
  893. this.query = this.selectedLabel;
  894. }
  895. },
  896. onOptionDestroy: function onOptionDestroy(option) {
  897. this.optionsCount--;
  898. this.filteredOptionsCount--;
  899. var index = this.options.indexOf(option);
  900. if (index > -1) {
  901. this.options.splice(index, 1);
  902. }
  903. this.broadcast('ElOption', 'resetIndex');
  904. },
  905. resetInputWidth: function resetInputWidth() {
  906. this.inputWidth = this.$refs.reference.$el.getBoundingClientRect().width;
  907. },
  908. handleResize: function handleResize() {
  909. this.resetInputWidth();
  910. if (this.multiple) this.resetInputHeight();
  911. }
  912. },
  913. created: function created() {
  914. var _this7 = this;
  915. this.cachedPlaceHolder = this.currentPlaceholder = this.placeholder;
  916. if (this.multiple && !Array.isArray(this.value)) {
  917. this.$emit('input', []);
  918. }
  919. if (!this.multiple && Array.isArray(this.value)) {
  920. this.$emit('input', '');
  921. }
  922. this.setSelected();
  923. this.debouncedOnInputChange = (0, _debounce2.default)(this.debounce, function () {
  924. _this7.onInputChange();
  925. });
  926. this.$on('handleOptionClick', this.handleOptionSelect);
  927. this.$on('onOptionDestroy', this.onOptionDestroy);
  928. this.$on('setSelected', this.setSelected);
  929. },
  930. mounted: function mounted() {
  931. var _this8 = this;
  932. if (this.multiple && Array.isArray(this.value) && this.value.length > 0) {
  933. this.currentPlaceholder = '';
  934. }
  935. (0, _resizeEvent.addResizeListener)(this.$el, this.handleResize);
  936. if (this.remote && this.multiple) {
  937. this.resetInputHeight();
  938. }
  939. this.$nextTick(function () {
  940. if (_this8.$refs.reference && _this8.$refs.reference.$el) {
  941. _this8.inputWidth = _this8.$refs.reference.$el.getBoundingClientRect().width;
  942. }
  943. });
  944. },
  945. beforeDestroy: function beforeDestroy() {
  946. if (this.$el && this.handleResize) (0, _resizeEvent.removeResizeListener)(this.$el, this.handleResize);
  947. }
  948. };
  949. /***/ },
  950. /***/ 263:
  951. /***/ function(module, exports, __webpack_require__) {
  952. var Component = __webpack_require__(3)(
  953. /* script */
  954. __webpack_require__(264),
  955. /* template */
  956. __webpack_require__(265),
  957. /* scopeId */
  958. null,
  959. /* cssModules */
  960. null
  961. )
  962. module.exports = Component.exports
  963. /***/ },
  964. /***/ 264:
  965. /***/ function(module, exports, __webpack_require__) {
  966. 'use strict';
  967. exports.__esModule = true;
  968. var _vuePopper = __webpack_require__(13);
  969. var _vuePopper2 = _interopRequireDefault(_vuePopper);
  970. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  971. exports.default = {
  972. name: 'ElSelectDropdown',
  973. componentName: 'ElSelectDropdown',
  974. mixins: [_vuePopper2.default],
  975. props: {
  976. placement: {
  977. default: 'bottom-start'
  978. },
  979. boundariesPadding: {
  980. default: 0
  981. },
  982. popperOptions: {
  983. default: function _default() {
  984. return {
  985. forceAbsolute: true,
  986. gpuAcceleration: false
  987. };
  988. }
  989. }
  990. },
  991. data: function data() {
  992. return {
  993. minWidth: ''
  994. };
  995. },
  996. computed: {
  997. popperClass: function popperClass() {
  998. return this.$parent.popperClass;
  999. }
  1000. },
  1001. watch: {
  1002. '$parent.inputWidth': function $parentInputWidth() {
  1003. this.minWidth = this.$parent.$el.getBoundingClientRect().width + 'px';
  1004. }
  1005. },
  1006. mounted: function mounted() {
  1007. this.referenceElm = this.$parent.$refs.reference.$el;
  1008. this.$parent.popperElm = this.popperElm = this.$el;
  1009. this.$on('updatePopper', this.updatePopper);
  1010. this.$on('destroyPopper', this.destroyPopper);
  1011. }
  1012. }; //
  1013. //
  1014. //
  1015. //
  1016. //
  1017. //
  1018. //
  1019. //
  1020. //
  1021. /***/ },
  1022. /***/ 265:
  1023. /***/ function(module, exports) {
  1024. module.exports={render:function (){var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;
  1025. return _c('div', {
  1026. staticClass: "el-select-dropdown",
  1027. class: [{
  1028. 'is-multiple': _vm.$parent.multiple
  1029. }, _vm.popperClass],
  1030. style: ({
  1031. minWidth: _vm.minWidth
  1032. })
  1033. }, [_vm._t("default")], 2)
  1034. },staticRenderFns: []}
  1035. /***/ },
  1036. /***/ 266:
  1037. /***/ function(module, exports) {
  1038. module.exports = require("element-ui/lib/tag");
  1039. /***/ },
  1040. /***/ 267:
  1041. /***/ function(module, exports) {
  1042. module.exports={render:function (){var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;
  1043. return _c('div', {
  1044. directives: [{
  1045. name: "clickoutside",
  1046. rawName: "v-clickoutside",
  1047. value: (_vm.handleClose),
  1048. expression: "handleClose"
  1049. }],
  1050. staticClass: "el-select"
  1051. }, [(_vm.multiple) ? _c('div', {
  1052. ref: "tags",
  1053. staticClass: "el-select__tags",
  1054. style: ({
  1055. 'max-width': _vm.inputWidth - 32 + 'px'
  1056. }),
  1057. on: {
  1058. "click": function($event) {
  1059. $event.stopPropagation();
  1060. _vm.toggleMenu($event)
  1061. }
  1062. }
  1063. }, [_c('transition-group', {
  1064. on: {
  1065. "after-leave": _vm.resetInputHeight
  1066. }
  1067. }, _vm._l((_vm.selected), function(item) {
  1068. return _c('el-tag', {
  1069. key: item.value,
  1070. attrs: {
  1071. "closable": "",
  1072. "hit": item.hitState,
  1073. "type": "primary",
  1074. "close-transition": ""
  1075. },
  1076. on: {
  1077. "close": function($event) {
  1078. _vm.deleteTag($event, item)
  1079. }
  1080. }
  1081. }, [_c('span', {
  1082. staticClass: "el-select__tags-text"
  1083. }, [_vm._v(_vm._s(item.currentLabel))])])
  1084. })), (_vm.filterable) ? _c('input', {
  1085. directives: [{
  1086. name: "model",
  1087. rawName: "v-model",
  1088. value: (_vm.query),
  1089. expression: "query"
  1090. }],
  1091. ref: "input",
  1092. staticClass: "el-select__input",
  1093. class: ("is-" + _vm.size),
  1094. style: ({
  1095. width: _vm.inputLength + 'px',
  1096. 'max-width': _vm.inputWidth - 42 + 'px'
  1097. }),
  1098. attrs: {
  1099. "type": "text",
  1100. "disabled": _vm.disabled,
  1101. "debounce": _vm.remote ? 300 : 0
  1102. },
  1103. domProps: {
  1104. "value": _vm._s(_vm.query)
  1105. },
  1106. on: {
  1107. "focus": function($event) {
  1108. _vm.visible = true
  1109. },
  1110. "keyup": _vm.managePlaceholder,
  1111. "keydown": [_vm.resetInputState, function($event) {
  1112. if (_vm._k($event.keyCode, "down", 40)) { return; }
  1113. $event.preventDefault();
  1114. _vm.navigateOptions('next')
  1115. }, function($event) {
  1116. if (_vm._k($event.keyCode, "up", 38)) { return; }
  1117. $event.preventDefault();
  1118. _vm.navigateOptions('prev')
  1119. }, function($event) {
  1120. if (_vm._k($event.keyCode, "enter", 13)) { return; }
  1121. $event.preventDefault();
  1122. _vm.selectOption($event)
  1123. }, function($event) {
  1124. if (_vm._k($event.keyCode, "esc", 27)) { return; }
  1125. $event.preventDefault();
  1126. _vm.visible = false
  1127. }, function($event) {
  1128. if (_vm._k($event.keyCode, "delete", [8, 46])) { return; }
  1129. _vm.deletePrevTag($event)
  1130. }],
  1131. "input": function($event) {
  1132. if ($event.target.composing) { return; }
  1133. _vm.query = $event.target.value
  1134. }
  1135. }
  1136. }) : _vm._e()], 1) : _vm._e(), _c('el-input', {
  1137. directives: [{
  1138. name: "model",
  1139. rawName: "v-model",
  1140. value: (_vm.selectedLabel),
  1141. expression: "selectedLabel"
  1142. }],
  1143. ref: "reference",
  1144. attrs: {
  1145. "type": "text",
  1146. "placeholder": _vm.currentPlaceholder,
  1147. "name": _vm.name,
  1148. "size": _vm.size,
  1149. "disabled": _vm.disabled,
  1150. "readonly": !_vm.filterable || _vm.multiple,
  1151. "validate-event": false,
  1152. "icon": _vm.iconClass
  1153. },
  1154. domProps: {
  1155. "value": (_vm.selectedLabel)
  1156. },
  1157. on: {
  1158. "focus": _vm.handleFocus,
  1159. "click": _vm.handleIconClick,
  1160. "input": function($event) {
  1161. _vm.selectedLabel = $event
  1162. }
  1163. },
  1164. nativeOn: {
  1165. "mousedown": function($event) {
  1166. _vm.handleMouseDown($event)
  1167. },
  1168. "keyup": function($event) {
  1169. _vm.debouncedOnInputChange($event)
  1170. },
  1171. "keydown": [function($event) {
  1172. if (_vm._k($event.keyCode, "down", 40)) { return; }
  1173. $event.preventDefault();
  1174. _vm.navigateOptions('next')
  1175. }, function($event) {
  1176. if (_vm._k($event.keyCode, "up", 38)) { return; }
  1177. $event.preventDefault();
  1178. _vm.navigateOptions('prev')
  1179. }, function($event) {
  1180. if (_vm._k($event.keyCode, "enter", 13)) { return; }
  1181. $event.preventDefault();
  1182. _vm.selectOption($event)
  1183. }, function($event) {
  1184. if (_vm._k($event.keyCode, "esc", 27)) { return; }
  1185. $event.preventDefault();
  1186. _vm.visible = false
  1187. }, function($event) {
  1188. if (_vm._k($event.keyCode, "tab", 9)) { return; }
  1189. _vm.visible = false
  1190. }],
  1191. "paste": function($event) {
  1192. _vm.debouncedOnInputChange($event)
  1193. },
  1194. "mouseenter": function($event) {
  1195. _vm.inputHovering = true
  1196. },
  1197. "mouseleave": function($event) {
  1198. _vm.inputHovering = false
  1199. }
  1200. }
  1201. }), _c('transition', {
  1202. attrs: {
  1203. "name": "el-zoom-in-top"
  1204. },
  1205. on: {
  1206. "after-leave": _vm.doDestroy,
  1207. "after-enter": _vm.handleMenuEnter
  1208. }
  1209. }, [_c('el-select-menu', {
  1210. directives: [{
  1211. name: "show",
  1212. rawName: "v-show",
  1213. value: (_vm.visible && _vm.emptyText !== false),
  1214. expression: "visible && emptyText !== false"
  1215. }],
  1216. ref: "popper"
  1217. }, [_c('el-scrollbar', {
  1218. directives: [{
  1219. name: "show",
  1220. rawName: "v-show",
  1221. value: (_vm.options.length > 0 && !_vm.loading),
  1222. expression: "options.length > 0 && !loading"
  1223. }],
  1224. class: {
  1225. 'is-empty': !_vm.allowCreate && _vm.filteredOptionsCount === 0
  1226. },
  1227. attrs: {
  1228. "tag": "ul",
  1229. "wrap-class": "el-select-dropdown__wrap",
  1230. "view-class": "el-select-dropdown__list"
  1231. }
  1232. }, [(_vm.showNewOption) ? _c('el-option', {
  1233. attrs: {
  1234. "value": _vm.query,
  1235. "created": ""
  1236. }
  1237. }) : _vm._e(), _vm._t("default")], 2), (_vm.emptyText && !_vm.allowCreate) ? _c('p', {
  1238. staticClass: "el-select-dropdown__empty"
  1239. }, [_vm._v(_vm._s(_vm.emptyText))]) : _vm._e()], 1)], 1)], 1)
  1240. },staticRenderFns: []}
  1241. /***/ }
  1242. /******/ });