@handaotech-design/bom 0.0.49 → 0.0.51

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.
Files changed (54) hide show
  1. package/dist/es/components/bom-tree/index.vue +91 -198
  2. package/dist/es/components/bom-workbench/index.vue +2 -15
  3. package/dist/es/hooks/use-ppboms.d.ts +3 -5
  4. package/dist/es/hooks/use-ppboms.js +44 -42
  5. package/dist/es/index.d.ts +0 -1
  6. package/dist/es/index.js +0 -1
  7. package/dist/es/models/bom.d.ts +23 -0
  8. package/dist/es/models/bom.js +5 -0
  9. package/dist/es/models/common.d.ts +6 -0
  10. package/dist/es/utils/api.d.ts +5 -0
  11. package/dist/es/utils/api.js +10 -0
  12. package/dist/es/utils/child-loader.d.ts +2 -8
  13. package/dist/es/utils/child-loader.js +4 -3
  14. package/dist/es/utils/http-client.d.ts +14 -0
  15. package/dist/es/utils/http-client.js +47 -0
  16. package/dist/es/utils/index.d.ts +1 -1
  17. package/dist/es/utils/index.js +1 -1
  18. package/dist/lib/components/bom-tree/index.vue +91 -198
  19. package/dist/lib/components/bom-workbench/index.vue +2 -15
  20. package/dist/lib/hooks/use-ppboms.d.ts +3 -5
  21. package/dist/lib/hooks/use-ppboms.js +49 -42
  22. package/dist/lib/index.d.ts +0 -1
  23. package/dist/lib/index.js +0 -12
  24. package/dist/lib/models/bom.d.ts +23 -0
  25. package/dist/lib/models/bom.js +7 -2
  26. package/dist/lib/models/common.d.ts +6 -0
  27. package/dist/lib/utils/api.d.ts +5 -0
  28. package/dist/lib/utils/api.js +16 -0
  29. package/dist/lib/utils/child-loader.d.ts +2 -8
  30. package/dist/lib/utils/child-loader.js +4 -3
  31. package/dist/lib/utils/http-client.d.ts +14 -0
  32. package/dist/lib/utils/http-client.js +52 -0
  33. package/dist/lib/utils/index.d.ts +1 -1
  34. package/dist/lib/utils/index.js +4 -4
  35. package/dist/style.css +0 -2
  36. package/package.json +1 -1
  37. package/dist/es/components/bom-tree-view/index.d.ts +0 -3
  38. package/dist/es/components/bom-tree-view/index.js +0 -10
  39. package/dist/es/components/bom-tree-view/index.vue +0 -420
  40. package/dist/es/models/http-client.d.ts +0 -4
  41. package/dist/es/models/http-client.js +0 -0
  42. package/dist/es/sdk/index.d.ts +0 -11
  43. package/dist/es/sdk/index.js +0 -34
  44. package/dist/es/utils/config.d.ts +0 -1
  45. package/dist/es/utils/config.js +0 -11
  46. package/dist/lib/components/bom-tree-view/index.d.ts +0 -3
  47. package/dist/lib/components/bom-tree-view/index.js +0 -29
  48. package/dist/lib/components/bom-tree-view/index.vue +0 -420
  49. package/dist/lib/models/http-client.d.ts +0 -4
  50. package/dist/lib/models/http-client.js +0 -1
  51. package/dist/lib/sdk/index.d.ts +0 -11
  52. package/dist/lib/sdk/index.js +0 -43
  53. package/dist/lib/utils/config.d.ts +0 -1
  54. package/dist/lib/utils/config.js +0 -18
@@ -3,92 +3,99 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.usePpboms = exports.QueryType = void 0;
6
+ exports.usePpboms = void 0;
7
7
  var _vue = require("vue");
8
- var _utils = require("../utils");
8
+ var _httpClient = require("../utils/http-client");
9
9
  var _models = require("../models");
