Skip to content

Commit

Permalink
feat linkage config
Browse files Browse the repository at this point in the history
  • Loading branch information
hyl committed Dec 7, 2024
1 parent 008b78c commit 0794fb3
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 38 deletions.
4 changes: 2 additions & 2 deletions packages/config/locales/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ export default {
emptyTip: '未选中字段',
linkage: {
text: '联动',
action1: '配置项联动',
action2: '值联动'
action1: '配置联动',
action2: '数据联动'
}
},
tab2: {
Expand Down
2 changes: 2 additions & 0 deletions packages/config/template/__test__/satisfaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ describe('template satisfaction', async () => {

await satisfactionEl[0].setValue(true)

await wait()

expect(wrapper.vm.formValues).toStrictEqual({ satisfaction: 5 })

expect(wrapper.find('.TextArea-improvementSuggestions').exists()).toBe(false)
Expand Down
15 changes: 14 additions & 1 deletion packages/form-design/Right/AttrEdit/LinkageConfig/Config.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const handleUseQuick = () => {
designInstance.updateCurrent(newCurrent)
}
if (type === 'computeVar') {
if (type === 'computeVar' && compute.length > 1) {
const [computeType, valueType] = compute
let all = variable.join('.')
Expand All @@ -66,6 +66,19 @@ const handleUseQuick = () => {
const newCurrent = setDataByPath(designInstance.current!, name, `{{ ${all} }}`)
designInstance.updateCurrent(newCurrent)
}
if (type === 'computeVar' && compute.length === 1) {
const [bool] = compute
const parseBoolean = bool.replaceAll('true', '!!').replaceAll('false', '!')
const newCurrent = setDataByPath(
designInstance.current!,
name,
`{{ ${parseBoolean}${variable.join('.')} }}`
)
designInstance.updateCurrent(newCurrent)
}
})
}
</script>
Expand Down
57 changes: 22 additions & 35 deletions packages/form-design/Right/AttrEdit/LinkageConfig/configSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const basicField = [
{ label: '占位提示', value: 'props.placeholder' }
]

const selectKeys = ['Select', 'Radio', 'Checkbox']

const extendChildren = (list: CascaderOptions, children: CascaderOptions): CascaderOptions => {
return list.map((item) => {
if (item.children) {
Expand All @@ -37,22 +39,14 @@ export const quickSchema = (schema: FormSchema) => {
}))
},
{
label: '选择类字段数据源-$selectData',
label: '选中项数据源-$selectData',
value: 'value2',
children: [
{
label: '选项2-1',
value: 'value2-1'
},
{
label: '选项2-2',
value: 'value2-2'
},
{
label: '选项2-3',
value: 'value2-2'
}
]
children: schema.items
.filter((item) => selectKeys.includes(item.component))
.map((item) => ({
label: `【${item.label}】数据源`,
value: `$selectData.${item.name}`
}))
}
]

Expand All @@ -62,20 +56,6 @@ export const quickSchema = (schema: FormSchema) => {
value: 'var',
children: varOptions
},
{
label: '布尔值',
value: 'boolean',
children: [
{
label: 'true',
value: true
},
{
label: 'false',
value: false
}
]
},
{ label: '手写字符串', value: 'strValue' },
{ label: '手写数字', value: 'numValue' }
]
Expand All @@ -95,11 +75,19 @@ export const quickSchema = (schema: FormSchema) => {
label: '小于',
value: 'less',
children: valueOptions
},
{
label: '为真',
value: 'true',
children: []
},
{
label: '为假',
value: 'false',
children: []
}
]



// const conditionOptions: CascaderOptions = extendChildren(varOptions, compareOptions)

// console.log(conditionOptions)
Expand Down Expand Up @@ -133,7 +121,7 @@ export const quickSchema = (schema: FormSchema) => {
{
label: '判断变量',
value: 'computeVar'
},
}
// {
// label: '条件判断',
// value: 'conditionVar'
Expand All @@ -148,7 +136,7 @@ export const quickSchema = (schema: FormSchema) => {
{
component: 'Cascader',
name: 'variable',
label: '选择变量',
label: '变量',
hidden: '{{ $item.type !== "var" && $item.type !== "computeVar"}}',
props: {
placeholder: '请选择...',
Expand All @@ -159,7 +147,6 @@ export const quickSchema = (schema: FormSchema) => {
options: varOptions
}
},


{
component: 'Cascader',
Expand Down Expand Up @@ -187,7 +174,7 @@ export const quickSchema = (schema: FormSchema) => {
name: 'numValue',
label: '手写数字',
hidden: '{{ !$item.compute.includes("numValue") }}'
},
}

// {
// component: 'Cascader',
Expand Down

0 comments on commit 0794fb3

Please sign in to comment.