feat: 支持配置系统图标
This commit is contained in:
@@ -13,6 +13,10 @@ export const authApi = {
|
||||
post('/auth/change-password', data),
|
||||
};
|
||||
|
||||
export const appApi = {
|
||||
info: () => get<{ appName: string; appIconUrl: string }>('/app-info'),
|
||||
};
|
||||
|
||||
export const dashboardApi = {
|
||||
overview: (params?: object) => get('/dashboard/overview', params),
|
||||
};
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
@expand="collapsed = false"
|
||||
>
|
||||
<div class="brand">
|
||||
<span class="brand-logo">艺</span>
|
||||
<img class="brand-logo" :src="appIconUrl" alt="" />
|
||||
<span v-show="!collapsed" class="brand-name text-ellipsis">{{ appName }}</span>
|
||||
</div>
|
||||
<n-menu
|
||||
@@ -76,6 +76,7 @@ import {
|
||||
import { useAuthStore } from '@/stores/auth';
|
||||
import { settingsApi } from '@/api';
|
||||
import { dialog } from '@/utils/feedback';
|
||||
import { resolveAppIcon, setFavicon } from '@/utils/appIcon';
|
||||
import LangSwitch from '@/components/LangSwitch.vue';
|
||||
import ThemeSwitch from '@/components/ThemeSwitch.vue';
|
||||
|
||||
@@ -86,6 +87,7 @@ const auth = useAuthStore();
|
||||
|
||||
const collapsed = ref(window.innerWidth < 900);
|
||||
const appName = ref(t('pages.login.title'));
|
||||
const appIconUrl = ref(resolveAppIcon());
|
||||
const filingInfo = ref('');
|
||||
|
||||
function renderIcon(icon: unknown) {
|
||||
@@ -139,20 +141,29 @@ function onUser(key: string) {
|
||||
}
|
||||
|
||||
let resizeHandler: () => void;
|
||||
async function loadSettings() {
|
||||
try {
|
||||
const s = await settingsApi.getAll();
|
||||
if (s.appName) appName.value = s.appName;
|
||||
appIconUrl.value = resolveAppIcon(s.appIconUrl);
|
||||
setFavicon(appIconUrl.value);
|
||||
filingInfo.value = s.filingInfo || '';
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
}
|
||||
onMounted(async () => {
|
||||
resizeHandler = () => {
|
||||
collapsed.value = window.innerWidth < 900;
|
||||
};
|
||||
window.addEventListener('resize', resizeHandler);
|
||||
try {
|
||||
const s = await settingsApi.getAll();
|
||||
if (s.appName) appName.value = s.appName;
|
||||
filingInfo.value = s.filingInfo || '';
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
window.addEventListener('artveris-settings-updated', loadSettings);
|
||||
await loadSettings();
|
||||
});
|
||||
onUnmounted(() => {
|
||||
window.removeEventListener('resize', resizeHandler);
|
||||
window.removeEventListener('artveris-settings-updated', loadSettings);
|
||||
});
|
||||
onUnmounted(() => window.removeEventListener('resize', resizeHandler));
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
@@ -164,15 +175,11 @@ onUnmounted(() => window.removeEventListener('resize', resizeHandler));
|
||||
padding: 0 16px;
|
||||
}
|
||||
.brand-logo {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
border-radius: 8px;
|
||||
background: var(--brand);
|
||||
color: #fff;
|
||||
font-weight: 700;
|
||||
object-fit: cover;
|
||||
background: #f6f8fb;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.brand-name {
|
||||
|
||||
@@ -347,6 +347,7 @@
|
||||
},
|
||||
"settings": {
|
||||
"appName": "Platform Name",
|
||||
"appIcon": "System Icon",
|
||||
"logRetentionDays": "Query Log Retention (days)",
|
||||
"operationLogRetentionDays": "Operation Log Retention (days)",
|
||||
"watermarkText": "Certificate Watermark",
|
||||
|
||||
@@ -347,6 +347,7 @@
|
||||
},
|
||||
"settings": {
|
||||
"appName": "平台名称",
|
||||
"appIcon": "系统图标",
|
||||
"logRetentionDays": "查询日志保留天数",
|
||||
"operationLogRetentionDays": "操作日志保留天数",
|
||||
"watermarkText": "证书水印文案",
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
export const DEFAULT_APP_ICON_URL = '/app-icon.svg';
|
||||
|
||||
export function resolveAppIcon(url?: string | null): string {
|
||||
const value = String(url || '').trim();
|
||||
return value || DEFAULT_APP_ICON_URL;
|
||||
}
|
||||
|
||||
export function setFavicon(url?: string | null): void {
|
||||
const href = resolveAppIcon(url);
|
||||
const selectors = ['link[rel="icon"]', 'link[rel="shortcut icon"]'];
|
||||
let link = document.head.querySelector<HTMLLinkElement>(selectors.join(','));
|
||||
if (!link) {
|
||||
link = document.createElement('link');
|
||||
link.rel = 'icon';
|
||||
document.head.appendChild(link);
|
||||
}
|
||||
link.type = href.endsWith('.svg') ? 'image/svg+xml' : '';
|
||||
link.href = href;
|
||||
}
|
||||
@@ -5,8 +5,8 @@
|
||||
</div>
|
||||
<div class="login-left">
|
||||
<div class="login-left-inner">
|
||||
<div class="logo">艺</div>
|
||||
<h1>{{ t('pages.login.title') }}</h1>
|
||||
<img class="logo" :src="appIconUrl" alt="" />
|
||||
<h1>{{ appName }}</h1>
|
||||
<p>{{ t('pages.login.subtitle') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
@@ -44,13 +44,15 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue';
|
||||
import { onMounted, ref } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import type { FormInst, FormRules } from 'naive-ui';
|
||||
import { PersonOutline, LockClosedOutline } from '@vicons/ionicons5';
|
||||
import { appApi } from '@/api';
|
||||
import { useAuthStore } from '@/stores/auth';
|
||||
import { message } from '@/utils/feedback';
|
||||
import { resolveAppIcon, setFavicon } from '@/utils/appIcon';
|
||||
import LangSwitch from '@/components/LangSwitch.vue';
|
||||
|
||||
const { t } = useI18n();
|
||||
@@ -60,6 +62,8 @@ const auth = useAuthStore();
|
||||
const formRef = ref<FormInst | null>(null);
|
||||
const form = ref({ username: '', password: '' });
|
||||
const loading = ref(false);
|
||||
const appName = ref(t('pages.login.title'));
|
||||
const appIconUrl = ref(resolveAppIcon());
|
||||
|
||||
const rules: FormRules = {
|
||||
username: { required: true, message: () => t('pages.login.placeholderUser'), trigger: 'blur' },
|
||||
@@ -83,6 +87,17 @@ async function onSubmit() {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
const info = await appApi.info();
|
||||
appName.value = info.appName || t('pages.login.title');
|
||||
appIconUrl.value = resolveAppIcon(info.appIconUrl);
|
||||
setFavicon(appIconUrl.value);
|
||||
} catch {
|
||||
setFavicon(appIconUrl.value);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
@@ -115,11 +130,7 @@ async function onSubmit() {
|
||||
margin: 0 auto 24px;
|
||||
border-radius: 18px;
|
||||
background: rgba(255, 255, 255, 0.16);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 38px;
|
||||
font-weight: 700;
|
||||
object-fit: cover;
|
||||
}
|
||||
.login-left-inner h1 {
|
||||
font-size: 28px;
|
||||
|
||||
@@ -11,6 +11,12 @@
|
||||
<n-form-item :label="t('pages.settings.appName')">
|
||||
<n-input v-model:value="form.appName" class="control-wide" />
|
||||
</n-form-item>
|
||||
<n-form-item :label="t('pages.settings.appIcon')">
|
||||
<div class="icon-setting">
|
||||
<img class="icon-preview" :src="currentIconUrl" alt="" />
|
||||
<media-upload v-model="form.appIconFiles" type="image" :max="1" />
|
||||
</div>
|
||||
</n-form-item>
|
||||
<n-form-item :label="t('pages.settings.watermarkText')">
|
||||
<n-input v-model:value="form.watermarkText" class="control-wide" />
|
||||
</n-form-item>
|
||||
@@ -81,11 +87,13 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { onMounted, reactive, ref } from 'vue';
|
||||
import { computed, onMounted, reactive, ref } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { settingsApi } from '@/api';
|
||||
import { message } from '@/utils/feedback';
|
||||
import BackupRestorePanel from '@/components/BackupRestorePanel.vue';
|
||||
import MediaUpload from '@/components/MediaUpload.vue';
|
||||
import { DEFAULT_APP_ICON_URL, resolveAppIcon, setFavicon } from '@/utils/appIcon';
|
||||
|
||||
const { t } = useI18n();
|
||||
const saving = ref(false);
|
||||
@@ -95,6 +103,7 @@ const backupScheduleOptions = [
|
||||
];
|
||||
const form = reactive({
|
||||
appName: '',
|
||||
appIconFiles: [] as Array<{ key: string; url?: string; name?: string; type?: string }>,
|
||||
logRetentionDays: 365,
|
||||
operationLogRetentionDays: 180,
|
||||
watermarkText: '',
|
||||
@@ -109,6 +118,8 @@ const form = reactive({
|
||||
async function load() {
|
||||
const s = await settingsApi.getAll();
|
||||
form.appName = s.appName || '';
|
||||
const appIconUrl = s.appIconUrl || '';
|
||||
form.appIconFiles = appIconUrl && appIconUrl !== DEFAULT_APP_ICON_URL ? [{ key: appIconUrl, url: appIconUrl, name: t('pages.settings.appIcon'), type: 'image' }] : [];
|
||||
form.logRetentionDays = Number(s.logRetentionDays || 365);
|
||||
form.operationLogRetentionDays = Number(s.operationLogRetentionDays || 180);
|
||||
form.watermarkText = s.watermarkText || '';
|
||||
@@ -123,8 +134,10 @@ async function load() {
|
||||
async function save() {
|
||||
saving.value = true;
|
||||
try {
|
||||
const appIconUrl = form.appIconFiles[0]?.url || form.appIconFiles[0]?.key || '';
|
||||
await settingsApi.update({
|
||||
appName: form.appName,
|
||||
appIconUrl,
|
||||
logRetentionDays: String(form.logRetentionDays),
|
||||
operationLogRetentionDays: String(form.operationLogRetentionDays),
|
||||
watermarkText: form.watermarkText,
|
||||
@@ -135,6 +148,8 @@ async function save() {
|
||||
backupRetentionDays: String(form.backupRetentionDays),
|
||||
backupRetentionCount: String(form.backupRetentionCount),
|
||||
});
|
||||
setFavicon(appIconUrl);
|
||||
window.dispatchEvent(new CustomEvent('artveris-settings-updated'));
|
||||
message.success(t('pages.settings.saved'));
|
||||
} finally {
|
||||
saving.value = false;
|
||||
@@ -142,6 +157,8 @@ async function save() {
|
||||
}
|
||||
|
||||
onMounted(load);
|
||||
|
||||
const currentIconUrl = computed(() => resolveAppIcon(form.appIconFiles[0]?.url || form.appIconFiles[0]?.key));
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
@@ -229,6 +246,20 @@ onMounted(load);
|
||||
font-size: 12px;
|
||||
color: #999;
|
||||
}
|
||||
.icon-setting {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 14px;
|
||||
}
|
||||
.icon-preview {
|
||||
width: 52px;
|
||||
height: 52px;
|
||||
border-radius: 12px;
|
||||
border: 1px solid var(--n-border-color);
|
||||
object-fit: cover;
|
||||
background: #f6f8fb;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.switch-field {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
Reference in New Issue
Block a user