resolver-egretimp-plus 0.0.123 → 0.0.125

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,231 @@
1
+ import { Engine, Rule } from 'json-rules-engine'
2
+ import { hasOwn } from '../utils'
3
+ import { calcRelateCodes} from './ruleUtils'
4
+ import { EVENS_INFO, getEventPriority, runEvent } from './events'
5
+
6
+ const AlwayFlase = 'alwaysFalse'
7
+ const symbolOperatorMap = {
8
+ '1': 'greaterThan',
9
+ '2': 'greaterThanInclusive',
10
+ '3': 'lessThan',
11
+ '4': 'lessThanInclusive',
12
+ '5': 'customEqual',
13
+ '6': 'notEqual',
14
+ '7': 'fullInclude',
15
+ '8': 'regular',
16
+ }
17
+
18
+ export const conditionType = {
19
+ COMPONENT: 1, // 1: 组件
20
+ SYSTEM: 2, // 2: 系统参数
21
+ SELF: 3, // 3: 手动输入
22
+ COMPONENT_ENMU: 4, // 组件枚举
23
+ NULL: 5 // 空
24
+ }
25
+
26
+ export class RuleDriver {
27
+ engine = null
28
+ config = null
29
+ dynamicMapComp = null
30
+ _mapComp = null
31
+ penddingRules = null
32
+ recovers = null
33
+ engineRule = null
34
+ rule = null
35
+ lang = 'zh'
36
+ messageInstance = null
37
+ constructor({
38
+ rule,
39
+ config,
40
+ dynamicMapComp,
41
+ _mapComp,
42
+ lang,
43
+ messageInstance,
44
+ penddingRules = {}
45
+ }) {
46
+ this.config = config
47
+ this.dynamicMapComp = dynamicMapComp
48
+ this._mapComp = _mapComp
49
+ this.penddingRules = penddingRules
50
+ this.rule = rule
51
+ this.lang = lang
52
+ this.messageInstance = messageInstance
53
+
54
+ this.engineRule = new Rule({
55
+ conditions: {all:[]},
56
+ onSuccess: (...arg) => {
57
+ this.executeEvents(...arg)
58
+ },
59
+ onFailure: (...arg) => {
60
+ this.executeRecoveEvents(...arg)
61
+ }
62
+ })
63
+ this.engine = new Engine()
64
+ this.engine.addRule(this.engineRule)
65
+ this.polyfillOperators()
66
+ }
67
+ run(rootValue, isInit) {
68
+ const conditions = this.generateRuleConditions(this.rule)
69
+ this.engineRule?.setConditions(conditions)
70
+ this.engine.updateRule(this.engineRule)
71
+ this.isInit = isInit // 执行run的时候传进来,表示是否时初始化的时候执行的
72
+ this.engine.run({
73
+ rootValue,
74
+ isInit
75
+ })
76
+ }
77
+ async executeEvents(...arg) {
78
+ console.log('executeEvents arg==:', arg)
79
+ const isInit = await arg[1]?.factValue?.('isInit')
80
+ const { pmRuleTargetEventVoList, pmRuleTargetEventVOList } = this.rule
81
+ const EventVoList = (pmRuleTargetEventVoList || pmRuleTargetEventVOList).sort((a, b) => getEventPriority(a.eventId) - getEventPriority(b.eventId))
82
+ this.recovers = runEvent.call(this, EventVoList, isInit)
83
+ }
84
+ async executeRecoveEvents(...arg) {
85
+ console.log('executeRecoveEvents arg==:', arg)
86
+ if (this.recovers) {
87
+ this.recovers?.reverse?.()?.forEach(recover => {
88
+ if (recover) {
89
+ recover()
90
+ }
91
+ })
92
+ } else {
93
+ const { pmRuleTargetEventVoList, pmRuleTargetEventVOList } = this.rule
94
+ const initRecoverEventVoList = (pmRuleTargetEventVoList || pmRuleTargetEventVOList).map(item => {
95
+ const ret = {
96
+ ...item
97
+ }
98
+ ret.eventId = EVENS_INFO[item.eventId]?.recover
99
+ return ret
100
+ })
101
+ const EventVoList = initRecoverEventVoList.sort((a, b) => getEventPriority(b.eventId) - getEventPriority(a.eventId))
102
+ const isInit = await arg[1]?.factValue?.('isInit')
103
+ runEvent.call(this, EventVoList, isInit)
104
+ }
105
+ }
106
+ generateRuleConditions(rule) {
107
+ const { eventExpress } = rule || {}
108
+ if (!eventExpress) return false
109
+
110
+ const expressObj = JSON.parse(eventExpress)
111
+ return this.paseRuleExpress(expressObj)
112
+ }
113
+ paseRuleExpress(expressInfo) {
114
+ const { relation, conditions } = expressInfo
115
+ const key = relation == '1' ? 'all' : 'any'
116
+ return {
117
+ [key]: conditions?.map(condition => {
118
+ if (hasOwn(condition ,'relation') && hasOwn(condition ,'conditions')) {
119
+ return this.paseRuleExpress(condition)
120
+ } else {
121
+ return this.generateRuleFace(condition)
122
+ }
123
+ })
124
+ }
125
+ }
126
+ polyfillOperators() {
127
+ this.engine?.addOperator('customEqual', (factValue, jsonValue) => {
128
+ return factValue == jsonValue || (!jsonValue && isArray(factValue) && !factValue.length)
129
+ })
130
+ this.engine?.addOperator('fullInclude', (factValue, jsonValue) => {
131
+ if (typeof factValue === 'number') factValue = `${factValue}`
132
+ if (Array.isArray(factValue) || typeof factValue === 'string') {
133
+ return factValue.indexOf(jsonValue) > -1
134
+ }
135
+ return false
136
+ })
137
+ this.engine?.addOperator('regular', (factValue, jsonValue) => {
138
+ if (['string', 'number'].includes(typeof jsonValue)) {
139
+ const reg = new RegExp(jsonValue)
140
+ return reg.test(factValue)
141
+ }
142
+ return false
143
+ })
144
+ this.engine?.addOperator('AlwayFlase', (factValue, jsonValue) => {
145
+ return false
146
+ })
147
+ }
148
+ getRelateCodes(path) {
149
+ return calcRelateCodes.call(this, path)
150
+ }
151
+ generateRuleFace(condition) {
152
+ let retCondition = {
153
+ fact: 'rootValue',
154
+ path: '',
155
+ operator: symbolOperatorMap[condition.symbol],
156
+ value: '',
157
+ }
158
+ const { refType, refValue, targetType, targetValue } = condition
159
+ if (conditionType.COMPONENT == refType) {
160
+ const configKeys = this.getRelateCodes(refValue)
161
+ if (configKeys.length > 1) {
162
+ console.error('ref config must single config', this.config, configCodes, path)
163
+ retCondition.operator = AlwayFlase
164
+ return
165
+ }
166
+ if (!configKeys.length) {
167
+ retCondition.operator = AlwayFlase
168
+ console.error('rule get refType Config fail,', '\nrefType:', refType, '\nrule:', this.rule, '\nconfig:', this.config)
169
+ return
170
+ }
171
+ retCondition.path = `$.${configKeys[0]?.replaceAll('->', '.')}`
172
+ }
173
+ if (conditionType.COMPONENT == targetType) {
174
+ retCondition.value = {
175
+ fact: 'rootValue',
176
+ }
177
+ const configKeys = this.getRelateCodes(targetValue)
178
+ if (configKeys.length > 1) {
179
+ console.error('target config must single config', this.config, configCodes, path)
180
+ retCondition.operator = AlwayFlase
181
+ return
182
+ }
183
+ if (!configKeys.length) {
184
+ retCondition.operator = AlwayFlase
185
+ console.error('rule get targetType Config fail,', '\nrefType:', refType, '\nrule:', this.rule, '\nconfig:', this.config)
186
+ return
187
+ }
188
+ retCondition.value.path = `$.${configKeys[0]?.replaceAll('->', '.')}`
189
+ }
190
+ if (conditionType.SYSTEM == targetType) {
191
+ retCondition.value = getSystemArgVal(targetValue)
192
+ }
193
+ if (conditionType.SELF == targetType) {
194
+ retCondition.value = targetValue
195
+ }
196
+ if (conditionType.COMPONENT_ENMU == targetType) {
197
+ retCondition.value = targetValue
198
+ }
199
+ if (conditionType.NULL == targetType) {
200
+ retCondition.value = null
201
+ }
202
+ console.log('face, refVal===:', refValue, 'targetValue==:', targetValue, 'condition==:', retCondition)
203
+ return retCondition
204
+ }
205
+ }
206
+
207
+
208
+ function getSystemArgVal(flag) {
209
+ const now = new Date()
210
+ switch (flag) {
211
+ case systemFlag.currentDate:
212
+ return formatDate(new Date(),"yyyy-MM-dd")
213
+ case systemFlag.currentTimestamp:
214
+ return new Date().getTime()
215
+ case systemFlag.CurrentYear:
216
+ return formatDate(new Date(),"yyyy")
217
+ case systemFlag.CurrentMonth:
218
+ return formatDate(new Date(),"MM")
219
+ case systemFlag.CurrentDay:
220
+ return formatDate(new Date(),"dd")
221
+ case systemFlag.CurrentAfter30Day:
222
+ now.setDate(now.getDate() + 30);
223
+ return formatDate(now, "yyyy-MM-dd")
224
+ case systemFlag.CurrentBefore30Day:
225
+ now.setDate(now.getDate() - 30);
226
+ return formatDate(now, "yyyy-MM-dd")
227
+ default:
228
+ return flag
229
+ }
230
+ }
231
+
@@ -0,0 +1,108 @@
1
+ import { hasOwn } from "../utils"
2
+
3
+ export function getRelateConfigKeys(keys = [], path = '', relatePath = '') {
4
+ const pathArr = path ? path.split('->') : []
5
+ const relatePathArr = relatePath ? relatePath.split('->') : []
6
+ let diffIdx = -1 // 此标识表示,是从那个所以开始,code不一样了
7
+ let currentIdx = 0
8
+ while(diffIdx === -1 && currentIdx < pathArr.length && currentIdx < relatePathArr.length) {
9
+ const pathCode = pathArr[currentIdx]
10
+ const pathCodeReg = new RegExp(`^${pathCode}(\\[\\d+\\])?$`)
11
+ const relateCode = relatePathArr[currentIdx]
12
+ if (pathCodeReg.test(relateCode)) {
13
+ pathArr.splice(currentIdx, 1, relateCode)
14
+ currentIdx++
15
+ } else {
16
+ diffIdx = currentIdx
17
+ }
18
+ }
19
+ const normalPath = pathArr.reduce((ret, pathCode) => {
20
+ const noramlPathCode = pathCode.replace(/([\[\]]{1})/g, (_,b) => {return `\\${b}`})
21
+ return ret + (ret ? `->${noramlPathCode}(\\[\\d+\\])?` : `${noramlPathCode}(\\[\\d+\\])?`)
22
+ }, '')
23
+ const normalPathReg = new RegExp(`^${normalPath}$`)
24
+ return keys.filter(code => {
25
+ return normalPathReg.test(code)
26
+ })
27
+ }
28
+
29
+ export function calcRelateCodes(path) {
30
+ const dynamicMapCompKeys = Object.keys(this.dynamicMapComp || {})
31
+ const { dynamicHireRelat = '' } = this.config || {}
32
+ const configCodes = getRelateConfigKeys(dynamicMapCompKeys, path, dynamicHireRelat,)
33
+ if (!configCodes.length) {
34
+ if (this._mapComp[path]) {
35
+ if (!this.penddingRules[path]) {
36
+ this.penddingRules[path] = []
37
+ }
38
+ if (!this.penddingRules[path].some((item) => item?.rule === this?.rule && item?.config === this?.config)) {
39
+ this.penddingRules[path].push(this)
40
+ }
41
+ }
42
+ }
43
+ return configCodes
44
+ }
45
+
46
+ export function getConfigValue(codesStr = '', refVal) {
47
+ if (!codesStr) return ''
48
+ const { config} = this
49
+ const { hireRelat = '' } = config
50
+ if (hireRelat === codesStr) {
51
+ // 如果走到这里,表示是触发条件中的一个条件是当前的配置项(config)
52
+ return config.bindValue
53
+ }
54
+ const configs = getCurrentComp.call(this, codesStr)
55
+ if (configs.length !== 1) {
56
+ return null
57
+ }
58
+ const retVal = refVal ? configs[0]?.refValue : configs[0]?.bindValue
59
+ return retVal
60
+ }
61
+
62
+
63
+ /**
64
+ * 根据code path 获取到对应的组件或者label
65
+ */
66
+ export function getCurrentComp(codesStr) {
67
+ if (!codesStr) return null
68
+ const { dynamicMapComp } = this
69
+ const configCodes = calcRelateCodes.call(this, codesStr)
70
+ return configCodes.map(code => {
71
+ return dynamicMapComp[code]
72
+ })
73
+ }
74
+
75
+ // 设置对应的值
76
+ export function setFormVal(pathStr, val) {
77
+ if (!pathStr) {
78
+ return
79
+ }
80
+ const configs = getCurrentComp.call(this, pathStr)
81
+ configs.forEach(cg => {
82
+ hasOwn(cg, 'refValue') && (cg.refValue = val)
83
+ })
84
+ }
85
+
86
+ export function greaterThan(val, targ) {
87
+ const valCanTran = canTransNumber(val)
88
+ const tragCanTran = canTransNumber(targ)
89
+ if (valCanTran && tragCanTran) {
90
+ return Number(val) > Number(targ)
91
+ } else {
92
+ return val + '' > targ + ''
93
+ }
94
+ }
95
+
96
+ export function lessThan(val, targ) {
97
+ const valCanTran = canTransNumber(val)
98
+ const tragCanTran = canTransNumber(targ)
99
+ if (valCanTran && tragCanTran) {
100
+ return Number(val) < Number(targ)
101
+ } else {
102
+ return val + '' < targ + ''
103
+ }
104
+ }
105
+
106
+ export function canTransNumber(val) {
107
+ return !isNaN(Number(val))
108
+ }
@@ -41,3 +41,4 @@
41
41
  @import './tree.scss';
