vue绘制评论页面

news2024/10/1 15:29:53
<template>
  <div>
    <div class="conmment_box">
      <div class="my-reply">
        <div class="reply-info">
          <el-input
            @focus="focusInput"
            type="textarea"
            placeholder="请输入内容"
            v-model="textarea"
            maxlength="1000"
            :autosize="{ minRows: 3, maxRows: 3 }"
            autofocus
            class="reply_input"
          >
          </el-input>
        </div>
        <div class="reply-btn-box">
          <div class="limit">
            还能输入
            <span class="num">{{ 1000 - inputLength }}</span>
            个字符
          </div>
          <el-button size="mini" type="primary" round @click="sendComment">
            发表评论
          </el-button>
        </div>
      </div>
      <div
        v-for="(item, i) in comments"
        :key="i"
        class="author-title reply-father"
      >
        <div class="author-info">
          <span class="author-name">{{ item.name }}</span>
          <span class="author-time">{{ item.time }}</span>
        </div>
        <div class="icon-btn">
          <span
            v-if="!item.inputShow"
            @click="showReplyInput(i, item.name, item.id)"
          >
            <i class="iconfont el-icon-s-comment"></i>
            回复
          </span>
          <span v-else @click="closeReplyInput(i, item.name, item.id)">
            <i class="iconfont el-icon-s-comment"></i>
            收起回复
          </span>
        </div>
        <div class="talk-box">
          <p>
            <span class="reply">{{ item.comment }}</span>
          </p>
        </div>
        <!-- 一级回复弹窗 -->
        <div v-show="_inputShow(i)" class="my-reply">
          <div class="reply-info">
            <el-input
              type="textarea"
              placeholder="请输入内容"
              v-model="replytextarea"
              maxlength="1000"
              :autosize="{ minRows: 3, maxRows: 3 }"
              autofocus
              class="reply_input"
            >
            </el-input>
          </div>
          <div class="reply-btn-box">
            <div class="limit">
              还能输入
              <span class="num">{{ 1000 - inputLength2 }}</span>
              个字符
            </div>
            <el-button
              size="mini"
              type="primary"
              round
              @click="sendCommentReply(i)"
            >
              发表评论
            </el-button>
          </div>
        </div>
        <div class="reply-box">
          <div v-for="(reply, j) in item.reply" :key="j" class="author-title">
            <div class="author-info">
              <span class="author-name">{{ reply.from }}</span>
              <span class="author-time">{{ reply.time }}</span>
            </div>
            <div class="icon-btn">
              <span
                v-if="!reply.inputShow"
                @click="showReplyInput2(i, reply.from, reply.id, j)"
              >
                <i class="iconfont el-icon-s-comment"></i>
                回复
              </span>
              <span
                v-else
                @click="closeReplyInput2(i, reply.from, reply.id, j)"
              >
                <i class="iconfont el-icon-s-comment"></i>
                收起回复
              </span>
            </div>
            <div class="talk-box">
              <p>
                <span>回复 {{ reply.to }}:</span>
                <span class="reply">{{ reply.comment }}</span>
              </p>
            </div>
            <!-- 二级回复弹窗 -->
            <div v-show="_inputShow2(i, j)" class="my-comment-reply">
              <div class="reply-info">
                <el-input
                  type="textarea"
                  placeholder="请输入内容"
                  v-model="replytextarea"
                  maxlength="1000"
                  :autosize="{ minRows: 3, maxRows: 3 }"
                  autofocus
                  class="reply_input"
                >
                </el-input>
              </div>
              <div class="reply-btn-box">
                <div class="limit">
                  还能输入
                  <span class="num">{{ 1000 - inputLength2 }}</span>
                  个字符
                </div>
                <el-button
                  size="mini"
                  type="primary"
                  round
                  @click="sendCommentReply(i)"
                >
                  发表评论
                </el-button>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import request from "@/utils/request";
