完成模型管理
This commit is contained in:
parent
2a4efd1ead
commit
5f6936ad0a
|
|
@ -5,7 +5,7 @@
|
||||||
<TableCustom :columns="columns" :tableData="tableData" :total="page.total" :viewFunc="handleView"
|
<TableCustom :columns="columns" :tableData="tableData" :total="page.total" :viewFunc="handleView"
|
||||||
:delFunc="handleDelete" :page-change="changePage" :editFunc="handleEdit">
|
:delFunc="handleDelete" :page-change="changePage" :editFunc="handleEdit">
|
||||||
<template #toolbarBtn>
|
<template #toolbarBtn>
|
||||||
<el-button type="warning" :icon="CirclePlusFilled" @click="visible_add = true">新增</el-button>
|
<el-button type="warning" :icon="CirclePlusFilled" @click="visible_add = true" v-if="userRole">新增</el-button>
|
||||||
</template>
|
</template>
|
||||||
</TableCustom>
|
</TableCustom>
|
||||||
|
|
||||||
|
|
@ -29,43 +29,37 @@ import { ref, reactive } from 'vue';
|
||||||
import { ElMessage } from 'element-plus';
|
import { ElMessage } from 'element-plus';
|
||||||
import { CirclePlusFilled } from '@element-plus/icons-vue';
|
import { CirclePlusFilled } from '@element-plus/icons-vue';
|
||||||
import { UserInfo } from '@/types/user';
|
import { UserInfo } from '@/types/user';
|
||||||
|
import { Model } from '@/types/model';
|
||||||
import { fetchUserData } from '@/api';
|
import { fetchUserData } from '@/api';
|
||||||
import { SearchUserService } from "@/api/user";
|
import {FindModelService} from "@/api/model";
|
||||||
import {GetUserInfoService} from "@/api/user";
|
import {UpdateModelService} from "@/api/model";
|
||||||
import {updateUserInfoService} from "@/api/user";
|
import {AddModelService} from "@/api/model";
|
||||||
|
import {DelModelService} from "@/api/model";
|
||||||
import TableCustom from '@/components/table-custom.vue';
|
import TableCustom from '@/components/table-custom.vue';
|
||||||
import TableDetail from '@/components/table-detail.vue';
|
import TableDetail from '@/components/table-detail.vue';
|
||||||
import TableSearch from '@/components/table-search.vue';
|
import TableSearch from '@/components/table-search.vue';
|
||||||
import { FormOption, FormOptionList } from '@/types/form-option';
|
import { FormOption, FormOptionList } from '@/types/form-option';
|
||||||
|
|
||||||
|
const userRole = localStorage.getItem('role') == 'admin';
|
||||||
|
|
||||||
// 查询相关
|
// 查询相关
|
||||||
const query = reactive({
|
const query = reactive({
|
||||||
name: '',
|
name: '',
|
||||||
});
|
});
|
||||||
const searchOpt = ref<FormOptionList[]>([
|
const searchOpt = ref<FormOptionList[]>([
|
||||||
{ type: 'input', label: '用户名或ID:', prop: 'name' }
|
{ type: 'input', label: '模型ID:', prop: 'name' }
|
||||||
])
|
])
|
||||||
const handleSearch = async () => {
|
const handleSearch = async () => {
|
||||||
let search_id= -1;
|
if (isFinite(query.name) == false){
|
||||||
let keyword_ = "";
|
ElMessage.error("请输入正确的会话ID");
|
||||||
//判断search_id是字符串还是数字
|
|
||||||
if(isNaN(query.name)){
|
|
||||||
//是字符串,说明是关键字
|
|
||||||
keyword_ = query.name;
|
|
||||||
}else if(isFinite(query.name)){
|
|
||||||
//是数字,说明是ID
|
|
||||||
search_id = parseInt(query.name);
|
|
||||||
}else{
|
|
||||||
//不是数字也不是字符串
|
|
||||||
ElMessage.error("输入错误,请输入数字或者关键字");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let req={
|
let req={
|
||||||
token: localStorage.getItem('token'),
|
token: localStorage.getItem('token'),
|
||||||
id: search_id,
|
type: "ID",
|
||||||
keyword: keyword_,
|
id: parseInt(query.name)
|
||||||
}
|
}
|
||||||
let result = await SearchUserService(req);
|
let result = await FindModelService(req);
|
||||||
tableData.value = result.data;
|
tableData.value = result.data;
|
||||||
page.total = result.data.length;
|
page.total = result.data.length;
|
||||||
};
|
};
|
||||||
|
|
@ -73,27 +67,26 @@ const handleSearch = async () => {
|
||||||
// 表格相关
|
// 表格相关
|
||||||
let columns = ref([
|
let columns = ref([
|
||||||
{ type: 'index', label: '序号', width: 55, align: 'center' },
|
{ type: 'index', label: '序号', width: 55, align: 'center' },
|
||||||
{ prop: 'ID', label: '用户ID' },
|
{ prop: 'ID', label: '模型ID' },
|
||||||
{ prop: 'Name', label: '用户名' },
|
{prop: 'Url', label: 'URl'},
|
||||||
{ prop: 'Age', label: '年龄'},
|
{ prop: 'Type', label: '类型' },
|
||||||
{ prop: 'Role', label: '角色' },
|
{ prop: 'Parameter', label: '参数' },
|
||||||
|
{prop: 'Description', label: '描述'},
|
||||||
{ prop: 'CreatedAt', label: '创建时间',type: 'date' },
|
{ prop: 'CreatedAt', label: '创建时间',type: 'date' },
|
||||||
{ prop: 'Email', label: '邮箱' },
|
{ prop: 'operator', label: '操作', width: 250 , operate: { view: true, edit: true, delete: true,push: {link: false,label:"继续该会话"} }},
|
||||||
{ prop: 'operator', label: '操作', width: 250 },
|
|
||||||
])
|
])
|
||||||
const page = reactive({
|
const page = reactive({
|
||||||
index: 1,
|
index: 1,
|
||||||
size: 10,
|
size: 10,
|
||||||
total: 122,
|
total: 122,
|
||||||
})
|
})
|
||||||
const tableData = ref<UserInfo[]>([]);
|
const tableData = ref<Model[]>([]);
|
||||||
const getData = async () => {
|
const getData = async () => {
|
||||||
let req={
|
let req={
|
||||||
token: localStorage.getItem('token'),
|
token: localStorage.getItem('token'),
|
||||||
id: -1,
|
type: "UserID"
|
||||||
keyword: "_121",
|
|
||||||
}
|
}
|
||||||
let result = await SearchUserService(req);
|
let result = await FindModelService(req);
|
||||||
tableData.value = result.data;
|
tableData.value = result.data;
|
||||||
page.total = result.data.length;
|
page.total = result.data.length;
|
||||||
};
|
};
|
||||||
|
|
@ -109,10 +102,10 @@ let options = ref<FormOption>({
|
||||||
labelWidth: '100px',
|
labelWidth: '100px',
|
||||||
span: 12,
|
span: 12,
|
||||||
list: [
|
list: [
|
||||||
{ type: 'input', label: '用户名', prop: 'Name', required: true },
|
{ type: 'input', label: '类型', prop: 'Type', required: true },
|
||||||
{ type: 'input', label: '密码', prop: 'Password', required: true },
|
{ type: 'input', label: 'URL', prop: 'Url', required: true },
|
||||||
{ type: 'input', label: '邮箱', prop: 'Email', required: true },
|
{ type: 'input', label: '参数', prop: 'Parameter', required: true },
|
||||||
{ type: 'input', label: '角色', prop: 'Role', required: true },
|
{ type: 'input', label: '描述', prop: 'Description', required: true },
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -121,15 +114,10 @@ let options_edit = ref<FormOption>({
|
||||||
labelWidth: '100px',
|
labelWidth: '100px',
|
||||||
span: 12,
|
span: 12,
|
||||||
list: [
|
list: [
|
||||||
{prop: 'Avatar',label: '头像', type: 'input', required: false},
|
{ type: 'input', label: '类型', prop: 'Type', required: true },
|
||||||
{ type: 'input', label: '用户名', prop: 'Name', required: true },
|
{ type: 'input', label: 'URL', prop: 'Url', required: true },
|
||||||
{ type: 'input', label: '年龄', prop: 'Age', required: false },
|
{ type: 'input', label: '参数', prop: 'Parameter', required: true },
|
||||||
{ type: 'input', label: '密码', prop: 'Password', required: false },
|
{ type: 'input', label: '描述', prop: 'Description', required: true },
|
||||||
{ type: 'input', label: '邮箱', prop: 'Email', required: true },
|
|
||||||
{ type: 'input', label: '性别', prop: 'Gender', required: false },
|
|
||||||
//select 选择框,可选择admin与user两种角色
|
|
||||||
{ type: 'select', label: '角色', prop: 'Role', opts: [{label:"管理员",value:"admin"},{label:"普通用户",value:"user"}],required: false },
|
|
||||||
|
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -138,10 +126,10 @@ const visible_add = ref(false);
|
||||||
const isEdit = ref(false);
|
const isEdit = ref(false);
|
||||||
const isAdd = ref(false);
|
const isAdd = ref(false);
|
||||||
const rowData = ref({});
|
const rowData = ref({});
|
||||||
const handleEdit = async (row: UserInfo) => {
|
const handleEdit = async (row: Model) => {
|
||||||
let data = await getUserInfo(row.ID);
|
let data = row;
|
||||||
|
|
||||||
rowData.value = data;
|
rowData.value = data;
|
||||||
|
console.log("edit_row_data:", rowData.value);
|
||||||
isEdit.value = true;
|
isEdit.value = true;
|
||||||
visible.value = true;
|
visible.value = true;
|
||||||
};
|
};
|
||||||
|
|
@ -150,19 +138,13 @@ const updateData = async (data) => {
|
||||||
try{
|
try{
|
||||||
let req={};
|
let req={};
|
||||||
req.token=localStorage.getItem("token");
|
req.token=localStorage.getItem("token");
|
||||||
//console.log(rowData.value);
|
|
||||||
|
|
||||||
//修改后的数据
|
//修改后的数据
|
||||||
req.id = data.ID;
|
req.id = data.ID;
|
||||||
req.name = data.Name;
|
req.type = data.Type;
|
||||||
req.age = data.Age;
|
req.url = data.Url;
|
||||||
req.gender = data.Gender;
|
req.parameter = data.Parameter;
|
||||||
req.password = data.Password;
|
req.description = data.Description;
|
||||||
req.email = data.Email;
|
result = await UpdateModelService(req)
|
||||||
req.avatar = data.Avatar;
|
|
||||||
req.Role = data.Role;
|
|
||||||
|
|
||||||
result = await updateUserInfoService(req)
|
|
||||||
if (result.code === 0) {
|
if (result.code === 0) {
|
||||||
ElMessage.success("更新成功");
|
ElMessage.success("更新成功");
|
||||||
this.updateDialogVisible = false;
|
this.updateDialogVisible = false;
|
||||||
|
|
@ -174,26 +156,34 @@ const updateData = async (data) => {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
}
|
}
|
||||||
closeDialog();
|
closeDialog();
|
||||||
handleSearch();
|
getData();
|
||||||
};
|
};
|
||||||
|
|
||||||
const getUserInfo = async (id) => {
|
const addData = async (data) => {
|
||||||
let result = {};
|
let result ={}
|
||||||
try{
|
try{
|
||||||
//获取用户信息
|
let req={};
|
||||||
let req={
|
req.token=localStorage.getItem("token");
|
||||||
token: localStorage.getItem('token'),
|
//修改后的数据
|
||||||
id: id,
|
req.type = data.Type;
|
||||||
};
|
req.url = data.Url;
|
||||||
result = await GetUserInfoService(req)
|
req.parameter = data.Parameter;
|
||||||
if(result.code===0){
|
req.description = data.Description;
|
||||||
return result.data;
|
result = await AddModelService(req)
|
||||||
|
if (result.code === 0) {
|
||||||
|
ElMessage.success("新增成功");
|
||||||
|
this.updateDialogVisible = false;
|
||||||
|
} else {
|
||||||
|
ElMessage.error("新增失败");
|
||||||
}
|
}
|
||||||
|
|
||||||
}catch(e){
|
}catch(e){
|
||||||
console.log(e);
|
console.log(e);
|
||||||
}
|
}
|
||||||
return {};
|
closeDialog();
|
||||||
}
|
getData();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
const closeDialog = () => {
|
const closeDialog = () => {
|
||||||
visible.value = false;
|
visible.value = false;
|
||||||
|
|
@ -205,50 +195,64 @@ const closeDialog = () => {
|
||||||
const visible1 = ref(false);
|
const visible1 = ref(false);
|
||||||
const viewData = ref({
|
const viewData = ref({
|
||||||
row: {},
|
row: {},
|
||||||
list: []
|
list: [
|
||||||
|
|
||||||
|
]
|
||||||
});
|
});
|
||||||
const handleView =async (row: UserInfo) => {
|
const handleView =async (row: Model) => {
|
||||||
let data = await getUserInfo(row.ID);
|
viewData.value.row = row;
|
||||||
viewData.value.row = data;
|
|
||||||
viewData.value.list = [
|
viewData.value.list = [
|
||||||
{
|
|
||||||
prop: 'Avatar',
|
|
||||||
label: '头像', //显示头像
|
|
||||||
type: 'image',
|
|
||||||
width: 100,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
prop: 'ID',
|
prop: 'ID',
|
||||||
label: '用户ID',
|
label: '模型ID',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
prop: 'Name',
|
prop: 'Url',
|
||||||
label: '用户名',
|
label: 'URL',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
prop: 'Email',
|
prop: 'Type',
|
||||||
label: '邮箱',
|
label: '类型',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
prop: 'Gender',
|
prop: 'Parameter',
|
||||||
label: '性别',
|
label: '参数',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
prop: 'Role',
|
prop: 'Description',
|
||||||
label: '角色',
|
label: '描述',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
prop: 'CreatedAt',
|
prop: 'CreatedAt',
|
||||||
label: '注册日期',
|
label: '创建时间',
|
||||||
type: 'date',
|
type: 'date'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
prop: 'UpdatedAt',
|
||||||
|
label: '更新时间',
|
||||||
|
type: 'date'
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
visible1.value = true;
|
visible1.value = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
// 删除相关
|
// 删除相关
|
||||||
const handleDelete = (row: UserInfo) => {
|
const handleDelete = async (row: Model) => {
|
||||||
ElMessage.success('删除成功');
|
let req={
|
||||||
|
token: localStorage.getItem('token'),
|
||||||
|
id: row.ID,
|
||||||
|
}
|
||||||
|
try{
|
||||||
|
let result = await DelModelService(req);
|
||||||
|
if(result.code===0){
|
||||||
|
ElMessage.success("删除成功");
|
||||||
|
getData();
|
||||||
|
}else{
|
||||||
|
ElMessage.error("删除失败");
|
||||||
|
}
|
||||||
|
}catch(e){
|
||||||
|
console.log(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue