Skip to content

Commit 7cc98a1

Browse files
authored
fix: onUpdate prefix event name faild to save (opentiny#1778)
1 parent 8319cbf commit 7cc98a1

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

packages/common/js/verification.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*/
1212

1313
export const REGEXP_EVENT_NAME = /^[a-z]+([A-Z][a-z]*)*$/
14+
export const REGEXP_UPDATE_EVENT_NAME = /^onUpdate:[a-zA-Z_$][\w$]*$/
1415

1516
export const verifyEventName = (name: string) => REGEXP_EVENT_NAME.test(name)
1617

packages/plugins/block/src/BlockEventForm.vue

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@
4141
/* metaService: engine.plugins.blockmanage.BlockEventForm */
4242
import { computed, reactive, watch } from 'vue'
4343
import { 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'
4549
import {
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

Comments
 (0)