All files / vue-koa-demo/src/components Detail.vue

0% Statements 0/16
100% Branches 0/0
0% Functions 0/5
0% Lines 0/15
1 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 36 37 38 39 40 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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103                                                                                                                                                                                                             
<template>
  <div class="detail">
    <el-form ref="detailTodo" :model="detailTodo" label-width="60px">
      <el-form-item label="时间">
        <p class="detail-date">{{ detailTodo.time }}</p>
      </el-form-item>
      <el-form-item label="内容">
        <p class="detail-content">{{ detailTodo.detail }}</p>
      </el-form-item>
      <img src="../assets/complete.png" alt="已完成" v-if="detailTodo.status === 'done'">
      <i @click="$router.replace('/todo')"></i>
    </el-form>
  </div>
</template>
 
<script>
import axios from 'axios'
import moment from 'moment'
 
export default {
  data () {
    return {
      detailTodo: {
        time: '',
        detail: '',
        status: 'todo'
      }
    }
  },
  created () {
    axios.get(`/api/todo/detail/${this.$route.params.todoId}`)
      .then(res => {
        this.detailTodo.detail = res.data.todo.todoDetail
        this.detailTodo.time = moment(Number(res.data.todo.todoTime)).format(`YYYY 年 MM 月 DD 日 hh:mm a`)
        this.detailTodo.status = res.data.todo.todoState
      })
      .catch(err => {
        console.log(err)
        this.$message.error({ message: '事项详情获取失败', duration: 1500 })
        setTimeout(() => {
          this.$router.push('/todo')
        }, 1000)
      })
  }
}
</script>
 
<style lang="scss" scoped>
.detail {
  flex: 1 1 auto;
  display: flex;
  justify-content: center;
  align-items: center;
}
img {
  width: 100px;
  position: absolute;
  right: 30px;
  bottom: 50px;
}
.el-form {
  width: 400px;
  padding: 90px 40px;
  margin: 0 auto;
  background: white;
  box-shadow: 0 0 20px 3px rgba(0, 0, 0, .1);
  position: relative;
  p {
    height: 42px;
  }
  .el-input:focus {
    border-color: none;
  }
  i {
    cursor: pointer;
    width: 28px;
    height: 28px;
    display: inline-block;
    position: absolute;
    left: 32px;
    bottom: 32px;
    background: url('../assets/back.png') no-repeat center center;
    background-size: 28px 28px;
  }
  p {
    text-align: left;
    border: 1px solid #DCDEE6;
    border-radius: 6px;
    box-sizing: border-box;
    padding: 0px 10px;
  }
  .detail-content {
    height: 300px;
    overflow-wrap: break-word;
    overflow-y: auto;
    cursor: default;
    &::-webkit-scrollbar {
      display: none;
    }
  }
}
</style>