This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
cyber-narrator-cn-ui/src/components/common/Error.vue

155 lines
4.7 KiB
Vue
Raw Normal View History

2022-11-18 15:18:05 +08:00
<template>
2023-03-16 19:07:37 +08:00
<div v-if="showDefault" class="error-component" :style="style" :class="class">
2022-11-21 17:31:30 +08:00
<div class="error-block" :style="{'max-width': localMaxWidth, 'width': localWidth}">
<svg class="icon error-icon-default" aria-hidden="true">
2022-11-21 17:31:30 +08:00
<use xlink:href="#cn-icon-baocuo"></use>
</svg>
{{ content }}
</div>
</div>
<div id="error-com">
<div v-if="tooltip !== undefined">
2022-11-18 15:18:05 +08:00
<el-popover
:width="localPopoverWidth"
placement="top-start"
trigger="hover"
:visible-arrow="false"
2022-11-18 16:59:37 +08:00
popper-class="error-popover"
2022-11-18 15:18:05 +08:00
:content="content">
<template #reference>
<span>
<svg class="icon error-icon-tooltip" aria-hidden="true">
2022-11-18 15:18:05 +08:00
<use xlink:href="#cn-icon-baocuo"></use>
</svg>
2022-11-18 16:59:37 +08:00
<!-- 为后续自定义icon插槽做预备-->
<!-- <i v-if="icon" :class="`icon cn-icon-${icon}`"></i>-->
2022-11-18 15:18:05 +08:00
</span>
</template>
</el-popover>
<!-- 不使用popover实现hover后续考虑替换为该方案-->
<!-- <span class="new-error-icon" @mouseenter="hoverError">-->
<!-- <svg class="icon item-popover-up" aria-hidden="true">-->
<!-- <use xlink:href="#cn-icon-baocuo"></use>-->
<!-- </svg>-->
<!-- <div id="error-content" class="error-content">-->
<!-- rview/appCompanyCyclrview/appCompanyCycleTrafficTotal?startTime=getSecond(this.timeFilter.startTime)&endTime=getSecond(this.timeFilter.endTime)&appCompanies=%27Tencent%27,%27Jingdong%27,%27Akamai%27,%27Bytedance%27,%27Baidu%27,%27Huawei%27,%27Beike%27,%27Aiqiyi%27,%27Ctrip%27,%27Meituan%27-->
<!-- </div>-->
<!-- </span>-->
</div>
2022-11-21 17:31:30 +08:00
<div class="error-block-info" v-if="info !== undefined">
<div>
<svg class="icon error-icon-default" aria-hidden="true">
2022-11-18 15:18:05 +08:00
<use xlink:href="#cn-icon-baocuo"></use>
</svg>
{{ content }}
</div>
</div>
</div>
</template>
2022-11-18 16:59:37 +08:00
<!-- start----------------调用方式----------------start -->
<!--
组件在全局注册了调用时: <chart-error :content="content"></chart-error>
-->
<!--
2022-11-21 17:31:30 +08:00
目前有三种形式分别是defaulttooltipinfo
默认即红框展示<chart-error :content="content" />
在标题之后显示需要鼠标移动到图标上显示弹窗<chart-error tooltip :content="content" />
文字提示<chart-error info :content="content" />
2022-11-18 16:59:37 +08:00
-->
<!--
自定义宽度<chart-error width="300" :content="content" />
2022-11-21 17:31:30 +08:00
自定义弹窗宽度<chart-error tooltip width="300" :content="content" />
注意info模式不支持宽度设置
2022-11-18 16:59:37 +08:00
-->
<!--
2022-11-21 17:31:30 +08:00
自定义icon图标<chart-error tooltip icon="baocuo" :content="content" />此时icon全称为'cn-icon-baocuo'
2022-11-18 16:59:37 +08:00
-->
<!-- end----------------调用方式----------------end -->
2022-11-18 15:18:05 +08:00
<script>
export default {
name: 'Error',
props: {
2022-11-21 17:31:30 +08:00
// 工具栏提示类型
tooltip: {
type: String
},
// 文字提示类型
info: {
2022-11-18 15:18:05 +08:00
type: String
},
2022-11-18 16:59:37 +08:00
// 报错信息内容,如果不传,默认为"Error"
2022-11-18 15:18:05 +08:00
content: {
type: String,
default: 'Error'
},
2022-11-21 17:31:30 +08:00
// 报错信息模块宽度如果类型选择tooltip则为弹窗宽度info模式没有宽度设置
2022-11-18 15:18:05 +08:00
width: {
type: String
},
2022-11-18 16:59:37 +08:00
// 报错信息模块最大宽度
2022-11-18 15:18:05 +08:00
maxWidth: {
2022-11-21 17:31:30 +08:00
type: String
// default: '350'
2022-11-18 15:18:05 +08:00
},
2022-11-18 16:59:37 +08:00
// 自定义icon图标
2022-11-18 15:18:05 +08:00
icon: {
type: String
},
2022-11-18 16:59:37 +08:00
// 自定义svg图标
2022-11-18 15:18:05 +08:00
svg: {
type: String
2023-03-16 19:07:37 +08:00
},
style: {
type: String
},
class: {
type: String
2022-11-18 15:18:05 +08:00
}
},
data () {
return {
2022-11-21 17:31:30 +08:00
showDefault: false, // 是否显示default分别是default、tooltip、info
2022-11-18 15:18:05 +08:00
showSmall: false, // 显示错误的类型true为图表模块内显示报错false为标题后显示报错
localWidth: '',
localMaxWidth: '',
2022-11-21 17:31:30 +08:00
localPopoverWidth: ''
2022-11-18 15:18:05 +08:00
}
},
mounted () {
this.initData()
},
methods: {
initData () {
2022-11-21 17:31:30 +08:00
if (this.tooltip !== undefined) {
this.showDefault = false
2022-11-18 15:18:05 +08:00
this.localPopoverWidth = this.width !== undefined
2022-11-21 17:31:30 +08:00
}
// 默认default模式
this.showDefault = this.tooltip === undefined && this.info === undefined
2022-11-18 15:18:05 +08:00
if (this.width) {
2022-11-18 16:59:37 +08:00
// 避免宽度出现负数的情况
2022-11-18 15:18:05 +08:00
this.localWidth = Math.abs(parseFloat(this.width)) + 'px'
}
if (this.maxWidth) {
2022-11-18 16:59:37 +08:00
// 避免宽度出现负数的情况
2022-11-18 15:18:05 +08:00
this.localMaxWidth = Math.abs(parseFloat(this.maxWidth)) + 'px'
}
},
/**
* 鼠标移入事件用于获取弹窗dom修改距离父元素的top
*/
hoverError (e) {
// const dom = document.getElementById('error-content')
// if (dom) {
// }
}
}
}
</script>