# message 告警提示组件 Beta

# 使用示例

默认

小尺寸长文字

大尺寸

全局调用

操作

<template>
  <div class="warning-tips-demo">
    <p>默认</p>
    <el-button :plain="true" @click="open1">告警提示-信息</el-button>
    <el-button :plain="true" @click="open2">告警信息-错误</el-button>
    <el-button :plain="true" @click="open3">告警提示-警告</el-button>
    <el-button :plain="true" @click="open4">告警提示-成功</el-button>
    <p>小尺寸长文字</p>
    <el-button :plain="true" @click="open5">告警-长文字提示-纯中文</el-button>
    <el-button :plain="true" @click="open7">告警-长文字提示-纯英文</el-button>
    <p>大尺寸</p>
    <el-button plain @click="open6">超长文本-信息</el-button>
    <el-button plain @click="open8">超长文本-错误</el-button>
    <el-button plain @click="open9">超长文本-告警</el-button>
    <el-button plain @click="open10">超长文本-成功</el-button>
    <p>全局调用</p>
    <el-button plain @click="open11">全局调用-信息</el-button>
    <el-button plain @click="open12">全局调用-警告</el-button>
    <el-button plain @click="open13">全局调用-错误</el-button>
    <el-button plain @click="open14">全局调用-成功</el-button>
    <p>操作</p>
    <el-button plain @click="open15">全局调用,关闭所有</el-button>
  </div>
</template>

<script>

  export default {
    name: 'warning-tips',
    methods: {
      open1() {
        this.$tips({
          title: '标题1',
          message: '您好,这是一条普通告警提示信息',
          duration: 2000,
          type: 'info',
          showClose: true,
        });
      },
      open2() {
        this.$tips({
          showClose: true,
          message: '您好,这是一条错误消息',
          type: 'error',
          duration: 2000,
        });
      },
      open3() {
        this.$tips({
          showClose: true,
          message: '您好,这是一条警告消息',
          type: 'warning',
          duration: 2000,
        });
      },
      open4() {
        this.$tips({
          showClose: true,
          message: '您好,这是一条成功消息',
          type: 'success',
          duration: 2000,
        });
      },
      open5() {
        this.$tips({
          showClose: true,
          duration: 2000,
          message:
            '系统将于进行升级,请及时保存你的资料!系统将于进行升级,请及时保存你的资料!系统将于!',
          type: 'warning',
        });
      },
      open6() {
        this.$tips({
          showClose: true,
          duration: 2000,
          type: 'info',
          message:
            '你的账户会员使用权限将在3天后到期,请及时跟进申请状况。如果有点问题,请联系审核人员去吧你的账户会员使用权限将在3天后到期,请及时跟进申请状况。如果有点问题,请联系审核人员去吧。',
        });
      },
      open8() {
        this.$tips({
          showClose: true,
          duration: 2000,
          type: 'error',
          message:
            '你的账户会员使用权限将在3天后到期,请及时跟进申请状况。如果有点问题,请联系审核人员去吧你的账户会员使用权限将在3天后到期,请及时跟进申请状况。如果有点问题,请联系审核人员去吧。',
        });
      },
      open9() {
        this.$tips({
          showClose: true,
          duration: 2000,
          type: 'warning',
          message:
            '你所提交的信息已经审核失败,可以进入个人信箱查看原因,如果有点疑问,请联系客服人员。谢谢',
        });
      },
      open10() {
        this.$tips({
          showClose: true,
          duration: 2000,
          type: 'success',
          message:
            '你所提交的信息已经审核通过,请及时跟进申请状况。如有问题,请联系审核人员或在线客服。谢谢',
        });
      },
      open11() {
        this.$tips.info(
          '你的账户会员使用权限将在3天后到期,请及时跟进申请状况。如果有点问题,请联系审核人员去吧你的账户会员使用权限将在3天后到期,请及时跟进申请状况。如果有点问题,请联系审核人员去吧。'
        );
      },
      open12() {
        this.$tips.warning(
          '你的账户会员使用权限将在3天后到期,请及时跟进申请状况。如果有点问题,请联系审核人员去吧你的账户会员使用权限将在3天后到期,请及时跟进申请状况。如果有点问题,请联系审核人员去吧。'
        );
      },
      open13() {
        this.$tips.error(
          '你的账户会员使用权限将在3天后到期,请及时跟进申请状况。如果有点问题,请联系审核人员去吧你的账户会员使用权限将在3天后到期,请及时跟进申请状况。如果有点问题,请联系审核人员去吧。'
        );
      },
      open14() {
        this.$tips.success(
          '你的账户会员使用权限将在3天后到期,请及时跟进申请状况。如果有点问题,请联系审核人员去吧你的账户会员使用权限将在3天后到期,请及时跟进申请状况。如果有点问题,请联系审核人员去吧。'
        );
      },
      open15() {
        this.$tips.closeAll();
      },
      open7() {
        this.$tips({
          showClose: true,
          duration: 2000,
          type: 'info',
          message:
            'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
        });
      },
    },
  };
