feat: 增加常用语层级显示,优化发送效果,修改回访模板样式
This commit is contained in:
parent
ebac93569b
commit
36eff63b10
@ -355,10 +355,8 @@ function preview(plan) {
|
|||||||
|
|
||||||
.category-text {
|
.category-text {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
overflow: hidden;
|
display: block;
|
||||||
display: -webkit-box;
|
overflow: visible;
|
||||||
-webkit-line-clamp: 2;
|
|
||||||
-webkit-box-orient: vertical;
|
|
||||||
word-break: break-all;
|
word-break: break-all;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -430,9 +428,7 @@ function preview(plan) {
|
|||||||
color: #6b7280;
|
color: #6b7280;
|
||||||
font-size: 30rpx;
|
font-size: 30rpx;
|
||||||
line-height: 40rpx;
|
line-height: 40rpx;
|
||||||
overflow: hidden;
|
word-break: break-all;
|
||||||
text-overflow: ellipsis;
|
|
||||||
white-space: nowrap;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.task-link {
|
.task-link {
|
||||||
|
|||||||
@ -21,14 +21,23 @@
|
|||||||
<view class="category-sidebar">
|
<view class="category-sidebar">
|
||||||
<scroll-view class="category-list" scroll-y>
|
<scroll-view class="category-list" scroll-y>
|
||||||
<view
|
<view
|
||||||
v-for="category in currentCategories"
|
v-for="category in currentCategoryNodes"
|
||||||
:key="category.id"
|
:key="category.id"
|
||||||
class="category-item"
|
class="category-item"
|
||||||
:class="{ active: currentCategory === category.id }"
|
:class="{ active: currentCategory === category.id }"
|
||||||
|
:style="getCategoryItemStyle(category)"
|
||||||
@click="handleCategoryClick(category)"
|
@click="handleCategoryClick(category)"
|
||||||
@longpress="handleCategoryLongPress(category)"
|
@longpress="handleCategoryLongPress(category)"
|
||||||
>
|
>
|
||||||
<view class="category-content">
|
<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>
|
<text class="category-name">{{ category.name }}</text>
|
||||||
<view
|
<view
|
||||||
v-if="activeTab === 'mine' && isEditMode && category.deletable"
|
v-if="activeTab === 'mine' && isEditMode && category.deletable"
|
||||||
@ -289,6 +298,7 @@ const myCategories = ref([]);
|
|||||||
const myPhrases = ref([]);
|
const myPhrases = ref([]);
|
||||||
const corpCategories = ref([]);
|
const corpCategories = ref([]);
|
||||||
const corpPhrases = ref([]);
|
const corpPhrases = ref([]);
|
||||||
|
const expandedCategoryMap = ref({});
|
||||||
|
|
||||||
const showPhrasePopup = ref(false);
|
const showPhrasePopup = ref(false);
|
||||||
const showCategoryPopup = ref(false);
|
const showCategoryPopup = ref(false);
|
||||||
@ -317,13 +327,83 @@ const currentCategories = computed(() => {
|
|||||||
return activeTab.value === "more" ? corpCategories.value : myCategories.value;
|
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 currentCategoryName = computed(() => {
|
||||||
const category = currentCategories.value.find((item) => item.id === currentCategory.value);
|
const category = currentCategories.value.find((item) => item.id === currentCategory.value);
|
||||||
return category ? category.name : "未选择";
|
return category ? category.name : "未选择";
|
||||||
});
|
});
|
||||||
|
|
||||||
const firstMyCategory = computed(() => {
|
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(() => {
|
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) => {
|
const normalizeFiles = (files) => {
|
||||||
if (!Array.isArray(files)) return [];
|
if (!Array.isArray(files)) return [];
|
||||||
return files
|
return files
|
||||||
@ -470,19 +554,37 @@ const switchTab = (tab) => {
|
|||||||
currentCategory.value =
|
currentCategory.value =
|
||||||
tab === "mine"
|
tab === "mine"
|
||||||
? defaultMyCategory.value?.id || firstMyCategory.value?.id || ""
|
? defaultMyCategory.value?.id || firstMyCategory.value?.id || ""
|
||||||
: corpCategories.value[0]?.id || "";
|
: firstCorpCategory.value?.id || "";
|
||||||
};
|
};
|
||||||
|
|
||||||
const toggleEditMode = () => {
|
const toggleEditMode = () => {
|
||||||
isEditMode.value = !isEditMode.value;
|
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) => {
|
const handleCategoryClick = (category) => {
|
||||||
if (activeTab.value === "mine" && isEditMode.value && category.deletable) {
|
if (activeTab.value === "mine" && isEditMode.value && category.deletable) {
|
||||||
editCategory(category);
|
editCategory(category);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
currentCategory.value = category.id;
|
currentCategory.value = category.id;
|
||||||
|
if (category.hasChildren) {
|
||||||
|
toggleCategoryExpand(category);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const sendPhrase = (phrase) => {
|
const sendPhrase = (phrase) => {
|
||||||
@ -882,7 +984,8 @@ const loadMyCategories = async ({ ensureDefault = true } = {}) => {
|
|||||||
const result = await api("getUserCommonWordCate", { corpId, userId });
|
const result = await api("getUserCommonWordCate", { corpId, userId });
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
const list = Array.isArray(result.list) ? result.list : [];
|
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) {
|
if (ensureDefault && !defaultMyCategory.value) {
|
||||||
await createDefaultMyCategory();
|
await createDefaultMyCategory();
|
||||||
return;
|
return;
|
||||||
@ -922,9 +1025,10 @@ const loadCorpCategories = async () => {
|
|||||||
const result = await api("getCorpCommonWordCate", { corpId, userId }, false);
|
const result = await api("getCorpCommonWordCate", { corpId, userId }, false);
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
const list = Array.isArray(result.list) ? result.list : [];
|
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) {
|
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;
|
min-height: 88rpx;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: flex-start;
|
||||||
padding: 12rpx 16rpx;
|
padding: 12rpx 16rpx;
|
||||||
color: #344054;
|
color: #344054;
|
||||||
background: #fff;
|
background: #fff;
|
||||||
@ -1080,15 +1184,28 @@ $border-color: #edf0f5;
|
|||||||
.category-content {
|
.category-content {
|
||||||
position: relative;
|
position: relative;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
text-align: center;
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
min-width: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.category-name {
|
.category-name {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
font-size: 30rpx;
|
font-size: 30rpx;
|
||||||
line-height: 40rpx;
|
line-height: 40rpx;
|
||||||
word-break: break-all;
|
word-break: break-all;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.category-toggle {
|
||||||
|
width: 32rpx;
|
||||||
|
height: 40rpx;
|
||||||
|
flex-shrink: 0;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
.delete-badge {
|
.delete-badge {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: -22rpx;
|
top: -22rpx;
|
||||||
|
|||||||
@ -1000,37 +1000,28 @@ const sendCommonPhrase = async (phraseOrContent) => {
|
|||||||
? phraseOrContent
|
? phraseOrContent
|
||||||
: phraseOrContent?.content || "";
|
: phraseOrContent?.content || "";
|
||||||
const files = Array.isArray(phraseOrContent?.files) ? phraseOrContent.files : [];
|
const files = Array.isArray(phraseOrContent?.files) ? phraseOrContent.files : [];
|
||||||
|
const hasContent = Boolean(content.trim());
|
||||||
|
|
||||||
if (content.trim()) {
|
if (!hasContent && files.length === 0) {
|
||||||
chatInputRef.value.setInputText(content);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (files.length === 0) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const shouldSendImages = await new Promise((resolve) => {
|
if (files.length > 0) {
|
||||||
uni.showModal({
|
uni.showLoading({ title: "发送中...", mask: true });
|
||||||
title: "提示",
|
|
||||||
content: `该常用语包含${files.length}张图片,是否发送图片?`,
|
|
||||||
cancelText: "取消",
|
|
||||||
confirmText: "发送",
|
|
||||||
success: (res) => {
|
|
||||||
resolve(Boolean(res.confirm));
|
|
||||||
},
|
|
||||||
fail: (error) => {
|
|
||||||
console.error("常用语图片发送确认失败:", error);
|
|
||||||
resolve(false);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!shouldSendImages) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const file of files) {
|
try {
|
||||||
await chatInputRef.value.sendImageMessageFromPhrase(file);
|
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