乐于分享
好东西不私藏

2026款Uniapp+DeepSeek三端流式AI解决方案,完结版!

2026款Uniapp+DeepSeek三端流式AI解决方案,完结版!

2026/02重磅跨端AI应用,基于uni-app+vue3+mphtml调用deepseek api打造【h5+小程序+安卓端】ai流式问答系统
uni-vue3-deepseek提供浅色+深色主题、新增深度思考链、复制代码、katex数学公式、链接跳转、图片预览等功能。支持运行到h5+小程序+安卓端

已关注

关注

重播 分享

编译到h5+小程序+app端效果。
https://b23.tv/T5uAsfm
技术栈
  • 开发工具:HbuilderX 4.87

  • 前端框架:uni-app+vue3+pinia2+vite5

  • 大模型框架:DeepSeek-V3.2

  • 组件库:uni-ui+uv-ui

  • 高亮插件:highlight.js

  • markdown解析:ua-markdown+mp-html

  • 本地缓存:pinia-plugin-unistorage

  • 支持编译:Web+小程序+APP端

功能点
  1. 支持编译到H5+小程序端+安卓App

  2. 新增深度思考链

  3. 新增支持katex数学公式

  4. 支持Mermaid图表渲染(仅H5端)

  5. 支持代码块顶部sticky粘性、横向滚动、行号、代码复制功能

  6. 支持各种代码高亮/复制代码、上下文多轮对话/本地会话存储

  7. 支持链接跳转、图片预览功能

  8. 修复小程序端表格边框线及各类标签选择器样式失效

项目结构目录
如下图:支持运行到三端。
2026最新款vite7+vue3接入deepseek网页版ai聊天,完结篇!
最新研发Electron39+DeepSeek电脑端AI帮手!
另外还支持运行到h5端,在pc页面以750px宽度展示页面布局。并且h5端支持mermaid图表功能。
uniapp配置环境变量.env
通过自己申请的deepseek apikey替换下项目根目录下.env文件里的key,就可以体验跨端ai能力。
# 项目名称VITE_APPNAME = 'Uniapp-DeepSeek'# 运行端口VITE_PORT = 5173# DeepSeek API配置VITE_DEEPSEEK_API_KEY = 替换为你的KeyVITE_DEEPSEEK_BASE_URL = https://api.deepseek.com
项目布局模板
<template>    <uv3-layout>        <!-- 导航栏 -->        <template #header>            <Toolbar:title="chatSession?.title" />        </template>        <viewv-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%;">                <viewclass="vu__chatbot">                    ...                </view>                <viewid="scrollbottom-placeholder"style="height: 1px;"></view>            </scroll-view>            <!-- 滚动到底部 -->            <viewclass="vu__scrollbottom" @click="scrollToBottom"><textclass="iconfont ai-arrD fw-700"></text></view>        </view>        <!-- 欢迎信息 -->        <viewv-elseclass="vu__welcomeinfo">            <viewclass="intro flex-c flex-col">                <viewclass="logo flex-c"style="gap: 15px;">                    <viewclass="iconfont ai-deepseek"style="font-size: 40px;"></view>                    <textstyle="color: #999; font-size: 20px;">+</text>                    <imagesrc="/static/uni.png"mode="widthFix"style="height: 30px; width: 30px;" />                </view>                <viewclass="name"><textclass="txt text-gradient">嘿~ Uniapp-DeepSeek</text></view>                <viewclass="desc">我可以帮你写代码、答疑解惑、写作各种创意内容,请把你的任务交给我吧~</view>            </view>            <viewclass="prompt">                <viewclass="tip flex-c"><textclass="flex1">试试这样问</text><viewclass="flex-c" @click="refreshPrompt">换一换<uni-iconstype="refreshempty"color="#999"size="14" /></view></view>                <viewv-for="(item,index) in promptList":key="index">                    <viewclass="option" @click="changePrompt(item.prompt)">{{item.emoji}} {{item.prompt}} <textclass="arrow iconfont ai-arrR c-999"></text></view>                </view>            </view>        </view>        <template #footer>            <view:style="{'padding-bottom': keyboardHeight + 'px'}">                <ChatEditorref="editorRef"v-model="promptValue":scrollBottom="scrollToBottom" />            </view>        </template>    </uv3-layout></template>
uniapp三端渲染markdown
之前是使用rich-text渲染markdown解析的富文本。由于小程序端有功能限制。改为mp-html插件渲染。
<template>    <viewclass="ua__markdown">        <mp-html:content="parseNodes" @linktap="handleLinkTap" />    </view></template>
const props = defineProps({    // 解析内容    sourceString,    // 是否显示代码块行号(关闭后性能更优)    showLine: { type: [BooleanString], defaulttrue },    // 开启katex    katex: { typeBooleandefaulttrue },    // markdown-it插件配置    plugins: {        typeArray,        default() => []    },})
目前支持各种常见的标签、表格、链接、图片预览、katex数学公式、复制代码等功能。另外mp-html还提供扩展插件,根据需要可以自己去扩展功能。
uniapp+deepseek实现流式SSE功能
由于uniapp不同端的差异性,接入deepseek流式输出,需要对不同平台做兼容处理。
h5和app端使用renderjs来实现流式。
// H5和APP端调用renderjs里的fetch// #ifdef APP-PLUS || H5this.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
小程序端使用uni.request 开启enableChuncked: true分块传输模式。
// #ifdef MP-WEIXINtry {    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模板已经正式同步到我的原创作品集。
https://b23.tv/T5uAsfm
往期推荐
最新研发Electron39+DeepSeek电脑端AI帮手!
2026最新款vite7+vue3接入deepseek网页版ai聊天,完结篇!
26最新款Vite7+DeepSeek流式输出AI模板
最新版Electron38+Vite7桌面端OS管理系统
最新研发Electron38+Vite7客户端Admin管理系统
最新版Electron38+Vite7电脑端仿微信聊天
基于Flutter3.32实战桌面端OS系统,完结篇!
最新版uniapp+vue3短视频+聊天+直播app应用
本站文章均为手工撰写未经允许谢绝转载:夜雨聆风 » 2026款Uniapp+DeepSeek三端流式AI解决方案,完结版!

评论 抢沙发

2 + 2 =
  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
×
订阅图标按钮