feat: 新增角色相关页面(WIP)

This commit is contained in:
李寻欢 2024-02-05 17:29:32 +08:00
parent 38d36c41db
commit e2d1d5b7d3
5 changed files with 146 additions and 12 deletions

20
src/api/role.ts Normal file
View File

@ -0,0 +1,20 @@
import { http } from "@/utils/http";
import { BaseResponse } from "@/api/base";
/* 角色返回结果 */
export type RoleResult = {
id: string;
createdAt: Date;
updatedAt: Date;
name: string;
code: string;
describe: string;
};
export const getAllRole = (data: any) => {
return http.request<BaseResponse<Array<RoleResult>>>(
"get",
"/admin/v1/role",
{ data }
);
};

View File

@ -73,8 +73,12 @@ const getAllRobotHandle = async () => {
// //
robotList.value = res.data; robotList.value = res.data;
}) })
.catch(() => { .catch(e => {
message("获取机器人列表失败", { type: "error" }); const response = e.response.data;
message(
response.message + (response.errMsg ? ": " + response.errMsg : ""),
{ type: "error" }
);
}) })
.finally(() => { .finally(() => {
// //
@ -329,12 +333,12 @@ onMounted(() => {
<style lang="scss" scoped> <style lang="scss" scoped>
.card-container { .card-container {
margin: 10px;
width: 100%;
display: flex; display: flex;
flex-wrap: wrap; flex-wrap: wrap;
gap: 20px; gap: 20px;
justify-content: flex-start; /* 改为 flex-start 以优先横向排列 */ justify-content: flex-start; /* 改为 flex-start 以优先横向排列 */
width: 100%;
margin: 10px;
} }
.robot-card { .robot-card {
@ -345,8 +349,8 @@ onMounted(() => {
.robot-header { .robot-header {
display: flex; display: flex;
justify-content: space-between;
align-items: center; align-items: center;
justify-content: space-between;
} }
.robot-name { .robot-name {
@ -362,7 +366,7 @@ onMounted(() => {
.vncIframe { .vncIframe {
width: 1280px; width: 1280px;
height: 747px; height: 747px;
transform-origin: left top;
transform: scale(0.95, 0.95); transform: scale(0.95, 0.95);
transform-origin: left top;
} }
</style> </style>

View File

@ -1,12 +1,86 @@
<script setup lang="ts"> <script setup lang="ts">
import {
searchForm,
loading,
getAllRoleHandle,
tableData
} from "./utils/setting";
import { onMounted } from "vue";
import { useRenderIcon } from "@/components/ReIcon/src/hooks";
import Refresh from "@iconify-icons/ep/refresh";
import Search from "@iconify-icons/ep/search";
defineOptions({ defineOptions({
name: "AdminRole" name: "AdminRole"
}); });
//
const onSearch = () => {
console.log("搜索");
};
//
const resetForm = () => {
console.log("重置");
};
onMounted(() => {
//
getAllRoleHandle();
});
</script> </script>
<template> <template>
<div class="flex justify-center items-center h-[640px]"> <div class="main">
角色管理 <el-form
ref="formRef"
:inline="true"
:model="searchForm"
class="search-form bg-bg_color w-[99/100] pl-8 pt-[12px]"
>
<el-form-item label="角色名称:" prop="name">
<el-input
v-model="searchForm.name"
placeholder="请输入角色名称"
clearable
class="!w-[180px]"
/>
</el-form-item>
<el-form-item label="角色标识:" prop="code">
<el-input
v-model="searchForm.code"
placeholder="请输入角色标识"
clearable
class="!w-[180px]"
/>
</el-form-item>
<el-form-item>
<el-button
type="primary"
:icon="useRenderIcon(Search)"
:loading="loading"
@click="onSearch"
>
搜索
</el-button>
<el-button :icon="useRenderIcon(Refresh)" @click="resetForm">
重置
</el-button>
</el-form-item>
</el-form>
<el-table :data="tableData" style="width: 100%; margin-top: 20px">
<el-table-column fixed prop="id" label="Id" width="300px" />
<el-table-column prop="name" label="名称" />
<el-table-column prop="code" label="角色代码" />
<el-table-column prop="describe" label="描述" />
<el-table-column prop="createdAt" label="创建时间" />
<el-table-column prop="updatedAt" label="更新时间" />
<el-table-column fixed="right" label="操作" width="120">
<template #default>
<el-button link type="primary" size="small">编辑</el-button>
</template>
</el-table-column>
</el-table>
</div> </div>
</template> </template>

View File

@ -0,0 +1,39 @@
import { reactive, ref } from "vue";
import { getAllRole, RoleResult } from "@/api/role";
import { message } from "@/utils/message";
// 查询表单
const searchForm = reactive({
keyword: "",
code: ""
});
// 数据加载状态
const loading = ref(true);
// 表格数据
const tableData = ref([] as RoleResult[]);
const getAllRoleHandle = () => {
// 设置为加载中
loading.value = true;
// 调用接口,获取数据
getAllRole(searchForm)
.then(res => {
// 获取成功,设置数据
tableData.value = res.data;
})
.catch(e => {
const response = e.response.data;
message(
response.message + (response.errMsg ? ": " + response.errMsg : ""),
{ type: "error" }
);
})
.finally(() => {
// 关闭加载动画
loading.value = false;
});
};
export { searchForm, loading, getAllRoleHandle, tableData };

View File

@ -2,11 +2,8 @@
defineOptions({ defineOptions({
name: "AdminUser" name: "AdminUser"
}); });
</script> </script>
<template> <template>
<div class="flex justify-center items-center h-[640px]"> <div class="flex justify-center items-center h-[640px]">用户管理</div>
用户管理
</div>
</template> </template>