Vue 表格中的text按钮被点击后,弹出备注框 + sessionStorage

html 复制代码
<template>
  <div>
    <el-table :data="tableData" border style="width: 100%" :cell-style="{ textAlign: 'center' }"
            :header-cell-style="{ textAlign: 'center' }" >
      <el-table-column prop="date" label="日期" :min-width="100"></el-table-column>
      <el-table-column prop="name" label="姓名"></el-table-column>
      <el-table-column prop="id" label="品类ID"></el-table-column>
      <el-table-column prop="type" label="提醒周期" :formatter="formatAlertType"></el-table-column>
      <el-table-column prop="remark" label="备注">
        <template slot-scope="scope">
          <el-button @click="showRemarkDialog(scope.row)" type="text" icon="el-icon-s-comment">备注</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-dialog :title="title" :visible.sync="dialogVisible" width="420px" class="remark-dialog">
      <div class="dialog-content">
        <span class="remark-label">备注:</span>
        <el-input type="textarea" v-model="remark" placeholder="请输入备注" :rows="5" maxlength="200" show-word-limit
          class="custom-textarea"></el-input>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="submitForm">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import '@/styles/textarea.css'
export default {
  data() {
    return {
      tableData: [
        { date: '2024-06-01', id: '01000', type: 0, name: '张三', savedRemark: '' },
        { date: '2024-06-02', id: '01001', type: 1, name: '李四', savedRemark: '' },
        { date: '2024-06-03', id: '01002', type: 0, name: '王五', savedRemark: '' },
      ],
      dialogVisible: false,
      remark: '',
      activeRow: null,

      alertOptions: [
        { label: '一周', value: 0 },
        { label: '一月', value: 1 }
      ],
      title:''
    };
  },
  methods: {
    showRemarkDialog(row) {
      this.remark = row.savedRemark;
      this.activeRow = row;
      this.dialogVisible = true;
      this.title = row.name
    },
    submitForm() {
      if (this.activeRow) {
        this.activeRow.savedRemark = this.remark;
        sessionStorage.setItem(this.getRowKey(this.activeRow), this.remark);
      }
      this.dialogVisible = false;
    },
    getRowKey(row) {
      return `${row.date}_${row.name}_${row.id}`;
    },
    loadSavedRemarks() {
      this.tableData.forEach(row => {
        row.savedRemark = sessionStorage.getItem(this.getRowKey(row)) || '';
      });
    },
    formatAlertType(row, column, cellValue) {
      const alertType = this.alertOptions.find(option => option.value === cellValue);
      return alertType ? alertType.label : '';
    },
  },
  created() {
    this.loadSavedRemarks()
  }
};
</script>

<style scoped>
.remark-dialog {
  margin-top: 10px;
}

.remark-label {
  font-size: 16px;
  margin-bottom: 10px;
  display: block;
}

.dialog-footer {
  text-align: center;
}

.custom-textarea {
  overflow-y: auto;
  resize: vertical;
}
</style>
<style>
.remark-dialog {
  .el-dialog__header {
    border-bottom: none;
  }

  .el-dialog__body {
    padding: 0;
  }

  .dialog-content {
    padding: 0 40px;
  }

  .el-dialog__footer {
    padding: 10px 10px 10px;
    border-top: none;
  }
}
</style>

element-textarea,滚动条样式更美观.

element-textarea,滚动条样式更美观._element的textarea的滚动条怎么修改-CSDN博客文章浏览阅读1.6k次。element-textarea,滚动条样式更美观.element的textarea的滚动条怎么修改https://blog.csdn.net/Backbody/article/details/129422810textarea.css

css 复制代码
@charset "UTF-8";

.el-textarea__inner::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

.el-textarea__inner::-webkit-scrollbar-thumb {
  border-radius: 3px;
  -moz-border-radius: 3px;
  -webkit-border-radius: 3px;
  background-color: #c3c3c3;
}

.el-textarea__inner::-webkit-scrollbar-track {
  background-color: transparent;
}

参考 element-ui表格内容居中(详细教程element-ui表格内容居中(详细教程)_elementui表格内容居中-CSDN博客

cpp 复制代码
:cell-style="{ textAlign: 'center' }"
:header-cell-style="{ textAlign: 'center' }"
table加这一句就好了

推荐和参看文章:element-plus中el-dialog使用::v-deep()穿透设置样式不生效踩坑记录

element-plus中el-dialog使用::v-deep()穿透设置样式不生效踩坑记录_element-plus样式穿透失败-CSDN博客文章浏览阅读736次。如上:我想去掉插槽自带的下边框和上边框,但是不生效。给el-dialog加个类,在不带scope的。_element-plus样式穿透失败https://blog.csdn.net/jieyucx/article/details/139283454?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_baidulandingword~default-0-139283454-blog-132542643.235^v43^pc_blog_bottom_relevance_base1&spm=1001.2101.3001.4242.1&utm_relevant_index=1

相关推荐
持久的棒棒君3 小时前
npm安装electron下载太慢,导致报错
前端·electron·npm
渔舟唱晚@4 小时前
大模型数据流处理实战:Vue+NDJSON的Markdown安全渲染架构
vue.js·大模型·数据流
crary,记忆5 小时前
Angular微前端架构:Module Federation + ngx-build-plus (Webpack)
前端·webpack·angular·angular.js
漂流瓶jz5 小时前
让数据"流动"起来!Node.js实现流式渲染/流式传输与背后的HTTP原理
前端·javascript·node.js
SamHou06 小时前
手把手 CSS 盒子模型——从零开始的奶奶级 Web 开发教程2
前端·css·web
我不吃饼干6 小时前
从 Vue3 源码中了解你所不知道的 never
前端·typescript
开航母的李大6 小时前
【中间件】Web服务、消息队列、缓存与微服务治理:Nginx、Kafka、Redis、Nacos 详解
前端·redis·nginx·缓存·微服务·kafka
Bruk.Liu6 小时前
《Minio 分片上传实现(基于Spring Boot)》
前端·spring boot·minio
鱼樱前端6 小时前
Vue3+d3-cloud+d3-scale+d3-scale-chromatic实现词云组件
前端·javascript·vue.js
q_19132846957 小时前
基于Springboot+Vue的办公管理系统
java·vue.js·spring boot·后端·intellij idea