up.
This commit is contained in:
parent
744e6c9de1
commit
28712780ff
@ -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">
|
||||||
|
|||||||
@ -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>
|
||||||
|
|||||||
@ -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 () => {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user