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

@@ -16,6 +16,10 @@
>
<view class="folder-icon">📂</view>
<text class="cat-name">{{ cat.name }}</text>
<view class="cat-ops" v-if="cat.id != 'all'">
<text class="cat-op-btn" @click.stop="handleEditCategory(cat)">✎</text>
<text class="cat-op-btn danger" @click.stop="handleDeleteCategory(cat)">×</text>
</view>
</view>
</scroll-view>
</view>
@@ -30,56 +34,41 @@
<view class="table-card border-shadow">
<view class="table-header">
<view class="th col-id"><text class="th-txt">ID</text></view>
<view class="th col-id"><text class="th-txt">序号</text></view>
<view class="th col-cat"><text class="th-txt">分类</text></view>
<view class="th col-title"><text class="th-txt">标题</text></view>
<view class="th col-detail"><text class="th-txt">详情</text></view>
<view class="th col-sort"><text class="th-txt">排序</text></view>
<view class="th col-time"><text class="th-txt">添加时间</text></view>
<view class="th col-op"><text class="th-txt">操作</text></view>
</view>
<view class="table-body">
<view class="table-row" v-for="item in wordList" :key="item.id">
<view class="td col-id"><text class="td-txt">{{ item.id }}</text></view>
<view class="td col-cat"><text class="td-txt">{{ item.category }}</text></view>
<view v-if="loading" class="table-loading" style="padding: 40px; text-align: center;">
<text>加载中...</text>
</view>
<view v-else-if="wordList.length === 0" class="table-empty" style="padding: 40px; text-align: center;">
<text>该分类下暂无话术</text>
</view>
<view v-else class="table-row" v-for="(item, index) in wordList" :key="item.id">
<view class="td col-id"><text class="td-txt">{{ index + 1 }}</text></view>
<view class="td col-cat"><text class="td-txt">{{ item.category_name }}</text></view>
<view class="td col-title"><text class="td-txt">{{ item.title }}</text></view>
<view class="td col-detail">
<text class="td-txt ellipsis-2">{{ item.content }}</text>
</view>
<view class="td col-sort"><text class="td-txt">{{ item.sort }}</text></view>
<view class="td col-time"><text class="td-txt">{{ item.time }}</text></view>
<view class="td col-op">
<text class="btn-action" @click="handleEdit(item)">编辑</text>
<text class="btn-action" @click="handleEditWord(item)">编辑</text>
<view class="divider"></view>
<text class="btn-action danger">删除</text>
<text class="btn-action danger" @click="handleDeleteWord(item)">删除</text>
</view>
</view>
</view>
<!-- 分页 -->
<view class="pagination-bar">
<text class="page-total">共 {{ wordList.length }} 条</text>
<view class="page-size-select">
<text class="size-txt">15条/页</text>
<text class="arrow-down">▼</text>
</view>
<view class="page-nav">
<view class="nav-prev"><text class="nav-icon"> < </text></view>
<view class="nav-item active"><text class="nav-num">1</text></view>
<view class="nav-next"><text class="nav-icon"> > </text></view>
</view>
<view class="page-jump">
<text class="jump-txt">前往</text>
<input class="jump-input" value="1" />
<text class="jump-txt">页</text>
</view>
</view>
</view>
</view>
</view>
<!-- 侧边弹窗 (Drawer) -->
<!-- 话术编辑弹窗 (Drawer) -->
<view v-if="showDrawer" class="drawer-mask" @click="closeDrawer">
<view class="drawer-content" @click.stop>
<view class="drawer-header">
@@ -93,10 +82,12 @@
<text class="label-txt">话术分类:</text>
</view>
<view class="input-box">
<view class="select-mock">
<text class="select-val">{{ formData.category || '请选择分类' }}</text>
<text class="arrow-down">▼</text>
</view>
<picker :value="categoryIndex" :range="categoryOptions" range-key="label" @change="onCategoryChange">
<view class="select-mock">
<text class="select-val">{{ categoryOptions[categoryIndex]?.label || '请选择分类' }}</text>
<text class="arrow-down">▼</text>
</view>
</picker>
</view>
</view>
@@ -106,7 +97,7 @@
<text class="label-txt">话术标题:</text>
</view>
<view class="input-box">
<input class="input-base" v-model="formData.title" placeholder="请输入话术标题" />
<input class="input-base" v-model="wordForm.title" placeholder="请输入话术标题" />
</view>
</view>
@@ -116,7 +107,7 @@
<text class="label-txt">话术内容:</text>
</view>
<view class="input-box">
<textarea class="textarea-base" v-model="formData.content" placeholder="请输入话术内容" />
<textarea class="textarea-base" v-model="wordForm.content" placeholder="请输入话术内容" />
</view>
</view>
@@ -125,7 +116,7 @@
<text class="label-txt">排序:</text>
</view>
<view class="input-box">
<input class="input-base" type="number" v-model="formData.sort" />
<input class="input-base" type="number" v-model="wordForm.sort" />
</view>
</view>
</view>
@@ -134,7 +125,7 @@
<view class="btn-cancel" @click="closeDrawer">
<text class="cancel-txt">取消</text>
</view>
<view class="btn-confirm" @click="submitForm">
<view class="btn-confirm" @click="submitWordForm">
<text class="confirm-txt">确定</text>
</view>
</view>
@@ -144,85 +135,202 @@
</template>
<script setup lang="uts">
import { ref, reactive } from 'vue'
import { ref, reactive, onMounted, computed } from 'vue'
import {
fetchWordCategoryList,
saveWordCategory,
deleteWordCategory,
fetchKefuWordList,
saveKefuWord,
deleteKefuWord,
type WordCategory,
type KefuWord
} from '@/services/admin/kefuService.uts'
interface WordItem {
id: string
category: string
title: string
content: string
sort: number
time: string
}
const categories = ref<WordCategory[]>([])
const wordList = ref<KefuWord[]>([])
const loading = ref(false)
const activeCategoryId = ref<string>('all')
interface Category {
id: number
name: string
}
const categories = ref<Category[]>([
{ id: 1, name: '全部' },
{ id: 2, name: '系统话术' }
])
const activeCategoryId = ref(1)
const wordList = ref<WordItem[]>([
{
id: '67',
category: '系统默认',
title: '旗舰版介绍',
content: '【旗舰版】可以授权给公司或者个人,企业自用搭建,不限制授权域名,提供专属技术总监、产品总监等。',
sort: 0,
time: '2024-09-27 10:15:07'
}
])
// 表单逻辑
// 表单控制
const showDrawer = ref(false)
const isEdit = ref(false)
const formData = reactive({
const wordForm = reactive({
id: '',
category: '系统话术',
categoryId: '',
title: '',
content: '',
sort: 0
})
const selectCategory = (id: number) => {
const categoryOptions = computed(() : any[] => {
return categories.value.map(c => ({ label: c.name, value: c.id }))
})
const categoryIndex = ref(0)
onMounted(() => {
loadCategories()
})
async function loadCategories() {
const res = await fetchWordCategoryList()
categories.value = [{ id: 'all', name: '全部' } as WordCategory, ...res]
if (activeCategoryId.value == 'all') {
loadWords(null)
}
}
async function loadWords(catId : string | null) {
loading.value = true
try {
const res = await fetchKefuWordList(catId)
wordList.value = res
} catch (e) {
uni.showToast({ title: '加载话术失败', icon: 'none' })
} finally {
loading.value = false
}
}
function selectCategory(id : string) {
activeCategoryId.value = id
loadWords(id == 'all' ? null : id)
}
const handleAddCategory = () => {
console.log('添加分类')
// 分类操作
async function handleAddCategory() {
uni.showModal({
title: '添加分类',
editable: true,
placeholderText: '请输入分类名称',
success: async (res) => {
if (res.confirm && res.content) {
const id = await saveWordCategory(null, res.content, 0)
if (id != null) {
uni.showToast({ title: '添加成功' })
loadCategories()
}
}
}
})
}
const handleAddWord = () => {
async function handleEditCategory(cat : WordCategory) {
uni.showModal({
title: '编辑分类',
editable: true,
content: cat.name,
success: async (res) => {
if (res.confirm && res.content) {
const id = await saveWordCategory(cat.id, res.content, cat.sort)
if (id != null) {
uni.showToast({ title: '修改成功' })
loadCategories()
}
}
}
})
}
async function handleDeleteCategory(cat : WordCategory) {
uni.showModal({
title: '提示',
content: `确定删除分类 "${cat.name}" 及其下所有话术吗?`,
success: async (res) => {
if (res.confirm) {
const ok = await deleteWordCategory(cat.id)
if (ok) {
uni.showToast({ title: '删除成功' })
if (activeCategoryId.value == cat.id) {
activeCategoryId.value = 'all'
}
loadCategories()
}
}
}
})
}
// 话术操作
function handleAddWord() {
isEdit.value = false
formData.id = ''
formData.title = ''
formData.content = ''
formData.sort = 0
wordForm.id = ''
wordForm.categoryId = activeCategoryId.value == 'all' ? '' : activeCategoryId.value
wordForm.title = ''
wordForm.content = ''
wordForm.sort = 0
// 更新 picker 索引
const idx = categoryOptions.value.findIndex((opt : any) => opt.value == wordForm.categoryId)
categoryIndex.value = idx > -1 ? idx : 0
showDrawer.value = true
}
const handleEdit = (item: WordItem) => {
function handleEditWord(item : KefuWord) {
isEdit.value = true
formData.id = item.id
formData.category = item.category
formData.title = item.title
formData.content = item.content
formData.sort = item.sort
wordForm.id = item.id
wordForm.categoryId = item.category_id
wordForm.title = item.title
wordForm.content = item.content
wordForm.sort = item.sort
const idx = categoryOptions.value.findIndex((opt : any) => opt.value == item.category_id)
categoryIndex.value = idx > -1 ? idx : 0
showDrawer.value = true
}
const closeDrawer = () => {
async function handleDeleteWord(item : KefuWord) {
uni.showModal({
title: '提示',
content: '确定删除该话术吗?',
success: async (res) => {
if (res.confirm) {
const ok = await deleteKefuWord(item.id)
if (ok) {
uni.showToast({ title: '删除成功' })
loadWords(activeCategoryId.value == 'all' ? null : activeCategoryId.value)
}
}
}
})
}
function onCategoryChange(e : any) {
categoryIndex.value = e.detail.value as number
wordForm.categoryId = categoryOptions.value[categoryIndex.value].value as string
}
function closeDrawer() {
showDrawer.value = false
}
const submitForm = () => {
console.log('提交表单', formData)
showDrawer.value = false
async function submitWordForm() {
if (!wordForm.categoryId) {
uni.showToast({ title: '请选择分类', icon: 'none' })
return
}
if (!wordForm.title || !wordForm.content) {
uni.showToast({ title: '请完善话术内容', icon: 'none' })
return
}
const resId = await saveKefuWord(
isEdit.value ? wordForm.id : null,
wordForm.categoryId,
wordForm.title,
wordForm.content,
wordForm.sort
)
if (resId != null) {
uni.showToast({ title: '保存成功' })
showDrawer.value = false
loadWords(activeCategoryId.value == 'all' ? null : activeCategoryId.value)
} else {
uni.showToast({ title: '保存失败', icon: 'none' })
}
}
</script>
@@ -248,9 +356,10 @@ const submitForm = () => {
/* 左侧分类 */
.category-sidebar {
width: 280px;
width: 240px;
display: flex;
flex-direction: column;
background-color: #fff;
}
.sidebar-header {
@@ -261,17 +370,19 @@ const submitForm = () => {
padding: 0 20px;
border-bottom: 1px solid #f0f0f0;
cursor: pointer;
background-color: #fafafa;
}
.plus-icon {
font-size: 18px;
color: #c0c4cc;
color: #2d8cf0;
margin-right: 8px;
}
.header-txt {
font-size: 14px;
color: #606266;
color: #2d8cf0;
font-weight: 500;
}
.category-list {
@@ -284,8 +395,9 @@ const submitForm = () => {
display: flex;
flex-direction: row;
align-items: center;
padding: 0 20px;
padding: 0 15px 0 20px;
cursor: pointer;
position: relative;
}
.category-item:hover {
@@ -294,7 +406,8 @@ const submitForm = () => {
.category-item.active {
background-color: #e6f7ff;
border-right: 2px solid #2d8cf0;
color: #2d8cf0;
border-right: 3px solid #2d8cf0;
}
.folder-icon {
@@ -304,9 +417,18 @@ const submitForm = () => {
.cat-name {
font-size: 14px;
color: #333;
flex: 1;
}
.cat-ops {
display: flex;
flex-direction: row;
gap: 8px;
opacity: 0.6;
}
.cat-op-btn { font-size: 16px; padding: 0 4px; }
.cat-op-btn.danger { color: #f5222d; }
/* 右侧内容 */
.content-main {
flex: 1;
@@ -339,6 +461,7 @@ const submitForm = () => {
display: flex;
flex-direction: column;
overflow: hidden;
background-color: #fff;
}
.table-header {
@@ -365,10 +488,11 @@ const submitForm = () => {
.table-body {
flex: 1;
overflow-y: auto;
}
.table-row {
height: 70px;
min-height: 70px;
display: flex;
flex-direction: row;
align-items: center;
@@ -379,12 +503,13 @@ const submitForm = () => {
display: flex;
align-items: center;
justify-content: center;
padding: 0 10px;
padding: 10px;
}
.td-txt {
font-size: 13px;
color: #606266;
text-align: center;
}
.ellipsis-2 {
@@ -401,8 +526,7 @@ const submitForm = () => {
.col-title { width: 150px; }
.col-detail { flex: 1; justify-content: flex-start; }
.col-sort { width: 80px; }
.col-time { width: 180px; }
.col-op { width: 150px; }
.col-op { width: 120px; }
.btn-action {
font-size: 13px;
@@ -410,9 +534,7 @@ const submitForm = () => {
cursor: pointer;
}
.danger {
color: #ed4014;
}
.danger { color: #f5222d; }
.divider {
width: 1px;
@@ -421,90 +543,22 @@ const submitForm = () => {
margin: 0 10px;
}
/* 分页 */
.pagination-bar {
padding: 15px 20px;
display: flex;
flex-direction: row;
align-items: center;
justify-content: flex-end;
border-top: 1px solid #f0f0f0;
}
.page-total { font-size: 13px; color: #606266; margin-right: 15px; }
.page-size-select {
border: 1px solid #dcdee2;
padding: 4px 10px;
border-radius: 4px;
display: flex;
flex-direction: row;
align-items: center;
margin-right: 15px;
}
.size-txt { font-size: 13px; color: #606266; margin-right: 8px; }
.nav-icon, .arrow-down { font-size: 10px; color: #808695; }
.page-nav { display: flex; flex-direction: row; align-items: center; margin-right: 15px; }
.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;
}
.nav-item.active {
background-color: #2d8cf0;
border-color: #2d8cf0;
}
.active .nav-num { color: #fff; }
.nav-num { font-size: 13px; color: #606266; }
.page-jump { display: flex; flex-direction: row; align-items: center; }
.jump-txt { font-size: 13px; color: #606266; }
.jump-input {
width: 40px;
height: 30px;
border: 1px solid #dcdee2;
border-radius: 4px;
text-align: center;
margin: 0 8px;
font-size: 13px;
}
/* 抽屉 Drawer 1:1 复刻 - 修正位置到右侧 */
/* 抽屉 Drawer */
.drawer-mask {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
top: 0; left: 0; right: 0; bottom: 0;
background-color: rgba(0, 0, 0, 0.4);
z-index: 1000;
}
.drawer-content {
position: absolute;
top: 0;
right: 0; /* 强制靠右占据右边屏幕 */
width: 50%; /* 占屏幕一半宽度 */
height: 100%;
top: 0; right: 0;
width: 450px; height: 100%;
background-color: #fff;
display: flex;
flex-direction: column;
box-shadow: -2px 0 8px rgba(0, 0, 0, 0.15);
animation: slideIn 0.3s ease;
}
@keyframes slideIn {
from { transform: translateX(100%); }
to { transform: translateX(0); }
}
.drawer-header {
@@ -517,22 +571,10 @@ const submitForm = () => {
border-bottom: 1px solid #f0f0f0;
}
.drawer-title {
font-size: 16px;
font-weight: 600;
color: #333;
}
.drawer-title { font-size: 16px; font-weight: 600; color: #333; }
.close-btn { font-size: 24px; color: #999; cursor: pointer; }
.close-btn {
font-size: 24px;
color: #999;
cursor: pointer;
}
.drawer-body {
flex: 1;
padding: 24px;
}
.drawer-body { flex: 1; padding: 24px; }
.form-item {
display: flex;
@@ -541,9 +583,7 @@ const submitForm = () => {
margin-bottom: 24px;
}
.align-start {
align-items: flex-start;
}
.align-start { align-items: flex-start; }
.label-box {
width: 100px;
@@ -553,19 +593,10 @@ const submitForm = () => {
margin-right: 15px;
}
.required {
color: #ed4014;
margin-right: 4px;
}
.required { color: #ed4014; margin-right: 4px; }
.label-txt { font-size: 14px; color: #606266; }
.label-txt {
font-size: 14px;
color: #606266;
}
.input-box {
flex: 1;
}
.input-box { flex: 1; }
.select-mock {
height: 36px;
@@ -579,10 +610,10 @@ const submitForm = () => {
}
.select-val { font-size: 14px; color: #333; }
.arrow-down { font-size: 10px; color: #999; }
.input-base {
width: 100%;
height: 36px;
width: 100%; height: 36px;
border: 1px solid #dcdee2;
border-radius: 4px;
padding: 0 12px;
@@ -590,8 +621,7 @@ const submitForm = () => {
}
.textarea-base {
width: 100%;
height: 120px;
width: 100%; height: 150px;
border: 1px solid #dcdee2;
border-radius: 4px;
padding: 10px 12px;