diff --git a/mock/asyncRoutes.ts b/mock/asyncRoutes.ts index e3823501e..73b6b1418 100644 --- a/mock/asyncRoutes.ts +++ b/mock/asyncRoutes.ts @@ -65,7 +65,7 @@ const systemMonitorRouter = { children: [ { path: "/monitor/online-user", - component: "monitor/online", + component: "monitor/online/index", name: "OnlineUser", meta: { icon: "ri:user-voice-line", diff --git a/mock/system.ts b/mock/system.ts index 6a5a43733..7c10baaa7 100644 --- a/mock/system.ts +++ b/mock/system.ts @@ -688,7 +688,7 @@ export default defineFakeRoute([ title: "menus.hsOnlineUser", name: "OnlineUser", path: "/monitor/online-user", - component: "monitor/online", + component: "monitor/online/index", rank: null, redirect: "", icon: "ri:user-voice-line", @@ -1011,5 +1011,42 @@ export default defineFakeRoute([ ] }; } + }, + // 在线用户 + { + url: "/online", + method: "post", + response: ({ body }) => { + let list = [ + { + id: 1, + username: "admin", + ip: faker.internet.ipv4(), + address: "中国河南省信阳市", + system: "macOS", + browser: "Chrome", + loginTime: new Date() + }, + { + id: 2, + username: "common", + ip: faker.internet.ipv4(), + address: "中国广东省深圳市", + system: "Windows", + browser: "Firefox", + loginTime: new Date() + } + ]; + list = list.filter(item => item.username.includes(body?.username)); + return { + success: true, + data: { + list, + total: list.length, // 总条目数 + pageSize: 10, // 每页显示条目个数 + currentPage: 1 // 当前页数 + } + }; + } } ]); diff --git a/src/api/system.ts b/src/api/system.ts index 1518ae060..2c0273d1e 100644 --- a/src/api/system.ts +++ b/src/api/system.ts @@ -19,32 +19,37 @@ type ResultTable = { }; }; -/** 获取用户管理列表 */ +/** 获取系统管理-用户管理列表 */ export const getUserList = (data?: object) => { return http.request("post", "/user", { data }); }; -/** 用户管理-获取所有角色列表 */ +/** 系统管理-用户管理-获取所有角色列表 */ export const getAllRoleList = () => { return http.request("get", "/list-all-role"); }; -/** 用户管理-根据userId,获取对应角色id列表(userId:用户id) */ +/** 系统管理-用户管理-根据userId,获取对应角色id列表(userId:用户id) */ export const getRoleIds = (data?: object) => { return http.request("post", "/list-role-ids", { data }); }; -/** 获取角色管理列表 */ +/** 获取系统管理-角色管理列表 */ export const getRoleList = (data?: object) => { return http.request("post", "/role", { data }); }; -/** 获取部门管理列表 */ +/** 获取系统管理-菜单管理列表 */ +export const getMenuList = (data?: object) => { + return http.request("post", "/menu", { data }); +}; + +/** 获取系统管理-部门管理列表 */ export const getDeptList = (data?: object) => { return http.request("post", "/dept", { data }); }; -/** 获取菜单管理列表 */ -export const getMenuList = (data?: object) => { - return http.request("post", "/menu", { data }); +/** 获取系统监控-在线用户列表 */ +export const getOnlineList = (data?: object) => { + return http.request("post", "/online", { data }); }; diff --git a/src/views/monitor/online.vue b/src/views/monitor/online.vue deleted file mode 100644 index b7caacf30..000000000 --- a/src/views/monitor/online.vue +++ /dev/null @@ -1,9 +0,0 @@ - - - diff --git a/src/views/monitor/online/hook.tsx b/src/views/monitor/online/hook.tsx new file mode 100644 index 000000000..f26c70364 --- /dev/null +++ b/src/views/monitor/online/hook.tsx @@ -0,0 +1,117 @@ +import dayjs from "dayjs"; +import { message } from "@/utils/message"; +import { getOnlineList } from "@/api/system"; +import { reactive, ref, onMounted, toRaw } from "vue"; +import type { PaginationProps } from "@pureadmin/table"; + +export function useRole() { + const form = reactive({ + username: "" + }); + const dataList = ref([]); + const loading = ref(true); + const pagination = reactive({ + total: 0, + pageSize: 10, + currentPage: 1, + background: true + }); + const columns: TableColumnList = [ + { + label: "序号", + prop: "id", + minWidth: 60 + }, + { + label: "用户名", + prop: "username", + minWidth: 100 + }, + { + label: "登录 IP", + prop: "ip", + minWidth: 140 + }, + { + label: "登录地点", + prop: "address", + minWidth: 140 + }, + { + label: "操作系统", + prop: "system", + minWidth: 100 + }, + { + label: "浏览器类型", + prop: "browser", + minWidth: 100 + }, + { + label: "登录时间", + prop: "loginTime", + minWidth: 180, + formatter: ({ loginTime }) => + dayjs(loginTime).format("YYYY-MM-DD HH:mm:ss") + }, + { + label: "操作", + fixed: "right", + slot: "operation" + } + ]; + + function handleSizeChange(val: number) { + console.log(`${val} items per page`); + } + + function handleCurrentChange(val: number) { + console.log(`current page: ${val}`); + } + + function handleSelectionChange(val) { + console.log("handleSelectionChange", val); + } + + function handleOffline(row) { + message(`${row.username}已被强制下线`, { type: "success" }); + onSearch(); + } + + async function onSearch() { + loading.value = true; + const { data } = await getOnlineList(toRaw(form)); + dataList.value = data.list; + pagination.total = data.total; + pagination.pageSize = data.pageSize; + pagination.currentPage = data.currentPage; + + setTimeout(() => { + loading.value = false; + }, 500); + } + + const resetForm = formEl => { + if (!formEl) return; + formEl.resetFields(); + onSearch(); + }; + + onMounted(() => { + onSearch(); + }); + + return { + form, + loading, + columns, + dataList, + pagination, + onSearch, + resetForm, + handleOffline, + handleSizeChange, + handleCurrentChange, + handleSelectionChange + }; +} diff --git a/src/views/monitor/online/index.vue b/src/views/monitor/online/index.vue new file mode 100644 index 000000000..4b927155c --- /dev/null +++ b/src/views/monitor/online/index.vue @@ -0,0 +1,125 @@ + + + + +