|
|
|
|
@ -0,0 +1,634 @@
|
|
|
|
|
poetizepoetize-im-uisrcstoreindex.js
|
|
|
|
|
|
|
|
|
|
// 从'vuex'包中导入createStore函数,用于创建一个新的Vuex store实例
|
|
|
|
|
import { createStore } from 'vuex';
|
|
|
|
|
|
|
|
|
|
// 导出通过createStore函数创建的Vuex store实例
|
|
|
|
|
export default createStore({
|
|
|
|
|
// state对象包含了应用的状态
|
|
|
|
|
// 这些状态可以在应用的任何组件中通过this.$store.state访问
|
|
|
|
|
state: {
|
|
|
|
|
// 从localStorage中获取当前用户信息,如果不存在则默认为空对象{}
|
|
|
|
|
// JSON.parse用于将JSON字符串转换为JavaScript对象
|
|
|
|
|
currentUser: JSON.parse(localStorage.getItem("currentUser") || '{}'),
|
|
|
|
|
// 从localStorage中获取系统配置信息,如果不存在则默认为空对象{}
|
|
|
|
|
sysConfig: JSON.parse(localStorage.getItem("sysConfig") || '{}')
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// getters对象可以包含一些方法,这些方法基于state中的状态计算并返回一些值
|
|
|
|
|
// 在这个例子中,getters对象是空的,意味着没有定义任何getter
|
|
|
|
|
getters: {},
|
|
|
|
|
|
|
|
|
|
// mutations对象包含了直接修改状态的方法(同步函数)
|
|
|
|
|
// Vuex要求更改Vuex的store中的状态的唯一方法是提交mutation
|
|
|
|
|
mutations: {
|
|
|
|
|
// loadCurrentUser方法用于加载当前用户信息
|
|
|
|
|
// 它接受两个参数:state(当前Vuex store的状态对象)和user(要设置的用户信息对象)
|
|
|
|
|
// 这个方法会将用户信息保存到state中,并更新localStorage中的currentUser项
|
|
|
|
|
loadCurrentUser(state, user) {
|
|
|
|
|
state.currentUser = user;
|
|
|
|
|
localStorage.setItem("currentUser", JSON.stringify(user));
|
|
|
|
|
},
|
|
|
|
|
// loadSysConfig方法用于加载系统配置信息
|
|
|
|
|
// 它接受两个参数:state(当前Vuex store的状态对象)和sysConfig(要设置的系统配置信息对象)
|
|
|
|
|
// 这个方法会将系统配置信息保存到state中,并更新localStorage中的sysConfig项
|
|
|
|
|
loadSysConfig(state, sysConfig) {
|
|
|
|
|
state.sysConfig = sysConfig;
|
|
|
|
|
localStorage.setItem("sysConfig", JSON.stringify(sysConfig));
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// actions对象包含了可以包含任意异步操作的函数
|
|
|
|
|
// 它们通过提交mutations而不是直接更改状态来更改Vuex store中的状态
|
|
|
|
|
// 在这个例子中,actions对象是空的,意味着没有定义任何action
|
|
|
|
|
actions: {},
|
|
|
|
|
|
|
|
|
|
// modules对象允许将store分割成模块(module),每个模块拥有自己的state、mutation、action、getter
|
|
|
|
|
// 在这个例子中,modules对象是空的,意味着没有定义任何模块
|
|
|
|
|
modules: {},
|
|
|
|
|
|
|
|
|
|
// plugins数组允许你注册Vuex插件,插件可以扩展Vuex的功能
|
|
|
|
|
// 在这个例子中,plugins数组是空的,意味着没有注册任何插件
|
|
|
|
|
plugins: []
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
poetizepoetize-im-uisrcrouterindex.js
|
|
|
|
|
|
|
|
|
|
// 从'vue-router'包中导入createRouter和createWebHistory函数
|
|
|
|
|
// createRouter用于创建一个新的router实例
|
|
|
|
|
// createWebHistory用于创建一个基于HTML5历史记录API的history实例
|
|
|
|
|
import { createRouter, createWebHistory } from 'vue-router';
|
|
|
|
|
|
|
|
|
|
// 从相对路径"../utils/constant"中导入constant模块,该模块可能包含一些常量定义
|
|
|
|
|
import constant from "../utils/constant";
|
|
|
|
|
|
|
|
|
|
// 定义一个路由配置数组,每个对象代表一个路由规则
|
|
|
|
|
const routes = [
|
|
|
|
|
{
|
|
|
|
|
// 路由的路径,当用户访问"/"时,此路由将被匹配
|
|
|
|
|
path: "/",
|
|
|
|
|
|
|
|
|
|
// 路由的meta字段,用于存储一些自定义信息,如权限要求等
|
|
|
|
|
// 在这个例子中,定义了一个requiresAuth: true,表示访问此路由需要用户认证
|
|
|
|
|
meta: { requiresAuth: true },
|
|
|
|
|
|
|
|
|
|
// 路由的组件,这里使用了一个懒加载的组件
|
|
|
|
|
// () => import('../components/index') 是一个异步组件加载的语法,表示当用户访问此路由时,才加载并渲染'index'组件
|
|
|
|
|
component: () => import('../components/index')
|
|
|
|
|
}
|
|
|
|
|
// 注意:这里只定义了一个路由规则,实际项目中可能会有更多
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// 创建一个新的router实例,并传入配置对象
|
|
|
|
|
const router = createRouter({
|
|
|
|
|
// 使用createWebHistory函数创建一个history实例,并传入constant.webHistory作为配置项
|
|
|
|
|
// constant.webHistory可能是一个配置项,用于定义history的行为,如基础路径等
|
|
|
|
|
// 但具体值取决于constant模块的实现,这里无法直接知道
|
|
|
|
|
history: createWebHistory(constant.webHistory),
|
|
|
|
|
|
|
|
|
|
// 传入之前定义的路由规则数组
|
|
|
|
|
routes,
|
|
|
|
|
|
|
|
|
|
// 定义一个scrollBehavior函数,用于控制路由跳转后的滚动行为
|
|
|
|
|
// 当用户从一个路由跳转到另一个路由时,这个函数会被调用
|
|
|
|
|
// to和from是路由对象,分别表示目标路由和来源路由
|
|
|
|
|
// savedPosition是一个对象,如果页面之前被滚动过,这里会包含滚动位置的信息
|
|
|
|
|
// 函数返回一个对象,指定滚动到页面的哪个位置
|
|
|
|
|
// 在这个例子中,总是滚动到页面顶部(left: 0, top: 0)
|
|
|
|
|
scrollBehavior(to, from, savedPosition) {
|
|
|
|
|
return { left: 0, top: 0 };
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 导出router实例,使其可以在Vue应用的创建过程中被使用
|
|
|
|
|
export default router;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
poetizepoetize-im-uisrchooksbindEmail.js
|
|
|
|
|
|
|
|
|
|
// 导入Vuex的useStore钩子,用于访问Vuex store
|
|
|
|
|
import { useStore } from 'vuex';
|
|
|
|
|
|
|
|
|
|
// 导入Naive UI的useDialog钩子,用于显示对话框
|
|
|
|
|
import { useDialog } from 'naive-ui';
|
|
|
|
|
|
|
|
|
|
// 导入Vue的nextTick函数,用于在下次DOM更新循环结束之后执行延迟回调
|
|
|
|
|
import { nextTick } from 'vue';
|
|
|
|
|
|
|
|
|
|
// 导入Element Plus的ElMessage组件,用于显示消息提示
|
|
|
|
|
import { ElMessage } from "element-plus";
|
|
|
|
|
|
|
|
|
|
// 导入Vue的reactive、getCurrentInstance、onMounted、onBeforeUnmount、watchEffect、toRefs函数
|
|
|
|
|
import { reactive, getCurrentInstance, onMounted, onBeforeUnmount, watchEffect, toRefs } from 'vue';
|
|
|
|
|
|
|
|
|
|
// 定义一个函数,该函数返回一个对象,该对象包含响应式数据和方法
|
|
|
|
|
export default function () {
|
|
|
|
|
// 获取当前Vue实例的上下文,并从中提取全局属性
|
|
|
|
|
const globalProperties = getCurrentInstance().appContext.config.globalProperties;
|
|
|
|
|
const $common = globalProperties.$common; // 自定义的常用方法集合
|
|
|
|
|
const $http = globalProperties.$http; // 自定义的HTTP请求方法
|
|
|
|
|
const $constant = globalProperties.$constant; // 自定义的常量集合
|
|
|
|
|
|
|
|
|
|
// 使用Vuex的useStore钩子获取store实例
|
|
|
|
|
const store = useStore();
|
|
|
|
|
|
|
|
|
|
// 使用Naive UI的useDialog钩子获取对话框实例
|
|
|
|
|
const dialog = useDialog();
|
|
|
|
|
|
|
|
|
|
// 定义响应式数据对象,用于绑定邮箱相关的数据
|
|
|
|
|
let bindEmailData = reactive({
|
|
|
|
|
emailVisible: false, // 邮箱对话框的显示状态
|
|
|
|
|
email: '', // 邮箱地址
|
|
|
|
|
code: '', // 验证码
|
|
|
|
|
password: '', // 密码
|
|
|
|
|
codeString: "验证码" // 倒计时显示的字符串,初始为"验证码"
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 定义一个变量,用于存储验证码倒计时的setInterval返回值
|
|
|
|
|
let intervalCode = null;
|
|
|
|
|
|
|
|
|
|
// 在组件挂载时执行的方法
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
showEmail(); // 调用showEmail方法检查是否需要显示邮箱绑定对话框
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 显示邮箱绑定对话框的逻辑(但当前代码未直接设置对话框可见性)
|
|
|
|
|
function showEmail() {
|
|
|
|
|
// 检查当前用户是否存在且未绑定邮箱,则可能需要显示对话框(但当前逻辑未实现)
|
|
|
|
|
if (!$common.isEmpty(store.state.currentUser) && $common.isEmpty(store.state.currentUser.email)) {
|
|
|
|
|
// 逻辑未实现,仅注释说明需要显示对话框
|
|
|
|
|
// bindEmailData.emailVisible = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取验证码的逻辑
|
|
|
|
|
function getCode() {
|
|
|
|
|
// 检查验证码倒计时是否正在进行,如果正在进行则提示稍后再试
|
|
|
|
|
if (bindEmailData.codeString === "验证码") {
|
|
|
|
|
// 校验邮箱格式并发送验证码请求
|
|
|
|
|
// ...(省略了具体的校验和请求逻辑)
|
|
|
|
|
|
|
|
|
|
// 设置验证码倒计时
|
|
|
|
|
bindEmailData.codeString = "30";
|
|
|
|
|
intervalCode = setInterval(() => {
|
|
|
|
|
// 每秒更新一次倒计时,直到倒计时结束
|
|
|
|
|
// ...(省略了具体的倒计时逻辑)
|
|
|
|
|
}, 1000);
|
|
|
|
|
} else {
|
|
|
|
|
// 提示稍后再试
|
|
|
|
|
ElMessage({
|
|
|
|
|
message: "请稍后再试!",
|
|
|
|
|
type: 'error'
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 提交邮箱绑定对话框的逻辑
|
|
|
|
|
function submitDialog() {
|
|
|
|
|
// 校验邮箱、验证码和密码(省略了具体的校验逻辑)
|
|
|
|
|
// ...
|
|
|
|
|
|
|
|
|
|
// 发送绑定邮箱的请求
|
|
|
|
|
// ...(省略了具体的请求逻辑)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 清除邮箱绑定对话框的数据和状态
|
|
|
|
|
function clearEmailDialog() {
|
|
|
|
|
// 重置对话框数据和状态
|
|
|
|
|
// ...(省略了具体的重置逻辑)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 返回响应式数据和方法,以便在组件中使用
|
|
|
|
|
return {
|
|
|
|
|
bindEmailData,
|
|
|
|
|
getCode,
|
|
|
|
|
submitDialog
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
poetizepoetize-im-uisrchookschangeData.js
|
|
|
|
|
|
|
|
|
|
// 导入所需的Vue Composition API函数、Vuex store、Naive UI对话框组件和Element Plus消息组件
|
|
|
|
|
import { useStore } from 'vuex';
|
|
|
|
|
import { useDialog } from 'naive-ui';
|
|
|
|
|
import { nextTick } from 'vue'; // 导入nextTick但未在代码中使用
|
|
|
|
|
import { ElMessage } from "element-plus";
|
|
|
|
|
import {
|
|
|
|
|
reactive,
|
|
|
|
|
getCurrentInstance,
|
|
|
|
|
onMounted,
|
|
|
|
|
onBeforeUnmount,
|
|
|
|
|
watchEffect,
|
|
|
|
|
toRefs
|
|
|
|
|
} from 'vue';
|
|
|
|
|
|
|
|
|
|
// 定义一个函数,接收friendData和groupData作为参数
|
|
|
|
|
export default function (friendData, groupData) {
|
|
|
|
|
// 获取Vue实例的全局属性
|
|
|
|
|
const globalProperties = getCurrentInstance().appContext.config.globalProperties;
|
|
|
|
|
const $common = globalProperties.$common; // 通用方法
|
|
|
|
|
const $http = globalProperties.$http; // HTTP请求方法
|
|
|
|
|
const $constant = globalProperties.$constant; // 常量配置
|
|
|
|
|
const store = useStore(); // 获取Vuex store实例
|
|
|
|
|
const dialog = useDialog(); // 获取Naive UI对话框实例
|
|
|
|
|
|
|
|
|
|
// 使用reactive创建一个响应式对象,用于存储修改信息
|
|
|
|
|
let changeDataData = reactive({
|
|
|
|
|
changeData: '', // 修改后的数据
|
|
|
|
|
changeType: null, // 修改类型
|
|
|
|
|
changeModal: false, // 修改信息模态框显示状态
|
|
|
|
|
avatarType: null, // 头像类型(用户或群组)
|
|
|
|
|
avatarPrefix: '', // 头像URL前缀
|
|
|
|
|
showAvatarDialog: false // 显示头像修改对话框
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 关闭模态框的函数,重置相关状态
|
|
|
|
|
function closeModal() {
|
|
|
|
|
changeDataData.avatarType = null;
|
|
|
|
|
changeDataData.avatarPrefix = '';
|
|
|
|
|
changeDataData.changeData = '';
|
|
|
|
|
changeDataData.changeType = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 显示头像修改对话框的函数,根据类型设置前缀
|
|
|
|
|
function changeAvatar(type) {
|
|
|
|
|
// 判断是否有权限修改头像
|
|
|
|
|
if (type === 1 || (type === 2 && groupData.groups[groupData.currentGroupId].masterFlag)) {
|
|
|
|
|
closeModal(); // 关闭其他模态框
|
|
|
|
|
changeDataData.showAvatarDialog = true; // 显示头像修改对话框
|
|
|
|
|
changeDataData.avatarType = type; // 设置头像类型
|
|
|
|
|
if (type === 1) {
|
|
|
|
|
changeDataData.avatarPrefix = 'userAvatar'; // 用户头像前缀
|
|
|
|
|
} else if (type === 2) {
|
|
|
|
|
changeDataData.avatarPrefix = 'im/groupAvatar'; // 群组头像前缀
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 改变数据类型(修改备注、群名等)的函数
|
|
|
|
|
function changeDataType(type) {
|
|
|
|
|
closeModal(); // 关闭其他模态框
|
|
|
|
|
changeDataData.changeType = type; // 设置修改类型
|
|
|
|
|
changeDataData.changeModal = true; // 显示修改信息模态框
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 提交头像修改的函数
|
|
|
|
|
function submitAvatar(avatar) {
|
|
|
|
|
if ($common.isEmpty(avatar)) {
|
|
|
|
|
ElMessage({ message: "请上传头像!", type: 'warning' }); // 提示上传头像
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// 根据头像类型执行相应的修改操作
|
|
|
|
|
if (changeDataData.avatarType === 1) {
|
|
|
|
|
// 用户头像修改逻辑
|
|
|
|
|
} else if (changeDataData.avatarType === 2) {
|
|
|
|
|
// 群组头像修改逻辑
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 提交修改的函数(备注、群名、公告、简介)
|
|
|
|
|
function submitChange() {
|
|
|
|
|
// 根据修改类型执行相应的修改操作
|
|
|
|
|
if (changeDataData.changeType === 1) {
|
|
|
|
|
// 修改备注逻辑
|
|
|
|
|
} else if (changeDataData.changeType === 2) {
|
|
|
|
|
// 修改群名逻辑
|
|
|
|
|
} else if (changeDataData.changeType === 3) {
|
|
|
|
|
// 修改公告逻辑
|
|
|
|
|
} else if (changeDataData.changeType === 4) {
|
|
|
|
|
// 修改简介逻辑
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 返回对象,包含状态和方法供外部使用
|
|
|
|
|
return {
|
|
|
|
|
changeDataData,
|
|
|
|
|
changeAvatar,
|
|
|
|
|
changeDataType,
|
|
|
|
|
submitAvatar,
|
|
|
|
|
submitChange
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
poetizepoetize-im-uisrchooksfriend.js
|
|
|
|
|
|
|
|
|
|
// 引入Vuex的useStore钩子,用于访问Vuex store
|
|
|
|
|
import {useStore} from 'vuex';
|
|
|
|
|
|
|
|
|
|
// 引入Naive UI的useDialog钩子,用于显示对话框
|
|
|
|
|
import {useDialog} from 'naive-ui';
|
|
|
|
|
|
|
|
|
|
// 引入Vue的nextTick函数,用于在下次DOM更新循环结束之后执行延迟回调
|
|
|
|
|
import {nextTick} from 'vue';
|
|
|
|
|
|
|
|
|
|
// 引入Element Plus的ElMessage组件,用于显示消息提示
|
|
|
|
|
import {ElMessage} from "element-plus";
|
|
|
|
|
|
|
|
|
|
// 引入Vue的reactive、getCurrentInstance、onMounted、onBeforeUnmount、watchEffect、toRefs函数
|
|
|
|
|
import {reactive, getCurrentInstance, onMounted, onBeforeUnmount, watchEffect, toRefs} from 'vue';
|
|
|
|
|
|
|
|
|
|
export default function () {
|
|
|
|
|
// 获取当前Vue实例的上下文,并从中获取全局属性
|
|
|
|
|
const globalProperties = getCurrentInstance().appContext.config.globalProperties;
|
|
|
|
|
const $common = globalProperties.$common; // 通用方法或属性
|
|
|
|
|
const $http = globalProperties.$http; // HTTP请求方法
|
|
|
|
|
const $constant = globalProperties.$constant; // 常量配置
|
|
|
|
|
|
|
|
|
|
// 使用Vuex的useStore钩子获取store实例
|
|
|
|
|
const store = useStore();
|
|
|
|
|
|
|
|
|
|
// 使用Naive UI的useDialog钩子获取对话框实例
|
|
|
|
|
const dialog = useDialog();
|
|
|
|
|
|
|
|
|
|
// 使用reactive创建一个响应式对象,用于存储好友数据
|
|
|
|
|
let friendData = reactive({
|
|
|
|
|
// 好友请求列表
|
|
|
|
|
friendRequests: [],
|
|
|
|
|
// 好友列表,使用friendId作为键
|
|
|
|
|
friends: {},
|
|
|
|
|
// 当前操作的好友ID
|
|
|
|
|
currentFriendId: null
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 异步函数,用于获取当前用户的好友列表
|
|
|
|
|
async function getImFriend() {
|
|
|
|
|
try {
|
|
|
|
|
const res = await $http.get($constant.baseURL + "/imChatUserFriend/getFriend", {friendStatus: 1});
|
|
|
|
|
if (!$common.isEmpty(res.data)) {
|
|
|
|
|
res.data.forEach(friend => {
|
|
|
|
|
friendData.friends[friend.friendId] = friend;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
ElMessage({
|
|
|
|
|
message: error.message,
|
|
|
|
|
type: 'error'
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 删除好友的函数
|
|
|
|
|
function removeFriend(currentFriendId) {
|
|
|
|
|
dialog.error({
|
|
|
|
|
title: '警告',
|
|
|
|
|
content: `你确定删除${friendData.friends[currentFriendId].remark}?`,
|
|
|
|
|
positiveText: '确定',
|
|
|
|
|
onPositiveClick: async () => {
|
|
|
|
|
try {
|
|
|
|
|
const res = await $http.get($constant.baseURL + "/imChatUserFriend/changeFriend", {
|
|
|
|
|
friendId: currentFriendId,
|
|
|
|
|
friendStatus: -1
|
|
|
|
|
});
|
|
|
|
|
delete friendData.friends[currentFriendId];
|
|
|
|
|
friendData.currentFriendId = null;
|
|
|
|
|
ElMessage({
|
|
|
|
|
message: "删除成功!",
|
|
|
|
|
type: 'success'
|
|
|
|
|
});
|
|
|
|
|
} catch (error) {
|
|
|
|
|
ElMessage({
|
|
|
|
|
message: error.message,
|
|
|
|
|
type: 'error'
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取好友请求的函数
|
|
|
|
|
function getFriendRequests() {
|
|
|
|
|
$http.get($constant.baseURL + "/imChatUserFriend/getFriend", {friendStatus: 0})
|
|
|
|
|
.then((res) => {
|
|
|
|
|
if (!$common.isEmpty(res.data)) {
|
|
|
|
|
friendData.friendRequests = res.data;
|
|
|
|
|
ElMessage({
|
|
|
|
|
message: "您有好友申请待处理!",
|
|
|
|
|
showClose: true,
|
|
|
|
|
type: 'success',
|
|
|
|
|
duration: 0
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
ElMessage({
|
|
|
|
|
message: error.message,
|
|
|
|
|
type: 'error'
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 修改好友请求状态的函数
|
|
|
|
|
function changeFriendStatus(friendId, status, index) {
|
|
|
|
|
$http.get($constant.baseURL + "/imChatUserFriend/changeFriend", {friendId: friendId, friendStatus: status})
|
|
|
|
|
.then((res) => {
|
|
|
|
|
friendData.friendRequests.splice(index, 1);
|
|
|
|
|
ElMessage({
|
|
|
|
|
message: "修改成功!",
|
|
|
|
|
type: 'success'
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
ElMessage({
|
|
|
|
|
message: error.message,
|
|
|
|
|
type: 'error'
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 返回对象,包含响应式数据和函数,供外部使用
|
|
|
|
|
return {
|
|
|
|
|
friendData,
|
|
|
|
|
getImFriend,
|
|
|
|
|
removeFriend,
|
|
|
|
|
getFriendRequests,
|
|
|
|
|
changeFriendStatus
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
poetizepoetize-im-uisrchooksfriendCircle.js
|
|
|
|
|
|
|
|
|
|
import {useStore} from 'vuex'; // 引入Vuex的useStore函数,用于访问Vuex store
|
|
|
|
|
import {useDialog} from 'naive-ui'; // 引入Naive UI的useDialog函数,用于弹出对话框
|
|
|
|
|
import {nextTick} from 'vue'; // 引入Vue的nextTick函数,用于在下次DOM更新循环结束之后执行延迟回调
|
|
|
|
|
import {ElMessage} from "element-plus"; // 引入Element Plus的ElMessage组件,用于显示消息提示
|
|
|
|
|
import {reactive, getCurrentInstance, onMounted, onBeforeUnmount, watchEffect, toRefs} from 'vue'; // 引入Vue的响应式API和其他生命周期钩子
|
|
|
|
|
|
|
|
|
|
export default function () {
|
|
|
|
|
// 获取Vue实例的全局属性
|
|
|
|
|
const globalProperties = getCurrentInstance().appContext.config.globalProperties;
|
|
|
|
|
const $common = globalProperties.$common; // 获取全局的common工具集
|
|
|
|
|
const $http = globalProperties.$http; // 获取全局的http请求方法
|
|
|
|
|
const $constant = globalProperties.$constant; // 获取全局的常量配置
|
|
|
|
|
const store = useStore(); // 使用Vuex store
|
|
|
|
|
const dialog = useDialog(); // 使用Naive UI的对话框
|
|
|
|
|
|
|
|
|
|
// 定义响应式数据
|
|
|
|
|
let friendCircleData = reactive({
|
|
|
|
|
showFriendCircle: false, // 是否显示朋友圈
|
|
|
|
|
treeHoleList: [], // 朋友圈列表数据
|
|
|
|
|
weiYanDialogVisible: false, // 是否显示发表朋友圈对话框
|
|
|
|
|
isPublic: true, // 发表的朋友圈是否公开
|
|
|
|
|
weiYanAvatar: '', // 发表朋友圈的用户头像
|
|
|
|
|
weiYanUsername: '', // 发表朋友圈的用户名
|
|
|
|
|
pagination: { // 分页配置
|
|
|
|
|
current: 1,
|
|
|
|
|
size: 10,
|
|
|
|
|
total: 0,
|
|
|
|
|
userId: null
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 显示发表朋友圈对话框
|
|
|
|
|
function launch() {
|
|
|
|
|
friendCircleData.weiYanDialogVisible = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 打开指定用户的朋友圈
|
|
|
|
|
function openFriendCircle(userId, avatar, username) {
|
|
|
|
|
friendCircleData.pagination.userId = userId; // 设置当前用户ID
|
|
|
|
|
friendCircleData.weiYanAvatar = avatar; // 设置用户头像
|
|
|
|
|
friendCircleData.weiYanUsername = username; // 设置用户名
|
|
|
|
|
getWeiYan(); // 获取朋友圈数据
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 删除朋友圈动态
|
|
|
|
|
function deleteTreeHole(id) {
|
|
|
|
|
dialog.error({ // 弹出确认删除对话框
|
|
|
|
|
title: '警告',
|
|
|
|
|
content: '确定删除?',
|
|
|
|
|
positiveText: '确定',
|
|
|
|
|
onPositiveClick: () => {
|
|
|
|
|
$http.get($constant.baseURL + "/weiYan/deleteWeiYan", {id: id}) // 发送删除请求
|
|
|
|
|
.then((res) => {
|
|
|
|
|
ElMessage({ // 提示删除成功
|
|
|
|
|
message: "删除成功!",
|
|
|
|
|
type: 'success'
|
|
|
|
|
});
|
|
|
|
|
resetPaginationAndList(); // 重置分页和列表数据
|
|
|
|
|
getWeiYan(); // 重新获取朋友圈数据
|
|
|
|
|
})
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
ElMessage({ // 提示错误信息
|
|
|
|
|
message: error.message,
|
|
|
|
|
type: 'error'
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取朋友圈数据
|
|
|
|
|
function getWeiYan() {
|
|
|
|
|
$http.post($constant.baseURL + "/weiYan/listWeiYan", friendCircleData.pagination)
|
|
|
|
|
.then((res) => {
|
|
|
|
|
if (!$common.isEmpty(res.data)) { // 如果返回的数据不为空
|
|
|
|
|
processRecords(res.data.records); // 处理朋友圈记录
|
|
|
|
|
friendCircleData.treeHoleList = friendCircleData.treeHoleList.concat(res.data.records); // 合并到列表
|
|
|
|
|
friendCircleData.pagination.total = res.data.total; // 更新总记录数
|
|
|
|
|
friendCircleData.showFriendCircle = true; // 显示朋友圈
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
ElMessage({ // 提示错误信息
|
|
|
|
|
message: error.message,
|
|
|
|
|
type: 'error'
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 提交发表朋友圈
|
|
|
|
|
function submitWeiYan(content) {
|
|
|
|
|
let weiYan = {
|
|
|
|
|
content: content,
|
|
|
|
|
isPublic: friendCircleData.isPublic
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$http.post($constant.baseURL + "/weiYan/saveWeiYan", weiYan)
|
|
|
|
|
.then((res) => {
|
|
|
|
|
resetPaginationAndList(); // 重置分页和列表数据
|
|
|
|
|
friendCircleData.weiYanDialogVisible = false; // 关闭发表对话框
|
|
|
|
|
getWeiYan(); // 重新获取朋友圈数据
|
|
|
|
|
})
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
ElMessage({ // 提示错误信息
|
|
|
|
|
message: error.message,
|
|
|
|
|
type: 'error'
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 重置分页和列表数据
|
|
|
|
|
function resetPaginationAndList() {
|
|
|
|
|
friendCircleData.pagination = {
|
|
|
|
|
current: 1,
|
|
|
|
|
size: 10,
|
|
|
|
|
total: 0,
|
|
|
|
|
userId: null
|
|
|
|
|
};
|
|
|
|
|
friendCircleData.treeHoleList = [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 清理朋友圈数据
|
|
|
|
|
function cleanFriendCircle() {
|
|
|
|
|
resetPaginationAndList(); // 重置分页和列表数据
|
|
|
|
|
friendCircleData.weiYanAvatar = ''; // 清空头像
|
|
|
|
|
friendCircleData.weiYanUsername = ''; // 清空用户名
|
|
|
|
|
friendCircleData.showFriendCircle = false; // 隐藏朋友圈
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 下一页朋友圈数据
|
|
|
|
|
function pageWeiYan() {
|
|
|
|
|
friendCircleData.pagination.current = friendCircleData.pagination.current + 1; // 更新当前页码
|
|
|
|
|
getWeiYan(); // 重新获取朋友圈数据
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 添加好友
|
|
|
|
|
function addFriend() {
|
|
|
|
|
dialog.success({ // 弹出确认添加好友对话框
|
|
|
|
|
title: '好友申请',
|
|
|
|
|
content: '确认提交好友申请,添加 ' + friendCircleData.weiYanUsername + ' 为好友?',
|
|
|
|
|
positiveText: '确定',
|
|
|
|
|
onPositiveClick: () => {
|
|
|
|
|
$http.get($constant.baseURL + "/imChatUserFriend/addFriend", {friendId: friendCircleData.pagination.userId})
|
|
|
|
|
.then((res) => {
|
|
|
|
|
ElMessage({ // 提示提交成功
|
|
|
|
|
message: "提交成功!",
|
|
|
|
|
type: 'success'
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
ElMessage({ // 提示错误信息
|
|
|
|
|
message: error.message,
|
|
|
|
|
type: 'error'
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 处理朋友圈记录,包括替换换行符和表情符号等
|
|
|
|
|
function processRecords(records) {
|
|
|
|
|
records.forEach(c => {
|
|
|
|
|
c.content = c.content.replace(/\n{2,}/g, '<div style="height: 12px"></div>'); // 替换连续换行符
|
|
|
|
|
c.content = c.content.replace(/\n/g, '<br/>'); // 替换单个换行符
|
|
|
|
|
c.content = $common.faceReg(c.content); // 替换表情符号
|
|
|
|
|
c.content = $common.pictureReg(c.content); // 替换图片链接
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 返回对外暴露的方法和数据
|
|
|
|
|
return {
|
|
|
|
|
friendCircleData,
|
|
|
|
|
launch,
|
|
|
|
|
openFriendCircle,
|
|
|
|
|
deleteTreeHole,
|
|
|
|
|
submitWeiYan,
|
|
|
|
|
pageWeiYan,
|
|
|
|
|
cleanFriendCircle,
|
|
|
|
|
addFriend
|
|
|
|
|
};
|
|
|
|
|
}
|