Commit 5edbc1ba by yancanhua

feat: 自定义组件开发

1 parent c54f3162
<script setup lang="ts"> <script setup lang="ts">
import type { CustomizeFormValidateResult } from "@/types/views/car-detail";
import { ref, watch } from "vue"; import { ref, watch } from "vue";
import type { CustomizeFormValidateResult } from "@/types/views/car-detail";
import selectDatePicker from "@/components/customizeForm/selectDatePicker.vue"; import selectDatePicker from "@/components/customizeForm/selectDatePicker.vue";
import selectDropdown from "@/components/customizeForm/selectDropdown.vue"; import selectDropdown from "@/components/customizeForm/selectDropdown.vue";
import buttonSelect from "@/components/customizeForm/buttonSelect.vue"; import buttonSelect from "@/components/customizeForm/buttonSelect.vue";
...@@ -29,11 +27,25 @@ const form = ref({}); ...@@ -29,11 +27,25 @@ const form = ref({});
const rules = ref({}); const rules = ref({});
watch(() => props.leafNodes, (nodes) => { watch(() => props.leafNodes, (nodes) => {
columnsList.value = nodes || []; columnsList.value = (nodes || []).map((item: any) => ({ ...item, value: getValueText(item), }));
console.log('watchLeafNodes', columnsList.value); console.log('watchLeafNodes', columnsList.value);
}, { immediate: true, deep: true }); }, { immediate: true, deep: true });
function getValueText(item: any) {
let valueText = '';
if (item?.inspectionResultVO) {
const inspectionValueList = item?.inspectionResultVO?.inspectionValueList || [];
if (inspectionValueList && inspectionValueList.length > 0) {
const inputList = ['text_input', 'textarea_input', 'number_input', 'date_picker'];
if (inputList.includes(item.interactionType)) {
valueText = inspectionValueList[0].valueText || '';
}
}
}
return valueText;
}
// 提交数据 // 提交数据
function setSubmitData() { function setSubmitData() {
let returnData: never[] = []; let returnData: never[] = [];
...@@ -90,6 +102,7 @@ function setSubmitData() { ...@@ -90,6 +102,7 @@ function setSubmitData() {
returnData.push({ nodeId: item.id, nodeName: item.nodeName, resultStatus: resultStatus.value ? 3 : 1, remark: '', data: dataList }); returnData.push({ nodeId: item.id, nodeName: item.nodeName, resultStatus: resultStatus.value ? 3 : 1, remark: '', data: dataList });
} }
}); });
console.log('validate', returnData);
return returnData; return returnData;
} }
...@@ -124,6 +137,17 @@ function getValidationRules(item: any) { ...@@ -124,6 +137,17 @@ function getValidationRules(item: any) {
return JSON.parse(item.validationRules || '{}'); return JSON.parse(item.validationRules || '{}');
} }
function setImgWidth(item: any) {
let resultStatus = false;
if (item.interactionType == 'image_upload' || item.interactionType == 'video_upload') {
const validationRules = JSON.parse(item.validationRules || '{}');
if (validationRules.maxCount && validationRules.maxCount == 1) {
resultStatus = true;
}
}
return resultStatus
}
defineExpose({ defineExpose({
validate, validate,
saveData, saveData,
...@@ -134,17 +158,18 @@ defineExpose({ ...@@ -134,17 +158,18 @@ defineExpose({
<template> <template>
<div> <div>
<van-form ref="customizeFormRef" :model="form" :rules="rules"> <van-form ref="customizeFormRef" :model="form" :rules="rules">
<div class="formTitle"> <div v-if="allowNoStructure" class="formTitle">
<!-- <div>{{ subTabLabel }}</div> --> <div @click="resultStatus = !resultStatus">
<div v-if="allowNoStructure" class="formRadio" @click="resultStatus = !resultStatus">
<van-icon v-if="!resultStatus" name="circle" size="14" color="#666666" /> <van-icon v-if="!resultStatus" name="circle" size="14" color="#666666" />
<van-icon v-if="resultStatus" name="checked" size="14" color="#185EFE" /> <van-icon v-if="resultStatus" name="checked" size="14" color="#185EFE" />
<span class="radioText">无此结构</span> <span class="radioText">无此结构</span>
</div> </div>
</div> </div>
<div v-for="(item, index) in columnsList" :key="index" class="customizeList" <div v-for="(item, index) in columnsList" :key="index" class="customizeList" :class="{
:class="{ 'border-bottom': index < columnsList.length - 1 && item.interactionType != 'image_upload' }"> 'border-bottom': index < columnsList.length - 1 && item.interactionType != 'image_upload',
'customizeList50': setImgWidth(item)
}">
<!-- 文本输入框 --> <!-- 文本输入框 -->
<div v-if="item.interactionType == 'text_input'"> <div v-if="item.interactionType == 'text_input'">
...@@ -201,18 +226,11 @@ defineExpose({ ...@@ -201,18 +226,11 @@ defineExpose({
.formTitle { .formTitle {
width: 100%; width: 100%;
float: left; float: left;
color: #333333;
font-size: 18px;
line-height: 24px;
background: #ffffff; background: #ffffff;
padding: 16px 12px; padding: 16px 12px;
display: flex; display: flex;
} }
.formRadio {
margin-left: 14px;
}
.radioText { .radioText {
color: #666666; color: #666666;
font-size: 12px; font-size: 12px;
...@@ -225,7 +243,7 @@ defineExpose({ ...@@ -225,7 +243,7 @@ defineExpose({
} }
.customizeList50 { .customizeList50 {
width: 50%; width: 50% !important;
float: left; float: left;
} }
......
<script setup lang="ts"> <script setup lang="ts">
import { ref } from "vue"; import { ref, watch } from "vue";
import { uploadFile } from "@/utils/upload.js"; import { uploadFile } from "@/utils/upload.js";
const uploading = ref(false); const uploading = ref(false);
...@@ -13,15 +13,31 @@ const props = defineProps({ ...@@ -13,15 +13,31 @@ const props = defineProps({
}); });
const emit = defineEmits(["update"]); const emit = defineEmits(["update"]);
const pickerValue = ref([]); const pickerValue = ref([]);
const fileInputRef = ref<HTMLInputElement | null>(null); const fileInputRef = ref<HTMLInputElement | null>(null);
function pickFile() { function pickFile() {
fileInputRef.value?.click(); fileInputRef.value?.click();
} }
//页面加载时初始化数据
onMounted(() => {
initData();
});
// 初始化数据
function initData() {
if (props?.item?.inspectionResultVO) {
const inspectionValueList = props?.item?.inspectionResultVO?.inspectionValueList || [];
for (const i of inspectionValueList) {
if (i.valueText) { pickerValue.value.push(i.valueText) }
}
if (pickerValue.value.length > 0) {
updateData();
}
}
}
// 计算属性 // 计算属性
const validationRules = computed(() => { const validationRules = computed(() => {
return JSON.parse(props.item.validationRules || '{}'); return JSON.parse(props.item.validationRules || '{}');
......
...@@ -10,6 +10,22 @@ const props = defineProps({ ...@@ -10,6 +10,22 @@ const props = defineProps({
const emit = defineEmits(["update"]); const emit = defineEmits(["update"]);
const pickerValue = ref(''); const pickerValue = ref('');
//页面加载时初始化数据
onMounted(() => {
initData();
});
// 初始化数据
function initData() {
if (props?.item?.inspectionResultVO) {
const inspectionValueList = props?.item?.inspectionResultVO?.inspectionValueList || [];
if (inspectionValueList && inspectionValueList.length > 0) {
pickerValue.value = inspectionValueList[0].valueKey || '';
}
}
}
// 计算属性 // 计算属性
const columnsList = computed(() => { const columnsList = computed(() => {
const optionsList = JSON.parse(props.item.options || '[]').map(item => { const optionsList = JSON.parse(props.item.options || '[]').map(item => {
......
...@@ -8,6 +8,8 @@ const props = defineProps({ ...@@ -8,6 +8,8 @@ const props = defineProps({
}, },
}); });
const columnsType = ref(['year', 'month']);
const emit = defineEmits(["update"]); const emit = defineEmits(["update"]);
const showPicker = ref(false); const showPicker = ref(false);
const pickerValue = ref([]); const pickerValue = ref([]);
...@@ -37,7 +39,7 @@ function onConfirm() { ...@@ -37,7 +39,7 @@ function onConfirm() {
<van-field v-model="item.value" clearable is-link :label="item.nodeName" name="datePicker" <van-field v-model="item.value" clearable is-link :label="item.nodeName" name="datePicker"
:placeholder="item.placeholder" readonly :required="item.required === 1" @click="handleShowPicker" /> :placeholder="item.placeholder" readonly :required="item.required === 1" @click="handleShowPicker" />
<van-popup v-model:show="showPicker" destroy-on-close position="bottom"> <van-popup v-model:show="showPicker" destroy-on-close position="bottom">
<van-date-picker v-model="pickerValue" :title="item.nodeName" @cancel="showPicker = false" <van-date-picker v-model="pickerValue" :title="item.nodeName" :columns-type="columnsType" @cancel="showPicker = false"
@confirm="onConfirm" /> @confirm="onConfirm" />
</van-popup> </van-popup>
</div> </div>
......
...@@ -12,6 +12,23 @@ const emit = defineEmits(["update"]); ...@@ -12,6 +12,23 @@ const emit = defineEmits(["update"]);
const showPicker = ref(false); const showPicker = ref(false);
const pickerValue = ref([]); const pickerValue = ref([]);
//页面加载时初始化数据
onMounted(() => {
initData();
});
// 初始化数据
function initData() {
if (props?.item?.inspectionResultVO) {
const inspectionValueList = props?.item?.inspectionResultVO?.inspectionValueList || [];
if (inspectionValueList && inspectionValueList.length > 0 && inspectionValueList[0].valueKey) {
pickerValue.value = [inspectionValueList[0].valueKey];
}
onConfirm();
}
}
// 计算属性 // 计算属性
const columnsList = computed(() => { const columnsList = computed(() => {
const optionsList = JSON.parse(props.item.options || '[]').map(item => { const optionsList = JSON.parse(props.item.options || '[]').map(item => {
...@@ -27,7 +44,7 @@ const columnsList = computed(() => { ...@@ -27,7 +44,7 @@ const columnsList = computed(() => {
function onConfirm() { function onConfirm() {
const picker = pickerValue.value && pickerValue.value.length > 0 ? pickerValue.value[0] : ""; const picker = pickerValue.value && pickerValue.value.length > 0 ? pickerValue.value[0] : "";
showPicker.value = false; showPicker.value = false;
const ObjectItem = columnsList.value.find(item => item.value == picker); const ObjectItem = columnsList.value.find(item => item.value == picker) || {};
props.item.valueText = ObjectItem.text || ''; props.item.valueText = ObjectItem.text || '';
props.item.valueKey = ObjectItem.value || ''; props.item.valueKey = ObjectItem.value || '';
props.item.value = picker || ''; props.item.value = picker || '';
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!