resolver-egretimp-plus 0.1.129 → 0.1.131

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "resolver-egretimp-plus",
3
- "version": "0.1.129",
3
+ "version": "0.1.131",
4
4
  "description": "交付体验渲染",
5
5
  "main": "./dist/web/index.js",
6
6
  "module": "./dist/web/index.js",
@@ -1,5 +1,5 @@
1
1
  import { computed, defineAsyncComponent, getCurrentInstance, inject, onBeforeMount, provide, ref, watch } from 'vue'
2
- import { COFNGI_KEY_EVENT_FLAG, commonPropsType, definePrivatelyProp, EXECTE_CLICK_EVENT_COMPONENTS, findComponent, getComponentPropsKeys, getComponentSolt, hasOwn, isPlainObject } from './utils/index.js'
2
+ import { COFNGI_KEY_EVENT_FLAG, commonPropsType, definePrivatelyProp, EXECTE_CLICK_EVENT_COMPONENTS, findComponent, getComponentPropsKeys, getComponentSolt, hasOwn, isFunction, isPlainObject } from './utils/index.js'
3
3
  import { useVmodels } from './hooks/index.js'
4
4
  import { getRenderComponentProps, generateFormItemPolyfill } from './utils/index.js'
5
5
  import rulesDriver, { recoverCb } from './rules/rulesDriver'
@@ -10,6 +10,7 @@ import { useRouter } from 'vue-router'
10
10
  import { onErrorCaptured } from 'vue'
11
11
  import LoadingComponent from './components/loadingComponent/LoadingComponent.vue'
12
12
  import { useConfigLoad } from './hooks/configLoad.js'
13
+ import { reactive } from 'vue'
13
14
 
14
15
  export default {
15
16
  name: 'AnalysisComponent',
@@ -53,6 +54,9 @@ export default {
53
54
  return ret
54
55
  })
55
56
  useConfigLoad(props.config)
57
+ const formContextKey = inject('_formContextKey')
58
+ const formContext = inject(formContextKey, {})
59
+ const _isH5 = inject('_isH5')
56
60
  const configsSet = inject('_configsSet')
57
61
  const ruleExecuter = inject('_ruleExecuter')
58
62
  const dialogReq = inject('_dialogReq', {})
