icon-picker.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  1. import { defineVxeComponent } from '../../ui/src/comp';
  2. import XEUtils from 'xe-utils';
  3. import { getConfig, getIcon, getI18n, globalEvents, renderer, createEvent, globalMixins, GLOBAL_EVENT_KEYS, renderEmptyElement } from '../../ui';
  4. import { getEventTargetNode, getAbsolutePos } from '../../ui/src/dom';
  5. import { getLastZIndex, nextZIndex, getFuncText } from '../../ui/src/utils';
  6. import { getSlotVNs } from '../../ui/src/vn';
  7. export default {
  8. name: 'VxeIconPicker',
  9. mixins: [
  10. globalMixins.sizeMixin
  11. ],
  12. model: {
  13. prop: 'value',
  14. event: 'modelValue'
  15. },
  16. props: {
  17. value: String,
  18. placeholder: String,
  19. clearable: Boolean,
  20. size: {
  21. type: String,
  22. default: () => getConfig().iconPicker.size || getConfig().size
  23. },
  24. className: [String, Function],
  25. popupClassName: [String, Function],
  26. showIconTitle: {
  27. type: Boolean,
  28. default: () => getConfig().iconPicker.showIconTitle
  29. },
  30. readonly: {
  31. type: Boolean,
  32. default: null
  33. },
  34. disabled: {
  35. type: Boolean,
  36. default: null
  37. },
  38. icons: Array,
  39. placement: String,
  40. transfer: {
  41. type: Boolean,
  42. default: null
  43. }
  44. },
  45. inject: {
  46. $xeModal: {
  47. default: null
  48. },
  49. $xeDrawer: {
  50. default: null
  51. },
  52. $xeTable: {
  53. default: null
  54. },
  55. $xeForm: {
  56. default: null
  57. },
  58. formItemInfo: {
  59. from: 'xeFormItemInfo',
  60. default: null
  61. }
  62. },
  63. provide() {
  64. const $xeIconPicker = this;
  65. return {
  66. $xeIconPicker
  67. };
  68. },
  69. data() {
  70. const reactData = {
  71. initialized: false,
  72. selectIcon: '',
  73. panelIndex: 0,
  74. panelStyle: {},
  75. panelPlacement: null,
  76. visiblePanel: false,
  77. isAniVisible: false,
  78. isActivated: false
  79. };
  80. const internalData = {
  81. hpTimeout: undefined
  82. };
  83. return {
  84. xID: XEUtils.uniqueId(),
  85. reactData,
  86. internalData
  87. };
  88. },
  89. computed: Object.assign(Object.assign({}, {}), { computeFormReadonly() {
  90. const $xeIconPicker = this;
  91. const props = $xeIconPicker;
  92. const $xeForm = $xeIconPicker.$xeForm;
  93. const { readonly } = props;
  94. if (readonly === null) {
  95. if ($xeForm) {
  96. return $xeForm.readonly;
  97. }
  98. return false;
  99. }
  100. return readonly;
  101. },
  102. computeIsDisabled() {
  103. const $xeIconPicker = this;
  104. const props = $xeIconPicker;
  105. const $xeForm = $xeIconPicker.$xeForm;
  106. const { disabled } = props;
  107. if (disabled === null) {
  108. if ($xeForm) {
  109. return $xeForm.disabled;
  110. }
  111. return false;
  112. }
  113. return disabled;
  114. },
  115. computeBtnTransfer() {
  116. const $xeIconPicker = this;
  117. const props = $xeIconPicker;
  118. const $xeTable = $xeIconPicker.$xeTable;
  119. const $xeModal = $xeIconPicker.$xeModal;
  120. const $xeDrawer = $xeIconPicker.$xeDrawer;
  121. const $xeForm = $xeIconPicker.$xeForm;
  122. const { transfer } = props;
  123. if (transfer === null) {
  124. const globalTransfer = getConfig().iconPicker.transfer;
  125. if (XEUtils.isBoolean(globalTransfer)) {
  126. return globalTransfer;
  127. }
  128. if ($xeTable || $xeModal || $xeDrawer || $xeForm) {
  129. return true;
  130. }
  131. }
  132. return transfer;
  133. },
  134. computeInpPlaceholder() {
  135. const $xeIconPicker = this;
  136. const props = $xeIconPicker;
  137. const { placeholder } = props;
  138. if (placeholder) {
  139. return getFuncText(placeholder);
  140. }
  141. const globalPlaceholder = getConfig().select.placeholder;
  142. if (globalPlaceholder) {
  143. return getFuncText(globalPlaceholder);
  144. }
  145. return getI18n('vxe.base.pleaseSelect');
  146. },
  147. computeIconList() {
  148. const $xeIconPicker = this;
  149. const props = $xeIconPicker;
  150. let { icons } = props;
  151. if (!icons || !icons.length) {
  152. icons = getConfig().iconPicker.icons || [];
  153. }
  154. return icons.map(item => {
  155. if (XEUtils.isString(item)) {
  156. return {
  157. title: item,
  158. icon: `vxe-icon-${`${item || ''}`.replace(/^vxe-icon-/, '')}`
  159. };
  160. }
  161. return {
  162. title: `${item.title || ''}`,
  163. icon: item.icon || '',
  164. iconRender: item.iconRender
  165. };
  166. });
  167. },
  168. computeIconGroupList() {
  169. const $xeIconPicker = this;
  170. const iconList = $xeIconPicker.computeIconList;
  171. return XEUtils.chunk(iconList, 4);
  172. },
  173. computeSelectIconItem() {
  174. const $xeIconPicker = this;
  175. const reactData = $xeIconPicker.reactData;
  176. const { selectIcon } = reactData;
  177. const iconList = $xeIconPicker.computeIconList;
  178. return selectIcon ? iconList.find(item => item.icon === selectIcon) : null;
  179. } }),
  180. methods: {
  181. //
  182. // Method
  183. //
  184. dispatchEvent(type, params, evnt) {
  185. const $xeIconPicker = this;
  186. $xeIconPicker.$emit(type, createEvent(evnt, { $iconPicker: $xeIconPicker }, params));
  187. },
  188. emitModel(value) {
  189. const $xeIconPicker = this;
  190. const { _events } = $xeIconPicker;
  191. if (_events && _events.modelValue) {
  192. $xeIconPicker.$emit('modelValue', value);
  193. }
  194. else {
  195. $xeIconPicker.$emit('model-value', value);
  196. }
  197. },
  198. isPanelVisible() {
  199. const $xeIconPicker = this;
  200. const reactData = $xeIconPicker.reactData;
  201. return reactData.visiblePanel;
  202. },
  203. togglePanel() {
  204. const $xeIconPicker = this;
  205. const reactData = $xeIconPicker.reactData;
  206. if (reactData.visiblePanel) {
  207. $xeIconPicker.hideOptionPanel();
  208. }
  209. else {
  210. $xeIconPicker.showOptionPanel();
  211. }
  212. return $xeIconPicker.$nextTick();
  213. },
  214. hidePanel() {
  215. const $xeIconPicker = this;
  216. const reactData = $xeIconPicker.reactData;
  217. if (reactData.visiblePanel) {
  218. $xeIconPicker.hideOptionPanel();
  219. }
  220. return $xeIconPicker.$nextTick();
  221. },
  222. showPanel() {
  223. const $xeIconPicker = this;
  224. const reactData = $xeIconPicker.reactData;
  225. if (!reactData.visiblePanel) {
  226. $xeIconPicker.showOptionPanel();
  227. }
  228. return $xeIconPicker.$nextTick();
  229. },
  230. focus() {
  231. const $xeIconPicker = this;
  232. const reactData = $xeIconPicker.reactData;
  233. const $input = $xeIconPicker.$refs.refInput;
  234. reactData.isActivated = true;
  235. $input.blur();
  236. return $xeIconPicker.$nextTick();
  237. },
  238. blur() {
  239. const $xeIconPicker = this;
  240. const reactData = $xeIconPicker.reactData;
  241. const $input = $xeIconPicker.$refs.refInput;
  242. $input.blur();
  243. reactData.isActivated = false;
  244. return $xeIconPicker.$nextTick();
  245. },
  246. updateZindex() {
  247. const $xeIconPicker = this;
  248. const reactData = $xeIconPicker.reactData;
  249. if (reactData.panelIndex < getLastZIndex()) {
  250. reactData.panelIndex = nextZIndex();
  251. }
  252. },
  253. updatePlacement() {
  254. const $xeIconPicker = this;
  255. const props = $xeIconPicker;
  256. const reactData = $xeIconPicker.reactData;
  257. return $xeIconPicker.$nextTick().then(() => {
  258. const { placement } = props;
  259. const { panelIndex } = reactData;
  260. const el = $xeIconPicker.$refs.refElem;
  261. const panelElem = $xeIconPicker.$refs.refOptionPanel;
  262. const btnTransfer = $xeIconPicker.computeBtnTransfer;
  263. if (panelElem && el) {
  264. const targetHeight = el.offsetHeight;
  265. const targetWidth = el.offsetWidth;
  266. const panelHeight = panelElem.offsetHeight;
  267. const panelWidth = panelElem.offsetWidth;
  268. const marginSize = 5;
  269. const panelStyle = {
  270. zIndex: panelIndex
  271. };
  272. const { boundingTop, boundingLeft, visibleHeight, visibleWidth } = getAbsolutePos(el);
  273. let panelPlacement = 'bottom';
  274. if (btnTransfer) {
  275. let left = boundingLeft;
  276. let top = boundingTop + targetHeight;
  277. if (placement === 'top') {
  278. panelPlacement = 'top';
  279. top = boundingTop - panelHeight;
  280. }
  281. else if (!placement) {
  282. // 如果下面不够放,则向上
  283. if (top + panelHeight + marginSize > visibleHeight) {
  284. panelPlacement = 'top';
  285. top = boundingTop - panelHeight;
  286. }
  287. // 如果上面不够放,则向下(优先)
  288. if (top < marginSize) {
  289. panelPlacement = 'bottom';
  290. top = boundingTop + targetHeight;
  291. }
  292. }
  293. // 如果溢出右边
  294. if (left + panelWidth + marginSize > visibleWidth) {
  295. left -= left + panelWidth + marginSize - visibleWidth;
  296. }
  297. // 如果溢出左边
  298. if (left < marginSize) {
  299. left = marginSize;
  300. }
  301. Object.assign(panelStyle, {
  302. left: `${left}px`,
  303. top: `${top}px`,
  304. minWidth: `${targetWidth}px`
  305. });
  306. }
  307. else {
  308. if (placement === 'top') {
  309. panelPlacement = 'top';
  310. panelStyle.bottom = `${targetHeight}px`;
  311. }
  312. else if (!placement) {
  313. // 如果下面不够放,则向上
  314. if (boundingTop + targetHeight + panelHeight > visibleHeight) {
  315. // 如果上面不够放,则向下(优先)
  316. if (boundingTop - targetHeight - panelHeight > marginSize) {
  317. panelPlacement = 'top';
  318. panelStyle.bottom = `${targetHeight}px`;
  319. }
  320. }
  321. }
  322. }
  323. reactData.panelStyle = panelStyle;
  324. reactData.panelPlacement = panelPlacement;
  325. return $xeIconPicker.$nextTick();
  326. }
  327. });
  328. },
  329. showOptionPanel() {
  330. const $xeIconPicker = this;
  331. const reactData = $xeIconPicker.reactData;
  332. const internalData = $xeIconPicker.internalData;
  333. const { hpTimeout } = internalData;
  334. const isDisabled = $xeIconPicker.computeIsDisabled;
  335. if (!isDisabled) {
  336. if (hpTimeout) {
  337. clearTimeout(hpTimeout);
  338. internalData.hpTimeout = undefined;
  339. }
  340. const btnTransfer = $xeIconPicker.computeBtnTransfer;
  341. const panelElem = $xeIconPicker.$refs.refOptionPanel;
  342. if (!reactData.initialized) {
  343. reactData.initialized = true;
  344. if (btnTransfer) {
  345. if (panelElem) {
  346. document.body.appendChild(panelElem);
  347. }
  348. }
  349. }
  350. reactData.isActivated = true;
  351. reactData.isAniVisible = true;
  352. setTimeout(() => {
  353. reactData.visiblePanel = true;
  354. }, 10);
  355. $xeIconPicker.updateZindex();
  356. $xeIconPicker.updatePlacement();
  357. }
  358. },
  359. hideOptionPanel() {
  360. const $xeIconPicker = this;
  361. const reactData = $xeIconPicker.reactData;
  362. const internalData = $xeIconPicker.internalData;
  363. reactData.visiblePanel = false;
  364. internalData.hpTimeout = setTimeout(() => {
  365. reactData.isAniVisible = false;
  366. }, 350);
  367. },
  368. changeEvent(evnt, selectValue) {
  369. const $xeIconPicker = this;
  370. const props = $xeIconPicker;
  371. const reactData = $xeIconPicker.reactData;
  372. const $xeForm = $xeIconPicker.$xeForm;
  373. const formItemInfo = $xeIconPicker.formItemInfo;
  374. reactData.selectIcon = selectValue;
  375. if (selectValue !== props.value) {
  376. $xeIconPicker.emitModel(selectValue);
  377. $xeIconPicker.dispatchEvent('change', { value: selectValue }, evnt);
  378. // 自动更新校验状态
  379. if ($xeForm && formItemInfo) {
  380. $xeForm.triggerItemEvent(evnt, formItemInfo.itemConfig.field, selectValue);
  381. }
  382. }
  383. },
  384. focusEvent() {
  385. const $xeIconPicker = this;
  386. const reactData = $xeIconPicker.reactData;
  387. const isDisabled = $xeIconPicker.computeIsDisabled;
  388. if (!isDisabled) {
  389. if (!reactData.visiblePanel) {
  390. $xeIconPicker.showOptionPanel();
  391. }
  392. }
  393. },
  394. blurEvent() {
  395. const $xeIconPicker = this;
  396. const reactData = $xeIconPicker.reactData;
  397. reactData.isActivated = false;
  398. },
  399. clearValueEvent(evnt, selectValue) {
  400. const $xeIconPicker = this;
  401. $xeIconPicker.changeEvent(evnt, selectValue);
  402. $xeIconPicker.dispatchEvent('clear', { value: selectValue }, evnt);
  403. },
  404. clearEvent(params, evnt) {
  405. const $xeIconPicker = this;
  406. $xeIconPicker.clearValueEvent(evnt, null);
  407. $xeIconPicker.hideOptionPanel();
  408. },
  409. togglePanelEvent(evnt) {
  410. const $xeIconPicker = this;
  411. const reactData = $xeIconPicker.reactData;
  412. evnt.preventDefault();
  413. if (reactData.visiblePanel) {
  414. $xeIconPicker.hideOptionPanel();
  415. }
  416. else {
  417. $xeIconPicker.showOptionPanel();
  418. }
  419. },
  420. clickEvent(evnt) {
  421. const $xeIconPicker = this;
  422. $xeIconPicker.togglePanelEvent(evnt);
  423. $xeIconPicker.dispatchEvent('click', {}, evnt);
  424. },
  425. handleGlobalMousewheelEvent(evnt) {
  426. const $xeIconPicker = this;
  427. const reactData = $xeIconPicker.reactData;
  428. const { visiblePanel } = reactData;
  429. const isDisabled = $xeIconPicker.computeIsDisabled;
  430. if (!isDisabled) {
  431. if (visiblePanel) {
  432. const panelElem = $xeIconPicker.$refs.refOptionPanel;
  433. if (getEventTargetNode(evnt, panelElem).flag) {
  434. $xeIconPicker.updatePlacement();
  435. }
  436. else {
  437. $xeIconPicker.hideOptionPanel();
  438. }
  439. }
  440. }
  441. },
  442. handleGlobalMousedownEvent(evnt) {
  443. const $xeIconPicker = this;
  444. const reactData = $xeIconPicker.reactData;
  445. const { visiblePanel } = reactData;
  446. const isDisabled = $xeIconPicker.computeIsDisabled;
  447. if (!isDisabled) {
  448. const el = $xeIconPicker.$refs.refElem;
  449. const panelElem = $xeIconPicker.$refs.refOptionPanel;
  450. reactData.isActivated = getEventTargetNode(evnt, el).flag || getEventTargetNode(evnt, panelElem).flag;
  451. if (visiblePanel && !reactData.isActivated) {
  452. $xeIconPicker.hideOptionPanel();
  453. }
  454. }
  455. },
  456. handleGlobalKeydownEvent(evnt) {
  457. const $xeIconPicker = this;
  458. const props = $xeIconPicker;
  459. const reactData = $xeIconPicker.reactData;
  460. const { clearable } = props;
  461. const { visiblePanel } = reactData;
  462. const isDisabled = $xeIconPicker.computeIsDisabled;
  463. if (!isDisabled) {
  464. const isTab = globalEvents.hasKey(evnt, GLOBAL_EVENT_KEYS.TAB);
  465. const isEnter = globalEvents.hasKey(evnt, GLOBAL_EVENT_KEYS.ENTER);
  466. const isEsc = globalEvents.hasKey(evnt, GLOBAL_EVENT_KEYS.ESCAPE);
  467. const isUpArrow = globalEvents.hasKey(evnt, GLOBAL_EVENT_KEYS.ARROW_UP);
  468. const isDwArrow = globalEvents.hasKey(evnt, GLOBAL_EVENT_KEYS.ARROW_DOWN);
  469. const isDel = globalEvents.hasKey(evnt, GLOBAL_EVENT_KEYS.DELETE);
  470. const isSpacebar = globalEvents.hasKey(evnt, GLOBAL_EVENT_KEYS.SPACEBAR);
  471. if (isTab) {
  472. reactData.isActivated = false;
  473. }
  474. if (visiblePanel) {
  475. if (isEsc || isTab) {
  476. $xeIconPicker.hideOptionPanel();
  477. }
  478. else if (isEnter) {
  479. evnt.preventDefault();
  480. evnt.stopPropagation();
  481. // changeOptionEvent(evnt, currentValue, currentOption)
  482. }
  483. else if (isUpArrow || isDwArrow) {
  484. evnt.preventDefault();
  485. // let { firstOption, offsetOption } = findOffsetOption(currentValue, isUpArrow)
  486. // if (!offsetOption && !findVisibleOption(currentValue)) {
  487. // offsetOption = firstOption
  488. // }
  489. // setCurrentOption(offsetOption)
  490. // scrollToOption(offsetOption, isDwArrow)
  491. }
  492. else if (isSpacebar) {
  493. evnt.preventDefault();
  494. }
  495. }
  496. else if ((isUpArrow || isDwArrow || isEnter || isSpacebar) && reactData.isActivated) {
  497. evnt.preventDefault();
  498. $xeIconPicker.showOptionPanel();
  499. }
  500. if (reactData.isActivated) {
  501. if (isDel && clearable) {
  502. $xeIconPicker.clearValueEvent(evnt, null);
  503. }
  504. }
  505. }
  506. },
  507. handleGlobalBlurEvent() {
  508. const $xeIconPicker = this;
  509. const reactData = $xeIconPicker.reactData;
  510. const { visiblePanel, isActivated } = reactData;
  511. if (visiblePanel) {
  512. $xeIconPicker.hideOptionPanel();
  513. }
  514. if (isActivated) {
  515. reactData.isActivated = false;
  516. }
  517. if (visiblePanel || isActivated) {
  518. const $input = $xeIconPicker.$refs.refInput;
  519. if ($input) {
  520. $input.blur();
  521. }
  522. }
  523. },
  524. handleClickIconEvent(evnt, item) {
  525. const $xeIconPicker = this;
  526. const value = item.icon;
  527. $xeIconPicker.changeEvent(evnt, value);
  528. $xeIconPicker.hideOptionPanel();
  529. },
  530. //
  531. // Render
  532. //
  533. renderIconWrapper(h) {
  534. const $xeIconPicker = this;
  535. const props = $xeIconPicker;
  536. const { showIconTitle } = props;
  537. const iconGroupList = $xeIconPicker.computeIconGroupList;
  538. const isDisabled = $xeIconPicker.computeIsDisabled;
  539. return h('div', {
  540. class: 'vxe-ico-picker--list-wrapper'
  541. }, iconGroupList.map(list => {
  542. return h('div', {
  543. class: 'vxe-ico-picker--list'
  544. }, list.map(item => {
  545. const { iconRender } = item;
  546. const compConf = iconRender ? renderer.get(iconRender.name) : null;
  547. const oIconMethod = compConf ? compConf.renderIconPickerOptionIcon : null;
  548. return h('div', {
  549. class: 'vxe-ico-picker--item',
  550. on: {
  551. click(evnt) {
  552. if (!isDisabled) {
  553. $xeIconPicker.handleClickIconEvent(evnt, item);
  554. }
  555. }
  556. }
  557. }, [
  558. h('div', {
  559. class: 'vxe-ico-picker--item-icon'
  560. }, oIconMethod && iconRender
  561. ? getSlotVNs(oIconMethod.call($xeIconPicker, h, iconRender, { $iconPicker: $xeIconPicker, option: item }))
  562. : [
  563. h('i', {
  564. class: item.icon || ''
  565. })
  566. ]),
  567. showIconTitle
  568. ? h('div', {
  569. class: 'vxe-ico-picker--item-title'
  570. }, `${item.title || ''}`)
  571. : renderEmptyElement($xeIconPicker)
  572. ]);
  573. }));
  574. }));
  575. },
  576. renderIconView(h) {
  577. const $xeIconPicker = this;
  578. const reactData = $xeIconPicker.reactData;
  579. const { selectIcon } = reactData;
  580. const selectIconItem = $xeIconPicker.computeSelectIconItem;
  581. if (selectIconItem) {
  582. const { iconRender } = selectIconItem;
  583. const compConf = iconRender ? renderer.get(iconRender.name) : null;
  584. const oIconMethod = compConf ? compConf.renderIconPickerOptionIcon : null;
  585. if (oIconMethod && iconRender) {
  586. return h('div', {
  587. key: 'inc',
  588. class: 'vxe-ico-picker--icon'
  589. }, getSlotVNs(oIconMethod.call($xeIconPicker, h, iconRender, { $iconPicker: $xeIconPicker, option: selectIconItem })));
  590. }
  591. }
  592. return h('div', {
  593. key: 'ind',
  594. class: 'vxe-ico-picker--icon'
  595. }, [
  596. h('i', {
  597. class: selectIcon
  598. })
  599. ]);
  600. },
  601. renderVN(h) {
  602. const $xeIconPicker = this;
  603. const props = $xeIconPicker;
  604. const reactData = $xeIconPicker.reactData;
  605. const { className, popupClassName, clearable } = props;
  606. const { initialized, isActivated, isAniVisible, visiblePanel, selectIcon } = reactData;
  607. const vSize = $xeIconPicker.computeSize;
  608. const isDisabled = $xeIconPicker.computeIsDisabled;
  609. const btnTransfer = $xeIconPicker.computeBtnTransfer;
  610. const formReadonly = $xeIconPicker.computeFormReadonly;
  611. const inpPlaceholder = $xeIconPicker.computeInpPlaceholder;
  612. if (formReadonly) {
  613. return h('div', {
  614. ref: 'refElem',
  615. class: ['vxe-ico-picker--readonly', className]
  616. }, [
  617. h('i', {
  618. class: selectIcon
  619. })
  620. ]);
  621. }
  622. return h('div', {
  623. ref: 'refElem',
  624. class: ['vxe-ico-picker', className ? (XEUtils.isFunction(className) ? className({ $iconPicker: $xeIconPicker }) : className) : '', {
  625. [`size--${vSize}`]: vSize,
  626. 'show--clear': clearable && !isDisabled && !!selectIcon,
  627. 'is--visible': visiblePanel,
  628. 'is--disabled': isDisabled,
  629. 'is--active': isActivated
  630. }]
  631. }, [
  632. h('div', {
  633. class: 'vxe-ico-picker--inner',
  634. on: {
  635. click: $xeIconPicker.clickEvent
  636. }
  637. }, [
  638. h('input', {
  639. ref: 'refInput',
  640. class: 'vxe-ico-picker--input',
  641. on: {
  642. focus: $xeIconPicker.focusEvent,
  643. blur: $xeIconPicker.blurEvent
  644. }
  645. }),
  646. selectIcon
  647. ? $xeIconPicker.renderIconView(h)
  648. : h('div', {
  649. class: 'vxe-ico-picker--placeholder'
  650. }, inpPlaceholder),
  651. h('div', {
  652. class: 'vxe-ico-picker--suffix'
  653. }, [
  654. h('div', {
  655. class: 'vxe-ico-picker--clear-icon',
  656. on: {
  657. click: $xeIconPicker.clearEvent
  658. }
  659. }, [
  660. h('i', {
  661. class: getIcon().INPUT_CLEAR
  662. })
  663. ]),
  664. h('div', {
  665. class: 'vxe-ico-picker--suffix-icon'
  666. }, [
  667. h('i', {
  668. class: visiblePanel ? getIcon().ICON_PICKER_OPEN : getIcon().ICON_PICKER_CLOSE
  669. })
  670. ])
  671. ])
  672. ]),
  673. h('div', {
  674. ref: 'refOptionPanel',
  675. class: ['vxe-table--ignore-clear vxe-ico-picker--panel', popupClassName ? (XEUtils.isFunction(popupClassName) ? popupClassName({ $iconPicker: $xeIconPicker }) : popupClassName) : '', {
  676. [`size--${vSize}`]: vSize,
  677. 'is--transfer': btnTransfer,
  678. 'ani--leave': isAniVisible,
  679. 'ani--enter': visiblePanel
  680. }],
  681. attrs: {
  682. placement: reactData.panelPlacement
  683. },
  684. style: reactData.panelStyle
  685. }, [
  686. initialized && (visiblePanel || isAniVisible)
  687. ? h('div', {
  688. class: 'vxe-ico-picker--panel-wrapper'
  689. }, [
  690. $xeIconPicker.renderIconWrapper(h)
  691. ])
  692. : renderEmptyElement($xeIconPicker)
  693. ])
  694. ]);
  695. }
  696. },
  697. watch: {
  698. value(val) {
  699. const $xeIconPicker = this;
  700. const reactData = $xeIconPicker.reactData;
  701. reactData.selectIcon = `${val || ''}`;
  702. }
  703. },
  704. created() {
  705. const $xeIconPicker = this;
  706. const props = $xeIconPicker;
  707. const reactData = $xeIconPicker.reactData;
  708. reactData.selectIcon = `${props.value || ''}`;
  709. globalEvents.on($xeIconPicker, 'mousewheel', $xeIconPicker.handleGlobalMousewheelEvent);
  710. globalEvents.on($xeIconPicker, 'mousedown', $xeIconPicker.handleGlobalMousedownEvent);
  711. globalEvents.on($xeIconPicker, 'keydown', $xeIconPicker.handleGlobalKeydownEvent);
  712. globalEvents.on($xeIconPicker, 'blur', $xeIconPicker.handleGlobalBlurEvent);
  713. },
  714. beforeDestroy() {
  715. const $xeIconPicker = this;
  716. const panelElem = $xeIconPicker.$refs.refOptionPanel;
  717. if (panelElem && panelElem.parentNode) {
  718. panelElem.parentNode.removeChild(panelElem);
  719. }
  720. globalEvents.off($xeIconPicker, 'mousewheel');
  721. globalEvents.off($xeIconPicker, 'mousedown');
  722. globalEvents.off($xeIconPicker, 'keydown');
  723. globalEvents.off($xeIconPicker, 'blur');
  724. },
  725. render(h) {
  726. return this.renderVN(h);
  727. }
  728. };