MyCustomModule.vue 2.25 KB
<template>
  <div
    v-if="module"
    class="my-custom-module-com"
    @mouseenter="showDelete = true"
    @mouseleave="showDelete = false"
  >
    <component
      :is="componentName"
      :module="module"
    />
    <div :class="['delete-box', showDelete && 'show']">
      <img src="/images/navagations/delete-icon.png" alt="" @click.stop="remove">
    </div>
  </div>
</template>

<script>
import { unCollectUserModel } from '@/api/usercenter.js'
export default {
  props: {
    module: {
      type: Object,
      default() {
        return null
      }
    }
  },
  data() {
    return {
      showDelete: false,
      componentName: null
    }
  },
  watch: {
    module: {
      handler: async function(val) {
        this.componentName = await this.$utils.loadComponent(val.serverName, val.condPath, 'view')
      },
      immediate: true
    }
  },
  methods: {
    remove() {
      this.$utils.showConfirm(
        '是否删除选中的定制模块?',
        '提示',
        'warning',
        '确定',
        '取消',
        () => {
          unCollectUserModel(this.module.code).then(res => {
            this.$utils.showMessageSuccess('删除成功')
            this.$emit('getUserModule')
          })
        }
      )
    }
  }
}
</script>

<style lang="scss">
.my-custom-module-com {
  position: relative;
  overflow: hidden;
  border-radius: 4px;
  .custom-module-bottom {
    display: flex;
    align-items: center;
    color: #6f6f6f;
    font-size: 14px;
    .custom-module-bottom-item {
      flex: 1;
      display: flex;
      align-items: center;
      border-right: 1px solid #6f6f6f;
      padding: 0 10px;
      box-sizing: border-box;
      &:last-child {
        border-right: none;
      }
      .custom-module-bottom-item-name {
        margin-right: 4px;
        white-space: nowrap;
      }
    }
  }
  .delete-box {
    position: absolute;
    bottom: -32px;
    left: 0;
    width: 100%;
    height: 32px;
    // background-color: rgba(5, 65, 110, 0.5);
    transition: bottom 0.3s;
    padding-right: 10px;
    box-sizing: border-box;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    &.show {
      bottom: 0;
      transition: bottom 0.3s;
    }
    img {
      height: 18px;
      cursor: pointer;
    }
  }
}
</style>