-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
176 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
miniprogram_npm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "miniprogram", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "app.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"@cloudbase/wx-cloud-client-sdk": "^1.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,91 @@ | ||
Page({ | ||
data: { | ||
loading: false, | ||
}, | ||
// 表单提交事件处理函数 | ||
submitForm: function(e) { | ||
const formData = e.detail.value; | ||
console.log('表单数据', formData); | ||
// 这里可以调用后端API生成行程,或者进行其他逻辑处理 | ||
submitForm: function (e) { | ||
if (this.loading) return | ||
|
||
wx.showLoading({ | ||
title: 'AI努力生成中', | ||
}) | ||
this.setData({ | ||
loading: true | ||
}) | ||
const formData = e.detail.value; | ||
console.log('表单数据', formData); | ||
const now = new Date(); | ||
wx.cloud.callFunction({ | ||
name: "cloudbase_module", | ||
data: { | ||
name: "ai_bot_send_msg", | ||
data: { | ||
msg: JSON.stringify({ | ||
destination: formData.destination, | ||
travelDays: formData.travelDays || 3, | ||
interests: formData.interests, | ||
startDate: formData.startDate || new Date(now.getFullYear(), now.getMonth() + 1, now.getDate() + 1) | ||
}), | ||
history: [ | ||
], | ||
bot: "fd474e576688dd86007f98c3346c7bbc", | ||
}, | ||
}, | ||
success: async (res) => { | ||
if (!res.result.code) { | ||
console.log(res.result.data.content) | ||
const itinerary = this.extractAndParseJSON(res.result.data.content) | ||
|
||
const { data } = await wx.cloud.models.itinerary.create({ | ||
data: { | ||
...itinerary, | ||
start_date: new Date(itinerary.start_date).valueOf() | ||
} | ||
}); | ||
|
||
const { id } = data; | ||
wx.navigateTo({ | ||
url: `/pages/itinerary/index?_id=${id}` | ||
}); | ||
console.log(data) | ||
|
||
} | ||
}, | ||
complete: (res) => { | ||
wx.hideLoading() | ||
this.setData({ | ||
loading: false | ||
}) | ||
} | ||
}); | ||
// 这里可以调用后端API生成行程,或者进行其他逻辑处理 | ||
}, | ||
extractAndParseJSON(text) { | ||
// 正则表达式匹配直接的JSON对象或被```json```包围的JSON字符串 | ||
const jsonRegex = /\{(?:[^{}]|(?:{[^{}]*}))*\}|```json([\s\S]*?)```/; | ||
|
||
let match; | ||
while ((match = jsonRegex.exec(text)) !== null) { | ||
// 尝试解析直接的JSON对象 | ||
if (match[1]) { | ||
try { | ||
return JSON.parse(match[1]); | ||
} catch (e) { | ||
console.error('解析直接JSON对象时发生错误:', e); | ||
} | ||
} | ||
// 尝试解析被```json```包围的JSON字符串 | ||
else if (match[3]) { | ||
try { | ||
return JSON.parse(match[3]); | ||
} catch (e) { | ||
console.error('解析被```json```包围的JSON字符串时发生错误:', e); | ||
} | ||
} | ||
} | ||
|
||
// 如果没有找到匹配的JSON或解析失败,则返回null | ||
console.log('没有找到或解析JSON失败'); | ||
return null; | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.