Merge remote-tracking branch 'origin/dev-2.45hjf' into dev-h2.45

This commit is contained in:
huxuejian 2026-05-29 15:47:28 +08:00
commit f5e6351e6e
3 changed files with 157 additions and 44 deletions

View File

@ -240,10 +240,21 @@ function onSearchInput() {
function canToggleFavorite(plan) { function canToggleFavorite(plan) {
if (!plan || !plan._id) return false; if (!plan || !plan._id) return false;
if (isCreatedByCurrentUser(plan)) return false;
if (activeViewType.value !== 'my') return true; if (activeViewType.value !== 'my') return true;
return Boolean(plan.isFavorite); return Boolean(plan.isFavorite);
} }
function isCreatedByCurrentUser(plan = {}) {
const userId = getUserId();
if (!userId) return false;
if (String(plan.createor || plan.creator || '') === userId) return true;
const signature = plan.creatorSignature && typeof plan.creatorSignature === 'object'
? plan.creatorSignature
: null;
return signature?.type === 'personal' && String(signature.person?.userId || '') === userId;
}
async function toggleFavorite(plan) { async function toggleFavorite(plan) {
const corpId = getCorpId(); const corpId = getCorpId();
const userId = getUserId(); const userId = getUserId();
@ -355,10 +366,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 +439,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 {

View File

@ -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,81 @@ const currentCategories = computed(() => {
return activeTab.value === "more" ? corpCategories.value : myCategories.value; return activeTab.value === "more" ? corpCategories.value : myCategories.value;
}); });
const getCategorySortValue = (category) => {
return category?.sort >= 0 ? Number(category.sort) : 10000;
};
const buildCategoryTree = (categories) => {
if (!Array.isArray(categories)) return [];
const level3 = categories
.filter((item) => item.level === 3)
.map((item) => {
const children = categories.filter((child) => child.parentId === item.id).map((child) => ({ ...child }));
const childrenIds = children.map((child) => child.id);
return { ...item, children, childrenIds };
});
const level2 = categories
.filter((item) => item.level === 2)
.map((item) => {
const children = level3.filter((child) => child.parentId === item.id).map((child) => ({ ...child }));
const childrenIds = children.map((child) => child.id);
children.forEach((child) => {
childrenIds.push(child.id);
if (Array.isArray(child.childrenIds)) {
childrenIds.push(...child.childrenIds);
}
});
return { ...item, children, childrenIds };
});
return categories
.filter((item) => item.level === 1)
.map((item) => {
const children = level2.filter((child) => child.parentId === item.id);
const childrenIds = children.map((child) => child.id);
children.forEach((child) => {
if (Array.isArray(child.childrenIds) && child.childrenIds.length > 0) {
childrenIds.push(...child.childrenIds);
}
});
return { ...item, children, childrenIds };
})
.sort((a, b) => getCategorySortValue(a) - getCategorySortValue(b));
};
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(() => {
@ -393,7 +471,7 @@ const normalizeCategory = (item, categoryType) => {
return { return {
id: item._id || item.id, id: item._id || item.id,
name, name,
sort: item.sort || 0, sort: item.sort,
level: item.level || 1, level: item.level || 1,
parentId: item.parentId || "", parentId: item.parentId || "",
type: categoryType, type: categoryType,
@ -402,6 +480,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 +552,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 +982,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 +1023,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 +1153,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 +1182,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;

View File

@ -1000,38 +1000,29 @@ 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) { try {
return; if (hasContent) {
await chatInputRef.value.sendTextMessageFromPhrase(content);
} }
for (const file of files) { for (const file of files) {
await chatInputRef.value.sendImageMessageFromPhrase(file); await chatInputRef.value.sendImageMessageFromPhrase(file);
} }
} finally {
if (files.length > 0) {
uni.hideLoading();
}
}
}; };
// //