Newer
Older
smartwell_front / src / layouts / components / Tools / alarmList.vue
<script lang="ts" setup name="AlarmList">
const messageList = ref<any[]>([])

setTimeout(() => {
  messageList.value = [
    {
      id: '1',
      title: '燃气浓度超限',
      device: '燃气智能监测终端',
      code: 'N57G215',
      alarmValue: '浓度12%vol',
      readStatus: '1',
      time: '2024-06-29 12:05:00',
      grade: '1',
    },
    {
      id: '2',
      title: '桩倾斜报警',
      device: '燃气智能监测终端',
      code: 'N57G215',
      alarmValue: '浓度12%vol',
      readStatus: '2',
      time: '2024-03-21 13:03:01',
      grade: '2',
    },
    {
      id: '3',
      title: '设备故障',
      device: '燃气智能监测终端',
      code: 'N57G215',
      alarmValue: '浓度12%vol',
      readStatus: '1',
      time: '2024-02-29 02:05:40',
      grade: '3',
    },
  ]
})
defineExpose({ messageList })
</script>

<template>
  <div class="message-container">
    <div v-show="messageList.length" class="message-title">
      报警({{ messageList.length }})
    </div>
    <el-scrollbar max-height="400px">
      <div v-if="!messageList.length">
        <el-empty :image-size="50" description="暂无报警" />
      </div>
      <template v-else>
        <div v-for="message of messageList" :key="message.id" class="message-item">
          <div class="message-content">
            <div class="title">
              <div class="container">
                <div :class="`mar circle circle-${message.grade}`">
                  1
                </div>
                <div class="mar">
                  {{ message.title }}
                </div>
                <div class="mar">
                  {{ message.time }}
                </div>
              </div>
              <div>
                <el-tag :type="message.readStatus === '1' ? 'success' : 'warning'" size="small">
                  {{ message.readStatus
                    === '1' ? '已读' : '未读' }}
                </el-tag>
                <el-tag type="info" size="small" style="margin-left: 5px;">
                  查看
                </el-tag>
              </div>
            </div>
            <div class="time">
              <div>
                {{ message.code }} | {{ message.device }} | {{ message.alarmValue }}
              </div>
            </div>
          </div>
        </div>
      </template>
    </el-scrollbar>
    <div v-if="messageList.length" class="message-footer">
      <div class="close">
        关闭声音
      </div>
      <div class="more">
        查看更多
      </div>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.message-container {
  width: 100%;
  padding: 0 5px;
  overflow-x: hidden;

  .message-title {
    width: 100%;
    text-align: center;
    padding-bottom: 10px;
    font-size: 14px;
    border-bottom: 1px solid #ddd;
  }

  .message-item {
    display: flex;
    align-items: center;
    border-bottom: 1px solid #ddd;
    padding: 8px 5px;
    cursor: pointer;

    &:hover {
      background-color: #f6f6f6;
    }

    .title {
      display: flex;
      font-size: 12px;

      // width: 70%;
      // display: flex;
      .container {
        align-items: center;
        width: 72%;
        display: flex;
        overflow: hidden;

        /* 确保超出的内容会被裁剪 */
        white-space: nowrap;

        /* 确保文本在一行内显示 */
        text-overflow: ellipsis;

        /* 超出的文本部分显示为省略号 */
      }

      .mar {
        margin: 0 5px;
      }
    }

    .circle {
      width: 12px;
      height: 12px;
      border-radius: 50%;
      color: transparent;
    }

    .circle-1 {
      background-color: #f56c6c;
    }

    .circle-2 {
      background-color: #ee9611;
    }

    .circle-3 {
      background-color: #ffd700;
    }

    .icon {
      width: 26px;
      height: 26px;
      margin-right: 10px;
      border-radius: 40px;
      color: #fff;
      background-color: var(--el-color-primary);
      padding: 4px;
    }

    .message-content {
      flex: 1;
      font-size: 14px;

      .time {
        margin-top: 3px;
        font-size: 12px;
        color: #888;
      }
    }
  }

  .message-footer {
    // margin-top: 10px;
    line-height: 2;
    text-align: center;
    cursor: pointer;
    display: flex;
    // justify-content: space-around;

    .close {
      border: 1px solid #ddd;
      border-right-color: transparent;
      border-top-color: transparent;
      flex: 1;
      width: 50%;

      &:hover {
        color: var(--el-color-primary);
      }
    }

    .more {
      // border-left: 0.5px solid #ddd;
      border: 1px solid #ddd;
      border-top-color: transparent;
      flex: 1;
      width: 50%;

      &:hover {
        color: var(--el-color-primary);
      }
    }
  }
}
</style>