Skip to content

Commit

Permalink
feat: 支持深度数据
Browse files Browse the repository at this point in the history
  • Loading branch information
greper committed Oct 25, 2022
1 parent d38f5ad commit 3ca871e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
18 changes: 15 additions & 3 deletions packages/fast-crud/src/components/crud/fs-form-item.vue
@@ -1,10 +1,12 @@
<template>
<component
:is="$fsui.formItem.name"
v-if="item"
class="fs-form-item"
:[$fsui.formItem.prop]="item?.key"
:[$fsui.formItem.prop]="computedKey"
v-bind="item"
:path="item?.key"
:path="item.key"
:rule-path="item.key"
>
<template #label>
{{ item.label || item.title }}
Expand Down Expand Up @@ -110,13 +112,23 @@ export default {
const computedHelperTooltip = computed(() => {
return _.merge({}, props.item.helper?.tooltip, props.helper?.tooltip);
});
const computedKey = computed(() => {
if (props.item == null) {
return;
}
if (props.item.key.indexOf(".") >= 0) {
return props.item.key.split(".");
}
return props.item.key;
});
return {
updateModelValue,
buildItemScope,
getComponentRef,
componentRenderRef,
computedHelperPosition,
computedHelperTooltip
computedHelperTooltip,
computedKey
};
}
};
Expand Down
13 changes: 8 additions & 5 deletions packages/fast-crud/src/components/crud/fs-form.vue
Expand Up @@ -252,13 +252,16 @@ export default {
// 初始数据赋值
_.each(computedColumns.value, (item, key) => {
form[key] = undefined;
_.set(form, key, undefined);
const defValue = unref(item.value);
if (defValue !== undefined) {
form[key] = defValue;
_.set(form, key, defValue);
}
if (initialForm && initialForm[key] !== undefined) {
form[key] = initialForm[key];
if (initialForm) {
const value = _.get(initialForm, key);
if (!!value) {
_.set(form, key, value);
}
}
});
//form.valueBuilder
Expand All @@ -267,7 +270,7 @@ export default {
return;
}
_.each(computedColumns.value, (item, key) => {
let value = form[key];
let value = _.get(form, key);
if (item.valueBuilder) {
item.valueBuilder({
value,
Expand Down
6 changes: 3 additions & 3 deletions packages/fast-crud/src/components/crud/fs-table.jsx
Expand Up @@ -248,7 +248,7 @@ export default {
return {
...scope,
key: item.key,
value: row[item.key],
value: _.get(row, item.key),
row,
form,
getComponentRef: (key) => {
Expand Down Expand Up @@ -292,9 +292,9 @@ export default {
return getContextFn(item, scope);
};
const vModel = {
modelValue: scope[tableColumnCI.row][item.key],
modelValue: _.get(scope[tableColumnCI.row], item.key),
"onUpdate:modelValue": (value) => {
scope[tableColumnCI.row][item.key] = value;
_.set(scope[tableColumnCI.row], item.key, value);
const newScope = getContextFn(item, scope);
ctx.emit("value-change", newScope);
if (item.valueChange) {
Expand Down

0 comments on commit 3ca871e

Please sign in to comment.