10
- const ppbomPageConfigCode = "PPBOM_PAGE";
11
- var QueryType = exports.QueryType = /* @__PURE__ */(QueryType2 => {
12
- QueryType2["ALL"] = "ALL";
13
- QueryType2["MODEL_ESN"] = "MODEL_ESN";
14
- return QueryType2;
15
- })(QueryType || {});
10
+ var _utils = require("../utils");
11
+ var _childLoader = require("../utils/child-loader");
12
+ const DEFAULT_PPBOM_PAGE_CONFIG_CODE = "PPBOM_PAGE";
16
13
  const usePpboms = params => {
17
14
  const {
18
15
  host,
19
16
  appId,
20
17
  appSecret,
21
- queryType,
18
+ configCode,
22
19
  options
23
20
  } = params;
24
21
  const loading = (0, _vue.ref)(false);
25
22
  const treeData = (0, _vue.ref)();
26
23
  const treeConfig = (0, _vue.ref)();
27
24
  const layoutConfig = (0, _vue.ref)();
25
+ const pageConfigCode = configCode ?? DEFAULT_PPBOM_PAGE_CONFIG_CODE;
26
+ const httpClient = new _httpClient.HttpClient({
27
+ baseURL: host,
28
+ defaultHeaders: {
29
+ "Content-Type": "application/json",
30
+ "X-CONSUMER-ID": appId,
31
+ "Authorization": `Bearer ${appSecret}`
32
+ }
33
+ });
28
34
  const queryBoms = async () => {
29
35
  const body = {
30
36
  page: 1,
31
37
  pageSize: Number.MAX_SAFE_INTEGER,
32
38
  ...(options ?? {})
33
39
  };
34
- const response = await fetch(`http://${host}/api/public/v2/ppboms/query/all`, {
35
- method: "POST",
36
- headers: {
37
- "Content-Type": "application/json",
38
- "X-CONSUMER-ID": appId,
39
- "Authorization": `Bearer ${appSecret}`
40
- },
41
- body: JSON.stringify(body)
42
- });
43
- return response.json();
40
+ const response = await httpClient.post("/api/public/v2/ppboms/query/all", body);
41
+ return response.data;
44
42
  };
45
- const queryBomsByModelEsn = async () => {
43
+ const queryBomsLazy = async () => {
46
44
  const body = {
47
45
  page: 1,
48
46
  pageSize: Number.MAX_SAFE_INTEGER,
49
- forceSettle: _models.YesNo.YES,
50
- lookupOnly: _models.YesNo.YES,
51
47
  ...(options ?? {})
52
48
  };
53
- const response = await fetch(`http://${host}/api/public/v2/ppboms/query/by-model-esn`, {
54
- method: "POST",
55
- headers: {
56
- "Content-Type": "application/json",
57
- "X-CONSUMER-ID": appId,
58
- "Authorization": `Bearer ${appSecret}`
59
- },
60
- body: JSON.stringify(body)
61
- });
62
- return response.json();
49
+ const response = await httpClient.post("/api/public/v2/ppboms/query/lazy-all", body);
50
+ return response.data;
63
51
  };
64
- const getData = async () => {
52
+ const getData = async queryType => {
65
53
  switch (queryType) {
66
- case "MODEL_ESN" /* MODEL_ESN */:
67
- return await queryBomsByModelEsn();
68
- default:
54
+ case _models.BomFetcherType.PPBOM_ALL:
69
55
  return await queryBoms();
56
+ case _models.BomFetcherType.PPBOM_LAZY_ALL:
57
+ return await queryBomsLazy();
58
+ default:
59
+ return {
60
+ items: [],
61
+ total: 0
62
+ };
70
63
  }
71
64
  };
72
65
  const getDataAndConfig = async () => {
73
66
  try {
74
67
  loading.value = true;
75
- const dataResp = await getData();
76
- const configResp = await (0, _utils.getConfig)(host, ppbomPageConfigCode, appId, appSecret);
77
- loading.value = false;
68
+ const configResp = await _utils.api.getConfig(pageConfigCode, httpClient);
78
69
  const props = configResp.config.props;
79
- treeData.value = (0, _utils.convertBomDataToTree)(dataResp.data.items, props.content.tree.nodeConfig.rule);
80
70
  treeConfig.value = props.content.tree;
81
- layoutConfig.value = props.content.tree.layout;
71
+ layoutConfig.value = props.content.layout;
72
+ const dataResp = await getData(props.bomFetcher.type);
73
+ treeData.value = dataResp.items;
74
+ loading.value = false;
82
75
  } finally {
83
76
  loading.value = false;
84
77
  }
85
78
  };
79
+ const loadChildren = async bomNode => {
80
+ const ruleEngine = new _utils.RuleEngine(treeConfig.value.nodeConfig.rule);
81
+ const matched = ruleEngine.matchOne({
82
+ bomNode
83
+ });
84
+ if (matched?.childrenLoader) {
85
+ const loader = _childLoader.ChildLoadersManager.getChildLoader(matched?.childrenLoader.type);
86
+ if (loader) {
87
+ return await loader(bomNode, httpClient);
88
+ }
89
+ }
90
+ return [];
91
+ };
86
92
  return {
87
93
  treeData,
88
94
  layoutConfig,
89
95
  treeConfig,
90
96
  loading,
91
- getDataAndConfig
97
+ getDataAndConfig,
98
+ loadChildren
92
99
  };
93
100
  };
94
101
  exports.usePpboms = usePpboms;
@@ -3,6 +3,5 @@ export * from './components';
3
3
  export * from './hooks';
4
4
  export * from './models';
5
5
  export * from './utils';
6
- export * from './sdk';
7
6
  export declare const install: (app: import("vue").App) => void;
8
7
  export default installer;
package/dist/lib/index.js CHANGED
@@ -56,18 +56,6 @@ Object.keys(_utils).forEach(function (key) {
56
56
  }
57
57
  });
58
58
  });
