noticeList.vue 2.88 KB
<template>
    <div class = "noticeList">
      <setting v-on:settingchanged="reload"></setting>
        <ul>
          <li class = "item">
            <a><div class = "title">아무 제목이나 써보았습니다.</div></a>
              <div class = "noticeInfo">
                <span class = "site sw" >SW융합</span>
                <span class = "date">2020-20-03</span>
              </div>
          </li>
          <li class = "item" v-for="notice in noticeList" :key="notice">
            <a v-bind:href="notice.link" target="_blank"><div class = "title">{{notice.title}}</div></a>
              <div class = "noticeInfo">
                <span class = "site khu" v-if="notice.site == '경희대학교 공지사항'">경희대</span>
                <span class = "site sw" v-else-if="notice.site == '소프트웨어 융합대학 공지사항'">SW융합</span>
                <span class = "site janghak" v-else-if="notice.site == '경희대학교 장학센터'">장학센터</span>
                <span class = "date">{{notice.date}}</span>
              </div>
          </li>
        </ul>
    </div>
</template>

<script>
import axios from 'axios'
import setting from './setting'

export default {
  el: '.noticeList',
  components: {
    'setting': setting
  },
  data () {
    return {
      noticeList: [],
      sql: 'select title,link,date_format(date,"%Y-%m-%d") as date,site from noticeList order by date desc',
      basic: 'select title,link,date_format(date,"%Y-%m-%d") as date,site from noticeList'
    }
  },
  created () {
    this.fetchNoticeList()
  },
  methods: {
    fetchNoticeList () {
      axios
        .post('/api/fetchNoticeList', {
          sql: this.sql
        })
        .then((noticeList) => {
          this.noticeList = noticeList.data
        })
    },
    reload (setting) {
      var sql = this.basic
      sql += ' where 0'
      setting.forEach(function (item) {
        if (item.seen === true) {
          sql += ' or site = ' + '\'' + item.official + '\''
        }
      })
      this.sql = sql + ' order by date desc'
      this.fetchNoticeList()
    }
  }
}
</script>

<style>
  .noticeList{
    width: 1010px;
    background: rgb(249,249,249);
  }
  ul{
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 0 auto 10px auto;
  }
  li{
    margin-bottom:2px;
  }
  .item{
    background: white;
    height: 32px;
    display: flex;
    position: relative;
    padding: 6px 15px 18px;
    width: 960px;
    border-radius:5px;
  }
  .title{
    font-size:15px;
  }
  a{
    color: #34495e;

  }
  a:visited{
    color: grey;
  }
  .noticeInfo{
    position: absolute;
    bottom:12px;
    font-size:12px;
  }
  .date{
    color: grey;
  }
  .site{
    color: white;
    font-size:10px;
    padding: 2px 10px;
  }
  .khu{
    background-color: #C0392B;
  }
  .sw{
    background-color: #3498DB;
  }
  .janghak{
    background-color: #632300;
  }
</style>