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

View File

@ -48,6 +48,7 @@
:option="config.option"
:item-bind="config.bind"
:key="config.id"
:ref="setItemRef"
/>
<el-form-item v-if="config.tips">
<ele-text type="placeholder" style="line-height: 1.6">
@ -60,6 +61,39 @@
<script setup lang="ts">
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<{
configList: any;
}>();
@ -70,4 +104,10 @@
}
return null;
};
defineExpose({
getFormData(){
return getAllDataValues();
}
})
</script>

View File

@ -30,16 +30,18 @@
@submit.prevent=""
>
<config-form-list
ref="configFormListRef"
:config-list="configList"
v-if="configList.length > 0"
/>
<el-button @click="saveForm">保存</el-button>
</el-form>
</ele-card>
</ele-page>
</template>
<script lang="ts" setup>
import {onMounted, ref} from 'vue';
import {onMounted, ref } from 'vue';
import {Refresh} from '@element-plus/icons-vue';
import {listConfigs, syncConfigs} from '@/api/system/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 configGroup = ref('');
onMounted(async () => {