|
|
@@ -45,17 +45,49 @@ import Dialog from '@/components/dialog/Dialog.vue';
|
|
|
import Field from '@/components/form/Field.vue';
|
|
|
import FlexCol from '@/components/layout/FlexCol.vue';
|
|
|
import FlexRow from '@/components/layout/FlexRow.vue';
|
|
|
-import { alert } from '@/components/dialog/CommonRoot';
|
|
|
-import { back } from '@/components/utils/PageAction';
|
|
|
-import { onMounted, ref } from 'vue';
|
|
|
+import { back, callTopOnPageBack } from '@/components/utils/PageAction';
|
|
|
+import { ref } from 'vue';
|
|
|
import { defaultTags } from '../data/DefaultTag';
|
|
|
import DragSortList from '@/common/components/DragSortList.vue';
|
|
|
+import { useLoadQuerys } from '@/components/composeabe/LoadQuerys';
|
|
|
+import OfficialApi, { WechatTopicItem } from '@/api/light/OfficialApi';
|
|
|
+import { toast, loading, hideLoading } from '@/components/utils/DialogAction';
|
|
|
|
|
|
-const tags = ref<{
|
|
|
+interface TagItem {
|
|
|
+ id?: number;
|
|
|
title: string;
|
|
|
icon: string;
|
|
|
disabled: boolean;
|
|
|
-}[]>([]);
|
|
|
+}
|
|
|
+
|
|
|
+const tags = ref<TagItem[]>([]);
|
|
|
+const originalTags = ref<WechatTopicItem[]>([]);
|
|
|
+
|
|
|
+const loadTags = async () => {
|
|
|
+ try {
|
|
|
+ const { list } = await OfficialApi.getWechatTopicList({
|
|
|
+ villageId: querys.value.villageId,
|
|
|
+ });
|
|
|
+ originalTags.value = list;
|
|
|
+ tags.value = list.length > 0
|
|
|
+ ? list.map(item => ({
|
|
|
+ id: item.id,
|
|
|
+ title: item.name,
|
|
|
+ icon: item.image,
|
|
|
+ disabled: false,
|
|
|
+ }))
|
|
|
+ : defaultTags.map(title => ({ title, icon: '', disabled: false }));
|
|
|
+ } catch (e) {
|
|
|
+ toast('加载话题列表失败');
|
|
|
+ tags.value = defaultTags.map(title => ({ title, icon: '', disabled: false }));
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+const { querys } = useLoadQuerys({
|
|
|
+ villageId: 0,
|
|
|
+}, async () => {
|
|
|
+ await loadTags();
|
|
|
+});
|
|
|
|
|
|
const addTagVisible = ref(false);
|
|
|
const addTagTitle = ref('');
|
|
|
@@ -76,21 +108,57 @@ const handleAddTag = () => {
|
|
|
addTagVisible.value = true;
|
|
|
}
|
|
|
|
|
|
-const handleSave = () => {
|
|
|
- //TODO: saveTags();
|
|
|
- alert({ content: '缺少接口,敬请期待' })
|
|
|
+const handleSave = async () => {
|
|
|
+ const villageId = querys.value.villageId;
|
|
|
+ const tasks: Promise<unknown>[] = [];
|
|
|
+
|
|
|
+ // 删除:原列表中存在但当前列表已移除的
|
|
|
+ for (const original of originalTags.value) {
|
|
|
+ if (!tags.value.some(tag => tag.id === original.id)) {
|
|
|
+ tasks.push(OfficialApi.delWechatTopic(original.id));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 保存:新增 或 名称/顺序发生变化的
|
|
|
+ tags.value.forEach((tag, index) => {
|
|
|
+ if (tag.id == null) {
|
|
|
+ tasks.push(OfficialApi.saveWechatTopic({
|
|
|
+ villageId,
|
|
|
+ name: tag.title,
|
|
|
+ weigh: index,
|
|
|
+ status: 1,
|
|
|
+ }));
|
|
|
+ } else {
|
|
|
+ const original = originalTags.value.find(item => item.id === tag.id);
|
|
|
+ if (original && (original.name !== tag.title || original.weigh !== index)) {
|
|
|
+ tasks.push(OfficialApi.saveWechatTopic({
|
|
|
+ id: tag.id,
|
|
|
+ villageId,
|
|
|
+ name: tag.title,
|
|
|
+ weigh: index,
|
|
|
+ status: original.status,
|
|
|
+ }));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ if (tasks.length > 0) {
|
|
|
+ loading('保存中');
|
|
|
+ try {
|
|
|
+ await Promise.all(tasks);
|
|
|
+ toast('保存成功');
|
|
|
+ } catch (e) {
|
|
|
+ toast('保存失败');
|
|
|
+ return;
|
|
|
+ } finally {
|
|
|
+ hideLoading();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ await callTopOnPageBack('backRefreshTags', {});
|
|
|
}
|
|
|
|
|
|
const handleCancel = () => {
|
|
|
back();
|
|
|
}
|
|
|
-
|
|
|
-onMounted(() => {
|
|
|
- //TODO: getTags(); 如果为空则使用默认话题列表 defaultTags
|
|
|
- tags.value = defaultTags.map(item => ({
|
|
|
- title: item,
|
|
|
- icon: '',
|
|
|
- disabled: false,
|
|
|
- }));
|
|
|
-})
|
|
|
</script>
|