feat: chat integration, tenant admin spec, backend chat service, miniprogram updates, DEMO moved to tmp, XCX-TEST removed, migrations & docs

This commit is contained in:
Neo
2026-03-20 09:02:10 +08:00
parent 3d2e5f8165
commit beb88d5bea
388 changed files with 6436 additions and 25458 deletions

View File

@@ -0,0 +1,9 @@
{
"component": true,
"usingComponents": {
"t-rate": "tdesign-miniprogram/rate/rate",
"t-textarea": "tdesign-miniprogram/textarea/textarea",
"t-button": "tdesign-miniprogram/button/button",
"t-icon": "tdesign-miniprogram/icon/icon"
}
}

View File

@@ -0,0 +1,244 @@
Component({
properties: {
visible: {
type: Boolean,
value: false,
},
customerName: {
type: String,
value: '',
},
initialScore: {
type: Number,
value: 0,
},
initialContent: {
type: String,
value: '',
},
/** 是否显示展开/收起按钮 */
showExpandBtn: {
type: Boolean,
value: true,
},
/** 是否显示评分区域 */
showRating: {
type: Boolean,
value: true,
},
},
data: {
ratingExpanded: false, // 默认收起
serviceScore: 0, // 再次服务此客户 1-5
returnScore: 0, // 再来店可能性 1-5
content: '',
keyboardHeight: 0, // 键盘高度 px
canSave: false, // 是否可保存
},
lifetimes: {
created() {
// 初始化私有缓存(不走 setData避免触发渲染
;(this as any)._heartContainerRect = null
;(this as any)._ballContainerRect = null
},
},
observers: {
visible(val: boolean) {
if (val) {
// 打开弹窗时重置
this.setData({
ratingExpanded: this.data.showRating && !this.data.showExpandBtn, // 只有在显示评分且无按钮时才默认展开
serviceScore: 0,
returnScore: 0,
content: this.data.initialContent || '',
keyboardHeight: 0,
canSave: false,
})
// 多次重试获取容器位置信息,确保首次也能正确缓存
this._retryGetContainerRects(0)
} else {
// 关闭时重置键盘高度
this.setData({ keyboardHeight: 0 })
}
},
// 任意评分或内容变化时重新计算 canSave
'serviceScore, returnScore, content, showRating'(
serviceScore: number,
returnScore: number,
content: string,
showRating: boolean
) {
// 如果不显示评分,只需要有内容即可保存;否则需要评分和内容都有
const canSave = showRating
? serviceScore > 0 && returnScore > 0 && content.trim().length > 0
: content.trim().length > 0
this.setData({ canSave })
},
},
methods: {
/** 缓存容器位置信息 */
_cacheContainerRects() {
const query = this.createSelectorQuery()
query.select('.rating-right-heart').boundingClientRect()
query.select('.rating-right-ball').boundingClientRect()
query.exec((res) => {
if (res[0]) (this as any)._heartContainerRect = res[0] as WechatMiniprogram.BoundingClientRectCallbackResult
if (res[1]) (this as any)._ballContainerRect = res[1] as WechatMiniprogram.BoundingClientRectCallbackResult
})
},
/** 重试获取容器位置,确保首次打开也能正确缓存 */
_retryGetContainerRects(attempt: number) {
const maxAttempts = 5
const delay = 50 + attempt * 50 // 50ms, 100ms, 150ms, 200ms, 250ms
setTimeout(() => {
this._cacheContainerRects()
// 检查是否成功缓存,如果没有且还有重试次数,继续重试
const heartRect = (this as any)._heartContainerRect
const ballRect = (this as any)._ballContainerRect
if ((!heartRect || !ballRect) && attempt < maxAttempts - 1) {
this._retryGetContainerRects(attempt + 1)
}
}, delay)
},
/** 切换展开/收起 */
onToggleExpand() {
const nextExpanded = !this.data.ratingExpanded
this.setData({ ratingExpanded: nextExpanded })
// 展开后重新获取位置
if (nextExpanded) {
setTimeout(() => {
this._cacheContainerRects()
}, 100)
}
},
/** 爱心点击 */
onHeartTap(e: WechatMiniprogram.BaseEvent) {
const score = e.currentTarget.dataset.score as number
this.setData({ serviceScore: score })
},
/** 爱心区域触摸开始 */
onHeartTouchStart(e: WechatMiniprogram.TouchEvent) {
this._updateHeartScore(e)
},
/** 爱心区域触摸移动 */
onHeartTouchMove(e: WechatMiniprogram.TouchEvent) {
this._updateHeartScore(e)
},
/** 更新爱心评分 */
_updateHeartScore(e: WechatMiniprogram.TouchEvent) {
const container = (this as any)._heartContainerRect as WechatMiniprogram.BoundingClientRectCallbackResult | null
if (!container) return
const touch = e.touches[0]
// 垂直方向超出不影响评分,仅用 X 轴计算
let relativeX = touch.clientX - container.left
// 水平边界:最左=1分最右=5分
if (relativeX < 0) relativeX = 0
if (relativeX > container.width) relativeX = container.width
// 计算分数 (1-5)
const score = Math.ceil((relativeX / container.width) * 5)
const finalScore = Math.max(1, Math.min(5, score))
if (finalScore !== this.data.serviceScore) {
this.setData({ serviceScore: finalScore })
}
},
/** 台球点击 */
onBallTap(e: WechatMiniprogram.BaseEvent) {
const score = e.currentTarget.dataset.score as number
this.setData({ returnScore: score })
},
/** 台球区域触摸开始 */
onBallTouchStart(e: WechatMiniprogram.TouchEvent) {
this._updateBallScore(e)
},
/** 台球区域触摸移动 */
onBallTouchMove(e: WechatMiniprogram.TouchEvent) {
this._updateBallScore(e)
},
/** 更新台球评分 */
_updateBallScore(e: WechatMiniprogram.TouchEvent) {
const container = (this as any)._ballContainerRect as WechatMiniprogram.BoundingClientRectCallbackResult | null
if (!container) return
const touch = e.touches[0]
// 垂直方向超出不影响评分,仅用 X 轴计算
let relativeX = touch.clientX - container.left
// 水平边界:最左=1分最右=5分
if (relativeX < 0) relativeX = 0
if (relativeX > container.width) relativeX = container.width
// 计算分数 (1-5)
const score = Math.ceil((relativeX / container.width) * 5)
const finalScore = Math.max(1, Math.min(5, score))
if (finalScore !== this.data.returnScore) {
this.setData({ returnScore: finalScore })
}
},
/** 文本输入 */
onContentInput(e: WechatMiniprogram.CustomEvent<{ value: string }>) {
this.setData({ content: e.detail.value })
},
/** 键盘弹出 */
onTextareaFocus(e: WechatMiniprogram.InputEvent) {
let height = (e as any).detail?.height ?? 0
// 修复首次激活时键盘高度可能为0需要设置最小值确保弹窗移动
if (height === 0) {
height = 260 // 微信小程序默认键盘高度约 260px
}
this.setData({ keyboardHeight: height })
},
/** 键盘收起 */
onTextareaBlur() {
this.setData({ keyboardHeight: 0 })
},
/** 确认保存 */
onConfirm() {
if (!this.data.canSave) return
// 计算综合评分取两个评分的平均值转换为10分制
const avgScore = (this.data.serviceScore + this.data.returnScore) / 2
const finalScore = avgScore * 2 // 转换为10分制
this.triggerEvent('confirm', {
score: finalScore,
content: this.data.content.trim(),
serviceScore: this.data.serviceScore,
returnScore: this.data.returnScore,
})
},
/** 取消 */
onCancel() {
this.triggerEvent('cancel')
},
/** 阻止冒泡 */
noop() {},
},
})

