no message

This commit is contained in:
wangdongbo 2026-01-23 16:42:50 +08:00
parent 7f94fd2ee0
commit 119ada9434

View File

@ -220,59 +220,63 @@ const editPhrase = (phrase) => {
const savePhrase = async () => { const savePhrase = async () => {
if (!phraseForm.value.content.trim()) { if (!phraseForm.value.content.trim()) {
uni.showToast({ uni.showToast({
title: "请输入内容", title: '请输入内容',
icon: "none", icon: 'none'
}); });
return; return;
} }
try { try {
if (editingPhrase.value) { const corpId = uni.getStorageSync('corpId');
// const userId = uni.getStorageSync('userId');
await api("saveCommonPhrase", {
id: editingPhrase.value.id, if (!corpId || !userId) {
categoryId: editingPhrase.value.categoryId, uni.showToast({
title: '请先登录',
icon: 'none'
});
return;
}
const result = await api('saveCommonPhrase', {
id: editingPhrase.value?.id,
categoryId: editingPhrase.value?.categoryId || currentCategory.value,
content: phraseForm.value.content, content: phraseForm.value.content,
corpId: uni.getStorageSync("corpId"), corpId,
userId
}); });
const index = phrases.value.findIndex( if (result.code === 200) {
(p) => p.id === editingPhrase.value.id if (editingPhrase.value) {
); //
const index = phrases.value.findIndex(p => p.id === editingPhrase.value.id);
if (index !== -1) { if (index !== -1) {
phrases.value[index].content = phraseForm.value.content; phrases.value[index].content = phraseForm.value.content;
} }
} else { } else {
// //
const result = await api("saveCommonPhrase", { if (result.data) {
categoryId: currentCategory.value,
content: phraseForm.value.content,
corpId: uni.getStorageSync("corpId"),
});
if (result.code === 200 && result.data) {
phrases.value.push(result.data); phrases.value.push(result.data);
} else {
// API使ID
phrases.value.push({
id: Date.now(),
categoryId: currentCategory.value,
content: phraseForm.value.content,
});
} }
} }
uni.showToast({ uni.showToast({
title: editingPhrase.value ? "保存成功" : "添加成功", title: editingPhrase.value ? '保存成功' : '添加成功',
icon: "success", icon: 'success'
}); });
closePopup(); closePopup();
} catch (error) { } else {
console.error("保存常用语失败:", error);
uni.showToast({ uni.showToast({
title: "操作失败", title: result.message || '操作失败',
icon: "none", icon: 'none'
});
}
} catch (error) {
console.error('保存常用语失败:', error);
uni.showToast({
title: '操作失败',
icon: 'none'
}); });
} }
}; };
@ -398,20 +402,52 @@ const closeCategoryPopup = () => {
// //
const loadPhrases = async () => { const loadPhrases = async () => {
try { try {
const result = await api("getCommonPhrases", { const corpId = uni.getStorageSync('corpId');
corpId: uni.getStorageSync("corpId"), const userId = uni.getStorageSync('userId');
if (!corpId) {
uni.showToast({
title: '请先登录',
icon: 'none'
});
return;
}
const result = await api('getCommonPhrases', {
corpId,
userId
}); });
if (result.code === 200 && result.data) { if (result.code === 200) {
//
if (Array.isArray(result.data)) {
phrases.value = result.data; phrases.value = result.data;
} else { }
// API使
phrases.value = getMockPhrases(); //
if (Array.isArray(result.categories)) {
const backendCategories = result.categories.map(cat => ({
id: cat.id,
name: cat.name,
deletable: true //
}));
// 使使
if (backendCategories.length > 0) {
categories.value = backendCategories;
//
if (!currentCategory.value || !categories.value.find(c => c.id === currentCategory.value)) {
currentCategory.value = categories.value[0].id;
}
}
}
} }
} catch (error) { } catch (error) {
console.error("加载常用语失败:", error); console.error('加载常用语失败:', error);
// 使 uni.showToast({
phrases.value = getMockPhrases(); title: '加载失败',
icon: 'none'
});
} }
}; };