@handaotech-design/bom 0.0.48 → 0.0.49

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.
@@ -3,5 +3,6 @@ export * from './components';
3
3
  export * from './hooks';
4
4
  export * from './models';
5
5
  export * from './utils';
6
+ export * from './sdk';
6
7
  export declare const install: (app: import("vue").App) => void;
7
8
  export default installer;
package/dist/es/index.js CHANGED
@@ -3,5 +3,6 @@ export * from "./components/index.js";
3
3
  export * from "./hooks/index.js";
4
4
  export * from "./models/index.js";
5
5
  export * from "./utils/index.js";
6
+ export * from "./sdk/index.js";
6
7
  export const install = installer.install;
7
8
  export default installer;
@@ -7,10 +7,26 @@ export interface BomNodeTitleConfig {
7
7
  export interface WorkBenchLayoutConfig {
8
8
  maxLeftWidth: number;
9
9
  }
10
+ export type NodeActionTitle = string | {
11
+ template: string;
12
+ };
13
+ export interface NodeActionDo {
14
+ type: string;
15
+ params?: Record<string, any>;
16
+ }
17
+ export interface NodeActionConfig {
18
+ title: NodeActionTitle;
19
+ children?: NodeActionConfig;
20
+ do?: NodeActionDo;
21
+ }
10
22
  export interface BomTreeNodeConfig {
11
23
  title?: BomNodeTitleConfig;
12
24
  selectable?: YesNo;
13
25
  icon?: string;
26
+ actions?: NodeActionConfig;
27
+ childrenLoader?: {
28
+ type: string;
29
+ };
14
30
  }
15
31
  export interface BomLocalFilter {
16
32
  placeholder?: string;
@@ -0,0 +1,4 @@
1
+ export interface HttpClient {
2
+ get<T>(url: string, config?: any): Promise<T>;
3
+ post<T>(url: string, data?: any, config?: any): Promise<T>;
4
+ }
File without changes
@@ -0,0 +1,11 @@
1
+ import type { HttpClient } from '../models/http-client';
2
+ import type { BomNode, BomTreeConfig } from '../models';
3
+ export declare class BomSDK {
4
+ httpClient: HttpClient;
5
+ constructor(client: HttpClient);
6
+ lazyLoadAll(): Promise<unknown>;
7
+ getBusinessConfig(configCode: string): Promise<unknown>;
8
+ getBusinessId(bomNodeId: string): Promise<unknown>;
9
+ loadChildren(bomNode: BomNode, treeConfig: BomTreeConfig): Promise<BomNode[]>;
10
+ getOperations(processPlanId: string): Promise<unknown>;
11
+ }
@@ -0,0 +1,34 @@
1
+ import { RuleEngine } from "../utils/index.js";
2
+ import { ChildLoadersManager } from "../utils/child-loader.js";
3
+ export class BomSDK {
4
+ httpClient;
5
+ constructor(client) {
6
+ this.httpClient = client;
7
+ }
8
+ async lazyLoadAll() {
9
+ return this.httpClient.post("/ppboms/query/lazy-all", {
10
+ page: 1,
11
+ pageSize: Number.MAX_SAFE_INTEGER
12
+ });
13
+ }
14
+ async getBusinessConfig(configCode) {
15
+ return this.httpClient.get(`/business-configs/${configCode}`);
16
+ }
17
+ async getBusinessId(bomNodeId) {
18
+ return this.httpClient.get(`/bom-nodes/${bomNodeId}/business`);
19
+ }
20
+ async loadChildren(bomNode, treeConfig) {
21
+ const ruleEngine = new RuleEngine(treeConfig.nodeConfig.rule);
22
+ const matched = ruleEngine.matchOne({ bomNode });
23
+ if (matched?.childrenLoader) {
24
+ const loader = ChildLoadersManager.getChildLoader(matched?.childrenLoader.type);
25
+ if (loader) {
26
+ return await loader(bomNode, this);
27
+ }
28
+ }
29
+ return [];
30
+ }
31
+ async getOperations(processPlanId) {
32
+ return this.httpClient.get(`/process-plans/${processPlanId}/operations`);
33
+ }
34
+ }
@@ -0,0 +1,15 @@
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[]>;
10
+ export declare namespace getOperationNodes {
11
+ var type: string;
12
+ }
13
+ export declare class ChildLoadersManager {
14
+ static getChildLoader(type: string): typeof getOperationNodes | undefined;
15
+ }
@@ -0,0 +1,25 @@
1
+ export async function getOperationNodes(bomNode, sdk) {
2
+ const { data: processPlanId } = await sdk.getBusinessId(bomNode.id);
3
+ const response = await sdk.getOperations(processPlanId);
4
+ return (response.data || []).map((op) => {
5
+ return {
6
+ id: op.id,
7
+ name: op.name,
8
+ code: op.operationNumber,
9
+ version: "V0",
10
+ qty: 1,
11
+ raw: {
12
+ id: op.id
13
+ },
14
+ businessType: "OPERATION",
15
+ key: op.id
16
+ };
17
+ });
18
+ }
19
+ getOperationNodes.type = "getOperationNodes";
20
+ const LOADERS = [getOperationNodes];
21
+ export class ChildLoadersManager {
22
+ static getChildLoader(type) {
23
+ return LOADERS.find((item) => item.type === type);
24
+ }
25
+ }
@@ -3,5 +3,6 @@ export * from './components';
3
3
  export * from './hooks';
4
4
  export * from './models';
5
5
  export * from './utils';
6
+ export * from './sdk';
6
7
  export declare const install: (app: import("vue").App) => void;
7
8
  export default installer;
package/dist/lib/index.js CHANGED
@@ -56,6 +56,18 @@ 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
+ });
59
71
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
60
72
  const install = exports.install = _defaults.default.install;
