自研2026版uniapp+mphtml调用deepseek [小程序.安卓.H5] 流式输出ai

0 阅读2分钟

经过一个月爆肝迭代,最新款uniapp+vue3接入deepseek api跨三端ai应用,完结啦!

未标题-d.png

p2.gif

2026版vue3.5+deepseek+arco+markdown网页版ai对话模板

2026原创Electron39.2+Vue3+DeepSeek从0-1手搓AI模板桌面应用Exe

p3-1.gif

项目技术点

  • 开发工具:HbuilderX4.87
  • 技术框架:uniapp+vue3+pinia2+vite5
  • 大模型框架:DeepSeek-V3.2
  • 组件库:uni-ui+uv-ui
  • 高亮插件:highlight.js
  • markdown解析:ua-markdown+mp-html
  • 本地缓存:pinia-plugin-unistorage
  • 支持编译:Web+小程序+APP端

未标题-19.png

主要增加的有:

  1. 支持深度思考链(三端)✨
  2. 支持LaTex数学公式(三端)✨
  3. 支持Mermaid图表(H5)✨
  4. 支持代码块滚动粘性、横向滚动、行号、复制代码(三端)✨
  5. 支持表格、链接、图片预览(三端)✨

p2-1.gif

未标题-17.png

项目结构目录

360截图20260208115436883.png

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

015360截图20260207222454496.png

016360截图20260207222615937.png

017360截图20260207225332423.png

017360截图20260207225332428.png

018360截图20260207225701329.png

2026版uniapp-deepseek跨端ai项目,新增深度思考链latex数学公式代码复制图片预览、支持h5+小程序+app端

未标题-12-xcx3.png

1711bd144c084dd8f3e57e6b51346981_1289798-20260210114712217-851001040.gif

uniapp+vue3环境变量配置

72e7393dd04f56a7a37adf755c8be155_1289798-20260210115147282-482971435.png

如上图:项目根目录下新建.env配置文件。

# 项目名称
VITE_APPNAME = 'Uniapp-DeepSeek'

# 运行端口
VITE_PORT = 5173

# DeepSeek API配置
VITE_DEEPSEEK_API_KEY = 替换为你的APIKey
VITE_DEEPSEEK_BASE_URL = https://api.deepseek.com

61aadf9864ceda0d163b376f7598728f_1289798-20260210115354270-1711989573.png

项目通用布局模板

ea976a00d74a5c59285df5c71182659c_1289798-20260210115630289-736325316.png

8335b300d3be421a223911e2c1171d92_1289798-20260210115645394-1780095662.png

<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>

001360截图20260207200111691.png

002360截图20260207200642012.png

002360截图20260207201444787.png

003360截图20260207201845259.png

004360截图20260207202814067.png

005360截图20260207203900313.png

006360截图20260207205035354.png

007360截图20260207210040482.png

007360截图20260207211220569.png

007360截图20260207211458042.png

009360截图20260207213420201.png

010360截图20260207220451823.png

011360截图20260207221046543.png

012360截图20260207221205097.png

012360截图20260207221217703.png

uniapp小程序/安卓/h5渲染markdown

一开始是使用rich-text组件渲染markdown数据,但是小程序下有功能限制。最后经过一番测试,使用mphtml插件,并且该插件提供其它扩展功能。

支持小程序复制代码、latex数学公式、图片预览等功能。

09d0c77dcddd7376eb052c68d7a46d27_1289798-20260210120219009-536359625.png

<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: () => []
    },
})

image.png

ae36024063b12108550aa549b6ba2288_1289798-20260210120818946-1712495072.png

uniapp+vue3接入deepseek sse流式

h5和app端使用renderjs实现流式,小程序则使用uni.request请求实现流式。

新增深度思考链功能。

// H5和APP端调用renderjs里的fetch
// #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

小程序请求流式

// #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项目就介绍差不多了。感谢阅读与支持!

2026最新款Vite7+Vue3+DeepSeek-V3.2+Markdown移动端流式输出AI会话

electron38.2-vue3os系统|Vite7+Electron38+Pinia3+ArcoDesign桌面版OS后台管理

基于electron38+vite7+vue3 setup+elementPlus电脑端仿微信/QQ聊天软件

2025最新款Electron38+Vite7+Vue3+ElementPlus电脑端后台系统Exe

基于uni-app+vue3+uvui跨三端仿微信app聊天模板【h5+小程序+app】

基于uniapp+vue3+uvue短视频+聊天+直播app系统

自研2025版flutter3.38实战抖音app短视频+聊天+直播商城系统

基于flutter3.32+window_manager仿macOS/Wins风格桌面os系统

flutter3.27+bitsdojo_window电脑端仿微信Exe应用

自研tauri2.0+vite6.x+vue3+rust+arco-design桌面版os管理系统Tauri2-ViteOS