feat: 优化文件结构、组件、布局

main
ChenZhaoYu 2 years ago
parent 72df35c929
commit 39f718ef16

@ -31,6 +31,7 @@
"OPENAI", "OPENAI",
"pinia", "pinia",
"rushstack", "rushstack",
"Sider",
"tailwindcss", "tailwindcss",
"unplugin", "unplugin",
"VITE", "VITE",

@ -1,13 +1,12 @@
<script setup lang="ts"> <script setup lang="ts">
import { GithubSite, NaiveProvider } from '@/components' import { NaiveProvider } from '@/components/common'
import Chat from '@/views/Chat/index.vue' import Chat from '@/views/Chat/index.vue'
</script> </script>
<template> <template>
<NaiveProvider> <NaiveProvider>
<div class="h-full overflow-hidden pb-[50px] p-4"> <div class="h-full p-4 overflow-hidden">
<Chat /> <Chat />
<GithubSite />
</div> </div>
</NaiveProvider> </NaiveProvider>
</template> </template>

@ -1,27 +0,0 @@
<script setup lang="ts">
import { defineComponent, h } from 'vue'
import { NConfigProvider, NMessageProvider, useMessage } from 'naive-ui'
function registerNaiveTools() {
window.$message = useMessage()
}
const NaiveProviderContent = defineComponent({
name: 'NaiveProviderContent',
setup() {
registerNaiveTools()
},
render() {
return h('div')
},
})
</script>
<template>
<NConfigProvider class="h-full">
<NMessageProvider>
<slot />
<NaiveProviderContent />
</NMessageProvider>
</NConfigProvider>
</template>

@ -0,0 +1,20 @@
<script setup lang='ts'>
interface Emit {
(e: 'click'): void
}
const emit = defineEmits<Emit>()
function handleClick() {
emit('click')
}
</script>
<template>
<button
class="flex items-center justify-center w-10 h-10 transition rounded-full hover:bg-neutral-100"
@click="handleClick"
>
<slot />
</button>
</template>

@ -0,0 +1,46 @@
<script setup lang='ts'>
import { computed } from 'vue'
import type { PopoverPlacement } from 'naive-ui'
import { NTooltip } from 'naive-ui'
import Button from './Button.vue'
interface Props {
tooltip?: string
placement?: PopoverPlacement
}
interface Emit {
(e: 'click'): void
}
const props = withDefaults(defineProps<Props>(), {
tooltip: '',
placement: 'bottom',
})
const emit = defineEmits<Emit>()
const showTooltip = computed(() => Boolean(props.tooltip))
function handleClick() {
emit('click')
}
</script>
<template>
<div v-if="showTooltip">
<NTooltip :placement="placement" trigger="hover">
<template #trigger>
<Button @click="handleClick">
<slot />
</Button>
</template>
{{ tooltip }}
</NTooltip>
</div>
<div v-else>
<Button @click="handleClick">
<slot />
</Button>
</div>
</template>

@ -0,0 +1,46 @@
<script setup lang="ts">
import { defineComponent, h } from 'vue'
import {
NConfigProvider,
NDialogProvider,
NLoadingBarProvider,
NMessageProvider,
NNotificationProvider,
useDialog,
useLoadingBar,
useMessage,
useNotification,
} from 'naive-ui'
function registerNaiveTools() {
window.$loadingBar = useLoadingBar()
window.$dialog = useDialog()
window.$message = useMessage()
window.$notification = useNotification()
}
const NaiveProviderContent = defineComponent({
name: 'NaiveProviderContent',
setup() {
registerNaiveTools()
},
render() {
return h('div')
},
})
</script>
<template>
<NConfigProvider class="h-full">
<NLoadingBarProvider>
<NDialogProvider>
<NNotificationProvider>
<NMessageProvider>
<slot />
<NaiveProviderContent />
</NMessageProvider>
</NNotificationProvider>
</NDialogProvider>
</NLoadingBarProvider>
</NConfigProvider>
</template>