@@ -101,7 +105,6 @@ export default {
101
105
  const onVnodeMounted = (e) => {
102
106
  definePrivatelyProp(props.config, 'vmIsBind', true)
103
107
 
104
-
105
108
  if (props.config.onVnodeMounted && typeof props.config.onVnodeMounted === 'function') {
106
109
  const context = {
107
110
  dataLoad: dataLoad
@@ -259,7 +262,58 @@ export default {
259
262
 
260
263
  provide('parent', props.config)
261
264
 
262
- const _isH5 = inject('_isH5')
265
+ if (OPEN_DATA_RULES) {
266
+ if (!_isH5?.value && props.config.renderby) {
267
+ provide(formContextKey, reactive({
268
+ ...formContext,
269
+ addField(field) {
270
+ if (!props.config?._formFields) {
271
+ definePrivatelyProp(props.config, '_formFields', [])
272
+ }
273
+ props.config?._formFields?.push(field)
274
+ formContext.addField(field)
275
+ },
276
+ removeField(field) {
277
+ const fields = props.config?._formFields
278
+ if (field.prop && fields) {
279
+ const idx = fields.indexOf(field)
280
+ if (idx !== -1) {
281
+ fields.splice(idx, 1)
282
+ }
283
+ }
284
+ formContext.removeField(field)
285
+ }
286
+ }))
287
+ }
288
+ } else {
289
+ // 在自定义组件中使用 form-item 进行声明的校验,这边进行兼容,可以在校验住的时候支持跳转
290
+ if (!_isH5?.value && props.config.renderby) {
291
+ provide(formContextKey, reactive({
292
+ ...formContext,
293
+ addField(field) {
294
+ if (field.validate && isFunction(field.validate)) {
295
+ const originValidate = field.validate
296
+ field.validate = function (...arg) {
297
+ const ret = originValidate.apply(this, arg)
298
+ Promise.resolve().catch
299
+ return ret?.then(ret => ret)?.catch(err => {
300
+ if (isPlainObject(err)) {
301
+ Object.keys(err).forEach(key => {
302
+ // 在自定义组件中form-item 校验失败之后,err 中绑定的 prop 属性手动替换成config 的dynamicHireRelat
303
+ err[props.config.dynamicHireRelat] = err[key]
304
+ delete err[key]
305
+ })
306
+ }
307
+ return Promise.reject(err)
308
+ }) || true
309
+ }
310
+ }
311
+ formContext.addField(field)
312
+ }
313
+ }))
314
+ }
315
+ }
316
+
263
317
  const onClick = (e, params) => {
264
318
  const context = {
265
319
  props,
@@ -67,6 +67,9 @@ const tabPaneProps = computed(() => {
67
67
  })
68
68
 
69
69
  const isLoaded = computed(() => {
70
+ if (props.config._notOpenLazy) {
71
+ return true
72
+ }
70
73
  if (OPEN_DATA_RULES) {
71
74
  return props?.config?.parent?._loadedNames?.includes(props.config?.metaCode)
72
75
  }
@@ -84,7 +84,11 @@ const value = computed({
84
84
  if (valueFormat === 'timestamp') {
85
85
  valueFormat = 'x'
86
86
  }
87
- modeValue.value = dayjs(val).format(valueFormat)
87
+ let currentVal = dayjs(val).format(valueFormat)
88
+ if (valueFormat === 'x') {
89
+ currentVal = dayjs(val).toDate().getTime()
90
+ }
91
+ modeValue.value = currentVal
88
92
  }
89
93
  })
90
94
  watch(value, () => {
@@ -146,9 +146,6 @@ const allInitEvents = {
146
146
  const { targetObj: target } = event
147
147
  if (!target) return
148
148
  const targetObj = `${target}`
149
- if (targetObj === 'PreInitiationTab1->tabPane3->tabPlane4->projectTab->purchaseSolution->purchaseContent->forBidPackage->bidPackage->purchaseMethodRow->supplierId') {
150
- debugger
151
- }
152
149
  setFormVal(targetObj, '', mapComp, rootValue, currentPath)
153
150
 
154
151
  },
@@ -6,6 +6,11 @@
6
6
  --el-checkbox-disabled-checked-input-border-color: #646A73;
7
7
  --el-checkbox-disabled-checked-icon-color: #FFFFFF;
8
8
  }
9
+ .el-checkbox__label {
10
+ max-width: 100%;
11
+ white-space: break-spaces;
12
+ }
13
+
9
14
  .el-checkbox__inner::after {
10
15
  border: 2px solid transparent;
11
16
  border-left: 0;
@@ -567,11 +567,13 @@ export function normalConfig({
567
567
 
568
568
  // _notOpenLazyopenLazy 属性
569
569
  // 如果是自定义组件,父层级组件都不能进行懒加载
570
- export function travelParentConfigLazy(config) {
571
- definePrivatelyProp(config, '_notOpenLazy', true)
572
- while (config.parent) {
570
+ export function travelParentConfigLazy(config, cb) {
571
+ while (config) {
572
+ if (!config.vmIsBind) {
573
+ definePrivatelyProp(config, '_notOpenLazy', true)
574
+ cb?.(config)
575
+ }
573
576
  config = config.parent
574
- definePrivatelyProp(config, '_notOpenLazy', true)
575
577
  }
576
578
  }
577
579
 
@@ -1100,7 +1102,7 @@ function generateFormItemPc (config, lang, compProps, params,) {
1100
1102
  if (isFormItem && slotName !== 'label') {
1101
1103
  slots.label = () => createFormLable(config, lang)
1102
1104
  }
1103
-
1105
+
1104
1106
  return (
1105
1107
  <formItemComp ref={(e) => {definePrivatelyProp(config, 'formItemVm', e)}} key={config.requiredFlag} class="custom-form-item" {...props}>{slots}</formItemComp>
1106
1108
  )
@@ -1174,7 +1176,7 @@ function getFormItemExtendProps(config, lang, params, compProps) {
1174
1176
  style.display = 'none'
1175
1177
  }
1176
1178
  return {
1177
- prop,
1179
+ prop: config._isValidated ? null : prop, // 如果是已经验证过的,就不需要再进行一次校验了
1178
1180
  rules: getFormItemRule(config, lang, params, compProps),
1179
1181
  class: {
1180
1182
  [`vertical-${config['label-vertical'] || config['labelVertical'] || 'center'}`]: true,
@@ -2,36 +2,38 @@ import { nextTick, toRaw } from "vue"
2
2
  import { calcDisable } from "./const"
3
3
  import { getFormItemRule, isCycleConfig, travelParentConfigLazy } from "./render"
4
4
  import AsyncValidator from 'async-validator'
5
+ import { definePrivatelyProp } from "./common"
6
+ import { computed } from "vue"
7
+ import { watch } from "vue"
8
+ import { ref } from "vue"
5
9
 
6
10
  export async function toValidate({
7
11
  rootConfig, rootValue, mode, lang, messageInstance,
8
12
  formRef, cb, dynamicMapComp
9
13
  }) {
14
+ const recoverCbs = []
10
15
  const flag = await validateConfig({
11
16
  validConfig: rootConfig,
12
17
  mode,
13
18
  lang,
14
19
  rootValue,
15
20
  dynamicMapComp,
16
- messageInstance
21
+ messageInstance,
22
+ recoverCbs
17
23
  })
18
- if (!flag) {
19
- if (!cb) {
20
- return formRef.value && formRef.value.validate().catch(err => {
21
- validFailAction(err, dynamicMapComp)
22
- return Promise.reject(err)
23
- })
24
- }
25
- return formRef.value && formRef.value.validate((valid, errInfo) => {
26
- errInfo && validFailAction(errInfo, dynamicMapComp)
27
- cb && cb(valid, errInfo)
24
+ if (!cb) {
25
+ const ret = formRef.value && formRef.value.validate().catch(err => {
26
+ return Promise.reject(err)
28
27
  })
29
- } else {
30
- if (!cb) {
31
- return Promise.resolve(true)
32
- }
33
- return cb?.(true)
28
+ ret.finally(() => {
29
+ recoverCbs?.forEach(cb => cb?.())
30
+ })
31
+ return ret
34
32
  }
33
+ return formRef.value && formRef.value.validate((valid, errInfo) => {
34
+ recoverCbs?.forEach(cb => cb?.())
35
+ cb && cb(valid, errInfo)
36
+ })
35
37
  }
36
38
 
37
39
  // 校验的一些附加动作, 例如校验失败,tab需要聚焦到失败tab页面,组件失败,需要展开
@@ -117,9 +119,10 @@ function validateConfig({
117
119
  lang,
118
120
  rootValue,
119
121
  dynamicMapComp,
120
- messageInstance
122
+ messageInstance,
123
+ recoverCbs = []
121
124
  }) {
122
- return travelConfig(validConfig, (config) => {
125
+ return travelConfig(validConfig, async (config) => {
123
126
  const compProps = {
124
127
  disabled: calcDisable(config, mode)
125
128
  }
@@ -136,24 +139,52 @@ function validateConfig({
136
139
  messageInstance
137
140
  }
138
141
  const rules = getFormItemRule(config, lang, params, compProps, true)
139
- if (rules && rules.length) {
140
- const validator = new AsyncValidator({
141
- [config.dynamicHireRelat]: rules
142
- })
143
-
144
- async function toValidate() {
145
- try {
146
- await validator.validate({[config.dynamicHireRelat]: toRaw(config?.refValue)})
147
- } catch (error) {
148
- travelParentConfigLazy(config)
149
- await nextTick()
150
- validFailAction({[config.dynamicHireRelat]: true}, dynamicMapComp)
151
- return Promise.reject()
142
+ let promiseRet = null
143
+ if (config._formFields) {
144
+ const valids = config._formFields.map(field => field.validate())
145
+ promiseRet = Promise.all(valids)
146
+ } else {
147
+ if (rules && rules.length) {
148
+ const validator = new AsyncValidator({
149
+ [config.dynamicHireRelat]: rules
150
+ })
151
+ promiseRet = validator.validate({[config.dynamicHireRelat]: toRaw(config?.refValue)})
152
+ }
153
+ }
154
+ if (promiseRet) {
155
+ try {
156
+ await promiseRet
157
+ // 如果走到这一步,说明验证通过了
158
+ definePrivatelyProp(config, '_isValidated', true)
159
+ recoverCbs.push(() => {
160
+ // 恢复未验证状态
161
+ config._isValidated = false
162
+ })
163
+ } catch (error) {
164
+ const vnodeLoadedList = ref([]) // 需要设置显示的组件的 config 集合
165
+ function initVnodeLoadedList(config) {
166
+ vnodeLoadedList.value.push(config)
152
167
  }
153
- return true
168
+ travelParentConfigLazy(config, initVnodeLoadedList)
169
+ // 所有 config 上的 vmIsBind 为true 的时候表示组件都加载了
170
+ const isLoaded = computed(() => {
171
+ return vnodeLoadedList.value.every(config => config.vmIsBind)
172
+ })
173
+
174
+ await new Promise((resolve) => {
175
+ watch(isLoaded, (val) => {
176
+ if (val) {
177
+ resolve()
178
+ }
179
+ }, {
180
+ immediate: true
181
+ })
182
+ })
183
+ validFailAction({[config.dynamicHireRelat]: true}, dynamicMapComp)
184
+ return Promise.reject()
154
185
  }
155
- return toValidate()
156
186
  }
187
+ return true
157
188
  })
158
189
  }
159
190