d-render
Version:
基于 Element Plus 二次封装的数据驱动渲染组件库 - 表单、搜索表单、表格配置化渲染
104 lines (101 loc) • 2.85 kB
JavaScript
import { defineComponent, computed, createVNode, mergeProps } from 'vue';
import CipFormItem from '../cip-form-item';
var __defProp = Object.defineProperty;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
};
var columnInput = /* @__PURE__ */ defineComponent({
name: "ColumnInput",
props: {
config: {
type: Object,
required: true
},
fieldKey: {
type: String
},
columnKey: String,
index: {
type: Number,
required: true
},
model: Object,
tableDependOnValues: Object,
propertyKey: [String, Number],
tableRuleKey: String,
tableData: Array,
updateData: {
type: Function,
required: true
},
rowEdit: {
type: Boolean,
default: void 0
}
},
setup(props) {
const computedConfig = computed(() => {
const config = __spreadValues({}, props.config);
config.width = "100%";
config.hideLabel = true;
const writable = props.config.writable;
if (writable) {
config.ruleKey = `${props.tableRuleKey}.${props.propertyKey}.${props.columnKey}`;
}
if (!writable) {
config.writable = false;
config.readable = true;
if (!config.dynamic) {
config.dependOn = [];
}
}
return config;
});
const fromItemProps = computed(() => {
let {
index,
model,
columnKey: fieldKey,
tableDependOnValues,
tableData,
updateData
} = props;
return {
model,
// 数据
fieldKey,
// 整合tableData对象的键值
tableDependOnValues,
// table data依赖数据
tableData,
// table的数据
config: computedConfig.value,
// 改变后的配置
inTable: true,
// 特殊标记
rowEdit: props.rowEdit,
// 行编辑(因为需要控制configConfig导致的编辑状态变化,所以只能交给DrFormItem处理)
"onUpdate:model": (val) => {
model = val;
updateData(val, index);
}
};
});
return () => createVNode(CipFormItem, mergeProps({
"style": "height: 30px;"
}, fromItemProps.value), null);
}
});
export { columnInput as default };