@handaotech-design/bom 0.0.16
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.
- package/README.md +13 -0
- package/build.config.ts +27 -0
- package/dist/es/all-components.d.ts +3 -0
- package/dist/es/all-components.js +10 -0
- package/dist/es/assets/icons/operation-selected.svg +3 -0
- package/dist/es/assets/icons/operation.svg +3 -0
- package/dist/es/assets/icons/process-path-selected.svg +3 -0
- package/dist/es/assets/icons/process-path.svg +3 -0
- package/dist/es/assets/icons/process-plan-selected.svg +3 -0
- package/dist/es/assets/icons/process-plan.svg +3 -0
- package/dist/es/assets/icons/remove-minus.svg +4 -0
- package/dist/es/assets/icons/remove-plus.svg +5 -0
- package/dist/es/assets/icons/search.svg +4 -0
- package/dist/es/components/bom-tree/index.d.ts +3 -0
- package/dist/es/components/bom-tree/index.js +5 -0
- package/dist/es/components/bom-tree/index.vue +358 -0
- package/dist/es/components/bom-workbench/index.d.ts +3 -0
- package/dist/es/components/bom-workbench/index.js +5 -0
- package/dist/es/components/bom-workbench/index.vue +98 -0
- package/dist/es/components/gray-input/index.d.ts +3 -0
- package/dist/es/components/gray-input/index.js +5 -0
- package/dist/es/components/gray-input/index.vue +44 -0
- package/dist/es/components/index.d.ts +4 -0
- package/dist/es/components/index.js +4 -0
- package/dist/es/components/left-right/index.d.ts +3 -0
- package/dist/es/components/left-right/index.js +5 -0
- package/dist/es/components/left-right/index.vue +142 -0
- package/dist/es/defaults.d.ts +4 -0
- package/dist/es/defaults.js +3 -0
- package/dist/es/hooks/index.d.ts +1 -0
- package/dist/es/hooks/index.js +1 -0
- package/dist/es/hooks/use-ppboms.d.ts +19 -0
- package/dist/es/hooks/use-ppboms.js +81 -0
- package/dist/es/index.d.ts +7 -0
- package/dist/es/index.js +7 -0
- package/dist/es/models/bom.d.ts +35 -0
- package/dist/es/models/bom.js +1 -0
- package/dist/es/models/common.d.ts +5 -0
- package/dist/es/models/common.js +5 -0
- package/dist/es/models/index.d.ts +2 -0
- package/dist/es/models/index.js +2 -0
- package/dist/es/shared/keys.d.ts +1 -0
- package/dist/es/shared/keys.js +1 -0
- package/dist/es/shared/make-installer.d.ts +4 -0
- package/dist/es/shared/make-installer.js +13 -0
- package/dist/es/shims-vue.d.ts +5 -0
- package/dist/es/tokens/index.d.ts +0 -0
- package/dist/es/tokens/index.js +0 -0
- package/dist/es/types/components.d.ts +17 -0
- package/dist/es/utils/bom.d.ts +3 -0
- package/dist/es/utils/bom.js +29 -0
- package/dist/es/utils/config.d.ts +1 -0
- package/dist/es/utils/config.js +11 -0
- package/dist/es/utils/index.d.ts +4 -0
- package/dist/es/utils/index.js +4 -0
- package/dist/es/utils/rule-engine.d.ts +20 -0
- package/dist/es/utils/rule-engine.js +50 -0
- package/dist/es/utils/template.d.ts +1 -0
- package/dist/es/utils/template.js +11 -0
- package/dist/lib/all-components.d.ts +3 -0
- package/dist/lib/all-components.js +12 -0
- package/dist/lib/assets/icons/operation-selected.svg +3 -0
- package/dist/lib/assets/icons/operation.svg +3 -0
- package/dist/lib/assets/icons/process-path-selected.svg +3 -0
- package/dist/lib/assets/icons/process-path.svg +3 -0
- package/dist/lib/assets/icons/process-plan-selected.svg +3 -0
- package/dist/lib/assets/icons/process-plan.svg +3 -0
- package/dist/lib/assets/icons/remove-minus.svg +4 -0
- package/dist/lib/assets/icons/remove-plus.svg +5 -0
- package/dist/lib/assets/icons/search.svg +4 -0
- package/dist/lib/components/bom-tree/index.d.ts +3 -0
- package/dist/lib/components/bom-tree/index.js +26 -0
- package/dist/lib/components/bom-tree/index.vue +358 -0
- package/dist/lib/components/bom-workbench/index.d.ts +3 -0
- package/dist/lib/components/bom-workbench/index.js +26 -0
- package/dist/lib/components/bom-workbench/index.vue +98 -0
- package/dist/lib/components/gray-input/index.d.ts +3 -0
- package/dist/lib/components/gray-input/index.js +26 -0
- package/dist/lib/components/gray-input/index.vue +44 -0
- package/dist/lib/components/index.d.ts +4 -0
- package/dist/lib/components/index.js +49 -0
- package/dist/lib/components/left-right/index.d.ts +3 -0
- package/dist/lib/components/left-right/index.js +26 -0
- package/dist/lib/components/left-right/index.vue +142 -0
- package/dist/lib/defaults.d.ts +4 -0
- package/dist/lib/defaults.js +10 -0
- package/dist/lib/hooks/index.d.ts +1 -0
- package/dist/lib/hooks/index.js +16 -0
- package/dist/lib/hooks/use-ppboms.d.ts +19 -0
- package/dist/lib/hooks/use-ppboms.js +94 -0
- package/dist/lib/index.d.ts +7 -0
- package/dist/lib/index.js +61 -0
- package/dist/lib/models/bom.d.ts +35 -0
- package/dist/lib/models/bom.js +7 -0
- package/dist/lib/models/common.d.ts +5 -0
- package/dist/lib/models/common.js +11 -0
- package/dist/lib/models/index.d.ts +2 -0
- package/dist/lib/models/index.js +27 -0
- package/dist/lib/shared/keys.d.ts +1 -0
- package/dist/lib/shared/keys.js +7 -0
- package/dist/lib/shared/make-installer.d.ts +4 -0
- package/dist/lib/shared/make-installer.js +20 -0
- package/dist/lib/shims-vue.d.ts +5 -0
- package/dist/lib/tokens/index.d.ts +0 -0
- package/dist/lib/tokens/index.js +1 -0
- package/dist/lib/types/components.d.ts +17 -0
- package/dist/lib/utils/bom.d.ts +3 -0
- package/dist/lib/utils/bom.js +40 -0
- package/dist/lib/utils/config.d.ts +1 -0
- package/dist/lib/utils/config.js +18 -0
- package/dist/lib/utils/index.d.ts +4 -0
- package/dist/lib/utils/index.js +49 -0
- package/dist/lib/utils/rule-engine.d.ts +20 -0
- package/dist/lib/utils/rule-engine.js +57 -0
- package/dist/lib/utils/template.d.ts +1 -0
- package/dist/lib/utils/template.js +19 -0
- package/dist/style.css +86 -0
- package/package.json +65 -0
- package/rollup.config.ts +47 -0
- package/src/all-components.ts +12 -0
- package/src/assets/icons/operation-selected.svg +3 -0
- package/src/assets/icons/operation.svg +3 -0
- package/src/assets/icons/process-path-selected.svg +3 -0
- package/src/assets/icons/process-path.svg +3 -0
- package/src/assets/icons/process-plan-selected.svg +3 -0
- package/src/assets/icons/process-plan.svg +3 -0
- package/src/assets/icons/remove-minus.svg +4 -0
- package/src/assets/icons/remove-plus.svg +5 -0
- package/src/assets/icons/search.svg +4 -0
- package/src/components/bom-tree/index.ts +5 -0
- package/src/components/bom-tree/index.vue +377 -0
- package/src/components/bom-workbench/index.ts +5 -0
- package/src/components/bom-workbench/index.vue +97 -0
- package/src/components/gray-input/index.ts +5 -0
- package/src/components/gray-input/index.vue +40 -0
- package/src/components/index.ts +4 -0
- package/src/components/left-right/index.ts +5 -0
- package/src/components/left-right/index.vue +149 -0
- package/src/defaults.ts +3 -0
- package/src/hooks/index.ts +1 -0
- package/src/hooks/use-ppboms.ts +97 -0
- package/src/index.ts +9 -0
- package/src/models/bom.ts +43 -0
- package/src/models/common.ts +6 -0
- package/src/models/index.ts +2 -0
- package/src/shared/keys.ts +1 -0
- package/src/shared/make-installer.ts +21 -0
- package/src/shims-vue.d.ts +5 -0
- package/src/tokens/index.ts +0 -0
- package/src/types/components.d.ts +17 -0
- package/src/utils/bom.ts +33 -0
- package/src/utils/config.ts +11 -0
- package/src/utils/index.ts +4 -0
- package/src/utils/rule-engine.ts +83 -0
- package/src/utils/template.ts +13 -0
- package/tsconfig.json +7 -0
- package/unocss.config.ts +55 -0
- package/vite-env.d.ts +1 -0
- package/vite.config.ts +79 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { ref } from 'vue'
|
|
2
|
+
import { convertBomDataToTree, getConfig } from '../utils'
|
|
3
|
+
import { YesNo } from '../models'
|
|
4
|
+
|
|
5
|
+
const ppbomPageConfigCode = 'PPBOM_PAGE'
|
|
6
|
+
|
|
7
|
+
export enum QueryType {
|
|
8
|
+
ALL = 'ALL',
|
|
9
|
+
MODEL_ESN = 'MODEL_ESN',
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface UsePpbomsParams {
|
|
13
|
+
host: string
|
|
14
|
+
appId: string
|
|
15
|
+
appSecret: string
|
|
16
|
+
queryType?: QueryType
|
|
17
|
+
options?: Record<string, any>
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const UsePpboms = (params: UsePpbomsParams) => {
|
|
21
|
+
const { host, appId, appSecret, queryType, options } = params
|
|
22
|
+
const loading = ref<boolean>(false)
|
|
23
|
+
const data = ref<any>()
|
|
24
|
+
const treeConfig = ref<any>()
|
|
25
|
+
const layoutConfig = ref<any>()
|
|
26
|
+
|
|
27
|
+
const queryBoms = async () => {
|
|
28
|
+
const body = {
|
|
29
|
+
page: 1,
|
|
30
|
+
pageSize: Number.MAX_SAFE_INTEGER,
|
|
31
|
+
...(options ?? {}),
|
|
32
|
+
}
|
|
33
|
+
const response = await fetch(`http://${host}/api/public/v2/ppboms/query/all`, {
|
|
34
|
+
method: 'POST',
|
|
35
|
+
headers: {
|
|
36
|
+
'Content-Type': 'application/json',
|
|
37
|
+
'X-CONSUMER-ID': appId,
|
|
38
|
+
'Authorization': `Bearer ${appSecret}`,
|
|
39
|
+
},
|
|
40
|
+
body: JSON.stringify(body),
|
|
41
|
+
})
|
|
42
|
+
return response.json()
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const queryBomsByModelEsn = async () => {
|
|
46
|
+
const body = {
|
|
47
|
+
page: 1,
|
|
48
|
+
pageSize: Number.MAX_SAFE_INTEGER,
|
|
49
|
+
forceSettle: YesNo.YES,
|
|
50
|
+
lookupOnly: YesNo.YES,
|
|
51
|
+
...(options ?? {}),
|
|
52
|
+
}
|
|
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()
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const getData = async () => {
|
|
66
|
+
switch (queryType) {
|
|
67
|
+
case QueryType.MODEL_ESN:
|
|
68
|
+
return await queryBomsByModelEsn()
|
|
69
|
+
default:
|
|
70
|
+
return await queryBoms()
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const getDataAndConfig = async () => {
|
|
75
|
+
try {
|
|
76
|
+
loading.value = true
|
|
77
|
+
const dataResp = await getData()
|
|
78
|
+
const configResp = await getConfig(host, ppbomPageConfigCode, appId, appSecret)
|
|
79
|
+
loading.value = false
|
|
80
|
+
const props = configResp.config.props
|
|
81
|
+
data.value = convertBomDataToTree(dataResp.data.items, props.content.tree.nodeConfig.rule)
|
|
82
|
+
treeConfig.value = props.content.tree
|
|
83
|
+
layoutConfig.value = props.content.tree.layout
|
|
84
|
+
}
|
|
85
|
+
finally {
|
|
86
|
+
loading.value = false
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return {
|
|
91
|
+
data,
|
|
92
|
+
layoutConfig,
|
|
93
|
+
treeConfig,
|
|
94
|
+
loading,
|
|
95
|
+
getDataAndConfig,
|
|
96
|
+
}
|
|
97
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { BaseRule } from '../utils'
|
|
2
|
+
import type { YesNo } from './common'
|
|
3
|
+
|
|
4
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
5
|
+
export const defaultTitleTemplate = '${code}'
|
|
6
|
+
|
|
7
|
+
export interface BomNodeTitleConfig {
|
|
8
|
+
template: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface WorkBenchLayoutConfig {
|
|
12
|
+
maxLeftWidth: number
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface BomTreeNodeConfig {
|
|
16
|
+
title?: BomNodeTitleConfig
|
|
17
|
+
selectable?: YesNo
|
|
18
|
+
icon?: string
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface BomLocalFilter {
|
|
22
|
+
placeholder?: string
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface BomTreeConfig {
|
|
26
|
+
filter?: BomLocalFilter
|
|
27
|
+
nodeConfig: {
|
|
28
|
+
rule: BaseRule<BomTreeNodeConfig>
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface BomNode {
|
|
33
|
+
id: string
|
|
34
|
+
key: string
|
|
35
|
+
code: string
|
|
36
|
+
version: string
|
|
37
|
+
name: string
|
|
38
|
+
qty: number
|
|
39
|
+
children?: BomNode[]
|
|
40
|
+
businessType: string
|
|
41
|
+
raw: Record<string, any>
|
|
42
|
+
[key: string]: any
|
|
43
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const INSTALLED_KEY = Symbol('INSTALLED_KEY')
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { App, Plugin } from '@vue/runtime-core'
|
|
2
|
+
import { INSTALLED_KEY } from './keys'
|
|
3
|
+
|
|
4
|
+
export const makeInstaller = (components: Plugin[] = []) => {
|
|
5
|
+
const install = (app: App) => {
|
|
6
|
+
// @ts-expect-error mark app as having installer flag
|
|
7
|
+
if (app[INSTALLED_KEY]) {
|
|
8
|
+
return
|
|
9
|
+
}
|
|
10
|
+
// @ts-expect-error set installer flag on app instance
|
|
11
|
+
app[INSTALLED_KEY] = true
|
|
12
|
+
|
|
13
|
+
components.forEach(c => app.use(c))
|
|
14
|
+
|
|
15
|
+
// if (options) provideGlobalConfig(options, app, true)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return {
|
|
19
|
+
install,
|
|
20
|
+
}
|
|
21
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// generated by unplugin-vue-components
|
|
2
|
+
// We suggest you to commit this file into source control
|
|
3
|
+
// Read more: https://github.com/vuejs/core/pull/3399
|
|
4
|
+
import '@vue/runtime-core'
|
|
5
|
+
|
|
6
|
+
export {}
|
|
7
|
+
|
|
8
|
+
declare module '@vue/runtime-core' {
|
|
9
|
+
export interface GlobalComponents {
|
|
10
|
+
BomTree: typeof import('./../components/bom-tree/index.vue')['default']
|
|
11
|
+
BomWorkbench: typeof import('./../components/bom-workbench/index.vue')['default']
|
|
12
|
+
GrayInput: typeof import('./../components/gray-input/index.vue')['default']
|
|
13
|
+
LeftRight: typeof import('./../components/left-right/index.vue')['default']
|
|
14
|
+
RouterLink: typeof import('vue-router')['RouterLink']
|
|
15
|
+
RouterView: typeof import('vue-router')['RouterView']
|
|
16
|
+
}
|
|
17
|
+
}
|
package/src/utils/bom.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import * as _ from 'lodash-es'
|
|
2
|
+
import type { BomNode, BomTreeNodeConfig } from '../models'
|
|
3
|
+
import { YesNo, defaultTitleTemplate } from '../models'
|
|
4
|
+
import type { BaseRule } from './rule-engine'
|
|
5
|
+
import { RuleEngine } from './rule-engine'
|
|
6
|
+
import { genText } from './template'
|
|
7
|
+
|
|
8
|
+
const defaultTreeNodeConfig: BomTreeNodeConfig = {
|
|
9
|
+
title: {
|
|
10
|
+
template: defaultTitleTemplate,
|
|
11
|
+
},
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const convertBomDataToTree = (treeData: BomNode[], nodeConfigRule: BaseRule<BomTreeNodeConfig>) => {
|
|
15
|
+
const ruleEngine = new RuleEngine<BomTreeNodeConfig>(nodeConfigRule)
|
|
16
|
+
const traverse = (nodes: BomNode[] = []) => {
|
|
17
|
+
for (const node of nodes) {
|
|
18
|
+
const nodeConfig = ruleEngine.matchOne({ bomNode: node }, defaultTreeNodeConfig)
|
|
19
|
+
const titleTemplate = nodeConfig?.title?.template ?? defaultTitleTemplate
|
|
20
|
+
Object.assign(node, {
|
|
21
|
+
key: node.key,
|
|
22
|
+
title: genText(node, titleTemplate),
|
|
23
|
+
selectable: nodeConfig?.selectable === YesNo.YES,
|
|
24
|
+
icon: nodeConfig?.icon,
|
|
25
|
+
})
|
|
26
|
+
if (!_.isEmpty(node.children)) {
|
|
27
|
+
traverse(node.children)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
traverse(treeData)
|
|
32
|
+
return treeData
|
|
33
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const getConfig = async (host: string, code: string, appId: string, appSecret: string) => {
|
|
2
|
+
const response = await fetch(`http://${host}/api/public/v2/business-configs/${code}`, {
|
|
3
|
+
method: 'GET',
|
|
4
|
+
headers: {
|
|
5
|
+
'Content-Type': 'application/json',
|
|
6
|
+
'X-CONSUMER-ID': appId,
|
|
7
|
+
'Authorization': `Bearer ${appSecret}`,
|
|
8
|
+
},
|
|
9
|
+
})
|
|
10
|
+
return await response.json()
|
|
11
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { Optional } from '../models/common'
|
|
2
|
+
|
|
3
|
+
export type RuleCondition = 'default' | 'always' | string | LogicExpression
|
|
4
|
+
|
|
5
|
+
export interface LogicExpression {
|
|
6
|
+
// 以后可扩展
|
|
7
|
+
logic: any
|
|
8
|
+
conditions: any[]
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface BaseRule<T> {
|
|
12
|
+
cases: BaseCase<T>[]
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface BaseCase<T> {
|
|
16
|
+
key?: string
|
|
17
|
+
condition: RuleCondition
|
|
18
|
+
result: T
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export class RuleEngine<T> {
|
|
22
|
+
private readonly rule: BaseRule<T>
|
|
23
|
+
|
|
24
|
+
constructor(rule: BaseRule<T>) {
|
|
25
|
+
this.rule = rule
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
matchOne(context: any, defaultResult?: T): Optional<T> | T {
|
|
29
|
+
let defaultRule: BaseCase<T> | undefined
|
|
30
|
+
|
|
31
|
+
for (const caseItem of this.rule.cases) {
|
|
32
|
+
const cond = caseItem.condition
|
|
33
|
+
if (cond === 'default') {
|
|
34
|
+
defaultRule = caseItem
|
|
35
|
+
continue
|
|
36
|
+
}
|
|
37
|
+
if (cond === 'always' || (typeof cond === 'string' && evaluate(cond, context))) {
|
|
38
|
+
return caseItem.result
|
|
39
|
+
}
|
|
40
|
+
// LogicExpression 暂不支持
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (defaultRule) {
|
|
44
|
+
return defaultRule.result
|
|
45
|
+
}
|
|
46
|
+
return defaultResult
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
matchMany(context: any, defaultResult?: T): T[] {
|
|
50
|
+
const results: T[] = []
|
|
51
|
+
let defaultRule: BaseCase<T> | undefined
|
|
52
|
+
|
|
53
|
+
for (const caseItem of this.rule.cases) {
|
|
54
|
+
const cond = caseItem.condition
|
|
55
|
+
if (cond === 'default') {
|
|
56
|
+
defaultRule = caseItem
|
|
57
|
+
continue
|
|
58
|
+
}
|
|
59
|
+
if (cond === 'always' || (typeof cond === 'string' && evaluate(cond, context))) {
|
|
60
|
+
results.push(caseItem.result)
|
|
61
|
+
}
|
|
62
|
+
// LogicExpression 暂不支持
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (results.length > 0) {
|
|
66
|
+
return results
|
|
67
|
+
}
|
|
68
|
+
const fallback = defaultRule?.result ?? defaultResult
|
|
69
|
+
return fallback ? [fallback] : []
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// TODO 安全的表达式求值器
|
|
74
|
+
function evaluate(expr: string, context: any): boolean {
|
|
75
|
+
try {
|
|
76
|
+
// eslint-disable-next-line no-new-func
|
|
77
|
+
const func = new Function('context', `with(context) { return ${expr}; }`)
|
|
78
|
+
return Boolean(func(context))
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
return false
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as _ from 'lodash-es'
|
|
2
|
+
|
|
3
|
+
export function genText(data: Record<string, any>, templateStr: string, defaultText?: string) {
|
|
4
|
+
const compiled = _.template(templateStr)
|
|
5
|
+
let str: string
|
|
6
|
+
try {
|
|
7
|
+
str = compiled(data)
|
|
8
|
+
}
|
|
9
|
+
catch (e) { // 模板变量找不到,暂时处理
|
|
10
|
+
str = defaultText ?? '--'
|
|
11
|
+
}
|
|
12
|
+
return str
|
|
13
|
+
}
|
package/tsconfig.json
ADDED
package/unocss.config.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineConfig,
|
|
3
|
+
presetAttributify,
|
|
4
|
+
presetIcons,
|
|
5
|
+
presetTypography,
|
|
6
|
+
presetUno,
|
|
7
|
+
transformerDirectives,
|
|
8
|
+
transformerVariantGroup,
|
|
9
|
+
} from 'unocss'
|
|
10
|
+
import { FileSystemIconLoader } from '@iconify/utils/lib/loader/node-loaders'
|
|
11
|
+
import type { UserConfig } from 'unocss'
|
|
12
|
+
const config: UserConfig = {
|
|
13
|
+
presets: [
|
|
14
|
+
presetUno(),
|
|
15
|
+
presetAttributify(),
|
|
16
|
+
presetIcons({
|
|
17
|
+
mode: 'auto',
|
|
18
|
+
autoInstall: false,
|
|
19
|
+
collections: {
|
|
20
|
+
icon: FileSystemIconLoader(
|
|
21
|
+
'src/assets/icons',
|
|
22
|
+
(svg) => {
|
|
23
|
+
if (svg.includes('class="keep"')) {
|
|
24
|
+
return svg
|
|
25
|
+
}
|
|
26
|
+
svg = svg.replace(/fill=".*"/, 'fill="currentColor"')
|
|
27
|
+
return svg
|
|
28
|
+
},
|
|
29
|
+
),
|
|
30
|
+
},
|
|
31
|
+
customizations: {
|
|
32
|
+
customize(props) {
|
|
33
|
+
props.width = '1em'
|
|
34
|
+
props.height = '1em'
|
|
35
|
+
return props
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
}),
|
|
39
|
+
presetTypography(),
|
|
40
|
+
],
|
|
41
|
+
transformers: [
|
|
42
|
+
transformerDirectives(),
|
|
43
|
+
transformerVariantGroup(),
|
|
44
|
+
],
|
|
45
|
+
safelist: [ // 声明icon,避免动态加载,不能显示的问题
|
|
46
|
+
'i-icon-process-plan',
|
|
47
|
+
'i-icon-process-plan-selected',
|
|
48
|
+
'i-icon-process-path',
|
|
49
|
+
'i-icon-process-path-selected',
|
|
50
|
+
'i-icon-operation',
|
|
51
|
+
'i-icon-operation-selected',
|
|
52
|
+
],
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export default defineConfig(config)
|
package/vite-env.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|
package/vite.config.ts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import path, { join, resolve } from 'path'
|
|
2
|
+
import vue from '@vitejs/plugin-vue'
|
|
3
|
+
import vueJsx from '@vitejs/plugin-vue-jsx'
|
|
4
|
+
import VueMacros from 'unplugin-vue-macros/vite'
|
|
5
|
+
import { defineConfig } from 'vite'
|
|
6
|
+
import Unocss from '@unocss/vite'
|
|
7
|
+
import dts from 'vite-plugin-dts'
|
|
8
|
+
import Components from 'unplugin-vue-components/vite'
|
|
9
|
+
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers'
|
|
10
|
+
|
|
11
|
+
const pkgRootPath = resolve(__dirname)
|
|
12
|
+
|
|
13
|
+
export default defineConfig({
|
|
14
|
+
build: {
|
|
15
|
+
target: 'modules',
|
|
16
|
+
outDir: 'dist',
|
|
17
|
+
lib: {
|
|
18
|
+
entry: './src/index.ts',
|
|
19
|
+
name: 'bom',
|
|
20
|
+
formats: ['es', 'cjs'],
|
|
21
|
+
fileName: format => `index.${format}.js`,
|
|
22
|
+
},
|
|
23
|
+
rollupOptions: {
|
|
24
|
+
external: [
|
|
25
|
+
'vue',
|
|
26
|
+
'vue-types',
|
|
27
|
+
'ant-design-vue',
|
|
28
|
+
'@handaotech-design/vue',
|
|
29
|
+
],
|
|
30
|
+
input: [join(pkgRootPath, '/src/index.ts')],
|
|
31
|
+
output: [
|
|
32
|
+
{
|
|
33
|
+
format: 'es',
|
|
34
|
+
dir: 'dist/es',
|
|
35
|
+
entryFileNames: '[name].js',
|
|
36
|
+
preserveModulesRoot: 'src',
|
|
37
|
+
preserveModules: true,
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
format: 'cjs',
|
|
41
|
+
dir: 'dist/lib',
|
|
42
|
+
entryFileNames: '[name].js',
|
|
43
|
+
preserveModulesRoot: 'src',
|
|
44
|
+
preserveModules: true,
|
|
45
|
+
exports: 'named',
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
plugins: [
|
|
51
|
+
vue(),
|
|
52
|
+
vueJsx(),
|
|
53
|
+
Unocss(),
|
|
54
|
+
VueMacros({
|
|
55
|
+
setupComponent: false,
|
|
56
|
+
setupSFC: false,
|
|
57
|
+
plugins: {
|
|
58
|
+
vue: vue({
|
|
59
|
+
isProduction: false,
|
|
60
|
+
}),
|
|
61
|
+
vueJsx: vueJsx(),
|
|
62
|
+
},
|
|
63
|
+
}),
|
|
64
|
+
dts({
|
|
65
|
+
entryRoot: 'src',
|
|
66
|
+
outputDir: 'dist/types',
|
|
67
|
+
tsConfigFilePath: path.resolve(__dirname, './tsconfig.json'),
|
|
68
|
+
skipDiagnostics: false,
|
|
69
|
+
}),
|
|
70
|
+
Components({
|
|
71
|
+
resolvers: [AntDesignVueResolver({
|
|
72
|
+
importStyle: true,
|
|
73
|
+
resolveIcons: true,
|
|
74
|
+
})],
|
|
75
|
+
dts: 'src/types/components.d.ts',
|
|
76
|
+
deep: true,
|
|
77
|
+
}),
|
|
78
|
+
],
|
|
79
|
+
})
|