New file |
| | |
| | | <template> |
| | | <div> |
| | | <h2>DeepSeek 聊天</h2> |
| | | <textarea v-model="inputMessage" placeholder="请输入消息"></textarea> |
| | | <button @click="sendMessage">发送</button> |
| | | <p>回复: {{ reply }}</p> |
| | | <p v-if="error" style="color: red">{{ error }}</p> |
| | | </div> |
| | | </template> |
| | | |
| | | <script> |
| | | export default { |
| | | name: 'Chat', |
| | | data() { |
| | | return { |
| | | inputMessage: '', |
| | | reply: '', |
| | | error: '' |
| | | }; |
| | | }, |
| | | methods: { |
| | | async sendMessage() { |
| | | if (!this.inputMessage.trim()) { |
| | | this.error = '消息不能为空'; |
| | | return; |
| | | } |
| | | this.error = ''; |
| | | this.reply = ''; |
| | | |
| | | try { |
| | | const response = await fetch('http://localhost:11434/api/chat', { |
| | | method: 'POST', |
| | | headers: { |
| | | 'Content-Type': 'application/json' |
| | | }, |
| | | body: JSON.stringify({ |
| | | model: 'ltkj-jy-ai', |
| | | messages: [ |
| | | { |
| | | role: 'system', |
| | | content: this.inputMessage |
| | | } |
| | | ], |
| | | stream: false |
| | | }) |
| | | }); |
| | | |
| | | if (!response.ok) { |
| | | throw new Error('网络响应错误'); |
| | | } |
| | | |
| | | const data = await response.json(); |
| | | // 从返回数据中提取 message.content 作为回复 |
| | | this.reply = data.message?.content || '收到回复,但格式可能不正确'; |
| | | } catch (err) { |
| | | this.error = '请求出错: ' + err.message; |
| | | console.error('Fetch 错误:', err); |
| | | } |
| | | } |
| | | } |
| | | }; |
| | | </script> |
| | | |
| | | <style scoped> |
| | | textarea { |
| | | width: 300px; |
| | | height: 100px; |
| | | margin-bottom: 10px; |
| | | } |
| | | button { |
| | | padding: 5px 10px; |
| | | } |
| | | </style> |
| | |
| | | discount: item.discount, |
| | | parentProId: item.parentProId, |
| | | cusIdCard: item.cusId, |
| | | yhj: item.nowPrice |
| | | })); // 创建新的对象,包含 discount 和 id |
| | | gaibianzhekou(newArray).then((res) => { |
| | | this.loadingSubmit = false; |