加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
新建文本文档 (21).txt 4.39 KB
一键复制 编辑 原始数据 按行查看 历史
屈小康 提交于 2024-04-08 20:58 . 渲染json
<template>
<div class="vFormClass">
<!-- {{ bizSubTypeName }} -->
<div class="title">{{ bizSubTypeName }}</div>
<v-form-render :form-json="formJson" :form-data="formData" :option-data="optionData" ref="vFormRef"></v-form-render>
</div>
</template>
<script setup>
const { bizSubTypeName, formDataDWB, formJson } = defineProps({
formDataDWB: {
type: Object,
default: {},
required: true,
},
bizSubTypeName: {
type: String,
default: "",
required: true,
},
remarkList: {
type: Array,
default: [],
required: false,
},
formJson: {
default: {},
required: true,
},
});
console.log(bizSubTypeName, "--");
const formData = reactive({});
const optionData = reactive({});
const vFormRef = ref(null);
const setTableDataToRefs = (value = [], setRefs = []) => {
if (setRefs.length > 0) {
setRefs.forEach((item, index) => {
console.log(vFormRef);
if (vFormRef.value.getWidgetRef(item)) {
vFormRef.value.getWidgetRef(item).setTableData(value[index]);
}
});
}
};
const getPropVal = props => {
//todo ���������߼������ڱ���չʾ
const propArray = props.split("_") || [];
const length = propArray.length;
let obj = {};
let value = "";
if (length == 1) {
return formDataDWB[propArray[0]];
}
if (length > 0) {
for (let i = 0; i < length; i++) {
if (i === 0 && formDataDWB[propArray[i]]) {
obj = formDataDWB[propArray[i]];
continue;
}
if (i === length - 1) {
value = obj[propArray[i]];
continue;
}
if (obj[propArray[i]]) {
obj = obj[propArray[i]];
}
}
}
return value;
};
const setTableProp = props => {
//todo ���������߼������ڱ���չʾ
const propArray = props.split("_") || [];
const length = propArray.length;
let obj = {};
let value = [];
for (let i = 1; i < length; i++) {
let type;
if (i == 1) {
type = formDataDWB[propArray[i]];
} else {
type = obj[propArray[i]];
}
if (Array.isArray(type)) {
if (Object.keys(obj).length > 0) {
value = obj[propArray[i]];
} else {
value = formDataDWB[propArray[i]];
}
continue;
} else {
obj = formDataDWB[propArray[i]];
continue;
}
}
return value;
};
const initTableData = formData => {
// console.log(formData, '---');
let result = replaceKey(formData);
let valueKeys = result[0] || [];
let dataKeys = result[1] || [];
let setKeys = [];
let setValueKeys = [];
let setRefs = [];
let valueList = [];
dataKeys.forEach((item, index) => {
if (item.includes("#vt_")) {
setKeys.push(index);
setRefs.push(item);
}
});
setKeys.forEach(item => {
setValueKeys.push(valueKeys[item]);
});
for (let i = 0; i < setValueKeys.length; i++) {
let value = setTableProp(setValueKeys[i]);
valueList.push(value);
}
if (valueList.length > 0) {
setTableDataToRefs(valueList, setRefs);
}
};
const initFormData = formJson => {
console.log(11);
let result = replaceKey(formJson);
let valueKeys = result[0];
let dataKey = result[1];
for (let i = 0; i < valueKeys.length; i++) {
const value = getPropVal(valueKeys[i]);
if (value) {
console.log(formData, "for");
let key = dataKey[i];
formData[key] = value;
// formData.dataKey[i] = value;
let regex = /#([^#]*#)/g;
let matches = str.match(regex);
let valueKeys = [];
let dataKey = [];
if (matches) {
valueKeys = matches.map(match => match.slice(1, -1));
}
if (matches) {
dataKey = matches.map(match => match.slice(0));
}
// tableList = JSON.parse(JSON.stringify(dataKey));
return [valueKeys, dataKey];
}; }
}
console.log("get new formData", formData);
};
const replaceKey = str => {
initFormData(JSON.stringify(formJson));
onMounted(() => {
nextTick(() => {
initTableData(JSON.stringify(formJson));
});
});
</script>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化