yk-element-components-v2
Version:
2 lines (1 loc) • 4.06 kB
JavaScript
(function(c,u){typeof exports=="object"&&typeof module<"u"?module.exports=u():typeof define=="function"&&define.amd?define(u):(c=typeof globalThis<"u"?globalThis:c||self,c.index=u())})(this,function(){"use strict";const c="";function u(t,e,s,a,i,r,f,b){var l=typeof t=="function"?t.options:t;e&&(l.render=e,l.staticRenderFns=s,l._compiled=!0),a&&(l.functional=!0),r&&(l._scopeId="data-v-"+r);var n;if(f?(n=function(o){o=o||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext,!o&&typeof __VUE_SSR_CONTEXT__<"u"&&(o=__VUE_SSR_CONTEXT__),i&&i.call(this,o),o&&o._registeredComponents&&o._registeredComponents.add(f)},l._ssrRegister=n):i&&(n=b?function(){i.call(this,(l.functional?this.parent:this).$root.$options.shadowRoot)}:i),n)if(l.functional){l._injectStyles=n;var g=l.render;l.render=function(C,h){return n.call(h),g(C,h)}}else{var d=l.beforeCreate;l.beforeCreate=d?[].concat(d,n):[n]}return{exports:t,options:l}}const p={props:{remote:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},clearable:{type:Boolean,default:!0},labelKey:{type:String,default:""},valueKey:{type:String,default:""},placeholder:{type:String,default:"\u8BF7\u9009\u62E9"},size:{type:String,default:"small"},data:{type:Array,default:()=>[]},optionColumn:{type:Array,default:()=>[]},filterable:{type:Boolean,default:!0},value:{type:String,default:""}},data(){return{selectValue:"",showData:[],customValue:!1,selectInfo:{}}},watch:{data(t){this.showData=JSON.parse(JSON.stringify(t))},value(t){this.selectValue=t,t||this.setCustomValue()}},mounted(){this.showData=JSON.parse(JSON.stringify(this.data)),this.selectValue=this.value,this.setCustomValue(this.selectValue)},methods:{selected(){this.disabled||(this.$refs.custom_select.focus(),this.customValue=!1)},setOption(t){t?this.showData=JSON.parse(JSON.stringify(this.data)):this.setCustomValue(this.selectValue),this.$emit("visible-change",t)},clear(t){this.showData=JSON.parse(JSON.stringify(this.data)),this.setCustomValue(),this.selectValue="",this.$emit("input",""),this.$emit("clear",t)},blur(t){this.$emit("blur",t)},focus(t){this.$emit("focus",t)},setCustomValue(t){t?(this.data.forEach(e=>{t==e[this.valueKey?this.valueKey:"value"]&&(this.selectInfo=e)}),this.customValue=!0):(this.customValue=!1,this.selectInfo={})},selectChange(t){this.setCustomValue(t),this.$emit("input",t),this.$emit("change",t)},remoteMethod(t){if(this.remote){this.$emit("remoteMethod",t);return}let e=[];t?e=this.data.filter(s=>{let a=!1;return this.optionColumn.forEach(i=>{s[i.key].indexOf(t)!=-1&&(a=!0)}),a}):e=this.data,this.showData=JSON.parse(JSON.stringify(e))}}};var _=function(){var e=this,s=e._self._c;return s("div",{staticClass:"custom_select_box"},[e.customValue?s("div",{staticClass:"custom_value",class:{disabledBg:e.disabled},on:{click:e.selected}},[s("img",{attrs:{src:e.selectInfo.image}}),s("div",[e._v(e._s(e.labelKey?e.selectInfo[e.labelKey]:e.selectInfo.label))]),e.disabled?e._e():s("i",{staticClass:"el-icon-circle-close",on:{click:function(a){return a.stopPropagation(),e.clear.apply(null,arguments)}}})]):e._e(),s("el-select",{ref:"custom_select",attrs:{size:e.size,placeholder:e.placeholder,"popper-class":"custom_select",filterable:!0,disabled:e.disabled,clearable:e.clearable,remote:"","reserve-keyword":"","remote-method":e.remoteMethod},on:{"visible-change":e.setOption,clear:e.clear,blur:e.blur,focus:e.focus,change:e.selectChange},model:{value:e.selectValue,callback:function(a){e.selectValue=a},expression:"selectValue"}},e._l(e.showData,function(a,i){return s("el-option",{key:"f"+i,attrs:{label:e.labelKey?a[e.labelKey]:a.label,value:e.valueKey?a[e.valueKey]:a.value}},[s("div",{staticClass:"custom_select_option"},[s("img",{attrs:{src:a.image}}),s("div",{staticStyle:{"margin-left":"10px"}},e._l(e.optionColumn,function(r,f){return s("div",{key:"child"+f},[e._v(" "+e._s(r.name)+e._s(r.name?":":"")+" "+e._s(a[r.key])+" ")])}),0)])])}),1)],1)},m=[],y=u(p,_,m,!1,null,null,null,null);const v=y.exports;return{install(t){t.component("yk-custom-select",v)}}});