42
42
  @import './steps.scss';
43
43
  @import './dialog.scss';
44
+ @import './textarea.scss';
@@ -0,0 +1,3 @@
1
+ .el-textarea {
2
+ --el-input-text-color: #1f2329;
3
+ }
@@ -0,0 +1,36 @@
1
+ export function getDomWidth(dom, offset = 0) {
2
+ const range = document.createRange()
3
+ range.setStart(dom, 0)
4
+ range.setEnd(dom, dom?.childNodes?.length)
5
+ return range.getBoundingClientRect()?.width - offset
6
+ }
7
+
8
+ export function getDomComputed(el) {
9
+ return window.getComputedStyle(el, null)
10
+ }
11
+
12
+ export function getPadding(el) {
13
+ const domCss = window.getComputedStyle(el, null)
14
+ const pl = Number.parseInt(domCss.paddingLeft, 10) || 0
15
+ const pr = Number.parseInt(domCss.paddingRight, 10) || 0
16
+
17
+ return {
18
+ left: pl,
19
+ right: pr
20
+ }
21
+ }
22
+
23
+ export function calcTextLength(text, fontSize) {
24
+ if (!text) return 0
25
+ const size = Number.parseInt(fontSize)
26
+ let realLength = 0
27
+ for(let i = 0; i < text.length; i ++) {
28
+ const charCode = text.charCodeAt(i)
29
+ if (charCode >= 0 && charCode <= 128) {
30
+ realLength += Number.parseFloat((0.54714 * size).toFixed(5))
31
+ } else {
32
+ realLength += 1 * size
33
+ }
34
+ }
35
+ return realLength
36
+ }
File without changes
@@ -1,13 +0,0 @@
1
-
2
-
3
- class RuleDriver {
4
- constructor() {
5
-
6
- }
7
- executeRule(rule) {
8
-
9
- }
10
- executeRules(rules) {
11
-
12
- }
13
- }
File without changes
File without changes