Skip to content

Commit

Permalink
feature: 登录注册连调,chatgpt接入
Browse files Browse the repository at this point in the history
  • Loading branch information
wisdomlsh committed Oct 28, 2023
1 parent 8217f51 commit 787602d
Show file tree
Hide file tree
Showing 31 changed files with 748 additions and 358 deletions.
40 changes: 15 additions & 25 deletions src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
/*
* @Descripttion:
* @version:
* @Author: 苏
* @email: 1373842098@qq.com
* @Date: 2023-03-08 17:15:44
* @LastEditors: sj
* @LastEditTime: 2023-03-10 09:13:19
*/
import type { AxiosProgressEvent, GenericAbortSignal } from 'axios'
import { post } from '@/utils/request'
import type { AxiosProgressEvent, GenericAbortSignal } from 'axios';
import { post } from '@/utils/request/index';

export function fetchChatAPI<T = any>(
prompt: string,
Expand All @@ -19,39 +10,38 @@ export function fetchChatAPI<T = any>(
url: '/chat',
data: { prompt, options },
signal,
})
});
}

export function fetchChatConfig<T = any>() {
return post<T>({
url: '/config',
})
});
}

export function fetchChatAPIProcess<T = any>(
params: {
prompt: string
options?: { conversationId?: string; parentMessageId?: string }
signal?: GenericAbortSignal
onDownloadProgress?: (progressEvent: AxiosProgressEvent) => void },
) {
export function fetchChatAPIProcess<T = any>(params: any) {
return post<T>({
url: '/chat-process',
data: { prompt: params.prompt, options: params.options },
url: 'https://api.openai.com/v1/chat/completions',
data: {
model: 'gpt-3.5-turbo',
messages: [{ role: 'user', content: params.prompt }],
stream: true,
// options: params.options,
},
signal: params.signal,
onDownloadProgress: params.onDownloadProgress,
})
});
}

export function fetchSession<T>() {
return post<T>({
url: '/session',
})
});
}

export function fetchVerify<T>(token: string) {
return post<T>({
url: '/verify',
data: { token },
})
});
}
16 changes: 16 additions & 0 deletions src/api/login.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { post } from '@/utils/request/index';
import type{ Register } from "./type";

export function fetchRegister<T>(data: Register ) {
return post<T>({
url: '/api/user/register',
data
});
}
export function fetchLogin<T>(data: Register ) {
return post<T>({
url: '/api/user/login',
data
});
}

60 changes: 0 additions & 60 deletions src/api/search.ts

This file was deleted.

5 changes: 5 additions & 0 deletions src/api/type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface Register {
userAccount: string,
userPassword: string,
checkPassword: string,
}
Binary file added src/assets/hmx.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ declare module 'vue' {
ASpace: typeof import('ant-design-vue/es')['Space']
ASwitch: typeof import('ant-design-vue/es')['Switch']
ATextarea: typeof import('ant-design-vue/es')['Textarea']
AUpload: typeof import('ant-design-vue/es')['Upload']
Button: typeof import('./components/common/HoverButton/Button.vue')['default']
General: typeof import('./components/common/Setting/General.vue')['default']
GithubSite: typeof import('./components/custom/GithubSite.vue')['default']
Expand Down
26 changes: 11 additions & 15 deletions src/components/PersonalSetting/PersonalSetting.vue
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
<template>
<a-drawer :open="visible" class="custom-class" root-class-name="root-class-name" :root-style="{ color: 'blue' }"
style="color: red" title="Basic Drawer" placement="right" @after-open-change="afterOpenChange">
<p>Some contents...</p>
<p>Some contents...</p>
<p>Some contents...</p>
</a-drawer>

<n-drawer :show="open" :width="700">
<n-drawer-content title="个人设置" closable>
</n-drawer-content>
</n-drawer>
</template>

<script setup lang="ts">
import { watch } from "vue";
interface Props {
visible: boolean
import { defineComponent, ref } from 'vue'
interface Iprops {
open: boolean
}
const props = defineProps<Props>()
console.log('====================================');
console.log(props?.visible);
console.log('====================================');
</script>
defineProps<Iprops>()
<style scoped lang="less"></style>
</script>
23 changes: 16 additions & 7 deletions src/components/RightContent/RightContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,30 @@
<template #icon>
<LogoutOutlined />
</template>
<span>退出登录</span>
<span @click="handleLogoutClick">退出登录</span>
</a-menu-item>
</a-menu>
</template>
<a-avatar shape="square" size="small">
<template #icon>
<UserOutlined />
<!-- <UserOutlined /> -->
<img src="../../assets/hmx.JPG" alt="">
</template>
{{ currentUser.nickname }}
</a-avatar>
</a-dropdown>
</a-space>
<PersonalSetting :visible="settingState"/>
<PersonalSetting :open="settingState"/>
</div>
</template>

<script setup lang="ts">
import { ref } from "vue";
import PersonalSetting from "@/components/PersonalSetting/PersonalSetting.vue";
import { useRouter } from "vue-router";
import { UserOutlined, SettingOutlined, LogoutOutlined, BgColorsOutlined } from '@ant-design/icons-vue';
import PersonalSetting from "@/components/PersonalSetting/PersonalSetting.vue";
import { apply, randomTheme } from '../../hooks/useTheme';
import router from "@/router";
export type CurrentUser = {
nickname: string;
Expand All @@ -49,14 +52,20 @@ defineProps<{
}>();
const settingState = ref<boolean>(false)
const route = useRouter()
const handleClick = () => {
apply(randomTheme());
};
const handleSettingClick = () => {
settingState.value = true
}
const handleLogoutClick = () => {
localStorage.clear()
setTimeout(() => {
route.replace('/login')
}, 100)
}
</script>
1 change: 0 additions & 1 deletion src/components/SettingDrawer/SettingDrawer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ const updateConf = (val: string | CheckedType | undefined, type: ConfType) => {
...toRaw(props.modelValue),
[`${type}`]: val,
};
console.log('newConf', newVal);
emit('update:modelValue', newVal);
};
</script>
Expand Down
16 changes: 11 additions & 5 deletions src/components/common/HoverButton/Button.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@ function handleClick() {
</script>

<template>
<button
class="flex items-center justify-center w-10 h-10 transition rounded-full hover:bg-neutral-100 dark:hover:bg-[#414755]"
@click="handleClick"
>
<n-button type="tertiary" class="rounded-full" @click="handleClick">
<slot />
</button>
</n-button>

</template>

<style scoped >
.rounded-full {
border-radius: 9999px;
}
</style>
18 changes: 15 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,20 @@ import 'ant-design-vue/dist/antd.variable.min.css';
import { createApp } from 'vue';
import { ConfigProvider } from 'ant-design-vue';
import ProLayout, { PageContainer } from '@ant-design-vue/pro-layout';
import NaiveUI from "naive-ui";
import router from './router';
import NaiveUI from 'naive-ui';
import { setupRouter } from './router';
import App from './App.vue';

createApp(App).use(router).use(ConfigProvider).use(NaiveUI).use(ProLayout).use(PageContainer).mount('#app');
async function bootstrap() {
const app = createApp(App);
await setupRouter(app);

app
.use(ConfigProvider)
.use(NaiveUI)
.use(ProLayout)
.use(PageContainer)
.mount('#app');
}

bootstrap();
Loading

0 comments on commit 787602d

Please sign in to comment.