🎉 搭完基本框架
This commit is contained in:
40
frontend/src/api.ts
Normal file
40
frontend/src/api.ts
Normal file
@ -0,0 +1,40 @@
|
||||
import {Invoke} from "../wailsjs/go/controller/App";
|
||||
|
||||
export interface Resp<T> {
|
||||
status: number;
|
||||
msg: string;
|
||||
err: string;
|
||||
data: T;
|
||||
}
|
||||
|
||||
// 类型保护函数
|
||||
function isResp<T>(obj: any): obj is Resp<T> {
|
||||
return (
|
||||
typeof obj === 'object' &&
|
||||
obj !== null &&
|
||||
typeof obj.status === 'number' &&
|
||||
(typeof obj.msg === 'string' || typeof obj.msg === null) &&
|
||||
(typeof obj.err === 'string' || typeof obj.err === null)
|
||||
);
|
||||
}
|
||||
|
||||
const invoke = async <T>(path: string, req: any): Promise<Resp<T>> => {
|
||||
const bs = JSON.stringify(req)
|
||||
console.log(`[DEBUG] invoke req: path = ${path}, req =`, req)
|
||||
const res = await Invoke(path, bs)
|
||||
console.log(`[DEBUG] invoke res: path = ${path}, res =`, res)
|
||||
try {
|
||||
const parsed = JSON.parse(res);
|
||||
if (isResp<T>(parsed)) {
|
||||
return parsed;
|
||||
} else {
|
||||
console.error('[ERROR] invoke: resp not valid =', res)
|
||||
throw new Error('Parsed response does not match Resp<T> structure');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`[ERROR] invoke: resp parse err, err = ${error}, res =`, res);
|
||||
throw new Error('Invalid response format');
|
||||
}
|
||||
}
|
||||
|
||||
export const Dial = invoke;
|
93
frontend/src/assets/fonts/OFL.txt
Normal file
93
frontend/src/assets/fonts/OFL.txt
Normal file
@ -0,0 +1,93 @@
|
||||
Copyright 2016 The Nunito Project Authors (contact@sansoxygen.com),
|
||||
|
||||
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
||||
This license is copied below, and is also available with a FAQ at:
|
||||
http://scripts.sil.org/OFL
|
||||
|
||||
|
||||
-----------------------------------------------------------
|
||||
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
||||
-----------------------------------------------------------
|
||||
|
||||
PREAMBLE
|
||||
The goals of the Open Font License (OFL) are to stimulate worldwide
|
||||
development of collaborative font projects, to support the font creation
|
||||
efforts of academic and linguistic communities, and to provide a free and
|
||||
open framework in which fonts may be shared and improved in partnership
|
||||
with others.
|
||||
|
||||
The OFL allows the licensed fonts to be used, studied, modified and
|
||||
redistributed freely as long as they are not sold by themselves. The
|
||||
fonts, including any derivative works, can be bundled, embedded,
|
||||
redistributed and/or sold with any software provided that any reserved
|
||||
names are not used by derivative works. The fonts and derivatives,
|
||||
however, cannot be released under any other type of license. The
|
||||
requirement for fonts to remain under this license does not apply
|
||||
to any document created using the fonts or their derivatives.
|
||||
|
||||
DEFINITIONS
|
||||
"Font Software" refers to the set of files released by the Copyright
|
||||
Holder(s) under this license and clearly marked as such. This may
|
||||
include source files, build scripts and documentation.
|
||||
|
||||
"Reserved Font Name" refers to any names specified as such after the
|
||||
copyright statement(s).
|
||||
|
||||
"Original Version" refers to the collection of Font Software components as
|
||||
distributed by the Copyright Holder(s).
|
||||
|
||||
"Modified Version" refers to any derivative made by adding to, deleting,
|
||||
or substituting -- in part or in whole -- any of the components of the
|
||||
Original Version, by changing formats or by porting the Font Software to a
|
||||
new environment.
|
||||
|
||||
"Author" refers to any designer, engineer, programmer, technical
|
||||
writer or other person who contributed to the Font Software.
|
||||
|
||||
PERMISSION & CONDITIONS
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
||||
redistribute, and sell modified and unmodified copies of the Font
|
||||
Software, subject to the following conditions:
|
||||
|
||||
1) Neither the Font Software nor any of its individual components,
|
||||
in Original or Modified Versions, may be sold by itself.
|
||||
|
||||
2) Original or Modified Versions of the Font Software may be bundled,
|
||||
redistributed and/or sold with any software, provided that each copy
|
||||
contains the above copyright notice and this license. These can be
|
||||
included either as stand-alone text files, human-readable headers or
|
||||
in the appropriate machine-readable metadata fields within text or
|
||||
binary files as long as those fields can be easily viewed by the user.
|
||||
|
||||
3) No Modified Version of the Font Software may use the Reserved Font
|
||||
Name(s) unless explicit written permission is granted by the corresponding
|
||||
Copyright Holder. This restriction only applies to the primary font name as
|
||||
presented to the users.
|
||||
|
||||
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
||||
Software shall not be used to promote, endorse or advertise any
|
||||
Modified Version, except to acknowledge the contribution(s) of the
|
||||
Copyright Holder(s) and the Author(s) or with their explicit written
|
||||
permission.
|
||||
|
||||
5) The Font Software, modified or unmodified, in part or in whole,
|
||||
must be distributed entirely under this license, and must not be
|
||||
distributed under any other license. The requirement for fonts to
|
||||
remain under this license does not apply to any document created
|
||||
using the Font Software.
|
||||
|
||||
TERMINATION
|
||||
This license becomes null and void if any of the above conditions are
|
||||
not met.
|
||||
|
||||
DISCLAIMER
|
||||
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
||||
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
||||
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
||||
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
||||
OTHER DEALINGS IN THE FONT SOFTWARE.
|
BIN
frontend/src/assets/fonts/nunito-v16-latin-regular.woff2
Normal file
BIN
frontend/src/assets/fonts/nunito-v16-latin-regular.woff2
Normal file
Binary file not shown.
BIN
frontend/src/assets/images/logo-universal.png
Normal file
BIN
frontend/src/assets/images/logo-universal.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 136 KiB |
22
frontend/src/main.tsx
Normal file
22
frontend/src/main.tsx
Normal file
@ -0,0 +1,22 @@
|
||||
import React from 'react'
|
||||
import {createRoot} from 'react-dom/client'
|
||||
import './style.css'
|
||||
import { FluentProvider, webLightTheme } from '@fluentui/react-components';
|
||||
import {createBrowserRouter,RouterProvider} from "react-router-dom";
|
||||
import Home from "./page/home/home";
|
||||
import Connection from "./page/connection/connection";
|
||||
|
||||
const container = document.getElementById('root')
|
||||
|
||||
const root = createRoot(container!)
|
||||
|
||||
const router = createBrowserRouter([
|
||||
{path:'/', element: <Home />},
|
||||
{path:'/connection', element: <Connection />},
|
||||
])
|
||||
|
||||
root.render(
|
||||
<FluentProvider theme={webLightTheme}>
|
||||
<RouterProvider router={router} />
|
||||
</FluentProvider>,
|
||||
);
|
28
frontend/src/page/connection/connection.css
Normal file
28
frontend/src/page/connection/connection.css
Normal file
@ -0,0 +1,28 @@
|
||||
div.connection-container {
|
||||
display: flex;
|
||||
height: 100vh;
|
||||
width: 100%;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
div.connection-form {
|
||||
max-width: 700px;
|
||||
min-width: 500px;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex: 1;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
div.connection-form-field {
|
||||
width: 100%;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
div.connection-form-field-actions {
|
||||
display: flex;
|
||||
margin-top: 50px;
|
||||
}
|
111
frontend/src/page/connection/connection.tsx
Normal file
111
frontend/src/page/connection/connection.tsx
Normal file
@ -0,0 +1,111 @@
|
||||
import './connection.css'
|
||||
import {
|
||||
useId,
|
||||
Button,
|
||||
FieldProps,
|
||||
useToastController,
|
||||
Toast,
|
||||
ToastTitle,
|
||||
ToastIntent,
|
||||
Toaster
|
||||
} from "@fluentui/react-components";
|
||||
import {Field, Input} from "@fluentui/react-components";
|
||||
import {useNavigate} from "react-router-dom";
|
||||
import {useState} from "react";
|
||||
import {Dial} from "../../api";
|
||||
|
||||
|
||||
const Connection = (props: Partial<FieldProps>) => {
|
||||
|
||||
const toasterId = useId("toaster");
|
||||
const {dispatchToast} = useToastController(toasterId);
|
||||
const navigate = useNavigate();
|
||||
const [value, setValue] = useState<{ name: string, endpoint: string, access: string, key: string }>({
|
||||
name: '',
|
||||
endpoint: '',
|
||||
access: '',
|
||||
key: ''
|
||||
})
|
||||
|
||||
function test() {
|
||||
const val = JSON.stringify(value);
|
||||
console.log('[DEBUG] connection.test: value =', val)
|
||||
Dial<string>("/api/connection/test", value).then(res => {
|
||||
if (res.status === 200) {
|
||||
dispatchToast(
|
||||
<Toast>
|
||||
<ToastTitle>连接成功!</ToastTitle>
|
||||
</Toast>,
|
||||
{position: "top-end", intent: "success"}
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return <div className='connection-container'>
|
||||
<div className='connection-form'>
|
||||
<div className='connection-form-field'>
|
||||
<Field
|
||||
label="name"
|
||||
validationState="success"
|
||||
validationMessage="This is a success message."
|
||||
{...props}
|
||||
>
|
||||
<Input placeholder='名称 (example: 测试S3-minio)' value={value.name} onChange={(e) => {
|
||||
setValue({...value, name: e.target.value});
|
||||
}}/>
|
||||
</Field>
|
||||
</div>
|
||||
<div className='connection-form-field'>
|
||||
<Field
|
||||
label="endpoint"
|
||||
validationState="success"
|
||||
validationMessage="This is a success message."
|
||||
{...props}
|
||||
>
|
||||
<Input placeholder='地址 (example: https://ip_or_server-name:port)' value={value.endpoint}
|
||||
onChange={(e) => {
|
||||
setValue({...value, endpoint: e.target.value});
|
||||
}}/>
|
||||
</Field>
|
||||
</div>
|
||||
<div className='connection-form-field'>
|
||||
<Field
|
||||
label="secret access"
|
||||
validationState="success"
|
||||
validationMessage="This is a success message."
|
||||
{...props}
|
||||
>
|
||||
<Input placeholder='' value={value.access} onChange={(e) => {
|
||||
setValue({...value, access: e.target.value});
|
||||
}}/>
|
||||
</Field>
|
||||
</div>
|
||||
<div className='connection-form-field'>
|
||||
<Field
|
||||
label="secret key"
|
||||
validationState="success"
|
||||
validationMessage="This is a success message."
|
||||
{...props}
|
||||
>
|
||||
<Input placeholder='' value={value.key} onChange={(e) => {
|
||||
setValue({...value, key: e.target.value});
|
||||
}}/>
|
||||
</Field>
|
||||
</div>
|
||||
<div className='connection-form-field connection-form-field-actions'>
|
||||
<Button appearance='transparent' onClick={() => test()}>测试连接</Button>
|
||||
<div style={{marginLeft: 'auto'}}>
|
||||
<Button style={{marginRight: '20px'}} className='connection-form-field-actions-cancel'
|
||||
onClick={() => {
|
||||
navigate("/")
|
||||
}}>取消</Button>
|
||||
<Button className='connection-form-field-actions-confirm' appearance='primary'>新建</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<Toaster toasterId={toasterId}/>
|
||||
</div>
|
||||
}
|
||||
|
||||
export default Connection;
|
50
frontend/src/page/home/home.css
Normal file
50
frontend/src/page/home/home.css
Normal file
@ -0,0 +1,50 @@
|
||||
div.container {
|
||||
height: 100vh;
|
||||
width: 100vw;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
div.header {
|
||||
height: 50px;
|
||||
border-bottom: 1px solid lightgray;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 0 8px;
|
||||
}
|
||||
|
||||
div.body {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
div.body div.body-connections {
|
||||
width: 200px;
|
||||
border-right: 1px solid lightgray;
|
||||
}
|
||||
|
||||
div.body-connections-search {
|
||||
display: flex;
|
||||
height: 30px;
|
||||
}
|
||||
|
||||
input.body-connections-search-input {
|
||||
border: none;
|
||||
border-bottom: 1px solid lightgray;
|
||||
width: calc(100% - 4px);
|
||||
height: 30px;
|
||||
outline: none;
|
||||
text-indent: 5px;
|
||||
}
|
||||
div.body-connections-search-dismiss{
|
||||
border: none;
|
||||
background: none;
|
||||
outline: none;
|
||||
border-bottom: 1px solid lightgray;
|
||||
height: 32px;
|
||||
width: 32px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
39
frontend/src/page/home/home.tsx
Normal file
39
frontend/src/page/home/home.tsx
Normal file
@ -0,0 +1,39 @@
|
||||
import {useState} from 'react';
|
||||
import './home.css';
|
||||
import {
|
||||
Button,
|
||||
} from "@fluentui/react-components";
|
||||
import {
|
||||
CloudAddFilled, DismissRegular
|
||||
} from "@fluentui/react-icons";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
|
||||
function Home() {
|
||||
const [connectionFilterKeywords, setConnectionFilterKeywords] = useState<string>('');
|
||||
const navigate = useNavigate();
|
||||
|
||||
return (
|
||||
<div className="container">
|
||||
<div className="header">
|
||||
<Button appearance="primary" icon={<CloudAddFilled />} onClick={() => {navigate("/connection")}}>
|
||||
新建连接
|
||||
</Button>
|
||||
</div>
|
||||
<div className="body">
|
||||
<div className="body-connections">
|
||||
<div className="body-connections-search">
|
||||
<input className="body-connections-search-input" type={"text"} placeholder="搜索连接" value={connectionFilterKeywords} onChange={(e) => setConnectionFilterKeywords(e.target.value)} />
|
||||
<div className="body-connections-search-dismiss" onClick={() => {setConnectionFilterKeywords('')}}>
|
||||
<DismissRegular />
|
||||
</div>
|
||||
</div>
|
||||
<div className="body-connections-list"></div>
|
||||
</div>
|
||||
<div className="body-content"></div>
|
||||
</div>
|
||||
<div className="footer"></div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default Home
|
18
frontend/src/style.css
Normal file
18
frontend/src/style.css
Normal file
@ -0,0 +1,18 @@
|
||||
body {
|
||||
margin: 0;
|
||||
color: white;
|
||||
font-family: "Nunito", -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto",
|
||||
"Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue",
|
||||
sans-serif;
|
||||
height: 100vh;
|
||||
width: 100vw;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: "Nunito";
|
||||
font-style: normal;
|
||||
font-weight: 400;
|
||||
src: local(""),
|
||||
url("assets/fonts/nunito-v16-latin-regular.woff2") format("woff2");
|
||||
}
|
||||
|
1
frontend/src/vite-env.d.ts
vendored
Normal file
1
frontend/src/vite-env.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
||||
/// <reference types="vite/client" />
|
Reference in New Issue
Block a user