修复模板选择bug
This commit is contained in:
parent
db585c5a32
commit
9ddcdf71b9
@ -1,2 +1,2 @@
|
|||||||
# 生产环境接口
|
# 生产环境接口
|
||||||
VITE_API_BASE_URL='https://backend.yunzer.cn'
|
VITE_API_BASE_URL='https://api.yunzer.cn'
|
||||||
|
|||||||
11
src/main.js
11
src/main.js
@ -37,8 +37,17 @@ authStore.checkAuth()
|
|||||||
|
|
||||||
// 如果用户已登录,在应用启动时加载动态路由
|
// 如果用户已登录,在应用启动时加载动态路由
|
||||||
if (authStore.isLoggedIn) {
|
if (authStore.isLoggedIn) {
|
||||||
loadAndAddDynamicRoutes().catch(err => {
|
loadAndAddDynamicRoutes()
|
||||||
|
.catch(err => {
|
||||||
console.error('应用启动时加载动态路由失败:', err);
|
console.error('应用启动时加载动态路由失败:', err);
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
// 检查是否因为 token 无效而导致路由加载失败
|
||||||
|
const token = localStorage.getItem('token');
|
||||||
|
if (!token) {
|
||||||
|
authStore.clearToken();
|
||||||
|
window.location.href = '#/login';
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -86,7 +86,7 @@ export async function loadAndAddDynamicRoutes() {
|
|||||||
console.error('加载动态路由失败:', error);
|
console.error('加载动态路由失败:', error);
|
||||||
dynamicRoutesAdded = true;
|
dynamicRoutesAdded = true;
|
||||||
routesLoadingPromise = null;
|
routesLoadingPromise = null;
|
||||||
return Promise.resolve();
|
throw error;
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|||||||
@ -171,6 +171,13 @@ export const useMenuStore = defineStore('menu', () => {
|
|||||||
stack: err.stack
|
stack: err.stack
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 如果是 token 无效错误,不使用缓存,直接抛出
|
||||||
|
if (err.message === 'token无效' || err.response?.status === 401) {
|
||||||
|
clearCache();
|
||||||
|
menus.value = [];
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
|
||||||
// 如果出错,尝试使用缓存数据
|
// 如果出错,尝试使用缓存数据
|
||||||
const cachedMenus = loadFromCache();
|
const cachedMenus = loadFromCache();
|
||||||
if (cachedMenus && cachedMenus.length > 0) {
|
if (cachedMenus && cachedMenus.length > 0) {
|
||||||
|
|||||||
@ -40,16 +40,14 @@ service.interceptors.response.use(
|
|||||||
if (error.response) {
|
if (error.response) {
|
||||||
switch (error.response.status) {
|
switch (error.response.status) {
|
||||||
case 401:
|
case 401:
|
||||||
// 处理未授权的错误 - 清除token并跳转登录页
|
|
||||||
console.error('未授权,请重新登录');
|
console.error('未授权,请重新登录');
|
||||||
localStorage.removeItem('token');
|
localStorage.removeItem('token');
|
||||||
// 避免循环导入,直接使用路由
|
localStorage.removeItem('userInfo');
|
||||||
if (window.location.hash !== '#/login') {
|
if (window.location.hash !== '#/login') {
|
||||||
window.location.href = '#/login';
|
window.location.href = '#/login';
|
||||||
}
|
}
|
||||||
break;
|
return Promise.reject(new Error('token无效'));
|
||||||
case 404:
|
case 404:
|
||||||
// 处理资源不存在的错误
|
|
||||||
console.error('请求的资源不存在');
|
console.error('请求的资源不存在');
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|||||||
@ -74,14 +74,17 @@ import { ref, onMounted } from 'vue'
|
|||||||
import { ElMessage } from 'element-plus'
|
import { ElMessage } from 'element-plus'
|
||||||
import { Refresh, Loading } from '@element-plus/icons-vue'
|
import { Refresh, Loading } from '@element-plus/icons-vue'
|
||||||
import { getThemeList, switchTheme } from '@/api/theme'
|
import { getThemeList, switchTheme } from '@/api/theme'
|
||||||
|
import { useAuthStore } from '@/stores/auth'
|
||||||
|
|
||||||
const API_BASE_URL = import.meta.env.VITE_API_BASE_URL
|
const API_BASE_URL = import.meta.env.VITE_API_BASE_URL
|
||||||
|
const authStore = useAuthStore()
|
||||||
|
|
||||||
// 状态
|
// 状态
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
const switching = ref('')
|
const switching = ref('')
|
||||||
const templateList = ref<any[]>([])
|
const templateList = ref<any[]>([])
|
||||||
const currentTheme = ref('default')
|
const currentTheme = ref('default')
|
||||||
|
const currentTid = ref<number>(0)
|
||||||
|
|
||||||
// 获取完整预览图URL
|
// 获取完整预览图URL
|
||||||
const getPreviewUrl = (path: string) => {
|
const getPreviewUrl = (path: string) => {
|
||||||
@ -94,7 +97,8 @@ const getPreviewUrl = (path: string) => {
|
|||||||
const fetchTemplates = async () => {
|
const fetchTemplates = async () => {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
try {
|
try {
|
||||||
const res = await getThemeList()
|
currentTid.value = (authStore.user as any)?.tid || 0
|
||||||
|
const res = await getThemeList({ tid: currentTid.value })
|
||||||
if (res.code === 200) {
|
if (res.code === 200) {
|
||||||
templateList.value = res.data.list || []
|
templateList.value = res.data.list || []
|
||||||
currentTheme.value = res.data.currentTheme || 'default'
|
currentTheme.value = res.data.currentTheme || 'default'
|
||||||
@ -110,9 +114,13 @@ const fetchTemplates = async () => {
|
|||||||
|
|
||||||
// 切换模板
|
// 切换模板
|
||||||
const handleUse = async (item: any) => {
|
const handleUse = async (item: any) => {
|
||||||
|
if (!currentTid.value) {
|
||||||
|
ElMessage.error('请先选择租户')
|
||||||
|
return
|
||||||
|
}
|
||||||
switching.value = item.key
|
switching.value = item.key
|
||||||
try {
|
try {
|
||||||
const res = await switchTheme({ theme_key: item.key })
|
const res = await switchTheme({ tid: currentTid.value, theme_key: item.key })
|
||||||
if (res.code === 200) {
|
if (res.code === 200) {
|
||||||
currentTheme.value = item.key
|
currentTheme.value = item.key
|
||||||
ElMessage.success('切换成功')
|
ElMessage.success('切换成功')
|
||||||
|
|||||||
@ -39,11 +39,30 @@
|
|||||||
<el-icon v-else class="logo-uploader-icon"><Plus /></el-icon>
|
<el-icon v-else class="logo-uploader-icon"><Plus /></el-icon>
|
||||||
</el-upload>
|
</el-upload>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
<el-form-item label="站点图标" prop="ico">
|
||||||
|
<el-upload
|
||||||
|
class="logo-uploader"
|
||||||
|
:show-file-list="false"
|
||||||
|
:auto-upload="false"
|
||||||
|
:on-change="handleIconChange"
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
v-if="ico"
|
||||||
|
:src="API_BASE_URL + ico.replace(/^\//, '/')"
|
||||||
|
class="logo-image"
|
||||||
|
/>
|
||||||
|
<el-icon v-else class="logo-uploader-icon"><Plus /></el-icon>
|
||||||
|
</el-upload>
|
||||||
|
<div class="form-tip">请上传ico格式文件</div>
|
||||||
|
</el-form-item>
|
||||||
<el-form-item label="企业名称" prop="companyname">
|
<el-form-item label="企业名称" prop="companyname">
|
||||||
<el-input v-model="companyname" placeholder="请输入企业名称" />
|
<el-input v-model="companyname" placeholder="请输入企业名称" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="站点SEO描述" prop="description">
|
<el-form-item label="企业介绍" prop="companyintroduction">
|
||||||
<el-input v-model="description" placeholder="请输入站点SEO描述" />
|
<el-input v-model="companyintroduction" type="textarea" rows="5" placeholder="请输入企业介绍" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="站点简介" prop="description">
|
||||||
|
<el-input v-model="description" placeholder="请输入站点简介" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="版权信息" prop="copyright">
|
<el-form-item label="版权信息" prop="copyright">
|
||||||
<el-input v-model="copyright" placeholder="如:© 2026 公司名称" />
|
<el-input v-model="copyright" placeholder="如:© 2026 公司名称" />
|
||||||
@ -76,17 +95,21 @@ const normalFormRef = ref<FormInstance>();
|
|||||||
|
|
||||||
const sitename = ref("");
|
const sitename = ref("");
|
||||||
const companyname = ref("");
|
const companyname = ref("");
|
||||||
|
const companyintroduction = ref("");
|
||||||
const logo = ref("");
|
const logo = ref("");
|
||||||
const logow = ref("");
|
const logow = ref("");
|
||||||
const description = ref("");
|
const description = ref("");
|
||||||
const copyright = ref("");
|
const copyright = ref("");
|
||||||
const icp = ref("");
|
const icp = ref("");
|
||||||
|
const ico = ref("");
|
||||||
|
|
||||||
const formData = {
|
const formData = {
|
||||||
sitename,
|
sitename,
|
||||||
companyname,
|
companyname,
|
||||||
|
companyintroduction,
|
||||||
logo,
|
logo,
|
||||||
logow,
|
logow,
|
||||||
|
ico,
|
||||||
description,
|
description,
|
||||||
copyright,
|
copyright,
|
||||||
icp,
|
icp,
|
||||||
@ -102,8 +125,10 @@ const initNormalInfos = async () => {
|
|||||||
if (res.code === 200 && res.data) {
|
if (res.code === 200 && res.data) {
|
||||||
const data = res.data;
|
const data = res.data;
|
||||||
sitename.value = data.sitename || "";
|
sitename.value = data.sitename || "";
|
||||||
|
companyintroduction.value = data.companyintroduction || "";
|
||||||
logo.value = data.logo || "";
|
logo.value = data.logo || "";
|
||||||
logow.value = data.logow || "";
|
logow.value = data.logow || "";
|
||||||
|
ico.value = data.ico || "";
|
||||||
description.value = data.description || "";
|
description.value = data.description || "";
|
||||||
copyright.value = data.copyright || "";
|
copyright.value = data.copyright || "";
|
||||||
icp.value = data.icp || "";
|
icp.value = data.icp || "";
|
||||||
@ -154,8 +179,10 @@ const handleSaveNormalInfos = async () => {
|
|||||||
const data = {
|
const data = {
|
||||||
tid: authStore.user.tid,
|
tid: authStore.user.tid,
|
||||||
sitename: sitename.value,
|
sitename: sitename.value,
|
||||||
|
companyintroduction: companyintroduction.value,
|
||||||
logo: logo.value,
|
logo: logo.value,
|
||||||
logow: logow.value,
|
logow: logow.value,
|
||||||
|
ico: ico.value,
|
||||||
description: description.value,
|
description: description.value,
|
||||||
companyname: companyname.value,
|
companyname: companyname.value,
|
||||||
copyright: copyright.value,
|
copyright: copyright.value,
|
||||||
@ -171,11 +198,27 @@ const handleSaveNormalInfos = async () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleIconChange = (file: UploadFile) => {
|
||||||
|
const uploadFormData = new FormData();
|
||||||
|
uploadFormData.append("file", file.raw);
|
||||||
|
uploadFormData.append("cate", "site");
|
||||||
|
|
||||||
|
uploadFile(uploadFormData).then((uploadRes) => {
|
||||||
|
if ((uploadRes.code === 200 || uploadRes.code === 201) && uploadRes.data?.url) {
|
||||||
|
ico.value = uploadRes.data.url.replace(/\\/g, "/");
|
||||||
|
} else {
|
||||||
|
ElMessage.error(uploadRes.msg || "上传失败");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const resetnormalForm = () => {
|
const resetnormalForm = () => {
|
||||||
sitename.value = "";
|
sitename.value = "";
|
||||||
companyname.value = "";
|
companyname.value = "";
|
||||||
|
companyintroduction.value = "";
|
||||||
logo.value = "";
|
logo.value = "";
|
||||||
logow.value = "";
|
logow.value = "";
|
||||||
|
ico.value = "";
|
||||||
description.value = "";
|
description.value = "";
|
||||||
copyright.value = "";
|
copyright.value = "";
|
||||||
icp.value = "";
|
icp.value = "";
|
||||||
@ -184,8 +227,10 @@ const resetnormalForm = () => {
|
|||||||
defineExpose({
|
defineExpose({
|
||||||
sitename,
|
sitename,
|
||||||
companyname,
|
companyname,
|
||||||
|
companyintroduction,
|
||||||
logo,
|
logo,
|
||||||
logow,
|
logow,
|
||||||
|
ico,
|
||||||
description,
|
description,
|
||||||
copyright,
|
copyright,
|
||||||
icp,
|
icp,
|
||||||
@ -202,6 +247,13 @@ onMounted(() => {
|
|||||||
background-color: #efefef;
|
background-color: #efefef;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.form-tip{
|
||||||
|
margin-left: 20px;
|
||||||
|
color: #999;
|
||||||
|
font-size: 12px;
|
||||||
|
margin-top: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
.logo-uploader {
|
.logo-uploader {
|
||||||
:deep(.el-upload) {
|
:deep(.el-upload) {
|
||||||
border: 1px dashed #d9d9d9;
|
border: 1px dashed #d9d9d9;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user