国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

基于vue3+pinia2仿ChatGPT聊天實例|vite4.x仿chatgpt界面

這篇具有很好參考價值的文章主要介紹了基于vue3+pinia2仿ChatGPT聊天實例|vite4.x仿chatgpt界面。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

使用vue3+pinia2開發(fā)仿制chatgpt界面聊天實例Vue3-Chatgpt

基于Vue3.x+Pinia2+VueRouter+Vue3-Markdown等技術(shù)構(gòu)建仿ChatGPT網(wǎng)頁端聊天程序。支持經(jīng)典+分欄界面布局、light/dark模式、全屏+半屏顯示、Markdown語法解析、側(cè)邊欄隱藏等功能。

基于vue3+pinia2仿ChatGPT聊天實例|vite4.x仿chatgpt界面
基于vue3+pinia2仿ChatGPT聊天實例|vite4.x仿chatgpt界面

技術(shù)框架

  • 編輯工具:Cursor
  • 框架技術(shù):Vue3+Vite4.x+Pinia2
  • 組件庫:VEPlus (基于vue3桌面端組件庫)
  • 國際化多語言:vue-i18n^9.2.2
  • 代碼高亮:highlight.js^11.7.0
  • 本地存儲:pinia-plugin-persistedstate^3.1.0
  • markdown解析:vue3-markdown-it

基于vue3+pinia2仿ChatGPT聊天實例|vite4.x仿chatgpt界面
基于vue3+pinia2仿ChatGPT聊天實例|vite4.x仿chatgpt界面

項目目錄結(jié)構(gòu)

基于vue3+pinia2仿ChatGPT聊天實例|vite4.x仿chatgpt界面
基于vue3+pinia2仿ChatGPT聊天實例|vite4.x仿chatgpt界面
基于vue3+pinia2仿ChatGPT聊天實例|vite4.x仿chatgpt界面
基于vue3+pinia2仿ChatGPT聊天實例|vite4.x仿chatgpt界面
基于vue3+pinia2仿ChatGPT聊天實例|vite4.x仿chatgpt界面
基于vue3+pinia2仿ChatGPT聊天實例|vite4.x仿chatgpt界面
基于vue3+pinia2仿ChatGPT聊天實例|vite4.x仿chatgpt界面
基于vue3+pinia2仿ChatGPT聊天實例|vite4.x仿chatgpt界面
基于vue3+pinia2仿ChatGPT聊天實例|vite4.x仿chatgpt界面
基于vue3+pinia2仿ChatGPT聊天實例|vite4.x仿chatgpt界面
基于vue3+pinia2仿ChatGPT聊天實例|vite4.x仿chatgpt界面
基于vue3+pinia2仿ChatGPT聊天實例|vite4.x仿chatgpt界面
基于vue3+pinia2仿ChatGPT聊天實例|vite4.x仿chatgpt界面
基于vue3+pinia2仿ChatGPT聊天實例|vite4.x仿chatgpt界面

vite.config.js配置

import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
import { parseEnv } from './src/utils/env'

// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
	const viteEnv = loadEnv(mode, process.cwd())
	const env = parseEnv(viteEnv)

	return {
		plugins: [vue()],

		// base: '/',
		// mode: 'development', // development|production

		/*構(gòu)建選項*/
		build: {
			// minify: 'esbuild', // 打包方式 esbuild(打包快)|terser
			// chunkSizeWarningLimit: 2000, // 打包大小警告
			// rollupOptions: {
			// 	output: {
			// 		chunkFileNames: 'assets/js/[name]-[hash].js',
			// 		entryFileNames: 'assets/js/[name]-[hash].js',
			// 		assetFileNames: 'assets/[ext]/[name]-[hash].[ext]',
			// 	}
			// }
		},
		esbuild: {
			// 打包去除 console.log 和 debugger
			drop: env.VITE_DROP_CONSOLE ? ['console', 'debugger'] : []
		},

		/*開發(fā)服務(wù)器選項*/
		server: {
			// 端口
			port: env.VITE_PORT,
			// 是否瀏覽器自動打開
			open: env.VITE_OPEN,
			// 開啟https
			https: env.VITE_HTTPS,
			// 代理配置
			proxy: {
				// ...
			}
		},

		resolve: {
			// 設(shè)置別名
			alias: {
				'@': resolve(__dirname, 'src'),
				'@assets': resolve(__dirname, 'src/assets'),
				'@components': resolve(__dirname, 'src/components'),
				'@views': resolve(__dirname, 'src/views'),
				// 解決vue-i18n警告提示:You are running the esm-bundler build of vue-i18n.
				'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js'
			}
		}
	}
})

main.js主入口

import { createApp } from 'vue'
import App from './App.vue'

