feat(admin): complete full integration of kefu, finance, product and order modules with real RPC data streams

This commit is contained in:
comlibmb
2026-02-11 18:45:46 +08:00
parent ee5c0c446b
commit 48320b410c
25 changed files with 2060 additions and 538 deletions

View File

@@ -3,29 +3,23 @@
<!-- 头部搜索 -->
<view class="search-card">
<view class="search-row">
<view class="search-item">
<text class="search-label">回复类型:</text>
<view class="mock-select">
<text class="select-val">请选择</text>
<text class="arrow-down-icon">▼</text>
</view>
</view>
<view class="search-item">
<text class="search-label">关键字:</text>
<input class="search-input" placeholder="请输入关键字" />
<input class="search-input" v-model="searchQuery" placeholder="请输入关键字" @confirm="handleQuery" />
</view>
<button class="btn-query">查询</button>
<button class="btn-query" @click="handleQuery">查询</button>
<button class="btn-reset" @click="handleReset">重置</button>
</view>
</view>
<!-- 数据表格区域 -->
<view class="table-card">
<view class="table-card border-shadow">
<view class="table-toolbar">
<button class="btn-primary-add" @click="openModal()">添加自动回复</button>
</view>
<view class="table-header-pane">
<view class="th flex-1">ID</view>
<view class="th flex-1">序号</view>
<view class="th flex-2">关键字</view>
<view class="th flex-2">回复类型</view>
<view class="th flex-4">回复内容</view>
@@ -34,33 +28,46 @@
</view>
<view class="table-body">
<view v-if="list.length === 0" class="empty-box">
<text class="empty-text">暂无数据</text>
<view v-if="loading" class="table-loading" style="padding: 40px; text-align: center;">
<text>加载中...</text>
</view>
<view v-for="(item, index) in list" :key="index" class="table-row-item">
<text class="td flex-1 color-9">{{ item.id }}</text>
<view v-else-if="list.length === 0" class="empty-box">
<text class="empty-text">暂无自动回复配置</text>
</view>
<view v-for="(item, index) in list" :key="item.id" class="table-row-item">
<text class="td flex-1 color-9">{{ (page - 1) * pageSize + index + 1 }}</text>
<text class="td flex-2">{{ item.keyword }}</text>
<text class="td flex-2">{{ item.type === 'text' ? '文字消息' : '图片消息' }}</text>
<text class="td flex-2">{{ item.reply_type === 'text' ? '文字消息' : '图片消息' }}</text>
<text class="td flex-4 color-6 truncate">{{ item.content }}</text>
<view class="td flex-2 row-center">
<view class="status-switch-mini" :class="item.status ? 'active' : ''" @click="toggleStatus(index)">
<view class="status-switch-mini" :class="item.status == 1 ? 'active' : ''" @click="toggleStatus(item)">
<view class="switch-dot-mini"></view>
</view>
</view>
<view class="td flex-2 row-center">
<text class="btn-action-blue" @click="openModal(item)">编辑</text>
<view class="v-divider-line"></view>
<text class="btn-action-red" @click="deleteItem(index)">删除</text>
<text class="btn-action-red" @click="handleDelete(item)">删除</text>
</view>
</view>
</view>
<!-- 分页栏 -->
<view class="pagination-bar">
<text class="page-total">共 {{ total }} 条</text>
<view class="page-nav">
<view class="nav-prev" :class="{ disabled: page <= 1 }" @click="prevPage"><text class="nav-icon"> < </text></view>
<view class="nav-item active"><text class="nav-num">{{ page }}</text></view>
<view class="nav-next" :class="{ disabled: page >= totalPages }" @click="nextPage"><text class="nav-icon"> > </text></view>
</view>
</view>
</view>
<!-- 添加/编辑弹窗 (Centered Modal) -->
<view class="modal-overlay" v-if="showModal" @click="closeModal">
<view class="modal-main-pane" @click.stop>
<view class="modal-header-box">
<text class="modal-title-txt">客服自动回复</text>
<text class="modal-title-txt">{{ isEdit ? '编辑自动回复' : '添加自动回复' }}</text>
<text class="modal-close-icon" @click="closeModal">×</text>
</view>
<view class="modal-body-form">
@@ -73,15 +80,15 @@
<view class="form-item-box">
<view class="label-box"><text class="form-label">回复类型:</text></view>
<view class="val-box row-center-start">
<view class="radio-item" @click="form.type = 'text'">
<view class="radio-circle" :class="form.type === 'text' ? 'radio-checked' : ''">
<view v-if="form.type === 'text'" class="radio-dot-inner"></view>
<view class="radio-item" @click="form.reply_type = 'text'">
<view class="radio-circle" :class="form.reply_type === 'text' ? 'radio-checked' : ''">
<view v-if="form.reply_type === 'text'" class="radio-dot-inner"></view>
</view>
<text class="radio-txt">文字消息</text>
</view>
<view class="radio-item" @click="form.type = 'image'">
<view class="radio-circle" :class="form.type === 'image' ? 'radio-checked' : ''">
<view v-if="form.type === 'image'" class="radio-dot-inner"></view>
<view class="radio-item" @click="form.reply_type = 'image'">
<view class="radio-circle" :class="form.reply_type === 'image' ? 'radio-checked' : ''">
<view v-if="form.reply_type === 'image'" class="radio-dot-inner"></view>
</view>
<text class="radio-txt">图片消息</text>
</view>
@@ -90,21 +97,21 @@
<view class="form-item-box">
<view class="label-box"><text class="form-label font-star">回复内容:</text></view>
<view class="val-box">
<input class="input-ctrl" v-model="form.content" placeholder="请输入回复内容" />
<textarea class="textarea-ctrl" v-model="form.content" placeholder="请输入回复内容" />
</view>
</view>
<view class="form-item-box">
<view class="label-box"><text class="form-label">状态:</text></view>
<view class="val-box row-center-start">
<view class="radio-item" @click="form.status = true">
<view class="radio-circle" :class="form.status ? 'radio-checked' : ''">
<view v-if="form.status" class="radio-dot-inner"></view>
<view class="radio-item" @click="form.status = 1">
<view class="radio-circle" :class="form.status === 1 ? 'radio-checked' : ''">
<view v-if="form.status === 1" class="radio-dot-inner"></view>
</view>
<text class="radio-txt">开启</text>
</view>
<view class="radio-item" @click="form.status = false">
<view class="radio-circle" :class="!form.status ? 'radio-checked' : ''">
<view v-if="!form.status" class="radio-dot-inner"></view>
<view class="radio-item" @click="form.status = 0">
<view class="radio-circle" :class="form.status === 0 ? 'radio-checked' : ''">
<view v-if="form.status === 0" class="radio-dot-inner"></view>
</view>
<text class="radio-txt">关闭</text>
</view>
@@ -121,43 +128,122 @@
</template>
<script setup lang="uts">
import { ref, reactive } from 'vue'
import { ref, reactive, onMounted, computed } from 'vue'
import {
fetchAutoReplyPage,
saveAutoReply as saveAutoReplyService,
deleteAutoReply,
setAutoReplyStatus,
type AutoReply
} from '@/services/admin/kefuService.uts'
interface AutoReplyItem {
id: number;
keyword: string;
type: string; // 'text' | 'image'
content: string;
status: boolean;
}
const list = reactive<AutoReplyItem[]>([])
const list = ref<AutoReply[]>([])
const loading = ref(false)
const total = ref(0)
const page = ref(1)
const pageSize = ref(15)
const searchQuery = ref('')
const showModal = ref(false)
const isEdit = ref(false)
const editIndex = ref(-1)
const currentId = ref<string | null>(null)
const form = reactive({
keyword: '',
type: 'text',
reply_type: 'text',
content: '',
status: true
status: 1
})
function openModal(item: AutoReplyItem | null = null) {
const totalPages = computed((): number => {
if (pageSize.value <= 0) return 1
return Math.ceil(total.value / pageSize.value)
})
onMounted(() => {
loadData()
})
async function loadData() {
loading.value = true
try {
const res = await fetchAutoReplyPage(page.value, pageSize.value, searchQuery.value || null)
list.value = res.items
total.value = res.total
} catch (e) {
uni.showToast({ title: '加载失败', icon: 'none' })
} finally {
loading.value = false
}
}
function handleQuery() {
page.value = 1
loadData()
}
function handleReset() {
searchQuery.value = ''
page.value = 1
loadData()
}
function prevPage() {
if (page.value > 1) {
page.value--
loadData()
}
}
function nextPage() {
if (page.value < totalPages.value) {
page.value++
loadData()
}
}
async function toggleStatus(item: AutoReply) {
const targetStatus = item.status === 1 ? 0 : 1
const ok = await setAutoReplyStatus(item.id, targetStatus)
if (ok) {
item.status = targetStatus
uni.showToast({ title: '状态更新成功' })
} else {
uni.showToast({ title: '操作失败', icon: 'none' })
}
}
async function handleDelete(item: AutoReply) {
uni.showModal({
title: '提示',
content: `确定删除关键字为 "${item.keyword}" 的自动回复吗?`,
success: async (res) => {
if (res.confirm) {
const ok = await deleteAutoReply(item.id)
if (ok) {
uni.showToast({ title: '删除成功' })
loadData()
}
}
}
})
}
function openModal(item: AutoReply | null = null) {
if (item != null) {
isEdit.value = true
currentId.value = item.id
form.keyword = item.keyword
form.type = item.type
form.reply_type = item.reply_type
form.content = item.content
form.status = item.status
editIndex.value = list.indexOf(item)
} else {
isEdit.value = false
currentId.value = null
form.keyword = ''
form.type = 'text'
form.reply_type = 'text'
form.content = ''
form.status = true
form.status = 1
}
showModal.value = true
}
@@ -166,7 +252,7 @@ function closeModal() {
showModal.value = false
}
function saveReply() {
async function saveReply() {
if (!form.keyword) {
uni.showToast({ title: '请输入关键字', icon: 'none' })
return
@@ -176,40 +262,21 @@ function saveReply() {
return
}
if (isEdit.value) {
const item = list[editIndex.value]
item.keyword = form.keyword
item.type = form.type
item.content = form.content
item.status = form.status
const resId = await saveAutoReplyService(
currentId.value,
form.keyword,
form.content,
form.reply_type,
form.status
)
if (resId != null) {
uni.showToast({ title: '保存成功' })
closeModal()
loadData()
} else {
list.unshift({
id: Date.now() % 10000,
keyword: form.keyword,
type: form.type,
content: form.content,
status: form.status
})
uni.showToast({ title: '保存失败', icon: 'none' })
}
closeModal()
uni.showToast({ title: '保存成功', icon: 'success' })
}
function toggleStatus(index: number) {
list[index].status = !list[index].status
}
function deleteItem(index: number) {
uni.showModal({
title: '提示',
content: '确定删除该自动回复吗?',
success: (res) => {
if (res.confirm) {
list.splice(index, 1)
uni.showToast({ title: '删除成功', icon: 'none' })
}
}
})
}
</script>
@@ -244,23 +311,10 @@ function deleteItem(index: number) {
margin-right: 10px;
white-space: nowrap;
}
.mock-select {
width: 200px;
height: 32px;
border: 1px solid #dcdfe6;
border-radius: 4px;
padding: 0 12px;
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
}
.select-val { font-size: 14px; color: #c0c4cc; }
.arrow-down-icon { font-size: 10px; color: #c0c4cc; }
.search-input {
width: 200px;
height: 32px;
width: 240px;
height: 36px;
border: 1px solid #dcdfe6;
border-radius: 4px;
padding: 0 12px;
@@ -269,14 +323,25 @@ function deleteItem(index: number) {
.btn-query {
background-color: #1890ff;
color: #fff;
height: 32px;
line-height: 32px;
height: 36px;
line-height: 36px;
padding: 0 20px;
border-radius: 4px;
font-size: 14px;
border: none;
margin-left: 10px;
}
.btn-reset {
background-color: #fff;
color: #666;
border: 1px solid #dcdfe6;
height: 36px;
line-height: 36px;
padding: 0 20px;
border-radius: 4px;
font-size: 14px;
margin-left: 10px;
}
/* 表格区域样式 */
.table-card {
@@ -290,8 +355,8 @@ function deleteItem(index: number) {
.btn-primary-add {
background-color: #1890ff;
color: #fff;
height: 32px;
line-height: 32px;
height: 34px;
line-height: 34px;
padding: 0 15px;
border-radius: 4px;
font-size: 14px;
@@ -307,9 +372,9 @@ function deleteItem(index: number) {
align-items: center;
}
.th {
font-size: 14px;
font-size: 13px;
font-weight: bold;
color: #333;
color: #606266;
padding: 0 10px;
}
.table-body {
@@ -318,7 +383,7 @@ function deleteItem(index: number) {
.table-row-item {
display: flex;
flex-direction: row;
height: 54px;
height: 64px;
align-items: center;
border-left: 1px solid #f0f0f0;
border-right: 1px solid #f0f0f0;
@@ -326,7 +391,7 @@ function deleteItem(index: number) {
}
.td {
padding: 0 10px;
font-size: 14px;
font-size: 13px;
color: #606266;
}
@@ -345,8 +410,8 @@ function deleteItem(index: number) {
.color-6 { color: #666; }
/* 操作按钮 */
.btn-action-blue { color: #1890ff; font-size: 14px; cursor: pointer; }
.btn-action-red { color: #ff4d4f; font-size: 14px; cursor: pointer; }
.btn-action-blue { color: #1890ff; font-size: 13px; cursor: pointer; }
.btn-action-red { color: #ff4d4f; font-size: 13px; cursor: pointer; }
.v-divider-line { width: 1px; height: 12px; background-color: #eee; margin: 0 10px; }
/* 状态开关 */
@@ -357,6 +422,7 @@ function deleteItem(index: number) {
border-radius: 11px;
position: relative;
transition: background-color 0.3s;
cursor: pointer;
}
.status-switch-mini.active {
background-color: #1890ff;
@@ -386,7 +452,7 @@ function deleteItem(index: number) {
align-items: center;
}
.modal-main-pane {
width: 600px;
width: 520px;
background-color: #fff;
border-radius: 4px;
overflow: hidden;
@@ -403,16 +469,16 @@ function deleteItem(index: number) {
.modal-close-icon { font-size: 22px; color: #999; cursor: pointer; }
.modal-body-form {
padding: 30px;
padding: 24px;
}
.form-item-box {
display: flex;
flex-direction: row;
margin-bottom: 24px;
margin-bottom: 20px;
align-items: center;
}
.label-box {
width: 100px;
width: 90px;
margin-right: 15px;
text-align: right;
}
@@ -428,12 +494,20 @@ function deleteItem(index: number) {
padding: 0 12px;
font-size: 14px;
}
.textarea-ctrl {
width: 100%;
height: 100px;
border: 1px solid #dcdfe6;
border-radius: 4px;
padding: 8px 12px;
font-size: 14px;
}
.radio-item {
display: flex;
flex-direction: row;
align-items: center;
margin-right: 30px;
margin-right: 24px;
cursor: pointer;
}
.radio-circle {
@@ -463,7 +537,7 @@ function deleteItem(index: number) {
.btn-foot-cancel {
background-color: #fff; border: 1px solid #dcdfe6; color: #606266;
padding: 0 20px; height: 32px; line-height: 32px; border-radius: 4px; font-size: 14px;
margin-right: 15px;
margin-right: 12px;
}
.btn-foot-submit {
background-color: #1890ff; color: #fff; border: none;
@@ -477,4 +551,24 @@ function deleteItem(index: number) {
.row-center { display: flex; flex-direction: row; align-items: center; justify-content: center; }
.row-center-start { display: flex; flex-direction: row; align-items: center; justify-content: flex-start; }
.text-center { text-align: center; }
/* 分页 */
.pagination-bar {
padding: 15px 0;
display: flex;
flex-direction: row;
align-items: center;
justify-content: flex-end;
}
.page-total { font-size: 13px; color: #606266; margin-right: 15px; }
.page-nav { display: flex; flex-direction: row; align-items: center; }
.nav-prev, .nav-next, .nav-item {
width: 30px; height: 30px; border: 1px solid #dcdee2;
display: flex; align-items: center; justify-content: center;
border-radius: 4px; margin: 0 4px; cursor: pointer;
}
.nav-item.active { background-color: #1890ff; border-color: #1890ff; }
.nav-item.active .nav-num { color: #fff; }
.nav-num, .nav-icon { font-size: 13px; color: #606266; }
.disabled { cursor: not-allowed; opacity: 0.5; }
</style>