index.vue 11.1 KB
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 104 105 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 142 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 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403
<template>
  <div v-loading="loading" class="email email-container">
    <div class="email-aside">
      <div class="email-account">
        <div class="email-account__left">
          <div v-if="hasAccount == '0'" class="emial-setting">
            <div class="tips">暂未配置邮箱账号,请先进行邮箱配置</div>
            <div class="setting" @click="showMailSetting">
              <i class="icon-youxiangpeizhi mail-icon" />
              邮箱配置
            </div>
          </div>
          <el-select v-else v-model="emailAccount" @change="accountChange">
            <el-option
              v-for="item in accountList"
              :key="item.id"
              :label="item.mail"
              :value="item.mail"
            ></el-option>
          </el-select>
        </div>
        <i
          v-if="hasAccount == '1'"
          class="el-icon-setting"
          @click="showMailSetting"
        ></i>
      </div>

      <div v-if="hasAccount == '1'" class="aside-bottom">
        <div class="btn-group">
          <el-button
            v-for="btn in btnList"
            :key="btn.value"
            :icon="btn.icon"
            :class="{ active: activeTab == btn.value }"
            size="small"
            @click="getCurrentTab(btn.value)"
          >
            {{ btn.label }}
          </el-button>
        </div>

        <div class="aside-content">
          <div v-show="activeTab == 'mail-edit'"></div>
          <div v-show="activeTab == 'mail-content'">
            <div
              :class="['all-email', { 'item-active': itemActive == 'all' }]"
              @click="handleClickAll"
            >
              <div>
                <i class="iconfont icon-quanbuyoujian"></i>
                <span>全部邮件</span>
              </div>

              <el-button size="mini" @click.stop="setSyncMail">
                同步邮件
              </el-button>
            </div>

            <div class="email-container">
              <div
                v-for="mail in mailReceiver"
                :key="mail.id"
                :class="['item', { 'item-active': itemActive == mail.id }]"
                @click="handleClick(mail)"
              >
                <i :class="mail.classIcon"></i>
                <span>{{ mail.nickName }}</span>
              </div>
            </div>
          </div>

          <div v-show="activeTab == 'mail-contacts'"></div>
        </div>
      </div>
    </div>

    <div class="email-content">
      <template v-if="hasAccount == '1'">
        <component
          :is="activeComponent"
          :mail-item="mailItem"
          :current-mail="currentMail"
          :account-list="accountList"
          :reply-mail-detail="replyMailDetail"
          @reply-mail="replyMail"
          @update-mail="updateMail"
        />
      </template>

      <template v-if="hasAccount == '0'">
        <div class="email-empty">
          <img src="@/assets/personal_images/email-empty.png" />
          <div class="tips">暂无邮件哦</div>
        </div>
      </template>
    </div>
    <mail-setting-list :mail-list-visible.sync="mailListVisible" />
  </div>
</template>

