search.vue 2.2 KB
<script setup lang="ts">
import { AnyObject } from "@/types/global";
import { Layout, LayoutContent, LayoutSider, Form, Space, Grid } from "@arco-design/web-vue";
import IconButton from "@/components/icon-button/index.vue";

type PropType = {
  model?: AnyObject;
  loading?: boolean;
  searchLabel?: string;
  searchIcon?: string;
  resetLabel?: string;
  resetIcon?: string;
  hideSearch?: boolean;
  hideReset?: boolean;
  inline?: boolean;
  split?: number;
  size?: "mini" | "small" | "medium" | "large";
  hideDivider?: boolean;
};

const props = withDefaults(defineProps<PropType>(), {
  loading: false,
  searchLabel: "搜索",
  searchIcon: "search",
  resetLabel: "重置",
  resetIcon: "refresh",
  hideSearch: false,
  hideReset: false,
  hideDivider: false,
  inline: false,
  split: 3,
  size: "small"
});
defineEmits<{ (e?: "search"): void; (e?: "reset"): void }>();

const layoutStyle = { marginBottom: "12px" };
const layoutRightStyle = props.hideSearch && props.hideReset ? {} : { borderLeft: "1px solid var(--color-neutral-3)" };

if (!props.hideDivider) {
  Object.assign(layoutStyle, { paddingBottom: "12px", borderBottom: "1px solid var(--color-neutral-3)" });
}
</script>

<template>
  <Layout :style="layoutStyle">
    <LayoutContent>
      <Form auto-label-width :model="model || {}" label-align="right" :size="size">
        <Grid :cols="split as number" :col-gap="12" :row-gap="12">
          <slot :size="size" />
        </Grid>
      </Form>
    </LayoutContent>
    <LayoutSider class="right" :style="layoutRightStyle">
      <Space :size="12" :direction="inline ? 'horizontal' : 'vertical'">
        <IconButton
          v-if="!hideSearch"
          :size="size"
          :icon="searchIcon"
          :label="searchLabel"
          type="primary"
          :loading="loading"
          @click="$emit('search')"
        />
        <IconButton v-if="!hideReset" :size="size" :icon="resetIcon" :label="resetLabel" @click="$emit('reset')" />
        <slot name="button" />
      </Space>
    </LayoutSider>
  </Layout>
</template>

<style scoped lang="less">
.right {
  border-left: 1px solid var(--color-neutral-3);
  margin-left: 12px;
  padding-left: 12px;
  box-shadow: unset;
  width: auto !important;
}
</style>