d-render
Version:
数据渲染库 - form、table、search-form
136 lines (133 loc) • 4.42 kB
JavaScript
import { defineComponent, toRefs, computed, unref, h } from 'vue';
import { getViewComponent, getInputComponent, getH5InputComponent } from '../utils';
import { useFormInject, getFieldValue, setFieldValue } from '@d-render/shared';
var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
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 __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
var index = /* @__PURE__ */ defineComponent({
name: "CipFormLayout",
props: {
config: Object,
// 字段配置信息
fieldKey: {
type: String,
required: true
},
// 字段名
model: {
// 字段所属model
type: Object,
default: () => ({})
},
grid: {
type: [Number, Boolean],
default: true
},
// Number | Boolean
componentKey: String,
isDesign: Boolean,
// 是否设计模式
drawType: String,
// 需要开启设计模式后优先级高于config.type 一般仅用于拖拽设计时使用, 平时无效果
readonly: Boolean
// 是否只读-即查看模式
},
emits: ["update:model", "validate", "submit", "cancel", "selectItem", "update:config"],
setup(props, context) {
const {
model
} = toRefs(props);
const cipForm = useFormInject();
const cipFormStyle = computed(() => {
var _a;
if (props.grid) {
return {
gridColumn: `span ${(_a = props.config) == null ? void 0 : _a.span}`
};
} else {
return "width: 100%";
}
});
const equipment = computed(() => {
return unref(cipForm.equipment) || "pc";
});
const formLayout = () => {
var _a, _b, _c;
const componentProps = {
class: ["cip-form-layout", {
"cip-form-layout--hidden": (_a = props.config) == null ? void 0 : _a.hideItem
}],
model: model.value,
config: props.config,
fieldKey: props.fieldKey,
style: cipFormStyle.value,
modelValue: getFieldValue(model.value, props.fieldKey),
"onUpdate:modelValue": (val) => {
const result = model.value;
setFieldValue(result, props.fieldKey, val, true);
context.emit("update:model", result);
}
};
const componentType = props.isDesign ? props.drawType || ((_b = props.config) == null ? void 0 : _b.type) : (_c = props.config) == null ? void 0 : _c.type;
if (props.readonly) {
return h(getViewComponent(componentType), componentProps, {
item: ({
children,
index
} = {
children: [],
index: 0
}) => {
var _a2, _b2;
return (_b2 = (_a2 = context.slots).item) == null ? void 0 : _b2.call(_a2, {
children,
index
});
}
});
} else {
const method = equipment.value === "pc" ? getInputComponent : getH5InputComponent;
return h(method(componentType), __spreadProps(__spreadValues({}, componentProps), {
"onUpdate:config": (val) => {
context.emit("update:config", val);
},
onValidate: (fn) => {
context.emit("validate", fn);
},
onSubmit: () => {
context.emit("submit");
},
onCancel: () => {
context.emit("cancel");
},
onSelectItem: (val) => {
context.emit("selectItem", val);
}
}), {
item: (scope) => {
var _a2, _b2;
return (_b2 = (_a2 = context.slots).item) == null ? void 0 : _b2.call(_a2, scope);
}
});
}
};
return () => formLayout();
}
});
export { index as default };