Skip to content

MessageBox

Used for displaying empty data state.

Basic Usage

Simply insert content using the default slot.

<template>
  <div>
    <b-button
      type="primary"
      @click="alert({ type: 'info', title: 'Title', message: 'This is the dialog content.', width: '500px' })"
    >
      Info
    </b-button>
    <b-button
      type="success"
      @click="alert({ type: 'success', title: 'Title', message: 'This is the dialog content.' })"
    >
      Success
    </b-button>
    <b-button
      type="warning"
      @click="alert({ type: 'warning', title: 'Title', message: 'This is the dialog content.' })"
    >
      Warning
    </b-button>
    <b-button type="danger" @click="showAlert">Error</b-button>
  </div>
</template>

<script setup lang="ts">
import { MessageBox, Message } from 'bin-ui-design'

function alert(opt) {
  MessageBox.alert(opt)
}

function showAlert() {
  MessageBox.alert({
    type: 'error',
    title: 'Title',
    message: 'This is the dialog content.',
    callback: action => {
      Message({
        type: 'info',
        message: `action: ${action}`
      })
    }
  })
}
</script>

Confirm Dialog

Simulate a confirm dialog for submit actions.

<template>
  <div>
    <b-button type="default" @click="open">Openconfirm</b-button>
  </div>
</template>

<script setup lang="ts">
import { MessageBox, Message } from 'bin-ui-design'

function open() {
  MessageBox.confirm({
    type: 'warning',
    title: 'Warning',
    message: '<p>此Actions将永久<span style="color:red;">Delete</span>该文件, 是否继续?</p>',
    useHTML: true
  })
    .then(() => {
      Message({ type: 'success', message: 'DeleteSuccess!' })
    })
    .catch(() => {
      Message({ type: 'info', message: '已CancelDelete' })
    })
}
</script>

Custom

Content can be customized.

<template>
  <div>
    <b-button type="default" @click="open">OpenMessageBox</b-button>
  </div>
</template>

<script setup lang="ts">
import { MessageBox, Message } from 'bin-ui-design'
import { h } from 'vue'

function open() {
  MessageBox.confirm({
    title: 'Message',
    message: h('p', null, [
      h('span', null, 'Content can be '),
      h('i', { style: 'color: teal' }, 'VNode')
    ]),
    showCancelButton: true,
    confirmText: 'OK',
    cancelText: 'Cancel',
    beforeClose: (action, instance, done) => {
      if (action === 'confirm') {
        instance.confirmButtonLoading = true
        instance.confirmText = '执Row中... , 三SecondClose'
        setTimeout(() => {
          done()
          setTimeout(() => {
            instance.confirmButtonLoading = false
          }, 300)
        }, 3000)
      } else {
        done()
      }
    }
  })
    .then(action => {
      Message({
        type: 'info',
        message: 'action: ' + action
      })
    })
    .catch(() => {
      Message({ type: 'info', message: 'Cancel' })
    })
}
</script>

API

In Vue 3, import the Message function and call it. The parameter can be a string or a CreateMessageProps object. For convenience, four type-specific call methods are also provided.

ts
import { MessageBox } from 'bin-ui-design'

// Options can be passed as a string. If a string is provided, it uses the default configuration and fills the message property.
MessageBox(options)
Message.alert(options)
Message.confirm(options)

Options

FunctionDescriptionTypeDefault
titleTitleString
messageContentString /Element String
typeType, used to show icons: info, success, warning, errorString
useHTMLWhether to use HTML contentBooleanfalse
iconClassReplace icon name (without prefix)String
callbackCallback function. If not using Promise, it can be specified via the parameter. The parameter is action, with values 'confirm' or 'cancel'Function
beforeCloseCallback before closing. Pauses the instance. action can be 'confirm' or 'cancel'Stringcancel
showCancelButtonWhether to show cancelbuttonBooleanfalse
scrollableWhether the page can scrollBooleanfalse
showConfirmButtonWhether to show the confirm buttonBooleantrue
cancelTextCancel button textStringcancel
confirmTextConfirm button textStringConfirm
maskClosableWhether clicking the mask closes the dialogBooleantrue, false for alert
escClosableWhether pressing ESC closes the dialogBooleantrue, false for alert