d-render
Version:
数据渲染库 - form、table、search-form
79 lines (76 loc) • 2.27 kB
JavaScript
import { defineComponent, computed, ref, provide, reactive, watch, createVNode } from 'vue';
import CipForm from '../cip-form';
var index = /* @__PURE__ */ defineComponent({
name: "CipFormRender",
props: {
scheme: Object,
schema: {
type: Object,
required: true
},
model: {
type: Object,
required: true
},
equipment: {
type: String,
default: "pc"
},
service: Object,
dataBus: Function
},
emits: ["update:model"],
setup(props, {
emit,
expose
}) {
const schemaBridge = computed(() => {
var _a;
return (_a = props.schema) != null ? _a : props.scheme;
});
const cipFormRef = ref(null);
const fieldList = computed(() => schemaBridge.value.list || []);
const labelPosition = computed(() => schemaBridge.value.labelPosition || "right");
const labelWidth = computed(() => schemaBridge.value.labelWidth || 100);
const labelSuffix = computed(() => schemaBridge.value.labelSuffix || " ");
const grid = computed(() => schemaBridge.value.grid || 1);
const methods = computed(() => {
return Object.keys(schemaBridge.value.methods || {}).reduce((acc, key) => {
acc[key] = new Function("model", "service", schemaBridge.value.methods[key]).bind(null, props.model, props.service);
return acc;
}, {});
});
provide("cipFormRender", reactive({
methods
}));
const init = computed(() => schemaBridge.value.init || []);
watch(() => schemaBridge.value, () => {
if (init.value) {
init.value.forEach((key) => {
const method = methods.value[key];
if (typeof method === "function") {
method();
}
});
}
}, {
immediate: true
});
expose({
cipFormRef
});
return () => createVNode(CipForm, {
"ref": cipFormRef,
"model": props.model,
"onUpdate:model": (val) => emit("update:model", val),
"fieldList": fieldList.value,
"labelPosition": labelPosition.value,
"equipment": props.equipment,
"labelWidth": labelWidth.value,
"labelSuffix": labelSuffix.value,
"grid": grid.value,
"dataBus": props.dataBus
}, null);
}
});
export { index as default };