Commit 7877b9a1 by 无尘

feat: 增加好办后台地区(省市县)选择

parent 305ce58b
{
"presets": [
["env", { "modules": false }],
"stage-3"
]
}
root = true
[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
.DS_Store
node_modules/
npm-debug.log
yarn-error.log
# Editor directories and files
.idea
*.suo
*.ntvs*
*.njsproj
*.sln
\ No newline at end of file
# 好办后台地区(省市县)选择
>>> HEAD
> A Vue.js area select Plugin
## Install
```shell
npm install @gic-test/vue-office-area -S
```
## how to use
```
// main.js
import vueOfficeArea from '@gic-test/vue-office-area'
Vue.use(vueOfficeArea)
// 使用页面
<vue-office-area :projectName="projectName" :postUrl="postUrl" :areaOptions="areaOptions" @selected="selected"></vue-office-area>
data() {
return {
// 可传参数
projectName: '', // 当前项目名
postUrl: '', // 自定义请求的 url,如: '/api-admin/dict-district-list'
// 省市县参数
areaOptions: {
provinceName: '',
provinceId: '',
cityName: '',
cityId: '',
countryName: '',
countyId: ''
},
}
}
methods: {
selected(val) {
console.log(val+"/////")
}
},
```
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("vue-office-area",[],t):"object"==typeof exports?exports["vue-office-area"]=t():e["vue-office-area"]=t()}("undefined"!=typeof self?self:this,function(){return function(e){function t(o){if(r[o])return r[o].exports;var n=r[o]={i:o,l:!1,exports:{}};return e[o].call(n.exports,n,n.exports,t),n.l=!0,n.exports}var r={};return t.m=e,t.c=r,t.d=function(e,r,o){t.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:o})},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="/dist/",t(t.s=3)}([function(e,t,r){"use strict";var o=r(11),n=r.n(o);t.a={name:"vue-area-ab",props:{areaOptions:{type:Object},projectName:{type:String,default:""},postUrl:{type:String}},data:function(){return{repProjectName:"gic-web",ruleForm:{provience:"",provinceName:"",city:"",cityName:"",countryName:"",country:"",areaId:""},optionsPro:[],optionsCity:[],optionsRegion:[],provinceId:"",cityId:"",countyId:"",typeId:1,getProId:"",getCityId:"",loginInnfo:{loginName:"damogic",password:1},baseUrl:"",requstUrl:""}},beforeMount:function(){var e=this,t=window.location.origin;console.log("当前host:",t),"-1"!=t.indexOf("localhost")?e.baseUrl="http://gicdev.demogic.com":e.baseUrl=t},methods:{handleChange:function(e){console.log(e),this.$emit("selected",e)},getPro:function(){var e=this;e.optionsPro.length||(e.typeId=1,e.getArea(0))},getCity:function(e){var t=this;if(t.typeId=2,!t.getProId)return void t.$message.error({duration:1e3,message:"请先选择省"});t.getArea(t.getProId)},getCountry:function(){var e=this;if(e.typeId=3,""==e.getCityId)return void e.$message.error({duration:1e3,message:"请先选择省市"});e.getArea(e.getCityId)},selectPro:function(e){var t=this;t.getProId=e,t.getCityId="",t.ruleForm.city="",t.ruleForm.country="",t.optionsPro.forEach(function(r,o){e==r.provinceId&&(t.ruleForm.provinceName=r.provinceName)}),t.$emit("selected",t.ruleForm)},selectCity:function(e){var t=this;t.getCityId=e,t.ruleForm.country="",t.optionsCity.forEach(function(r,o){e==r.cityId&&(t.ruleForm.cityName=r.cityName)}),t.$emit("selected",t.ruleForm)},selectCountry:function(e){var t=this;t.areaId=e,t.ruleForm.areaId=e,t.optionsRegion.forEach(function(r,o){e==r.countyId&&(t.ruleForm.countryName=r.countyName)}),t.$emit("selected",t.ruleForm)},getArea:function(e){var t=this;console.log(e);var r={requestProject:t.repProjectName};0==e&&(r.type=t.typeId),0!=e&&(r.type=t.typeId,r.id=e),t.optionsCity=[],t.optionsRegion=[],t.axios.post(t.baseUrl+requstUrl,n.a.stringify(r)).then(function(e){console.log(e,e.data,e.data.errorCode);var r="";if(r=e.data,0==r.errorCode){if(1==t.typeId){t.optionsPro=[];for(var o in r.result)t.optionsPro.push(r.result[o]);console.log("省:",t.optionsPro)}if(2==t.typeId)for(var o in r.result)delete r.result[o].provinceId,t.optionsCity.push(r.result[o]);if(3==t.typeId)for(var o in r.result)delete r.result[o].provinceId,delete r.result[o].cityId,t.optionsRegion.push(r.result[o]);return!1}t.$message.error({duration:1e3,message:e.data.errorMessage})}).catch(function(e){console.log(e),t.$message.error({duration:1e3,message:res.data.errorMessage})})},toLogin:function(){var e=this;e.axios.post(e.baseUrl+"/api-auth/doLogin",n.a.stringify(e.loginInnfo)).then(function(t){console.log(t),0==t.data.errorCode&&e.getArea()}).catch(function(t){console.log(t),e.$message.error({duration:1e3,message:t.errorMessage})})},setNewData:function(e){var t=this;t.ruleForm.provience=e.provinceName,t.ruleForm.city=e.cityName,t.ruleForm.country=e.countryName,t.ruleForm.provinceName=e.provinceName,t.ruleForm.cityName=e.cityName,t.ruleForm.countryName=e.countryName,t.ruleForm.areaId=e.countyId,t.getProId=e.provinceId,t.getCityId=e.cityId,console.log("that.ruleForm:",t.ruleForm)}},watch:{areaOptions:function(e,t){this.setNewData(e)},projectName:function(e,t){this.repProjectName=e||"gic-web"},postUrl:function(e,t){this.requstUrl=e}},mounted:function(){console.log("传递的参数对象:",this.areaOptions);var e=this;e.repProjectName=e.projectName||"gic-web",e.requstUrl=e.postUrl,e.setNewData(e.areaOptions)}}},function(e,t,r){"use strict";var o=Object.prototype.hasOwnProperty,n=function(){for(var e=[],t=0;t<256;++t)e.push("%"+((t<16?"0":"")+t.toString(16)).toUpperCase());return e}();t.arrayToObject=function(e,t){for(var r=t&&t.plainObjects?Object.create(null):{},o=0;o<e.length;++o)void 0!==e[o]&&(r[o]=e[o]);return r},t.merge=function(e,r,n){if(!r)return e;if("object"!=typeof r){if(Array.isArray(e))e.push(r);else{if("object"!=typeof e)return[e,r];(n.plainObjects||n.allowPrototypes||!o.call(Object.prototype,r))&&(e[r]=!0)}return e}if("object"!=typeof e)return[e].concat(r);var i=e;return Array.isArray(e)&&!Array.isArray(r)&&(i=t.arrayToObject(e,n)),Array.isArray(e)&&Array.isArray(r)?(r.forEach(function(r,i){o.call(e,i)?e[i]&&"object"==typeof e[i]?e[i]=t.merge(e[i],r,n):e.push(r):e[i]=r}),e):Object.keys(r).reduce(function(e,o){var i=r[o];return Object.prototype.hasOwnProperty.call(e,o)?e[o]=t.merge(e[o],i,n):e[o]=i,e},i)},t.decode=function(e){try{return decodeURIComponent(e.replace(/\+/g," "))}catch(t){return e}},t.encode=function(e){if(0===e.length)return e;for(var t="string"==typeof e?e:String(e),r="",o=0;o<t.length;++o){var i=t.charCodeAt(o);45===i||46===i||95===i||126===i||i>=48&&i<=57||i>=65&&i<=90||i>=97&&i<=122?r+=t.charAt(o):i<128?r+=n[i]:i<2048?r+=n[192|i>>6]+n[128|63&i]:i<55296||i>=57344?r+=n[224|i>>12]+n[128|i>>6&63]+n[128|63&i]:(o+=1,i=65536+((1023&i)<<10|1023&t.charCodeAt(o)),r+=n[240|i>>18]+n[128|i>>12&63]+n[128|i>>6&63]+n[128|63&i])}return r},t.compact=function(e,r){if("object"!=typeof e||null===e)return e;var o=r||[],n=o.indexOf(e);if(-1!==n)return o[n];if(o.push(e),Array.isArray(e)){for(var i=[],a=0;a<e.length;++a)e[a]&&"object"==typeof e[a]?i.push(t.compact(e[a],o)):void 0!==e[a]&&i.push(e[a]);return i}return Object.keys(e).forEach(function(r){e[r]=t.compact(e[r],o)}),e},t.isRegExp=function(e){return"[object RegExp]"===Object.prototype.toString.call(e)},t.isBuffer=function(e){return null!==e&&void 0!==e&&!!(e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer(e))}},function(e,t,r){"use strict";var o=String.prototype.replace,n=/%20/g;e.exports={default:"RFC3986",formatters:{RFC1738:function(e){return o.call(e,n,"+")},RFC3986:function(e){return e}},RFC1738:"RFC1738",RFC3986:"RFC3986"}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var o=r(4),n={install:function(e,t){e.component(o.a.name,o.a)}};"undefined"!=typeof window&&window.Vue&&window.Vue.use(n),t.default=n},function(e,t,r){"use strict";function o(e){r(5)}var n=r(0),i=r(14),a=r(10),s=o,c=a(n.a,i.a,!1,s,null,null);t.a=c.exports},function(e,t,r){var o=r(6);"string"==typeof o&&(o=[[e.i,o,""]]),o.locals&&(e.exports=o.locals);r(8)("5e767a08",o,!0,{})},function(e,t,r){t=e.exports=r(7)(!1),t.push([e.i,".area-wrapper,.gray-wrapper{position:relative}.area-wrapper{bottom:0;height:40px}.w-160{width:160px}.w-160+.w-160{margin-left:3px}",""])},function(e,t){function r(e,t){var r=e[1]||"",n=e[3];if(!n)return r;if(t&&"function"==typeof btoa){var i=o(n);return[r].concat(n.sources.map(function(e){return"/*# sourceURL="+n.sourceRoot+e+" */"})).concat([i]).join("\n")}return[r].join("\n")}function o(e){return"/*# sourceMappingURL=data:application/json;charset=utf-8;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(e))))+" */"}e.exports=function(e){var t=[];return t.toString=function(){return this.map(function(t){var o=r(t,e);return t[2]?"@media "+t[2]+"{"+o+"}":o}).join("")},t.i=function(e,r){"string"==typeof e&&(e=[[null,e,""]]);for(var o={},n=0;n<this.length;n++){var i=this[n][0];"number"==typeof i&&(o[i]=!0)}for(n=0;n<e.length;n++){var a=e[n];"number"==typeof a[0]&&o[a[0]]||(r&&!a[2]?a[2]=r:r&&(a[2]="("+a[2]+") and ("+r+")"),t.push(a))}},t}},function(e,t,r){function o(e){for(var t=0;t<e.length;t++){var r=e[t],o=u[r.id];if(o){o.refs++;for(var n=0;n<o.parts.length;n++)o.parts[n](r.parts[n]);for(;n<r.parts.length;n++)o.parts.push(i(r.parts[n]));o.parts.length>r.parts.length&&(o.parts.length=r.parts.length)}else{for(var a=[],n=0;n<r.parts.length;n++)a.push(i(r.parts[n]));u[r.id]={id:r.id,refs:1,parts:a}}}}function n(){var e=document.createElement("style");return e.type="text/css",p.appendChild(e),e}function i(e){var t,r,o=document.querySelector("style["+g+'~="'+e.id+'"]');if(o){if(y)return m;o.parentNode.removeChild(o)}if(h){var i=d++;o=f||(f=n()),t=a.bind(null,o,i,!1),r=a.bind(null,o,i,!0)}else o=n(),t=s.bind(null,o),r=function(){o.parentNode.removeChild(o)};return t(e),function(o){if(o){if(o.css===e.css&&o.media===e.media&&o.sourceMap===e.sourceMap)return;t(e=o)}else r()}}function a(e,t,r,o){var n=r?"":o.css;if(e.styleSheet)e.styleSheet.cssText=b(t,n);else{var i=document.createTextNode(n),a=e.childNodes;a[t]&&e.removeChild(a[t]),a.length?e.insertBefore(i,a[t]):e.appendChild(i)}}function s(e,t){var r=t.css,o=t.media,n=t.sourceMap;if(o&&e.setAttribute("media",o),v.ssrId&&e.setAttribute(g,t.id),n&&(r+="\n/*# sourceURL="+n.sources[0]+" */",r+="\n/*# sourceMappingURL=data:application/json;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(n))))+" */"),e.styleSheet)e.styleSheet.cssText=r;else{for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(document.createTextNode(r))}}var c="undefined"!=typeof document;if("undefined"!=typeof DEBUG&&DEBUG&&!c)throw new Error("vue-style-loader cannot be used in a non-browser environment. Use { target: 'node' } in your Webpack config to indicate a server-rendering environment.");var l=r(9),u={},p=c&&(document.head||document.getElementsByTagName("head")[0]),f=null,d=0,y=!1,m=function(){},v=null,g="data-vue-ssr-id",h="undefined"!=typeof navigator&&/msie [6-9]\b/.test(navigator.userAgent.toLowerCase());e.exports=function(e,t,r,n){y=r,v=n||{};var i=l(e,t);return o(i),function(t){for(var r=[],n=0;n<i.length;n++){var a=i[n],s=u[a.id];s.refs--,r.push(s)}t?(i=l(e,t),o(i)):i=[];for(var n=0;n<r.length;n++){var s=r[n];if(0===s.refs){for(var c=0;c<s.parts.length;c++)s.parts[c]();delete u[s.id]}}}};var b=function(){var e=[];return function(t,r){return e[t]=r,e.filter(Boolean).join("\n")}}()},function(e,t){e.exports=function(e,t){for(var r=[],o={},n=0;n<t.length;n++){var i=t[n],a=i[0],s=i[1],c=i[2],l=i[3],u={id:e+":"+n,css:s,media:c,sourceMap:l};o[a]?o[a].parts.push(u):r.push(o[a]={id:a,parts:[u]})}return r}},function(e,t){e.exports=function(e,t,r,o,n,i){var a,s=e=e||{},c=typeof e.default;"object"!==c&&"function"!==c||(a=e,s=e.default);var l="function"==typeof s?s.options:s;t&&(l.render=t.render,l.staticRenderFns=t.staticRenderFns,l._compiled=!0),r&&(l.functional=!0),n&&(l._scopeId=n);var u;if(i?(u=function(e){e=e||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext,e||"undefined"==typeof __VUE_SSR_CONTEXT__||(e=__VUE_SSR_CONTEXT__),o&&o.call(this,e),e&&e._registeredComponents&&e._registeredComponents.add(i)},l._ssrRegister=u):o&&(u=o),u){var p=l.functional,f=p?l.render:l.beforeCreate;p?(l._injectStyles=u,l.render=function(e,t){return u.call(t),f(e,t)}):l.beforeCreate=f?[].concat(f,u):[u]}return{esModule:a,exports:s,options:l}}},function(e,t,r){"use strict";var o=r(12),n=r(13),i=r(2);e.exports={formats:i,parse:n,stringify:o}},function(e,t,r){"use strict";var o=r(1),n=r(2),i={brackets:function(e){return e+"[]"},indices:function(e,t){return e+"["+t+"]"},repeat:function(e){return e}},a=Date.prototype.toISOString,s={delimiter:"&",encode:!0,encoder:o.encode,serializeDate:function(e){return a.call(e)},skipNulls:!1,strictNullHandling:!1},c=function e(t,r,n,i,a,s,c,l,u,p,f){var d=t;if("function"==typeof c)d=c(r,d);else if(d instanceof Date)d=p(d);else if(null===d){if(i)return s?s(r):r;d=""}if("string"==typeof d||"number"==typeof d||"boolean"==typeof d||o.isBuffer(d))return s?[f(s(r))+"="+f(s(d))]:[f(r)+"="+f(String(d))];var y=[];if(void 0===d)return y;var m;if(Array.isArray(c))m=c;else{var v=Object.keys(d);m=l?v.sort(l):v}for(var g=0;g<m.length;++g){var h=m[g];a&&null===d[h]||(y=Array.isArray(d)?y.concat(e(d[h],n(r,h),n,i,a,s,c,l,u,p,f)):y.concat(e(d[h],r+(u?"."+h:"["+h+"]"),n,i,a,s,c,l,u,p,f)))}return y};e.exports=function(e,t){var r=e,o=t||{};if(null!==o.encoder&&void 0!==o.encoder&&"function"!=typeof o.encoder)throw new TypeError("Encoder has to be a function.");var a=void 0===o.delimiter?s.delimiter:o.delimiter,l="boolean"==typeof o.strictNullHandling?o.strictNullHandling:s.strictNullHandling,u="boolean"==typeof o.skipNulls?o.skipNulls:s.skipNulls,p="boolean"==typeof o.encode?o.encode:s.encode,f=p?"function"==typeof o.encoder?o.encoder:s.encoder:null,d="function"==typeof o.sort?o.sort:null,y=void 0!==o.allowDots&&o.allowDots,m="function"==typeof o.serializeDate?o.serializeDate:s.serializeDate;if(void 0===o.format)o.format=n.default;else if(!Object.prototype.hasOwnProperty.call(n.formatters,o.format))throw new TypeError("Unknown format option provided.");var v,g,h=n.formatters[o.format];"function"==typeof o.filter?(g=o.filter,r=g("",r)):Array.isArray(o.filter)&&(g=o.filter,v=g);var b=[];if("object"!=typeof r||null===r)return"";var j;j=o.arrayFormat in i?o.arrayFormat:"indices"in o?o.indices?"indices":"repeat":"indices";var C=i[j];v||(v=Object.keys(r)),d&&v.sort(d);for(var w=0;w<v.length;++w){var N=v[w];u&&null===r[N]||(b=b.concat(c(r[N],N,C,l,u,f,g,d,y,m,h)))}return b.join(a)}},function(e,t,r){"use strict";var o=r(1),n=Object.prototype.hasOwnProperty,i={allowDots:!1,allowPrototypes:!1,arrayLimit:20,decoder:o.decode,delimiter:"&",depth:5,parameterLimit:1e3,plainObjects:!1,strictNullHandling:!1},a=function(e,t){for(var r={},o=e.split(t.delimiter,t.parameterLimit===1/0?void 0:t.parameterLimit),i=0;i<o.length;++i){var a,s,c=o[i],l=-1===c.indexOf("]=")?c.indexOf("="):c.indexOf("]=")+1;-1===l?(a=t.decoder(c),s=t.strictNullHandling?null:""):(a=t.decoder(c.slice(0,l)),s=t.decoder(c.slice(l+1))),n.call(r,a)?r[a]=[].concat(r[a]).concat(s):r[a]=s}return r},s=function(e,t,r){if(!e.length)return t;var o,n=e.shift();if("[]"===n)o=[],o=o.concat(s(e,t,r));else{o=r.plainObjects?Object.create(null):{};var i="["===n.charAt(0)&&"]"===n.charAt(n.length-1)?n.slice(1,-1):n,a=parseInt(i,10);!isNaN(a)&&n!==i&&String(a)===i&&a>=0&&r.parseArrays&&a<=r.arrayLimit?(o=[],o[a]=s(e,t,r)):o[i]=s(e,t,r)}return o},c=function(e,t,r){if(e){var o=r.allowDots?e.replace(/\.([^.[]+)/g,"[$1]"):e,i=/(\[[^[\]]*])/,a=/(\[[^[\]]*])/g,c=i.exec(o),l=c?o.slice(0,c.index):o,u=[];if(l){if(!r.plainObjects&&n.call(Object.prototype,l)&&!r.allowPrototypes)return;u.push(l)}for(var p=0;null!==(c=a.exec(o))&&p<r.depth;){if(p+=1,!r.plainObjects&&n.call(Object.prototype,c[1].slice(1,-1))&&!r.allowPrototypes)return;u.push(c[1])}return c&&u.push("["+o.slice(c.index)+"]"),s(u,t,r)}};e.exports=function(e,t){var r=t||{};if(null!==r.decoder&&void 0!==r.decoder&&"function"!=typeof r.decoder)throw new TypeError("Decoder has to be a function.");if(r.delimiter="string"==typeof r.delimiter||o.isRegExp(r.delimiter)?r.delimiter:i.delimiter,r.depth="number"==typeof r.depth?r.depth:i.depth,r.arrayLimit="number"==typeof r.arrayLimit?r.arrayLimit:i.arrayLimit,r.parseArrays=!1!==r.parseArrays,r.decoder="function"==typeof r.decoder?r.decoder:i.decoder,r.allowDots="boolean"==typeof r.allowDots?r.allowDots:i.allowDots,r.plainObjects="boolean"==typeof r.plainObjects?r.plainObjects:i.plainObjects,r.allowPrototypes="boolean"==typeof r.allowPrototypes?r.allowPrototypes:i.allowPrototypes,r.parameterLimit="number"==typeof r.parameterLimit?r.parameterLimit:i.parameterLimit,r.strictNullHandling="boolean"==typeof r.strictNullHandling?r.strictNullHandling:i.strictNullHandling,""===e||null===e||void 0===e)return r.plainObjects?Object.create(null):{};for(var n="string"==typeof e?a(e,r):e,s=r.plainObjects?Object.create(null):{},l=Object.keys(n),u=0;u<l.length;++u){var p=l[u],f=c(p,n[p],r);s=o.merge(s,f,r)}return o.compact(s)}},function(e,t,r){"use strict";var o=function(){var e=this,t=e.$createElement,r=e._self._c||t;return r("div",{staticClass:"area-box"},[r("div",{staticClass:"area-wrapper"},[r("div",{staticClass:"area-container"},[r("div",{staticClass:"area-wrap"},[r("el-select",{staticClass:"w-160",attrs:{"no-data-text":" ",placeholder:"请选择省份"},on:{focus:e.getPro,change:e.selectPro},model:{value:e.ruleForm.provience,callback:function(t){e.$set(e.ruleForm,"provience",t)},expression:"ruleForm.provience"}},e._l(e.optionsPro,function(e){return r("el-option",{key:e.provinceId,attrs:{label:e.provinceName,value:e.provinceId}})})),e._v(" "),r("el-select",{staticClass:"w-160",attrs:{"no-data-text":" ",placeholder:"请选择城市"},on:{focus:e.getCity,change:e.selectCity},model:{value:e.ruleForm.city,callback:function(t){e.$set(e.ruleForm,"city",t)},expression:"ruleForm.city"}},e._l(e.optionsCity,function(e){return r("el-option",{key:e.cityId,attrs:{label:e.cityName,value:e.cityId}})})),e._v(" "),r("el-select",{staticClass:"w-160",attrs:{"no-data-text":" ",placeholder:"请选择区县"},on:{focus:e.getCountry,change:e.selectCountry},model:{value:e.ruleForm.country,callback:function(t){e.$set(e.ruleForm,"country",t)},expression:"ruleForm.country"}},e._l(e.optionsRegion,function(e){return r("el-option",{key:e.countyId,attrs:{label:e.countyName,value:e.countyId}})}))],1)])])])},n=[],i={render:o,staticRenderFns:n};t.a=i}])});
//# sourceMappingURL=vue-office-area.js.map
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<title>vue-office-area</title>
</head>
<body>
<div id="app"></div>
<!-- <script src="/dist/build.js"></script> -->
<script src="/dist/vue-office-area.js"></script>
</body>
</html>
{
"name": "@gic-test/vue-office-area",
"description": "vue-office-area Plugin",
"version": "1.0.2",
"license": "MIT",
"private": false,
"main": "dist/vue-office-area.js",
"scripts": {
"dev": "cross-env NODE_ENV=development webpack-dev-server --open --hot",
"build": "cross-env NODE_ENV=production webpack --progress --hide-modules"
},
"dependencies": {
"axios": "^0.18.0",
"vue": "^2.5.11"
},
"browserslist": [
"> 1%",
"last 2 versions",
"not ie <= 8"
],
"devDependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-preset-env": "^1.6.0",
"babel-preset-stage-3": "^6.24.1",
"cross-env": "^5.0.5",
"css-loader": "^0.28.7",
"file-loader": "^1.1.4",
"node-sass": "^4.5.3",
"sass-loader": "^6.0.6",
"vue-loader": "^13.0.5",
"vue-template-compiler": "^2.4.4",
"webpack": "^3.6.0",
"webpack-dev-server": "^2.9.1"
}
}
<template>
<div id="app">
<vue-office-area :projectName="projectName" :postUrl="postUrl" :areaOptions="areaOptions" @selected="selected"></vue-office-area>
</div>
</template>
<script>
import vueOfficeArea from './lib/vue-office-area'
export default {
name: 'app',
data () {
return {
projectName: '', // 当前项目名
postUrl: '', // url
areaOptions: {
provinceName: '',
provinceId: '',
cityName: '',
cityId: '',
countryName: '',
countyId: ''
},
}
},
components: {
vueOfficeArea
},
methods: {
selected(val) {
// 模拟检查数据
console.log(val)
}
}
}
</script>
<style lang="scss">
* {
margin: 0;
padding: 0;
}
</style>
import axios from 'axios';
import qs from 'qs';
axios.defaults.timeout = 10000;
let base = "http://192.168.1.164:8282/gic/";
const timeout = 10000;
let token = ''//sessionStorage.getItem('user');
/*
*
* 统一 get 请求方法
* @url: 请求的 url
* @params: 请求带的参数
* @header: 带 token
*
*/
export const getRequest = (url, params) => {
return axios({
method: 'get',
url: `${base}${url}`,
data: {},
params: params,
headers: {'content-type': 'application/x-www-form-urlencoded'},// "token": token
});
}
import vueOfficeArea from './vue-office-area.vue' // 导入组件
const OfficeArea = {
install(Vue, options) {
Vue.component(vueOfficeArea.name, vueOfficeArea) // vueOfficeArea.name 组件的name属性
// 类似通过 this.$xxx 方式调用插件的 其实只是挂载到原型上而已
// Vue.prototype.$xxx // 最终可以在任何地方通过 this.$xxx 调用
// 虽然没有明确规定用$开头 但是大家都默认遵守这个规定
}
}
if (typeof window !== 'undefined' && window.Vue) {
window.Vue.use(OfficeArea);
}
export default OfficeArea
// export {
// vueOfficeArea
// }
<template>
<div class="area-box">
<div class="area-wrapper">
<div class="area-container" >
<div class="area-wrap">
<el-select class="w-160" no-data-text=" " v-model="ruleForm.provience" placeholder="请选择省份" @focus="getPro" @change="selectPro">
<el-option
v-for="item in optionsPro"
:key="item.provinceId"
:label="item.provinceName"
:value="item.provinceId">
</el-option>
</el-select>
<el-select class="w-160" no-data-text=" " v-model="ruleForm.city" placeholder="请选择城市" @focus="getCity" @change="selectCity">
<el-option
v-for="item in optionsCity"
:key="item.cityId"
:label="item.cityName"
:value="item.cityId">
</el-option>
</el-select>
<el-select class="w-160" no-data-text=" " v-model="ruleForm.country" placeholder="请选择区县" @focus="getCountry" @change="selectCountry">
<el-option
v-for="item in optionsRegion"
:key="item.countyId"
:label="item.countyName"
:value="item.countyId">
</el-option>
</el-select>
</div>
</div>
</div>
</div>
</template>
<script>
// import { getRequest } from './api';
import qs from 'qs';
export default {
name: 'vue-area-ab',
props: {
areaOptions: {
type: Object
},
projectName: {
type: String,
default: ''
},
postUrl: {
type: String,
}
},
data () {
return {
repProjectName: 'gic-web', // 项目名
// 省市区
ruleForm: {
provience: '',
provinceName: '',
city: '',
cityName: '',
countryName: '',
country: '',
areaId: ''// 选择的区 id
},
// 省
optionsPro: [
],
// 市
optionsCity: [
],
// 区/县
optionsRegion: [
],
provinceId: '',
cityId: '',
countyId: '',
// 区域
typeId: 1, // 1:省 2:市 3:区(县)
getProId: '', // 选择的省 id
getCityId: '',// 选择的城市 id
// 登录信息
loginInnfo: {
loginName: 'damogic',
password: 1
},
// 获取 location origin
baseUrl: '',
requstUrl: '',
}
},
beforeMount() {
const that = this
var host = window.location.origin;
console.log("当前host:",host)
if (host.indexOf('localhost') != '-1') {
that.baseUrl = 'http://gicdev.demogic.com';
}else {
that.baseUrl = host
}
},
methods: {
handleChange(value) {
console.log(value);
//选择完毕后将值传递给父组件
this.$emit('selected', value)
},
// 点击省
getPro: function() {
const that = this
if (that.optionsPro.length) {
return;
}
that.typeId = 1
that.getArea(0)
},
// 点击市
getCity: function(e) {
const that = this
that.typeId = 2
if (!that.getProId) {
that.$message.error({
duration: 1000,
message: '请先选择省'
})
return;
}
that.getArea(that.getProId)
},
// 点击县区
getCountry: function() {
const that = this
that.typeId = 3
if (that.getCityId == '') {
// showMsg.showmsg('请先选择省市','warning')
that.$message.error({
duration: 1000,
message: '请先选择省市'
})
return;
}
that.getArea(that.getCityId)
},
// 选择省
selectPro: function(e) {
const that = this
that.getProId = e;
that.getCityId = ''
that.ruleForm.city = ''
that.ruleForm.country = ''
that.optionsPro.forEach(function(item,index){
if (e == item.provinceId) {
that.ruleForm.provinceName = item.provinceName
}
})
that.$emit('selected', that.ruleForm)
},
// 选择市
selectCity: function(e) {
const that = this
that.getCityId = e;
that.ruleForm.country = ''
that.optionsCity.forEach(function(item,index){
if (e == item.cityId) {
that.ruleForm.cityName = item.cityName
}
})
that.$emit('selected', that.ruleForm)
},
// 选择县区
selectCountry: function(e) {
const that = this
that.areaId = e
that.ruleForm.areaId = e
that.optionsRegion.forEach(function(item,index){
if (e == item.countyId) {
that.ruleForm.countryName = item.countyName
}
})
that.$emit('selected', that.ruleForm)
},
// 获取区域
getArea: function(areaId) {
const that = this
console.log(areaId)
var para = {
requestProject: that.repProjectName
};
if (areaId == 0) {
para.type = that.typeId;
}
if (areaId != 0) {
para.type = that.typeId;
para.id = areaId;
}
that.optionsCity = [];
that.optionsRegion = [];
that.axios.post(that.baseUrl+requstUrl,qs.stringify(para)).then((res) => {
console.log(res,res.data,res.data.errorCode)
var resList = '';
resList = res.data;
if (resList.errorCode == 0) {
// 如果是省
if (that.typeId == 1) {
that.optionsPro = [];
for (var i in resList.result) {
// if (i == '710000'|| i == '810000' || i =='820000') {return;}
that.optionsPro.push(resList.result[i])
}
console.log("省:",that.optionsPro)
}
// 如果是市
if (that.typeId == 2) {
for (var i in resList.result) {
delete resList.result[i].provinceId
that.optionsCity.push(resList.result[i])
}
}
// 如果是区
if (that.typeId == 3) {
for (var i in resList.result) {
delete resList.result[i].provinceId;
delete resList.result[i].cityId;
that.optionsRegion.push(resList.result[i])
}
}
return false;
}
that.$message.error({
duration: 1000,
message: res.data.errorMessage
})
}).catch(function (error) {
console.log(error);
that.$message.error({
duration: 1000,
message: res.data.errorMessage
})
});
},
toLogin() {
const that = this;
that.axios.post(that.baseUrl+'/api-auth/doLogin',qs.stringify(that.loginInnfo)).then((res) => {
console.log(res)
var resLogin = res.data
if (resLogin.errorCode == 0) {
that.getArea();
}
}).catch(function (error) {
console.log(error);
that.$message.error({
duration: 1000,
message: error.errorMessage
})
});
},
setNewData(optionData) {
const that = this;
that.ruleForm.provience = optionData.provinceName;
that.ruleForm.city = optionData.cityName;
that.ruleForm.country = optionData.countryName;
that.ruleForm.provinceName = optionData.provinceName;
that.ruleForm.cityName = optionData.cityName;
that.ruleForm.countryName = optionData.countryName;
that.ruleForm.areaId = optionData.countyId;
that.getProId = optionData.provinceId;
that.getCityId = optionData.cityId;
console.log("that.ruleForm:",that.ruleForm)
},
},
watch: {
areaOptions: function(newData,oldData){
const that = this;
that.setNewData(newData)
},
projectName: function(newData,oldData){
const that = this;
that.repProjectName = newData || 'gic-web';
},
postUrl: function(newData,oldData){
const that = this;
that.requstUrl = newData;
},
},
/* 接收数据 */
mounted(){
console.log("传递的参数对象:",this.areaOptions)
const that = this;
// 项目名
that.repProjectName = that.projectName || 'gic-web';
that.requstUrl = that.postUrl
that.setNewData(that.areaOptions)
},
}
</script>
<style>
.gray-wrapper {
position: relative;
}
.area-wrapper {
position: relative;
bottom: 0px;
height: 40px;
}
.w-160 {
width: 160px;
}
.w-160+.w-160 {
margin-left: 3px;
}
</style>
import Vue from 'vue'
import App from './App.vue'
new Vue({
el: '#app',
render: h => h(App)
})
var path = require('path')
var webpack = require('webpack')
module.exports = {
// entry: './src/main.js',
entry: './src/lib/index.js',
output: {
path: path.resolve(__dirname, './dist'),
publicPath: '/dist/',
// filename: 'build.js',
filename: 'vue-office-area.js',
library: 'vue-office-area',
libraryTarget: 'umd',
umdNamedDefine: true
},
module: {
rules: [
{
test: /\.css$/,
use: [
'vue-style-loader',
'css-loader'
],
},
{
test: /\.scss$/,
use: [
'vue-style-loader',
'css-loader',
'sass-loader'
],
},
{
test: /\.sass$/,
use: [
'vue-style-loader',
'css-loader',
'sass-loader?indentedSyntax'
],
},
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
loaders: {
// Since sass-loader (weirdly) has SCSS as its default parse mode, we map
// the "scss" and "sass" values for the lang attribute to the right configs here.
// other preprocessors should work out of the box, no loader config like this necessary.
'scss': [
'vue-style-loader',
'css-loader',
'sass-loader'
],
'sass': [
'vue-style-loader',
'css-loader',
'sass-loader?indentedSyntax'
]
}
// other vue-loader options go here
}
},
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/
},
{
test: /\.(png|jpg|gif|svg)$/,
loader: 'file-loader',
options: {
name: '[name].[ext]?[hash]'
}
}
]
},
resolve: {
alias: {
'vue$': 'vue/dist/vue.esm.js'
},
extensions: ['*', '.js', '.vue', '.json']
},
devServer: {
historyApiFallback: true,
noInfo: true,
overlay: true
},
performance: {
hints: false
},
devtool: '#eval-source-map'
}
if (process.env.NODE_ENV === 'production') {
module.exports.devtool = '#source-map'
// http://vue-loader.vuejs.org/en/workflow/production.html
module.exports.plugins = (module.exports.plugins || []).concat([
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"'
}
}),
new webpack.optimize.UglifyJsPlugin({
sourceMap: true,
compress: {
warnings: false
}
}),
new webpack.LoaderOptionsPlugin({
minimize: true
})
])
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment