This commit is contained in:
全栈小学生 2025-03-14 18:33:34 +08:00
parent d09a12489d
commit e7a5f5d316
3 changed files with 193 additions and 195 deletions

View File

@ -6,21 +6,19 @@
</view> </view>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { ref, reactive, onMounted } from 'vue'; import { ref, reactive, onMounted } from 'vue';
import diyGroup from '@/addon/components/diy/group/index.vue' import diyGroup from '@/addon/components/diy/group/index.vue'
import { getFormRecord } from '@/app/api/diy_form'; import { getFormRecord } from '@/app/api/diy_form';
const props = defineProps(['record_id','completeLayout']); const props = defineProps(['record_id', 'completeLayout']);
const emits = defineEmits(['callback']) const emits = defineEmits(['callback'])
const loading = ref(true);
const loading = ref(true); const diyFormData: any = reactive({
const diyFormData: any = reactive({
global: {}, global: {},
value: [] value: []
}) })
onMounted(() => { onMounted(() => {
getFormRecord({ getFormRecord({
record_id: props.record_id record_id: props.record_id
}).then((res: any) => { }).then((res: any) => {
@ -55,5 +53,5 @@
loading.value = false; loading.value = false;
emits('callback', []) emits('callback', [])
}) })
}) })
</script> </script>

View File

@ -7,27 +7,27 @@
</view> </view>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { ref, reactive, computed, onMounted, watch } from 'vue'; import { ref, reactive, computed, onMounted, watch } from 'vue';
import { useDiyForm } from '@/hooks/useDiyForm' import { useDiyForm } from '@/hooks/useDiyForm'
import { deepClone,getValidTime } from '@/utils/common' import { deepClone, getValidTime } from '@/utils/common'
import diyGroup from '@/addon/components/diy/group/index.vue' import diyGroup from '@/addon/components/diy/group/index.vue'
const props = defineProps(['form_id', 'relate_id', 'storage_name', 'form_border']); const props = defineProps(['form_id', 'relate_id', 'storage_name', 'form_border']);
const diy = useDiyForm({ const diy = useDiyForm({
form_id: props.form_id, form_id: props.form_id,
needLogin: false // needLogin: false //
}) })
const diyGroupRef = ref(null) const diyGroupRef = ref(null)
const requestData = computed(() => { const requestData = computed(() => {
return diy.requestData; return diy.requestData;
}) })
const diyFormData: any = reactive({}) const diyFormData: any = reactive({})
onMounted(() => { onMounted(() => {
diy.getData(() => { diy.getData(() => {
diyFormData.status = diy.data.status; diyFormData.status = diy.data.status;
if (diyFormData.status) { if (diyFormData.status) {
@ -38,7 +38,7 @@
diyFormData.global.bottomTabBarSwitch = false; // diyFormData.global.bottomTabBarSwitch = false; //
} }
let value: any = []; let value: any = [];
if(props.form_border == 'none'){ if (props.form_border == 'none') {
diyFormData.global.borderControl = false; diyFormData.global.borderControl = false;
} }
// //
@ -53,9 +53,9 @@
watchFormData(); watchFormData();
} }
}) })
}) })
const watchFormData = () => { const watchFormData = () => {
watch( watch(
() => diyFormData.value, () => diyFormData.value,
(newValue, oldValue) => { (newValue, oldValue) => {
@ -66,7 +66,7 @@
}; };
newValue.forEach((item: any) => { newValue.forEach((item: any) => {
// //
if (item.componentType == 'diy_form' && item.componentName != 'FormSubmit') { if (item.componentType == 'diy_form' && item.componentName != 'FormSubmit' && item.field.cache) {
// //
let field = deepClone(item.field); let field = deepClone(item.field);
// //
@ -90,11 +90,11 @@
}, },
{ deep: true } { deep: true }
) )
} }
const verify = () => { const verify = () => {
if(!diyFormData.status) return true; if (!diyFormData.status) return true;
if(!diyFormData.value) return true; if (!diyFormData.value) return true;
let allPass = true; // let allPass = true; //
let componentRefs = diyGroupRef.value.getFormRef().componentRefs; let componentRefs = diyGroupRef.value.getFormRef().componentRefs;
@ -138,46 +138,46 @@
uni.setStorageSync(props.storage_name, data) uni.setStorageSync(props.storage_name, data)
} }
return allPass; return allPass;
} }
// //
const getData = ()=> { const getData = () => {
return { return {
form_id: props.form_id, form_id: props.form_id,
value: diyFormData.value, value: diyFormData.value,
relate_id: props.relate_id || 0 // id relate_id: props.relate_id || 0 // id
} }
} }
const clearStorage = (keys: any=[]) => { const clearStorage = (keys: any = []) => {
uni.removeStorageSync('diyFormStorage_' + props.form_id) uni.removeStorageSync('diyFormStorage_' + props.form_id)
if (props.storage_name) uni.removeStorageSync(props.storage_name) if (props.storage_name) uni.removeStorageSync(props.storage_name)
if(keys) { if (keys) {
keys.forEach((key: any) => { keys.forEach((key: any) => {
uni.removeStorageSync(key) uni.removeStorageSync(key)
}) })
} }
} }
// //
diy.onHide(); diy.onHide();
// //
diy.onUnload(); diy.onUnload();
// //
// diy.onPageScroll() // diy.onPageScroll()
defineExpose({ defineExpose({
verify, verify,
getData, getData,
clearStorage clearStorage
}) })
</script> </script>
<style lang="scss"> <style lang="scss">
.diy-template-wrap { .diy-template-wrap {
/* #ifdef MP */ /* #ifdef MP */
.child-diy-template-wrap { .child-diy-template-wrap {
::v-deep .diy-group { ::v-deep .diy-group {
@ -186,6 +186,7 @@
} }
} }
} }
/* #endif */ /* #endif */
} }
</style> </style>

View File

@ -112,7 +112,6 @@
<template v-if="component.componentName == 'FormFile'"> <template v-if="component.componentName == 'FormFile'">
<diy-form-file ref="diyFormFileRef" :component="component" :global="data.global" :index="index" /> <diy-form-file ref="diyFormFileRef" :component="component" :global="data.global" :index="index" />
</template> </template>
</view> </view>
</view> </view>
<template v-if="diyStore.mode == '' && data.global && data.global.bottomTabBarSwitch"> <template v-if="diyStore.mode == '' && data.global && data.global.bottomTabBarSwitch">