View File

@@ -0,0 +1,83 @@
<view class="modal-overlay {{keyboardHeight > 0 ? 'modal-overlay--keyboard-open' : ''}}" wx:if="{{visible}}" catchtap="onCancel" catchtouchmove="noop">
<view class="modal-container" catchtap="noop">
<!-- 头部 -->
<view class="modal-header">
<view class="header-left">
<text class="modal-title">添加备注</text>
<view class="expand-btn" wx:if="{{showExpandBtn && showRating}}" bindtap="onToggleExpand" hover-class="expand-btn--hover">
<text class="expand-text">{{ratingExpanded ? '收起评价 ▴' : '展开评价 ▾'}}</text>
</view>
</view>
<view class="modal-close" bindtap="onCancel" hover-class="modal-close--hover">
<t-icon name="close" size="40rpx" color="#8b8b8b" />
</view>
</view>
<!-- 评分区域 -->
<view class="rating-section" wx:if="{{showRating && ratingExpanded}}">
<!-- 再次服务此客户 - 爱心 -->
<view class="rating-group">
<text class="rating-label">再次服务此客户</text>
<view class="rating-right rating-right-heart" bindtouchstart="onHeartTouchStart" bindtouchmove="onHeartTouchMove">
<view class="rating-row">
<view class="rating-item" wx:for="{{[1,2,3,4,5]}}" wx:key="*this" bindtap="onHeartTap" data-score="{{item}}" hover-class="rating-item--hover">
<image class="rating-icon" src="{{serviceScore >= item ? '/assets/icons/heart-filled.svg' : '/assets/icons/heart-empty.svg'}}" />
</view>
</view>
<view class="rating-hints">
<text class="hint" style="text-align: left;">不想</text>
<text class="hint"></text>
<text class="hint">一般</text>
<text class="hint"></text>
<text class="hint">非常想</text>
</view>
</view>
</view>
<!-- 再来店可能性 - 台球 -->
<view class="rating-group">
<text class="rating-label">再来店可能性</text>
<view class="rating-right rating-right-ball" bindtouchstart="onBallTouchStart" bindtouchmove="onBallTouchMove">
<view class="rating-row">
<view class="rating-item" wx:for="{{[1,2,3,4,5]}}" wx:key="*this" bindtap="onBallTap" data-score="{{item}}" hover-class="rating-item--hover">
<image class="rating-icon" src="{{returnScore >= item ? '/assets/icons/ball-black.svg' : '/assets/icons/ball-gray.svg'}}" />
</view>
</view>
<view class="rating-hints">
<text class="hint" style="text-align: left;">不可能</text>
<text class="hint"></text>
<text class="hint">不好说</text>
<text class="hint"></text>
<text class="hint">肯定能</text>
</view>
</view>
</view>
</view>
<!-- 文本输入 -->
<view class="textarea-section">
<textarea
class="note-textarea"
placeholder="请输入备注内容..."
value="{{content}}"
bindinput="onContentInput"
bindfocus="onTextareaFocus"
bindblur="onTextareaBlur"
maxlength="500"
auto-height
adjust-position="{{false}}"
placeholder-class="textarea-placeholder"
/>
</view>
<!-- 键盘弹出时的占位,防止内容被遮挡 -->
<view wx:if="{{keyboardHeight > 0}}" style="height: {{keyboardHeight}}px;"></view>
<!-- 保存按钮 -->
<view class="modal-footer {{keyboardHeight > 0 ? 'modal-footer--float' : ''}}" style="{{keyboardHeight > 0 ? 'bottom: ' + keyboardHeight + 'px;' : ''}}">
<view class="save-btn {{!canSave ? 'disabled' : ''}}" bindtap="onConfirm" hover-class="{{canSave ? 'save-btn--hover' : ''}}">
<text class="save-text">保存</text>
</view>
</view>
</view>
</view>

