Skip to content

Commit

Permalink
fix:table slot edit params should not get alert (#802)
Browse files Browse the repository at this point in the history
* fix:table notch saving error message

* fix: change slotparams cause warning

* fix: change by review

* fix: typo parma -> param

---------

Co-authored-by: chilingling <[email protected]>
  • Loading branch information
ianxinnew and chilingling authored Sep 28, 2024
1 parent 452563a commit 4ea63ab
Showing 1 changed file with 52 additions and 39 deletions.
91 changes: 52 additions & 39 deletions packages/common/component/MetaJsSlot.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
</div>
<tiny-form-item
:prop="paramsPropPath(index)"
:rules="[{ validator: parmasStringValidator, trigger: 'blur' }]"
:rules="[{ validator: paramsStringValidator, trigger: 'blur' }]"
class="slot-name-form-item"
>
<tiny-input
v-model="slot.params"
class="use-slot-params"
@change="validParmas(slot, paramsPropPath(index))"
@change="validParams(paramsPropPath(index), slot)"
></tiny-input>
</tiny-form-item>
</div>
Expand Down Expand Up @@ -84,67 +84,81 @@ export default {
const paramsPropPath = (index) => `${index}.params`
const parmasStringValidator = (rule, value, callback) => {
if (value && value.split(',').some((parma) => !verifyJsVarName(parma))) {
const paramsStringValidator = (rule, value, callback) => {
if (value && value.split(',').some((param) => !verifyJsVarName(param))) {
callback(new Error('仅支持JavaScript中有效的变量名'))
} else {
callback()
}
}
const toggleSlot = (idx, { bind, name, params = '' }) => {
const slotInfo = {
[name]: {
type: 'JSSlot',
value: [
{
componentName: 'div'
}
]
}
const updateSlotParams = (slotData) => {
emit('update:modelValue', slotData)
// 更新当前选中组件的根属性,不更新在jsslot中的数据非响应式
const [propsName] = path.split('.')
const schema = useProperties().getSchema()
schema.props[propsName] = JSON.parse(JSON.stringify(schema.props[propsName]))
}
const setSlotParams = ({ name, params = '' }) => {
if (!props.modelValue?.[name]) {
return
}
const slotData = { ...slotInfo, ...(props.modelValue || {}) }
const slotData = { ...(props.modelValue || {}) }
if (params.length) {
slotData[name].params = params.split(',')
} else {
delete slotData[name].params
}
updateSlotParams(slotData)
}
const toggleSlot = (idx, { bind, name, params = '' }) => {
// 原本绑定的,解除绑定
if (bind) {
useModal().confirm({
title: '提示',
message: '关闭后插槽内的内容将被清空,是否继续?',
status: 'info',
exec: () => {
slotList.value[idx].bind = false
delete slotData[name]
emit('update:modelValue', slotData)
const [propsName] = path.split('.')
const schema = useProperties().getSchema()
schema.props[propsName] = JSON.parse(JSON.stringify(schema.props[propsName]))
},
cancel: () => {}
const { [name]: _deleted, ...rest } = { ...(props.modelValue || {}) }
updateSlotParams(rest)
}
})
} else {
slotList.value[idx].bind = true
return
}
emit('update:modelValue', slotData)
// 更新当前选中组件的根属性,不根新在jsslot中的数据非响应式
const [propsName] = path.split('.')
const schema = useProperties().getSchema()
schema.props[propsName] = JSON.parse(JSON.stringify(schema.props[propsName]))
}
// 未绑定的,新增绑定
slotList.value[idx].bind = true
const slotInfo = {
[name]: {
type: 'JSSlot',
value: [
{
componentName: 'div'
}
]
}
}
if (params.length) {
slotInfo[name].params = params.split(',')
}
const setParams = (slot) => {
slot.bind && toggleSlot(true, slot)
updateSlotParams({ ...(props.modelValue || {}), ...slotInfo })
}
const validParmas = (slot, parmasPath) => {
slotRef.value.validateField([parmasPath], (tips) => {
if (!tips) {
setParams(slot)
const validParams = (paramsPath, slot) => {
slotRef.value.validateField([paramsPath], (error) => {
if (!error) {
slot.bind && setSlotParams(slot)
}
})
}
Expand All @@ -159,9 +173,8 @@ export default {
slotList,
paramsPropPath,
slotRef,
parmasStringValidator,
validParmas,
setParams,
paramsStringValidator,
validParams,
state,
componentsMap
}
Expand Down

0 comments on commit 4ea63ab

Please sign in to comment.