// 引入Router和Store
import Router from './router'
import Store from './store'

// 引入插件配置
import Plugins from './plugins'

const app = createApp(App)

app
.use(Router)
.use(Store)
.use(Plugins)
.mount('#app')

vue3.x組件庫

項目中使用的組件庫是基于vue3自定義UI組件庫Ve-plus。一個支持40+組件的輕量級組件庫。
基于vue3+pinia2仿ChatGPT聊天實例|vite4.x仿chatgpt界面

基于vue3+pinia2仿ChatGPT聊天實例|vite4.x仿chatgpt界面
安裝組件

yarn add ve-plus
npm i ve-plus --save

https://blog.csdn.net/yanxinyun1990/article/details/129312570

整體布局

項目支持2種布局模式,整體分為頂欄+側(cè)邊欄+主體內(nèi)容三大模塊構(gòu)成。
基于vue3+pinia2仿ChatGPT聊天實例|vite4.x仿chatgpt界面

基于vue3+pinia2仿ChatGPT聊天實例|vite4.x仿chatgpt界面

<div class="ve__layout-body flex1 flexbox">
	<!-- //中間欄 -->
	<div class="ve__layout-menus flexbox" :class="{'hidden': store.config.collapse}">
		<aside class="ve__layout-aside flexbox flex-col">
			<ChatNew />
			<Scrollbar class="flex1" autohide size="4" gap="1">
				<ChatList />
			</Scrollbar>
			<ExtraLink />
			<Collapse />
		</aside>
	</div>

	<!-- //右邊欄 -->
	<div class="ve__layout-main flex1 flexbox flex-col">
		<!-- 主內(nèi)容區(qū) -->
		<Main />
	</div>
</div>
<template>
	<div class="vegpt__editor">
		<div class="vegpt__editor-inner">
			<Flex :gap="0">
				<Popover placement="top" trigger="click" width="150">
					<Button class="btn" type="link" icon="ve-icon-yuyin1" v-tooltip="{content: '發(fā)送語音', theme: 'light', arrow: false}"></Button>
					<template #content>
						<div class="flexbox flex-alignc flex-col" style="padding: 15px 0;">
							<Icon name="ve-icon-yuyin" size="40" color="#0fa27e" />
							<p class="fs-12 mb-15 c-999">網(wǎng)絡(luò)不給力</p>
							<Button size="small"><i style="background:#f00;border-radius:50%;box-shadow:0 1px 2px #999;margin-right:5px;height:8px;width:8px;"></i>開始講話</Button>
						</div>
					</template>
				</Popover>
				<Button class="btn" type="link" v-tooltip="{content: '發(fā)送圖片', theme: 'light', arrow: false}">
					<Icon name="ve-icon-photo" size="16" cursor />
					<input ref="uploadImgRef" type="file" title="" accept="image/*" @change="handleUploadImage" />
				</Button>
				<Input
					class="flex1"
					ref="editorRef"
					v-model="editorText"
					type="textarea"
					:autosize="{maxRows: 4}"
					clearable
					placeholder="Prompt..."
					@keydown="handleKeydown"
					@clear="handleClear"
					style="margin: 0 5px;"
				/>
				<Button class="btn" type="link" icon="ve-icon-submit" @click="handleSubmit"></Button>
			</Flex>
		</div>
	</div>
</template>
import { ref, watch } from 'vue'
import { guid } from '@/utils'
import { chatStore } from '@/store/modules/chat'

const props = defineProps({
	value: { type: [String, Number] }
})
const emit = defineEmits(['clear'])

const chatState = chatStore()

const uploadImgRef = ref()
const editorRef = ref()
const editorText = ref(props.value)

// ...

// 發(fā)送會話
const handleSubmit = () => {
	editorRef.value.focus()
	if(!editorText.value) return

	let data = {
		type: 'text',
		role: 'User',
		key: guid(),
		content: editorText.value
	}
	chatState.addSession(data)
	// 清空
	editorText.value = ''
}
const handleKeydown = (e) => {
	// ctrl+enter
	if(e.ctrlKey && e.keyCode == 13) {
		handleSubmit()
	}
}
const handleClear = () => {
	emit('clear')
}
// 選擇圖片
const handleUploadImage = () => {
	let file = uploadImgRef.value.files[0]
	if(!file) return
	let size = Math.floor(file.size / 1024)
	console.log(size)
	if(size > 2*1024) {
		Message.danger('圖片大小不能超過2M')
		uploadImgRef.value.value = ''
		return false
	}
	let reader = new FileReader()
	reader.readAsDataURL(file)
	reader.onload = function() {
		let img = this.result

		let data = {
			type: 'image',
			role: 'User',
			key: guid(),
			content: img
		}
		chatState.addSession(data)
	}
}

