做几方面优化

This commit is contained in:
2026-09-25 00:27:15 +08:00
parent eafa5e1cf4
commit 92403171d4
14 changed files with 2142 additions and 258 deletions
+136 -12
View File
@@ -1,5 +1,8 @@
<template>
<el-aside :width="width" class="common-aside">
<el-aside
:width="width"
:class="['common-aside', { 'is-collapsed': isCollapse }]"
>
<!-- 加载状态 -->
<div v-if="loading" class="loading-spinner">
<i class="el-icon-loading" style="font-size: 24px; color: #fff"></i>
@@ -12,9 +15,12 @@
<el-button size="small" @click="fetchMenus">重新加载</el-button>
</div>
<!-- 菜单标题:放在 el-menu 之外,避免随菜单一起滚动消失 -->
<h3 v-if="showMenu">{{ isCollapse ? "管理" : asideTitle }}</h3>
<!-- 菜单主体 -->
<el-menu
v-else
v-if="showMenu"
:collapse="isCollapse"
:collapse-transition="false"
:background-color="asideBgColor"
@@ -22,13 +28,11 @@
:active-text-color="activeColor"
:active-background-color="activeBgColor"
class="el-menu-vertical-demo"
popper-class="common-aside-popper"
:unique-opened="true"
@select="handleMenuSelect"
:default-active="route.path"
>
<!-- 菜单标题 -->
<h3>{{ isCollapse ? "管理" : asideTitle }}</h3>
<!-- 无模块时显示提示 -->
<el-menu-item v-if="!currentModule" index="/home">
<i class="fa-solid fa-house"></i>
@@ -55,6 +59,7 @@
v-else
:index="item.path || item.id.toString()"
:unique-opened="true"
teleported
:class="{ 'is-locked': item.locked }"
>
<template #title>
@@ -81,6 +86,7 @@
v-else
:index="child.path || child.id.toString()"
:unique-opened="true"
teleported
:class="{ 'is-locked': child.locked }"
>
<template #title>
@@ -116,6 +122,7 @@
v-else
:index="grandchild.path || grandchild.id.toString()"
:unique-opened="true"
teleported
:class="{ 'is-locked': grandchild.locked }"
>
<template #title>
@@ -177,7 +184,9 @@ const errorMsg = computed(() => menuStore.error || "加载菜单失败");
const store = useAllDataStore();
const isCollapse = computed(() => store.state.isCollapse);
const width = computed(() => (store.state.isCollapse ? "64px" : "200px"));
const width = computed(() => (store.state.isCollapse ? "64px" : "220px"));
// 菜单与标题的显示条件(与加载/错误分支互斥,避免 v-else 绑定错元素)
const showMenu = computed(() => !loading.value && !(hasError.value && list.value.length === 0));
const asideBgColor = ref("#304156");
const asideTextColor = ref("#bfcbd9");
@@ -508,7 +517,8 @@ h3 {
// 菜单样式
:deep(.el-menu) {
border-right: none;
height: calc(100% - 80px);
// 标题已移到 el-menu 之外,这里只减掉标题区高度
height: calc(100% - 60px);
overflow-y: auto;
overflow-x: hidden;
padding: 16px 8px;
@@ -577,14 +587,14 @@ h3 {
}
}
// 悬浮样式
// 悬浮样式:一律用蓝色系,避免 EP 默认的深灰/黑色 hover
.el-menu-item:hover:not(.is-active),
.el-sub-menu__title:hover {
html:not(.dark) & {
background-color: rgba(255, 255, 255, 0.1) !important;
background-color: rgba(30, 86, 210, 0.5) !important;
}
html.dark & {
background-color: rgba(60, 60, 60, 0.8) !important;
background-color: rgba(57, 115, 255, 0.45) !important;
}
color: #ffffff !important;
}
@@ -649,12 +659,54 @@ h3 {
.el-menu-item:hover:not(.is-active),
.el-sub-menu__title:hover {
background: rgba(255, 255, 255, 0.08) !important;
color: var(--el-color-primary-light-3) !important;
background: rgba(57, 115, 255, 0.45) !important;
color: #fff !important;
}
}
}
// ---------------------------------------------------------------- 折叠态修复
// 折叠(isCollapse)时 Element Plus 有一套自己的布局,下面逐条修正显示问题:
// 1) EP 会把 .el-menu 强制成 64px,而 el-aside 的宽度有 0.3s 动画,
// 两者不同步会导致收起瞬间菜单内容先跳变、右侧露出空白 → 改回 100% 跟随动画
// 2) 菜单项保留默认左右内边距 + 图标右外边距,在 64px 宽下图标会偏左 → 归零并居中
// 3) 激活项的 -3px 左移补偿在折叠态会把图标顶偏 → 折叠时取消
// 4) 64px 宽的栏里再放 4px 滚动条很突兀 → 折叠时隐藏(仍可滚动)
:deep(.el-menu.el-menu--collapse) {
width: 100% !important;
padding-left: 0;
padding-right: 0;
scrollbar-width: none;
&::-webkit-scrollbar {
display: none;
}
.el-menu-item,
.el-sub-menu > .el-sub-menu__title {
padding-left: 0 !important;
padding-right: 0 !important;
justify-content: center;
}
.menu-icon {
margin-right: 0;
}
.el-menu-item.is-active {
margin-left: 0;
}
}
// 折叠后标题区收紧,避免 64px 下文字贴边
.common-aside.is-collapsed h3 {
font-size: 15px;
padding: 0 4px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
// 响应式设计
// 注意:手机端(≤768px)侧栏的抽屉式布局由 Main.vue 统一控制(fixed 定位 + transform 动画),
// 此处不要再对 .common-aside 设置 width,避免覆盖父级布局逻辑。
@@ -664,3 +716,75 @@ h3 {
}
}
</style>
<style lang="less">
// 折叠后 hover 弹出的子菜单浮层被 teleport 到 body,scoped 样式命中不了,
// 只能用 popper-class + 全局样式配色,否则会是 Element Plus 默认的白底浮层
.common-aside-popper.el-popper {
background: #3973ff !important;
border: 1px solid rgba(255, 255, 255, 0.14) !important;
box-shadow: 0 8px 24px rgba(6, 45, 163, 0.28);
.el-popper__arrow::before {
background: #3973ff !important;
border-color: rgba(255, 255, 255, 0.14) !important;
}
.el-menu {
background: transparent !important;
padding: 4px;
border-right: none;
}
// 菜单项与"还有下级"的父级标题统一配色,避免 EP 默认的深灰/黑色 hover
.el-menu-item {
color: rgba(255, 255, 255, 0.88);
border-radius: 8px;
font-size: 13px;
&:hover {
background: rgba(30, 86, 210, 0.55) !important;
color: #fff !important;
}
&.is-active {
background: rgba(30, 86, 210, 0.7) !important;
color: #fff !important;
}
}
.el-sub-menu__title {
color: rgba(255, 255, 255, 0.88);
border-radius: 8px;
background: transparent !important;
&:hover {
background: rgba(30, 86, 210, 0.55) !important;
color: #fff !important;
}
}
// 折叠态下 EP 用 ArrowRight 表示"还有下级",但展开时会内联 rotateZ(180deg) 把箭头翻成向左;
// 浮层里的子菜单应当始终指向右(表示继续向右展开),故强制不旋转(内联样式需 !important 覆盖)
.el-sub-menu__icon-arrow {
transform: rotateZ(0deg) !important;
}
// 浮层宽度收敛,降低深层级因空间不足被 popper 翻转到左侧的概率
.el-menu {
min-width: 180px;
}
}
html.dark {
.common-aside-popper.el-popper {
background: #2d2d2d !important;
border-color: rgba(255, 255, 255, 0.1) !important;
.el-popper__arrow::before {
background: #2d2d2d !important;
border-color: rgba(255, 255, 255, 0.1) !important;
}
}
}
</style>
+28 -1
View File
@@ -171,6 +171,22 @@ export async function logoutSSO() {
window.location.href = `${AUTH_BASE}/logout?${params.toString()}`;
}
/**
* 取「当前登录的那一家企业」的名称。
*
* userinfo 的 tenants 是该账号可进入的全部企业,只能用于做企业切换列表;
* 顶部展示必须是当前会话选中的企业(tid),不能把全部企业名拼接。
* 取值顺序:后端 tenant_name → 按 tid 在 tenants 中匹配 → 兜底第一家。
*/
export function resolveTenantName(data) {
if (!data) return '';
if (data.tenant_name) return data.tenant_name;
const list = data.tenants || [];
const hit = list.find((t) => String(t.tid) === String(data.tid));
if (hit) return hit.tenant_name || '';
return list.length ? (list[0].tenant_name || '') : '';
}
/**
* 确保本地存在完整的用户信息(含 id / group_id)。
*
@@ -199,7 +215,7 @@ export async function ensureUserInfo() {
name: data.name || data.nickname || '',
group_id: data.group_id || '',
tid: data.tid || '',
tenant_name: (data.tenants || []).map((t) => t.tenant_name).join('、'),
tenant_name: resolveTenantName(data),
avatar: data.avatar || '',
type: 'backend'
};
@@ -235,5 +251,16 @@ export async function switchTenant(tid) {
const data = await res.json().catch(() => ({}));
if (!res.ok || data.code !== 200) throw new Error(data.msg || "切换企业失败");
if (data.data?.tokens) setTokens(data.data.tokens);
// 切换后同步本地缓存的企业信息,避免顶部仍显示切换前的企业名
try {
const info = await fetchUserInfo();
const raw = localStorage.getItem('userInfo');
const merged = raw ? JSON.parse(raw) : {};
merged.tid = info.tid || tid;
merged.tenant_name = resolveTenantName(info);
localStorage.setItem('userInfo', JSON.stringify(merged));
} catch (e) {
// 同步失败不阻断切换结果
}
return data.data;
}
@@ -82,14 +82,16 @@
</div>
</div>
<!-- 新建 / 编辑 -->
<el-dialog
<!-- 新建 / 编辑:右侧滑出抽屉,纵向空间比居中弹窗更充足 -->
<el-drawer
v-model="dialogVisible"
:title="editing ? '编辑模板' : '新建模板'"
width="820px"
size="min(1200px, 92vw)"
:close-on-click-modal="false"
class="template-drawer"
@closed="editorReady = false"
>
<el-form :model="form" label-width="100px">
<el-form :model="form" label-width="100px" class="template-form">
<el-row :gutter="16">
<el-col :span="12">
<el-form-item label="模板名称" required>
@@ -130,15 +132,19 @@
<el-form-item label="模板描述">
<el-input v-model="form.description" type="textarea" :rows="2" placeholder="模板适用场景说明" />
</el-form-item>
<el-form-item label="模板正文">
<el-input v-model="form.content" type="textarea" :rows="12" placeholder="标书模板内容" />
<el-form-item label="模板正文" class="editor-form-item">
<div class="template-editor-box">
<UmoEditor v-if="editorReady" v-model="form.content" />
</div>
</el-form-item>
</el-form>
<template #footer>
<el-button @click="dialogVisible = false">取消</el-button>
<el-button type="primary" :loading="submitting" @click="handleSubmit">保存</el-button>
<div class="drawer-footer">
<el-button @click="dialogVisible = false">取消</el-button>
<el-button type="primary" :loading="submitting" @click="handleSubmit">保存</el-button>
</div>
</template>
</el-dialog>
</el-drawer>
<!-- 预览 -->
<el-dialog v-model="previewVisible" :title="previewRow?.template_name || '模板预览'" width="800px">
@@ -150,7 +156,13 @@
<el-descriptions-item label="引用次数">{{ previewRow?.use_count || 0 }}</el-descriptions-item>
</el-descriptions>
<el-divider />
<div class="preview-content">{{ previewRow?.content || "(空)" }}</div>
<!-- 富文本内容按 HTML 渲染;旧数据为纯文本时保持原样换行展示 -->
<div
v-if="isRichText(previewRow?.content)"
class="preview-content is-rich"
v-html="previewRow.content"
></div>
<div v-else class="preview-content">{{ previewRow?.content || "(空)" }}</div>
<template v-if="previewRow?.file_url">
<el-divider />
<el-link :href="previewRow.file_url" target="_blank" type="primary">打开模板文件</el-link>
@@ -160,7 +172,7 @@
</template>
<script setup>
import { ref, reactive, onMounted } from "vue";
import { ref, reactive, onMounted, nextTick } from "vue";
import { ElMessage, ElMessageBox } from "element-plus";
import { Plus, Search, Refresh, RefreshLeft } from "@element-plus/icons-vue";
import {
@@ -170,6 +182,7 @@ import {
deleteTemplate,
} from "@/api/crmBidding";
import { bidTemplateTypeOptions, templateTypeText } from "@/views/apps/crm/dict";
import UmoEditor from "@/views/components/UmoEditor.vue";
const loading = ref(false);
const tableData = ref([]);
@@ -181,6 +194,8 @@ const previewVisible = ref(false);
const previewRow = ref(null);
const editing = ref(null);
const submitting = ref(false);
// UmoEditor 只在创建时读取一次初始值,故每次打开弹窗重建实例以保证载入当前内容
const editorReady = ref(false);
const emptyForm = () => ({
template_name: "",
@@ -225,10 +240,19 @@ function resetFilters() {
handleSearch();
}
// 每次打开都重建编辑器实例,避免残留上一条模板的内容
function openEditorDialog() {
editorReady.value = false;
dialogVisible.value = true;
nextTick(() => {
editorReady.value = true;
});
}
function openCreate() {
editing.value = null;
Object.assign(form, emptyForm());
dialogVisible.value = true;
openEditorDialog();
}
function openEdit(row) {
@@ -242,7 +266,7 @@ function openEdit(row) {
file_url: row.file_url || "",
status: Number(row.status) || 1,
});
dialogVisible.value = true;
openEditorDialog();
}
async function handleSubmit() {
@@ -288,11 +312,70 @@ function openPreview(row) {
previewRow.value = row;
previewVisible.value = true;
}
// 判断内容是否为富文本 HTML(旧数据由纯文本 textarea 保存,需保持原样展示)
function isRichText(content) {
return /<(p|div|br|h[1-6]|ul|ol|li|table|img|strong|b|span)\b[\s\S]*>/i.test(content || "");
}
</script>
<style lang="less" scoped src="../../styles/crm-page.less"></style>
<style scoped>
/* 抽屉主体改为纵向 flex:表单撑满,正文编辑区吃掉剩余高度(真正的自适应) */
.template-drawer :deep(.el-drawer__body) {
display: flex;
flex-direction: column;
overflow: hidden;
padding: 16px 20px;
}
.template-form {
flex: 1;
min-height: 0;
display: flex;
flex-direction: column;
}
.drawer-footer {
display: flex;
justify-content: flex-end;
gap: 12px;
}
/* 正文字段吃掉表单剩余高度,内容区同样撑满 */
.editor-form-item {
flex: 1;
min-height: 0;
:deep(.el-form-item__content) {
flex: 1;
min-height: 0;
display: flex;
}
}
/* umo-editor 以 100% 填充父容器;宽度锁死为容器宽度,杜绝横向拉伸 */
.template-editor-box {
width: 100%;
max-width: 100%;
min-width: 0;
flex: 1;
min-height: 320px;
border: 1px solid #dcdfe6;
border-radius: 4px;
overflow: hidden;
background: #fff;
}
.template-editor-box :deep(.umo-editor),
.template-editor-box :deep(umo-editor) {
width: 100% !important;
max-width: 100% !important;
min-width: 0 !important;
height: 100%;
}
.preview-content {
white-space: pre-wrap;
word-break: break-word;
@@ -300,4 +383,25 @@ function openPreview(row) {
font-size: 14px;
min-height: 120px;
}
/* 富文本预览:按 HTML 结构展示,图片自适应 */
.preview-content.is-rich {
white-space: normal;
:deep(img) {
max-width: 100%;
height: auto;
}
:deep(table) {
border-collapse: collapse;
width: 100%;
th,
td {
border: 1px solid #dcdfe6;
padding: 8px 12px;
}
}
}
</style>
+3 -1
View File
@@ -20,6 +20,7 @@ import {
handleAuthorizeCallback,
redirectToAuthorize,
fetchUserInfo,
resolveTenantName,
} from "@/utils/authClient";
const error = ref("");
@@ -38,7 +39,8 @@ async function saveUserInfo() {
name: info.name || info.nickname || "",
group_id: info.group_id || "",
tid: info.tid || "",
tenant_name: (info.tenants || []).map((t) => t.tenant_name).join("、"),
// 顶部展示的是当前登录的企业,不是该账号可进入的全部企业
tenant_name: resolveTenantName(info),
avatar: info.avatar || "",
type: "backend",
};
+20 -2
View File
@@ -1,5 +1,5 @@
<template>
<div class="umo-editor-wrapper">
<div class="umo-editor-wrapper" :style="wrapperStyle">
<umo-editor
ref="editorRef"
v-bind="options"
@@ -11,7 +11,7 @@
</template>
<script setup>
import { ref, watch } from 'vue'
import { ref, watch, computed } from 'vue'
import { UmoEditor } from '@umoteam/editor'
import '@umoteam/editor/style'
import { uploadFile } from '@/api/file'
@@ -21,6 +21,16 @@ const props = defineProps({
type: String,
default: '',
},
// 编辑器高度:默认填满父容器(父容器需有确定高度);
// 传 'auto' 时由 minHeight 兜底,配合父容器自适应高度
height: {
type: String,
default: '100%',
},
minHeight: {
type: Number,
default: 0,
},
})
const emit = defineEmits(['update:modelValue'])
@@ -29,6 +39,11 @@ const content = ref(props.modelValue)
const editorRef = ref(null)
const isCreated = ref(false)
const wrapperStyle = computed(() => ({
height: props.height,
minHeight: props.minHeight ? props.minHeight + 'px' : '',
}))
const options = {
height: '100%',
// umo-editor 会定时触发自动保存(onSave),内容已随表单统一提交,这里给空实现避免控制台报错
@@ -77,10 +92,13 @@ watch(
box-sizing: border-box;
overflow: hidden;
}
/* 注意:必须是 :deep,写成 ::deep 会被浏览器当作无效选择器丢弃,
导致宽度限制失效、编辑器被横向拉伸出滚动条 */
:deep(.umo-editor),
:deep(umo-editor) {
width: 100% !important;
max-width: 100% !important;
min-width: 0 !important;
box-sizing: border-box;
}
</style>