@ -0,0 +1,5 @@
import HoverButton from './HoverButton/index.vue'
import NaiveProvider from './NaiveProvider.vue'
import SvgIcon from './SvgIcon.vue'
export { HoverButton, NaiveProvider, SvgIcon }

@ -0,0 +1,3 @@
import GithubSite from './GithubSite.vue'
export { GithubSite }

@ -1,5 +0,0 @@
import NaiveProvider from './NaiveProvider.vue'
import Icon from './Icon.vue'
import GithubSite from './GithubSite.vue'
export { NaiveProvider, Icon, GithubSite }

@ -1,3 +1,6 @@
interface Window { interface Window {
$loadingBar?: import('naive-ui').LoadingBarProviderInst;
$dialog?: import('naive-ui').DialogProviderInst;
$message?: import('naive-ui').MessageProviderInst; $message?: import('naive-ui').MessageProviderInst;
$notification?: import('naive-ui').NotificationProviderInst;
} }

@ -1,9 +1,10 @@
<script setup lang='ts'> <script setup lang='ts'>
import { nextTick, onMounted, ref } from 'vue' import { nextTick, onMounted, ref } from 'vue'
import { NButton, NInput, NPopover, useMessage } from 'naive-ui' import { NButton, NInput, useMessage } from 'naive-ui'
import { Message } from './components' import { Message } from './components'
import { clearChatContext, fetchChatAPI } from './request' import { clearChatContext, fetchChatAPI } from './request'
import { Icon } from '@/components' import { Layout } from './layout'
import { HoverButton, SvgIcon } from '@/components/common'
interface ListProps { interface ListProps {
dateTime: string dateTime: string
@ -75,23 +76,16 @@ function addMessage(message: string, reversal = false) {
</script> </script>
<template> <template>
<div class="flex flex-col h-full overflow-hidden border rounded-md shadow-md"> <Layout>
<div class="flex flex-col h-full">
<header class="flex items-center justify-between p-4"> <header class="flex items-center justify-between p-4">
<h1 class="text-xl font-bold"> <h1 class="text-xl font-bold">
ChatGPT Web ChatGPT Web
</h1> </h1>
<div> <div class="flex items-center space-x-4">
<NPopover> <HoverButton tooltip="Clear" @click="handleClear">
<template #trigger> <SvgIcon icon="ri:delete-bin-6-line" />
<button </HoverButton>
class="w-[40px] h-[40px] rounded-full hover:bg-neutral-100 transition flex justify-center items-center"
@click="handleClear"
>
<Icon icon="ri:delete-bin-6-line" />
</button>
</template>
<span>Clear Context</span>
</NPopover>
</div> </div>
</header> </header>
<main class="flex-1 overflow-hidden border-y"> <main class="flex-1 overflow-hidden border-y">
@ -109,10 +103,11 @@ function addMessage(message: string, reversal = false) {
<NInput v-model:value="prompt" placeholder="Type a message..." @keypress="handleEnter" /> <NInput v-model:value="prompt" placeholder="Type a message..." @keypress="handleEnter" />
<NButton type="primary" :loading="loading" @click="handleSubmit"> <NButton type="primary" :loading="loading" @click="handleSubmit">
<template #icon> <template #icon>
<Icon icon="ri:send-plane-fill" /> <SvgIcon icon="ri:send-plane-fill" />
</template> </template>
</NButton> </NButton>
</div> </div>
</footer> </footer>
</div> </div>
</Layout>
</template> </template>

@ -0,0 +1,27 @@
<script setup lang='ts'>
import { NLayout, NLayoutContent, NLayoutSider } from 'naive-ui'
</script>
<template>
<div class="h-full overflow-hidden border rounded-md shadow-md">
<NLayout class="h-full" has-sider>
<NLayoutSider
collapse-mode="width"
:collapsed-width="120"
:width="240"
show-trigger="arrow-circle"
class="p-4"
bordered
>
<span>Sider</span>
</NLayoutSider>
<NLayoutContent class="h-full">
<slot />
</NLayoutContent>
</NLayout>
</div>
</template>
<style>
</style>

@ -0,0 +1,3 @@
import Layout from './Layout.vue'
export { Layout }
Loading…
Cancel
Save