no message
This commit is contained in:
parent
7f94fd2ee0
commit
119ada9434
@ -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'
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user