uni-im-info-card.vue 5.2 KB
Newer Older
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
<template>
  <view class="info-card" :class="{link}" @click="$emit('click')">
    <slot name="left"></slot>
    <view class="avatar-box">
      <image class="avatar" :src="avatarUrl" mode="widthFix"></image>
      <slot name="avatar-overlay-list"></slot>
    </view>
    <view class="main">
      <view class="row">
        <text class="title">{{title}}</text>
        <view class="tag-box">
          <view class="tag" v-for="(tag,index) in tags" :key="tag">{{tag}}</view>
        </view>
        <view class="time" v-if="time">{{time}}</view>
      </view>
      <view class="row">
        <view class="note-box">
          <text class="red-note">{{redNote}}</text>
          <text class="note">{{note}}</text>
        </view>
        <view class="state">
          <image v-if="mute" class="mute" mode="widthFix" src="@/uni_modules/uni-im/static/mute.png">
          </image>
          <template v-if="badge">
            <view v-if="mute" class="red-point"></view>
            <view v-else class="badge">{{badge > 99 ? '99+' : badge}}</view>
          </template>
        </view>
      </view>
    </view>
    <image v-if="pinned" class="pinned" mode="widthFix" src="@/uni_modules/uni-im/static/pinned.png">
    </image>
    <slot></slot>
    <slot name="right"></slot>
  </view>
</template>

<script>
  export default {
    emits: ['click'],
    props: {
      avatarUrl: {
        type: String,
        default: '/uni_modules/uni-im/static/avatarUrl.png'
      },
      title: {
        type: String,
        default: ''
      },
      tags: {
        type: Array,
        default: () => []
      },
      time: {
        type: String,
        default: ''
      },
      note: {
        type: String,
        default: ''
      },
      badge: {
        type: Number,
        default: 0
      },
      mute: {
        type: Boolean,
        default: false
      },
      pinned: {
        type: Boolean,
        default: false
      },
      redNote: {
        type: String,
        default: ''
      },
      link: {
        type: Boolean,
        default: false
      }
    },
    computed: {
    },
    data() {
      return {

      }
    },
    methods: {}
  }
</script>

94
<style lang="scss">
95 96 97 98 99 100 101 102 103 104
  // 限制只能一行,超出显示省略号
  @mixin ellipsis {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .info-card {
    position: relative;
    padding:10px 12px;
    flex-direction: row;
DCloud_JSON's avatar
DCloud_JSON 已提交
105
    &::after {
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
      content: "";
      position: absolute;
      left: 50px;
      right: 0;
      bottom: 0;
      height: 1px;
      transform: scaleY(0.1);
      background-color: #eee;
    }
    /* #ifdef H5 */
    @media screen and (min-device-width:960px){
      ::after {
        display: none;
      }
    }
    &.link{
      cursor: pointer;
      &:hover {
        background-color: #f0f0f0;
      }
    }
    /* #endif */
    .avatar-box{
      position: relative;
      .avatar {
        width: 40px;
        height: 40px;
        border-radius: 5px;
        flex-shrink: 0;
      }
    }
    .main {
      flex-grow: 1;
      justify-content: center;
      overflow: hidden;
      margin-left: 5px;
DCloud_JSON's avatar
DCloud_JSON 已提交
142
      flex-shrink: 1;
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
      .row {
        flex-direction: row;
        align-items: center;
        // min-height: 20px;

        .title {
          font-size: 16px;
          color: #333;
          @include ellipsis;
        }

        .tag-box {
          transform: scale(0.8);
          margin-right: 5px;

          .tag {
            word-break: keep-all;
            font-size: 12px;
            color: #1a6dfe;
            border: 1px solid #1a6dfe;
            border-radius: 2px;
            padding: 0 2px;
          }
        }

        .time {
          // 不换行
          white-space: nowrap;
          font-size: 10px;
          color: #999;
          margin-left: auto;
        }

        .state {
          margin-left: auto;
          flex-direction: row;
          align-items: center;

          .red-point {
            width: 8px;
            height: 8px;
            background-color: #f00;
            border-radius: 50%;
            margin-left: 2px;
          }

          .mute {
            width: 13px;
            height: 13px;
            opacity: 0.7;
          }

          .badge {
            transform: scale(0.9);
            font-size: 12px;
            color: #fff;
            background-color: #f00;
            border-radius: 10px;
            min-width: 16px;
            min-height: 16px;
            padding: 0 5px;
            justify-content: center;
            align-items: center;
            margin:0 2px;
            align-self: flex-end;
          }
        }

        .note-box {
          flex-direction: row;
          overflow: hidden;
DCloud_JSON's avatar
DCloud_JSON 已提交
214 215
          align-items: center;
          flex-shrink: 1;
216 217 218 219 220 221 222

          .red-note {
            font-size: 12px;
            white-space: nowrap;
            color: #f00;
          }

DCloud_JSON's avatar
DCloud_JSON 已提交
223
          .note {
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
            font-size: 14px;
            color: #aaa;
            @include ellipsis;
          }
        }
      }
    }

    .pinned {
      position: absolute;
      right: 3px;
      top: 3px;
      width: 8px;
      height: 8px;
    }
  }
</style>