2025-03-24 14:50:11 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<div>
|
2025-03-29 16:40:35 +08:00
|
|
|
|
<TableSearch :query="query" :options="searchOpt" :search="handleSearch" :refresh="getData" />
|
2025-03-24 14:50:11 +08:00
|
|
|
|
<div class="container">
|
|
|
|
|
|
<TableCustom :columns="columns" :tableData="tableData" :total="page.total" :viewFunc="handleView"
|
2025-03-29 16:40:35 +08:00
|
|
|
|
:delFunc="handleDelete" :page-change="changePage" :editFunc="handleEdit" :refresh="getData">
|
2025-03-24 14:50:11 +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-24 14:50:11 +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 { Function } from '@/types/function';
|
|
|
|
|
|
import {FindFunctionService} from "@/api/function";
|
|
|
|
|
|
import {UpdateFunctionService} from "@/api/function";
|
|
|
|
|
|
import {AddFunctionService} from "@/api/function";
|
|
|
|
|
|
import {DelFunctionService} from "@/api/function";
|
|
|
|
|
|
import {FindModelService} from "@/api/model";
|
|
|
|
|
|
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';
|
|
|
|
|
|
|
|
|
|
|
|
// 查询相关
|
|
|
|
|
|
const query = reactive({
|
|
|
|
|
|
name: '',
|
|
|
|
|
|
});
|
|
|
|
|
|
const searchOpt = ref<FormOptionList[]>([
|
|
|
|
|
|
{ type: 'input', label: '模型ID:', prop: 'name' }
|
|
|
|
|
|
])
|
|
|
|
|
|
const handleSearch = async () => {
|
|
|
|
|
|
// query.name是否是数字
|
|
|
|
|
|
if (isNaN(Number(query.name))) {
|
|
|
|
|
|
ElMessage.error('请输入数字');
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
let req={
|
|
|
|
|
|
token: localStorage.getItem('token'),
|
|
|
|
|
|
type: "ID",
|
|
|
|
|
|
id: parseInt(query.name)
|
|
|
|
|
|
}
|
|
|
|
|
|
let result = await FindFunctionService(req);
|
|
|
|
|
|
tableData.value = result.data;
|
|
|
|
|
|
page.total = result.data.length;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 表格相关
|
|
|
|
|
|
let columns = ref([
|
|
|
|
|
|
// { type: 'index', label: '序号', width: 55, align: 'center' },
|
|
|
|
|
|
{ prop: 'ID', label: '功能ID' },
|
|
|
|
|
|
{prop: 'Name', label: '名称'},
|
|
|
|
|
|
{prop: "ModelID", label: "模型ID"},
|
|
|
|
|
|
{ prop: 'Function', label: '功能' },
|
|
|
|
|
|
{ prop: 'Info', label: '描述信息' },
|
|
|
|
|
|
{ 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-24 14:50:11 +08:00
|
|
|
|
])
|
|
|
|
|
|
const page = reactive({
|
|
|
|
|
|
index: 1,
|
|
|
|
|
|
size: 10,
|
|
|
|
|
|
total: 122,
|
|
|
|
|
|
})
|
|
|
|
|
|
const tableData = ref<Function[]>([]);
|
|
|
|
|
|
const model_select_opts = ref([]);
|
|
|
|
|
|
const getData = async () => {
|
|
|
|
|
|
let req={
|
|
|
|
|
|
token: localStorage.getItem('token'),
|
|
|
|
|
|
type: "UserID"
|
|
|
|
|
|
}
|
|
|
|
|
|
let modelResult = await FindModelService(req);
|
2025-03-31 13:58:13 +08:00
|
|
|
|
model_select_opts.value.length = 0; // 清空数组
|
2025-03-24 14:50:11 +08:00
|
|
|
|
for (let i = 0; i < modelResult.data.length; i++) {
|
|
|
|
|
|
model_select_opts.value.push({
|
|
|
|
|
|
label: modelResult.data[i].Type + ":" + modelResult.data[i].Description,
|
|
|
|
|
|
value: modelResult.data[i].ID
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
let result = await FindFunctionService(req);
|
|
|
|
|
|
tableData.value = result.data;
|
|
|
|
|
|
page.total = result.data.length;
|
|
|
|
|
|
};
|
|
|
|
|
|
getData();
|
|
|
|
|
|
|
|
|
|
|
|
const changePage = (val: number) => {
|
|
|
|
|
|
page.index = val;
|
|
|
|
|
|
getData();
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 新增弹窗
|
|
|
|
|
|
let options = ref<FormOption>({
|
|
|
|
|
|
labelWidth: '100px',
|
|
|
|
|
|
span: 12,
|
|
|
|
|
|
list: [
|
|
|
|
|
|
{ type: 'input', label: '名称', prop: 'Name', required: true },
|
2025-03-31 13:58:13 +08:00
|
|
|
|
{ type: 'select', label: '模型', prop: 'ModelIDS', required: true, opts:model_select_opts.value ,multiple: true},
|
2025-03-24 14:50:11 +08:00
|
|
|
|
{ type: 'input', label: '功能', prop: 'Function', required: true },
|
|
|
|
|
|
{ type: 'input', label: '描述', prop: 'Info', required: true },
|
|
|
|
|
|
]
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
//编辑弹窗
|
|
|
|
|
|
let options_edit = ref<FormOption>({
|
|
|
|
|
|
labelWidth: '100px',
|
|
|
|
|
|
span: 12,
|
|
|
|
|
|
list: [
|
|
|
|
|
|
{ type: 'input', label: '名称', prop: 'Name', required: true },
|
2025-03-30 19:30:06 +08:00
|
|
|
|
{ type: 'select', label: '模型', prop: 'ModelIDS', required: true, opts:model_select_opts.value, multiple: true},
|
2025-03-24 14:50:11 +08:00
|
|
|
|
{ type: 'input', label: '功能', prop: 'Function', required: true },
|
|
|
|
|
|
{ type: 'input', label: '描述', prop: 'Info', required: true },
|
|
|
|
|
|
]
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
const visible = ref(false);
|
|
|
|
|
|
const visible_add = ref(false);
|
|
|
|
|
|
const isEdit = ref(false);
|
|
|
|
|
|
const isAdd = ref(false);
|
2025-03-31 19:06:57 +08:00
|
|
|
|
const rowData = ref<Function>({} as Function);
|
2025-03-24 14:50:11 +08:00
|
|
|
|
const handleEdit = async (row: Function) => {
|
|
|
|
|
|
let data = row;
|
|
|
|
|
|
rowData.value = data;
|
2025-03-31 13:58:13 +08:00
|
|
|
|
let model_ids = JSON.parse(data.ModelIDS.toString())
|
|
|
|
|
|
let model_id_list = []
|
|
|
|
|
|
for (let i = 0; i < model_ids.length; i++) {
|
|
|
|
|
|
model_id_list.push(model_ids[i]["id"])
|
|
|
|
|
|
}
|
|
|
|
|
|
rowData.value.ModelIDS = model_id_list
|
2025-03-30 19:30:06 +08:00
|
|
|
|
//console.log("edit_row_data:", rowData.value);
|
2025-03-24 14:50:11 +08:00
|
|
|
|
isEdit.value = true;
|
|
|
|
|
|
visible.value = true;
|
|
|
|
|
|
};
|
|
|
|
|
|
const updateData = async (data) => {
|
2025-03-30 19:30:06 +08:00
|
|
|
|
let model_id =[]
|
2025-03-31 13:58:13 +08:00
|
|
|
|
console.log("model update:",data)
|
|
|
|
|
|
let model_id_list= data["ModelIDS"]
|
2025-03-30 19:30:06 +08:00
|
|
|
|
for (let i = 0; i < model_id_list.length; i++) {
|
|
|
|
|
|
model_id.push({"id":model_id_list[i]})
|
|
|
|
|
|
}
|
|
|
|
|
|
let model_ids = JSON.stringify(model_id)
|
2025-03-24 14:50:11 +08:00
|
|
|
|
let result ={}
|
|
|
|
|
|
try{
|
|
|
|
|
|
let req={
|
|
|
|
|
|
token:localStorage.getItem("token"),
|
|
|
|
|
|
id: data.ID,
|
2025-03-24 21:44:38 +08:00
|
|
|
|
name: data.Name,
|
2025-03-30 19:30:06 +08:00
|
|
|
|
model_id: model_id_list[0],
|
2025-03-24 21:44:38 +08:00
|
|
|
|
function: data.Function,
|
2025-03-30 19:30:06 +08:00
|
|
|
|
model_ids: model_ids,
|
2025-03-24 21:44:38 +08:00
|
|
|
|
info: data.Info
|
2025-03-24 14:50:11 +08:00
|
|
|
|
};
|
|
|
|
|
|
result = await UpdateFunctionService(req)
|
2025-03-24 21:44:38 +08:00
|
|
|
|
if (result['code'] === 0) {
|
2025-03-24 14:50:11 +08:00
|
|
|
|
ElMessage.success("更新成功");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
ElMessage.error("更新失败");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}catch(e){
|
|
|
|
|
|
console.log(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
closeDialog();
|
|
|
|
|
|
getData();
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const addData = async (data) => {
|
2025-03-31 13:58:13 +08:00
|
|
|
|
let model_id =[]
|
|
|
|
|
|
console.log("model update:",data)
|
|
|
|
|
|
let model_id_list= data["ModelIDS"]
|
|
|
|
|
|
for (let i = 0; i < model_id_list.length; i++) {
|
|
|
|
|
|
model_id.push({"id":model_id_list[i]})
|
|
|
|
|
|
}
|
|
|
|
|
|
let model_ids = JSON.stringify(model_id)
|
2025-03-24 14:50:11 +08:00
|
|
|
|
let result ={}
|
|
|
|
|
|
try{
|
|
|
|
|
|
let req={
|
|
|
|
|
|
token:localStorage.getItem("token"),
|
|
|
|
|
|
name: data.Name,
|
2025-03-31 13:58:13 +08:00
|
|
|
|
model_id: model_id_list[0],
|
|
|
|
|
|
model_ids: model_ids,
|
2025-03-24 14:50:11 +08:00
|
|
|
|
function: data.Function,
|
|
|
|
|
|
info: data.Info
|
|
|
|
|
|
}
|
|
|
|
|
|
result = await AddFunctionService(req)
|
2025-03-24 21:44:38 +08:00
|
|
|
|
if (result['code'] === 0) {
|
2025-03-24 14:50:11 +08:00
|
|
|
|
ElMessage.success("新增成功");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
ElMessage.error("新增失败");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}catch(e){
|
|
|
|
|
|
console.log(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
closeDialog();
|
|
|
|
|
|
getData();
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const closeDialog = () => {
|
|
|
|
|
|
visible.value = false;
|
|
|
|
|
|
visible_add.value = false;
|
|
|
|
|
|
isEdit.value = false;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 查看详情弹窗相关
|
|
|
|
|
|
const visible1 = ref(false);
|
|
|
|
|
|
const viewData = ref({
|
|
|
|
|
|
row: {},
|
|
|
|
|
|
list: [
|
|
|
|
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
});
|
|
|
|
|
|
const handleView =async (row: Function) => {
|
|
|
|
|
|
viewData.value.row = row;
|
|
|
|
|
|
viewData.value.list = [
|
|
|
|
|
|
{
|
|
|
|
|
|
prop: 'ID',
|
|
|
|
|
|
label: '功能ID',
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
prop: 'Name',
|
|
|
|
|
|
label: '名称',
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
prop: 'Function',
|
|
|
|
|
|
label: '功能',
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
prop: 'ModelID',
|
|
|
|
|
|
label: '模型ID',
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
prop: 'Info',
|
|
|
|
|
|
label: '描述',
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
prop: 'CreatedAt',
|
|
|
|
|
|
label: '创建时间',
|
|
|
|
|
|
type: 'date'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
prop: 'UpdatedAt',
|
|
|
|
|
|
label: '更新时间',
|
|
|
|
|
|
type: 'date'
|
|
|
|
|
|
},
|
|
|
|
|
|
]
|
|
|
|
|
|
visible1.value = true;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 删除相关
|
|
|
|
|
|
const handleDelete = async (row: Function) => {
|
|
|
|
|
|
let req={
|
|
|
|
|
|
token: localStorage.getItem('token'),
|
|
|
|
|
|
id: row.ID,
|
|
|
|
|
|
}
|
|
|
|
|
|
try{
|
|
|
|
|
|
let result = await DelFunctionService(req);
|
2025-03-24 21:44:38 +08:00
|
|
|
|
if(result['code'] === 0){
|
2025-03-24 14:50:11 +08:00
|
|
|
|
ElMessage.success("删除成功");
|
|
|
|
|
|
getData();
|
|
|
|
|
|
}else{
|
|
|
|
|
|
ElMessage.error("删除失败");
|
|
|
|
|
|
}
|
|
|
|
|
|
}catch(e){
|
|
|
|
|
|
console.log(e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped></style>
|