1 parent
9dc861d560
commit
fd475cd88d
54 files changed
+987
-91
No files matched your search
@@ -148,7 +148,7 @@ export function usePage(pageKey = 'base') {
|
||||
const restartPreview = ref(null)
|
||||
const hasChanges = computed(() => editorText.value !== loadedText.value || !!secretValue.value || !!savedGeneration.value)
|
||||
|
||||
const canWrite = computed(() => globalStatus.hasCapability('config.write_global'))
|
||||
const canWrite = computed(() => globalStatus.hasCapability(apiSection() === 'plugins' ? 'plugin.write_global' : 'config.write_global'))
|
||||
const canRollback = computed(() => globalStatus.hasCapability('config.rollback'))
|
||||
const canMigrate = computed(() => globalStatus.hasCapability('database.migrate'))
|
||||
const canRestart = computed(() => globalStatus.hasCapability('service.restart'))
|
||||
|
||||
@@ -56,10 +56,9 @@ export function usePage() {
|
||||
{ key: 'plugins', label: lang.plugin_settings, hint: '扩展功能管理', icon: Grid, component: PluginSettings, capability: 'plugin.read' },
|
||||
{ key: 'logs', label: '日志', hint: '操作、收发信与运行记录', icon: Document, component: LogSettings, capability: 'audit.read' },
|
||||
].filter(item => {
|
||||
// 全局日志包含其他账号与运行信息,不能把本人审计能力当作全局权限。
|
||||
if (item.key === 'logs' && globalStatus.role !== 'super_admin') return false
|
||||
// 日志数据范围由服务端强制过滤;菜单只决定入口是否可见。
|
||||
return globalStatus.hasCapability(item.capability) ||
|
||||
(item.key === 'plugins' && globalStatus.hasCapability('config.read'))
|
||||
(item.key === 'plugins' && globalStatus.hasCapability('plugin.read_global'))
|
||||
}))
|
||||
|
||||
const activeSettings = computed(() => settingsMenu.value.find(item => item.key === globalStatus.settingsActiveTab))
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
||||
import { http } from '@/utils/axios'
|
||||
import { useGlobalStatusStore } from '@/stores/useGlobalStatusStore'
|
||||
import { parseRuntimeLine, summarizeRuntime, timeParts } from './RuntimeLog.js'
|
||||
|
||||
export function useLogs() {
|
||||
const store = useGlobalStatusStore()
|
||||
const canFilterActor = computed(() => ['super_admin', 'admin'].includes(store.role))
|
||||
const category = ref('operation')
|
||||
const loading = ref(false)
|
||||
const error = ref('')
|
||||
@@ -90,7 +93,7 @@ export function useLogs() {
|
||||
return
|
||||
}
|
||||
appliedFilters = { kind: category.value, from: from.toISOString(), to: to.toISOString() }
|
||||
if (!isRuntime.value && actorId.value.trim()) appliedFilters.actorId = actorId.value.trim()
|
||||
if (canFilterActor.value && !isRuntime.value && actorId.value.trim()) appliedFilters.actorId = actorId.value.trim()
|
||||
offset.value = 0
|
||||
previousOffsets.length = 0
|
||||
detail.value = null
|
||||
@@ -125,6 +128,7 @@ export function useLogs() {
|
||||
|
||||
return {
|
||||
category, categories, loading, error, items, lines, offset,
|
||||
canFilterActor,
|
||||
hasMore, actorId, dateRange, detail, details, isRuntime,
|
||||
runtimeDetail, runtimeRows, runtimeSummary, visibleCount, pageRange,
|
||||
currentCategory, resultType, runtimeRowClass, timeParts,
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
format="YYYY-MM-DD HH:mm"
|
||||
aria-label="日志时间范围"
|
||||
/>
|
||||
<el-input v-if="!isRuntime" v-model="actorId" clearable placeholder="操作者编号" aria-label="操作者编号" @keyup.enter="search" />
|
||||
<el-input v-if="!isRuntime && canFilterActor" v-model="actorId" clearable placeholder="操作者编号" aria-label="操作者编号" @keyup.enter="search" />
|
||||
<div class="log-filter-actions">
|
||||
<el-button :disabled="loading" @click="recent">最近 24 小时</el-button>
|
||||
<el-button type="primary" :loading="loading" @click="search">查询</el-button>
|
||||
@@ -171,6 +171,7 @@ import { useLogs } from './LogSettings.js'
|
||||
|
||||
const {
|
||||
category, categories, loading, error, items, offset,
|
||||
canFilterActor,
|
||||
hasMore, actorId, dateRange, detail, details, isRuntime,
|
||||
runtimeDetail, runtimeRows, runtimeSummary, pageRange,
|
||||
currentCategory, resultType, runtimeRowClass, timeParts,
|
||||
|
||||
@@ -4,7 +4,7 @@ import { useGlobalStatusStore } from '@/stores/useGlobalStatusStore'
|
||||
|
||||
export function usePage() {
|
||||
const store = useGlobalStatusStore()
|
||||
const selectedSection = ref(store.hasCapability('config.read') ? 'spam_block' : 'telegram-user')
|
||||
const selectedSection = ref(store.hasCapability('plugin.read_global') ? 'spam_block' : 'telegram-user')
|
||||
const currentPage = ref(null)
|
||||
const pageHost = ref(null)
|
||||
const switching = ref(false)
|
||||
@@ -14,7 +14,7 @@ export function usePage() {
|
||||
let disposed = false
|
||||
|
||||
// 全局配置不依赖正在运行的插件列表,未启用的插件也必须可以配置。
|
||||
const sectionOptions = computed(() => store.hasCapability('config.read') ? [
|
||||
const sectionOptions = computed(() => store.hasCapability('plugin.read_global') ? [
|
||||
{ value: 'spam_block', label: '垃圾邮件拦截', kind: 'config' },
|
||||
{ value: 'telegram_push', label: 'Telegram 推送', kind: 'config' },
|
||||
{ value: 'wechat_push', label: '微信推送', kind: 'config' }
|
||||
|
||||
@@ -26,7 +26,7 @@ export function useSpamBlockSettings() {
|
||||
const settings = reactive({ ...defaultSettings })
|
||||
const hasChanges = computed(() => JSON.stringify(settings) !== savedInput)
|
||||
|
||||
const canWrite = () => globalStatus.hasCapability('config.write_global')
|
||||
const canWrite = () => globalStatus.hasCapability('plugin.write_global')
|
||||
|
||||
const notifyResponseError = (response, fallback) => {
|
||||
if (!response || response.errorNo !== 0) {
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
.profile-settings {
|
||||
max-width: 480px;
|
||||
width: 100%;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import { ref } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { http } from '@/utils/axios'
|
||||
import { useGlobalStatusStore } from '@/stores/useGlobalStatusStore'
|
||||
import { roleMeta } from '@/utils/userRoles.mjs'
|
||||
|
||||
export function useProfile() {
|
||||
const store = useGlobalStatusStore()
|
||||
const name = ref(store.userInfos.name || '')
|
||||
const saving = ref(false)
|
||||
async function save() {
|
||||
if (saving.value) return
|
||||
if (!name.value.trim()) return ElMessage.error('请输入显示名称')
|
||||
saving.value = true
|
||||
try {
|
||||
const result = await http.post('/api/v1/user/profile', { name: name.value.trim() })
|
||||
if (result?.errorNo !== 0) throw new Error(result?.errorMsg || '个人资料保存失败')
|
||||
store.userInfos.name = result.data.name
|
||||
name.value = result.data.name
|
||||
ElMessage.success('个人资料已保存')
|
||||
} catch (error) {
|
||||
ElMessage.error(error.message || '个人资料保存失败')
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
return { store, name, saving, save, roleMeta }
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<template>
|
||||
<section class="security-section profile-settings">
|
||||
<div class="settings-header">
|
||||
<h3>个人资料</h3>
|
||||
</div>
|
||||
<el-form label-position="top" @submit.prevent="save">
|
||||
<el-form-item label="当前账号">
|
||||
<el-input :model-value="store.userInfos.account" disabled />
|
||||
</el-form-item>
|
||||
<el-form-item label="权限级别">
|
||||
<el-tag :type="roleMeta(store.role).type">{{ roleMeta(store.role).label }}</el-tag>
|
||||
</el-form-item>
|
||||
<el-form-item label="显示名称">
|
||||
<el-input v-model="name" maxlength="10" placeholder="请输入显示名称" />
|
||||
</el-form-item>
|
||||
<el-button type="primary" native-type="submit" :loading="saving">
|
||||
保存资料
|
||||
</el-button>
|
||||
</el-form>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { useProfile } from './ProfileSettings.js'
|
||||
const { store, name, saving, save, roleMeta } = useProfile()
|
||||
</script>
|
||||
|
||||
<style scoped src="./ProfileSettings.css"></style>
|
||||
@@ -15,6 +15,7 @@ export function usePage() {
|
||||
const canReadGlobalPolicy = computed(() => globalStatus.hasCapability('config.read'))
|
||||
const sectionOptions = computed(() => {
|
||||
const options = []
|
||||
options.push({ value: 'profile', label: '个人资料' })
|
||||
if (canReadGlobalPolicy.value) {
|
||||
options.push({ value: 'security-policy', label: '安全策略' })
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
/>
|
||||
|
||||
<div class="security-main">
|
||||
<ProfileSettings v-if="selectedSection === 'profile'" />
|
||||
<GlobalSecurityPolicy
|
||||
v-if="selectedSection === 'security-policy'"
|
||||
ref="globalSecurityPolicyPage"
|
||||
@@ -102,6 +103,7 @@
|
||||
|
||||
<script setup>
|
||||
import { usePage } from './SecuritySettings.js'
|
||||
import ProfileSettings from './ProfileSettings/ProfileSettings.vue'
|
||||
import SettingsSubmenu from '../SettingsSubmenu/SettingsSubmenu.vue'
|
||||
import GlobalSecurityPolicy from './GlobalSecurityPolicy/GlobalSecurityPolicy.vue'
|
||||
import ExternalEmailBindingDialog from './ExternalEmailBindingDialog/ExternalEmailBindingDialog.vue'
|
||||
|
||||
@@ -72,8 +72,10 @@ export function usePage() {
|
||||
|
||||
const availableRoles = computed(() => assignableRoles(globalStatus.role))
|
||||
|
||||
const canCreateUser = computed(() => globalStatus.hasCapability('user.create'))
|
||||
|
||||
const canEditSelectedUser = computed(() => editModel.value === 'create'
|
||||
? availableRoles.value.length > 0
|
||||
? canCreateUser.value && availableRoles.value.length > 0
|
||||
: canManageUser(globalStatus.role, selectedUser.value?.Role))
|
||||
|
||||
const canSelectRole = computed(() => canEditSelectedUser.value
|
||||
@@ -122,6 +124,7 @@ export function usePage() {
|
||||
}
|
||||
|
||||
const createUser = function () {
|
||||
if (!canCreateUser.value) return
|
||||
selectedUser.value = null
|
||||
editUserInfo.account = ""
|
||||
editUserInfo.name = ""
|
||||
@@ -220,6 +223,7 @@ export function usePage() {
|
||||
editModel,
|
||||
editUserInfo,
|
||||
availableRoles,
|
||||
canCreateUser,
|
||||
canEditSelectedUser,
|
||||
canSelectRole,
|
||||
roleChanged,
|
||||
|
||||
@@ -60,7 +60,7 @@
|
||||
</el-table-column>
|
||||
<el-table-column align="right" width="68">
|
||||
<template #header>
|
||||
<el-button type="primary" size="small" @click="createUser" class="new-btn" plain>
|
||||
<el-button v-if="canCreateUser" type="primary" size="small" @click="createUser" class="new-btn" plain>
|
||||
<el-icon><Plus /></el-icon> 新建
|
||||
</el-button>
|
||||
</template>
|
||||
@@ -239,6 +239,7 @@ const {
|
||||
editModel,
|
||||
editUserInfo,
|
||||
availableRoles,
|
||||
canCreateUser,
|
||||
canEditSelectedUser,
|
||||
canSelectRole,
|
||||
roleChanged,
|
||||
|
||||
Reference in new issue
Block a user