1- import {
2- defineComponent ,
3- ref ,
4- renderSlot ,
5- computed ,
6- Transition ,
7- watch ,
8- } from 'vue'
1+ import { defineComponent , ref , renderSlot , computed , Transition } from "vue"
92import {
103 OptionItem ,
114 editableSelectProps ,
125 EditableSelectProps ,
13- } from ' ./editable-select-types'
14- import ' ./editable-select.scss'
15- import { Icon } from ' ../../icon'
16- import ClickOutside from ' ../../shared/devui-directive/clickoutside'
17- import { className } from '.. /utils'
18- import { debounce } from ' lodash'
6+ } from " ./editable-select-types"
7+ import " ./editable-select.scss"
8+ import { Icon } from " ../../icon"
9+ import ClickOutside from " ../../shared/devui-directive/clickoutside"
10+ import { className } from ". /utils"
11+ import { debounce } from " lodash"
1912export default defineComponent ( {
20- name : ' DEditableSelect' ,
13+ name : " DEditableSelect" ,
2114 directives : { ClickOutside } ,
2215 props : editableSelectProps ,
23- emits : [ ' update:modelValue' ] ,
16+ emits : [ " update:modelValue" ] ,
2417 setup ( props : EditableSelectProps , ctx ) {
2518 const inputCls = className (
26- ' devui-form-control devui-dropdown-origin devui-dropdown-origin-open' ,
19+ " devui-form-control devui-dropdown-origin devui-dropdown-origin-open" ,
2720 {
2821 disabled : props . disabled ,
2922 }
3023 )
3124
3225 const getLiCls = ( item ) => {
3326 const { disabledKey } = props
34- return className ( ' devui-dropdown-item' , {
27+ return className ( " devui-dropdown-item" , {
3528 disabled : disabledKey ? ! ! item [ disabledKey ] : false ,
3629 } )
3730 }
3831
3932 const visible = ref ( false )
40- const inputValue = ref ( '' )
33+ const inputValue = ref ( "" )
4134 const query = ref ( props . modelValue )
4235
4336 const wait = computed ( ( ) => ( props . remote ? 300 : 0 ) )
4437
4538 const emptyText = computed ( ( ) => {
4639 const options = filteredOptions . value
4740 if ( ! props . remote && inputValue . value && options . length === 0 ) {
48- return ' 没有相关记录'
41+ return " 没有相关记录"
4942 }
5043 if ( options . length === 0 ) {
51- return ' 没有数据'
44+ return " 没有数据"
5245 }
5346 return null
5447 } )
5548 const normalizeOptions = computed ( ( ) => {
5649 let options : OptionItem
5750 const { disabledKey } = props
58- disabledKey ? disabledKey : ' disabled'
51+ disabledKey ? disabledKey : " disabled"
5952 return props . options . map ( ( item ) => {
60- if ( typeof item !== ' object' ) {
53+ if ( typeof item !== " object" ) {
6154 options = {
6255 name : item ,
6356 }
@@ -113,11 +106,11 @@ export default defineComponent({
113106 }
114107 const selectOptionClick = ( e , item ) => {
115108 const { disabledKey } = props
116- query . value = item . name
117- if ( item [ disabledKey ] ) {
109+ if ( disabledKey && item [ disabledKey ] ) {
118110 e . stopPropagation ( )
119111 } else {
120- ctx . emit ( 'update:modelValue' , item . name )
112+ query . value = item . name
113+ ctx . emit ( "update:modelValue" , item . name )
121114 }
122115 }
123116 return ( ) => {
@@ -144,7 +137,7 @@ export default defineComponent({
144137 < ul
145138 class = "devui-list-unstyled scroll-height"
146139 style = { {
147- maxHeight : props . maxHeight + 'px' ,
140+ maxHeight : props . maxHeight + "px" ,
148141 } }
149142 >
150143 { filteredOptions . value . map ( ( item ) => {
@@ -155,7 +148,7 @@ export default defineComponent({
155148 key = { item . name }
156149 >
157150 { ctx . slots . default
158- ? renderSlot ( ctx . slots , ' default' , { item } )
151+ ? renderSlot ( ctx . slots , " default" , { item } )
159152 : item . name }
160153 </ li >
161154 )
0 commit comments