<script>
  import { getMailTreeList, getSysncById } from '@/api/personal'
  import MailEdit from './components/MailEdit'
  import MailContent from './components/MailContent'
  import MailContacts from './components/MailContacts'
  import MailSettingList from './components/MailSettingList'
  export default {
    name: 'EmailCenter',
    components: {
      MailEdit,
      MailContent,
      MailContacts,
      MailSettingList,
    },
    data() {
      return {
        mailItem: null,
        currentMail: null,
        itemActive: 'all',
        itemActiveName: '',
        searchKey: '',
        activeTab: 'mail-content',
        hasAccount: '',
        mailListVisible: false,
        emailAccount: '',
        emailAccountId: '',
        replyMailDetail: null,

        activeComponent: 'mail-content',

        allAcountData: [],
        accountList: [],
        mailReceiver: [],

        btnList: [
          { label: '写信', value: 'mail-edit', icon: 'el-icon-edit' },
          { label: '收信箱', value: 'mail-content', icon: 'el-icon-receiving' },
          { label: '通讯录', value: 'mail-contacts', icon: 'el-icon-user' },
        ],
      }
    },
    watch: {
      mailListVisible: {
        handler(val) {
          if (!val) {
            this._getMailTreeList()
          }
        },
        immediate: true,
      },
    },
    methods: {
      showMailSetting() {
        this.mailListVisible = true
      },
      handleClick(mailItem) {
        this.mailItem = mailItem
        this.itemActive = mailItem.id
        this.itemActiveName = mailItem.nickName.substring(0, 3)
      },
      handleClickAll() {
        this.mailItem = null
        this.itemActive = 'all'
      },
      getCurrentTab(value) {
        this.activeTab = value
        this.activeComponent = value
      },
      replyMail(mailDetail) {
        this.replyMailDetail = mailDetail
        this.activeTab = 'mail-edit'
        this.activeComponent = 'mail-edit'
      },
      updateMail(payload) {
        this._getMailTreeList()
        if (payload == 'mailEdit') {
          this.activeTab = 'mail-content'
          this.activeComponent = 'mail-content'
        }
      },
      // 同步邮件
      setSyncMail() {
        const { id } = this.currentMail
        if (!id) {
          return
        }
        this.$message.warning('收信中,请稍候...')
        getSysncById(id).then((data) => {
          if (data.state) {
            this._getMailTreeList()
            this.$message.success(data.message)
          } else {
            this.$message.error(data.message)
          }
        })
      },
      accountChange(val) {
        this.mailItem = null
        this.itemActive = 'all'
        this.itemActiveName = ''
        const tempA = this.allAcountData.filter(
          (item) => item.mailAddress == val
        )
        if (tempA && tempA.length) {
          this.currentMail = tempA[0]
          this.mailReceiver = this.setCurrentMail(tempA[0].children)
        }
      },
      _getMailTreeList() {
        this.loading = true
        getMailTreeList().then((data) => {
          if (data && data.length) {
            this.hasAccount = '1'
            this.accountList = []
            this.allAcountData = data
            let hasDefaultMail = false
            data.forEach((item) => {
              this.accountList.push({
                id: item.id,
                mail: item.mailAddress,
              })
              if (item.mailAddress === this.emailAccount) {
                this.setMailInfo(item)
              }
              if (item.isDefault) {
                hasDefaultMail = true
                this.setMailInfo(item)
              }
            })

            if (!hasDefaultMail && !this.emailAccount) {
              this.setMailInfo(data[0])
            }
          } else {
            this.hasAccount = '0'
          }
        })
        this.loading = false
      },
      setMailInfo(item) {
        this.currentMail = item
        this.mailReceiver = this.setCurrentMail(item.children)
        this.emailAccountId = item.id
        this.emailAccount = item.mailAddress
      },
      setCurrentMail(list) {
        list.forEach((item) => {
          const nickName = item.nickName.substring(0, 3)
          if (nickName == '收件箱') {
            item.classIcon = 'iconfont icon-shoujianxiang'
          }
          if (nickName == '发件箱') {
            item.classIcon = 'iconfont icon-yifasong'
          }
          if (nickName == '草稿箱') {
            item.classIcon = 'iconfont icon-caogao'
          }
          if (nickName == '垃圾箱') {
            item.classIcon = 'iconfont icon-lajiyoujian'
          }
          if (this.itemActiveName == nickName) {
            this.itemActive = item.id
          }
        })
        return list
      },
    },
  }
</script>

<style lang="scss" scoped>
  .email {
    width: 100%;
    height: 100%;
    display: flex;
    background: var(--background) !important;
    .mail-icon {
      padding-right: 4px;
    }

    .email-aside {
      width: 300px;
      height: 100%;
      border-right: 1px solid #e6e6e6;
      background: #fff;
      .email-account {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 20px 10px;
        .email-account__left {
          width: 100%;
          .emial-setting {
            display: flex;
            align-items: center;
            flex-direction: column;
            justify-content: center;
            .tips {
              color: #333;
              font-size: $base-font-size-big;
            }
            .setting {
              width: 160px;
              color: #fff;
              font-size: $base-font-size-default;
              text-align: center;
              padding: 10px 0;
              margin-top: 24px;
              border-radius: 2px;
              background: var(--themeColor);
              cursor: pointer;
            }
          }
        }
        i {
          font-size: $base-font-size-big;
          cursor: pointer;
        }
      }
      .aside-bottom {
        padding: 0 10px;
        .btn-group {
          width: 100% !important;
          display: flex;
          .el-button {
            flex: 1;
          }
          .el-button--small {
            padding: 9px 10px;
          }
          .active {
            color: var(--themeColor);
            border: 1px solid var(--themeColor);
          }
        }
        .aside-content {
          margin: 20px 0;
          color: $base-font-color;
          i {
            display: inline-block;
            width: 20px;
            text-align: center;
            font-size: $base-font-size-default;
            margin-right: 3px;
          }
          .item-active {
            color: #2e5ee2;
            background: rgba(47, 97, 235, 0.26);
          }
          .all-email {
            height: 38px;
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 2px 5px;
            cursor: pointer;
            border-radius: 4px;
            .el-icon-box {
              color: #f2b140;
            }
            span {
              font-weight: bold;
            }
          }
          .email-container {
            padding: 5px 0;
            .item {
              height: 38px;
              line-height: 38px;
              padding: 0 27px;
              cursor: pointer;
              border-radius: 4px;
            }
          }
        }
      }
    }

    .email-content {
      width: calc(100% - 340px);
      height: calc(
        100vh - #{$base-top-bar-height} - #{$base-tabs-bar-height} - #{$base-content-margin} *
          2 - 40px
      );
      overflow-y: auto;
      padding: 20px;
      background: linear-gradient(180deg, #fff 0%, #fff 100%);

      .email-empty {
        height: 100%;
        display: flex;
        align-items: center;
        flex-direction: column;
        justify-content: center;
        .tips {
          color: #333;
          font-size: $base-font-size-big;
        }
      }
    }
  }
</style>