基于vue3+pinia2仿ChatGPT聊天實例|vite4.x仿chatgpt界面

/**
 * 聊天狀態(tài)管理
 * @author YXY  Q:282310962
 */

import { defineStore } from 'pinia'
import { guid, isEmpty } from '@/utils'

export const chatStore = defineStore('chat', {
	state: () => ({
		// 聊天會話記錄
		sessionId: '',
		session: []
	}),
	getters: {},
	actions: {
		// 創(chuàng)建新會話
		createSession(ssid) {
			this.sessionId = ssid
			this.session.push({
				sessionId: ssid,
				title: '',
				data: []
			})
		},

		// 新增會話
		addSession(message) {
			// 判斷當前會話uuid是否存在,不存在創(chuàng)建新會話
			if(!this.sessionId) {
				const ssid = guid()
				this.createSession(ssid)
			}
			this.session.map(item => {
				if(item.sessionId == this.sessionId) {
					if(!item.title) {
						item.title = message.content
					}
					item.data.push(message)
				}
			})
			// ...
		},

		// 獲取會話
		getSession() {
			return this.session.find(item => item.sessionId == this.sessionId)
		},

		// 移除會話
		removeSession(ssid) {
			const index = this.session.findIndex(item => item?.sessionId === ssid)
			if(index > -1) {
				this.session.splice(index, 1)
			}
			this.sessionId = ''
		},
		// 刪除某一條會話
		deleteSession(ssid) {
			// ...
		},

		// 清空會話
		clearSession() {
			this.session = []
			this.sessionId = ''
		}
	},
	// 本地持久化存儲(默認存儲localStorage)
	persist: true
	/* persist: {
		// key: 'chatStore', // 不設(shè)置則是默認app
		storage: localStorage,
		paths: ['aa', 'bb'] // 設(shè)置緩存鍵
	} */
})

好了,基于vue3+vite4+pinia2開發(fā)模仿chatgpt聊天就分享到這里。

Tauri-Vue3聊天實例|Tauri跨端聊天
uniapp-ttlive短視頻聊天|uniapp+uview仿抖音實例

基于vue3+pinia2仿ChatGPT聊天實例|vite4.x仿chatgpt界面文章來源地址http://www.zghlxwxcb.cn/news/detail-438630.html

