解决element的Table表格组件的高度问题( height只能是数字或者字符串 ),实现height: calc(100vh - 260px) 的效果

注:也可直接将el-table的height属性绑定为字符串:calc(100vh - 260px) 实现为同样的效果, 260 是顶部和底部导航以及部分自定义布局 ;例:

<template>
  <el-table
    :data="tableData"
    :height="` calc(100vh - 260px)`"
    border
    style="width: 100%">
    <el-table-column
      prop="date"
      label="日期"
      width="180">
    </el-table-column>
    <el-table-column
      prop="name"
      label="姓名"
      width="180">
    </el-table-column>
    <el-table-column
      prop="address"
      label="地址">
    </el-table-column>
  </el-table>
</template>

<script>
  export default {
    data() {
      return {
        tableData: [{
          date: '2016-05-03',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1518 弄'
        }, {
          date: '2016-05-02',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1518 弄'
        }]
      }
    }
  }
</script>

一、定义获取浏览器窗口高度的js文件

相当于用js实现了 height: calc(100vh - 260px); 的效果

注意: 260 是顶部和底部导航以及部分自定义布局 ;
autoTableHeight.js

//获取浏览器窗口高度,处理Element的Table组件的高度问题(height只能是数字或者字符串)
function autoTableHeight() {
    var winHeight = 0;
    if (window.innerHeight) {
        winHeight = window.innerHeight;
    } else if (document.body && document.body.clientHeight) {
        winHeight = document.body.clientHeight;
    } //通过深入Document内部对body进行检测,获取浏览器窗口高度
    else if (document.documentElement && document.documentElement.clientHeight) {
        winHeight = document.documentElement.clientHeight;
    }
    // 260  是顶部和底部导航以及部分自定义布局  ;相当于用js实现了 height: calc(100vh - 260px); 的效果
    return winHeight - 260;
}

//浏览器窗口变化时
window.onresize = function() {
    autoTableHeight();
};

//浏览器重新加载时
window.onload = function() {
    autoTableHeight();
};

export default autoTableHeight;

在组件中引入js文件,并给el-table绑定height

  1. 在组件内部,el-table绑定height, :height="tableHeight"
  2. 表格设置height属性后,表头得以固定,且超出该高度会出现滚动条
  3. 注意,我这里省去了头部和顶部以及侧边栏的代码。
<template>
  <div class="inform-manage comn_bg">
          <el-table
            :data="tableData"
            class="multiple-table"
            border
            :highlight-current-row="true"
            :height="tableHeight"
            :default-sort="{ prop: 'name', order: 'descending' }"
            @sort-change="handleSortChange"
            @selection-change="handleSelectionChange"
            ref="multipleTable"
            tooltip-effect="dark"
            style="width: 100%;"
          >
            <el-table-column
              fixed="left"
              type="selection"
              width="55"
              align="center"
            ></el-table-column>
            <el-table-column
              sortable
              prop="name"
              label="通知公告标题"
              width="120"
              align="center"
            ></el-table-column>
            <el-table-column
              sortable
              prop="address"
              label="发布单位"
              align="center"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              sortable
              prop="remark"
              label="发布人"
              align="center"
              width="120"
            ></el-table-column>
            <el-table-column
              sortable
              prop="date"
              label="发布时间"
              align="center"
              width="120"
            ></el-table-column>
            <el-table-column
              sortable
              prop="address"
              label="内容概述"
              align="center"
              width="120"
            ></el-table-column>
            <el-table-column
              sortable
              prop="remark"
              label="备注"
              align="center"
              width="120"
            ></el-table-column>
            <el-table-column sortable label="排序号" width="120" align="center">
              <template slot-scope="scope" align="center">
                <el-input
                  class="sort_input"
                  v-model="scope.row.sortNum"
                ></el-input>
              </template>
            </el-table-column>
            <el-table-column sortable label="状态" align="center">
              <template slot-scope="scope">
                <span>{{ scope.row.status | filterStatus }}</span>
              </template>
            </el-table-column>
            <el-table-column sortable label="操作" align="center" width="200">
              <template slot-scope="scope">
                <button class="download_btn">
                  <i class="el-icon-download"></i> 下载
                </button>
                <button class="detail_btn">
                  <i class="el-icon-tickets"></i> 发布详情
                </button>
              </template>
            </el-table-column>
          </el-table>
      </div>
    </div>
  </div>