export default {
  computed: {
    inputLength() {
      return this.textarea.length;
    },
    inputLength2() {
      return this.replytextarea.length;
    },
  },
  props: {
    direction: {
      type: String,
      default: "rtl",
    },
  },
  data() {
    return {
      textarea: "",
      replytextarea: "",
      drawer: true,
      closeInput: true,
      index: "0",
      index1: "0",
      index2: "0",
      replyComment: "",
      myName: "Lana Del Rey",
      myId: 19870621,
      to: "",
      toId: -1,
      comments: [
        {
          name: "风居住的街道",
          id: 19870621,
          comment: "我发布一张新电影我不是小三,大家快来看啊",
          time: "2024年9月16日 18:43",
          commentNum: 2,
          like: 15,
          inputShow: false,
          reply: [
            {
              from: "暖阳冬天",
              fromId: 19891221,
              to: "风居住的街道",
              toId: 19870621,
              comment: "我很喜欢你的新电影!!",
              time: "2024年9月16日 18:43",
              commentNum: 1,
              like: 15,
              inputShow: false,
            },
            {
              from: "风居住的街道",
              fromId: 1123,
              to: "风居住的街道",
              toId: 19870621,
              comment: "别忘记宣传我们的新电影啊",
              time: "2024年9月16日 18:43",
              commentNum: 0,
              like: 5,
              inputShow: false,
            },
          ],
        },
        {
          name: "爱跑的鹿",
          id: 19891221,
          comment: "我发行了我的新电影Lover",
          time: "2024年9月16日 18:43",
          commentNum: 1,
          like: 5,
          inputShow: false,
          reply: [
            {
              from: "风居住的街道",
              fromId: 19870621,
              to: "小张",
              toId: 19891221,
              comment: "新电影和speak now 一样棒!",
              time: "2024年9月16日 18:43",
              commentNum: 25,
              like: 5,
              inputShow: false,
            },
          ],
        },
        {
          name: "洽洽库",
          id: 20240830,
          comment: "ckwell on everywhere",
          time: "2024年9月16日 18:43",
          commentNum: 0,
          like: 5,
          inputShow: false,
          reply: [],
        },
      ],
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    /**
     * 获取列表
     */
    getList() {
      // let id = "334551";
      // let _query = {};
      // request({
      //   url: `/api/plan/Comment/getListById/${id}`,
      //   method: "post",
      //   data: _query,
      // }).then((res) => {
      //   console.log(res);
      // });
    },
    handleClose() {},
    focusInput() {
      this.closeInput = false;
    },
    hideReplyBtn() {
      replyInput.style.padding = "10px";
      replyInput.style.border = "none";
    },
    showReplyInput(i, name, id) {
      this.closeInput = true;
      this.comments[this.index1].reply[this.index2].inputShow = false;
      this.comments[this.index].inputShow = false;
      this.index = i;
      this.comments[i].inputShow = true;
      this.to = name;
      this.toId = id;
    },
    closeReplyInput(i, name, id) {
      this.closeInput = false;
      this.comments[this.index].inputShow = false;
    },
    showReplyInput2(i, name, id, j) {
      this.closeInput = true;
      this.comments[this.index].inputShow = false;
      this.comments[this.index1].reply[this.index2].inputShow = false;
      this.index1 = i;
      this.index2 = j;
      this.comments[i].reply[j].inputShow = true;
      this.to = name;
      this.toId = id;
    },
    closeReplyInput2(i, name, id, j) {
      this.closeInput = false;
      this.comments[i].reply[j].inputShow = false;
    },
    _inputShow(i) {
      return this.comments[i].inputShow && this.closeInput;
    },
    _inputShow2(i, j) {
      return this.comments[i].reply[j].inputShow && this.closeInput;
    },
    sendComment() {
      if (!this.textarea) {
        this.$message({
          showClose: true,
          type: "warning",
          message: "评论不能为空",
        });
      } else {
        let a = {};
        let timeNow = new Date().getTime();
        let time = this.dateStr(timeNow);
        a.name = this.myName;
        a.comment = this.textarea;
        a.time = time;
        a.commentNum = 0;
        a.like = 0;
        this.comments.push(a);
        this.replyComment = "";
        this.textarea = "";
      }
    },
    sendCommentReply(i) {
      if (!this.replytextarea) {
        this.$message({
          showClose: true,
          type: "warning",
          message: "评论不能为空",
        });
      } else {
        let a = {};
        let timeNow = new Date().getTime();
        let time = this.dateStr(timeNow);
        a.from = this.myName;
        a.to = this.to;
        a.comment = this.replytextarea;
        a.time = time;
        a.commentNum = 0;
        a.like = 0;
        this.comments[i].reply.push(a);
        this.replytextarea = "";
      }
    },
    dateStr(date) {
      //获取js 时间戳
      var time = new Date().getTime();
      //去掉 js 时间戳后三位,与php 时间戳保持一致
      time = parseInt((time - date) / 1000);
      //存储转换值
      var s;
      if (time < 60 * 10) {
        //十分钟内
        return "刚刚";
      } else if (time < 60 * 60 && time >= 60 * 10) {
        //超过十分钟少于1小时
        s = Math.floor(time / 60);
        return s + "分钟前";
      } else if (time < 60 * 60 * 24 && time >= 60 * 60) {
        //超过1小时少于24小时
        s = Math.floor(time / 60 / 60);
        return s + "小时前";
      } else if (time < 60 * 60 * 24 * 30 && time >= 60 * 60 * 24) {
        //超过1天少于30天内
        s = Math.floor(time / 60 / 60 / 24);
        return s + "天前";
      } else {
        //超过30天ddd
        var date = new Date(parseInt(date));
        return (
          date.getFullYear() +
          "/" +
          (date.getMonth() + 1) +
          "/" +
          date.getDate()
        );
      }
    },
  },
};
</script>

<style lang="scss" scoped>
>>> .conmment_drawer {
  .el-drawer__header {
    margin-bottom: 0px;
    padding: 10px 16px;
    border-bottom: 1px solid rgba(178, 186, 194, 0.3);
  }
}
.conmment_box {
  .my-reply {
    padding: 10px;
    background-color: rgba(245, 246, 247, 0.8);
    margin: 10px 16px;
    border-radius: 8px;
    .reply-info {
      display: inline-block;
      width: 100%;
      >>> .reply_input {
        .el-textarea__inner {
          background: rgba(245, 246, 247, 0.8);
          border: none;
          padding: 0px 6px;
        }
      }
    }
    .reply-btn-box {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 0px 6px;
      margin-top: 10px;
      .limit {
        font-size: 12px;
        color: #999aaa;
        .num {
          color: #222226;
        }
      }
    }
  }
  .my-comment-reply {
    padding: 10px;
    background-color: #ffff;
    margin-top: 8px;
    border-radius: 8px;
    .reply-info {
      display: inline-block;
      width: 100%;
      >>> .reply_input {
        .el-textarea__inner {
          background: #ffff;
          border: none;
          padding: 0px 6px;
        }
      }
    }
    .reply-btn-box {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 0px 6px;
      margin-top: 10px;
      .limit {
        font-size: 12px;
        color: #999aaa;
        .num {
          color: #222226;
        }
      }
    }
  }
  .author-title:not(:last-child) {
    border-bottom: 1px solid rgba(178, 186, 194, 0.3);
  }
  .author-title {
    padding: 10px 16px;
    .author-info {
      display: inline-block;
      width: 60%;
      line-height: 20px;
      > span {
        cursor: pointer;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
      }
      .author-name {
        color: #000;
        font-size: 16px;
        font-weight: bold;
      }
      .author-time {
        margin-left: 6px;
        font-size: 12px;
        color: #aaa4a4;
      }
    }
    .icon-btn {
      width: 30%;
      padding: 0 !important ;
      float: right;
      text-align: right;
      font-size: 12px;
      color: #999aaa;

      > span {
        cursor: pointer;
      }
      .iconfont {
        font-size: 14px;
      }
    }
    .talk-box {
      margin-top: 8px;
      font-size: 14px;
      > p {
        margin: 0;
        color: #222226;
      }
      .reply {
        font-size: 14px;
        color: #000;
      }
    }
    .reply-box {
      margin: 10px 0 0 30px;
      background-color: #efefef;
      border-radius: 4px;
    }
  }
}
</style>

效果:

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2166390.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

LaTeX 编辑器-TeXstudio

TeXstudio 是一款开源跨平台 LaTeX 编辑软件&#xff0c;界面与 Texmaker 类似。TeXstudio 为用户提供互动式拼写检查、代码折叠、语法高亮、代码提示和自动完成等特性&#xff0c;功能丰富&#xff0c;界面美观&#xff0c;但软件本身不提供底层功能&#xff0c;需要使用者自行…

Qualcomm AI Hub模型优化1: Whisper-Base-En导出及问题解决

1 从Qualcomm AI Hub Module中选择Whisper-Base-En模块部署 1.1 进入module虚拟环境 python3 -m venv qai_hub_models_env && source qai_hub_models_env/bin/activate1.2 使用pip安装高通音频转录包 pip install "qai_hub_models[whisper_base_en]" 1.3…

C语言 | Leetcode C语言题解之第436题寻找右区间

题目&#xff1a; 题解&#xff1a; typedef struct {int start;int index; } Node;int cmp(const void *pa, const void *pb) {return ((Node *)pa)->start - ((Node *)pb)->start; }int* findRightInterval(int** intervals, int intervalsSize, int* intervalsColSiz…

网站建设中,JavaScript为什么现在可以做后台了?

JavaScript&#xff0c;作为一种最初为浏览器端脚本设计的语言&#xff0c;已经逐渐发展成为可以在服务器端运行的强大工具。以下是JavaScript可以做后台开发的原因分析&#xff1a; Node.js的崛起 事件驱动与非阻塞I/O&#xff1a;Node.js的事件驱动和非阻塞I/O模型使得JavaSc…

uniapp实现展示1个或多个文字标签,可点击切换选中、不选中的状态

前言 uni-tag是uni-app框架提供的一个标签组件&#xff0c;用于展示标签或者标记某个元素。它可以在视图中用来显示一组标签&#xff0c;并且支持自定义样式和事件。 提示&#xff1a;以下是本篇文章正文内容&#xff0c;下面案例可供参考 uni-notice-bar组件具有以下特点&…

利用千帆SDK实现作文自动批改

目录 作文批改实操 0. 环境准备 1. 大模型推理调用 1.1 Prompt 初探&#xff08;尝试到优化&#xff09; 1.2 Prompt 自动优化迭代&#xff08;APO&#xff1a;Automatic Prompt Optimization&#xff09; 1.3 推理超参优化&#xff08;autotuner&#xff09; 1.3.1 准备…

MATLAB案例 | 基于Copula的可靠度分析

本文详细介绍了Copula函数的绘制及在可靠度分析中的应用 各种类型Copula函数绘图完整代码例题1完整代码例题2完整代码各种类型Copula函数绘图 完整代码 clear clcy_gaussian = copularnd(gaussian, 0.9, 1000); y_t = copularnd(t, 0.91, 17.53,1000); y_Gumbel = copularnd(G…

【Java网络编程】使用Tcp和Udp实现一个小型的回声客户端服务器程序

网络编程的概念 Java中的网络编程是指使用Java语言及其库创建和管理网络应用程序的过程。这一过程使得不同的计算机可以通过网络进行通信和数据交换。Java提供了一系列强大的API&#xff08;应用程序编程接口&#xff09;来支持网络编程&#xff0c;主要涉及以下几个概念&…

AtCoder Beginner Contest 372

A - delete . 题目&#xff1a; 代码&#xff1a; #include <bits/stdc.h>using namespace std;typedef long long LL;int main() {string s;cin>>s;for(auto &x: s){if(x!.) cout<<x;}return 0; } B - 3^A 题目&#xff1a; 思路&#xff1a; 预处…

基于Node.js+Express+MySQL+VUE新闻网站管理系统的设计与实现

1. 引言 随着互联网技术的发展&#xff0c;人们获取信息的方式发生了巨大的变化。传统的新闻媒体逐渐向数字化、智能化方向发展。新闻推荐网站管理系统能够帮助新闻网站更好地管理和推荐新闻内容&#xff0c;提高用户体验。本文将详细介绍一个新闻推荐网站管理系统的整体设计与…

【C++】继承(下)

个人主页~ 继承&#xff08;上&#xff09;~ 继承 四、派生类的默认成员函数五、继承与友元六、继承与静态成员七、复杂的菱形继承以及菱形虚拟继承1、菱形继承2、菱形虚拟继承 八、继承的总结与反思继承和组合 四、派生类的默认成员函数 派生类的构造函数必须调用基类的构造…

(学习记录)使用HAL库 STM32CubeMX——spi(DMA)配置OLED

&#xff08;学习总结&#xff09;STM32CubeMX HAL库教程 学习笔记撰写心得 &#xff08;学习总结&#xff09;STM32CubeMX HAL库教程 学习笔记撰写心得https://blog.csdn.net/Wang2869902214/article/details/142435481 使用HAL库 STM32CubeMX——spi配置 使用硬件spi驱动7针…

element 输入框文字+对应签进行长度 和 的判断

输入文字长度 指定标签的长度 &#xff08;判断长度并提示&#xff09; <div style"position: relative;" classchangyongyu><el-input type"textarea" :autosize"{ minRows: 8, maxRows: 8 }" style"margin-bottom:10px;"…

【React】useEffect

1. 基本介绍 概念 语法 副作用函数依赖项数组&#xff08;空数组时&#xff0c;只会在组件渲染完毕后执行一次副作用函数&#xff09; 2. 使用 import { useEffect, useState } from reactfunction App() {const [value, setValue] useState(0)useEffect(() > {console…

docker-图形化工具-portainer的使用

文章目录 1、安装和启动2、设置登陆密码3、dashboard 上述对容器和镜像的管理都是基于docker客户端的命令来完成&#xff0c;不太方便。为了方便的对docker中的一些对象(镜像、容器、数据卷…)来进行管理&#xff0c;可以使用Portainer来完成。Portainer是一个可视化的容器镜像…

Spring Boot 学习之路 -- Service 层

前言 最近因为业务需要&#xff0c;被拉去研究后端的项目&#xff0c;代码框架基于 Spring Boot&#xff0c;对我来说完全小白&#xff0c;需要重新学习研究…出于个人习惯&#xff0c;会以 Blog 文章的方式做一些记录&#xff0c;文章内容基本来源于「 Spring Boot 从入门到精…

如何帮助我们改造升级原有架构——基于TDengine 平台

一、简介 TDengine 核心是一款高性能、集群开源、云原生的时序数据库&#xff08;Time Series Database&#xff0c;TSDB&#xff09;&#xff0c;专为物联网IoT平台、工业互联网、电力、IT 运维等场景设计并优化&#xff0c;具有极强的弹性伸缩能力。同时它还带有内建的缓存、…

AI可信度标准与框架

AI 可信度被定义为&#xff1a;无论从技术层面还是社会层面&#xff0c;AI 在执行任务时均能够赢得用户的信任和接受的程度。具体地&#xff0c;一个高可信度的 AI 应包含两个组成部分&#xff0c;这些组成部分应贯穿于系统的整个生命周期&#xff1a; &#xff08;一&#xff…

数据结构 ——— C语言实现动态顺序表

目录 顺序表的概念 顺序表的结构&#xff08;静态顺序表和动态顺序表&#xff09; 1. 静态顺序表&#xff1a;使用固定长度的数组存储元素 2. 动态顺序表&#xff1a;使用动态开辟的数组存储元素 为什么选择实现动态顺序表 静态顺序表的缺点&#xff1a; 动态顺序表的优点…

读构建可扩展分布式系统:方法与实践15可扩展系统的基本要素

1. 可扩展系统的基本要素 1.1. 分布式系统在本质上就是复杂的&#xff0c;你必须考虑多种故障模式&#xff0c;并设计应对所有可能发生的情况的处理方式 1.2. 大规模应用程序需要协调大量的硬件和软件组件&#xff0c;共同实现低延迟和高吞吐量的能力 1.3. 面临的挑战是将所…