feat: 增加常用语层级显示,优化发送效果,修改回访模板样式
This commit is contained in:
parent
ebac93569b
commit
36eff63b10
@ -355,10 +355,8 @@ function preview(plan) {
|
||||
|
||||
.category-text {
|
||||
width: 100%;
|
||||
overflow: hidden;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
display: block;
|
||||
overflow: visible;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
@ -430,9 +428,7 @@ function preview(plan) {
|
||||
color: #6b7280;
|
||||
font-size: 30rpx;
|
||||
line-height: 40rpx;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.task-link {
|
||||
|
||||
@ -21,14 +21,23 @@
|
||||
<view class="category-sidebar">
|
||||
<scroll-view class="category-list" scroll-y>
|
||||
<view
|
||||
v-for="category in currentCategories"
|
||||
v-for="category in currentCategoryNodes"
|
||||
:key="category.id"
|
||||
class="category-item"
|
||||
:class="{ active: currentCategory === category.id }"
|
||||
:style="getCategoryItemStyle(category)"
|
||||
@click="handleCategoryClick(category)"
|
||||
@longpress="handleCategoryLongPress(category)"
|
||||
>
|
||||
<view class="category-content">
|
||||
<view class="category-toggle">
|
||||
<uni-icons
|
||||
v-if="category.hasChildren"
|
||||
:type="category.expanded ? 'bottom' : 'right'"
|
||||
size="14"
|
||||
color="#6b7280"
|
||||
/>
|
||||
</view>
|
||||
<text class="category-name">{{ category.name }}</text>
|
||||
<view
|
||||
v-if="activeTab === 'mine' && isEditMode && category.deletable"
|
||||
@ -289,6 +298,7 @@ const myCategories = ref([]);
|
||||
const myPhrases = ref([]);
|
||||
const corpCategories = ref([]);
|
||||
const corpPhrases = ref([]);
|
||||
const expandedCategoryMap = ref({});
|
||||
|
||||
const showPhrasePopup = ref(false);
|
||||
const showCategoryPopup = ref(false);
|
||||
@ -317,13 +327,83 @@ const currentCategories = computed(() => {
|
||||
return activeTab.value === "more" ? corpCategories.value : myCategories.value;
|
||||
});
|
||||
|
||||
const getCategorySortValue = (category) => {
|
||||
return Number.isFinite(Number(category?.sort)) ? Number(category.sort) : 10000;
|
||||
};
|
||||
|
||||
const sortCategorySiblings = (list) => {
|
||||
return [...list].sort((a, b) => {
|
||||
const sortDiff = getCategorySortValue(a) - getCategorySortValue(b);
|
||||
if (sortDiff !== 0) return sortDiff;
|
||||
return String(a.name || "").localeCompare(String(b.name || ""), "zh-Hans-CN");
|
||||
});
|
||||
};
|
||||
|
||||
const buildCategoryTree = (categories) => {
|
||||
const nodeMap = new Map();
|
||||
const roots = [];
|
||||
|
||||
categories.forEach((category) => {
|
||||
nodeMap.set(category.id, { ...category, children: [], childrenIds: [] });
|
||||
});
|
||||
|
||||
nodeMap.forEach((node) => {
|
||||
const parent = node.parentId ? nodeMap.get(node.parentId) : null;
|
||||
if (parent) {
|
||||
parent.children.push(node);
|
||||
} else {
|
||||
roots.push(node);
|
||||
}
|
||||
});
|
||||
|
||||
const normalizeNodes = (nodes) => {
|
||||
return sortCategorySiblings(nodes).map((node) => {
|
||||
const children = normalizeNodes(node.children || []);
|
||||
const childrenIds = [];
|
||||
children.forEach((child) => {
|
||||
childrenIds.push(child.id);
|
||||
if (Array.isArray(child.childrenIds)) {
|
||||
childrenIds.push(...child.childrenIds);
|
||||
}
|
||||
});
|
||||
return { ...node, children, childrenIds };
|
||||
});
|
||||
};
|
||||
|
||||
return normalizeNodes(roots);
|
||||
};
|
||||
|
||||
const flattenCategoryTree = (nodes, visibleOnly = false) => {
|
||||
const list = [];
|
||||
const walk = (items) => {
|
||||
items.forEach((item) => {
|
||||
const children = Array.isArray(item.children) ? item.children : [];
|
||||
const expanded = expandedCategoryMap.value[item.id] !== false;
|
||||
list.push({ ...item, hasChildren: children.length > 0, expanded });
|
||||
if (children.length > 0 && (!visibleOnly || expanded)) {
|
||||
walk(item.children);
|
||||
}
|
||||
});
|
||||
};
|
||||
walk(nodes);
|
||||
return list;
|
||||
};
|
||||
|
||||
const currentCategoryTree = computed(() => buildCategoryTree(currentCategories.value));
|
||||
|
||||
const currentCategoryNodes = computed(() => flattenCategoryTree(currentCategoryTree.value, true));
|
||||
|
||||
const currentCategoryName = computed(() => {
|
||||
const category = currentCategories.value.find((item) => item.id === currentCategory.value);
|
||||
return category ? category.name : "未选择";
|
||||
});
|
||||
|
||||
const firstMyCategory = computed(() => {
|
||||
return myCategories.value[0];
|
||||
return flattenCategoryTree(buildCategoryTree(myCategories.value))[0];
|
||||
});
|
||||
|
||||
const firstCorpCategory = computed(() => {
|
||||
return flattenCategoryTree(buildCategoryTree(corpCategories.value))[0];
|
||||
});
|
||||
|
||||
const defaultMyCategory = computed(() => {
|
||||
@ -402,6 +482,10 @@ const normalizeCategory = (item, categoryType) => {
|
||||
};
|
||||
};
|
||||
|
||||
const sortFlatCategoriesByTree = (categories) => {
|
||||
return flattenCategoryTree(buildCategoryTree(categories)).map(({ hasChildren, expanded, ...item }) => item);
|
||||
};
|
||||
|
||||
const normalizeFiles = (files) => {
|
||||
if (!Array.isArray(files)) return [];
|
||||
return files
|
||||
@ -470,19 +554,37 @@ const switchTab = (tab) => {
|
||||
currentCategory.value =
|
||||
tab === "mine"
|
||||
? defaultMyCategory.value?.id || firstMyCategory.value?.id || ""
|
||||
: corpCategories.value[0]?.id || "";
|
||||
: firstCorpCategory.value?.id || "";
|
||||
};
|
||||
|
||||
const toggleEditMode = () => {
|
||||
isEditMode.value = !isEditMode.value;
|
||||
};
|
||||
|
||||
const getCategoryItemStyle = (category) => {
|
||||
const level = Math.max(Number(category?.level || 1), 1);
|
||||
return {
|
||||
paddingLeft: `${8 + (level - 1) * 12}rpx`,
|
||||
};
|
||||
};
|
||||
|
||||
const toggleCategoryExpand = (category) => {
|
||||
if (!category?.hasChildren) return;
|
||||
expandedCategoryMap.value = {
|
||||
...expandedCategoryMap.value,
|
||||
[category.id]: !category.expanded,
|
||||
};
|
||||
};
|
||||
|
||||
const handleCategoryClick = (category) => {
|
||||
if (activeTab.value === "mine" && isEditMode.value && category.deletable) {
|
||||
editCategory(category);
|
||||
return;
|
||||
}
|
||||
currentCategory.value = category.id;
|
||||
if (category.hasChildren) {
|
||||
toggleCategoryExpand(category);
|
||||
}
|
||||
};
|
||||
|
||||
const sendPhrase = (phrase) => {
|
||||
@ -882,7 +984,8 @@ const loadMyCategories = async ({ ensureDefault = true } = {}) => {
|
||||
const result = await api("getUserCommonWordCate", { corpId, userId });
|
||||
if (result.success) {
|
||||
const list = Array.isArray(result.list) ? result.list : [];
|
||||
myCategories.value = list.map((item) => normalizeCategory(item, "user")).filter((item) => item.id);
|
||||
const categories = list.map((item) => normalizeCategory(item, "user")).filter((item) => item.id);
|
||||
myCategories.value = sortFlatCategoriesByTree(categories);
|
||||
if (ensureDefault && !defaultMyCategory.value) {
|
||||
await createDefaultMyCategory();
|
||||
return;
|
||||
@ -922,9 +1025,10 @@ const loadCorpCategories = async () => {
|
||||
const result = await api("getCorpCommonWordCate", { corpId, userId }, false);
|
||||
if (result.success) {
|
||||
const list = Array.isArray(result.list) ? result.list : [];
|
||||
corpCategories.value = list.map((item) => normalizeCategory(item, "corp")).filter((item) => item.id);
|
||||
const categories = list.map((item) => normalizeCategory(item, "corp")).filter((item) => item.id);
|
||||
corpCategories.value = sortFlatCategoriesByTree(categories);
|
||||
if (activeTab.value === "more" && !currentCategory.value) {
|
||||
currentCategory.value = corpCategories.value[0]?.id || "";
|
||||
currentCategory.value = firstCorpCategory.value?.id || "";
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -1051,7 +1155,7 @@ $border-color: #edf0f5;
|
||||
min-height: 88rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
justify-content: flex-start;
|
||||
padding: 12rpx 16rpx;
|
||||
color: #344054;
|
||||
background: #fff;
|
||||
@ -1080,15 +1184,28 @@ $border-color: #edf0f5;
|
||||
.category-content {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.category-name {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
font-size: 30rpx;
|
||||
line-height: 40rpx;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.category-toggle {
|
||||
width: 32rpx;
|
||||
height: 40rpx;
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.delete-badge {
|
||||
position: absolute;
|
||||
top: -22rpx;
|
||||
|
||||
@ -994,43 +994,34 @@ onHide(() => {
|
||||
|
||||
const sendCommonPhrase = async (phraseOrContent) => {
|
||||
if (!chatInputRef.value) return;
|
||||
|
||||
const content =
|
||||
typeof phraseOrContent === "string"
|
||||
|
||||
const content =
|
||||
typeof phraseOrContent === "string"
|
||||
? phraseOrContent
|
||||
: phraseOrContent?.content || "";
|
||||
const files = Array.isArray(phraseOrContent?.files) ? phraseOrContent.files : [];
|
||||
const hasContent = Boolean(content.trim());
|
||||
|
||||
if (content.trim()) {
|
||||
chatInputRef.value.setInputText(content);
|
||||
}
|
||||
|
||||
if (files.length === 0) {
|
||||
if (!hasContent && files.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const shouldSendImages = await new Promise((resolve) => {
|
||||
uni.showModal({
|
||||
title: "提示",
|
||||
content: `该常用语包含${files.length}张图片,是否发送图片?`,
|
||||
cancelText: "取消",
|
||||
confirmText: "发送",
|
||||
success: (res) => {
|
||||
resolve(Boolean(res.confirm));
|
||||
},
|
||||
fail: (error) => {
|
||||
console.error("常用语图片发送确认失败:", error);
|
||||
resolve(false);
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
if (!shouldSendImages) {
|
||||
return;
|
||||
if (files.length > 0) {
|
||||
uni.showLoading({ title: "发送中...", mask: true });
|
||||
}
|
||||
|
||||
for (const file of files) {
|
||||
await chatInputRef.value.sendImageMessageFromPhrase(file);
|
||||
try {
|
||||
if (hasContent) {
|
||||
await chatInputRef.value.sendTextMessageFromPhrase(content);
|
||||
}
|
||||
|
||||
for (const file of files) {
|
||||
await chatInputRef.value.sendImageMessageFromPhrase(file);
|
||||
}
|
||||
} finally {
|
||||
if (files.length > 0) {
|
||||
uni.hideLoading();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user