TableTitle.vue 1.3 KB
Newer Older
陈文彬 已提交
1
<template>
V
vben 已提交
2 3
  <BasicTitle :class="prefixCls" v-if="getTitle" :helpMessage="helpMessage">
    {{ getTitle }}
陈文彬 已提交
4 5 6 7 8
  </BasicTitle>
</template>
<script lang="ts">
  import { computed, defineComponent, PropType } from 'vue';
  import { BasicTitle } from '/@/components/Basic/index';
V
vben 已提交
9
  import { useDesign } from '/@/hooks/web/useDesign';
陈文彬 已提交
10
  import { isFunction } from '/@/utils/is';
V
Vben 已提交
11

陈文彬 已提交
12
  export default defineComponent({
V
vben 已提交
13
    name: 'BasicTableTitle',
陈文彬 已提交
14 15 16
    components: { BasicTitle },
    props: {
      title: {
V
vben 已提交
17
        type: [Function, String] as PropType<string | ((data) => string)>,
陈文彬 已提交
18 19
      },
      getSelectRows: {
V
vben 已提交
20
        type: Function as PropType<() => any[]>,
陈文彬 已提交
21 22 23 24 25 26
      },
      helpMessage: {
        type: [String, Array] as PropType<string | string[]>,
      },
    },
    setup(props) {
V
vben 已提交
27 28 29
      const { prefixCls } = useDesign('basic-table-title');

      const getTitle = computed(() => {
陈文彬 已提交
30 31 32 33 34 35 36 37 38 39 40
        const { title, getSelectRows = () => {} } = props;
        let tit = title;

        if (isFunction(title)) {
          tit = title({
            selectRows: getSelectRows(),
          });
        }
        return tit;
      });

V
vben 已提交
41
      return { getTitle, prefixCls };
陈文彬 已提交
42 43 44
    },
  });
</script>
V
vben 已提交
45 46 47 48 49 50
<style lang="less">
  @prefix-cls: ~'@{namespace}-basic-table-title';

  .@{prefix-cls} {
    display: flex;
    align-items: center;
V
vben 已提交
51
    justify-content: space-between;
V
vben 已提交
52 53
  }
</style>