Skip to content

Dialog

提示弹窗

html

<pa-cell title="提示弹窗" is-link @click="onOpen()" />

<pa-dialog
  v-model:show="visible"
  title="提示"
  message="落霞与孤鹜齐飞,秋水共长天一色"
></pa-dialog>
ts

import { ref } from 'vue'

const visible = ref(false)

const onOpen = () => {
  visible.value = true
}

提示弹窗(无标题)

html

<pa-cell title="提示弹窗(无标题)" is-link @click="onOpen()" />

<pa-dialog v-model:show="visible" message="落霞与孤鹜齐飞,秋水共长天一色"></pa-dialog>
ts

import { ref } from 'vue'

const visible = ref(false)

const onOpen = () => {
  visible.value = true
}

确认弹窗

html

<pa-cell title="确认弹窗" is-link @click="onOpen()" />

<pa-dialog
  v-model:show="visible"
  title="提示"
  message="落霞与孤鹜齐飞,秋水共长天一色"
  show-cancel-button
></pa-dialog>
ts

import { ref } from 'vue'

const visible = ref(false)

const onOpen = () => {
  visible.value = true
}

圆角按钮样式

html

<pa-cell-group inset>
  <pa-cell title="提示弹窗" is-link @click="onOpen({ title: '提示' })" />
  <pa-cell title="提示弹窗(无标题)" is-link @click="onOpen()" />
  <pa-cell
    title="确认弹窗"
    is-link
    @click="
      onOpen({
        title: '标题',
        showCancelButton: true,
      })
    "
  />
</pa-cell-group>

<pa-dialog
  v-model:show="visible"
  theme="round-button"
  message="落霞与孤鹜齐飞,秋水共长天一色"
  v-bind="dialogProps"
></pa-dialog>
ts

import { ref } from 'vue'
import type { DialogProps } from '../../components/dialog/props'

const visible = ref(false)
const dialogProps = ref<Partial<DialogProps>>({})

const onOpen = (props: Partial<DialogProps> = {}) => {
  dialogProps.value = props
  visible.value = true
}

异步关闭

html

<pa-cell-group inset>
  <pa-cell title="异步关闭" is-link @click="onOpen()" />
</pa-cell-group>

<pa-dialog
  v-model:show="visible"
  title="提示"
  message="落霞与孤鹜齐飞,秋水共长天一色"
  show-cancel-button
  :close-on-click-overlay="false"
  :before-close="onBeforeClose"
/>
ts

import { ref } from 'vue'
import type { ActionType } from '../../components/dialog/props'

const visible = ref(false)

const onOpen = () => {
  visible.value = true
}

const onBeforeClose = (action: ActionType) => {
  if (action === 'confirm') {
    return new Promise<boolean>((resolve) => {
      setTimeout(() => {
        resolve(true)
      }, 1000)
    })
  } else {
    return true
  }
}

自定义内容

html

<pa-cell title="自定义内容" is-link @click="onOpen()" />

<pa-dialog v-model:show="visible" title="标题">
  <view class="flex flex-col items-center justify-center pt-20 pb-50">
    <view class="text-28 color-black-2">这是自定义内容</view>
    <image src="../../images/demo.jpeg" style="width: 80px; height: 80px" />
  </view>
</pa-dialog>
ts

import { ref } from 'vue'

const visible = ref(false)

const onOpen = () => {
  visible.value = true
}

自定义底部

html

<pa-cell title="自定义底部" is-link @click="onOpen()" />

<pa-dialog
  v-model:show="visible"
  title="标题"
  message="可以自定义底部,比如自定按钮,方便利用微信开放能力"
>
  <view class="flex flex-col items-center justify-center pt-20 pb-50 px-48">
    <view class="text-28 color-black-2">可以自定义底部,比如自定按钮,方便利用微信开放能力</view>
    <image v-if="avatarUrl" :src="avatarUrl" style="width: 80px; height: 80px" />
  </view>
  <template #footer>
    <view class="flex items-center justify-between pt-16 px-48 pb-32">
      <pa-button class="width-full block mr-32" type="default" block @click="onOpen(false)">
        取消
      </pa-button>
      <pa-button
        class="width-full block"
        block
        open-type="chooseAvatar"
        @chooseavatar="onChooseAvatar"
      >
        获取头像
      </pa-button>
    </view>
  </template>
</pa-dialog>
ts

import { ref } from 'vue'
import type { EventDetail } from '../../types'

const visible = ref(false)
const avatarUrl = ref<string>()

const onOpen = (show = true) => {
  visible.value = show
}

const onChooseAvatar = (e: EventDetail<{ avatarUrl: string }>) => {
  if (e.detail.avatarUrl) {
    avatarUrl.value = e.detail.avatarUrl
  }
}

Dialog Props

参数说明类型默认值
show是否显示弹窗boolean-
zIndexz-index层级number999
duration动画的执行时间,单位msstring | number300
overlay是否显示遮罩booleantrue
closeOnClickOverlay点击遮罩是否关闭弹窗booleantrue
overlayStyle自定义遮罩层样式CSSProperties-
title标题string-
width弹窗宽度,默认单位为pxstring | number320
message文本内容,支持通过\n换行string-
messageAlign内容对齐方式,可选值为left right'left'|'center'|'right'-
theme样式风格'default'|'round-button''default'
showConfirmButton是否显示确认按钮booleantrue
showCancelButton是否显示取消按钮boolean-
confirmButtonText确认按钮的文本string'确认'
cancelButtonText取消按钮的文本string'取消'
beforeClose关闭前的回调函数,返回 false 可阻止关闭,支持返回 Promise(action:ActionType)=>boolean|Promise<boolean>-

Dialog Event

事件名参数
confirm()
cancel()
update:show(value: PopupProps['show'])
open()
opened()
close()
closed()
clickOverlay()

Dialog Slot

名称说明
default-
footer-

样式变量

名称默认值
--pa-dialog-radius16px
--pa-dialog-header-padding-top26px
--pa-dialog-font-size16px
--pa-dialog-header-font-weight500
--pa-dialog-header-line-height24px
--pa-dialog-message-max-height60vh
--pa-dialog-message-padding26px 24px
--pa-dialog-message-font-size14px
--pa-dialog-message-line-height20px
--pa-dialog-button-height48px
--pa-dialog-round-button-height36px