@kmkf-fe-packages/kmkf-utils 0.7.15-alpha.0 → 0.7.15-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,34 @@
1
+ interface TreeOption {
2
+ label: string;
3
+ value: string;
4
+ children?: TreeOption[];
5
+ }
6
+ export default class BsAddressData {
7
+ private static instance;
8
+ addrData: Record<string, [string, string | number]>;
9
+ addrNameMap: Record<string, string>;
10
+ addressOptions: TreeOption[];
11
+ constructor();
12
+ initData: () => void;
13
+ parseData: (addrCode: string | number) => {
14
+ label: string;
15
+ value: string;
16
+ }[];
17
+ getProvinceByCode: (countryIndex: string | number) => {
18
+ label: string;
19
+ value: string;
20
+ }[];
21
+ getCityByProCode: (countryIndex: string | number) => {
22
+ label: string;
23
+ value: string;
24
+ }[];
25
+ getAreaByCityCode: (countryIndex: string | number) => {
26
+ label: string;
27
+ value: string;
28
+ }[];
29
+ getProCodeByName: (proName: string) => number | undefined;
30
+ getNameByCode: (code: string | number) => string;
31
+ static getInstance(): BsAddressData;
32
+ }
33
+ export declare type BsAddressDataClass = BsAddressData;
34
+ export {};
@@ -0,0 +1,89 @@
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
4
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
5
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
7
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
8
+ import request from "../request";
9
+ import { toTree } from "../utils";
10
+ import get from "lodash/get";
11
+ var BsAddressData = /*#__PURE__*/function () {
12
+ function BsAddressData() {
13
+ var _this = this;
14
+ _classCallCheck(this, BsAddressData);
15
+ _defineProperty(this, "addrData", {});
16
+ _defineProperty(this, "addrNameMap", {});
17
+ _defineProperty(this, "addressOptions", []);
18
+ _defineProperty(this, "initData", function () {
19
+ var _Object$keys;
20
+ if (((_Object$keys = Object.keys(_this.addrData)) === null || _Object$keys === void 0 ? void 0 : _Object$keys.length) > 0) return;
21
+ request({
22
+ url: "/qy/gdfw/template/queryAreas",
23
+ method: "get",
24
+ data: {}
25
+ }).then(function (resp) {
26
+ var map = {};
27
+ var res = {};
28
+ var list = resp.data;
29
+ for (var i = 0; i < list.length; i++) {
30
+ res[list[i]["id"]] = [list[i]["name"], list[i]["parentId"]];
31
+ map[list[i]["name"]] = list[i]["id"];
32
+ }
33
+ _this.addrData = res;
34
+ _this.addrNameMap = map;
35
+ _this.addressOptions = get(toTree(list, 0), "0.children", []);
36
+ });
37
+ });
38
+ _defineProperty(this, "parseData", function (addrCode) {
39
+ var nameCode = {},
40
+ arr = [];
41
+ for (var key in _this.addrData) {
42
+ if (Object.prototype.hasOwnProperty.call(_this.addrData, key)) {
43
+ var valueArray = _this.addrData[key];
44
+ if (valueArray[1] === Number(addrCode)) {
45
+ nameCode[valueArray[0]] = key;
46
+ arr.push({
47
+ label: valueArray[0],
48
+ value: key
49
+ });
50
+ }
51
+ }
52
+ }
53
+ return arr;
54
+ });
55
+ _defineProperty(this, "getProvinceByCode", function (countryIndex) {
56
+ return _this.parseData(countryIndex);
57
+ });
58
+ _defineProperty(this, "getCityByProCode", function (countryIndex) {
59
+ return _this.parseData(countryIndex);
60
+ });
61
+ _defineProperty(this, "getAreaByCityCode", function (countryIndex) {
62
+ return _this.parseData(countryIndex);
63
+ });
64
+ _defineProperty(this, "getProCodeByName", function (proName) {
65
+ for (var key in _this.addrData) {
66
+ if (_this.addrData[key][0] === proName) {
67
+ return Number(key);
68
+ }
69
+ }
70
+ });
71
+ _defineProperty(this, "getNameByCode", function (code) {
72
+ var _ref;
73
+ return (_ref = (_this.addrData || {})[code] || []) === null || _ref === void 0 ? void 0 : _ref[0];
74
+ });
75
+ this.initData();
76
+ }
77
+ _createClass(BsAddressData, null, [{
78
+ key: "getInstance",
79
+ value: function getInstance() {
80
+ if (!BsAddressData.instance) {
81
+ BsAddressData.instance = new BsAddressData();
82
+ }
83
+ return BsAddressData.instance;
84
+ }
85
+ }]);
86
+ return BsAddressData;
87
+ }();
88
+ _defineProperty(BsAddressData, "instance", void 0);
89
+ export { BsAddressData as default };
@@ -1,6 +1,7 @@
1
1
  export { default as ExpressData } from "./expressData";
2
2
  export { default as ExpressInterceptData } from "./expressInterceptData";
3
3
  export { default as AddressData } from "./addressData";
4
+ export { default as BsAddressData } from "./bsAddressData";
4
5
  export { default as PlatData } from "./platData";
5
6
  export { default as LogisticsAddressData } from "./logisticsAddressData";
6
7
  export { default as request } from "./request";
package/dist/esm/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  export { default as ExpressData } from "./expressData";
2
2
  export { default as ExpressInterceptData } from "./expressInterceptData";
3
3
  export { default as AddressData } from "./addressData";
4
+ export { default as BsAddressData } from "./bsAddressData";
4
5
  export { default as PlatData } from "./platData";
5
6
  export { default as LogisticsAddressData } from "./logisticsAddressData";
6
7
  export { default as request } from "./request";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kmkf-fe-packages/kmkf-utils",
3
- "version": "0.7.15-alpha.0",
3
+ "version": "0.7.15-alpha.5",
4
4
  "module": "dist/esm/index.js",
5
5
  "typings": "dist/esm/index.d.ts",
6
6
  "files": [
@@ -42,5 +42,5 @@
42
42
  "gitHooks": {
43
43
  "pre-commit": "lint-staged"
44
44
  },
45
- "gitHead": "d4b347ccc78afe1ac7f89f12655ce72fdfabb0f6"
45
+ "gitHead": "e0a00366bed469e96b301ebf6753c2078cb8492c"
46
46
  }