</template>
<script>
import autoTableHeight from "@/utils/autoTableHeight.js"; // 1. 引入刚刚定义的js文件 
export default {
  data() {
    return {
      tableData: [
        {
          date: "2016-05-03",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1518 弄",
          remark: "备注信息1",
          sortNum: 1,
          status: true
        },
        {
          date: "2016-05-02",
          name: "张晓",
          address: "上海市普陀区金沙江路 1518 弄",
          remark: "备注信息2",
          sortNum: 2,
          status: false
        },
        {
          date: "2016-05-04",
          name: "阿厌",
          address: "上海市普陀区金沙江路 1518 弄",
          remark: "备注信息3",
          sortNum: 3,
          status: true
        }
      ],
      multipleSelection: []
    };
  },
  computed: {
    tableHeight() { 
      return autoTableHeight(); // 2. 调用函数,返回高度
    }
  },
  methods: {
    handleSelectionChange(val) {
      this.multipleSelection = val;
      console.log("通知table data:", val);
    },
    handleSortChange({ column, prop, order }) {
      console.log("通知页排序变化:", prop);
    }
  },
  filters: {
    filterStatus(status) {
      return status ? "已发布" : "待发布";
    }
  }
};
</script>
<style lang="scss">
.inform-manage {
  .download_btn {
    background: $icon_color;
    border: 1px solid $icon_color;
    color: #fff;
    padding: 2px;
    cursor: pointer;
  }
  .detail_btn {
    background: #ffb800;
    border: 1px solid #ffb800;
    margin-left: 20px;
    color: #fff;
    padding: 2px;
    cursor: pointer;
  }
}
</style>

在这里插入图片描述