61
73
  module.exports = _defaults.default;
@@ -7,10 +7,26 @@ export interface BomNodeTitleConfig {
7
7
  export interface WorkBenchLayoutConfig {
8
8
  maxLeftWidth: number;
9
9
  }
10
+ export type NodeActionTitle = string | {
11
+ template: string;
12
+ };
13
+ export interface NodeActionDo {
14
+ type: string;
15
+ params?: Record<string, any>;
16
+ }
17
+ export interface NodeActionConfig {
18
+ title: NodeActionTitle;
19
+ children?: NodeActionConfig;
20
+ do?: NodeActionDo;
21
+ }
10
22
  export interface BomTreeNodeConfig {
11
23
  title?: BomNodeTitleConfig;
12
24
  selectable?: YesNo;
13
25
  icon?: string;
26
+ actions?: NodeActionConfig;
27
+ childrenLoader?: {
28
+ type: string;
29
+ };
14
30
  }
15
31
  export interface BomLocalFilter {
16
32
  placeholder?: string;
@@ -0,0 +1,4 @@
1
+ export interface HttpClient {
2
+ get<T>(url: string, config?: any): Promise<T>;
3
+ post<T>(url: string, data?: any, config?: any): Promise<T>;
4
+ }
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,11 @@
1
+ import type { HttpClient } from '../models/http-client';
2
+ import type { BomNode, BomTreeConfig } from '../models';
3
+ export declare class BomSDK {
4
+ httpClient: HttpClient;
5
+ constructor(client: HttpClient);
6
+ lazyLoadAll(): Promise<unknown>;
7
+ getBusinessConfig(configCode: string): Promise<unknown>;
8
+ getBusinessId(bomNodeId: string): Promise<unknown>;
9
+ loadChildren(bomNode: BomNode, treeConfig: BomTreeConfig): Promise<BomNode[]>;
10
+ getOperations(processPlanId: string): Promise<unknown>;
11
+ }
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.BomSDK = void 0;
7
+ var _utils = require("../utils");
8
+ var _childLoader = require("../utils/child-loader");
9
+ class BomSDK {
10
+ httpClient;
11
+ constructor(client) {
12
+ this.httpClient = client;
13
+ }
14
+ async lazyLoadAll() {
15
+ return this.httpClient.post("/ppboms/query/lazy-all", {
16
+ page: 1,
17
+ pageSize: Number.MAX_SAFE_INTEGER
18
+ });
19
+ }
20
+ async getBusinessConfig(configCode) {
21
+ return this.httpClient.get(`/business-configs/${configCode}`);
22
+ }
23
+ async getBusinessId(bomNodeId) {
24
+ return this.httpClient.get(`/bom-nodes/${bomNodeId}/business`);
25
+ }
26
+ async loadChildren(bomNode, treeConfig) {
27
+ const ruleEngine = new _utils.RuleEngine(treeConfig.nodeConfig.rule);
28
+ const matched = ruleEngine.matchOne({
29
+ bomNode
30
+ });
31
+ if (matched?.childrenLoader) {
32
+ const loader = _childLoader.ChildLoadersManager.getChildLoader(matched?.childrenLoader.type);
33
+ if (loader) {
34
+ return await loader(bomNode, this);
35
+ }
36
+ }
37
+ return [];
38
+ }
39
+ async getOperations(processPlanId) {
40
+ return this.httpClient.get(`/process-plans/${processPlanId}/operations`);
41
+ }
42
+ }
43
+ exports.BomSDK = BomSDK;
@@ -0,0 +1,15 @@
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[]>;
10
+ export declare namespace getOperationNodes {
11
+ var type: string;
12
+ }
13
+ export declare class ChildLoadersManager {
14
+ static getChildLoader(type: string): typeof getOperationNodes | undefined;
15
+ }
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ChildLoadersManager = void 0;
7
+ exports.getOperationNodes = getOperationNodes;
8
+ async function getOperationNodes(bomNode, sdk) {
9
+ const {
10
+ data: processPlanId
11
+ } = await sdk.getBusinessId(bomNode.id);
12
+ const response = await sdk.getOperations(processPlanId);
13
+ return (response.data || []).map(op => {
14
+ return {
15
+ id: op.id,
16
+ name: op.name,
17
+ code: op.operationNumber,
18
+ version: "V0",
19
+ qty: 1,
20
+ raw: {
21
+ id: op.id
22
+ },
23
+ businessType: "OPERATION",
24
+ key: op.id
25
+ };
26
+ });
27
+ }
28
+ getOperationNodes.type = "getOperationNodes";
29
+ const LOADERS = [getOperationNodes];
30
+ class ChildLoadersManager {
31
+ static getChildLoader(type) {
32
+ return LOADERS.find(item => item.type === type);
33
+ }
34
+ }
35
+ exports.ChildLoadersManager = ChildLoadersManager;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@handaotech-design/bom",
3
- "version": "0.0.48",
3
+ "version": "0.0.49",
4
4
  "license": "MIT",
5
5
  "sideEffects": false,
6
6
  "exports": {