到了這里,關(guān)于基于vue3+pinia2仿ChatGPT聊天實例|vite4.x仿chatgpt界面的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • Vite4+Typescript+Vue3+Pinia 從零搭建(7) - request封裝

    Vite4+Typescript+Vue3+Pinia 從零搭建(7) - request封裝

    項目代碼同步至碼云 weiz-vue3-template 基于 axios 封裝請求,支持多域名請求地址 utils 目錄下新建 request 文件夾,并新建 index.ts 、 request.ts 和 status.ts 文件。 此時,eslint會報 switch 前面的空格錯誤,需要修改 .eslintrc.cjs 里的 indent ,修改后,錯誤消失。 src 目錄下新建 api 文件夾,

    2024年02月04日
    瀏覽(98)
  • Vite4+Typescript+Vue3+Pinia 從零搭建(2) - ts配置

    項目代碼同步至碼云 weiz-vue3-template 關(guān)于tsconfig的配置字段可查看其他文檔,如 typeScript tsconfig配置詳解 文件修改如下: 修改文件如下: 新建文件夾 types ,用來存放類型定義。比如新建 index.d.ts : 后續(xù)也可以新增其他文件,比如 global.d.ts 存放全局定義, router.d.ts 存放路由定

    2024年02月05日
    瀏覽(101)
  • Vite4+Typescript+Vue3+Pinia 從零搭建(3) - vite配置

    Vite4+Typescript+Vue3+Pinia 從零搭建(3) - vite配置

    項目代碼同步至碼云 weiz-vue3-template 關(guān)于vite的詳細配置可查看 vite官方文檔,本文簡單介紹vite的常用配置。 項目初建后, vite.config.ts 的默認內(nèi)容如下: 比如,修改 App.vue : 根目錄下新建 .env 、 .env.development 、 .env.production 三個文件。 .env 文件內(nèi)新增內(nèi)容: .env.development 文件內(nèi)

    2024年02月05日
    瀏覽(86)
  • Vite4+Typescript+Vue3+Pinia 從零搭建(5) - 路由router

    Vite4+Typescript+Vue3+Pinia 從零搭建(5) - 路由router

    項目代碼同步至碼云 weiz-vue3-template Vue Router 是 Vue.js 的官方路由。它與 Vue.js 核心深度集成,讓用 Vue.js 構(gòu)建單頁應(yīng)用變得輕而易舉。 在 src/view 下新建 home.vue 和 login.vue ,內(nèi)容如下: login.vue 里修改下對應(yīng)name即可 index.ts 作為路由入口, static.ts 作為靜態(tài)路由, modules 內(nèi)還可以

    2024年02月05日
    瀏覽(100)
  • Vite4+Typescript+Vue3+Pinia 從零搭建(6) - 狀態(tài)管理pina

    Vite4+Typescript+Vue3+Pinia 從零搭建(6) - 狀態(tài)管理pina

    項目代碼同步至碼云 weiz-vue3-template pina 是 vue3 官方推薦的狀態(tài)管理庫,由 Vue 核心團隊維護,旨在替代 vuex。pina 的更多介紹,可從 pina官網(wǎng) 查看 更簡潔直接的 API,提供組合式風(fēng)格的 API 支持模塊熱更新和服務(wù)端渲染 對TS支持更為友好 src目錄下新建store文件夾,并新建index.t

    2024年02月05日
    瀏覽(23)
  • Vue3 Vite4 ElementPlus TS模板(含Vue-Router4+Pinia4)

    Vue3 Vite4 ElementPlus TS模板(含Vue-Router4+Pinia4)

    手動安裝配置Vue3 ElementPlus模板比較繁瑣,網(wǎng)上尋找一些模板不太符合自己預(yù)期,因此花點精力搭建一個符合自己需求的架子 采用最新的組件,版本如下: vite 4.3.9 vite-plugin-mock 2.9.8 vue 3.3.4 pinia 2.1.3 vue-router 4.2.2 element-plus 2.3.6 滿足自己以下功能: Vite工具熱啟動速度快,修改后

    2024年02月08日
    瀏覽(24)
  • Electron-ChatGPT桌面端ChatGPT實例|electron25+vue3聊天AI模板EXE

    Electron-ChatGPT桌面端ChatGPT實例|electron25+vue3聊天AI模板EXE

    基于 electron25+vite4+vue3 仿制chatgpt客戶端聊天模板 ElectronChatGPT 。 electron-chatgpt 使用最新桌面端技術(shù) Electron25.x 結(jié)合 Vite4.x 全家桶技術(shù)開發(fā)跨端模仿ChatGPT智能聊天程序模板。支持 經(jīng)典+分欄兩種布局、暗黑+明亮主題模式,集成electron封裝多窗口及通訊 功能。 編碼工具:vscode 框架

    2024年02月08日
    瀏覽(21)
  • Vue3.2 + TypeScript + Pinia + Vite4 + Element-Plus + 微前端(qiankun) 后臺管理系統(tǒng)模板(已開源---顯示項目頁面截圖)

    Vue3.2 + TypeScript + Pinia + Vite4 + Element-Plus + 微前端(qiankun) 后臺管理系統(tǒng)模板(已開源---顯示項目頁面截圖)

    Wocwin-Admin,是基于 Vue3.2、TypeScript、Vite、Pinia、Element-Plus、Qiankun(微前端) 開源的一套后臺管理模板;同時集成了微前端 qiankun也可以當做一個子應(yīng)用。項目中組件頁面使用了Element-plus 二次封裝 t-ui-plus 組件,目前已新增fastmock接口。 Link:https://wocwin.github.io/wocwin-admin/ 賬號:

    2024年02月08日
    瀏覽(40)
  • 基于Electron24+Vite4+Vue3搭建桌面端應(yīng)用

    基于Electron24+Vite4+Vue3搭建桌面端應(yīng)用

    一說到創(chuàng)建桌面應(yīng)用,就不得不提及Electron和Tauri框架。這次給大家主要分享的是基于electron最新版本整合vite4.x構(gòu)建vue3桌面端應(yīng)用程序。 之前也有使用vite2+vue3+electronc創(chuàng)建桌面端項目,不過? vue-cli-plugin-electron-builder ?腳手架插件構(gòu)建的項目electron版本只有13.x。如今electron版本

    2024年02月06日
    瀏覽(46)
  • 基于uni-app+vue3跨端「h5+小程序+App」仿制chatGPT模板實例

    基于uni-app+vue3跨端「h5+小程序+App」仿制chatGPT模板實例

    uni-chatgpt 一款uniapp+vite4+uview-plus多端ChatGPT模板實例。 全新首發(fā)的一款多端仿制chatgpt智能對話實戰(zhàn)項目,基于 uniApp+Vue3+Pinia+uViewUI+MarkdownIt 等技術(shù)開發(fā)搭建項目。支持編譯到 h5+小程序+APP端 ,支持markdown語法解析及代碼高亮。 全屏沉浸式頂部導(dǎo)航條+底部tabbar 支持解析h5+小程序

    2024年02月12日
    瀏覽(27)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包