From 0d06fe8fb693b9228662889dac8f4f854f652f69 Mon Sep 17 00:00:00 2001 From: fhysy <1149505133@qq.com> Date: Tue, 11 Mar 2025 16:23:59 +0800 Subject: [PATCH] =?UTF-8?q?feat(fun):=20=E6=B7=BB=E5=8A=A0=20AI=20?= =?UTF-8?q?=E5=89=A7=E6=9C=AC=E7=94=9F=E6=88=90=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 素材录入页面添加 AI 生成剧本按钮 - 新增 AiDrama 页面用于与 AI 助手交互 - 实现与 DeepSeek API 的流式和非流式通信 - 添加 Markdown 渲染功能 - 优化聊天界面布局和交互 --- pages.json | 6 + pages/fun/AiDrama.vue | 634 +++++++++++++++++++++++++++++++++++++ pages/fun/markdown.js | 64 ++++ pages/fun/materialEdit.vue | 19 ++ 4 files changed, 723 insertions(+) create mode 100644 pages/fun/AiDrama.vue create mode 100644 pages/fun/markdown.js diff --git a/pages.json b/pages.json index 18ca7c4..17fa7bb 100644 --- a/pages.json +++ b/pages.json @@ -656,6 +656,12 @@ "navigationBarTitleText": "视频预览", "navigationBarBackgroundColor": "#fff" } + },{ + "path": "AiDrama", + "style": { + "navigationBarTitleText": "AI 剧本助手", + "navigationBarBackgroundColor": "#fff" + } }] }, { diff --git a/pages/fun/AiDrama.vue b/pages/fun/AiDrama.vue new file mode 100644 index 0000000..93e169b --- /dev/null +++ b/pages/fun/AiDrama.vue @@ -0,0 +1,634 @@ + + + + + \ No newline at end of file diff --git a/pages/fun/markdown.js b/pages/fun/markdown.js new file mode 100644 index 0000000..10ee336 --- /dev/null +++ b/pages/fun/markdown.js @@ -0,0 +1,64 @@ +// 简单的Markdown渲染函数 +export function renderMarkdown(content) { + if (!content) return ''; + + // 由于UniApp的rich-text组件支持HTML,我们将Markdown转换为HTML + // 这是一个简化版的Markdown解析器,仅支持基本语法 + + let html = content + // 转义HTML特殊字符 + .replace(/&/g, '&') + .replace(//g, '>') + + // 标题 + .replace(/^# (.*$)/gm, '

$1

') + .replace(/^## (.*$)/gm, '

$1

') + .replace(/^### (.*$)/gm, '

$1

') + .replace(/^#### (.*$)/gm, '

$1

') + .replace(/^##### (.*$)/gm, '
$1
') + .replace(/^###### (.*$)/gm, '
$1
') + + // 粗体和斜体 + .replace(/\*\*(.*?)\*\*/g, '$1') + .replace(/\*(.*?)\*/g, '$1') + .replace(/__(.*?)__/g, '$1') + .replace(/_(.*?)_/g, '$1') + + // 链接 + .replace(/\[([^\]]+)\]$$([^)]+)$$/g, '$1') + + // 图片 + .replace(/!\[([^\]]+)\]$$([^)]+)$$/g, '$1') + + // 无序列表 + .replace(/^\s*[-*+]\s+(.*$)/gm, '
  • $1
  • ') + + // 有序列表 + .replace(/^\s*\d+\.\s+(.*$)/gm, '
  • $1
  • ') + + // 代码块 + .replace(/```([\s\S]*?)```/g, '
    $1
    ') + + // 行内代码 + .replace(/`([^`]+)`/g, '$1') + + // 引用 + .replace(/^\> (.*$)/gm, '
    $1
    ') + + // 段落 + .replace(/\n\s*\n/g, '

    ') + + // 换行 + .replace(/\n/g, '
    '); + + // 包装在段落标签中 + html = '

    ' + html + '

    '; + + // 修复列表 + html = html.replace(/
  • .*?<\/li>/g, function(match) { + return ''; + }); + + return html; +} \ No newline at end of file diff --git a/pages/fun/materialEdit.vue b/pages/fun/materialEdit.vue index ca5ab1d..a0833c2 100644 --- a/pages/fun/materialEdit.vue +++ b/pages/fun/materialEdit.vue @@ -8,6 +8,16 @@ + + + 剧本 视频的剧本 + + + Ai生成剧本 + + {{ item.attrTitle }} {{ item.attrHint ? '(' +item.attrHint + ')' : '' }} @@ -100,6 +110,7 @@ audioType: ['.wav', '.mp3', '.aac', '.flac', '.ogg'], audioH5Type: ['wav', 'mp3', 'aac', 'flac', 'ogg'], buttonLoading:false, + scriptContent:'', // videoType: ['.avi', '.mp4', '.mkv', '.flv', '.mov', '.wmv', '.mpeg', '.3gp'], } }, @@ -112,6 +123,14 @@ this.getProductDetail(); }, methods: { + getAiDramaTxt(txt){ + this.scriptContent = txt; + }, + openAiDrama(){ + uni.navigateTo({ + url:'./AiDrama' + }) + }, getDisabledStatus(){ if(this.commitState !== 'add' && this.commitState !== 'draft' && this.commitState !== 'back'){ return true;