2025-03-21 17:16:12 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<div>
|
2025-03-29 16:40:35 +08:00
|
|
|
|
<TableSearch :query="query" :options="searchOpt" :search="handleSearch" :refresh="getData" />
|
2025-03-21 17:16:12 +08:00
|
|
|
|
<div class="container">
|
|
|
|
|
|
<TableCustom :columns="columns" :tableData="tableData" :total="page.total" :viewFunc="handleView"
|
2025-05-10 14:55:31 +08:00
|
|
|
|
:delFunc="handleDelete" :changePage="changePage2" :currentPage="page.currentPage" :editFunc="handleEdit" :genOperate="handleGenOperate" :refresh="getData">
|
2025-03-21 17:16:12 +08:00
|
|
|
|
<template #toolbarBtn>
|
2025-04-07 19:41:10 +08:00
|
|
|
|
<el-button type="warning" :icon="CirclePlusFilled" @click="visible_add = true">新增</el-button>
|
2025-03-21 17:16:12 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
</TableCustom>
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<el-dialog :title="isEdit ? '编辑': '编辑'" v-model="visible" width="700px" destroy-on-close
|
|
|
|
|
|
:close-on-click-modal="false" @close="closeDialog">
|
|
|
|
|
|
<TableEdit :form-data="rowData" :options="options_edit" :edit="isEdit" :update="updateData" />
|
|
|
|
|
|
</el-dialog>
|
|
|
|
|
|
<el-dialog :title="isAdd ? '新增' : '新增'" v-model="visible_add" width="700px" destroy-on-close
|
|
|
|
|
|
:close-on-click-modal="false" @close="closeDialog">
|
|
|
|
|
|
<TableEdit :form-data="rowData" :options="options" :edit="isAdd" :update="addData" />
|
|
|
|
|
|
</el-dialog>
|
|
|
|
|
|
<el-dialog title="查看详情" v-model="visible1" width="700px" destroy-on-close>
|
|
|
|
|
|
<TableDetail :data="viewData"></TableDetail>
|
|
|
|
|
|
</el-dialog>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script setup lang="ts" name="system-user">
|
|
|
|
|
|
import { ref, reactive } from 'vue';
|
|
|
|
|
|
import { ElMessage } from 'element-plus';
|
|
|
|
|
|
import { CirclePlusFilled } from '@element-plus/icons-vue';
|
|
|
|
|
|
import { UserInfo } from '@/types/user';
|
2025-03-21 19:22:42 +08:00
|
|
|
|
import { Model } from '@/types/model';
|
|
|
|
|
|
import {FindModelService} from "@/api/model";
|
|
|
|
|
|
import {UpdateModelService} from "@/api/model";
|
|
|
|
|
|
import {AddModelService} from "@/api/model";
|
|
|
|
|
|
import {DelModelService} from "@/api/model";
|
2025-03-21 17:16:12 +08:00
|
|
|
|
import TableCustom from '@/components/table-custom.vue';
|
|
|
|
|
|
import TableDetail from '@/components/table-detail.vue';
|
|
|
|
|
|
import TableSearch from '@/components/table-search.vue';
|
|
|
|
|
|
import { FormOption, FormOptionList } from '@/types/form-option';
|
2025-05-10 14:55:31 +08:00
|
|
|
|
import { pa } from 'element-plus/es/locale';
|
2025-03-21 17:16:12 +08:00
|
|
|
|
|
2025-03-21 19:22:42 +08:00
|
|
|
|
|
2025-03-21 17:16:12 +08:00
|
|
|
|
// 查询相关
|
|
|
|
|
|
const query = reactive({
|
|
|
|
|
|
name: '',
|
|
|
|
|
|
});
|
|
|
|
|
|
const searchOpt = ref<FormOptionList[]>([
|
2025-03-21 19:22:42 +08:00
|
|
|
|
{ type: 'input', label: '模型ID:', prop: 'name' }
|
2025-03-21 17:16:12 +08:00
|
|
|
|
])
|
|
|
|
|
|
const handleSearch = async () => {
|
2025-03-22 18:11:38 +08:00
|
|
|
|
// query.name是否是数字
|
|
|
|
|
|
if (isNaN(Number(query.name))) {
|
|
|
|
|
|
ElMessage.error('请输入数字');
|
2025-03-21 19:22:42 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-03-30 13:43:39 +08:00
|
|
|
|
if (query.name === '') {
|
|
|
|
|
|
ElMessage.error('请输入模型ID');
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-03-21 17:16:12 +08:00
|
|
|
|
let req={
|
|
|
|
|
|
token: localStorage.getItem('token'),
|
2025-03-21 19:22:42 +08:00
|
|
|
|
type: "ID",
|
|
|
|
|
|
id: parseInt(query.name)
|
2025-03-21 17:16:12 +08:00
|
|
|
|
}
|
2025-03-21 19:22:42 +08:00
|
|
|
|
let result = await FindModelService(req);
|
2025-05-10 14:55:31 +08:00
|
|
|
|
if (result["data"]==null){
|
|
|
|
|
|
ElMessage.error("没有该模型");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-03-21 17:16:12 +08:00
|
|
|
|
page.total = result.data.length;
|
2025-05-10 14:55:31 +08:00
|
|
|
|
page.index = 1;
|
|
|
|
|
|
allData.value = result.data;
|
|
|
|
|
|
// 分页
|
|
|
|
|
|
let start = (page.index - 1) * page.size;
|
|
|
|
|
|
let end = start + page.size;
|
|
|
|
|
|
if (end > page.total) {
|
|
|
|
|
|
end = page.total;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (start > page.total) {
|
|
|
|
|
|
start = page.total;
|
|
|
|
|
|
}
|
|
|
|
|
|
tableData.value = result.data.slice(start, end);
|
2025-03-21 17:16:12 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 表格相关
|
|
|
|
|
|
let columns = ref([
|
2025-03-24 21:44:38 +08:00
|
|
|
|
// { type: 'index', label: '序号', width: 55, align: 'center' },
|
2025-03-21 19:22:42 +08:00
|
|
|
|
{ prop: 'ID', label: '模型ID' },
|
|
|
|
|
|
{ prop: 'Type', label: '类型' },
|
|
|
|
|
|
{prop: 'Description', label: '描述'},
|
2025-03-25 16:05:18 +08:00
|
|
|
|
{ prop: 'Parameter', label: '参数', width: 250 },
|
|
|
|
|
|
{prop: 'Url', label: 'URl'},
|
2025-03-30 16:54:44 +08:00
|
|
|
|
{ prop: 'token', label: '消耗token数',width:50},
|
2025-03-21 17:16:12 +08:00
|
|
|
|
{ prop: 'CreatedAt', label: '创建时间',type: 'date' },
|
2025-03-29 16:40:35 +08:00
|
|
|
|
{ prop: 'operator', label: '操作', width: 250 , operate: { view: true, edit: true, delete: true,push: {link: false,label:"继续该会话"},gen: {show: false,label:"下载文件"} }},
|
2025-03-21 17:16:12 +08:00
|
|
|
|
])
|
|
|
|
|
|
const page = reactive({
|
|
|
|
|
|
index: 1,
|
|
|
|
|
|
size: 10,
|
|
|
|
|
|
total: 122,
|
2025-05-10 14:55:31 +08:00
|
|
|
|
pageSizes: [10, 20, 30, 40],
|
|
|
|
|
|
currentPage: 1,
|
2025-03-21 17:16:12 +08:00
|
|
|
|
})
|
2025-03-21 19:22:42 +08:00
|
|
|
|
const tableData = ref<Model[]>([]);
|
2025-05-10 14:55:31 +08:00
|
|
|
|
const allData = ref<Model[]>([]);
|
2025-03-21 17:16:12 +08:00
|
|
|
|
const getData = async () => {
|
|
|
|
|
|
let req={
|
|
|
|
|
|
token: localStorage.getItem('token'),
|
2025-03-21 19:22:42 +08:00
|
|
|
|
type: "UserID"
|
2025-03-21 17:16:12 +08:00
|
|
|
|
}
|
2025-03-21 19:22:42 +08:00
|
|
|
|
let result = await FindModelService(req);
|
2025-03-21 17:16:12 +08:00
|
|
|
|
page.total = result.data.length;
|
2025-05-10 14:55:31 +08:00
|
|
|
|
page.index = 1;
|
2025-05-12 13:49:08 +08:00
|
|
|
|
page.currentPage = 1;
|
2025-05-10 14:55:31 +08:00
|
|
|
|
allData.value = result.data;
|
|
|
|
|
|
// 分页
|
|
|
|
|
|
let start = (page.index - 1) * page.size;
|
|
|
|
|
|
let end = start + page.size;
|
|
|
|
|
|
if (end > page.total) {
|
|
|
|
|
|
end = page.total;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (start > page.total) {
|
|
|
|
|
|
start = page.total;
|
|
|
|
|
|
}
|
|
|
|
|
|
tableData.value = result.data.slice(start, end);
|
2025-05-12 13:49:08 +08:00
|
|
|
|
await getModelTTypeOptions();
|
2025-03-21 17:16:12 +08:00
|
|
|
|
};
|
|
|
|
|
|
getData();
|
|
|
|
|
|
|
2025-05-10 14:55:31 +08:00
|
|
|
|
const changePage = async (val: number) => {
|
|
|
|
|
|
console.log("page index:", page.index);
|
2025-03-21 17:16:12 +08:00
|
|
|
|
page.index = val;
|
|
|
|
|
|
getData();
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-05-10 14:55:31 +08:00
|
|
|
|
const changePage2 = async (val: number) => {
|
|
|
|
|
|
//console.log("page index:", page.index);
|
|
|
|
|
|
page.index = val;
|
|
|
|
|
|
//分页
|
|
|
|
|
|
let start = (page.index - 1) * page.size;
|
|
|
|
|
|
let end = start + page.size;
|
|
|
|
|
|
if (end > page.total) {
|
|
|
|
|
|
end = page.total;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (start > page.total) {
|
|
|
|
|
|
start = page.total;
|
|
|
|
|
|
}
|
|
|
|
|
|
tableData.value = allData.value.slice(start, end);
|
|
|
|
|
|
page.currentPage = val;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-05-12 13:49:08 +08:00
|
|
|
|
const modelTypeOptions = ref([
|
|
|
|
|
|
{ label: '本地部署模型', value: 'ollama' },
|
|
|
|
|
|
{ label: '星火', value: 'spark' },
|
|
|
|
|
|
{ label: '豆包', value: 'doubao' }
|
|
|
|
|
|
]);
|
|
|
|
|
|
let opts = ref([]);
|
|
|
|
|
|
const getModelTTypeOptions =()=>{
|
|
|
|
|
|
opts.value = [];
|
|
|
|
|
|
let modelTypeMap = new Map();
|
|
|
|
|
|
//遍历所有数据
|
|
|
|
|
|
for(let i=0;i<allData.value.length;i++){
|
|
|
|
|
|
let modelType = allData.value[i].Type;
|
|
|
|
|
|
if(!modelTypeMap.has(modelType)){
|
|
|
|
|
|
modelTypeMap.set(modelType,modelType);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//console.log("modelTypeMap:", modelTypeMap);
|
|
|
|
|
|
//遍历map
|
|
|
|
|
|
for(let [key,value] of modelTypeMap){
|
|
|
|
|
|
opts.value.push({label:key,value:value});
|
|
|
|
|
|
}
|
|
|
|
|
|
//console.log("opts:", opts);
|
|
|
|
|
|
options.value.list[0].opts = opts.value;
|
|
|
|
|
|
options_edit.value.list[0].opts = opts.value;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-21 17:16:12 +08:00
|
|
|
|
// 新增弹窗
|
|
|
|
|
|
let options = ref<FormOption>({
|
|
|
|
|
|
labelWidth: '100px',
|
|
|
|
|
|
span: 12,
|
|
|
|
|
|
list: [
|
2025-05-12 13:49:08 +08:00
|
|
|
|
{ type: 'select', label: '类型', prop: 'Type', required: true, allowcreate:true, opts: opts.value },
|
2025-03-21 19:22:42 +08:00
|
|
|
|
{ type: 'input', label: 'URL', prop: 'Url', required: true },
|
|
|
|
|
|
{ type: 'input', label: '参数', prop: 'Parameter', required: true },
|
|
|
|
|
|
{ type: 'input', label: '描述', prop: 'Description', required: true },
|
2025-03-21 17:16:12 +08:00
|
|
|
|
]
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
//编辑弹窗
|
|
|
|
|
|
let options_edit = ref<FormOption>({
|
|
|
|
|
|
labelWidth: '100px',
|
|
|
|
|
|
span: 12,
|
|
|
|
|
|
list: [
|
2025-05-12 13:49:08 +08:00
|
|
|
|
{ type: 'select', label: '类型', prop: 'Type', required: true, allowcreate:true,opts:opts.value},
|
2025-03-21 19:22:42 +08:00
|
|
|
|
{ type: 'input', label: 'URL', prop: 'Url', required: true },
|
2025-03-25 16:05:18 +08:00
|
|
|
|
{ type: 'input', label: '参数', prop: 'Parameter', required: true, rows: 4 },
|
2025-03-21 19:22:42 +08:00
|
|
|
|
{ type: 'input', label: '描述', prop: 'Description', required: true },
|
2025-03-21 17:16:12 +08:00
|
|
|
|
]
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
const visible = ref(false);
|
|
|
|
|
|
const visible_add = ref(false);
|
|
|
|
|
|
const isEdit = ref(false);
|
|
|
|
|
|
const isAdd = ref(false);
|
|
|
|
|
|
const rowData = ref({});
|
2025-03-21 19:22:42 +08:00
|
|
|
|
const handleEdit = async (row: Model) => {
|
|
|
|
|
|
let data = row;
|
2025-03-21 17:16:12 +08:00
|
|
|
|
rowData.value = data;
|
2025-03-21 19:22:42 +08:00
|
|
|
|
console.log("edit_row_data:", rowData.value);
|
2025-03-21 17:16:12 +08:00
|
|
|
|
isEdit.value = true;
|
|
|
|
|
|
visible.value = true;
|
|
|
|
|
|
};
|
|
|
|
|
|
const updateData = async (data) => {
|
|
|
|
|
|
let result ={}
|
|
|
|
|
|
try{
|
2025-03-22 18:11:38 +08:00
|
|
|
|
let req={
|
|
|
|
|
|
token:localStorage.getItem("token"),
|
|
|
|
|
|
id: data.ID,
|
|
|
|
|
|
type: data.Type,
|
|
|
|
|
|
url: data.Url,
|
|
|
|
|
|
parameter: data.Parameter,
|
|
|
|
|
|
description: data.Description
|
|
|
|
|
|
};
|
2025-03-21 19:22:42 +08:00
|
|
|
|
result = await UpdateModelService(req)
|
2025-03-25 16:05:18 +08:00
|
|
|
|
if (result["code"] === 0) {
|
2025-03-21 17:16:12 +08:00
|
|
|
|
ElMessage.success("更新成功");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
ElMessage.error("更新失败");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}catch(e){
|
|
|
|
|
|
console.log(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
closeDialog();
|
2025-03-21 19:22:42 +08:00
|
|
|
|
getData();
|
2025-03-21 17:16:12 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2025-03-21 19:22:42 +08:00
|
|
|
|
const addData = async (data) => {
|
|
|
|
|
|
let result ={}
|
2025-03-21 17:16:12 +08:00
|
|
|
|
try{
|
2025-03-25 16:05:18 +08:00
|
|
|
|
let req={
|
|
|
|
|
|
token:localStorage.getItem("token"),
|
|
|
|
|
|
type: data.Type,
|
|
|
|
|
|
url: data.Url,
|
|
|
|
|
|
parameter: data.Parameter,
|
|
|
|
|
|
description: data.Description
|
|
|
|
|
|
};
|
2025-03-21 19:22:42 +08:00
|
|
|
|
result = await AddModelService(req)
|
2025-03-25 16:05:18 +08:00
|
|
|
|
if (result["code"] === 0) {
|
2025-03-21 19:22:42 +08:00
|
|
|
|
ElMessage.success("新增成功");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
ElMessage.error("新增失败");
|
2025-03-21 17:16:12 +08:00
|
|
|
|
}
|
2025-03-21 19:22:42 +08:00
|
|
|
|
|
2025-03-21 17:16:12 +08:00
|
|
|
|
}catch(e){
|
|
|
|
|
|
console.log(e);
|
|
|
|
|
|
}
|
2025-03-21 19:22:42 +08:00
|
|
|
|
closeDialog();
|
|
|
|
|
|
getData();
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-03-21 17:16:12 +08:00
|
|
|
|
|
|
|
|
|
|
const closeDialog = () => {
|
|
|
|
|
|
visible.value = false;
|
|
|
|
|
|
visible_add.value = false;
|
|
|
|
|
|
isEdit.value = false;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-03-29 16:40:35 +08:00
|
|
|
|
const handleGenOperate = async (row: File) => {
|
|
|
|
|
|
console.log("gen row:", row);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-21 17:16:12 +08:00
|
|
|
|
// 查看详情弹窗相关
|
|
|
|
|
|
const visible1 = ref(false);
|
|
|
|
|
|
const viewData = ref({
|
|
|
|
|
|
row: {},
|
2025-03-21 19:22:42 +08:00
|
|
|
|
list: [
|
|
|
|
|
|
|
|
|
|
|
|
]
|
2025-03-21 17:16:12 +08:00
|
|
|
|
});
|
2025-03-21 19:22:42 +08:00
|
|
|
|
const handleView =async (row: Model) => {
|
|
|
|
|
|
viewData.value.row = row;
|
2025-03-21 17:16:12 +08:00
|
|
|
|
viewData.value.list = [
|
|
|
|
|
|
{
|
|
|
|
|
|
prop: 'ID',
|
2025-03-21 19:22:42 +08:00
|
|
|
|
label: '模型ID',
|
2025-03-21 17:16:12 +08:00
|
|
|
|
},
|
|
|
|
|
|
{
|
2025-03-21 19:22:42 +08:00
|
|
|
|
prop: 'Type',
|
|
|
|
|
|
label: '类型',
|
2025-03-21 17:16:12 +08:00
|
|
|
|
},
|
2025-03-25 16:05:18 +08:00
|
|
|
|
{
|
|
|
|
|
|
prop: 'Description',
|
|
|
|
|
|
label: '描述',
|
|
|
|
|
|
},
|
2025-03-21 17:16:12 +08:00
|
|
|
|
{
|
2025-03-21 19:22:42 +08:00
|
|
|
|
prop: 'Parameter',
|
|
|
|
|
|
label: '参数',
|
2025-03-21 17:16:12 +08:00
|
|
|
|
},
|
|
|
|
|
|
{
|
2025-03-25 16:05:18 +08:00
|
|
|
|
prop: 'Url',
|
|
|
|
|
|
label: 'URL',
|
2025-03-21 17:16:12 +08:00
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
prop: 'CreatedAt',
|
2025-03-21 19:22:42 +08:00
|
|
|
|
label: '创建时间',
|
|
|
|
|
|
type: 'date'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
prop: 'UpdatedAt',
|
|
|
|
|
|
label: '更新时间',
|
|
|
|
|
|
type: 'date'
|
2025-03-21 17:16:12 +08:00
|
|
|
|
},
|
|
|
|
|
|
]
|
|
|
|
|
|
visible1.value = true;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 删除相关
|
2025-03-21 19:22:42 +08:00
|
|
|
|
const handleDelete = async (row: Model) => {
|
|
|
|
|
|
let req={
|
|
|
|
|
|
token: localStorage.getItem('token'),
|
|
|
|
|
|
id: row.ID,
|
|
|
|
|
|
}
|
|
|
|
|
|
try{
|
|
|
|
|
|
let result = await DelModelService(req);
|
2025-03-25 16:05:18 +08:00
|
|
|
|
if(result["code"] === 0){
|
2025-03-21 19:22:42 +08:00
|
|
|
|
ElMessage.success("删除成功");
|
|
|
|
|
|
getData();
|
|
|
|
|
|
}else{
|
|
|
|
|
|
ElMessage.error("删除失败");
|
|
|
|
|
|
}
|
|
|
|
|
|
}catch(e){
|
|
|
|
|
|
console.log(e);
|
|
|
|
|
|
}
|
2025-03-21 17:16:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped></style>
|