基于coze+微信小程序的ai对话

界面介绍:

代码:(替换你的coze的配置)

<template><view class="container"><!-- 高斯模糊背景 --><view class="animated-bg"><view class="gradient-blob"></view><view class="gradient-blob two"></view><view class="gradient-blob three"></view><view class="gradient-blob four"></view><view class="overlay"></view></view><!-- 返回按钮 --><view class="back-button" @tap="goBack"><text class="back-icon">←</text><text class="back-text">返回</text></view><!-- 头部区域 --><view class="header"><text class="logo-text">AI Assistant</text><text class="subtitle">智能学习英语,探索无限可能</text></view><!-- 搜索区域 --><view class="search-section" :class="{ 'search-focused': isFocused }"><view class="search-box"><text class="search-icon">🔍</text><input class="search-input" type="text" v-model="searchQuery"placeholder="探索任何英语问题..."@focus="handleFocus"@blur="handleBlur"@confirm="handleSearch"/><view v-if="searchQuery" @tap="clearSearch" class="clear-btn"><text class="clear-icon">✕</text></view></view></view><!-- 内容区域 --><scroll-view class="content-section" scroll-y :class="{ 'has-result': searchResult }"><!-- 默认状态 --><view class="welcome-section" v-if="!searchResult && !loading"><view class="feature-cards"><view class="feature-card"><text class="card-icon">💡</text><text class="card-title">智能问答</text></view><view class="feature-card"><text class="card-icon">🎯</text><text class="card-title">精准解析</text></view><view class="feature-card"><text class="card-icon">🚀</text><text class="card-title">即时响应</text></view></view><view class="quick-starts"><text class="section-title">快速开始</text><view class="suggestion-chips"><text class="chip" @tap="useExample('讲解英语的发展历程')">英语简史</text><text class="chip" @tap="useExample('如何有效的学习英语?')">英语学习方法</text><text class="chip" @tap="useExample('如何提高学习效率?')">提高英语学习效率</text></view></view></view><!-- 加载状态 --><view class="loading-state" v-if="loading"><view class="pulse-loader"><view class="pulse"></view><view class="pulse"></view><view class="pulse"></view></view><text class="loading-text">AI 思考中...</text></view><!-- 结果展示 --><view class="result-wrapper" v-if="searchResult"><view class="result-card"><view class="result-header"><text class="ai-badge">AI</text><text class="timestamp">{{new Date().toLocaleTimeString()}}</text></view><text class="result-text">{{searchResult}}</text></view><!-- 跟进问题 --><view class="follow-up-section" v-if="followUpQuestions.length"><text class="section-title">延伸思考</text><view class="follow-up-list"><view class="follow-up-item" v-for="(question, index) in followUpQuestions" :key="index"@tap="useExample(question)"><text class="follow-up-icon">❯</text><text class="follow-up-text">{{question}}</text></view></view></view></view></scroll-view></view>
</template><script>export default {data() {return {searchQuery: '',searchResult: '',followUpQuestions: [],loading: false,isFocused: false,// Coze API 配置cozeConfig: {apiUrl: 'https://api.coze.cn/open_api/v2/chat',token: '', // 替换为您的访问令牌botId: '', // 替换为您的机器人IDuserId: '' // 用户ID,可以根据需要修改}}},methods: {// 返回上一页goBack() {uni.navigateBack({delta: 1 // 返回的页面层数,1 表示返回上一页});},handleFocus() {this.isFocused = true},handleBlur() {this.isFocused = false},clearSearch() {this.searchQuery = ''this.searchResult = ''},useExample(text) {this.searchQuery = textthis.handleSearch()},async handleSearch() {if (!this.searchQuery.trim()) {uni.showToast({title: '请输入搜索内容',icon: 'none'});return;}this.loading = true;this.followUpQuestions = [];try {const response = await uni.request({url: this.cozeConfig.apiUrl,method: 'POST',header: {'Authorization': `Bearer ${this.cozeConfig.token}`,'Content-Type': 'application/json','Accept': '*/*','Host': 'api.coze.cn','Connection': 'keep-alive'},data: {conversation_id: Date.now().toString(),bot_id: this.cozeConfig.botId,user: this.cozeConfig.userId,query: this.searchQuery,stream: false}});// 解析响应const responseData = response[1].data; // 第二个元素才是实际数据if (responseData.code === 0) {const messages = responseData.messages || [];// 只获取类型为 answer 的第一条消息作为核心回答const answer = messages.find(msg => msg.type === 'answer');if (answer) {// 移除可能的 verbose 信息和系统提示let cleanAnswer = answer.content.replace(/\{.*?\}/g, '') // 移除 JSON 格式的内容.replace(/\[.*?\]/g, '') // 移除方括号内的内容.trim();this.searchResult = cleanAnswer;}// 获取跟进问题const followUps = messages.filter(msg => msg.type === 'follow_up');if (followUps.length > 0) {this.followUpQuestions = followUps.map(q => q.content);}} else {throw new Error('API 请求失败');}} catch (error) {console.error('API Error:', error);uni.showToast({title: '搜索失败,请重试',icon: 'none'});} finally {this.loading = false;}}}}
</script><style>.container {min-height: 100vh;position: relative;overflow: hidden;background: #f8f9fa;}.animated-bg {position: fixed;width: 100%;height: 100%;top: 0;left: 0;overflow: hidden;z-index: 0;background: linear-gradient(125deg, #00fff3, #ff00e6);animation: gradientBG 15s ease infinite;}.gradient-blob {position: absolute;width: 1000rpx;height: 1000rpx;background: linear-gradient(45deg,rgba(255, 49, 97, 0.5),rgba(255, 97, 162, 0.5));border-radius: 50%;filter: blur(80px);animation: blob-movement 20s infinite linear,color-shift 10s infinite alternate;opacity: 0.7;top: -300rpx;left: -300rpx;}.gradient-blob.two {background: linear-gradient(45deg,rgba(67, 206, 162, 0.5),rgba(24, 90, 157, 0.5));animation: blob-movement-2 25s infinite linear,color-shift-2 12s infinite alternate;animation-delay: -3s;top: 60%;left: 60%;}.gradient-blob.three {background: linear-gradient(45deg,rgba(255, 197, 84, 0.5),rgba(255, 159, 0, 0.5));animation: blob-movement-3 30s infinite linear,color-shift-3 8s infinite alternate;animation-delay: -5s;top: 40%;left: 30%;}.gradient-blob.four {background: linear-gradient(45deg,rgba(147, 88, 255, 0.5),rgba(19, 123, 255, 0.5));animation: blob-movement-4 28s infinite linear,color-shift-4 15s infinite alternate;animation-delay: -7s;top: 20%;left: 70%;}.overlay {position: absolute;top: 0;left: 0;right: 0;bottom: 0;background: rgba(255, 255, 255, 0.2);backdrop-filter: blur(20px);}@keyframes gradientBG {0% {background-position: 0% 50%;}50% {background-position: 100% 50%;}100% {background-position: 0% 50%;}}@keyframes blob-movement {0% {transform: translate(0, 0) scale(1) rotate(0deg);}33% {transform: translate(300rpx, 200rpx) scale(1.2) rotate(120deg);}66% {transform: translate(-200rpx, 400rpx) scale(0.8) rotate(240deg);}100% {transform: translate(0, 0) scale(1) rotate(360deg);}}@keyframes blob-movement-2 {0% {transform: translate(0, 0) scale(1.1) rotate(0deg);}33% {transform: translate(-250rpx, -300rpx) scale(0.9) rotate(120deg);}66% {transform: translate(300rpx, -200rpx) scale(1.2) rotate(240deg);}100% {transform: translate(0, 0) scale(1.1) rotate(360deg);}}@keyframes blob-movement-3 {0% {transform: translate(0, 0) scale(0.9) rotate(0deg);}33% {transform: translate(400rpx, -100rpx) scale(1.1) rotate(120deg);}66% {transform: translate(-300rpx, 200rpx) scale(0.8) rotate(240deg);}100% {transform: translate(0, 0) scale(0.9) rotate(360deg);}}@keyframes blob-movement-4 {0% {transform: translate(0, 0) scale(1) rotate(0deg);}33% {transform: translate(-200rpx, 300rpx) scale(1.1) rotate(120deg);}66% {transform: translate(250rpx, -250rpx) scale(0.9) rotate(240deg);}100% {transform: translate(0, 0) scale(1) rotate(360deg);}}@keyframes color-shift {0% {background: linear-gradient(45deg, rgba(255, 49, 97, 0.5), rgba(255, 97, 162, 0.5));}100% {background: linear-gradient(45deg, rgba(255, 182, 193, 0.5), rgba(255, 20, 147, 0.5));}}@keyframes color-shift-2 {0% {background: linear-gradient(45deg, rgba(67, 206, 162, 0.5), rgba(24, 90, 157, 0.5));}100% {background: linear-gradient(45deg, rgba(0, 255, 255, 0.5), rgba(0, 128, 128, 0.5));}}@keyframes color-shift-3 {0% {background: linear-gradient(45deg, rgba(255, 197, 84, 0.5), rgba(255, 159, 0, 0.5));}100% {background: linear-gradient(45deg, rgba(255, 215, 0, 0.5), rgba(255, 140, 0, 0.5));}}@keyframes color-shift-4 {0% {background: linear-gradient(45deg, rgba(147, 88, 255, 0.5), rgba(19, 123, 255, 0.5));}100% {background: linear-gradient(45deg, rgba(138, 43, 226, 0.5), rgba(65, 105, 225, 0.5));}}/* 头部样式 */.header {padding: 60rpx 40rpx;text-align: center;z-index: 1;position: relative;}.logo-text {font-size: 48rpx;color: #1a1a1a;font-weight: 600;letter-spacing: 2rpx;text-shadow: 0 2px 4px rgba(255, 255, 255, 0.2);}.subtitle {font-size: 28rpx;color: rgba(0, 0, 0, 0.7);margin-top: 16rpx;display: block;}/* 搜索框样式 */.search-section {padding: 20rpx 40rpx;position: relative;z-index: 2;}.search-box {background: rgba(255, 255, 255, 0.2);backdrop-filter: blur(20px);border-radius: 20rpx;padding: 24rpx 32rpx;display: flex;align-items: center;border: 1px solid rgba(255, 255, 255, 0.3);transition: all 0.3s ease;}.search-box:hover {background: rgba(255,255,255,0.15);}.search-input {flex: 1;margin: 0 20rpx;font-size: 32rpx;color: #1a1a1a;height: 48rpx;line-height: 48rpx;}.search-icon, .clear-icon {font-size: 32rpx;color: rgba(255,255,255,0.6);}/* 功能卡片 */.feature-cards {display: flex;justify-content: space-around;padding: 40rpx;gap: 20rpx;}.feature-card {background: rgba(255, 255, 255, 0.2);backdrop-filter: blur(10px);border-radius: 16rpx;padding: 30rpx;text-align: center;flex: 1;border: 1px solid rgba(255, 255, 255, 0.3);transition: all 0.3s ease;}.feature-card:active {transform: scale(0.98);background: rgba(255,255,255,0.15);}.card-icon {font-size: 48rpx;margin-bottom: 16rpx;display: block;}.card-title {color: #fff;font-size: 28rpx;}/* 建议词条 */.quick-starts {padding: 40rpx;}.section-title {color: rgba(0, 0, 0, 0.7);font-size: 28rpx;margin-bottom: 20rpx;display: block;}.suggestion-chips {display: flex;flex-wrap: wrap;gap: 16rpx;}.chip {background: rgba(255,255,255,0.1);padding: 16rpx 32rpx;border-radius: 100rpx;color: #fff;font-size: 28rpx;transition: all 0.3s ease;}.chip:active {background: rgba(255,255,255,0.2);transform: scale(0.98);}/* 加载动画 */.loading-state {padding: 60rpx;text-align: center;}.pulse-loader {display: flex;justify-content: center;gap: 12rpx;}.pulse {width: 16rpx;height: 16rpx;background: #fff;border-radius: 50%;animation: pulse 1.5s infinite ease-in-out;}.pulse:nth-child(2) { animation-delay: 0.2s; }.pulse:nth-child(3) { animation-delay: 0.4s; }@keyframes pulse {0%, 100% { transform: scale(0.5); opacity: 0.2; }50% { transform: scale(1); opacity: 1; }}.loading-text {color: rgba(255,255,255,0.7);font-size: 28rpx;margin-top: 20rpx;display: block;}/* 结果卡片 */.result-wrapper {padding: 40rpx;}.result-card {background: rgba(255, 255, 255, 0.2);backdrop-filter: blur(15px);border-radius: 20rpx;padding: 30rpx;border: 1px solid rgba(255, 255, 255, 0.3);animation: slideUp 0.3s ease;}.result-header {display: flex;justify-content: space-between;align-items: center;margin-bottom: 20rpx;}.ai-badge {background: linear-gradient(135deg, #7C3AED, #3B82F6);color: #fff;padding: 6rpx 16rpx;border-radius: 8rpx;font-size: 24rpx;}.timestamp {color: rgba(255,255,255,0.5);font-size: 24rpx;}.result-text {color: #1a1a1a;font-size: 30rpx;line-height: 1.6;}/* 跟进问题 */.follow-up-section {margin-top: 40rpx;}.follow-up-list {display: flex;flex-direction: column;gap: 16rpx;}.follow-up-item {background: rgba(255, 255, 255, 0.15);padding: 24rpx;border-radius: 16rpx;display: flex;align-items: center;transition: all 0.3s ease;backdrop-filter: blur(10px);}.follow-up-item:active {background: rgba(255,255,255,0.15);transform: translateX(10rpx);}.follow-up-icon {color: rgba(255,255,255,0.5);margin-right: 16rpx;font-size: 24rpx;}.follow-up-text {color: #1a1a1a;font-size: 28rpx;}@keyframes slideUp {from { opacity: 0;transform: translateY(20rpx);}to {opacity: 1;transform: translateY(0);}}.search-input::placeholder {color: rgba(0, 0, 0, 0.4);}.back-button {position: fixed;top: 40rpx;left: 20rpx;display: flex;align-items: center;padding: 10rpx 20rpx;background: rgba(255, 255, 255, 0.8);border-radius: 50rpx;backdrop-filter: blur(10px);z-index: 999;box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);}.back-icon {font-size: 36rpx;margin-right: 10rpx;color: #333;}.back-text {font-size: 28rpx;color: #333;}
</style>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/diannao/71974.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Day11,Hot100(贪心算法)

贪心 &#xff08;1&#xff09;121. 买卖股票的最佳时机 第 i 天卖出的最大利润&#xff0c;即在前面最低价的时候买入 class Solution:def maxProfit(self, prices: List[int]) -> int:min_price prices[0]ans 0for price in prices:ans max(ans, price - min_price…

Linux内核自定义协议族开发指南:理解net_device_ops、proto_ops与net_proto_family

在Linux内核中开发自定义协议族需要深入理解网络协议栈的分层模型。net_device_ops、proto_ops和net_proto_family是三个关键结构体,分别作用于不同的层次。本文将详细解析它们的作用、交互关系及实现方法,并提供一个完整的开发框架。 一、核心结构体的作用与层级关系 struct…

SpringBoot 中的 Redis 序列化

SpringBoot 中的 Redis 序列化 在 Spring Boot 中&#xff0c;Redis 的序列化是指将 Java 对象转换为字节流&#xff08;序列化&#xff09;以便存储到 Redis 中&#xff0c;以及从 Redis 中读取字节流并将其转换回 Java 对象&#xff08;反序列化&#xff09;。 这是因为在 R…

vLLM服务设置开机自启动(Linux)

要在开机时进入指定的 conda 环境并启动此 vllm 服务&#xff0c;您可以通过以下步骤设置一个 systemd 服务来自动执行脚本。 一、第一步&#xff1a;创建一个启动脚本 1.打开终端并创建启动脚本&#xff0c;例如 /home/username/start_vllm.sh&#xff08;请替换 username 为…

AI绘画软件Stable Diffusion详解教程(3):Windows系统本地化部署操作方法(通用版)

上一篇教程介绍了如何在本地部署Stable Diffusion专业版&#xff0c;虽然便于技术人员研究&#xff0c;但是普通人使用起来不便捷&#xff0c;每次只能通过cmd窗口的指令形式或者python代码方式来画图&#xff0c;要记很多的指令很繁琐。 本篇教程教您搭建webui版的&#xff0…

大数据SQL调优专题——调优切入

引入 我们都知道大数据的SQL优化&#xff0c;并非一蹴而就的简单任务&#xff0c;而是一个涉及多个环节的复杂过程。虽然我们的专栏名字叫大数据SQL调优&#xff0c;但是调优并不是简单对SQL优化&#xff0c;而是一个涉及多个环节的复杂过程。实际上从需求接入到最终交付&…

贪心算法精品题

1.找钱问题 本题的贪心策略在于我们希望就可能的保留作用大的5元 class Solution { public:bool lemonadeChange(vector<int>& bills) {std::map<int ,int> _map;for(auto ch:bills){if(ch 5) _map[ch];else if(ch 10){if(_map[5] 0) return false;else{_m…

spring结合mybatis多租户实现单库分表

实现单库分表 思路&#xff1a;student表数据量大&#xff0c;所以将其进行分表处理。一共有三个分表&#xff0c;分别是student0&#xff0c;student1&#xff0c;student2&#xff0c;在新增数据的时候&#xff0c;根据请求头中的meta-tenant参数决定数据存在哪张表表。 数…

Ecode前后端传值

说明 在泛微 E9 系统开发过程中&#xff0c;使用 Ecode 调用后端接口并进行传值是极为常见且关键的操作。在上一篇文章中&#xff0c;我们探讨了 Ecode 调用后端代码的相关内容&#xff0c;本文将深入剖析在 Ecode 中如何向后端传值&#xff0c;以及后端又该如何处理接收这些值…

黑马Java面试教程_P5_微服务

系列博客目录 文章目录 系列博客目录1.引言2.Spring Cloud2.1 Spring Cloud 5大组件有哪些?面试文稿 2.2 服务注册和发现是什么意思?Spring Cloud 如何实现服务注册发现?面试文稿 2.3 我看你之前也用过nacos、你能说下nacos与eureka的区别?面试文稿 2.4 你们项目负载均衡如…

【2025深度学习环境搭建-2】pytorch+Docker+VS Code+DevContainer搭建本地深度学习环境

上一篇文章&#xff1a;【2025深度学习环境搭建-1】在Win11上用WSL2和Docker解锁GPU加速 先启动Docker&#xff01;对文件内容有疑问&#xff0c;就去问AI 一、用Docker拉取pytorch镜像&#xff0c;启动容器&#xff0c;测试GPU docker pull pytorch/pytorch:2.5.0-cuda12.4…

Linux驱动开发实战(一):LED控制驱动详解

Linux驱动开发野火实战&#xff08;一&#xff09;&#xff1a;LED控制驱动详解 文章目录 Linux驱动开发野火实战&#xff08;一&#xff09;&#xff1a;LED控制驱动详解引言一、基础知识1.1 什么是字符设备驱动1.2 重要的数据结构read 函数write 函数open 函数release 函数 二…

Linux上用C++和GCC开发程序实现不同MySQL实例下单个Schema之间的稳定高效的数据迁移

设计一个在Linux上运行的GCC C程序&#xff0c;同时连接两个不同的MySQL实例&#xff0c;两个实例中分别有两个Schema的表结构完全相同&#xff0c;复制一个实例中一个Schema里的所有表的数据到另一个实例中一个Schema里&#xff0c;使用以下快速高效的方法&#xff0c;加入异常…

Redis除了做缓存还能做什么?

Redis 除了作为高性能缓存外&#xff0c;还因其丰富的数据结构和功能&#xff0c;广泛应用于多种场景。以下是 Redis 的十大核心用途及具体示例&#xff1a; 1. 分布式会话存储 用途&#xff1a;存储用户会话信息&#xff08;如登录状态&#xff09;&#xff0c;实现多服务间共…

JBoltAI_SpringBoot如何区分DeepSeek R1深度思考和具体回答的内容(基于Ollama)?

当我们用Ollama运行DeepSeek R1模型&#xff0c;向它提问时&#xff0c;会发现它的回答里是有think标签的 如果我们直接将Ollama的回复用于生产环境&#xff0c;肯定是不行的&#xff0c;对于不同的场景&#xff0c;前面输出的一堆内容&#xff0c;可能并不需要在客户端展示&a…

MySQL 使用 `WHERE` 子句时 `COUNT(*)`、`COUNT(1)` 和 `COUNT(column)` 的区别解析

文章目录 1. COUNT() 函数的基本作用2. COUNT(*)、COUNT(1) 和 COUNT(column) 的详细对比2.1 COUNT(*) —— 统计所有符合条件的行2.2 COUNT(1) —— 统计所有符合条件的行2.3 COUNT(column) —— 统计某一列非 NULL 的记录数 3. 性能对比3.1 EXPLAIN 分析 4. 哪种方式更好&…

将DeepSeek接入vscode的N种方法

接入deepseek方法一:cline 步骤1:安装 Visual Studio Code 后,左侧导航栏上点击扩展。 步骤2:搜索 cline,找到插件后点击安装。 步骤3:在大模型下拉菜单中找到deep seek,然后下面的输入框输入你在deepseek申请的api key,就可以用了 让deepseek给我写了一首关于天气的…

AndroidManifest.xml文件的作用

AndroidManifest.xml文件在Android应用程序中扮演着至关重要的角色。它是应用程序的全局配置文件&#xff0c;提供了关于应用程序的所有必要信息&#xff0c;这些信息对于Android系统来说是至关重要的&#xff0c;因为它决定了应用程序的运行方式和权限要求&#xff0c;确保了应…

Mac本地部署Deep Seek R1

Mac本地部署Deep Seek R1 1.安装本地部署大型语言模型的工具 ollama 官网&#xff1a;https://ollama.com/ 2.下载Deepseek R1模型 网址&#xff1a;https://ollama.com/library/deepseek-r1 根据电脑配置&#xff0c;选择模型。 我的电脑&#xff1a;Mac M3 24G内存。 这…

React进阶之前端业务Hooks库(五)

前端业务Hooks库 Hooks原理useStateuseEffect上述问题useState,useEffect 复用的能力练习:怎样实现一套React过程中的hooks状态 & 副作用Hooks原理 不能在循环中、条件判断、子函数中调用,只能在函数最外层去调用useEffect 中,deps 为空,执行一次useState 使用: imp…