59
- var _sdk = require("./sdk");
60
- Object.keys(_sdk).forEach(function (key) {
61
- if (key === "default" || key === "__esModule") return;
62
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
63
- if (key in exports && exports[key] === _sdk[key]) return;
64
- Object.defineProperty(exports, key, {
65
- enumerable: true,
66
- get: function () {
67
- return _sdk[key];
68
- }
69
- });
70
- });
71
59
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
72
60
  const install = exports.install = _defaults.default.install;
73
61
  module.exports = _defaults.default;
@@ -49,3 +49,26 @@ export interface BomNode {
49
49
  raw: Record<string, any>;
50
50
  [key: string]: any;
51
51
  }
52
+ export interface BomNodeDetails {
53
+ component: any;
54
+ }
55
+ export interface PageLayoutConfig {
56
+ maxLeftWidth: number;
57
+ }
58
+ export interface BomContentConfig {
59
+ layout?: PageLayoutConfig;
60
+ tree: BomTreeConfig;
61
+ nodeDetails: BomNodeDetails;
62
+ }
63
+ export declare enum BomFetcherType {
64
+ PPBOM_LAZY_ALL = "ppbomLazyAll",
65
+ PPBOM_ALL = "ppbomAll"
66
+ }
67
+ export interface BomFetcherConfig {
68
+ type: BomFetcherType;
69
+ }
70
+ export interface BomPageConfig {
71
+ bomType: string;
72
+ bomFetcher: BomFetcherConfig;
73
+ content: BomContentConfig;
74
+ }
@@ -3,5 +3,10 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.defaultTitleTemplate = void 0;
7
- const defaultTitleTemplate = exports.defaultTitleTemplate = "${code}";
6
+ exports.defaultTitleTemplate = exports.BomFetcherType = void 0;
7
+ const defaultTitleTemplate = exports.defaultTitleTemplate = "${code}";
8
+ var BomFetcherType = exports.BomFetcherType = /* @__PURE__ */(BomFetcherType2 => {
9
+ BomFetcherType2["PPBOM_LAZY_ALL"] = "ppbomLazyAll";
10
+ BomFetcherType2["PPBOM_ALL"] = "ppbomAll";
11
+ return BomFetcherType2;
12
+ })(BomFetcherType || {});
@@ -3,3 +3,9 @@ export declare enum YesNo {
3
3
  NO = "NO"
4
4
  }