<template> <el-container style="height: 100vh; overflow: hidden;"> <!-- 侧边栏 --> <el-aside width="200px" style="background-color: #304156;"> <el-menu default-active="1" class="el-menu-vertical-demo" background-color="#304156" text-color="#bfcbd9" active-text-color="#409EFF"> <el-menu-item index="1"> <i class="el-icon-user"></i> <span>员工管理</span> </el-menu-item> </el-menu> </el-aside> <!-- 主内容区 --> <el-container> <!-- 头部 --> <el-header class="app-header"> <h2 class="app-title">员工管理系统</h2> </el-header> <!-- 主要内容 --> <el-main class="app-content"> <!-- 查询条件 --> <div class="query-section"> <el-row :gutter="20"> <el-col :span="4"> <el-input v-model="queryParams.name" placeholder="请输入姓名" clearable /> </el-col> <el-col :span="4"> <el-select v-model="queryParams.gender" placeholder="请选择性别" clearable> <el-option label="男" :value="0" /> <el-option label="女" :value="1" /> </el-select> </el-col> <el-col :span="4"> <el-select v-model="queryParams.job" placeholder="请选择职位" clearable> <el-option v-for="item in jobOptions" :key="item.value" :label="item.label" :value="item.value" /> </el-select> </el-col> <el-col :span="6"> <el-date-picker v-model="queryParams.dateRange" type="daterange" start-placeholder="开始日期" end-placeholder="结束日期" format="YYYY-MM-DD" value-format="YYYY-MM-DD" /> </el-col> <el-col :span="6" class="action-buttons"> <el-button type="primary" @click="fetchData" icon="el-icon-search">搜索</el-button> <el-button type="success" @click="showAddDialog" icon="el-icon-plus">新增</el-button> <el-button type="danger" @click="batchDelete" icon="el-icon-delete">批量删除</el-button> </el-col> </el-row> </div> <!-- 数据表格 --> <div class="table-section"> <el-table :data="tableData" border stripe style="width: 100%" @selection-change="handleSelectionChange"> <el-table-column type="selection" width="55" align="center" /> <el-table-column prop="id" label="ID" width="80" align="center" /> <el-table-column prop="name" label="姓名" width="120" /> <el-table-column label="头像" width="100" align="center"> <template #default="scope"> <el-avatar v-if="scope.row.image" :src="scope.row.image" :size="50" shape="square" :preview-src-list="[scope.row.image]" /> <el-avatar v-else :size="50" shape="square"> <i class="el-icon-user-solid" style="font-size: 24px;" /> </el-avatar> </template> </el-table-column> <el-table-column prop="gender" label="性别" width="80" align="center"> <template #default="scope"> <el-tag :type="scope.row.gender === 0 ? 'primary' : 'danger'"> {{ scope.row.gender === 0 ? '男' : '女' }} </el-tag> </template> </el-table-column> <el-table-column prop="job" label="职位" width="150"> <template #default="scope"> <el-tag :type="getJobTagType(scope.row.job)"> {{ jobMap[scope.row.job] || '未知' }} </el-tag> </template> </el-table-column> <el-table-column prop="entrydate" label="入职时间" width="120" align="center" /> <el-table-column prop="createTime" label="创建时间" width="180" align="center" /> <!-- 添加最后修改时间列 --> <el-table-column prop="updateTime" label="最后修改时间" width="180" align="center" /> <el-table-column label="操作" width="200" align="center" fixed="right"> <template #default="scope"> <el-button size="small" type="primary" icon="el-icon-edit" @click="handleEdit(scope.row)">编辑</el-button> <el-button size="small" type="danger" icon="el-icon-delete" @click="handleDelete(scope.row.id)">删除</el-button> </template> </el-table-column> </el-table> </div> <!-- 分页组件 --> <div class="pagination-section"> <el-pagination background layout="total, prev, pager, next, sizes" :total="total" :page-sizes="[5, 10, 20, 50]" :page-size="queryParams.pageSize" v-model:current-page="queryParams.pageNum" @current-change="fetchData" @size-change="handleSizeChange" /> </div> </el-main> </el-container> </el-container> <!-- 新增/编辑对话框 - 优化样式 --> <el-dialog v-model="dialogVisible" :title="dialogTitle" width="700px" :close-on-click-modal="false"> <el-form :model="form" ref="formRef" :rules="formRules" label-width="100px" label-position="left"> <el-row :gutter="20"> <el-col :span="12"> <el-form-item label="姓名" prop="name"> <el-input v-model="form.name" /> </el-form-item> </el-col> <el-col :span="12"> <el-form-item label="用户名" prop="username"> <el-input v-model="form.username" /> </el-form-item> </el-col> </el-row> <el-row :gutter="20"> <el-col :span="12"> <el-form-item label="性别" prop="gender"> <el-select v-model="form.gender" placeholder="请选择性别" style="width: 100%"> <el-option label="男" :value="0" /> <el-option label="女" :value="1" /> </el-select> </el-form-item> </el-col> <el-col :span="12"> <el-form-item label="职位" prop="job"> <el-select v-model="form.job" placeholder="请选择职位" style="width: 100%"> <el-option v-for="item in jobOptions" :key="item.value" :label="item.label" :value="item.value" /> </el-select> </el-form-item> </el-col> </el-row> <el-row :gutter="20"> <el-col :span="12"> <el-form-item label="密码" prop="password" v-if="!isEdit"> <el-input v-model="form.password" show-password /> </el-form-item> </el-col> <el-col :span="12"> <el-form-item label="入职时间" prop="entrydate"> <el-date-picker v-model="form.entrydate" type="date" placeholder="选择日期" format="YYYY-MM-DD" value-format="YYYY-MM-DD" style="width: 100%" /> </el-form-item> </el-col> </el-row> <el-form-item label="头像链接" prop="image"> <el-input v-model="form.image" placeholder="请输入图片URL" /> <div class="avatar-preview" v-if="form.image"> <el-image :src="form.image" fit="cover" style="width: 100px; height: 100px; margin-top: 10px;" :preview-src-list="[form.image]" /> </div> </el-form-item> <el-form-item class="form-actions"> <el-button type="primary" @click="submitForm">提交</el-button> <el-button @click="dialogVisible = false">取消</el-button> </el-form-item> </el-form> </el-dialog> </template> <script setup> import { ref, reactive, onMounted } from 'vue'; import axios from 'axios'; import { ElMessage, ElMessageBox } from 'element-plus'; // 设置 axios 实例 const apiClient = axios.create({ baseURL: 'http://localhost:8080/emps', timeout: 5000, }); // 表格数据 const tableData = ref([]); const total = ref(0); const selectedRows = ref([]); const formRef = ref(null); // 查询参数 const queryParams = reactive({ pageNum: 1, pageSize: 5, name: '', gender: null, job: null, dateRange: [] }); // 表单数据 const form = reactive({ id: null, username: '', password: '', name: '', gender: null, job: null, image: '', entrydate: '' }); // 表单验证规则 const formRules = { name: [{ required: true, message: '请输入姓名', trigger: 'blur' }], username: [{ required: true, message: '请输入用户名', trigger: 'blur' }], gender: [{ required: true, message: '请选择性别', trigger: 'change' }], job: [{ required: true, message: '请选择职位', trigger: 'change' }], password: [{ required: true, message: '请输入密码', trigger: 'blur' }], entrydate: [{ required: true, message: '请选择入职日期', trigger: 'change' }] }; // 对话框控制 const dialogVisible = ref(false); const dialogTitle = ref('新增员工'); const isEdit = ref(false); // 职位映射表 const jobMap = { 1: '班主任', 2: '讲师', 3: '学工主管', 4: '教研主管', 5: '咨询师' }; // 职位选项 const jobOptions = [ { label: '班主任', value: 1 }, { label: '讲师', value: 2 }, { label: '学工主管', value: 3 }, { label: '教研主管', value: 4 }, { label: '咨询师', value: 5 } ]; // 获取职位标签类型 const getJobTagType = (job) => { const types = ['', 'success', 'warning', 'danger', 'info', 'primary']; return types[job] || 'info'; }; // 获取数据 const fetchData = async () => { const params = { page: queryParams.pageNum, pageSize: queryParams.pageSize, name: queryParams.name, gender: queryParams.gender, job: queryParams.job, begin: queryParams.dateRange[0] || '', end: queryParams.dateRange[1] || '' }; try { const res = await apiClient.get('', { params }); if (res.data.code === 1) { tableData.value = res.data.data.rows.map(item => ({ ...item, // 格式化最后修改时间 updateTime: formatDateTime(item.updateTime) })); total.value = res.data.data.total; } else { ElMessage.error('获取数据失败:' + res.data.msg); } } catch (error) { console.error('请求出错:', error); ElMessage.error('网络请求失败,请检查后端是否运行正常'); } }; // 时间格式化函数 const formatDateTime = (dateTime) => { if (!dateTime) return ''; // 如果是字符串直接返回 if (typeof dateTime === 'string') { // 尝试解析ISO格式时间 try { const date = new Date(dateTime); return date.toLocaleString('zh-CN', { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit' }).replace(/\//g, '-'); } catch (e) { return dateTime; } } // 如果是Date对象或时间戳 const date = new Date(dateTime); return date.toLocaleString('zh-CN', { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit' }).replace(/\//g, '-'); }; // 显示新增对话框 const showAddDialog = () => { dialogTitle.value = '新增员工'; isEdit.value = false; Object.assign(form, { id: null, username: '', password: '', name: '', gender: null, job: null, image: '', entrydate: '' }); dialogVisible.value = true; }; // 显示编辑对话框 const handleEdit = (row) => { dialogTitle.value = '编辑员工'; isEdit.value = true; Object.assign(form, { ...row }); dialogVisible.value = true; }; // 提交表单 const submitForm = async () => { try { await formRef.value.validate(); if (isEdit.value) { await apiClient.put('', form); ElMessage.success('员工信息更新成功'); } else { await apiClient.post('', form); ElMessage.success('员工添加成功'); } dialogVisible.value = false; fetchData(); } catch (error) { if (error.name !== 'Error') { console.error('保存失败:', error); ElMessage.error('操作失败:' + (error.response?.data?.message || error.message)); } } }; // 删除员工 const handleDelete = async (id) => { try { await ElMessageBox.confirm(`确认删除ID为 ${id} 的员工吗?`, '删除确认', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' }); await apiClient.delete(`/${[id]}`); ElMessage.success('删除成功'); fetchData(); } catch (error) { if (error !== 'cancel') { console.error('删除失败:', error); ElMessage.error('删除失败:' + (error.response?.data?.message || error.message)); } } }; // 批量删除 const batchDelete = async () => { if (selectedRows.value.length === 0) { ElMessage.warning('请至少选择一条记录'); return; } try { const ids = selectedRows.value.map(item => item.id); await ElMessageBox.confirm(`确认删除选中的 ${ids.length} 条员工吗?`, '批量删除确认', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' }); await apiClient.delete(`/${ids}`); ElMessage.success(`成功删除 ${ids.length} 条记录`); fetchData(); } catch (error) { if (error !== 'cancel') { console.error('批量删除失败:', error); ElMessage.error('删除失败:' + (error.response?.data?.message || error.message)); } } }; // 表格选择监听 const handleSelectionChange = (rows) => { selectedRows.value = rows; }; // 处理分页大小变化 const handleSizeChange = (size) => { queryParams.pageSize = size; fetchData(); }; // 初始化加载数据 onMounted(() => { fetchData(); }); </script> <style scoped> /* 全局样式 */ .app-header { background-color: #fff; box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08); display: flex; align-items: center; padding: 0 20px; z-index: 1; } .app-title { margin: 0; font-size: 18px; font-weight: 600; color: #333; } .app-content { padding: 20px; background-color: #f0f2f5; height: calc(100vh - 60px); overflow-y: auto; } .query-section { background: #fff; padding: 20px; border-radius: 4px; margin-bottom: 20px; box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1); } .table-section { background: #fff; padding: 20px; border-radius: 4px; margin-bottom: 20px; box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1); } .pagination-section { display: flex; justify-content: center; background: #fff; padding: 15px 0; border-radius: 4px; box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1); } .action-buttons { display: flex; justify-content: flex-end; } .form-actions { display: flex; justify-content: center; margin-top: 20px; } .avatar-preview { display: flex; justify-content: center; margin-top: 10px; } .el-avatar { background-color: #f5f7fa; display: flex; align-items: center; justify-content: center; } .el-avatar i { color: #909399; } /* 优化对话框样式 */ .el-dialog__body { padding: 20px 25px; } /* 调整操作列按钮间距 */ .el-table .el-button { margin: 0 5px; } /* 确保选择器宽度100% */ .el-select { width: 100%; } </style> 优化一下代码使代码量减少,更简洁,解决表格右侧空白的问题
07-15
<script setup> import { onBeforeUnmount, ref, shallowRef } from 'vue' import { Editor, Toolbar } from '@wangeditor/editor-for-vue' import '@wangeditor/editor/dist/css/style.css' import router from "@/router/index.js"; // 编辑器实例 const editorRef = shallowRef() // 内容 HTML const valueHtml = ref('') // 编辑器配置 const editorConfig = { placeholder: '请输入内容...', MENU_CONF: { insertImage: { checkImage(src) { if (src.indexOf("http") !== 0) { return "图片网址必须以 http/https 开头"; } return true; }, }, } } // 工具栏配置 const toolbarConfig = { toolbarKeys: [ 'headerSelect', 'bold', 'italic', 'underline', 'through', 'color', 'bgColor', 'fontSize', 'fontFamily', 'lineHeight', 'bulletedList', 'numberedList', 'todo', 'justifyLeft', 'justifyRight', 'justifyCenter', 'insertLink', 'insertImage', 'insertTable', 'codeBlock', 'blockquote', 'divider', 'emotion', 'undo', 'redo' ] } // 历史记录相关状态 const showHistory = ref(false) const historyItems = ref([ { title: 'AI生成的学习笔记', date: '2023-10-15 14:30' }, { title: '项目会议记录', date: '2023-10-14 09:45' }, { title: '技术方案设计', date: '2023-10-12 16:20' }, { title: '读书笔记 - 人工智能导论', date: '2023-10-10 11:15' }, { title: '周计划安排', date: '2023-10-08 08:30' }, { title: '周计划安排', date: '2023-10-08 08:30' }, { title: '周计划安排', date: '2023-10-08 08:30' }, { title: '周计划安排', date: '2023-10-08 08:30' }, { title: '周计划安排', date: '2023-10-08 08:30' }, { title: '周计划安排', date: '2023-10-08 08:30' }, { title: '周计划安排', date: '2023-10-08 08:30' }, { title: '周计划安排', date: '2023-10-08 08:30' } ]) // 编辑器回调函数 const handleCreated = (editor) => { editorRef.value = editor console.log("编辑器已创建", editor) } const handleChange = (editor) => { console.log("内容变化:", editor.children) } const handleDestroyed = (editor) => { console.log('编辑器已销毁', editor) } const handleFocus = (editor) => { console.log('编辑器获得焦点', editor) } const handleBlur = (editor) => { console.log('编辑器失去焦点', editor) } const customAlert = (info, type) => { alert(`【系统提示】${type} - ${info}`) } const customPaste = (editor, event, callback) => { console.log('粘贴事件', event) callback(true) // 继续默认的粘贴行为 } // 及时销毁编辑器 onBeforeUnmount(() => { const editor = editorRef.value if (editor == null) return editor.destroy() }) // 头部按钮功能 const handleBack = () => { router.back() // 返回上一页 } const toggleHistory = () => { showHistory.value = !showHistory.value } const goToProfile = () => { alert('跳转到个人用户管理界面') } </script> <template> <div class="editor-layout"> <!-- 固定头部 --> <header class="app-header"> <button class="back-btn" @click="handleBack"> <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M19 12H5M12 19l-7-7 7-7"/> </svg> </button> <h1 class="app-title">Edulens AI_<span class="gradient-text">AI笔记</span></h1> <div class="header-right"> <button class="history-btn" @click="toggleHistory"> <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <circle cx="12" cy="12" r="10"></circle> <polyline points="12 6 12 12 16 14"></polyline> </svg> <span>历史记录</span> </button> <div class="user-avatar" @click="goToProfile"> <div class="avatar-placeholder"> <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"></path> <circle cx="12" cy="7" r="4"></circle> </svg> </div> </div> </div> </header> <!-- 固定工具栏 --> <div class="fixed-toolbar"> <Toolbar :editor="editorRef" :defaultConfig="toolbarConfig" /> </div> <!-- 编辑器区域 --> <!-- <div class="page-container">--> <div class="editor-container" > <Editor v-model="valueHtml" :defaultConfig="editorConfig" @onChange="handleChange" @onCreated="handleCreated" @onDestroyed="handleDestroyed" @onFocus="handleFocus" @onBlur="handleBlur" @customAlert="customAlert" @customPaste="customPaste" /> </div> <!-- </div>--> <!-- 历史记录侧边栏 --> <div class="history-sidebar" :class="{ active: showHistory }"> <div class="sidebar-header"> <h2>历史记录</h2> <button class="close-btn" @click="toggleHistory"> <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <line x1="18" y1="6" x2="6" y2="18"></line> <line x1="6" y1="6" x2="18" y2="18"></line> </svg> </button> </div> <div class="history-list"> <div v-for="(item, index) in historyItems" :key="index" class="history-item"> <div class="history-title">{{ item.title }}</div> <div class="history-date">{{ item.date }}</div> </div> </div> </div> <!-- 历史记录遮罩 --> <div v-if="showHistory" class="sidebar-mask" @click="toggleHistory"></div> </div> </template> <style> /* 基础样式重置 */ * { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; } .editor-layout { position: relative; height: 100vh; overflow: hidden; background: linear-gradient(135deg, #f5f7fa 0%, #e4edf5 100%); } /* 固定头部样式 */ .app-header { position: fixed; top: 0; left: 0; right: 0; height: 60px; display: flex; align-items: center; padding: 0 20px; background: #ffffff; box-shadow: 0 2px 15px rgba(0, 0, 0, 0.1); z-index: 1000; transition: all 0.3s ease; } .back-btn { width: 40px; height: 40px; border: none; background: none; cursor: pointer; border-radius: 50%; display: flex; align-items: center; justify-content: center; transition: all 0.2s ease; } .back-btn:hover { background: #f0f5ff; transform: translateX(-2px); } .back-btn svg { width: 20px; height: 20px; color: #4a6cf7; } .app-title { flex: 1; text-align: left; font-size: 1.4rem; font-weight: 600; color: #1a1a1a; letter-spacing: 0.5px; } .header-right { display: flex; align-items: center; gap: 15px; } .history-btn { display: flex; align-items: center; gap: 6px; padding: 8px 15px; background: #f0f5ff; border: none; border-radius: 20px; color: #4a6cf7; font-weight: 500; font-size: 0.9rem; cursor: pointer; transition: all 0.2s ease; } .history-btn:hover { background: #e1e9ff; transform: translateY(-1px); box-shadow: 0 2px 8px rgba(74, 108, 247, 0.2); } .history-btn svg { width: 18px; height: 18px; } .user-avatar { width: 40px; height: 40px; border-radius: 50%; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); display: flex; align-items: center; justify-content: center; cursor: pointer; transition: all 0.3s ease; box-shadow: 0 4px 10px rgba(118, 75, 162, 0.3); } .user-avatar:hover { transform: scale(1.05); box-shadow: 0 6px 15px rgba(118, 75, 162, 0.4); } .avatar-placeholder { width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; background: rgba(255, 255, 255, 0.2); } .avatar-placeholder svg { width: 18px; height: 18px; color: white; } /* 固定工具栏样式 */ .fixed-toolbar { position: fixed; top: 60px; /* 在头部下方 */ left: 0; right: 0; z-index: 999; background: white; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05); border-bottom: 1px solid #eaeef5; padding: 0 10px; } /* 编辑器容器样式 */ .editor-container { margin-top: 110px; /* 头部高度 + 工具栏高度 */ height: calc(100vh - 150px); /*overflow-y: auto;*/ padding: 20px; background: white; border-radius: 12px; /*margin-left: 20px; margin-right: 20px;*/ margin-left: auto; margin-right: auto; box-shadow: 0 5px 20px rgba(0, 0, 0, 0.05); width: 1000px; /* 固定宽度 */ } /* 历史记录侧边栏 */ .history-sidebar { position: fixed; top: 0; right: -400px; width: 380px; height: 100vh; background: white; z-index: 2000; box-shadow: -5px 0 25px rgba(0, 0, 0, 0.1); transition: right 0.4s cubic-bezier(0.23, 1, 0.32, 1); display: flex; flex-direction: column; } .history-sidebar.active { right: 0; } .sidebar-header { display: flex; justify-content: space-between; align-items: center; padding: 20px; border-bottom: 1px solid #eee; } .sidebar-header h2 { color: #333; font-weight: 600; } .close-btn { background: none; border: none; width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; cursor: pointer; transition: all 0.2s ease; } .close-btn:hover { background: #f5f7fa; } .close-btn svg { width: 20px; height: 20px; color: #666; } .history-list { flex: 1; overflow-y: auto; padding: 15px; } .history-item { padding: 15px; border-radius: 8px; margin-bottom: 10px; background: #f9fbfd; transition: all 0.2s ease; cursor: pointer; border-left: 3px solid #4a6cf7; } .history-item:hover { background: #edf3ff; transform: translateX(5px); } .history-title { font-weight: 500; color: #1a1a1a; margin-bottom: 5px; } .history-date { font-size: 0.85rem; color: #666; } /* 历史记录遮罩 */ .sidebar-mask { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0, 0, 0, 0.4); z-index: 1500; backdrop-filter: blur(2px); } /* 响应式设计 */ @media (max-width: 768px) { .app-header { padding: 0 10px; } .app-title { font-size: 1.1rem; } .history-btn span { display: none; } .editor-container { margin-left: 10px; margin-right: 10px; padding: 15px; } .history-sidebar { width: 85%; } } /* 滚动条美化 */ ::-webkit-scrollbar { width: 8px; } ::-webkit-scrollbar-track { background: #f1f1f1; border-radius: 4px; } ::-webkit-scrollbar-thumb { background: #c1c1c1; border-radius: 4px; } ::-webkit-scrollbar-thumb:hover { background: #a8a8a8; } .page-container { overflow-y: auto; /* 启用页面级滚动 */ } .gradient-text { /* 渐变背景(与头像的渐变颜色保持一致) */ background: linear-gradient(135deg, #00ffe9 0%, #e70fff 100%); /* 将背景裁剪为文字形状(兼容 Safari/Chrome) */ -webkit-background-clip: text; background-clip: text; /* 文字透明,显示背景渐变 */ color: transparent; /* 可选:增强文字重量,让渐变更明显 */ font-weight: 700; } </style> 写一个保存按钮用于向后端发送保存请求
最新发布
07-30
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值