
2026跨三端重磅ai模板 - 基于uniapp+vue3+mphtml接入deepseek-chat流式聊天ai系统。

主要增加的有:




支持运行到web+小程序+安卓端。



uni-vue3-ai支持运行到h5端,在web pc页面以750px宽度显示页面。






如上图:在项目根目录下新建.env文件,并配置如下:
# 项目名称
VITE_APPNAME = 'Uniapp-DeepSeek'
# 运行端口
VITE_PORT = 5173
# DeepSeek API配置
VITE_DEEPSEEK_API_KEY = 替换为你的APIKey
VITE_DEEPSEEK_BASE_URL = https://api.deepseek.com



<template>
<uv3-layout>
<!-- 导航栏 -->
<template #header>
<Toolbar :title="chatSession?.title" />
</template>
<view v-if="chatSession && !isEmpty(chatSession.data)" class="vu__chatview flexbox flex-col">
<scroll-view :scroll-into-view="scrollIntoView" scroll-y="true" @scrolltolower="onScrollToLower" @scroll="onScroll" style="height: 100%;">
<view class="vu__chatbot">
...
</view>
<view id="scrollbottom-placeholder" style="height: 1px;"></view>
</scroll-view>
<!-- 滚动到底部 -->
<view class="vu__scrollbottom" @click="scrollToBottom"><text class="iconfont ai-arrD fw-700"></text></view>
</view>
<!-- 欢迎信息 -->
<view v-else class="vu__welcomeinfo">
<view class="intro flex-c flex-col">
<view class="logo flex-c" style="gap: 15px;">
<view class="iconfont ai-deepseek" style="font-size: 40px;"></view>
<text style="color: #999; font-size: 20px;">+</text>
<image src="/static/uni.png" mode="widthFix" style="height: 30px; width: 30px;" />
</view>
<view class="name"><text class="txt text-gradient">嘿~ Uniapp-DeepSeek</text></view>
<view class="desc">我可以帮你写代码、答疑解惑、写作各种创意内容,请把你的任务交给我吧~</view>
</view>
<view class="prompt">
<view class="tip flex-c"><text class="flex1">试试这样问</text><view class="flex-c" @click="refreshPrompt">换一换<uni-icons type="refreshempty" color="#999" size="14" /></view></view>
<view v-for="(item,index) in promptList" :key="index">
<view class="option" @click="changePrompt(item.prompt)">{{item.emoji}} {{item.prompt}} <text class="arrow iconfont ai-arrR c-999"></text></view>
</view>
</view>
</view>
<template #footer>
<view :style="{'padding-bottom': keyboardHeight + 'px'}">
<ChatEditor ref="editorRef" v-model="promptValue" :scrollBottom="scrollToBottom" />
</view>
</template>
</uv3-layout>
</template>
之前使用rich-text组件渲染markdown,小程序端有诟病,不支持复制代码和图片预览。改为使用mp-html插件,而且该插件还支持各种其它扩展功能。
目前支持复制代码、latex公式、链接、图片预览等功能。

<template>
<view class="ua__markdown">
<mp-html :content="parseNodes" @linktap="handleLinkTap" />
</view>
</template>配置参数
const props = defineProps({
// 解析内容
source: String,
// 是否显示代码块行号(关闭后性能更优)
showLine: { type: [Boolean, String], default: true },
// 开启katex
katex: { type: Boolean, default: true },
// markdown-it插件配置
plugins: {
type: Array,
default: () => []
},
})
















H5和APP端调用renderjs里的fetch,小程序端使用uni.request实现流式功能。
// #ifdef APP-PLUS || H5
this.fetchAppH5({
url: baseURL+'/v1/chat/completions',
method: 'POST',
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${apiKEY}`,
},
body: {
// 多轮会话
messages: this.multiConversation ? this.historySession : [{role: 'user', content: editorValue}],
model: this.chatState.thinkingEnabled ? 'deepseek-reasoner' : 'deepseek-chat', // deepseek-chat对话模型 deepseek-reasoner推理模型
stream: true, // 流式输出
max_tokens: 8192, // 限制一次请求中模型生成 completion 的最大 token 数(默认使用 4096)
temperature: 0.4, // 严谨采样 越低越严谨(默认1)
}
})
// #endif小程序SSE
// #ifdef MP-WEIXIN
try {
this.loading = true
this.answerText = ''
this.reasoningText = ''
this.lastUpdate = 0
// 发起新请求前终止旧请求
const requestTask = await uni.request({
url: baseURL+'/v1/chat/completions',
method: 'POST',
header: {
"Content-Type": "application/json",
"Authorization": `Bearer ${apiKEY}`,
},
data: {
// 多轮会话
messages: this.multiConversation ? this.historySession : [{role: 'user', content: editorValue}],
model: this.chatState.thinkingEnabled ? 'deepseek-reasoner' : 'deepseek-chat',
stream: true, // 流式输出
max_tokens: 8192, // 限制一次请求中模型生成 completion 的最大 token 数(默认使用 4096)
temperature: 0.4, // 严谨采样 越低越严谨(默认1)
},
enableChunked: true, //开启分块传输 transfer-encoding chunked
success: (res) => {
const { statusCode } = res
if (statusCode !== 200) {
// 手动处理错误码
console.error('请求失败,状态码:', statusCode)
this.loading = false
this.answerText = ''
this.reasoningText = ''
uni.showToast({
title: errorMsgCode[statusCode],
icon: 'none'
})
return
}
console.log('request success', res)
},
fail: (error) => {
console.log('request fail', error)
this.loading = false
this.answerText = ''
this.reasoningText = ''
uni.showToast({
title: error.errMsg,
icon: 'none'
})
}
})
requestTask.onChunkReceived((res) => {
// console.log('Received chunk', res)
// ...
})
} catch (error) {
this.loading = false
this.chatState.updateSession(this.botKey, {loading: false})
throw new Error(`request error: ${error.message || '请求异常'}`)
}
// #endif基于uniapp接入deepseek跨端ai项目就分享到这里,感谢阅读与支持。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。