Skip to content

Commit

Permalink
refactor: 优化系统日志、在线用户、存储管理、部门管理相关代码
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles7c committed Apr 22, 2024
1 parent 2ddd900 commit 2987d3e
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 51 deletions.
2 changes: 1 addition & 1 deletion src/apis/monitor/online.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import http from '@/utils/http'
import type * as Monitor from './type'

const BASE_URL = '/monitor/online/user'
const BASE_URL = '/monitor/online'

/** @desc 查询在线用户列表 */
export function listOnlineUser(query: Monitor.OnlineUserQuery) {
Expand Down
24 changes: 12 additions & 12 deletions src/views/monitor/log/login/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</template>
<template #custom-right>
<a-tooltip content="导出">
<a-button @click="onExport">
<a-button v-permission="['monitor:log:export']" @click="onExport">
<template #icon>
<icon-download />
</template>
Expand Down Expand Up @@ -109,6 +109,17 @@ const {
search
} = useTable((p) => listLog({ ...queryForm, page: p.page, size: p.size }), { immediate: true })
// 过滤查询
const filterChange = (dataIndex, filteredValues) => {
try {
const slotName = columns[dataIndex.split('_').pop()].slotName as string
queryForm[slotName] = filteredValues.join(',')
search()
} catch (error) {
search()
}
}
// 重置
const reset = () => {
queryForm.ip = undefined
Expand All @@ -125,17 +136,6 @@ const reset = () => {
const onExport = () => {
useDownload(() => exportLoginLog(queryForm))
}
// 过滤查询
const filterChange = (dataIndex, filteredValues) => {
try {
const slotName = columns[dataIndex.split('_').pop()].slotName as string
queryForm[slotName] = filteredValues.join(',')
search()
} catch (error) {
search()
}
}
</script>

<style lang="scss" scoped></style>
6 changes: 3 additions & 3 deletions src/views/monitor/log/operation/OperationLogDetailDrawer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@ const getDataDetail = async () => {
}
const visible = ref(false)
// 打开详情
const open = async (id: string) => {
// 详情
const onDetail = async (id: string) => {
dataId.value = id
await getDataDetail()
visible.value = true
}
defineExpose({ open })
defineExpose({ onDetail })
</script>

<style lang="scss" scoped>
Expand Down
36 changes: 18 additions & 18 deletions src/views/monitor/log/operation/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
</template>
<template #custom-right>
<a-tooltip content="导出">
<a-button @click="onExport">
<a-button v-permission="['monitor:log:export']" @click="onExport">
<template #icon>
<icon-download />
</template>
</a-button>
</a-tooltip>
</template>
<template #createTime="{ record }">
<a-link @click="openDetail(record)">{{ record.createTime }}</a-link>
<a-link @click="onDetail(record)">{{ record.createTime }}</a-link>
</template>
<template #status="{ record }">
<a-tag v-if="record.status === 1" color="green">
Expand All @@ -57,9 +57,9 @@

<script setup lang="ts">
import { listLog, exportOperationLog, type LogResp } from '@/apis'
import OperationLogDetailDrawer from './OperationLogDetailDrawer.vue'
import type { TableInstanceColumns } from '@/components/GiTable/type'
import DateRangePicker from '@/components/DateRangePicker/index.vue'
import OperationLogDetailDrawer from './OperationLogDetailDrawer.vue'
import { useTable, useDownload } from '@/hooks'
import dayjs from 'dayjs'
Expand Down Expand Up @@ -121,7 +121,18 @@ const {
search
} = useTable((p) => listLog({ ...queryForm, page: p.page, size: p.size }), { immediate: true })
// 重置查询
// 过滤查询
const filterChange = (dataIndex, filteredValues) => {
try {
const slotName = columns[dataIndex.split('_').pop()].slotName as string
queryForm[slotName] = filteredValues.join(',')
search()
} catch (error) {
search()
}
}
// 重置
const reset = () => {
queryForm.description = undefined
queryForm.ip = undefined
Expand All @@ -139,21 +150,10 @@ const onExport = () => {
useDownload(() => exportOperationLog(queryForm))
}
// 过滤查询
const filterChange = (dataIndex, filteredValues) => {
try {
const slotName = columns[dataIndex.split('_').pop()].slotName as string
queryForm[slotName] = filteredValues.join(',')
search()
} catch (error) {
search()
}
}
const OperationLogDetailDrawerRef = ref<InstanceType<typeof OperationLogDetailDrawer>>()
// 查询详情
const openDetail = (item: LogResp) => {
OperationLogDetailDrawerRef.value?.open(item.id)
// 详情
const onDetail = (item: LogResp) => {
OperationLogDetailDrawerRef.value?.onDetail(item.id)
}
</script>

Expand Down
14 changes: 11 additions & 3 deletions src/views/monitor/online/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
@ok="handleKickout(record.token)"
>
<a-link
v-permission="['monitor:online:kickout']"
status="danger"
:title="currentToken === record.token ? '不能强退自己' : '强退'"
:disabled="currentToken === record.token"
Expand All @@ -50,9 +51,12 @@ import DateRangePicker from '@/components/DateRangePicker/index.vue'
import { useUserStore } from '@/stores'
import { useTable } from '@/hooks'
import { isMobile } from '@/utils'
import has from '@/utils/has'
defineOptions({ name: 'MonitorOnline' })
const userStore = useUserStore()
const currentToken = userStore.token
const columns: TableInstanceColumns[] = [
{
title: '序号',
Expand All @@ -66,7 +70,13 @@ const columns: TableInstanceColumns[] = [
{ title: '浏览器', dataIndex: 'browser', ellipsis: true, tooltip: true },
{ title: '终端系统', dataIndex: 'os', ellipsis: true, tooltip: true },
{ title: '登录时间', dataIndex: 'loginTime', width: 180 },
{ title: '操作', slotName: 'action', align: 'center', fixed: !isMobile() ? 'right' : undefined }
{
title: '操作',
slotName: 'action',
align: 'center',
fixed: !isMobile() ? 'right' : undefined,
show: has.hasPermOr(['monitor:online:kickout'])
}
]
const queryForm = reactive({
Expand All @@ -89,8 +99,6 @@ const reset = () => {
search()
}
const userStore = useUserStore()
const currentToken = userStore.token
// 强退
const handleKickout = (token: string) => {
kickout(token).then(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/views/system/dept/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ import DeptAddModal from './DeptAddModal.vue'
import { Message } from '@arco-design/web-vue'
import type GiTable from '@/components/GiTable/index.vue'
import type { TableInstanceColumns } from '@/components/GiTable/type'
import { DisEnableStatusList } from '@/constant/common'
import { useDownload } from '@/hooks'
import { isMobile } from '@/utils'
import has from '@/utils/has'
import { DisEnableStatusList } from '@/constant/common'
defineOptions({ name: 'SystemDept' })
Expand Down
2 changes: 1 addition & 1 deletion src/views/system/role/RoleAddModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
:title="title"
:mask-closable="false"
:esc-to-close="false"
:width="width >= 580 ? 580 : '100%'"
:width="width >= 600 ? 600 : '100%'"
@before-ok="save"
@close="reset"
>
Expand Down
2 changes: 1 addition & 1 deletion src/views/system/role/RoleDetailDrawer.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<a-drawer v-model:visible="visible" title="角色详情" :width="width >= 580 ? 580 : '100%'" :footer="false">
<a-drawer v-model:visible="visible" title="角色详情" :width="width >= 600 ? 600 : '100%'" :footer="false">
<a-descriptions title="基础信息" :column="2" size="large" class="general-description">
<a-descriptions-item label="ID" :span="2">{{ dataDetail?.id }}</a-descriptions-item>
<a-descriptions-item label="名称">{{ dataDetail?.name }}</a-descriptions-item>
Expand Down
2 changes: 1 addition & 1 deletion src/views/system/storage/StorageAddModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
:title="title"
:mask-closable="false"
:esc-to-close="false"
:width="width >= 580 ? 580 : '100%'"
:width="width >= 600 ? 600 : '100%'"
@before-ok="save"
@close="reset"
>
Expand Down
6 changes: 3 additions & 3 deletions src/views/system/storage/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<a-link
v-permission="['system:storage:delete']"
status="danger"
:title="record.isDefault ? '默认存储库不能删除' : undefined"
:title="record.isDefault ? '默认存储不能删除' : undefined"
:disabled="record.disabled"
@click="onDelete(record)"
>
Expand Down Expand Up @@ -104,9 +104,9 @@ const columns: TableInstanceColumns[] = [
title: '操作',
slotName: 'action',
width: 130,
show: has.hasPermOr(['system:storage:update', 'system:storage:delete']),
align: 'center',
fixed: !isMobile() ? 'right' : undefined
fixed: !isMobile() ? 'right' : undefined,
show: has.hasPermOr(['system:storage:update', 'system:storage:delete'])
}
]
Expand Down
10 changes: 4 additions & 6 deletions src/views/system/user/UserAddModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
:title="title"
:mask-closable="false"
:esc-to-close="false"
:width="width >= 580 ? 580 : '100%'"
:width="width >= 600 ? 600 : '100%'"
@before-ok="save"
@close="reset"
>
Expand Down Expand Up @@ -160,26 +160,24 @@ const onUpdate = async (id: string) => {
// 保存
const save = async () => {
const rawPassword = form.password
try {
const isInvalid = await formRef.value?.validate()
if (isInvalid) return false
if (isUpdate.value) {
await updateUser(form, dataId.value)
Message.success('修改成功')
} else {
const rawPassword = form.password
if (rawPassword) {
form.password = encryptByRsa(rawPassword) || ''
}
await addUser(form).catch(() => {
form.password = rawPassword
return false
})
await addUser(form)
Message.success('新增成功')
}
emit('save-success')
return true
} catch (error) {
form.password = rawPassword
return false
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/views/system/user/UserDetailDrawer.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<a-drawer v-model:visible="visible" title="用户详情" :width="width >= 580 ? 580 : '100%'" :footer="false">
<a-drawer v-model:visible="visible" title="用户详情" :width="width >= 600 ? 600 : '100%'" :footer="false">
<a-descriptions :column="2" size="large" class="general-description">
<a-descriptions-item label="ID" :span="2">{{ dataDetail?.id }}</a-descriptions-item>
<a-descriptions-item label="用户名">{{ dataDetail?.username }}</a-descriptions-item>
Expand Down

0 comments on commit 2987d3e

Please sign in to comment.