Merge remote-tracking branch 'origin/dev-wdb'

This commit is contained in:
huxuejian 2026-02-04 13:33:40 +08:00
commit 3af5c6750f
6 changed files with 702 additions and 54 deletions

View File

@ -134,7 +134,13 @@
"style": { "style": {
"navigationBarTitleText": "宣教文章" "navigationBarTitleText": "宣教文章"
} }
} },
{
"path": "pages/article/send-article",
"style": {
"navigationBarTitleText": "选择宣教文章"
}
}
], ],
"globalStyle": { "globalStyle": {
"navigationBarTextStyle": "white", "navigationBarTextStyle": "white",

View File

@ -0,0 +1,585 @@
<template>
<view class="article-page">
<view class="header">
<view class="search-bar">
<uni-icons type="search" size="18" color="#999" />
<input
class="search-input"
v-model="searchTitle"
placeholder="输入内容名称搜索"
@input="handleSearch"
/>
</view>
</view>
<view class="content">
<view class="category-sidebar">
<scroll-view scroll-y class="category-scroll">
<view
v-for="cate in categoryList"
:key="cate._id || 'all'"
class="category-item"
:class="{ active: currentCateId === cate._id }"
@click="selectCategory(cate)"
>
{{ cate.label }}
</view>
</scroll-view>
</view>
<view class="article-list">
<scroll-view
scroll-y
class="article-scroll"
@scrolltolower="loadMore"
lower-threshold="50"
>
<view
v-if="loading && articleList.length === 0"
class="loading-container"
>
<uni-icons type="spinner-cycle" size="30" color="#999" />
<text class="loading-text">加载中...</text>
</view>
<view v-else-if="articleList.length === 0" class="empty-container">
<empty-data title="暂无文章" />
</view>
<view v-else>
<view
v-for="article in articleList"
:key="article._id"
class="article-item"
>
<view class="article-content" @click="previewArticle(article)">
<text class="article-title">{{ article.title }}</text>
<view class="article-footer">
<text class="article-date">{{ article.date }}</text>
<button
class="send-btn"
size="mini"
type="primary"
@click.stop="sendArticle(article)"
>
发送
</button>
</view>
</view>
</view>
<view v-if="loading && articleList.length > 0" class="loading-more">
<uni-icons type="spinner-cycle" size="20" color="#999" />
<text>加载中...</text>
</view>
<view
v-if="!loading && articleList.length >= total"
class="no-more"
>
没有更多了
</view>
</view>
</scroll-view>
</view>
</view>
<!-- 文章预览弹窗 -->
<uni-popup ref="previewPopup" type="bottom" :safe-area="false">
<view class="preview-container">
<view class="preview-header">
<text class="preview-title">{{ previewArticleData.title }}</text>
<view class="preview-close" @click="closePreview">
<uni-icons type="closeempty" size="24" color="#333" />
</view>
</view>
<scroll-view scroll-y class="preview-content">
<view class="rich-text-wrapper">
<rich-text :nodes="previewArticleData.content"></rich-text>
</view>
</scroll-view>
<view class="preview-footer">
<button class="preview-close-btn" @click="closePreview">关闭</button>
</view>
</view>
</uni-popup>
</view>
</template>
<script setup>
import { ref, onMounted } from "vue";
import { onLoad } from "@dcloudio/uni-app";
import api from "@/utils/api.js";
import useAccountStore from "@/store/account.js";
import EmptyData from "@/components/empty-data.vue";
const accountStore = useAccountStore();
const env = __VITE_ENV__;
const corpId = env.MP_CORP_ID;
//
const pageParams = ref({
groupId: "",
corpId: "",
});
//
const searchTitle = ref("");
let searchTimer = null;
//
const categoryList = ref([{ _id: "", label: "全部" }]);
const currentCateId = ref(""); // ""_id
//
const articleList = ref([]);
const loading = ref(false);
const page = ref(1);
const pageSize = 30;
const total = ref(0);
//
const previewArticleData = ref({
title: "",
content: "",
});
const previewPopup = ref(null);
//
const getCategoryList = async () => {
try {
const res = await api("getArticleCateList", { corpId: corpId });
if (res.success && res.list) {
const cates = res.list || [];
categoryList.value = [{ _id: "", label: "全部" }, ...cates];
}
} catch (error) {
console.error("获取分类列表失败:", error);
}
};
//
const selectCategory = (cate) => {
currentCateId.value = cate._id || "";
page.value = 1;
articleList.value = [];
loadArticleList();
};
//
const handleSearch = () => {
if (searchTimer) {
clearTimeout(searchTimer);
}
searchTimer = setTimeout(() => {
page.value = 1;
articleList.value = [];
loadArticleList();
}, 500);
};
//
const loadArticleList = async () => {
if (loading.value) return;
loading.value = true;
try {
const params = {
corpId: corpId,
page: page.value,
pageSize: pageSize,
enable: true,
title: searchTitle.value,
};
// ID
if (currentCateId.value) {
params.cateIds = [currentCateId.value];
}
const res = await api("getArticleList", params);
if (res.success && res.list) {
const { list = [], total: count = 0 } = res;
const formattedList = list.map((item) => {
//
let date = "";
if (item.createTime) {
const d = new Date(item.createTime);
const year = d.getFullYear();
const month = String(d.getMonth() + 1).padStart(2, "0");
const day = String(d.getDate()).padStart(2, "0");
date = `${year}-${month}-${day}`;
}
return {
...item,
date,
};
});
if (page.value === 1) {
articleList.value = formattedList;
} else {
articleList.value = [...articleList.value, ...formattedList];
}
total.value = count;
} else {
uni.showToast({
title: res.message || "获取文章列表失败",
icon: "none",
});
}
} catch (error) {
console.error("加载文章列表失败:", error);
uni.showToast({
title: "加载失败,请重试",
icon: "none",
});
} finally {
loading.value = false;
}
};
//
const loadMore = () => {
if (loading.value || articleList.value.length >= total.value) return;
page.value += 1;
loadArticleList();
};
// 使
const processRichTextContent = (html) => {
if (!html) return "";
// img
let processedHtml = html.replace(
/<img/gi,
'<img style="max-width:100%;height:auto;display:block;margin:10px 0;"'
);
//
processedHtml = processedHtml.replace(
/style="[^"]*width:\s*\d+px[^"]*"/gi,
(match) => {
return match.replace(/width:\s*\d+px;?/gi, "max-width:100%;");
}
);
//
processedHtml = processedHtml.replace(
/<table/gi,
'<table style="max-width:100%;overflow-x:auto;display:block;"'
);
//
processedHtml = `<div style="width:100%;overflow-x:hidden;word-wrap:break-word;word-break:break-all;">${processedHtml}</div>`;
return processedHtml;
};
//
const previewArticle = async (article) => {
try {
uni.showLoading({ title: "加载中..." });
const res = await api("getArticle", { id: article._id, corpId: corpId });
uni.hideLoading();
if (res.success && res.data) {
previewArticleData.value = {
title: res.data.title || article.title,
content: processRichTextContent(res.data.content || ""),
};
previewPopup.value?.open();
} else {
uni.showToast({
title: res.message || "预览文章失败",
icon: "none",
});
}
} catch (error) {
uni.hideLoading();
console.error("预览文章失败:", error);
uni.showToast({
title: "预览失败,请重试",
icon: "none",
});
}
};
//
const closePreview = () => {
previewPopup.value?.close();
};
//
const sendArticle = async (article) => {
try {
const { globalTimChatManager } = await import("@/utils/tim-chat.js");
if (!globalTimChatManager || !globalTimChatManager.tim || !globalTimChatManager.isLoggedIn) {
uni.showToast({
title: "IM系统未就绪请重试",
icon: "none",
});
return;
}
// ID
const conversationID = `GROUP${pageParams.value.groupId}`;
globalTimChatManager.currentConversationID = conversationID;
console.log("发送文章会话ID:", conversationID);
//
const customMessageData = {
type: "article",
title: article.title || "宣教文章",
articleId: article._id,
imgUrl: article.cover || "",
desc: "点击查看详情",
};
//
const sendResult = await globalTimChatManager.sendCustomMessage(customMessageData);
if (sendResult && sendResult.success) {
console.log("✓ 文章消息已发送");
uni.showToast({
title: "发送成功",
icon: "success",
});
//
setTimeout(() => {
uni.navigateBack();
}, 1000);
} else {
throw new Error(sendResult?.error || "发送失败");
}
} catch (error) {
console.error("发送文章失败:", error);
uni.showToast({
title: error.message || "发送失败",
icon: "none",
});
}
};
//
onLoad((options) => {
if (options.groupId) {
pageParams.value.groupId = options.groupId;
}
if (options.corpId) {
pageParams.value.corpId = options.corpId;
}
});
onMounted(() => {
getCategoryList();
loadArticleList();
});
</script>
<style scoped lang="scss">
.article-page {
display: flex;
flex-direction: column;
height: 100vh;
background-color: #f5f5f5;
}
.header {
background-color: #fff;
padding: 20rpx;
border-bottom: 1px solid #eee;
}
.search-bar {
display: flex;
align-items: center;
background-color: #f5f5f5;
border-radius: 8rpx;
padding: 16rpx 24rpx;
}
.search-input {
flex: 1;
margin-left: 16rpx;
font-size: 28rpx;
}
.content {
flex: 1;
display: flex;
overflow: hidden;
}
.category-sidebar {
width: 200rpx;
background-color: #f8f8f8;
border-right: 1px solid #eee;
}
.category-scroll {
height: 100%;
}
.category-item {
padding: 20rpx 24rpx;
font-size: 28rpx;
color: #333;
text-align: center;
border-bottom: 1px solid #eee;
transition: all 0.3s ease;
position: relative;
}
.category-item.active {
background-color: #fff;
color: #0877f1;
font-weight: bold;
border-left: 4rpx solid #0877f1;
}
.article-list {
flex: 1;
background-color: #fff;
}
.article-scroll {
height: 100%;
}
.loading-container,
.empty-container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 100rpx 0;
}
.loading-text {
margin-top: 20rpx;
font-size: 28rpx;
color: #999;
}
.article-item {
padding: 24rpx 30rpx;
border-bottom: 1px solid #eee;
transition: background-color 0.2s ease;
}
.article-item:active {
background-color: #f5f5f5;
}
.article-content {
display: flex;
flex-direction: column;
gap: 16rpx;
}
.article-title {
font-size: 28rpx;
color: #333;
line-height: 1.6;
word-break: break-all;
font-weight: 500;
}
.article-footer {
display: flex;
align-items: center;
justify-content: space-between;
gap: 20rpx;
}
.article-date {
flex: 1;
font-size: 24rpx;
color: #999;
}
.send-btn {
flex-shrink: 0;
font-size: 26rpx;
padding: 8rpx 32rpx;
height: auto;
line-height: 1.4;
}
.loading-more,
.no-more {
display: flex;
align-items: center;
justify-content: center;
padding: 30rpx 0;
font-size: 24rpx;
color: #999;
gap: 10rpx;
}
/* 预览弹窗样式 */
.preview-container {
background-color: #fff;
border-radius: 20rpx 20rpx 0 0;
height: 80vh;
display: flex;
flex-direction: column;
}
.preview-header {
display: flex;
align-items: center;
justify-content: space-between;
padding: 30rpx;
border-bottom: 1px solid #eee;
}
.preview-title {
flex: 1;
font-size: 32rpx;
font-weight: bold;
color: #333;
}
.preview-close {
padding: 10rpx;
}
.preview-content {
flex: 1;
padding: 0;
overflow-y: auto;
}
.rich-text-wrapper {
padding: 30rpx;
width: 100%;
box-sizing: border-box;
overflow: hidden;
}
/* rich-text 内部样式 */
.rich-text-wrapper ::v-deep rich-text {
width: 100%;
}
.rich-text-wrapper ::v-deep rich-text img {
max-width: 100% !important;
height: auto !important;
display: block;
}
.preview-footer {
padding: 20rpx;
border-top: 1px solid #eee;
}
.preview-close-btn {
width: 100%;
background-color: #1890ff;
color: #fff;
}
</style>

View File

@ -1,11 +1,19 @@
<template> <template>
<page-loading v-if="loading" /> <page-loading v-if="loading" />
<full-page v-else-if="teams.length && team" class="home-container" :pageStyle="pageStyle"> <full-page
v-else-if="teams.length && team"
class="home-container"
:pageStyle="pageStyle"
>
<template #header> <template #header>
<team-head :team="team" :teams="teams" @changeTeam="changeTeam" /> <team-head :team="team" :teams="teams" @changeTeam="changeTeam" />
</template> </template>
<view class="home-section home-section--first"> <view class="home-section home-section--first">
<customer-archive :corpId="corpId" :team="team" @update:customers="handleCustomersUpdate" /> <customer-archive
:corpId="corpId"
:team="team"
@update:customers="handleCustomersUpdate"
/>
</view> </view>
<view class="home-section"> <view class="home-section">
<consult :corpId="corpId" :teamId="team.teamId" :customers="customers" /> <consult :corpId="corpId" :teamId="team.teamId" :customers="customers" />
@ -20,21 +28,21 @@
<yc-home v-else /> <yc-home v-else />
</template> </template>
<script setup> <script setup>
import { computed, ref, watch } from 'vue'; import { computed, ref, watch } from "vue";
import { storeToRefs } from 'pinia' import { storeToRefs } from "pinia";
import useGuard from '@/hooks/useGuard'; import useGuard from "@/hooks/useGuard";
import useAccount from '@/store/account'; import useAccount from "@/store/account";
import api from '@/utils/api'; import api from "@/utils/api";
import { toast } from '@/utils/widget'; import { toast } from "@/utils/widget";
import FullPage from '@/components/full-page.vue'; import FullPage from "@/components/full-page.vue";
import articleList from './article-list.vue'; import articleList from "./article-list.vue";
import consult from './consult.vue'; import consult from "./consult.vue";
import customerArchive from './customer-archive.vue'; import customerArchive from "./customer-archive.vue";
import teamHead from './team-head.vue'; import teamHead from "./team-head.vue";
import teamMate from './team-mate.vue'; import teamMate from "./team-mate.vue";
import ycHome from './yc-home.vue'; import ycHome from "./yc-home.vue";
import pageLoading from './loading.vue'; import pageLoading from "./loading.vue";
const { useLoad, useShow } = useGuard(); const { useLoad, useShow } = useGuard();
const { account } = storeToRefs(useAccount()); const { account } = storeToRefs(useAccount());
@ -48,7 +56,7 @@ const corpId = computed(() => team.value?.corpId);
// UI 281px + 375 稿281px 562rpx // UI 281px + 375 稿281px 562rpx
const pageStyle = const pageStyle =
'background: linear-gradient(180deg, #065BD6 15.05%, #F6FAFA 95.37%) 0 0/100% 562rpx no-repeat, #F6FAFA;'; "background: linear-gradient(180deg, #065BD6 15.05%, #F6FAFA 95.37%) 0 0/100% 562rpx no-repeat, #F6FAFA;";
function handleCustomersUpdate(newCustomers) { function handleCustomersUpdate(newCustomers) {
customers.value = newCustomers; customers.value = newCustomers;
@ -56,13 +64,13 @@ function handleCustomersUpdate(newCustomers) {
async function changeTeam({ teamId, corpId, corpName }) { async function changeTeam({ teamId, corpId, corpName }) {
loading.value = true; loading.value = true;
const res = await api('getTeamData', { teamId, corpId }); const res = await api("getTeamData", { teamId, corpId });
loading.value = false; loading.value = false;
if (res && res.data) { if (res && res.data) {
team.value = res.data; team.value = res.data;
team.value.corpName = corpName; team.value.corpName = corpName;
} else { } else {
toast(res?.message || '获取团队信息失败') toast(res?.message || "获取团队信息失败");
} }
} }
@ -70,26 +78,28 @@ async function getTeams() {
loading.value = true; loading.value = true;
const res = await api('getWxappRelateTeams', { openid: account.value.openid }); const res = await api('getWxappRelateTeams', { openid: account.value.openid });
teams.value = res && Array.isArray(res.data) ? res.data : []; teams.value = res && Array.isArray(res.data) ? res.data : [];
const validTeam = teams.value.find(item => team.value && item.teamId === team.value.teamId) || teams.value[0]; const validTeam =
teams.value.find(
(item) => team.value && item.teamId === team.value.teamId
) || teams.value[0];
if (validTeam) { if (validTeam) {
changeTeam(validTeam) changeTeam(validTeam);
return return;
} else { } else {
team.value = null; team.value = null;
} }
loading.value = false loading.value = false;
} }
useLoad(opts => { useLoad((opts) => {
if (opts.teamId) { if (opts.teamId) {
team.value = { teamId: opts.teamId, corpId: opts.corpId }; team.value = { teamId: opts.teamId, corpId: opts.corpId };
} }
}) });
useShow(() => { useShow(() => {
getTeams(); getTeams();
}) });
</script> </script>
<style scoped> <style scoped>
.home-container { .home-container {

View File

@ -388,24 +388,27 @@ $primary-color: #0877F1;
.input-toolbar { .input-toolbar {
display: flex; display: flex;
align-items: center; align-items: flex-end;
padding: 28rpx 0 28rpx 0; padding: 28rpx 0 28rpx 0;
gap: 12rpx;
padding-left: 20rpx;
padding-right: 20rpx;
} }
.voice-toggle-btn{ .voice-toggle-btn{
height: 56rpx; height: 56rpx;
display: flex; display: flex;
align-items: center; align-items: center;
flex: none; flex-shrink: 0;
padding-left: 20rpx; padding: 0;
} }
.plus-btn { .plus-btn {
width: 56rpx; width: 56rpx;
height: 56rpx; height: 56rpx;
display: flex; display: flex;
align-items: center; align-items: center;
flex: none; flex-shrink: 0;
padding-right: 20rpx; padding: 0;
} }
.send-btn { .send-btn {
@ -418,13 +421,13 @@ $primary-color: #0877F1;
height: 64rpx; height: 64rpx;
min-width: 112rpx; min-width: 112rpx;
padding: 0 32rpx; padding: 0 32rpx;
margin-left: 16rpx;
box-shadow: 0 2rpx 8rpx rgba(56, 118, 246, 0.08); box-shadow: 0 2rpx 8rpx rgba(56, 118, 246, 0.08);
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
transition: background 0.2s; transition: background 0.2s;
flex: none; flex-shrink: 0;
white-space: nowrap;
} }
.send-btn:active { .send-btn:active {
@ -433,11 +436,12 @@ $primary-color: #0877F1;
.input-area { .input-area {
flex: 1; flex: 1;
margin: 0 8rpx; margin: 0;
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
min-width: 0; min-width: 0;
max-width: calc(100vw - 280rpx);
} }
.text-input, .text-input,

View File

@ -324,8 +324,16 @@ const cancelRecord = () => {
stopRecordUtil(recorderManager); stopRecordUtil(recorderManager);
}; };
//
const goToArticleList = () => {
uni.navigateTo({
url: `/pages/article/article-list?groupId=${props.groupId}&corpId=${props.corpId}`,
});
};
const morePanelButtons = [ const morePanelButtons = [
{ text: "照片", icon: "/static/icon/zhaopian.png", action: showImagePicker }, { text: "照片", icon: "/static/icon/zhaopian.png", action: showImagePicker },
{ text: "宣教", icon: "/static/icon/xuanjiaowenzhang.png", action: goToArticleList },
]; ];
function handleInputFocus() { function handleInputFocus() {

View File

@ -2534,36 +2534,71 @@ class TimChatManager {
} }
} }
// 格式化自定义消息
// 格式化自定义消息 // 格式化自定义消息
formatCustomMessage(payload) { formatCustomMessage(payload) {
try { try {
if (!payload || !payload.data) { if (!payload || !payload.data) {
console.warn('payload.data 为空:', payload)
return '[自定义消息]' return '[自定义消息]'
} }
const customData = typeof payload.data === 'string' let customData
? JSON.parse(payload.data) try {
: payload.data customData = typeof payload.data === 'string'
? JSON.parse(payload.data)
: payload.data
} catch (parseError) {
console.error('JSON 解析失败:', payload.data, parseError)
return payload.description || '[自定义消息]'
}
const messageType = customData.messageType || customData.type const messageType = customData.messageType || customData.type
const messageTypeMap = { // 使用 switch 语句保持与 getGroupListInternal 中的逻辑一致
system_message: '[系统消息]', let messageText = '[自定义消息]'
symptom: '[病情描述]', switch (messageType) {
prescription: '[处方单]', case 'system_message':
refill: '[续方申请]', messageText = '[系统消息]'
survey: '[问卷调查]', break
article: '[文章]', case 'symptom':
consult_pending: '患者向团队发起咨询请在1小时内接诊', messageText = '[病情描述]'
consult_rejected: '咨询已被拒绝', break
consult_timeout: '咨询已超时自动关闭', case 'prescription':
consult_accepted: '已接诊,会话已开始', messageText = '[处方单]'
consult_ended: '已结束当前会话', break
case 'refill':
messageText = '[续方申请]'
break
case 'survey':
messageText = '[问卷调查]'
break
case 'article':
messageText = '[文章]'
break
case 'consult_pending':
messageText = '患者向团队发起咨询请在1小时内接诊超时将自动关闭会话'
break
case 'consult_rejected':
messageText = '患者向团队发起咨询,由于有紧急事务要处理暂时无法接受咨询.本次会话已关闭'
break
case 'consult_timeout':
messageText = '患者向团队发起咨询,团队成员均未接受咨询,本次会话已自动关闭'
break
case 'consult_accepted':
messageText = '已接诊,会话已开始'
break
case 'consult_ended':
messageText = '已结束当前会话'
break
default:
messageText = customData.content || '[自定义消息]'
} }
return messageTypeMap[messageType] || customData.content || '[自定义消息]' console.log('自定义消息类型:', messageType, '显示文本:', messageText)
return messageText
} catch (error) { } catch (error) {
console.error('格式化自定义消息失败:', error) console.error('格式化自定义消息失败:', error, payload)
return '[自定义消息]' return '[自定义消息]'
} }
} }