使用用例

基本使用

<template>
  <GButton class="w-200 mg-10" type="shrink" icon="round" balance @click="visible = true">打开弹窗</GButton>
  <GModal :visible="visible" @close="visible = false" title="标题" :ok="{ text: 'confirm', disable: true}" :cancel="{ text: 'cancel' }">
    <div style="color: var(--blank-white); font-size: 25px;">
      通过`visible`控制弹窗显示与隐藏
      <br />
      '@close' 会在点击 × 或者开启遮罩层关闭后执行, mask默认开启
      <br />
      通过 ok、cancel 配置按钮,不配置则不显示按钮, 可以进行单个配置,优先级高于统一配置,见类型定义
    </div>
  </GModal>
</template>
<script setup>
  import { ref } from 'vue'
  const visible = ref(false)
</script>

嵌套使用

组件内部维护了一个层级表,保证后者能够位于前者之上。可以使用zIndex属性指定一个层级表
<template>
  <GButton class="w-200 mg-10" type="shrink" icon="round" balance @click="visible = true">打开弹窗</GButton>
  <GModal :visible="visible" @close="visible = false">
    <GButton class="w-200 mg-10" type="shrink" icon="round" balance @click="visible2 = true">打开弹窗2</GButton>
  </GModal>

  <GModal :visible="visible2" @close="visible2 = false">
    <div style="color: var(--blank-white); font-size: 25px;">
      弹窗二号
      <br />
      组件内部维护了一个层级表,保证后者能够位于前者之上。可以使用zIndex属性指定一个层级表
    </div>
  </GModal>
</template>
<script setup>
  import { ref } from 'vue'
  const visible = ref(false)
  const visible2 = ref(false)
</script>

内置主题

内置了lightdark两种主题,可以通过theme属性进行配置; light主题下,无法使用关闭按钮(还原游戏内容)
<template>
  <GButton class="w-200 mg-10" type="shrink" icon="round" balance @click="() => {theme = 'dark'; visible = true}">Dark</GButton>
  <GButton class="w-200 mg-10" type="shrink" icon="round" balance @click="() => {theme = 'light'; visible = true}">Light</GButton>
  <GModal :visible="visible" @close="visible = false" :theme="theme" okText="确认" cancelText="取消">
   
  </GModal>
</template>
<script setup>
  import { ref } from 'vue'
  const visible = ref(false)
  const theme = ref('dark')
</script>

函数式调用

函数式调用 默认关闭mask
<template>
  <GButton class="w-200 mg-10" type="shrink" icon="round" balance @click="() => callModal('dark')">Dark</GButton>
  <GButton class="w-200 mg-10" type="shrink" icon="round" balance @click="() => callModal('light')">Light</GButton>

</template>
<script setup>
  import { ModalFunc } from '@shi-zhong/genshin-ui'

  const callModal = (theme) => {
    ModalFunc({
      title: '标题',
      text: '正文默认居中',
      theme,
      mask: true,
      okText: '确认',
    })
  }

</script>

类型定义


interface ModalButtonConfig {
  text?: string
  icon?: string
  disable?: boolean
}

interface ModalOptionProps {
  title?: string
  text?: string
  mask?: boolean
  theme?: 'dark' | 'light'
  ok?: ModalButtonConfig
  cancel?: ModalButtonConfig
}

interface ModalCallback {
  onOk?: () => void
  onCancel?: () => void
  onClose?: () => void
}

type ModalFunc = (option?: ModalOptionProps, callback?: ModalCallback) => void

参数定义

参数说明类型是否可选默认值
visible是否显示boolean必须false
theme主题'dark' | 'light'可选dark
title标题string可选Title
okText确认按钮文字string可选Confirm
okIcon确认按钮图标string可选round
okDisable确认按钮是否禁用boolean可选false
cancelText取消按钮文字string可选Cancel
cancelIcon取消按钮图标string可选fork
cancelDisable取消按钮是否禁用boolean可选false
ok确认按钮总配置ModalButtonConfig可选-
cancel取消按钮总配置ModalButtonConfig可选-
mask是否启用遮罩层关闭boolean可选true
zIndex面板层级number可选Auto

事件说明

事件名说明回调参数
close关闭触发() => void
cancel取消触发() => void
ok确认触发() => void
Last Updated:
Contributors: shi-zhong