前端和json优化

This commit is contained in:
2025-11-28 17:16:17 +08:00
parent 34e69c7f62
commit dfb11c85f1
135 changed files with 930 additions and 633 deletions

View File

@@ -1,5 +1,5 @@
<template>
<div class="change-home" v-if="isAdmin">
<div class="change-home">
<div class="change-home-item" @click="changeHome">
<span v-if="home">前往用户页</span>
<span v-else>前往管理页</span>
@@ -10,14 +10,8 @@
import { ref, onMounted } from 'vue';
import { useRouter } from 'vue-router';
const isAdmin = ref<boolean>(false);
const home = ref<boolean>(false);
const router = useRouter();
const routes = router.getRoutes();
function hasAdmin(){
return routes.some((route: any) => route.path.startsWith('/admin'));
}
function changeHome(){
if(home.value){
@@ -27,10 +21,7 @@ function changeHome(){
}
home.value = !home.value;
}
onMounted(() => {
isAdmin.value = hasAdmin();
home.value = router.currentRoute.value.path.startsWith('/admin');
});
</script>
<style scoped lang="scss">
</style>

View File

@@ -65,9 +65,8 @@
</div>
<div class="dropdown-divider" v-if="userMenus.length > 0"></div>
<div class="dropdown-footer">
<div class="dropdown-item info">
<div class="dropdown-item info" v-if="isAdmin">
<img class="item-icon icon-logout" src="@/assets/imgs/admin-home.svg" alt="切换页面">
<ChangeHome />
</div>
<div class="dropdown-item danger" @click="handleLogout">
@@ -82,7 +81,7 @@
</template>
<script setup lang="ts">
import { ref, computed } from 'vue';
import { ref, computed, onMounted } from 'vue';
import { useRouter } from 'vue-router';
import { useStore } from 'vuex';
import type { UserVO, SysMenu } from '@/types';
@@ -90,6 +89,10 @@ import { ChangeHome } from '@/components/base';
import userIcon from '@/assets/imgs/user.svg';
import settingsIcon from '@/assets/imgs/settings.svg';
import { FILE_DOWNLOAD_URL } from '@/config';
const router = useRouter();
const routes = router.getRoutes();
// Props
interface Props {
user?: UserVO | null;
@@ -110,9 +113,8 @@ const dropdownPosition = ref({ top: 0, left: 0 });
const closeTimer = ref<number | null>(null);
// Composition API
const router = useRouter();
const store = useStore();
const isAdmin = ref<boolean>(false);
// 计算属性
const isLoggedIn = computed(() => {
return store.getters['auth/isAuthenticated'];
@@ -131,6 +133,12 @@ const primaryRole = computed(() => {
// 这里可以从store中获取用户角色信息
return store.getters['auth/userRoles'][0].roleName || '';
});
function hasAdmin(){
return routes.some((route: any) => route.path.startsWith('/admin'));
}
onMounted(() => {
isAdmin.value = hasAdmin();
});
// 获取用户下拉菜单(个人中心和账号中心)
const userMenus = computed(() => {

View File

@@ -313,6 +313,7 @@ function handleJumpPage() {
<style lang="scss" scoped>
.login-logs {
background-color: #FFFFFF;
padding: 20px;
}

View File

@@ -385,6 +385,7 @@ function handleSizeChange(size: number) {
<style lang="scss" scoped>
.operation-logs {
background-color: #FFFFFF;
padding: 20px;
}

View File

@@ -197,20 +197,42 @@ function getRenderType(item: ConfigItem): string {
}
/**
* 解析 options JSON 字符串
* @param optionsStr JSON 字符串
* 解析 options 字符串支持JSON数组和逗号分隔字符串
* @param optionsStr JSON 字符串或逗号分隔的字符串
* @returns 选项数组
*/
function parseOptions(optionsStr?: string): Array<{ label: string; value: any }> {
if (!optionsStr) {
return [];
}
try {
// 尝试解析为JSON
const parsed = JSON.parse(optionsStr);
return Array.isArray(parsed) ? parsed : [];
} catch (error) {
console.warn('解析 options 失败:', error);
if (Array.isArray(parsed)) {
return parsed;
}
return [];
} catch (error) {
// 如果JSON解析失败尝试作为逗号分隔的字符串处理
// 格式:'aliyun,tencent' 或 'aliyun:阿里云,tencent:腾讯云'
const items = optionsStr.split(',').map(item => item.trim()).filter(item => item);
return items.map(item => {
// 检查是否包含冒号分隔符 (value:label 格式)
const parts = item.split(':');
if (parts.length === 2) {
return {
value: parts[0].trim(),
label: parts[1].trim()
};
}
// 如果没有冒号value和label相同
return {
value: item,
label: item
};
});
}
}
@@ -346,11 +368,12 @@ async function saveConfig(groupKey: string) {
<style lang="scss" scoped>
.system-config {
background-color: #FFFFFF;
padding: 20px;
:deep(.el-tabs--border-card) {
border: none;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
// box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}
:deep(.el-tabs__content) {