UNPKG

jiku-ui

Version:

A Component Library for Vue.js.

2 lines (1 loc) 11.4 kB
module.exports=function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},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 r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)n.d(r,i,function(t){return e[t]}.bind(null,i));return r},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=74)}({0:function(e,t,n){"use strict";function r(e,t,n,r,i,s,a,o){var l,c="function"==typeof e?e.options:e;if(t&&(c.render=t,c.staticRenderFns=n,c._compiled=!0),r&&(c.functional=!0),s&&(c._scopeId="data-v-"+s),a?(l=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__),i&&i.call(this,e),e&&e._registeredComponents&&e._registeredComponents.add(a)},c._ssrRegister=l):i&&(l=o?function(){i.call(this,(c.functional?this.parent:this).$root.$options.shadowRoot)}:i),l)if(c.functional){c._injectStyles=l;var u=c.render;c.render=function(e,t){return l.call(t),u(e,t)}}else{var d=c.beforeCreate;c.beforeCreate=d?[].concat(d,l):[l]}return{exports:e,options:c}}n.d(t,"a",(function(){return r}))},35:function(e,t){e.exports=require("jiku-ui/lib/select")},36:function(e,t){e.exports=require("jiku-ui/lib/option")},43:function(e,t){e.exports=require("lodash/get")},58:function(e,t){e.exports=require("q")},59:function(e,t){e.exports=require("jiku-ui/lib/cascader")},60:function(e,t){e.exports=require("lodash/debounce")},74:function(e,t,n){"use strict";n.r(t);var r=function(){var e=this,t=e.$createElement;return(e._self._c||t)(e.componentId,{ref:"address",tag:"component",attrs:{"http-client":e.httpClient,"api-url-map":e.apiUrlMap,"response-props":e.responseProps,"response-path":e.responsePath,placeholder:e.placeholder,"address-i-ds":e.value,disabled:e.disabled,level:e.level,clearable:e.clearable},on:{change:e.change}})};r._withStripped=!0;var i=function(){var e=this.$createElement;return(this._self._c||e)("hn-cascader",{ref:"hnAddressCascader",staticClass:"hn-address-cascader",attrs:{value:this.addressIDs,props:this.props,options:this.districts,placeholder:this.placeholder,disabled:this.disabled,clearable:this.clearable},on:{change:this.change}})};i._withStripped=!0;var s=n(58),a=n(59),o=n.n(a);var l=n(43),c=n.n(l),u={props:{httpClient:{required:!0},apiUrlMap:{required:!0},responseProps:{required:!0},responsePath:{required:!0},addressIDs:{type:Array,default:function(){return[]}},level:{required:!0},disabled:{required:!0},clearable:{type:Boolean,default:!1}},computed:{addressHttpClient:function(){return this.httpClient||this.$axios||this.$fetch||window.fetch}},methods:{getAllProvince:function(){var e,t,n=this.apiUrlMap,r=this.responseProps,i=this.responsePath,s=this.level;return(e=this.addressHttpClient,t=n.province,e(t,{method:"get"})).then((function(e){return c()(e,i,e).map((function(e){return{label:e[r.provinceName],value:e[r.provinceID],leaf:1===s}}))})).catch((function(){return[]}))},getCities:function(e){var t=this.apiUrlMap,n=this.responseProps,r=this.responsePath,i=this.level;return function(e,t,n){return e(t+"?provinceID="+n,{method:"get"})}(this.addressHttpClient,t.city,e).then((function(e){return c()(e,r,e).map((function(e){return{label:e[n.cityName],value:e[n.cityID],leaf:2===i}}))})).catch((function(){return[]}))},getCounties:function(e){var t=this.apiUrlMap,n=this.responseProps,r=this.responsePath,i=this.level;return function(e,t,n){return e(t+"?cityID="+n,{method:"get"})}(this.addressHttpClient,t.county,e).then((function(e){return c()(e,r,e).map((function(e){return{label:e[n.countyName],value:e[n.countyID],leaf:3===i}}))})).catch((function(){return[]}))},getTowns:function(e){var t=this.apiUrlMap,n=this.responseProps,r=this.responsePath,i=this.level;return function(e,t,n){return e(t+"?countyID="+n,{method:"get"})}(this.addressHttpClient,t.town,e).then((function(e){return c()(e,r,e).map((function(e){return{label:e[n.townName],value:e[n.townID],leaf:4===i}}))})).catch((function(){return[]}))}}},d={name:"HnAddressCascader",components:{HnCascader:o.a},mixins:[u],props:{placeholder:{type:String,default:"请选择地区"}},data:function(){var e=this;return{props:{lazy:!0,lazyLoad:function(t,n){var r=t.level,i=t.value;if(t.children&&t.children.length)return n([]);if(0===r){if(e.addressIDs.length)return;e.getAllProvince().then((function(e){return n(e)}))}else 1===r?e.getCities(i).then((function(e){return n(e)})):2===r?e.getCounties(i).then((function(e){return n(e)})):e.getTowns(i).then((function(e){return n(e)}))}},districts:[]}},created:function(){this.addressIDs.length&&this.setDefaultValue(this.addressIDs)},methods:{setCities:function(e,t,n){var r=n.find((function(t){return t.value===e}));r&&(r.children=t)},setCounties:function(e,t,n){var r=n.find((function(t){return t.value===e}));r&&(r.children=t)},setTowns:function(e,t,n){var r=n.find((function(t){return t.value===e}));r&&(r.children=t)},change:function(e){if(e.length){var t=this.$refs.hnAddressCascader.$refs.panel.getNodeByValue(e).pathLabels;this.$emit("change",{provinceName:t[0],cityName:t[1],countyName:t[2],townName:t[3],provinceID:e[0],cityID:e[1],countyID:e[2],townID:e[3]})}else this.$emit("change",{provinceName:"",cityName:"",countyName:"",townName:"",provinceID:"",cityID:"",countyID:"",townID:""})},setDefaultValue:function(e){var t=this,n=this.level,r=e[0],i=e[1],a=e[2],o=[this.getAllProvince()];return r&&(o.push(this.getCities(r)),i&&n>2&&(o.push(this.getCounties(i)),a&&n>3&&o.push(this.getTowns(a)))),s.Promise.all(o).then((function(e){var n=e[0],s=void 0===n?[]:n,o=e[1],l=void 0===o?[]:o,c=e[2],u=void 0===c?[]:c,d=e[3],h=void 0===d?[]:d;t.setCities(r,l,s),t.setCounties(i,u,l),t.setTowns(a,h,u),t.districts=s})).catch((function(e){setTimeout((function(){throw e}))}))}}},h=n(0),p=Object(h.a)(d,i,[],!1,null,null,null);p.options.__file="packages/address/src/address-cascader.vue";var f=p.exports,v=function(){var e=this,t=e.$createElement,n=e._self._c||t;return n("div",{staticClass:"hn-address-select"},[n("hn-select",{staticClass:"hn-address-select--province",attrs:{placeholder:e.placeholder[0],"value-key":"value",disabled:e.disabled,clearable:e.clearable},model:{value:e.currentProvince,callback:function(t){e.currentProvince=t},expression:"currentProvince"}},e._l(e.provinces,(function(e){return n("hn-option",{key:e.value,attrs:{label:e.label,value:e}})})),1),e.level>1?n("hn-select",{staticClass:"hn-address-select--city",attrs:{placeholder:e.placeholder[1],"value-key":"value",disabled:e.disabled,clearable:e.clearable},model:{value:e.currentCity,callback:function(t){e.currentCity=t},expression:"currentCity"}},e._l(e.cities,(function(e){return n("hn-option",{key:e.value,attrs:{label:e.label,value:e}})})),1):e._e(),e.level>2?n("hn-select",{staticClass:"hn-address-select--county",attrs:{placeholder:e.placeholder[2],"value-key":"value",disabled:e.disabled,clearable:e.clearable},model:{value:e.currentCounty,callback:function(t){e.currentCounty=t},expression:"currentCounty"}},e._l(e.counties,(function(e){return n("hn-option",{key:e.value,attrs:{label:e.label,value:e}})})),1):e._e(),e.level>3?n("hn-select",{staticClass:"hn-address-select--town",attrs:{placeholder:e.placeholder[3],"value-key":"value",disabled:e.disabled,clearable:e.clearable},model:{value:e.currentTown,callback:function(t){e.currentTown=t},expression:"currentTown"}},e._l(e.towns,(function(e){return n("hn-option",{key:e.value,attrs:{label:e.label,value:e}})})),1):e._e()],1)};v._withStripped=!0;var y=n(60),b=n.n(y),m=n(35),C=n.n(m),g=n(36),w=n.n(g),D={name:"HnAddressSelect",components:{HnSelect:C.a,HnOption:w.a},mixins:[u],props:{placeholder:{type:Array,default:function(){return["请选择省","市","区/县","乡/镇/街道"]}}},data:function(){return{provinces:[],cities:[],counties:[],towns:[],currentProvince:null,currentCity:null,currentCounty:null,currentTown:null}},computed:{},watch:{currentProvince:function(e){this.cities=[],e&&this.setCities(e.value,!!e.label),e&&!e.label||(this.currentCity=null,this.change())},currentCity:function(e){this.counties=[],e&&this.setCounties(e.value,!!e.label),e&&!e.label||(this.currentCounty=null,this.change())},currentCounty:function(e){this.towns=[],e&&this.setTowns(e.value),e&&!e.label||(this.currentTown=null,this.change())},currentTown:function(e){e&&!e.label||this.change()}},created:function(){this.setProvinces(),this.addressIDs.length&&this.setDefaultValue(this.addressIDs)},mounted:function(){},methods:{setProvinces:function(){var e=this;this.getAllProvince().then((function(t){e.provinces=t}))},setCities:function(e,t){var n=this;this.getCities(e).then((function(e){n.cities=e,t&&(n.counties=[])}))},setCounties:function(e,t){var n=this;this.level<=2||this.getCounties(e).then((function(e){n.counties=e,t&&(n.towns=[])})).catch((function(){t&&(n.towns=[])}))},setTowns:function(e){var t=this;this.level<=3||this.getTowns(e).then((function(e){t.towns=e}))},change:b()((function(){var e=this.currentProvince,t=this.currentCity,n=this.currentCounty,r=this.currentTown;this.$emit("change",{provinceName:e.label,cityName:t&&t.label,countyName:n&&n.label,townName:r&&r.label,provinceID:e.value,cityID:t&&t.value,countyID:n&&n.value,townID:r&&r.value})}),500),setDefaultValue:function(e){var t=e[0],n=e[1],r=e[2],i=e[3];t&&(this.currentProvince={value:t}),n&&(this.currentCity={value:n}),r&&(this.currentCounty={value:r}),i&&(this.currentTown={value:i})}}},_=Object(h.a)(D,v,[],!1,null,null,null);_.options.__file="packages/address/src/address-select.vue";var I={name:"HnAddress",components:{HnAddressCascader:f,HnAddressSelect:_.exports},props:{value:{type:Array,default:function(){return[]}},httpClient:Function,apiUrlMap:{type:Object,default:function(){var e="https://openapi.qipeipu.com/bs/region/find";return{province:e+"/allProvince",city:e+"/findCityByProvinceID",county:e+"/findCountyByCityID",town:e+"/findTownByCountyID"}}},responseProps:{type:Object,default:function(){return{provinceID:"provinceID",provinceName:"provinceName",cityID:"cityID",cityName:"cityName",countyID:"countyID",countyName:"countyName",townID:"townID",townName:"townName"}}},responsePath:{type:String,default:"data.model"},level:{type:Number,default:4},disabled:{type:Boolean,default:!1},placeholder:[String,Array],clearable:{type:Boolean,default:!1},isCascade:{type:Boolean,default:!0}},computed:{componentId:function(){return this.isCascade?"HnAddressCascader":"HnAddressSelect"}},methods:{change:function(e){this.$emit("change",e),e.provinceID?this.$emit("input",[e.provinceID,e.cityID,e.countyID,e.townID].slice(0,this.level)):this.$emit("input",[])},setDefaultValue:function(e){return this.$refs.address.setDefaultValue(e)}}},P=Object(h.a)(I,r,[],!1,null,null,null);P.options.__file="packages/address/src/main.vue";var N=P.exports;N.install=function(e){e.component(N.name,N)};t.default=N}}).default;