View File

@@ -0,0 +1,241 @@
/* 备注弹窗样式 */
.modal-overlay {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.5);
display: flex;
align-items: flex-end;
z-index: 1000;
transition: align-items 0.3s ease;
}
/* 键盘弹出时,弹窗移到顶部 */
.modal-overlay--keyboard-open {
align-items: flex-start;
}
.modal-container {
width: 100%;
background: #fff;
border-radius: 48rpx 48rpx 0 0;
padding: 40rpx 40rpx 60rpx;
max-height: 80vh;
overflow-y: auto;
transition: border-radius 0.3s ease;
}
/* 键盘弹出时,改为全圆角 */
.modal-overlay--keyboard-open .modal-container {
border-radius: 0 0 48rpx 48rpx;
max-height: none;
}
/* 头部 */
.modal-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 32rpx;
}
.header-left {
display: flex;
align-items: center;
gap: 24rpx;
}
.modal-title {
font-size: 32rpx;
line-height: 44rpx;
font-weight: 600;
color: #242424;
}
.expand-btn {
padding: 6rpx 24rpx;
background: #e8e8e8;
border-radius: 999rpx;
line-height: 16rpx;
}
.expand-text {
font-size: 22rpx;
line-height: 32rpx;
color: #5e5e5e;
}
.expand-btn--hover {
background: #eeeeee;
}
.modal-close {
width: 64rpx;
height: 64rpx;
display: flex;
align-items: center;
justify-content: center;
border-radius: 50%;
background: transparent;
}
.modal-close--hover {
background: #f3f3f3;
}
/* 评分区域 */
.rating-section {
margin-bottom: 32rpx;
}
.rating-group {
display: flex;
align-items: center;
justify-content: space-between;
padding: 24rpx 32rpx;
background: #f3f3f3;
border-radius: 16rpx;
margin-bottom: 16rpx;
}
.rating-group:last-child {
margin-bottom: 0;
}
.rating-label {
flex-shrink: 0;
font-size: 24rpx;
line-height: 40rpx;
color: #242424;
padding-top: 8rpx;
font-weight: 700;
}
.rating-right {
display: flex;
flex-direction: column;
gap: 4rpx;
}
.rating-row {
display: flex;
align-items: center;
gap: 8rpx;
}
.rating-item {
flex: 0 0 auto;
display: flex;
align-items: center;
justify-content: center;
padding: 0;
/* 移除过渡动画 */
}
.rating-item--hover {
opacity: 0.7;
}
.rating-icon {
width: 56rpx;
height: 56rpx;
display: block;
/* 移除过渡动画 */
transition: none;
}
.rating-hints {
display: flex;
justify-content: space-between;
gap: 8rpx;
}
.hint {
font-size: 20rpx;
line-height: 28rpx;
color: #a6a6a6;
text-align: center;
width: 80rpx;
flex-shrink: 0;
}
.hint:nth-child(2n) {
width: 8rpx;
flex-shrink: 0;
}
/* 文本输入 */
.textarea-section {
margin-bottom: 32rpx;
}
.note-textarea {
width: 100%;
min-height: 240rpx;
padding: 24rpx;
background: #f3f3f3;
border-radius: 24rpx;
font-size: 28rpx;
line-height: 40rpx;
color: #242424;
border: 2rpx solid #f3f3f3;
transition: border-color 0.2s;
}
.note-textarea:focus {
border-color: #0052d9;
background: #fff;
}
.textarea-placeholder {
color: #a6a6a6;
}
/* 底部按钮 */
.modal-footer {
display: flex;
}
/* 键盘弹出时固定在键盘上方 */
.modal-footer--float {
position: fixed;
left: 0;
right: 0;
padding: 12rpx 40rpx 16rpx;
background: #fff;
box-shadow: 0 -2rpx 16rpx rgba(0, 0, 0, 0.06);
z-index: 1001;
}
.save-btn {
flex: 1;
height: 96rpx;
display: flex;
align-items: center;
justify-content: center;
background: linear-gradient(135deg, #0052d9, #2979ff);
border-radius: 24rpx;
box-shadow: 0 8rpx 24rpx rgba(0, 82, 217, 0.3);
}
.save-btn.disabled {
background: #e7e7e7;
box-shadow: none;
}
.save-text {
font-size: 32rpx;
line-height: 44rpx;
font-weight: 600;
color: #fff;
}
.save-btn.disabled .save-text {
color: #a6a6a6;
}
.save-btn--hover {
opacity: 0.85;
}