首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >uni-app+mphtml快速集成DeepSeek-V4智能ai应用

uni-app+mphtml快速集成DeepSeek-V4智能ai应用

原创
作者头像
andy2018
发布2026-05-28 10:31:12
发布2026-05-28 10:31:12
330
举报
文章被收录于专栏:h5h5

经过一周迭代研发uniapp+vue3+markdown+mp-html深度对接deepseek-v4快速大模型,纯手搓打造web+小程序端+app端通用流式输出ai智能对话模板。

uniapp-vue3-ai项目支持暗黑+浅色主题、新增深度思考链、复制代码、katex数学公式、链接跳转、图片预览等功能。支持运行到H5+小程序+App端

功能支持性

  • 支持深度思考链【三端】✨
  • 支持kaTex数学公式【三端】✨
  • 支持mermaid图表【仅H5】✨
  • 支持代码块滚动粘性、横向滚动、行号、复制代码【三端】✨
  • 支持表格、链接、图片预览【三端】✨

Vite8.0+Vue3.5+Arco深度对接DeepSeek网页版AI智能助手

Electron41 + Vite8打造流式输出客户端AI助手

最新实战Vite7.3+Tauri2.10深度集成DeepSeek桌面端AI智能助手

Flutter3.41实战AI:从零到一构建app版流式ai系统

原创自研Flutter3.41+Dio+WindowManager打造桌面版AI问答系统

最新款flutter3.41 & dart3.11仿写抖音app

最新实战Flutter3.41客户端聊天程序EXE

项目结构目录

支持编译到web端,在pc页面以750px宽度布局,h5端支持mermaid图表渲染功能。

uni-app环境变量.env

代码语言:javascript
复制
# 项目名称
VITE_APPNAME = 'Uniapp-DeepSeek'

# 运行端口
VITE_PORT = 5173

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

项目通用布局

代码语言:javascript
复制
<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>

uni-app支持三端渲染markdown组件

这次升级迭代,替换原先rich-text组件为mp-html来渲染markdown内容。支持小程序katex/代码复制/图片预览等功能。

修复微信小程序里一些常用标签table、h1-h6 hr...,导致样式会失效问题。

代码语言:javascript
复制
<template>
    <view class="ua__markdown">
        <mp-html :content="parseNodes" @linktap="handleLinkTap" />
    </view>
</template>

组件配置

代码语言:javascript
复制
const props = defineProps({
    // 解析内容
    source: String,
    // 是否显示代码块行号(关闭后性能更优)
    showLine: { type: [Boolean, String], default: true },
    // 开启katex
    katex: { type: Boolean, default: true },
    // markdown-it插件配置
    plugins: {
        type: Array,
        default: () => []
    },
})

uni-app+deepseek流式sse打字效果

小程序端使用uni.request开启 enableChunked 实现流式,H5和App端采用renderjs方式fetch来实现流式功能。

  • 小程序sse
代码语言:javascript
复制
// #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}],
            // 对话模型(快速模式deepseek-v4-flash 专家模式deepseek-v4-pro)
            model: 'deepseek-v4-flash',
            // 是否深度思考
            thinking: {'type': this.chatState.thinkingEnabled ? 'enabled' : 'disabled'},
            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
  • h5/app端sse
代码语言:javascript
复制
// 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}],
        // 对话模型(快速模式deepseek-v4-flash 专家模式deepseek-v4-pro)
        model: 'deepseek-v4-flash',
        // 是否深度思考
        thinking: {'type': this.chatState.thinkingEnabled ? 'enabled' : 'disabled'},
        stream: true, // 流式输出
        max_tokens: 8192, // 限制一次请求中模型生成 completion 的最大 token 数(默认使用 4096)
        temperature: 0.4, // 严谨采样 越低越严谨(默认1)
    }
})
// #endif

最后附上几个最新实战项目

Flutter3.41构建高性能App聊天界面对话+气泡+朋友圈

Flutter3.41实战AI:从零到一构建app版流式ai系统

Electron41 + Vite8打造流式输出客户端AI助手

Vite8.0+Vue3.5+Arco深度对接DeepSeek网页版AI智能助手

2026版開工新作uni-app+mphtml结合deepseek跨端ai应用

vite7.2-deepseek流式ai对话|vue3.5+vant4+katex+mermaid智能ai打字会话

最新实战Vite7.3+Tauri2.10深度集成DeepSeek桌面端AI智能助手

electron38-vite7-vue3os电脑端os管理系统

最新版electron38-vite7-admin电脑端中后台管理系统

Electron38+Vite7+Pinia3+ElementPlus客户端聊天程序

基于tauri2.8+vite7+vue3+element-plus仿QQ/微信聊天应用

tauri2.9-vite7-vue3admin客户端后台系统管理Exe模板

最新原创uniapp-vue3-osadmin手机版后台管理系统

最新研发uniapp+vue3仿微信app聊天模板

基于uni-app+vue3实战短视频+聊天+直播app商城

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 功能支持性
  • 项目结构目录
  • uni-app环境变量.env
  • 项目通用布局
  • uni-app支持三端渲染markdown组件
  • uni-app+deepseek流式sse打字效果
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档