feat(ai-house): 支持 Markdown 并优化找房交互

This commit is contained in:
2026-08-08 06:48:09 +08:00
parent d6861ab8c4
commit 87890a10ed
8 changed files with 138 additions and 241 deletions
+23 -41
View File
@@ -29,47 +29,29 @@ function createPageVm() {
return vm
}
function receiveLocationResponse(fieldName, locationCards) {
const vm = createPageVm()
const response = {
type: 'house_ai_result',
answer: '已按已维护的地点资料筛选,以下地点可供参考。'
}
response[fieldName] = locationCards
vm.handleSocketMessage(JSON.stringify(response))
return vm.messages.find((message) => message.type === 'location')
}
const locationCard = {
location_id: 101,
city: '南宁市',
location_name: '五象航洋城',
parent_location_name: '五象新区',
tags: ['停车方便'],
knowledge_items: [{
topic: 'parking',
title: '停车',
parking_available: true,
parking_fee: '月租 300 元'
const vm = createPageVm()
vm.handleSocketMessage(JSON.stringify({
type: 'house_ai_result',
answer: '航洋城附近通勤方便,停车以现场政策为准。',
locationCards: [{
locationId: 101,
locationName: '航洋城',
knowledgeItems: [{ title: '停车' }]
}],
houses: [{
houseId: 201,
houseTitle: '航洋城附近两居室',
files: []
}]
}
}))
const locationMessage = receiveLocationResponse('location_cards', JSON.stringify([locationCard]))
assert.equal(vm.messages.filter((message) => message.type === 'location').length, 0,
'地点资料不应在小程序中创建卡片消息')
assert.equal(vm.messages.filter((message) => message.type === 'text').length, 1,
'地点资料应由 AI 直接组织为文本回答')
assert.equal(vm.messages.find((message) => message.type === 'text').content,
'航洋城附近通勤方便,停车以现场政策为准。')
assert.equal(vm.messages.filter((message) => message.type === 'list').length, 1,
'房源结果仍应创建房源卡片消息')
assert.ok(locationMessage, '地点咨询回包应创建地点卡片消息')
assert.ok(Array.isArray(locationMessage.locationCards), '地点卡片应转换为数组')
assert.equal(locationMessage.locationCards[0].locationId, 101)
assert.equal(locationMessage.locationCards[0].locationName, '五象航洋城')
assert.equal(locationMessage.locationCards[0].knowledgeItems[0].parkingAvailable, true)
const backendLocationMessage = receiveLocationResponse('locationCards', [{
locationId: 102,
city: '南宁市',
locationName: '会展航洋城',
knowledgeItems: []
}])
assert.ok(backendLocationMessage, '后端驼峰地点卡片回包应保持兼容')
assert.equal(backendLocationMessage.locationCards[0].locationName, '会展航洋城')
console.log('地点咨询回包能够创建可渲染的地点卡片消息')
console.log('地点资料仅由 AI 组织为文本,页面不渲染地点卡片')
+24
View File
@@ -0,0 +1,24 @@
const assert = require('node:assert/strict')
const fs = require('node:fs')
const path = require('node:path')
const root = path.resolve(__dirname, '..')
const pagePath = path.join(root, 'pages/ai-house/index.vue')
const componentPath = path.join(root, 'uni_modules/mp-html/components/mp-html/mp-html.vue')
const markdownPluginPath = path.join(root, 'uni_modules/mp-html/components/mp-html/markdown/index.js')
const page = fs.readFileSync(pagePath, 'utf8')
const component = fs.readFileSync(componentPath, 'utf8')
assert.match(page, /v-if="message\.role === 'ai'"[\s\S]*:content="message\.content"[\s\S]*markdown/)
assert.match(component, /markdown:\s*Boolean/)
assert.match(component, /require\('\.\/markdown\/index\.js'\)/)
const Markdown = require(markdownPluginPath)
const html = new Markdown({ markdown: true }).onUpdate('# 标题\n\n**重点**\n\n- 房源 A')
assert.match(html, /<h1[^>]*>标题<\/h1>/)
assert.match(html, /<strong>重点<\/strong>/)
assert.match(html, /<li>房源 A<\/li>/)
console.log('AI 找房 Markdown 渲染配置检查通过')
+24
View File
@@ -0,0 +1,24 @@
const assert = require('node:assert/strict')
const fs = require('node:fs')
const path = require('node:path')
const pagePath = path.resolve(__dirname, '../pages/ai-house/index.vue')
const page = fs.readFileSync(pagePath, 'utf8')
for (const label of ['面积和价格', '物业和水电', '空调和停车']) {
assert.match(page, new RegExp(`label: '${label}'`))
}
for (const question of [
'介绍一下所有楼盘的面积和价格。',
'介绍一下所有楼盘的物业费和水电收费情况。',
'介绍一下所有楼盘是否配备空调和停车位。'
]) {
assert.ok(page.includes(`question: '${question}'`))
}
assert.ok(!page.includes('这套房的面积和价格是多少?'))
assert.ok(!page.includes('这套房的物业费和水电怎么收费?'))
assert.ok(!page.includes('这套房有空调和停车位吗?'))
console.log('AI 找房全量楼盘快捷提问检查通过')