Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

2.8 KB
Raw Blame
<script setup lang="ts">
import { computed, ref } from "vue";
import { Button } from "@/components/ui/button";
import { RefreshCw } from "@lucide/vue";
import type { GeneratorParams } from "@/lib/dataGrid/dataGenerate";
import CommonOptions from "./CommonOptions.vue";
import { useI18n } from "vue-i18n";

const props = defineProps<{ params: GeneratorParams }>();

const { t } = useI18n();

const ipTypes = [
  { value: "ipv4", label: "IPv4", regex: "^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$" },
  { value: "ipv6", label: "IPv6", regex: "^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$" },
];

function generateIPv4(): string {
  return `${Math.floor(Math.random() * 256)}.${Math.floor(Math.random() * 256)}.${Math.floor(Math.random() * 256)}.${Math.floor(Math.random() * 256)}`;
}

function generateIPv6(): string {
  const groups: string[] = [];
  for (let i = 0; i < 8; i++) {
    groups.push(
      Math.floor(Math.random() * 65536)
        .toString(16)
        .padStart(4, "0"),
    );
  }
  return groups.join(":");
}

const previewKey = ref(0);
const currentRegex = computed(() => {
  const t = props.params.ipType ?? "ipv4";
  return ipTypes.find((x) => x.value === t)?.regex ?? "";
});
const previewVal = computed(() => {
  void previewKey.value;
  if (props.params.ipType === "ipv6") return generateIPv6();
  return generateIPv4();
});

function refresh() {
  previewKey.value++;
}
</script>

<template>
  <div class="space-y-3">
    <div class="rounded-md border bg-muted/10 p-3">
      <div class="text-xs text-muted-foreground mb-2">{{ t("dataGenerate.ipType") }}</div>
      <div class="flex items-center gap-2 text-xs">
        <button v-for="x in ipTypes" :key="x.value" type="button" class="px-2 py-1 rounded border text-xs" :class="(params.ipType || 'ipv4') === x.value ? 'bg-primary text-primary-foreground border-primary' : 'bg-background'" @click="params.ipType = x.value">{{ x.label }}</button>
      </div>
    </div>
    <div class="rounded-md border bg-muted/10 p-3">
      <div class="text-xs text-muted-foreground mb-1">{{ t("dataGenerate.regex") }}</div>
      <div class="font-mono text-xs bg-background rounded border px-2 py-1 break-all">{{ currentRegex }}</div>
    </div>
    <div class="rounded-md border bg-muted/10 p-3">
      <div class="flex items-center gap-2 text-xs">
        <span class="text-muted-foreground shrink-0">{{ t("dataGenerate.preview") }}</span>
        <span :key="previewKey" class="font-mono text-sm">{{ previewVal }}</span>
        <Button variant="ghost" size="icon" class="h-5 w-5 ml-auto" @click="refresh">
          <RefreshCw class="h-3 w-3" />
        </Button>
      </div>
    </div>
    <CommonOptions :params="params" />
  </div>
</template>