This commit is contained in:
u2nyakim 2025-08-26 11:04:26 +08:00
parent 744e6c9de1
commit 28712780ff
3 changed files with 56 additions and 8 deletions

View File

@ -26,7 +26,6 @@
<el-switch <el-switch
size="small" size="small"
:model-value="dataValue" :model-value="dataValue"
@update:modelValue="(val) => updateDataValue(val)"
v-bind="itemBind" v-bind="itemBind"
/> />
</template> </template>
@ -77,8 +76,8 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import {ref, onMounted} from "vue"; import {ref, onMounted, toRaw} from "vue";
import { strToValue} from "@/utils/sys-config"; import { strToValue } from "@/utils/sys-config";
const props = defineProps<{ const props = defineProps<{
name: string; name: string;
@ -92,11 +91,12 @@ const props = defineProps<{
const dataValue = ref<any>(); const dataValue = ref<any>();
onMounted(() => { onMounted(() => {
dataValue.value = strToValue(props.type, props.value); dataValue.value = strToValue(props.type, props.value);
// console.log("", props, dataValue.value,);
}); });
const updateDataValue = (val) => { defineExpose({
console.log("更新val", val); getDataValue(){
} return [props.name, toRaw(dataValue.value)];
}
})
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">

View File

@ -48,6 +48,7 @@
:option="config.option" :option="config.option"
:item-bind="config.bind" :item-bind="config.bind"
:key="config.id" :key="config.id"
:ref="setItemRef"
/> />
<el-form-item v-if="config.tips"> <el-form-item v-if="config.tips">
<ele-text type="placeholder" style="line-height: 1.6"> <ele-text type="placeholder" style="line-height: 1.6">
@ -60,6 +61,39 @@
<script setup lang="ts"> <script setup lang="ts">
import ConfigFormItem from '../components/config-form-item.vue'; import ConfigFormItem from '../components/config-form-item.vue';
import {onBeforeUpdate, ref} from "vue";
import type { ComponentPublicInstance } from "vue";
//
interface ConfigFormItemInstance {
getDataValue: () => any; //
}
//
const itemRefs = ref<ConfigFormItemInstance[]>([]);
//
const setItemRef = (el: unknown) => {
const component = el as ComponentPublicInstance & ConfigFormItemInstance;
if (component && component.getDataValue) {
itemRefs.value.push(component);
}
};
//
const getAllDataValues = () => {
let data = {}
itemRefs.value.map((item)=>{
const [name, value] = item.getDataValue();
data[name] = value;
});
return data;
};
//
onBeforeUpdate(() => {
itemRefs.value = [];
});
const props = defineProps<{ const props = defineProps<{
configList: any; configList: any;
}>(); }>();
@ -70,4 +104,10 @@
} }
return null; return null;
}; };
defineExpose({
getFormData(){
return getAllDataValues();
}
})
</script> </script>

View File

@ -30,16 +30,18 @@
@submit.prevent="" @submit.prevent=""
> >
<config-form-list <config-form-list
ref="configFormListRef"
:config-list="configList" :config-list="configList"
v-if="configList.length > 0" v-if="configList.length > 0"
/> />
<el-button @click="saveForm">保存</el-button>
</el-form> </el-form>
</ele-card> </ele-card>
</ele-page> </ele-page>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import {onMounted, ref} from 'vue'; import {onMounted, ref } from 'vue';
import {Refresh} from '@element-plus/icons-vue'; import {Refresh} from '@element-plus/icons-vue';
import {listConfigs, syncConfigs} from '@/api/system/config'; import {listConfigs, syncConfigs} from '@/api/system/config';
import {getSysConfig, strToBind, strToOption} from '@/utils/sys-config'; import {getSysConfig, strToBind, strToOption} from '@/utils/sys-config';
@ -86,6 +88,12 @@ const sync = () => {
}); });
} }
const configFormListRef = ref(null);
const saveForm = () => {
const allValues = configFormListRef.value?.getFormData();
console.log('所有组件数据:', allValues);
}
const groupItems = ref([]); const groupItems = ref([]);
const configGroup = ref(''); const configGroup = ref('');
onMounted(async () => { onMounted(async () => {