5
5
  export type Optional<T> = T | undefined | null;
6
+ export interface HttpResponse<T> {
7
+ code: number;
8
+ message: string;
9
+ data: T;
10
+ detail?: any;
11
+ }
@@ -0,0 +1,5 @@
1
+ import type { HttpClient } from './http-client';
2
+ export declare const api: {
3
+ getConfig: <T>(code: string, httpClient: HttpClient) => Promise<T>;
4
+ getBusinessId: <T>(bomNodeId: string, httpClient: HttpClient) => Promise<T>;
5
+ };
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.api = void 0;
7
+ const getConfig = async (code, httpClient) => {
8
+ return httpClient.get(`/api/public/v2/business-configs/${code}`);
9
+ };
10
+ const getBusinessId = async (bomNodeId, httpClient) => {
11
+ return httpClient.get(`/api/public/v2/ppboms/nodes/${bomNodeId}/business`);
12
+ };
13
+ const api = exports.api = {
14
+ getConfig,
15
+ getBusinessId
16
+ };
@@ -1,12 +1,6 @@
1
1
  import type { BomNode } from '../models';
2
- export interface IPartialBomSDK {
3
- httpClient: any;
4
- getBusinessId(bomNodeId: string): Promise<any>;
5
- getBusinessConfig(configCode: string): Promise<any>;
6
- getOperations(processPlanId: string): Promise<any>;
7
- }
8
- export type ChildLoaderFn = (bomNode: BomNode, sdk: IPartialBomSDK) => Promise<BomNode[]>;
9
- export declare function getOperationNodes(bomNode: BomNode, sdk: IPartialBomSDK): Promise<BomNode[]>;
2
+ import type { HttpClient } from './http-client';
3
+ export declare function getOperationNodes(bomNode: BomNode, httpClient: HttpClient): Promise<BomNode[]>;
10
4
  export declare namespace getOperationNodes {
11
5
  var type: string;
12
6
  }
@@ -5,11 +5,12 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.ChildLoadersManager = void 0;
7
7
  exports.getOperationNodes = getOperationNodes;
