4141/* metaService: engine.plugins.blockmanage.BlockEventForm */
4242import { computed , reactive , watch } from ' vue'
4343import { Input as TinyInput , Form as TinyForm , FormItem as TinyFormItem , TinyPopover } from ' @opentiny/vue'
44- import { REGEXP_EVENT_NAME , verifyEventName } from ' @opentiny/tiny-engine-common/js/verification'
44+ import {
45+ REGEXP_EVENT_NAME ,
46+ REGEXP_UPDATE_EVENT_NAME ,
47+ verifyEventName
48+ } from ' @opentiny/tiny-engine-common/js/verification'
4549import {
4650 getEditBlockPropertyList ,
4751 getEditBlockEvents ,
@@ -106,16 +110,15 @@ export default {
106110 const rules = {
107111 eventName: [
108112 {
109- pattern: REGEXP_EVENT_NAME ,
110- validator : (rule : any /* IFormInnerRule */ , value : string , callback : (e ? : Error ) => void ) => {
113+ validator : (_rule : any /* IFormInnerRule */ , value : string , callback : (e ? : Error ) => void ) => {
111114 if (isUpdateEvent .value ) {
112- const matched = / ^ onUpdate: [ a-zA-Z _$][ \w $] * $ / .test (value )
115+ const matched = REGEXP_UPDATE_EVENT_NAME .test (value )
113116 const propertyMatched = propertys .value .some ((item ) => item .property === value .replace (' onUpdate:' , ' ' ))
114117 return matched && propertyMatched
115118 ? callback ()
116119 : callback (new Error (` ${value } 需要有对应的 ${value .replace (' onUpdate:' , ' ' )} 在属性中定义 ` ))
117120 }
118- if (! rule . pattern .test (value )) {
121+ if (! REGEXP_EVENT_NAME .test (value )) {
119122 callback (new Error (eventNameTip ))
120123 } else {
121124 callback ()
@@ -134,7 +137,12 @@ export default {
134137 )
135138
136139 const changeEventName = () => {
137- if (formData .eventName !== getEditEventName () && verifyEventName (formData .eventName )) {
140+ const isEventNameValid = isUpdateEvent .value
141+ ? REGEXP_UPDATE_EVENT_NAME .test (formData .eventName ) &&
142+ propertys .value .some ((item : any ) => item .property === formData .eventName .replace (' onUpdate:' , ' ' ))
143+ : verifyEventName (formData .eventName )
144+
145+ if (formData .eventName !== getEditEventName () && isEventNameValid ) {
138146 renameBlockEventName (formData .eventName , getEditEventName ())
139147 }
140148 }
0 commit comments