import { defineStore } from "pinia" import { getGroupUserListFromInteraction, getGroupUserListFromTriangle, getGroupUserListFromSocial, getInteractionPostList, getInteractionCommunityNodes, getInteractionCommunityDetailNodes, getInteractionCommunityStatistics, getSocialCommunityList, getSocialCommunityStatistics, getSocialCommunityDetailNodes, getSocialPostListByRelationId, getCharacterSocialCommunityNodes, getCharacterSocialCommunityStatistics, getCharacterSocialCommunityDetailNodes } from "@/service/api/linkPrediction" import defaultAvatar from "@/assets/images/avatar/default.png" import nodePrefix from "@/assets/images/linkPrediction/icon/node-count-prefix.png" import communityPrefix from "@/assets/images/linkPrediction/icon/community-count-prefix.png" import hiddenPrefix from "@/assets/images/linkPrediction/icon/hidden-count-prefix.png" import tightCommunityPrefix from "@/assets/images/linkPrediction/icon/tightCommunityPrefix.png" export const useCharacterInteractionStore = defineStore("characterInteraction", { state: () => ({ userList: [], //用户组列表 posts: [], //贴文列表 communityNodeList: [], //所有社团数据 curComponent: "CommunityNode", curSelecedGroupIds: [], predictionLegendContent: "互动隐关系", communityDetailNodeRelation: [], //点击一级界面后,查询到的节点间关系 communityDetailNodeList: [], //节点用户列表 timeList: [], predictionUserIds: [], //包含从用户组选择的用户id或者是点击某个社团或者连边后,所需要高亮的所有用户的id curRelationId: "", predictionLineColor: "#f8bf38", predictionLegendIcon: `image://${new URL("@/assets/images/linkPrediction/icon/hidden-icon.png", import.meta.url)}`, anlysisList: [ { id: 1, title: "平均评论数", unit: "数量", xAxis: [0, 20, 40, 60, 80, 100], max: 100, rows: [ { label: "目标用户", value: 98.8, type: "leader" }, { label: "所有用户", value: 0.01, type: "user" } ] }, { id: 2, title: "平均转发次数", unit: "数量", xAxis: [0, 3, 6, 9, 12, 16, 18], max: 18, rows: [ { label: "目标用户", value: 17, type: "leader" }, { label: "所有用户", value: 0.01, type: "user" } ] }, { id: 3, title: "互动时间间隔", unit: "秒", xAxis: [0, 30, 60, 90, 120, 150], max: 150, rows: [ { label: "目标用户", value: 3.63, type: "leader", highlight: false }, { label: "所有用户", value: 127.63, type: "user" } ] } ], wordCloudData: [ { text: "佩洛西", top: 115.5, left: 215.5, width: 109, height: 40, fontSize: 28, opacity: 1 }, { text: "中国", top: 183.5, left: 69.5, width: 73, height: 35, fontSize: 22, opacity: 1 }, { text: "中国人民解放军", top: 72.5, left: 132.5, width: 123, height: 22, fontSize: 12, opacity: 1 }, { text: "中美关系", top: 171.5, left: 212.5, width: 81, height: 22, fontSize: 14, opacity: 0.8 }, { text: "台独", top: 135.5, left: 42.5, width: 57, height: 24, fontSize: 16, opacity: 1 }, { text: "台海和平", top: 228.5, left: 230.5, width: 81, height: 22, fontSize: 14, opacity: 0.8 }, { text: "坚决反对", top: 200.5, left: 38.5, width: 73, height: 19, fontSize: 12, opacity: 0.7 }, { text: "联合公报", top: 241.5, left: 130.5, width: 73, height: 19, fontSize: 12, opacity: 0.7 }, { text: "有力反制", top: 211.5, left: 143.5, width: 73, height: 19, fontSize: 12, opacity: 1 }, { text: "白宫", top: 176.5, left: 15.5, width: 49, height: 19, fontSize: 12, opacity: 0.8 }, { text: "内政", top: 87.5, left: 36.5, width: 53, height: 22, fontSize: 14, opacity: 1 }, { text: "访台", top: 103.5, left: 95.5, width: 49, height: 19, fontSize: 12, opacity: 0.8 }, { text: "领土", top: 57.5, left: 72.5, width: 49, height: 19, fontSize: 12, opacity: 0.6 }, { text: "原则", top: 77.5, left: 264.5, width: 49, height: 19, fontSize: 12, opacity: 0.7 }, { text: "台湾", top: 195.5, left: 287.5, width: 49, height: 19, fontSize: 12, opacity: 0.8 } ], statisticsList: [ { id: 1, icon: nodePrefix, name: "节点数", key: "nodesCount" }, { id: 2, icon: communityPrefix, name: "社团数", key: "groupCount" }, { id: 3, icon: hiddenPrefix, name: "隐关系数", key: "hiddenInteractionCount" } ], statisticsDetailList: [ { id: 1, icon: nodePrefix, name: "节点数", key: "nodesCount" }, { id: 2, icon: communityPrefix, name: "社团数", key: "groupCount" }, { id: 3, icon: hiddenPrefix, name: "隐关系数", key: "hiddenInteractionCount" } ] }), actions: { //初始化用户组列表 async initGroupList() { const res = await getGroupUserListFromInteraction() if (res.code != 200) { return } this.userList = res.data.userList.sort((a, b) => a.rank - b.rank) }, //初始化贴文数据 && 点击用户组列表展示该用户组的贴文 async initInteractionPostList(userGroupId) { const res = await getInteractionPostList(userGroupId) if (res.code != 200) return this.posts = res.data }, //初始化社团节点 async initGraphCommunityNode() { const res = await getInteractionCommunityNodes() if (res.code != 200) return this.communityNodeList = res.data }, //点击社团节点的黄色边,或者存在预测节点的社团,获取社团内部详情 async initGraphCommunityDetailNode(ids, time = "2024-05-16 16:56:04", relationId = -1) { this.curSelecedGroupIds = ids const res = await getInteractionCommunityDetailNodes(ids, relationId, time) if (res.code != 200) return const customStatisticsObj = Object.assign({}, res.data.communityStatistics) //计算两个用户是否同属与同一个社团 if ( customStatisticsObj.groupCount == null && customStatisticsObj.hiddenInteractionCount == null ) { customStatisticsObj.hiddenInteractionCount = 1 customStatisticsObj.groupCount = ids[0] === ids[1] ? 1 : 2 } this.statisticsDetailList = this.statisticsDetailList.map((item) => ({ ...item, count: customStatisticsObj[item.key] })) this.communityDetailNodeRelation = res.data.userRelation this.communityDetailNodeList = res.data.userList this.timeList = Array.from(new Set(res.data.timeList)) this.predictionUserIds = res.data.predictNodes }, //初始化社团统计数据 async initGraphStatistics() { const res = await getInteractionCommunityStatistics() this.statisticsList = this.statisticsList.map((item) => ({ ...item, count: res.data[item.key] })) } }, persist: true // 开启持久化 }) export const useSocialGroupsStore = defineStore("socialGroups", { state: () => ({ userList: [], communityNodeList: [], curComponent: "CommunityNode", curSelecedGroupIds: [], communityDetailNodeList: [], // 社交紧密团体的所有用户 communityAllNodeList: [], timeList: [], // 当前需要高亮的用户id curHighlightUserIdList: [], // 当前的relationId curRelationId: "", // 记录点击边的时序列表 clickEdgeTimeList: [], // 记录是从边点的还是列表项中的点击 clickEvent: "list", // list 表示从列表项点的, edge 表示从边点的 statisticsList: [ { id: 1, icon: nodePrefix, name: "节点数", key: "nodesCount" }, { id: 2, icon: communityPrefix, name: "社团数", key: "groupCount" }, { id: 3, icon: tightCommunityPrefix, name: "紧密团体数", key: "hiddenInteractionCount" } ], statisticsDetailList: [ { id: 1, icon: nodePrefix, name: "节点数", key: "nodesCount" }, { id: 2, icon: communityPrefix, name: "社团数", key: "groupCount" }, { id: 3, icon: tightCommunityPrefix, name: "紧密团体数", key: "hiddenInteractionCount" } ], userChartList: [ { id: 1, group: [ { id: 1, name: "Polo Hun", avatar: defaultAvatar, fancy: 634, post: 32 }, { id: 2, name: "楊政子", avatar: defaultAvatar, fancy: 5556, post: 23 }, { id: 3, name: "楊政子", avatar: defaultAvatar, fancy: 5556, post: 23 } ], number: "0.60" }, { id: 2, group: [ { id: 7, name: "一人一讚 馬總統感恩有您 永遠支...", avatar: defaultAvatar, fancy: 0, post: 0 }, { id: 8, name: "一人一讚 馬總統感恩有您 永遠支...", avatar: defaultAvatar, fancy: 564, post: 13 }, { id: 9, name: "一人一讚 馬總統感恩有您 永遠支...", avatar: defaultAvatar, fancy: 564, post: 13 } ], number: 0.45 }, { id: 3, group: [ { id: 10, name: "一人一讚 馬總統感恩有您 永遠支...", avatar: defaultAvatar, fancy: 0, post: 0 }, { id: 11, name: "一人一讚 馬總統感恩有您 永遠支...", avatar: defaultAvatar, fancy: 564, post: 13 }, { id: 12, name: "一人一讚 馬總統感恩有您 永遠支...", avatar: defaultAvatar, fancy: 564, post: 13 } ], number: 0.32 } ], posts: [], anlysisList: [ { id: 1, title: "平均评论数", unit: "数量", xAxis: [0, 20, 40, 60, 80, 100], max: 100, rows: [ { label: "目标用户", value: 37.33, type: "leader" }, { label: "所有用户", value: 0.06, type: "user" } ] }, { id: 2, title: "平均转发次数", unit: "数量", xAxis: [0, 0.1, 0.2, 0.3, 0.4, 0.5], max: 0.5, rows: [ { label: "目标用户", value: 0.31, type: "leader" }, { label: "所有用户", value: 0.004, type: "user" } ] }, { id: 3, title: "互动时间间隔", unit: "秒", xAxis: [0, 100, 200, 300, 400, 500], max: 600, rows: [ { label: "目标用户", value: 42.55, type: "leader", highlight: false }, { label: "所有用户", value: 582.23, type: "user" } ] } ], wordCloudData: [ { text: "佩洛西", top: 115.5, left: 215.5, width: 109, height: 40, fontSize: 28, opacity: 1 }, { text: "中国", top: 183.5, left: 69.5, width: 73, height: 35, fontSize: 22, opacity: 1 }, { text: "中国人民解放军", top: 72.5, left: 132.5, width: 123, height: 22, fontSize: 12, opacity: 1 }, { text: "中美关系", top: 171.5, left: 212.5, width: 81, height: 22, fontSize: 14, opacity: 0.8 }, { text: "台独", top: 135.5, left: 42.5, width: 57, height: 24, fontSize: 16, opacity: 1 }, { text: "台海和平", top: 228.5, left: 230.5, width: 81, height: 22, fontSize: 14, opacity: 0.8 }, { text: "坚决反对", top: 200.5, left: 38.5, width: 73, height: 19, fontSize: 12, opacity: 0.7 }, { text: "联合公报", top: 241.5, left: 130.5, width: 73, height: 19, fontSize: 12, opacity: 0.7 }, { text: "有力反制", top: 211.5, left: 143.5, width: 73, height: 19, fontSize: 12, opacity: 1 }, { text: "白宫", top: 176.5, left: 15.5, width: 49, height: 19, fontSize: 12, opacity: 0.8 }, { text: "内政", top: 87.5, left: 36.5, width: 53, height: 22, fontSize: 14, opacity: 1 }, { text: "访台", top: 103.5, left: 95.5, width: 49, height: 19, fontSize: 12, opacity: 0.8 }, { text: "领土", top: 57.5, left: 72.5, width: 49, height: 19, fontSize: 12, opacity: 0.6 }, { text: "原则", top: 77.5, left: 264.5, width: 49, height: 19, fontSize: 12, opacity: 0.7 }, { text: "台湾", top: 195.5, left: 287.5, width: 49, height: 19, fontSize: 12, opacity: 0.8 } ] }), actions: { // 互动行为相似列表数据 async initGroupList() { const res = await getGroupUserListFromTriangle() if (res.code != 200) return // 按rank属性升序排序userList res.data.userList.sort((a, b) => a.rank - b.rank) this.userList = res.data.userList }, // 事件脉络分析中的帖文数据 async initPostList(relationId) { const res = await getSocialPostListByRelationId(relationId) if (res.code != 200) return if (this.posts.length != 0) { this.posts.push(...res.data) } else { this.posts = res.data } }, // 获取对应用户组的postList async getSocialGroupPostListByRelationId(relationId) { const res = await getSocialPostListByRelationId(relationId) if (res.code != 200) return // console.log("打印对应relationId的帖文列表:", res.data) this.posts = res.data }, async initGraphCommunityNode() { const res = await getSocialCommunityList() if (res.code != 200) return this.communityNodeList = res.data }, // 社交紧密团体识别的社团统计 async initGraphStatistics() { const res = await getSocialCommunityStatistics() this.statisticsList = this.statisticsList.map((item) => ({ ...item, count: res.data[item.key] })) }, // 传递社交团体的数组,获取其详情 async initGraphCommunityDetailNode(ids, time = "2024-05-16 16:56:04", relationId = -1) { this.curSelecedGroupIds = ids const res = await getSocialCommunityDetailNodes(ids, relationId, time) if (res.code != 200) return console.log("index.js:", res.data) const customStatisticsObj = Object.assign({}, res.data.communityStatistics) //计算两个用户是否同属与同一个社团 if ( customStatisticsObj.groupCount == null && customStatisticsObj.hiddenInteractionCount == null ) { customStatisticsObj.hiddenInteractionCount = 1 // 创建一个Set来获取不重复的ids const uniqueIds = new Set(ids); customStatisticsObj.groupCount = uniqueIds.size; } this.statisticsDetailList = this.statisticsDetailList.map((item) => ({ ...item, count: customStatisticsObj[item.key] })) // 设置社交紧密团体的所有用户id this.communityAllNodeList = res.data.userList this.communityDetailNodeList = res.data.userRelation this.curHighlightUserIdList = res.data.predictNodes }, // 修改timeList setTimeList(timeList) { this.timeList = timeList }, // 点击边,先获取需要的timeList async getClickEdgeTimeList(ids, time = "2024-05-16 16:56:04") { const relationId = -1 const res = await getSocialCommunityDetailNodes(ids, relationId, time) if (res.code != 200) return console.log("3.获取边中的timelist并设置成它") this.setTimeList(res.data.timeList) } }, persist: true // 开启持久化 }) export const useCharacterHiddenStore = defineStore("characterHidden", { state: () => ({ userList: [], posts: [], communityNodeList: [], curComponent: "CommunityNode", timeList: [], predictionUserIds: [], //包含从用户组选择的用户id或者是点击某个社团或者连边后,所需要高亮的所有用户的id curRelationId: "", curSelecedGroupIds: [], communityDetailNodeRelation: [], //点击一级界面后,查询到的节点间关系 communityDetailNodeList: [], //节点用户列表 predictionLineColor: "#FF3F8F", predictionLegendContent: "社交隐关系", predictionLegendIcon: `image://${new URL("@/assets/images/linkPrediction/icon/socialCharacter-legend-icon.png", import.meta.url)}`, statisticsList: [ { id: 1, icon: nodePrefix, name: "节点数", key: "nodesCount" }, { id: 2, icon: communityPrefix, name: "社团数", key: "groupCount" }, { id: 3, icon: hiddenPrefix, name: "隐关系数", key: "hiddenInteractionCount" } ], anlysisList: [ { id: 1, title: "平均评论数", unit: "数量", xAxis: [0, 20, 40, 60, 80, 100], max: 100, rows: [ { label: "目标用户", value: 90.8, type: "leader" }, { label: "所有用户", value: 0.01, type: "user" } ] }, { id: 2, title: "平均转发次数", unit: "数量", xAxis: [0, 3, 6, 9, 12, 16, 18], max: 18, rows: [ { label: "目标用户", value: 17, type: "leader" }, { label: "所有用户", value: 0.01, type: "user" } ] }, { id: 3, title: "互动时间间隔", unit: "秒", xAxis: [0, 30, 60, 90, 120, 150], max: 150, rows: [ { label: "目标用户", value: 3.63, type: "leader", highlight: false }, { label: "所有用户", value: 127.63, type: "user" } ] } ], wordCloudData: [ { text: "佩洛西", top: 115.5, left: 215.5, width: 109, height: 40, fontSize: 28, opacity: 1 }, { text: "中国", top: 183.5, left: 69.5, width: 73, height: 35, fontSize: 22, opacity: 1 }, { text: "中国人民解放军", top: 72.5, left: 132.5, width: 123, height: 22, fontSize: 12, opacity: 1 }, { text: "中美关系", top: 171.5, left: 212.5, width: 81, height: 22, fontSize: 14, opacity: 0.8 }, { text: "台独", top: 135.5, left: 42.5, width: 57, height: 24, fontSize: 16, opacity: 1 }, { text: "台海和平", top: 228.5, left: 230.5, width: 81, height: 22, fontSize: 14, opacity: 0.8 }, { text: "坚决反对", top: 200.5, left: 38.5, width: 73, height: 19, fontSize: 12, opacity: 0.7 }, { text: "联合公报", top: 241.5, left: 130.5, width: 73, height: 19, fontSize: 12, opacity: 0.7 }, { text: "有力反制", top: 211.5, left: 143.5, width: 73, height: 19, fontSize: 12, opacity: 1 }, { text: "白宫", top: 176.5, left: 15.5, width: 49, height: 19, fontSize: 12, opacity: 0.8 }, { text: "内政", top: 87.5, left: 36.5, width: 53, height: 22, fontSize: 14, opacity: 1 }, { text: "访台", top: 103.5, left: 95.5, width: 49, height: 19, fontSize: 12, opacity: 0.8 }, { text: "领土", top: 57.5, left: 72.5, width: 49, height: 19, fontSize: 12, opacity: 0.6 }, { text: "原则", top: 77.5, left: 264.5, width: 49, height: 19, fontSize: 12, opacity: 0.7 }, { text: "台湾", top: 195.5, left: 287.5, width: 49, height: 19, fontSize: 12, opacity: 0.8 } ], statisticsDetailList: [ { id: 1, icon: nodePrefix, name: "节点数", key: "nodesCount" }, { id: 2, icon: communityPrefix, name: "社团数", key: "groupCount" }, { id: 3, icon: hiddenPrefix, name: "隐关系数", key: "hiddenInteractionCount" } ] }), actions: { async initGroupList() { const res = await getGroupUserListFromSocial() if (res.code != 200) return this.userList = res.data.userList.sort((a, b) => a.rank - b.rank) }, async initCharacterSocialHiddenPostList(relationId) { const res = await getInteractionPostList(relationId) if (res.code != 200) return this.posts = res.data }, async initGraphCommunityNode() { const res = await getCharacterSocialCommunityNodes() if (res.code !== 200) return this.communityNodeList = res.data }, async initGraphStatistics() { const res = await getCharacterSocialCommunityStatistics() this.statisticsList = this.statisticsList.map((item) => ({ ...item, count: res.data[item.key] })) }, async initGraphCommunityDetailNode(ids, time = "2024-05-16 16:56:04", relationId = -1) { this.curSelecedGroupIds = ids const res = await getCharacterSocialCommunityDetailNodes(ids, relationId, time) if (res.code != 200) return const customStatisticsObj = Object.assign({}, res.data.communityStatistics) //计算两个用户是否同属与同一个社团 if ( customStatisticsObj.groupCount == null && customStatisticsObj.hiddenInteractionCount == null ) { customStatisticsObj.hiddenInteractionCount = 1 customStatisticsObj.groupCount = ids[0] === ids[1] ? 1 : 2 } this.statisticsDetailList = this.statisticsDetailList.map((item) => ({ ...item, count: customStatisticsObj[item.key] })) this.communityDetailNodeRelation = res.data.userRelation this.communityDetailNodeList = res.data.userList this.timeList = Array.from(new Set(res.data.timeList)) this.predictionUserIds = res.data.predictNodes } }, persist: true // 开启持久化 })