Merge pull request #718 from xinnan-tech/web-vue-model-modify

Web vue model modify
This commit is contained in:
Sakura-RanChen
2025-04-09 14:26:04 +08:00
committed by GitHub
4 changed files with 119 additions and 99 deletions
@@ -1,5 +1,5 @@
<template>
<el-dialog :visible.sync="visible" width="975px" center custom-class="custom-dialog" :show-close="false"
<el-dialog :visible="dialogVisible" @update:visible="handleVisibleChange" width="975px" center custom-class="custom-dialog" :show-close="false"
class="center-dialog">
<div style="margin: 0 18px; text-align: left; padding: 10px; border-radius: 10px;">
<div style="font-size: 30px; color: #3d4566; margin-top: -10px; margin-bottom: 10px; text-align: center;">
@@ -63,7 +63,7 @@
<div style="font-size: 20px; font-weight: bold; color: #3d4566; margin-bottom: 15px;">调用信息</div>
<div style="height: 2px; background: #e9e9e9; margin-bottom: 22px;"></div>
<el-form :model="formData.configJson" label-width="100px" label-position="left" class="custom-form">
<el-form :model="formData.configJson" label-width="auto" label-position="left" class="custom-form">
<template v-for="(row, rowIndex) in chunkedCallInfoFields">
<div :key="rowIndex" style="display: flex; gap: 20px; margin-bottom: 0;">
<el-form-item
@@ -104,6 +104,7 @@ export default {
data() {
return {
providers: [],
dialogVisible: false,
providersLoaded: false,
providerFields: [],
currentProvider: null,
@@ -122,8 +123,11 @@ export default {
},
watch: {
visible(val) {
this.dialogVisible = val;
if(val) {
this.initConfigJson();
} else {
this.resetForm();
}
},
'formData.supplier'(newVal) {
@@ -171,6 +175,17 @@ export default {
});
this.formData.configJson = { ...defaultConfig };
},
handleVisibleChange(val) {
this.dialogVisible = val;
this.$emit('update:visible', val);
if (!val) {
this.resetForm();
}
},
handleClose() {
this.$emit('update:visible', false);
},
initDynamicConfig() {
const newConfig = {};
this.providerFields.forEach(field => {
@@ -223,10 +238,6 @@ export default {
this.providerFields = [];
this.currentProvider = null;
},
handleClose() {
this.resetForm();
this.$emit('update:visible', false);
}
}
}
</script>
@@ -44,7 +44,7 @@
</el-select>
</el-form-item>
<el-form-item label="排序号" prop="sort" style="flex: 1;">
<el-input v-model="form.sort" placeholder="请输入排序号" class="custom-input-bg"></el-input>
<el-input v-model.number="form.sort" type="number" placeholder="请输入排序号" class="custom-input-bg"></el-input>
</el-form-item>
</div>
@@ -61,10 +61,11 @@
<div style="font-size: 20px; font-weight: bold; color: #3d4566; margin-bottom: 15px;">调用信息</div>
<div style="height: 2px; background: #e9e9e9; margin-bottom: 22px;"></div>
<el-form :model="form.configJson" ref="callInfoForm" label-width="100px" label-position="left" class="custom-form">
<el-form :model="form.configJson" ref="callInfoForm" label-width="auto" class="custom-form">
<template v-for="(row, rowIndex) in chunkedCallInfoFields">
<div :key="rowIndex" style="display: flex; gap: 20px; margin-bottom: 0;">
<el-form-item v-for="field in row"
<el-form-item
v-for="field in row"
:key="field.prop"
:label="field.label"
:prop="field.prop"
@@ -72,7 +73,7 @@
<el-input
v-model="form.configJson[field.prop]"
:placeholder="field.placeholder"
:type="field.type || 'text'"
:type="field.type"
class="custom-input-bg"
:show-password="field.type === 'password'">
</el-input>
@@ -129,6 +130,10 @@ export default {
dialogVisible: this.visible,
providers: [],
providersLoaded: false,
allProvidersData: null,
pendingProviderType: null,
pendingModelData: null,
dynamicCallInfoFields: [],
form: {
id: "",
modelType: "",
@@ -144,60 +149,19 @@ export default {
};
},
computed: {
callInfoFields() {
const fieldsMap = {
llm: [
{ label: '模型名称', prop: 'model_name', placeholder: '请输入model_name' },
{ label: '接口地址', prop: 'base_url', placeholder: '请输入base_url' },
{ label: '秘钥信息', prop: 'api_key', placeholder: '请输入api_key', type: 'password' }
],
vad: [
{ label: '模型名称', prop: 'model_name', placeholder: '请输入model_name' },
{ label: '模型目录', prop: 'model_dir', placeholder: '请输入model_dir' },
{ label: '阈值', prop: 'threshold', placeholder: '请输入threshold' },
{ label: '静音时长', prop: 'min_silence_duration_ms', placeholder: '请输入min_silence_duration_ms' },
{ label: '接口地址', prop: 'base_url', placeholder: '请输入base_url' },
{ label: '秘钥信息', prop: 'api_key', placeholder: '请输入api_key', type: 'password' }
],
asr: [
{ label: '模型名称', prop: 'model_name', placeholder: '请输入model_name' },
{ label: '集群', prop: 'cluster', placeholder: '请输入cluster' },
{ label: '接口地址', prop: 'base_url', placeholder: '请输入base_url' },
{ label: '秘钥信息', prop: 'api_key', placeholder: '请输入api_key', type: 'password' }
],
intent: [
{ label: '模型名称', prop: 'model_name', placeholder: '请输入model_name' },
{ label: 'LLM模型', prop: 'llm', placeholder: '请输入llm' },
{ label: '接口地址', prop: 'base_url', placeholder: '请输入base_url' },
{ label: '秘钥信息', prop: 'api_key', placeholder: '请输入api_key', type: 'password' }
],
tts: [
{ label: '模型名称', prop: 'model_name', placeholder: '请输入model_name' },
{ label: '语音ID', prop: 'voice_id', placeholder: '请输入voice_id' },
{ label: '接口地址', prop: 'base_url', placeholder: '请输入base_url' },
{ label: '秘钥信息', prop: 'api_key', placeholder: '请输入api_key', type: 'password' }
],
memory: [
{ label: '模型名称', prop: 'model_name', placeholder: '请输入model_name' },
{ label: '接口地址', prop: 'base_url', placeholder: '请输入base_url' },
{ label: '秘钥信息', prop: 'api_key', placeholder: '请输入api_key', type: 'password' }
]
};
return fieldsMap[this.modelType] || [];
},
chunkedCallInfoFields() {
const chunkSize = 2;
const result = [];
for (let i = 0; i < this.callInfoFields.length; i += chunkSize) {
result.push(this.callInfoFields.slice(i, i + chunkSize));
for (let i = 0; i < this.dynamicCallInfoFields.length; i += chunkSize) {
result.push(this.dynamicCallInfoFields.slice(i, i + chunkSize));
}
return result;
},
},
watch: {
modelType() {
this.resetProviders()
this.resetProviders();
this.loadProviders();
},
dialogVisible(val) {
this.$emit('update:visible', val);
@@ -209,6 +173,14 @@ export default {
},
visible(val) {
this.dialogVisible = val;
if (val) {
this.loadProviders();
}
},
'form.configJson.type'(newVal) {
if (newVal && this.providersLoaded) {
this.loadProviderFields(newVal);
}
}
},
methods: {
@@ -222,7 +194,7 @@ export default {
isEnabled: false,
docLink: "",
remark: "",
sort: 0,
sort: "",
configJson: JSON.parse(JSON.stringify(DEFAULT_CONFIG_JSON))
};
},
@@ -235,38 +207,14 @@ export default {
Api.model.getModelConfig(this.modelData.id, ({ data }) => {
if (data.code === 0 && data.data) {
const model = data.data;
this.pendingProviderType = model.configJson.type;
this.pendingModelData = model;
let configJson = model.configJson || {};
if (typeof configJson !== 'object' || Array.isArray(configJson)) {
console.warn('Invalid configJson format, using default');
configJson = {};
if (this.providersLoaded) {
this.loadProviderFields(model.configJson.type);
} else {
this.loadProviders();
}
this.callInfoFields.forEach(field => {
if (!configJson.hasOwnProperty(field.prop)) {
configJson[field.prop] = '';
}
});
this.form = {
id: model.id || "",
modelType: model.modelType || "",
modelCode: model.modelCode || "",
modelName: model.modelName || "",
isDefault: model.isDefault || 0,
isEnabled: model.isEnabled || 0,
docLink: model.docLink || "",
remark: model.remark || "",
sort: model.sort || 0,
configJson: {
...JSON.parse(JSON.stringify(DEFAULT_CONFIG_JSON)),
...configJson,
config: {
...DEFAULT_CONFIG_JSON.config,
...(configJson.config || {})
}
}
};
}
});
}
@@ -304,8 +252,62 @@ export default {
value: item.providerCode
}));
this.providersLoaded = true;
this.allProvidersData = data;
if (this.pendingProviderType) {
this.loadProviderFields(this.pendingProviderType);
}
});
},
loadProviderFields(providerCode) {
if (this.allProvidersData) {
const provider = this.allProvidersData.find(p => p.providerCode === providerCode);
if (provider) {
this.dynamicCallInfoFields = JSON.parse(provider.fields || '[]').map(f => ({
label: f.label,
prop: f.key,
type: f.type === 'password' ? 'password' : 'text',
placeholder: `请输入${f.label}`
}));
if (this.pendingModelData && this.pendingProviderType === providerCode) {
this.processModelData(this.pendingModelData);
this.pendingModelData = null;
this.pendingProviderType = null;
}
}
}
},
processModelData(model) {
let configJson = model.configJson || {};
this.dynamicCallInfoFields.forEach(field => {
if (!configJson.hasOwnProperty(field.prop)) {
configJson[field.prop] = '';
}
});
this.form = {
id: model.id || "",
modelType: model.modelType || "",
modelCode: model.modelCode || "",
modelName: model.modelName || "",
isDefault: model.isDefault || 0,
isEnabled: model.isEnabled || 0,
docLink: model.docLink || "",
remark: model.remark || "",
sort: Number(model.sort) || 0,
configJson: {
...JSON.parse(JSON.stringify(DEFAULT_CONFIG_JSON)),
...configJson,
config: {
...DEFAULT_CONFIG_JSON.config,
...(configJson.config || {})
}
}
};
}
}
};
</script>
+12 -12
View File
@@ -4,16 +4,16 @@
<div class="operation-bar">
<h2 class="page-title">模型配置</h2>
<div class="right-operations">
<el-button plain size="small" @click="handleImport" style="background: #7b9de5; color: white;">
<img loading="lazy" alt="" src="@/assets/model/inner_conf.png">
导入配置
</el-button>
<el-button plain size="small" @click="handleExport" style="background: #71c9d1; color: white;">
<img loading="lazy" alt="" src="@/assets/model/output_conf.png">
导出配置
</el-button>
</div>
<!-- <div class="right-operations">-->
<!-- <el-button plain size="small" @click="handleImport" style="background: #7b9de5; color: white;">-->
<!-- <img loading="lazy" alt="" src="@/assets/model/inner_conf.png">-->
<!-- 导入配置-->
<!-- </el-button>-->
<!-- <el-button plain size="small" @click="handleExport" style="background: #71c9d1; color: white;">-->
<!-- <img loading="lazy" alt="" src="@/assets/model/output_conf.png">-->
<!-- 导出配置-->
<!-- </el-button>-->
<!-- </div>-->
</div>
<!-- 主体内容 -->
@@ -53,7 +53,7 @@
</div>
<div class="action-group">
<div class="search-group">
<el-input placeholder="请输入模型名称查询" v-model="search" size="small" class="search-input" clearable @keyup.enter="handleSearch" />
<el-input placeholder="请输入模型名称查询" v-model="search" size="small" class="search-input" clearable @keyup.enter.native="handleSearch" />
<el-button type="primary" size="small" class="search-btn" @click="handleSearch">
查询
</el-button>
@@ -69,7 +69,7 @@
<el-table-column label="模型编码" prop="modelCode" align="center"></el-table-column>
<el-table-column label="提供商" align="center">
<template slot-scope="scope">
{{ scope.row.configJson?.provider || '未知' }}
{{ scope.row.configJson.type || '未知' }}
</template>
</el-table-column>
<el-table-column label="是否启用" align="center">
@@ -5,7 +5,7 @@
<div class="operation-bar">
<h2 class="page-title">用户管理</h2>
<div class="right-operations">
<el-input placeholder="请输入手机号码查询" v-model="searchPhone" class="search-input"
<el-input placeholder="请输入手机号码查询" v-model="searchPhone" class="search-input" clearable
@keyup.enter.native="handleSearch" />
<el-button class="btn-search" @click="handleSearch">搜索</el-button>
</div>
@@ -556,6 +556,13 @@ export default {
}
}
}
:deep(.el-table .el-button--text) {
color: #7079aa !important;
}
:deep(.el-table .el-button--text:hover) {
color: #5a64b5 !important;
}
:deep(.custom-selection-header) {
.el-checkbox {