This commit is contained in:
2023-06-02 23:53:07 +08:00
parent afb2e49345
commit 4dedacf449
31 changed files with 1368 additions and 1236 deletions

View File

@@ -1,8 +1,4 @@
<template>
<nav>
<router-link to="/">Home</router-link> |
<router-link to="/about">About</router-link>
</nav>
<router-view/>
</template>

20
src/api/account.ts Normal file
View File

@@ -0,0 +1,20 @@
import QueryAPI from '@/api/query'
import { BASE_API } from '@/data/constants'
import { APIRoot } from './api-models'
const ACCOUNT_URL = `${BASE_API}account/`
export async function Register(name: string, email: string, password: string): Promise<APIRoot<string>> {
return QueryAPI<string>(`${ACCOUNT_URL}register`, {
name,
email,
password,
})
}
export async function Login(nameOrEmail: string, password: string): Promise<APIRoot<string>> {
return QueryAPI<string>(`${ACCOUNT_URL}login`, {
nameOrEmail,
password,
})
}

5
src/api/api-models.ts Normal file
View File

@@ -0,0 +1,5 @@
export interface APIRoot<T> {
code: number;
message: string;
data: T;
}

13
src/api/query.ts Normal file
View File

@@ -0,0 +1,13 @@
/* eslint-disable indent */
import { APIRoot } from './api-models';
export default async function QueryAPI<T>(url: string, body?: unknown): Promise<APIRoot<T>> {
const data = await fetch(url,{
method: 'post',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(body)
}); // 不处理异常, 在页面处理
return await data.json() as APIRoot<T>;
}

View File

@@ -2,13 +2,15 @@
<div class="hello">
<h1>{{ msg }}</h1>
<p>
For a guide and recipes on how to configure / customize this project,<br>
For a guide and recipes on how to configure / customize this project,<br />
check out the
<a href="https://cli.vuejs.org" target="_blank" rel="noopener">vue-cli documentation</a>.
</p>
<h3>Installed CLI Plugins</h3>
<ul>
<li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-babel" target="_blank" rel="noopener">babel</a></li>
<li>
<a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-babel" target="_blank" rel="noopener">babel</a>
</li>
<li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-pwa" target="_blank" rel="noopener">pwa</a></li>
<li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-router" target="_blank" rel="noopener">router</a></li>
<li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-vuex" target="_blank" rel="noopener">vuex</a></li>
@@ -35,14 +37,14 @@
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { defineComponent } from 'vue'
export default defineComponent({
name: 'HelloWorld',
props: {
msg: String,
},
});
})
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->

3
src/data/constants.ts Normal file
View File

@@ -0,0 +1,3 @@
const debugAPI = `${process.env.VITE_debugAPI}/api/`
const releseAPI = `${document.location.protocol}//api.vtsuru.live/api/`;
export const BASE_API = process.env.NODE_ENV === 'development' ? debugAPI : releseAPI;

View File

@@ -1,18 +1,18 @@
<template>
<div class="home">
<img alt="Vue logo" src="../assets/logo.png">
<HelloWorld msg="Welcome to Your Vue.js + TypeScript App"/>
<img alt="Vue logo" src="../assets/logo.png" />
<HelloWorld msg="Welcome to Your Vue.js + TypeScript App" />
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import HelloWorld from '@/components/HelloWorld.vue'; // @ is an alias to /src
import { defineComponent } from 'vue'
import HelloWorld from '@/components/HelloWorld.vue' // @ is an alias to /src
export default defineComponent({
name: 'HomeView',
components: {
HelloWorld,
},
});
})
</script>

View File

@@ -1,9 +1,13 @@
<template>
<n-button>
Hello
</n-button>
<div style="display: flex;justify-content: center;">
<div>
<NText strong tag="h1">
vtsuru
</NText>
</div>
</div>
</template>
<script lang="ts" setup>
import { NButton } from 'naive-ui';
import { NButton, NText } from 'naive-ui'
</script>