Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Hooke
/
data-table
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Authored by
hookehuyr
2022-12-05 16:12:27 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
95000ed4266695966fa5825b69a1ce85a2e73371
95000ed4
1 parent
cdc48e6f
fix 动态绑定ref值修复
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
21 deletions
src/views/index.vue
src/views/index.vue
View file @
95000ed
...
...
@@ -27,9 +27,9 @@
<van-form @submit="onSubmit">
<van-cell-group :border="false">
<component
:id="item.key"
:ref="item.component_props.name"
v-for="(item, index) in formData"
:id="item.key"
:ref="(el) => setRefMap(el, item)"
:key="index"
:is="item.component"
:item="item"
...
...
@@ -49,6 +49,16 @@
</div>
</template>
<script>
export default {
mounted() {
setTimeout(() => {
// console.warn(this.$refs);
}, 100);
},
};
</script>
<script setup>
import "@vant/touch-emulator";
import { createComponentType } from "@/hooks/useComponentType";
...
...
@@ -115,6 +125,30 @@ const formatData = (data) => {
return arr;
};
// 处理没有绑定值的组件的赋值
// 图片上传,文件上传,电子签名,评分组件
const image_uploader = ref([]);
const file_uploader = ref([]);
const sign = ref([]);
const rate_picker = ref([]);
// 动态绑定ref数据
const setRefMap = (el, item) => {
if (el) {
if (item.component_props.name === "image_uploader") {
image_uploader.value.push(el);
}
if (item.component_props.name === "file_uploader") {
file_uploader.value.push(el);
}
if (item.component_props.name === "sign") {
sign.value.push(el);
}
if (item.component_props.name === "rate_picker") {
rate_picker.value.push(el);
}
}
};
onMounted(async () => {
const { data } = await queryFormAPI({ form_code: $route.query.code });
const form_data = data[0];
...
...
@@ -168,13 +202,6 @@ onMounted(async () => {
createComponentType(formData.value);
});
// 处理没有绑定值的组件的赋值
// 图片上传,文件上传,电子签名,评分组件
const image_uploader = ref(null);
const file_uploader = ref(null);
const sign = ref(null);
const rate_picker = ref(null);
// 操作绑定自定义字段回调
const onActive = (item) => {
if (item.key === "image_uploader") {
...
...
@@ -251,30 +278,26 @@ const validOther = () => {
const onSubmit = async (values) => {
// 合并自定义字段到提交表单字段
postData.value = _.assign(postData.value, values);
// 格式化value值为json格式, 提交格式有问题
// for (let key in postData.value) {
// key = JSON.stringify(key);
// // postData.value[key] = postData.value[key];
// }
// 检查非表单输入项
if (validOther().status) {
// 通过验证
const result = await addFormDataAPI({
form_code: $route.query.code,
// data: JSON.stringify(postData.value),
data: postData.value,
});
if (result.code) {
showSuccessToast("提交成功");
}
// console.warn(postData.value);
// console.warn("通过验证");
} else {
console.warn(validOther().key + "不通过验证");
// 图片上传控件报错提示
if (validOther().key === "image_uploader") {
showFailToast("图片上传为空");
}
// // 图片上传控件报错提示
// if (validOther().key === "image_uploader") {
// showFailToast("图片上传为空");
// }
// // 文件上传控件报错提示
// if (validOther().key === "file_uploader") {
// showFailToast("文件上传为空");
// }
}
};
</script>
...
...
Please
register
or
login
to post a comment