</script>

<style scoped></style>

显示代码 复制代码

# Options

参数 必填 说明 类型 可选值 默认值
message 消息文字 string / VNode
type 主题 主题 string string / success/warning/info/error info
dangerouslyUseHTMLString 是否将 message 属性作为 HTML 片段处理 boolean false
duration 显示时间, 毫秒。设为 0 则不会自动关闭 number 3000
iconClass 自定义图标的类名,会覆盖 type string
showClose 是否显示关闭按钮 boolean false
center 文字是否居中 boolean false
onClose 关闭时的回调函数, 参数为被关闭的 YKcWarningTips 实例 function
offset YKcWarningTips 距离窗口顶部的偏移量 number 20

# 方法

调用 YKcWarningTipsthis.$tips 会返回当前 YKcWarningTips 的实例。 如果需要手动关闭实例,可以调用它的 close 方法。

方法名 说明
close 关闭当前的 YKcWarningTips

# 全局方法

YKC UI 为 · 添加了全局方法 $tips。因此在 vue instance 中可以采用本页面中的方式调用 YKcWarningTips

# 单独引入

单独引入 YKcWarningTips

import YKcWarningTips from '@ykc/ykc-ui/packages/warning-tips';

此时调用方法为 YKcWarningTips(options)。 我们也为每个 type 定义了各自的方法,如 YKcWarningTips.success(options)。 并且可以调用 YKcWarningTips.closeAll() 手动关闭所有实例。

# VNode 作为消息内容

<template>
  <el-button :plain="true" @click="open">打开消息提示</el-button>
  <el-button :plain="true" @click="openVn">VNode</el-button>
</template>

<script>
export default {
  methods: {
    open() {
      this.$tips('这是一条消息提示');
    },

    openVn() {
      const h = this.$createElement;
      this.$tips({
        message: h('p', null, [
          h('span', null, '内容可以是 '),
          h('i', { style: 'color: teal' }, 'VNode')
        ])
      });
    }
  }
}
</script>
显示代码 复制代码

# 使用 HTML 片段

message 属性支持传入 HTML 片段

<template>
  <el-button :plain="true" @click="openHTML">使用 HTML 片段</el-button>
</template>

<script>
  export default {
    methods: {
      openHTML() {
        this.$tips({
          dangerouslyUseHTMLString: true,
          message: '<strong>这是 <i>HTML</i> 片段</strong>'
        });
      }
    }
  }
</script>
显示代码 复制代码

!> message 属性虽然支持传入 HTML 片段,但是在网站上动态渲染任意 HTML 是非常危险的,因为容易导致 XSS 攻击。因此在 dangerouslyUseHTMLString 打开的情况下,请确保 message 的内容是可信的,永远不要将用户提交的内容赋值给 message 属性。

Last Updated: 2021/10/19 下午2:59:17