@beeapi/nutui
Version:
一套轻量级移动端Vue组件库
7 lines • 7.22 kB
JavaScript
/*!
* @beeapi/nutui v2.2.10 - checkboxgroup.js, 451ed2404bee284b891e, Sat Dec 19 2020 12:06:10 GMT+0800 (中国标准时间)
* (c) 2017-2020 JDC
* Released under the MIT License.
*/
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("checkboxgroup",[],t):"object"==typeof exports?exports.checkboxgroup=t():e.checkboxgroup=t()}("undefined"!=typeof self?self:this,(function(){return function(e){var t={};function n(i){if(t[i])return t[i].exports;var a=t[i]={i:i,l:!1,exports:{}};return e[i].call(a.exports,a,a.exports,n),a.l=!0,a.exports}return n.m=e,n.c=t,n.d=function(e,t,i){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var a in e)n.d(i,a,function(t){return e[t]}.bind(null,a));return i},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="./",n(n.s=175)}({0:function(e,t,n){"use strict";function i(e,t,n,i,a,o,u,s){var c,l="function"==typeof e?e.options:e;if(t&&(l.render=t,l.staticRenderFns=n,l._compiled=!0),i&&(l.functional=!0),o&&(l._scopeId="data-v-"+o),u?(c=function(e){(e=e||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(e=__VUE_SSR_CONTEXT__),a&&a.call(this,e),e&&e._registeredComponents&&e._registeredComponents.add(u)},l._ssrRegister=c):a&&(c=s?function(){a.call(this,(l.functional?this.parent:this).$root.$options.shadowRoot)}:a),c)if(l.functional){l._injectStyles=c;var r=l.render;l.render=function(e,t){return c.call(t),r(e,t)}}else{var f=l.beforeCreate;l.beforeCreate=f?[].concat(f,c):[c]}return{exports:e,options:l}}n.d(t,"a",(function(){return i}))},113:function(e,t,n){},175:function(e,t,n){"use strict";n.r(t);var i=n(8),a=n.n(i),o=n(3),u=n.n(o),s=n(50),c=(n(71),{name:"nut-checkboxgroup",props:{name:String,checkBoxData:{type:Array,required:!0},value:{type:Array,required:!0},keys:{type:Object,default:function(){return{id:"id",name:"name",class:"class",label:"label",value:"value",disabled:"disabled"}}},customClass:{type:String,default:""},label:{type:[String,Number,Boolean],default:""},size:{type:[String,Number],default:"base"},disabled:{type:Boolean,default:!1},animation:{type:Boolean,default:!0},vertical:{type:Boolean,default:!1}},data:function(){return{ignoreChange:!1,checkboxValues:[],initialValue:[]}},components:u()({},s.a.name,s.a),watch:{value:function(){this.init()}},mounted:function(){this.init()},methods:{init:function(){var e=this;this.initialValue=this.value,this.checkBoxData.map((function(t){"object"===a()(t)&&(t.checked=e.isOptionCheckedByDefault(t))}))},isObject:function(e){return null!==e&&"object"===a()(e)},looseIndexOf:function(e,t){for(var n=0;n<e.length;n++)if(this.looseEqual(e[n],t))return n;return-1},isOptionCheckedByDefault:function(e){return this.looseIndexOf(this.initialValue,e[this.keys.value]||e)>-1},looseEqual:function(e,t){return e==t||!(!this.isObject(e)||!this.isObject(t))&&JSON.stringify(e)===JSON.stringify(t)},changeEvt:function(e,t){if(!this.ignoreChange){var n=e[0],i=e[1],a=e[2],o=[],u=t[this.keys.value]||t,s=this.looseIndexOf(this.value,u);n&&s<0&&(o=this.value.concat(u)),!n&&s>-1&&(o=this.value.slice(0,s).concat(this.value.slice(s+1))),this.$emit("input",o),this.$emit("change",o,i,a)}},toggleAll:function(e){if(!1!==e){!0===e&&this.checkBoxData.map((function(e){e.checked=!0})),e||this.checkBoxData.map((function(e){e.checked=!e.checked}));var t=[],n=[];this.checkBoxData.filter((function(e){return e.checked&&(t.push(e.value),n.push(e.label)),e.checked}));this.$emit("input",t),this.$emit("change",t,n,null)}else this.$emit("input",[])}}}),l=n(0),r=Object(l.a)(c,(function(){var e=this,t=e.$createElement,n=e._self._c||t;return n("div",{class:["nut-checkboxgroup",{vertical:e.vertical},e.customClass]},e._l(e.checkBoxData,(function(t,i){return n("div",{key:t[e.keys.id],staticClass:"checkbox-item"},[n("nut-checkbox",{attrs:{name:e.name||t[e.keys.name],disabled:e.disabled||t[e.keys.disabled],label:t[e.keys.label],animation:e.animation,size:t.size?t.size:e.size,id:t[e.keys.id],checked:t.checked},on:{"update:checked":function(n){return e.$set(t,"checked",n)},change:function(n){return e.changeEvt(arguments,t)}},model:{value:e.checkboxValues[i],callback:function(t){e.$set(e.checkboxValues,i,t)},expression:"checkboxValues[index]"}},[e._v(e._s(t[e.keys.label]||t[e.keys.value]||t)+"\n ")])],1)})),0)}),[],!1,null,null,null).exports;n(113);r.install=function(e){e.component(r.name,r)};t.default=r},3:function(e,t){e.exports=function(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}},50:function(e,t,n){"use strict";var i=n(8),a=n.n(i),o={name:"nut-checkbox",props:{name:{type:String},size:{type:[String,Number,Boolean],default:"base"},label:{type:String,default:""},value:{required:!0},trueValue:{default:!0},falseValue:{default:!1},submittedValue:{type:String,default:"on"},checked:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},animation:{type:Boolean,default:!0}},watch:{value:function(){this.isChecked=this.looseEqual(this.value,this.trueValue)},checked:function(e,t){this.isChecked=e}},data:function(){return{isChecked:this.value==this.trueValue||this.checked}},mounted:function(){this.$emit("update:checked",this.isChecked?this.trueValue:this.falseValue,this.label),this.$emit("input",this.isChecked?this.trueValue:this.falseValue,this.label)},methods:{isObject:function(e){return null!==e&&"object"===a()(e)},looseEqual:function(e,t){return e==t||!(!this.isObject(e)||!this.isObject(t))&&JSON.stringify(e)===JSON.stringify(t)},changeEvt:function(e){var t=this.isChecked,n=e.target.checked;this.$emit("input",n?this.trueValue:this.falseValue,this.label,e),t!==n&&this.$emit("change",n?this.trueValue:this.falseValue,this.label,e)}}},u=n(0),s=Object(u.a)(o,(function(){var e=this,t=e.$createElement,n=e._self._c||t;return n("label",{class:["nut-checkbox","nut-checkbox-size-"+e.size]},[n("input",{class:{"nut-checkbox-ani":e.animation},attrs:{type:"checkbox",name:e.name,disabled:e.disabled},domProps:{checked:e.isChecked,value:e.submittedValue},on:{change:e.changeEvt}}),e._v(" "),e.label?n("span",{staticClass:"nut-checkbox-label"},[e._v("\n "+e._s(e.label)+"\n ")]):n("span",{staticClass:"nut-checkbox-label"},[e._t("default")],2)])}),[],!1,null,null,null);t.a=s.exports},71:function(e,t,n){},8:function(e,t){function n(t){return"function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?e.exports=n=function(e){return typeof e}:e.exports=n=function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},n(t)}e.exports=n}})}));
//# sourceMappingURL=checkboxgroup.js.map