feat: xbutton

This commit is contained in:
xingyu4j
2022-11-04 18:01:46 +08:00
parent d79b23c8a2
commit bca13b1961
6 changed files with 75 additions and 43 deletions

View File

@ -0,0 +1,3 @@
import XButton from './src/XButton.vue'
export { XButton }

View File

@ -0,0 +1,41 @@
<script setup lang="ts">
import { propTypes } from '@/utils/propTypes'
import { computed, useAttrs, PropType } from 'vue'
import { useI18n } from '@/hooks/web/useI18n'
const { t } = useI18n() // 国际化
const props = defineProps({
modelValue: propTypes.bool.def(false),
loading: propTypes.bool.def(false),
preIcon: propTypes.string.def(''),
postIcon: propTypes.string.def(''),
iTitle: propTypes.string.def(''),
title: propTypes.string.def('按钮'),
type: propTypes.oneOf(['primary', 'success', 'warning', 'danger', 'info']).def('primary'),
link: propTypes.bool.def(false),
circle: propTypes.bool.def(false),
round: propTypes.bool.def(false),
plain: propTypes.bool.def(false),
onClick: { type: Function as PropType<(...args) => any>, default: null }
})
const getBindValue = computed(() => {
const delArr: string[] = ['title', 'preIcon', 'postIcon', 'onClick']
const attrs = useAttrs()
const obj = { ...attrs, ...props }
for (const key in obj) {
if (delArr.indexOf(key) !== -1) {
delete obj[key]
}
}
return obj
})
</script>
<template>
<el-button v-bind="getBindValue" @click="onClick">
<Icon :icon="preIcon" v-if="preIcon" class="mr-1px" />
{{ iTitle ? t(iTitle) : title }}
<Icon :icon="postIcon" v-if="postIcon" class="mr-1px" />
</el-button>
</template>

View File

@ -18,34 +18,14 @@ const props = defineProps({
})
const getBindValue = computed(() => {
const delArr: string[] = ['title']
const attrs = useAttrs()
const obj = { ...attrs, ...props }
for (const key in obj) {
if (delArr.indexOf(key) !== -1) {
delete obj[key]
}
}
return obj
})
</script>
<template>
<vxe-modal
v-bind="getBindValue"
:width="width"
:height="height"
:title="title"
min-width="460"
min-height="320"
:loading="loading"
:fullscreen="fullscreen"
destroy-on-close
show-zoom
resize
transfer
:show-footer="showFooter"
>
<vxe-modal v-bind="getBindValue" destroy-on-close show-zoom resize transfer>
<template v-if="slots.header" #header>
<slot name="header"></slot>
</template>

View File

@ -5,6 +5,7 @@ import { Table } from '@/components/Table'
import { Search } from '@/components/Search'
import { Dialog } from '@/components/Dialog'
import { XModal } from '@/components/XModal'
import { XButton } from '@/components/XButton'
import { DictTag } from '@/components/DictTag'
import { ContentWrap } from '@/components/ContentWrap'
import { Descriptions } from '@/components/Descriptions'
@ -16,6 +17,7 @@ export const setupGlobCom = (app: App<Element>): void => {
app.component('Search', Search)
app.component('Dialog', Dialog)
app.component('XModal', XModal)
app.component('XButton', XButton)
app.component('DictTag', DictTag)
app.component('ContentWrap', ContentWrap)
app.component('Descriptions', Descriptions)