Skip to content

Commit

Permalink
feat: 迁移旧的结果展示页面
Browse files Browse the repository at this point in the history
  • Loading branch information
nopdan committed Mar 9, 2024
1 parent 4061b7c commit 2631808
Show file tree
Hide file tree
Showing 13 changed files with 568 additions and 82 deletions.
12 changes: 7 additions & 5 deletions cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ var serverCmd = &cobra.Command{
Use: "server",
Short: "启动 web 服务",
Run: func(cmd *cobra.Command, args []string) {
server.Serve(Port, Silent)
server.Serve(port, silent, prefix)
},
}

var Port string
var Silent bool
var port int
var silent bool
var prefix string

func init() {
serverCmd.Flags().StringVarP(&Port, "port", "p", "7172", "指定端口")
serverCmd.Flags().BoolVarP(&Silent, "silent", "s", false, "静默启动")
serverCmd.Flags().IntVarP(&port, "port", "p", 7007, "指定端口")
serverCmd.Flags().BoolVarP(&silent, "silent", "s", false, "静默启动")
serverCmd.Flags().StringVarP(&prefix, "prefix", "d", "", "工作目录")
}
Binary file modified frontend/bun.lockb
Binary file not shown.
7 changes: 7 additions & 0 deletions frontend/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,20 @@ declare module "@vue/runtime-core" {
CollisionDistBar: (typeof import("./src/components/Result/CollisionDistBar.vue"))["default"];
CombsDescription: (typeof import("./src/components/Result/CombsDescription.vue"))["default"];
CombsDistBar: (typeof import("./src/components/Result/CombsDistBar.vue"))["default"];
Compare: (typeof import("./src/components/Compare.vue"))["default"];
ComparedBars: (typeof import("./src/components/Result/comparedBars.vue"))["default"];
Data: (typeof import("./src/components/Data.vue"))["default"];
FingerPie: (typeof import("./src/components/Result/FingerPie.vue"))["default"];
FingersDescription: (typeof import("./src/components/Result/FingersDescription.vue"))["default"];
HandComp: (typeof import("./src/components/Result/HandComp.vue"))["default"];
HandsDescription: (typeof import("./src/components/Result/HandsDescription.vue"))["default"];
KeyHeatSorted: (typeof import("./src/components/Result/KeyHeatSorted.vue"))["default"];
Main: (typeof import("./src/components/Main.vue"))["default"];
MultiResult: (typeof import("./src/components/MultiResult.vue"))["default"];
NButton: (typeof import("naive-ui"))["NButton"];
NCard: (typeof import("naive-ui"))["NCard"];
NDescriptions: (typeof import("naive-ui"))["NDescriptions"];
NDescriptionsItem: (typeof import("naive-ui"))["NDescriptionsItem"];
NDivider: (typeof import("naive-ui"))["NDivider"];
NDrawer: (typeof import("naive-ui"))["NDrawer"];
NDrawerContent: (typeof import("naive-ui"))["NDrawerContent"];
Expand All @@ -36,6 +41,7 @@ declare module "@vue/runtime-core" {
NRadio: (typeof import("naive-ui"))["NRadio"];
NRadioGroup: (typeof import("naive-ui"))["NRadioGroup"];
NSelect: (typeof import("naive-ui"))["NSelect"];
NSpace: (typeof import("naive-ui"))["NSpace"];
NSwitch: (typeof import("naive-ui"))["NSwitch"];
NTag: (typeof import("naive-ui"))["NTag"];
NText: (typeof import("naive-ui"))["NText"];
Expand All @@ -44,6 +50,7 @@ declare module "@vue/runtime-core" {
Result: (typeof import("./src/components/Result/Result.vue"))["default"];
ResultBasic: (typeof import("./src/components/Result/ResultBasic.vue"))["default"];
ResultKeyHeat: (typeof import("./src/components/Result/ResultKeyHeat.vue"))["default"];
Show: (typeof import("./src/components/Show.vue"))["default"];
Text: (typeof import("./src/components/Text.vue"))["default"];
WordsDescription: (typeof import("./src/components/Result/WordsDescription.vue"))["default"];
WordsDistBar: (typeof import("./src/components/Result/WordsDistBar.vue"))["default"];
Expand Down
75 changes: 75 additions & 0 deletions frontend/src/components/Data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Generated by https://quicktype.io

export interface Data {
Info: Info;
Commit: Commit;
Pair: Pair;
Keys: { [key: string]: Key };
Han: Han;
Dist: Dist;
CodeLen: CodeLen;
LeftHand: number;
RightHand: number;
Equivalent: number;
}

export interface CodeLen {
Total: number;
PerChar: number;
}

export interface Commit {
Count: number;
Word: number;
WordChars: number;
WordFirst: number;
Collision: number;
CollisionChars: number;
}

export interface Dist {
CodeLen: number[];
WordLen: number[];
Collision: number[];
Finger: number[];
}

export interface Han {
NotHan: string;
NotHans: number;
NotHanCount: number;
Lack: string;
Lacks: number;
LackCount: number;
}

export interface Info {
TextName: string;
TextLen: number;
DictName: string;
DictLen: number;
Single: boolean;
}

export interface Key {
Count: number;
Rate: number;
}

export interface Pair {
Count: number;
SameFinger: number;
DoubleHit: number;
TribleHit: number;
SingleSpan: number;
MultiSpan: number;
Staggered: number;
Disturb: number;
LeftToLeft: number;
LeftToRight: number;
RightToLeft: number;
RightToRight: number;
DiffFinger: number;
SameHand: number;
DiffHand: number;
}
35 changes: 8 additions & 27 deletions frontend/src/components/Main.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<script setup lang="ts">
import { Data } from "./Data";
import { TextConfig } from "./Text.vue";
import Text from "./Text.vue";
let route = "api/";
const cleanMode = ref(false);
const textList = reactive(new Array<TextConfig>());
function addText(config: TextConfig): void {
Expand Down Expand Up @@ -155,7 +154,7 @@ const localFiles = ref({
dict: [],
});
function fetchList() {
fetch(route + "list", {
fetch("/list", {
method: "GET",
})
.then((response) => response.json())
Expand All @@ -170,7 +169,8 @@ function fetchList() {
fetchList();
const activeDrawer = ref(false);
/** 总的结果 */
const result = ref<Data[][]>([]);
async function race() {
// 生成 formData
const formData = new FormData();
Expand All @@ -184,14 +184,15 @@ async function race() {
// post 请求 url
// fetch 发送 post 请求
await fetch(route + "race", {
await fetch("/race", {
method: "POST",
body: formData,
})
.then((response) => response.json())
.then((data) => {
fetchList();
result.value = data as Data[][];
console.log(data);
activeDrawer.value = !activeDrawer.value;
})
.catch((error) => {
console.error("Error:", error);
Expand Down Expand Up @@ -276,27 +277,7 @@ async function race() {
>开始比赛</n-button
>
</div>

<n-drawer v-model:show="activeDrawer" :width="502" placement="bottom" height="100vh">
<n-drawer-content :native-scrollbar="false" closable>
<template #header>
<div style="display: flex; align-items: center; justify-content: center">
<div style="width: 100%; margin-right: 10px">文章</div>
<!-- <n-select
v-model:value="textConfig.name"
:options="textOptions"
placeholder="请选择"
style="min-width: 500px"
/> -->
</div>
</template>
《斯通纳》是美国作家约翰·威廉姆斯在 1965 年出版的小说。

<template #footer>
<n-button>Footer</n-button>
</template>
</n-drawer-content>
</n-drawer>
<Show :result="result"></Show>
</template>

<style>
Expand Down
Loading

0 comments on commit 2631808

Please sign in to comment.