MyChatDetail.vue 3.0 KB
Newer Older
1
<template>
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
  <div>
    <!-- <el-button @click="$router.back()">后退</el-button> -->
    <el-button @click="goBack()">后退</el-button>
    <h4 class="text-center">ChatGpt问答详情 --- {{ id }}</h4>
    <el-container>
      <el-main>
        <el-table border :data="list">
          <el-table-column label="序号" width="50">
            <template slot-scope="scope">
              <span>{{ scope.row.id }}</span>
            </template>
          </el-table-column>
          <el-table-column label="问题" width="240">
            <template slot-scope="scope">
              <span>{{ scope.row.question }}</span>
            </template>
          </el-table-column>
          <el-table-column label="回答">
            <template slot-scope="scope">
              <span id="td-response">{{ scope.row.response }}</span>
            </template>
          </el-table-column>
          <el-table-column label="创建时间" width="170">
            <template slot-scope="scope">
              <span>{{ scope.row.createTime | dateFormat }}</span>
            </template>
          </el-table-column>
        </el-table>
      </el-main>
    </el-container>
    <div class="button-container">
      <el-button @click="copyCode">复制回答</el-button>
    </div>
  </div>
36 37 38
</template>
<script>
// 导入 axios 请求库
39
import axios from "axios";
40
export default {
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
  name: "MyChatDetail",
  props: ["id"],
  data() {
    return {
      list: [],
    };
  },
  created() {
    // 调用请求数据的方法
    this.initChatList();
  },
  methods: {
    goBack() {
      // 传递参数到前一个页面
      const params = {
        // 参数名: 参数值
        back: "back",
        // baz: "qux",
      };

      // 使用 $router.push() 导航到前一个页面
      this.$router.push({
        path: "/home/chat", // 前一个页面的路径
        query: params, // 参数对象
      });
66
    },
67 68 69 70
    // 封装请求列表数据的方法
    async initChatList() {
      // 调用 axios 的 get 方法,请求列表数据
      const { data: res } = await axios.get(
71
        "http://120.79.36.53:8888/chatbot/" + this.id
72 73 74 75 76 77 78 79 80 81 82 83
      );
      // 只要请求回来的数据,在页面渲染期间要用到,则必须转存到 data 中
      if (res.code === 200) {
        this.list = [
          {
            id: res.result.id,
            question: res.result.question,
            response: res.result.response,
            createTime: res.result.createTime,
          },
        ];
      }
84
    },
85 86 87 88 89 90 91 92 93 94
    copyCode() {
      const codeBlock = document.getElementById("td-response");
      const range = document.createRange();
      range.selectNode(codeBlock);
      const selection = window.getSelection();
      selection.removeAllRanges();
      selection.addRange(range);
      document.execCommand("copy");
      selection.removeAllRanges();
      this.$message.success("代码已复制到剪贴板");
95
    },
96
  },
97 98 99 100 101
};
</script>

<style lang="less" scoped>
.button-container {
102 103 104 105
  position: fixed;
  bottom: 0;
  right: 0;
  margin: 16px;
106
}
107
</style>