enhance(ui):调整授权码部分功能。

This commit is contained in:
徐涛 2024-04-05 11:42:23 +08:00
parent 33dadb0d1b
commit 618a44fdd0
6 changed files with 58 additions and 4 deletions

View File

@ -3,4 +3,7 @@
}
.license-code-area {
flex-grow: 1;
overflow-x: hidden;
overflow-y: auto;
overflow-wrap: break-word;
}

View File

@ -1,8 +1,10 @@
import { ActionIcon, Flex, Group, Paper, Textarea, Title, Tooltip } from "@mantine/core";
import { useLicenseCode } from "@/hooks/use-license-code";
import { ActionIcon, Box, Flex, Group, Paper, Title, Tooltip } from "@mantine/core";
import { IconCopy } from "@tabler/icons-react";
import classes from "./LicenseCode.module.css";
export function LicenseCode() {
const [licenseCode] = useLicenseCode();
return (
<Paper shadow="md" p="lg" className={classes["container"]}>
<Flex direction="column" justify="flex-start" align="stretch" gap="md">
@ -14,7 +16,9 @@ export function LicenseCode() {
</ActionIcon>
</Tooltip>
</Group>
<Textarea autosize minRows={9} maxRows={12} readOnly variant="transparent" />
<Box className={classes["license-code-area"]} c="green">
{licenseCode}
</Box>
</Flex>
</Paper>
);

View File

@ -1,3 +1,9 @@
.conatiner {
flex-grow: 1;
}
.title {
flex-grow: 5;
}
.title-search {
flex-grow: 1;
}

View File

@ -1,10 +1,21 @@
import { Flex, Paper, Title } from "@mantine/core";
import { Flex, Paper, TextInput, Title } from "@mantine/core";
import { IconSearch } from "@tabler/icons-react";
import classes from "./ProductList.module.css";
export function ProductList() {
return (
<Paper shadow="md" p="lg" h="100%">
<Flex direction="column" justify="flex-start" align="stretch" gap="md">
<Title order={4}></Title>
<Flex direction="row" justify={"space-between"} align={"center"} gap="sm">
<Title order={4} className={classes["title"]}>
</Title>
<TextInput
placeholder="输入关键词检索产品"
className={classes["title-search"]}
leftSection={<IconSearch size={16} />}
/>
</Flex>
</Flex>
</Paper>
);

View File

@ -0,0 +1,6 @@
import { useState } from "react";
export function useLicenseCode(): [string, (licenseCode: string) => void] {
const [licenseCode, setLicenseCode] = useState<string>("");
return [licenseCode, setLicenseCode];
}

View File

@ -0,0 +1,24 @@
import { useEffect, useState } from "react";
type ProductSearchKeyword = string | undefined | null;
interface Product {
id: string;
name: string;
}
export function useProducts(keyword: ProductSearchKeyword): Product[] {
const [products, setProducts] = useState<Product[]>([]);
useEffect(() => {
async function fetchProducts() {
const response = await fetch(`/api/products?keyword=${keyword}`);
const data = await response.json();
setProducts(data);
}
fetchProducts();
}, [keyword]);
return products;
}