8
- async function getOperationNodes(bomNode, sdk) {
8
+ var _api = require("./api");
9
+ async function getOperationNodes(bomNode, httpClient) {
9
10
  const {
10
11
  data: processPlanId
11
- } = await sdk.getBusinessId(bomNode.id);
12
- const response = await sdk.getOperations(processPlanId);
12
+ } = await _api.api.getBusinessId(bomNode.id, httpClient);
13
+ const response = await httpClient.get(`/api/public/v2/process-plans/${processPlanId}/operations`);
13
14
  return (response.data || []).map(op => {
14
15
  return {
15
16
  id: op.id,
@@ -0,0 +1,14 @@
1
+ export interface HttpClientOptions {
2
+ baseURL: string;
3
+ defaultHeaders?: Record<string, string>;
4
+ authProvider?: () => string | Promise<string>;
5
+ }
6
+ export declare class HttpClient {
7
+ private readonly baseURL;
8
+ private readonly defaultHeaders;
9
+ private readonly authProvider?;
10
+ constructor(options: HttpClientOptions);
11
+ get<T>(url: string, config?: RequestInit): Promise<T>;
12
+ post<T>(url: string, data?: any, config?: RequestInit): Promise<T>;
13
+ private request;
14
+ }
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.HttpClient = void 0;
7
+ class HttpClient {
8
+ baseURL;
9
+ defaultHeaders;
10
+ authProvider;
11
+ constructor(options) {
12
+ this.baseURL = options.baseURL;
13
+ this.defaultHeaders = options.defaultHeaders || {};
14
+ this.authProvider = options.authProvider;
15
+ }
16
+ async get(url, config) {
17
+ return this.request(url, {
18
+ method: "GET",
19
+ ...config
20
+ });
21
+ }
22
+ async post(url, data, config) {
23
+ return this.request(url, {
24
+ method: "POST",
25
+ body: data !== void 0 ? JSON.stringify(data) : void 0,
26
+ ...config
27
+ });
28
+ }
29
+ async request(url, init) {
30
+ const headers = {
31
+ "Content-Type": "application/json",
32
+ ...this.defaultHeaders,
33
+ ...init.headers
34
+ };
35
+ if (this.authProvider) {
36
+ const token = await this.authProvider();
37
+ if (token) {
38
+ headers.Authorization = `Bearer ${token}`;
39
+ }
40
+ }
41
+ const response = await fetch(`${this.baseURL}${url}`, {
42
+ ...init,
43
+ headers
44
+ });
45
+ if (!response.ok) {
46
+ const text = await response.text();
47
+ throw new Error(`[Bom Component] HTTP ${response.status} ${response.statusText}: ${text}`);
48
+ }
49
+ return response.json();
50
+ }
51
+ }
52
+ exports.HttpClient = HttpClient;
@@ -1,4 +1,4 @@
1
1
  export * from './bom';
2
2
  export * from './rule-engine';
3
3
  export * from './template';
4
- export * from './config';
4
+ export * from './api';
@@ -36,14 +36,14 @@ Object.keys(_template).forEach(function (key) {
36
36
  }
37
37
  });
38
38
  });
39
- var _config = require("./config");
40
- Object.keys(_config).forEach(function (key) {
39
+ var _api = require("./api");
40
+ Object.keys(_api).forEach(function (key) {
41
41
  if (key === "default" || key === "__esModule") return;
42
- if (key in exports && exports[key] === _config[key]) return;
42
+ if (key in exports && exports[key] === _api[key]) return;
43
43
  Object.defineProperty(exports, key, {
44
44
  enumerable: true,
45
45
  get: function () {
46
- return _config[key];
46
+ return _api[key];
47
47
  }
48
48
  });
49
49
  });
package/dist/style.css CHANGED
@@ -42,7 +42,6 @@
42
42
  [grid=""]{display:grid;}
43
43
  .m-20px{margin:20px;}
44
44
  .mr-4px{margin-right:4px;}
45
- .mr-8px{margin-right:8px;}
46
45
  .ms{margin-inline-start:1rem;}
47
46
  .mt-12px{margin-top:12px;}
48
47
  .inline{display:inline;}
@@ -72,7 +71,6 @@
72
71
  .resize{resize:both;}
73
72
  .items-center{align-items:center;}
74
73
  .justify-center{justify-content:center;}
75
- .overflow-y-hidden{overflow-y:hidden;}
76
74
  .truncate{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}
77
75
  .b{border-width:1px;}
78
76
  .rounded{border-radius:0.25rem;}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@handaotech-design/bom",
3
- "version": "0.0.49",
3
+ "version": "0.0.51",
4
4
  "license": "MIT",
5
5
  "sideEffects": false,
6
6
  "exports": {
@@ -1,3 +0,0 @@
1
- export * from './index.vue';
2
- export declare const HdBomTree: any;
3
- export default HdBomTree;
@@ -1,10 +0,0 @@
1
- import { Dropdown, Input, Tree } from "ant-design-vue";
2
- import { MoreOutlined } from "@ant-design/icons-vue";
3
- import { withInstall } from "../../utils/install.js";
4
- import BomTree from "./index.vue";
5
- export * from "./index.vue";
6
- const antdComponents = Object.fromEntries(
7
- [Input, Tree, Dropdown, MoreOutlined].map((comp) => [comp.name, comp])
8
- );
9
- export const HdBomTree = withInstall(BomTree, antdComponents);
10
- export default HdBomTree;