Browse Source

代码整理优化

master
xie.bx 3 years ago
parent
commit
db40f25433
  1. 31
      commom/pom.xml
  2. 16
      im-platform/pom.xml
  3. 2
      im-platform/src/main/java/com/lx/implatform/ImplatformApp.java
  4. 39
      im-platform/src/main/java/com/lx/implatform/config/GlobalCorsConfig.java
  5. 1
      im-platform/src/main/java/com/lx/implatform/config/WebSecurityConfg.java
  6. 2
      im-platform/src/main/java/com/lx/implatform/service/impl/FriendServiceImpl.java
  7. 3
      im-platform/src/main/java/com/lx/implatform/service/impl/GroupServiceImpl.java
  8. 2
      im-platform/src/main/java/com/lx/implatform/service/impl/SecurityUserDetailsServiceImpl.java
  9. 15
      im-platform/src/main/java/com/lx/implatform/task/PullAlreadyReadMessageTask.java
  10. 4
      im-platform/src/main/resources/application.yml
  11. 14
      im-platform/src/main/resources/db/db.sql
  12. 16
      im-server/pom.xml
  13. 2
      im-server/src/main/java/com/lx/implatform/imserver/IMServerApp.java
  14. 18
      im-server/src/main/java/com/lx/implatform/imserver/task/AbstractPullMessageTask.java
  15. 1
      im-server/src/main/java/com/lx/implatform/imserver/task/PullUnreadGroupMessageTask.java
  16. 1
      im-ui/src/api/httpRequest.js
  17. 20
      im-ui/src/components/chat/ChatGroup.vue
  18. 7
      im-ui/src/components/chat/ChatGroupSide.vue
  19. 16
      im-ui/src/components/chat/ChatPrivate.vue
  20. 2
      im-ui/src/components/common/HeadImage.vue
  21. 2
      im-ui/src/components/common/UserInfo.vue
  22. 4
      im-ui/src/components/friend/AddFriend.vue
  23. 2
      im-ui/src/components/group/AddGroupMember.vue
  24. 17
      im-ui/src/components/setting/Setting.vue
  25. 4
      im-ui/src/store/friendStore.js
  26. 2
      im-ui/src/store/groupStore.js
  27. 2
      im-ui/src/store/userStore.js
  28. 6
      im-ui/src/view/Chat.vue
  29. 6
      im-ui/src/view/Friend.vue
  30. 17
      im-ui/src/view/Group.vue
  31. 14
      im-ui/src/view/Home.vue
  32. 2
      im-ui/src/view/Login.vue
  33. 2
      im-ui/src/view/Register.vue
  34. 24
      pom.xml

31
commom/pom.xml

@ -17,28 +17,33 @@
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>com.baomidou</groupId> <groupId>org.projectlombok</groupId>
<artifactId>mybatis-plus-generator</artifactId> <artifactId>lombok</artifactId>
<version>3.3.2</version> <version>${lombok.version}</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>cn.hutool</groupId> <groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId> <artifactId>hutool-all</artifactId>
</dependency> </dependency>
<!--FastJson-->
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>com.alibaba</groupId>
<artifactId>lombok</artifactId> <artifactId>fastjson</artifactId>
<version>1.18.16</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.commons</groupId> <groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId> <artifactId>commons-lang3</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-generator</artifactId>
<version>3.3.2</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>compile</scope>
</dependency>
<dependency> <dependency>
<groupId>org.springframework</groupId> <groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId> <artifactId>spring-beans</artifactId>
@ -53,9 +58,5 @@
<artifactId>velocity</artifactId> <artifactId>velocity</artifactId>
<version>${velocity.version}</version> <version>${velocity.version}</version>
</dependency> </dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
</dependencies> </dependencies>
</project> </project>

16
im-platform/pom.xml

@ -104,14 +104,18 @@
</dependencies> </dependencies>
<build> <build>
<finalName>${project.artifactId}</finalName>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>spring-boot-maven-plugin</artifactId>
<configuration> <executions>
<source>8</source> <execution>
<target>8</target> <goals>
</configuration> <goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin> </plugin>
</plugins> </plugins>
</build> </build>

2
im-platform/src/main/java/com/lx/implatform/ImplatformApp.java

@ -16,6 +16,6 @@ import org.springframework.context.annotation.EnableAspectJAutoProxy;
public class ImplatformApp { public class ImplatformApp {
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(ImplatformApp.class); SpringApplication.run(ImplatformApp.class,args);
} }
} }

39
im-platform/src/main/java/com/lx/implatform/config/GlobalCorsConfig.java

@ -0,0 +1,39 @@
package com.lx.implatform.config;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
import java.util.Arrays;
@Configuration
public class GlobalCorsConfig {
@Bean
public FilterRegistrationBean<CorsFilter> corsFilter() {
FilterRegistrationBean<CorsFilter> corsFilterFilterRegistrationBean = new FilterRegistrationBean<>();
//添加CORS配置信息
CorsConfiguration corsConfiguration = new CorsConfiguration();
//允许的域,不要写*,否则cookie就无法使用了
corsConfiguration.addAllowedOrigin("*");
//允许的头信息
corsConfiguration.addAllowedHeader("*");
//允许的请求方式
corsConfiguration.setAllowedMethods(Arrays.asList("POST", "PUT", "GET", "OPTIONS", "DELETE"));
//是否发送cookie信息
corsConfiguration.setAllowCredentials(true);
//预检请求的有效期,单位为秒
corsConfiguration.setMaxAge(3600L);
//添加映射路径,标识待拦截的请求
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", corsConfiguration);
corsFilterFilterRegistrationBean.setFilter(new CorsFilter(source));
corsFilterFilterRegistrationBean.setOrder(Ordered.HIGHEST_PRECEDENCE);
return corsFilterFilterRegistrationBean;
}
}

1
im-platform/src/main/java/com/lx/implatform/config/WebSecurityConfg.java

@ -149,6 +149,7 @@ public class WebSecurityConfg extends WebSecurityConfigurerAdapter {
AuthenticationEntryPoint entryPoint(){ AuthenticationEntryPoint entryPoint(){
return (request, response, exception) -> { return (request, response, exception) -> {
response.setContentType("application/json;charset=utf-8"); response.setContentType("application/json;charset=utf-8");
log.info(request.getRequestURI());
PrintWriter out = response.getWriter(); PrintWriter out = response.getWriter();
Result result = ResultUtils.error(ResultCode.NO_LOGIN); Result result = ResultUtils.error(ResultCode.NO_LOGIN);
out.write(new ObjectMapper().writeValueAsString(result)); out.write(new ObjectMapper().writeValueAsString(result));

2
im-platform/src/main/java/com/lx/implatform/service/impl/FriendServiceImpl.java

@ -40,7 +40,7 @@ public class FriendServiceImpl extends ServiceImpl<FriendMapper, Friend> impleme
@Override @Override
public List<Friend> findFriendByUserId(Long UserId) { public List<Friend> findFriendByUserId(Long UserId) {
QueryWrapper<Friend> queryWrapper = new QueryWrapper<>(); QueryWrapper<Friend> queryWrapper = new QueryWrapper();
queryWrapper.lambda().eq(Friend::getUserId,UserId); queryWrapper.lambda().eq(Friend::getUserId,UserId);
List<Friend> friends = this.list(queryWrapper); List<Friend> friends = this.list(queryWrapper);
return friends; return friends;

3
im-platform/src/main/java/com/lx/implatform/service/impl/GroupServiceImpl.java

@ -71,9 +71,12 @@ public class GroupServiceImpl extends ServiceImpl<GroupMapper, Group> implements
groupMember.setGroupId(group.getId()); groupMember.setGroupId(group.getId());
groupMember.setUserId(user.getId()); groupMember.setUserId(user.getId());
groupMember.setAliasName(user.getNickName()); groupMember.setAliasName(user.getNickName());
groupMember.setRemark(groupName);
groupMember.setHeadImage(user.getHeadImageThumb()); groupMember.setHeadImage(user.getHeadImageThumb());
groupMemberService.save(groupMember); groupMemberService.save(groupMember);
GroupVO vo = BeanUtils.copyProperties(group, GroupVO.class); GroupVO vo = BeanUtils.copyProperties(group, GroupVO.class);
vo.setAliasName(user.getNickName());
vo.setRemark(groupName);
return vo; return vo;
} }

2
im-platform/src/main/java/com/lx/implatform/service/impl/SecurityUserDetailsServiceImpl.java

@ -31,7 +31,7 @@ public class SecurityUserDetailsServiceImpl implements UserDetailsService {
throw new UsernameNotFoundException("用户不存在"); throw new UsernameNotFoundException("用户不存在");
} }
//定义权限列表. //定义权限列表.
List<GrantedAuthority> authorities = new ArrayList<>(); List<GrantedAuthority> authorities = new ArrayList();
// 用户可以访问的资源名称(或者说用户所拥有的权限) 注意:必须"ROLE_"开头 // 用户可以访问的资源名称(或者说用户所拥有的权限) 注意:必须"ROLE_"开头
authorities.add(new SimpleGrantedAuthority("ROLE_XX")); authorities.add(new SimpleGrantedAuthority("ROLE_XX"));

15
im-platform/src/main/java/com/lx/implatform/task/PullAlreadyReadMessageTask.java

@ -5,12 +5,14 @@ import com.lx.common.contant.RedisKey;
import com.lx.common.enums.MessageStatusEnum; import com.lx.common.enums.MessageStatusEnum;
import com.lx.implatform.entity.PrivateMessage; import com.lx.implatform.entity.PrivateMessage;
import com.lx.implatform.service.IPrivateMessageService; import com.lx.implatform.service.IPrivateMessageService;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -32,16 +34,24 @@ public class PullAlreadyReadMessageTask {
@PostConstruct @PostConstruct
public void init(){ public void init(){
for(int i=0;i<threadNum;i++){ for(int i=0;i<threadNum;i++){
executorService.submit(new Task()); executorService.execute(new Task());
} }
} }
@PreDestroy
public void destroy(){
log.info("{}线程任务关闭",this.getClass().getSimpleName());
executorService.shutdown();
}
protected class Task implements Runnable{ protected class Task implements Runnable{
@SneakyThrows
@Override @Override
public void run() { public void run() {
try { try {
String key = RedisKey.IM_READED_PRIVATE_MESSAGE_ID; String key = RedisKey.IM_READED_PRIVATE_MESSAGE_ID;
Integer msgId = (Integer)redisTemplate.opsForList().leftPop(key,1, TimeUnit.SECONDS); Integer msgId = (Integer)redisTemplate.opsForList().leftPop(key,10, TimeUnit.SECONDS);
if(msgId!=null){ if(msgId!=null){
UpdateWrapper<PrivateMessage> updateWrapper = new UpdateWrapper<>(); UpdateWrapper<PrivateMessage> updateWrapper = new UpdateWrapper<>();
updateWrapper.lambda().eq(PrivateMessage::getId,msgId) updateWrapper.lambda().eq(PrivateMessage::getId,msgId)
@ -51,6 +61,7 @@ public class PullAlreadyReadMessageTask {
} }
}catch (Exception e){ }catch (Exception e){
log.error(e.getMessage()); log.error(e.getMessage());
Thread.sleep(200);
}finally { }finally {
// 下一次循环 // 下一次循环
executorService.submit(this); executorService.submit(this);

4
im-platform/src/main/resources/application.yml

@ -29,8 +29,8 @@ mybatis-plus:
# *.xml的具体路径 # *.xml的具体路径
- classpath*:mapper/*.xml - classpath*:mapper/*.xml
minio: minio:
endpoint: http://127.0.0.1:9001 endpoint: http://127.0.0.1:9001 #内网地址
public: http://127.0.0.1:9001 public: http://3xagfu.natappfree.cc/file #外网访问地址
accessKey: admin accessKey: admin
secretKey: 12345678 secretKey: 12345678
bucketName: lx-im bucketName: lx-im

14
im-platform/src/main/resources/db/db.sql

@ -1,4 +1,4 @@
use `lx-im`; use `box-im`;
create table `im_user`( create table `im_user`(
`id` bigint not null auto_increment primary key comment 'id', `id` bigint not null auto_increment primary key comment 'id',
`user_name` varchar(255) not null comment '用户名', `user_name` varchar(255) not null comment '用户名',
@ -33,7 +33,7 @@ create table `im_private_message`(
`type` tinyint(1) NOT NULL comment '消息类型 0:文字 1:图片 2:文件', `type` tinyint(1) NOT NULL comment '消息类型 0:文字 1:图片 2:文件',
`status` tinyint(1) NOT NULL comment '状态 0:未读 1:已读 ', `status` tinyint(1) NOT NULL comment '状态 0:未读 1:已读 ',
`send_time` datetime DEFAULT CURRENT_TIMESTAMP comment '发送时间', `send_time` datetime DEFAULT CURRENT_TIMESTAMP comment '发送时间',
key `idx_send_recv_user_id` (`send_user_id`,`recv_user_id`) key `idx_send_recv_id` (`send_id`,`recv_id`)
)ENGINE=InnoDB CHARSET=utf8mb3 comment '私聊消息'; )ENGINE=InnoDB CHARSET=utf8mb3 comment '私聊消息';
@ -71,13 +71,3 @@ create table `im_group_message`(
`send_time` datetime DEFAULT CURRENT_TIMESTAMP comment '发送时间', `send_time` datetime DEFAULT CURRENT_TIMESTAMP comment '发送时间',
key `idx_group_id` (group_id) key `idx_group_id` (group_id)
)ENGINE=InnoDB CHARSET=utf8mb3 comment '群消息'; )ENGINE=InnoDB CHARSET=utf8mb3 comment '群消息';
create table `im_group_message_read_pos`(
`id` bigint not null auto_increment primary key comment 'id',
`group_id` bigint not null comment '群id',
`user_id` bigint not null comment '用户id',
`read_pos` bigint default 0 comment '已读取消息的最大消息id',
`last_read_time` datetime DEFAULT CURRENT_TIMESTAMP comment '最后读取时间',
key `idx_user_id`(`user_id`)
)ENGINE=InnoDB CHARSET=utf8mb3 comment '群消息读取位置';

16
im-server/pom.xml

@ -39,14 +39,18 @@
</dependencies> </dependencies>
<build> <build>
<finalName>${project.artifactId}</finalName>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>spring-boot-maven-plugin</artifactId>
<configuration> <executions>
<source>8</source> <execution>
<target>8</target> <goals>
</configuration> <goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin> </plugin>
</plugins> </plugins>
</build> </build>

2
im-server/src/main/java/com/lx/implatform/imserver/IMServerApp.java

@ -25,7 +25,7 @@ public class IMServerApp implements CommandLineRunner {
private WebsocketServer WSServer; private WebsocketServer WSServer;
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(IMServerApp.class); SpringApplication.run(IMServerApp.class,args);
} }

18
im-server/src/main/java/com/lx/implatform/imserver/task/AbstractPullMessageTask.java

@ -1,10 +1,12 @@
package com.lx.implatform.imserver.task; package com.lx.implatform.imserver.task;
import com.lx.implatform.imserver.websocket.WebsocketServer; import com.lx.implatform.imserver.websocket.WebsocketServer;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
@ -29,7 +31,10 @@ public abstract class AbstractPullMessageTask{
public void init(){ public void init(){
// 初始化定时器 // 初始化定时器
executorService = Executors.newFixedThreadPool(threadNum); executorService = Executors.newFixedThreadPool(threadNum);
for(int i=0;i<threadNum;i++){
executorService.execute(new Runnable() { executorService.execute(new Runnable() {
@SneakyThrows
@Override @Override
public void run() { public void run() {
try{ try{
@ -39,11 +44,24 @@ public abstract class AbstractPullMessageTask{
Thread.sleep(100); Thread.sleep(100);
}catch (Exception e){ }catch (Exception e){
log.error("任务调度异常",e); log.error("任务调度异常",e);
Thread.sleep(200);
} }
if(!executorService.isShutdown()){
executorService.execute(this); executorService.execute(this);
} }
}
}); });
} }
}
@PreDestroy
public void destroy(){
log.info("{}线程任务关闭",this.getClass().getSimpleName());
executorService.shutdown();
}
public abstract void pullMessage(); public abstract void pullMessage();
} }

1
im-server/src/main/java/com/lx/implatform/imserver/task/PullUnreadGroupMessageTask.java

@ -28,6 +28,7 @@ public class PullUnreadGroupMessageTask extends AbstractPullMessageTask {
private RedisTemplate<String,Object> redisTemplate; private RedisTemplate<String,Object> redisTemplate;
@Override @Override
public void pullMessage() { public void pullMessage() {
// 从redis拉取未读消息 // 从redis拉取未读消息

1
im-ui/src/api/httpRequest.js

@ -3,6 +3,7 @@ import router from '@/router'
import {Message} from 'element-ui' import {Message} from 'element-ui'
const http = axios.create({ const http = axios.create({
baseURL: process.env.VUE_APP_BASE_API,
timeout: 1000 * 30, timeout: 1000 * 30,
withCredentials: true, withCredentials: true,
headers: { headers: {

20
im-ui/src/components/chat/ChatGroup.vue

@ -21,13 +21,13 @@
<div class="chat-tool-bar"> <div class="chat-tool-bar">
<div title="表情" class="el-icon-service" @click="$message.error('还不支持发表情符号呢')"></div> <div title="表情" class="el-icon-service" @click="$message.error('还不支持发表情符号呢')"></div>
<div title="发送图片" > <div title="发送图片" >
<file-upload action="/api/image/upload" :maxSize="5*1024*1024" :fileTypes="['image/jpeg', 'image/png', 'image/jpg', 'image/webp','image/gif']" <file-upload :action="imageAction" :maxSize="5*1024*1024" :fileTypes="['image/jpeg', 'image/png', 'image/jpg', 'image/webp','image/gif']"
@before="handleImageBefore" @success="handleImageSuccess" @fail="handleImageFail"> @before="handleImageBefore" @success="handleImageSuccess" @fail="handleImageFail">
<i class="el-icon-picture-outline"></i> <i class="el-icon-picture-outline"></i>
</file-upload> </file-upload>
</div> </div>
<div title="发送文件"> <div title="发送文件">
<file-upload action="/api/file/upload" :maxSize="10*1024*1024" @before="handleFileBefore" @success="handleFileSuccess" <file-upload :action="fileAction" :maxSize="10*1024*1024" @before="handleFileBefore" @success="handleFileSuccess"
@fail="handleFileFail"> @fail="handleFileFail">
<i class="el-icon-wallet"></i> <i class="el-icon-wallet"></i>
</file-upload> </file-upload>
@ -80,7 +80,7 @@
type: 1 type: 1
} }
this.$http({ this.$http({
url: '/api/message/group/send', url: '/message/group/send',
method: 'post', method: 'post',
data: msgInfo data: msgInfo
}).then((data) => { }).then((data) => {
@ -138,7 +138,7 @@
type: 2 type: 2
} }
this.$http({ this.$http({
url: '/api/message/group/send', url: '/message/group/send',
method: 'post', method: 'post',
data: msgInfo data: msgInfo
}).then(() => { }).then(() => {
@ -200,7 +200,7 @@
type: 0 type: 0
} }
this.$http({ this.$http({
url: '/api/message/group/send', url: '/message/group/send',
method: 'post', method: 'post',
data: msgInfo data: msgInfo
}).then((data) => { }).then((data) => {
@ -224,7 +224,7 @@
}, },
loadGroup(groupId) { loadGroup(groupId) {
this.$http({ this.$http({
url: `/api/group/find/${groupId}`, url: `/group/find/${groupId}`,
method: 'get' method: 'get'
}).then((group) => { }).then((group) => {
this.group = group; this.group = group;
@ -232,7 +232,7 @@
}); });
this.$http({ this.$http({
url: `/api/group/members/${groupId}`, url: `/group/members/${groupId}`,
method: 'get' method: 'get'
}).then((groupMembers) => { }).then((groupMembers) => {
this.groupMembers = groupMembers; this.groupMembers = groupMembers;
@ -261,6 +261,12 @@
title() { title() {
let size = this.groupMembers.filter(m => !m.quit).length; let size = this.groupMembers.filter(m => !m.quit).length;
return `${this.chat.showName}(${size})`; return `${this.chat.showName}(${size})`;
},
imageAction(){
return `${process.env.VUE_APP_BASE_API}/image/upload`;
},
fileAction(){
return `${process.env.VUE_APP_BASE_API}/file/upload`;
} }
}, },

7
im-ui/src/components/chat/ChatGroupSide.vue

@ -80,7 +80,7 @@
}, },
loadGroupMembers() { loadGroupMembers() {
this.$http({ this.$http({
url: `/api/group/members/${this.group.id}`, url: `/group/members/${this.group.id}`,
method: "get" method: "get"
}).then((members) => { }).then((members) => {
this.groupMembers = members; this.groupMembers = members;
@ -89,7 +89,7 @@
handleSaveGroup() { handleSaveGroup() {
let vo = this.group; let vo = this.group;
this.$http({ this.$http({
url: "/api/group/modify", url: "/group/modify",
method: "put", method: "put",
data: vo data: vo
}).then((group) => { }).then((group) => {
@ -105,7 +105,7 @@
type: 'warning' type: 'warning'
}).then(() => { }).then(() => {
this.$http({ this.$http({
url: `/api/group/quit/${this.group.id}`, url: `/group/quit/${this.group.id}`,
method: 'delete' method: 'delete'
}).then(() => { }).then(() => {
this.$store.commit("removeGroup", this.group.id); this.$store.commit("removeGroup", this.group.id);
@ -124,6 +124,7 @@
isOwner() { isOwner() {
return this.group.ownerId == this.$store.state.userStore.userInfo.id; return this.group.ownerId == this.$store.state.userStore.userInfo.id;
} }
} }
} }
</script> </script>

16
im-ui/src/components/chat/ChatPrivate.vue

@ -18,13 +18,13 @@
<div class="chat-tool-bar"> <div class="chat-tool-bar">
<div class="el-icon-service"></div> <div class="el-icon-service"></div>
<div> <div>
<file-upload action="/api/image/upload" :maxSize="5*1024*1024" :fileTypes="['image/jpeg', 'image/png', 'image/jpg','image/webp', 'image/gif']" <file-upload :action="imageAction" :maxSize="5*1024*1024" :fileTypes="['image/jpeg', 'image/png', 'image/jpg','image/webp', 'image/gif']"
@before="handleImageBefore" @success="handleImageSuccess" @fail="handleImageFail"> @before="handleImageBefore" @success="handleImageSuccess" @fail="handleImageFail">
<i class="el-icon-picture-outline"></i> <i class="el-icon-picture-outline"></i>
</file-upload> </file-upload>
</div> </div>
<div> <div>
<file-upload action="/api/file/upload" :maxSize="10*1024*1024" @before="handleFileBefore" @success="handleFileSuccess" <file-upload :action="fileAction" :maxSize="10*1024*1024" @before="handleFileBefore" @success="handleFileSuccess"
@fail="handleFileFail"> @fail="handleFileFail">
<i class="el-icon-wallet"></i> <i class="el-icon-wallet"></i>
</file-upload> </file-upload>
@ -67,7 +67,7 @@
type: 1 type: 1
} }
this.$http({ this.$http({
url: '/api/message/private/send', url: '/message/private/send',
method: 'post', method: 'post',
data: msgInfo data: msgInfo
}).then((data) => { }).then((data) => {
@ -126,7 +126,7 @@
type: 2 type: 2
} }
this.$http({ this.$http({
url: '/api/message/private/send', url: '/message/private/send',
method: 'post', method: 'post',
data: msgInfo data: msgInfo
}).then(() => { }).then(() => {
@ -180,7 +180,7 @@
type: 0 type: 0
} }
this.$http({ this.$http({
url: '/api/message/private/send', url: '/message/private/send',
method: 'post', method: 'post',
data: msgInfo data: msgInfo
}).then((data) => { }).then((data) => {
@ -212,6 +212,12 @@
computed: { computed: {
mine() { mine() {
return this.$store.state.userStore.userInfo; return this.$store.state.userStore.userInfo;
},
imageAction(){
return `${process.env.VUE_APP_BASE_API}/image/upload`;
},
fileAction(){
return `${process.env.VUE_APP_BASE_API}/file/upload`;
} }
}, },
mounted() { mounted() {

2
im-ui/src/components/common/HeadImage.vue

@ -28,7 +28,7 @@
showUserInfo(e){ showUserInfo(e){
if(this.id && this.id>0){ if(this.id && this.id>0){
this.$http({ this.$http({
url: `/api/user/find/${this.id}`, url: `/user/find/${this.id}`,
method: 'get' method: 'get'
}).then((user) => { }).then((user) => {
this.$store.commit("setUserInfoBoxPos",e); this.$store.commit("setUserInfoBoxPos",e);

2
im-ui/src/components/common/UserInfo.vue

@ -63,7 +63,7 @@
}, },
handleAddFriend() { handleAddFriend() {
this.$http({ this.$http({
url: "/api/friend/add", url: "/friend/add",
method: "post", method: "post",
params: { params: {
friendId: this.user.id friendId: this.user.id

4
im-ui/src/components/friend/AddFriend.vue

@ -45,7 +45,7 @@
}, },
handleSearch() { handleSearch() {
this.$http({ this.$http({
url: "/api/user/findByNickName", url: "/user/findByNickName",
method: "get", method: "get",
params: { params: {
nickName: this.searchText nickName: this.searchText
@ -56,7 +56,7 @@
}, },
handleAddFriend(user){ handleAddFriend(user){
this.$http({ this.$http({
url: "/api/friend/add", url: "/friend/add",
method: "post", method: "post",
params: { params: {
friendId: user.id friendId: user.id

2
im-ui/src/components/group/AddGroupMember.vue

@ -64,7 +64,7 @@
}) })
if (inviteVO.friendIds.length > 0) { if (inviteVO.friendIds.length > 0) {
this.$http({ this.$http({
url: "/api/group/invite", url: "/group/invite",
method: 'post', method: 'post',
data: inviteVO data: inviteVO
}).then(() => { }).then(() => {

17
im-ui/src/components/setting/Setting.vue

@ -3,7 +3,7 @@
<el-form :model="userInfo" label-width="80px" :rules="rules" ref="settingForm"> <el-form :model="userInfo" label-width="80px" :rules="rules" ref="settingForm">
<el-form-item label="头像"> <el-form-item label="头像">
<file-upload class="avatar-uploader" <file-upload class="avatar-uploader"
action="/api/image/upload" :action="imageAction"
:showLoading="true" :showLoading="true"
:maxSize="maxSize" :maxSize="maxSize"
@success="handleUploadSuccess" @success="handleUploadSuccess"
@ -53,7 +53,7 @@
}, },
maxSize: 5*1024*1024, maxSize: 5*1024*1024,
action: "/api/image/upload", action: "/image/upload",
rules: { rules: {
nickName: [{ nickName: [{
required: true, required: true,
@ -74,7 +74,7 @@
return false; return false;
} }
this.$http({ this.$http({
url: "/api/user/update", url: "/user/update",
method: "put", method: "put",
data: this.userInfo data: this.userInfo
}).then(()=>{ }).then(()=>{
@ -94,11 +94,16 @@
type: Boolean type: Boolean
} }
}, },
computed:{
imageAction(){
return `${process.env.VUE_APP_BASE_API}/image/upload`;
}
},
mounted() { mounted() {
this.userInfo = this.$store.state.userStore.userInfo; //
console.log(this.userInfo) let mine = this.$store.state.userStore.userInfo;
this.userInfo = JSON.parse(JSON.stringify(mine));
} }
} }
</script> </script>

4
im-ui/src/store/friendStore.js

@ -10,7 +10,7 @@ export default {
mutations: { mutations: {
initFriendStore(state) { initFriendStore(state) {
httpRequest({ httpRequest({
url: '/api/friend/list', url: '/friend/list',
method: 'get' method: 'get'
}).then((friends) => { }).then((friends) => {
this.commit("setFriends",friends); this.commit("setFriends",friends);
@ -48,7 +48,7 @@ export default {
} }
state.friends.forEach((f)=>{userIds.push(f.id)}); state.friends.forEach((f)=>{userIds.push(f.id)});
httpRequest({ httpRequest({
url: '/api/user/online', url: '/user/online',
method: 'get', method: 'get',
params: {userIds: userIds.join(',')} params: {userIds: userIds.join(',')}
}).then((onlineIds) => { }).then((onlineIds) => {

2
im-ui/src/store/groupStore.js

@ -9,7 +9,7 @@ export default {
mutations: { mutations: {
initGroupStore(state) { initGroupStore(state) {
httpRequest({ httpRequest({
url: '/api/group/list', url: '/group/list',
method: 'get' method: 'get'
}).then((groups) => { }).then((groups) => {
this.commit("setGroups",groups); this.commit("setGroups",groups);

2
im-ui/src/store/userStore.js

@ -11,7 +11,7 @@ export default {
console.log("用户切换") console.log("用户切换")
this.commit("resetChatStore"); this.commit("resetChatStore");
} }
state.userInfo = userInfo; state.userInfo = Object.assign(state.userInfo, userInfo);
} }
} }

6
im-ui/src/view/Chat.vue

@ -66,7 +66,7 @@
type: 0 type: 0
} }
this.$http({ this.$http({
url: '/api/message/group/send', url: '/message/group/send',
method: 'post', method: 'post',
data: msgInfo data: msgInfo
}).then((data) => { }).then((data) => {
@ -86,7 +86,7 @@
// //
let userId = chat.targetId; let userId = chat.targetId;
this.$http({ this.$http({
url: `/api/user/find/${userId}`, url: `/user/find/${userId}`,
method: 'get' method: 'get'
}).then((user) => { }).then((user) => {
// //
@ -104,7 +104,7 @@
headImage: user.headImageThumb headImage: user.headImageThumb
}; };
this.$http({ this.$http({
url: "/api/friend/update", url: "/friend/update",
method: "put", method: "put",
data: friendInfo data: friendInfo
}).then(() => { }).then(() => {

6
im-ui/src/view/Friend.vue

@ -84,7 +84,7 @@
type: 'warning' type: 'warning'
}).then(() => { }).then(() => {
this.$http({ this.$http({
url: `/api/friend/delete/${friend.id}`, url: `/friend/delete/${friend.id}`,
method: 'delete' method: 'delete'
}).then((data) => { }).then((data) => {
this.$message.success("删除好友成功"); this.$message.success("删除好友成功");
@ -117,7 +117,7 @@
friend.headImage = user.headImageThumb; friend.headImage = user.headImageThumb;
friend.nickName = user.nickName; friend.nickName = user.nickName;
this.$http({ this.$http({
url: "/api/friend/update", url: "/friend/update",
method: "put", method: "put",
data: friend data: friend
}).then(() => { }).then(() => {
@ -127,7 +127,7 @@
}, },
loadUserInfo(friend,index){ loadUserInfo(friend,index){
this.$http({ this.$http({
url: `/api/user/find/${friend.id}`, url: `/user/find/${friend.id}`,
method: 'get' method: 'get'
}).then((user) => { }).then((user) => {
this.userInfo = user; this.userInfo = user;

17
im-ui/src/view/Group.vue

@ -26,7 +26,7 @@
<div v-show="activeGroup.id"> <div v-show="activeGroup.id">
<div class="r-group-info"> <div class="r-group-info">
<div> <div>
<file-upload class="avatar-uploader" action="/api/image/upload" :disabled="!isOwner" :showLoading="true" <file-upload class="avatar-uploader" :action="imageAction" :disabled="!isOwner" :showLoading="true"
:maxSize="maxSize" @success="handleUploadSuccess" :fileTypes="['image/jpeg', 'image/png', 'image/jpg','image/webp']"> :maxSize="maxSize" @success="handleUploadSuccess" :fileTypes="['image/jpeg', 'image/png', 'image/jpg','image/webp']">
<img v-if="activeGroup.headImage" :src="activeGroup.headImage" class="avatar"> <img v-if="activeGroup.headImage" :src="activeGroup.headImage" class="avatar">
<i v-else class="el-icon-plus avatar-uploader-icon"></i> <i v-else class="el-icon-plus avatar-uploader-icon"></i>
@ -119,7 +119,7 @@
inputErrorMessage: '请输入群聊名称' inputErrorMessage: '请输入群聊名称'
}).then((o) => { }).then((o) => {
this.$http({ this.$http({
url: `/api/group/create?groupName=${o.value}`, url: `/group/create?groupName=${o.value}`,
method: 'post' method: 'post'
}).then((group) => { }).then((group) => {
this.$store.commit("addGroup", group); this.$store.commit("addGroup", group);
@ -148,7 +148,7 @@
if (valid) { if (valid) {
let vo = this.activeGroup; let vo = this.activeGroup;
this.$http({ this.$http({
url: "/api/group/modify", url: "/group/modify",
method: "put", method: "put",
data: vo data: vo
}).then((group) => { }).then((group) => {
@ -165,7 +165,7 @@
type: 'warning' type: 'warning'
}).then(() => { }).then(() => {
this.$http({ this.$http({
url: `/api/group/delete/${this.activeGroup.id}`, url: `/group/delete/${this.activeGroup.id}`,
method: 'delete' method: 'delete'
}).then(() => { }).then(() => {
this.$store.commit("removeGroup", this.activeGroup.id); this.$store.commit("removeGroup", this.activeGroup.id);
@ -182,7 +182,7 @@
type: 'warning' type: 'warning'
}).then(() => { }).then(() => {
this.$http({ this.$http({
url: `/api/group/kick/${this.activeGroup.id}`, url: `/group/kick/${this.activeGroup.id}`,
method: 'delete', method: 'delete',
params: { params: {
userId: member.userId userId: member.userId
@ -201,7 +201,7 @@
type: 'warning' type: 'warning'
}).then(() => { }).then(() => {
this.$http({ this.$http({
url: `/api/group/quit/${this.activeGroup.id}`, url: `/group/quit/${this.activeGroup.id}`,
method: 'delete' method: 'delete'
}).then(() => { }).then(() => {
this.$store.commit("removeGroup", this.activeGroup.id); this.$store.commit("removeGroup", this.activeGroup.id);
@ -224,7 +224,7 @@
}, },
loadGroupMembers() { loadGroupMembers() {
this.$http({ this.$http({
url: `/api/group/members/${this.activeGroup.id}`, url: `/group/members/${this.activeGroup.id}`,
method: "get" method: "get"
}).then((members) => { }).then((members) => {
this.groupMembers = members; this.groupMembers = members;
@ -241,6 +241,9 @@
}, },
isOwner() { isOwner() {
return this.activeGroup.ownerId == this.$store.state.userStore.userInfo.id; return this.activeGroup.ownerId == this.$store.state.userStore.userInfo.id;
},
imageAction(){
return `${process.env.VUE_APP_BASE_API}/image/upload`;
} }
}, },
mounted() { mounted() {

14
im-ui/src/view/Home.vue

@ -68,7 +68,7 @@
init(userInfo) { init(userInfo) {
this.$store.commit("setUserInfo", userInfo); this.$store.commit("setUserInfo", userInfo);
this.$store.commit("initStore"); this.$store.commit("initStore");
this.$wsApi.createWebSocket("ws://localhost:8878/im", this.$store); this.$wsApi.createWebSocket(process.env.VUE_APP_WS_URL, this.$store);
this.$wsApi.onopen(() => { this.$wsApi.onopen(() => {
this.pullUnreadMessage(); this.pullUnreadMessage();
}); });
@ -92,12 +92,12 @@
pullUnreadMessage() { pullUnreadMessage() {
// //
this.$http({ this.$http({
url: "/api/message/private/pullUnreadMessage", url: "/message/private/pullUnreadMessage",
method: 'post' method: 'post'
}); });
// //
this.$http({ this.$http({
url: "/api/message/group/pullUnreadMessage", url: "/message/group/pullUnreadMessage",
method: 'post' method: 'post'
}); });
}, },
@ -110,7 +110,7 @@
} }
// //
this.$http({ this.$http({
url: `/api/friend/find/${msg.sendId}`, url: `/friend/find/${msg.sendId}`,
method: 'get' method: 'get'
}).then((friend) => { }).then((friend) => {
this.insertPrivateMessage(friend, msg); this.insertPrivateMessage(friend, msg);
@ -138,7 +138,7 @@
} }
// //
this.$http({ this.$http({
url: `/api/group/find/${msg.groupId}`, url: `/group/find/${msg.groupId}`,
method: 'get' method: 'get'
}).then((group) => { }).then((group) => {
this.insertGroupMessage(group, msg); this.insertGroupMessage(group, msg);
@ -159,7 +159,7 @@
}, },
handleExit() { handleExit() {
this.$http({ this.$http({
url: "/api/logout", url: "/logout",
method: 'get' method: 'get'
}).then(() => { }).then(() => {
this.$wsApi.closeWebSocket(); this.$wsApi.closeWebSocket();
@ -180,7 +180,7 @@
}, },
mounted() { mounted() {
this.$http({ this.$http({
url: "/api/user/self", url: "/user/self",
methods: 'get' methods: 'get'
}).then((userInfo) => { }).then((userInfo) => {
this.init(userInfo); this.init(userInfo);

2
im-ui/src/view/Login.vue

@ -63,7 +63,7 @@
this.$refs[formName].validate((valid) => { this.$refs[formName].validate((valid) => {
if (valid) { if (valid) {
this.$http({ this.$http({
url: "/api/login", url: "/login",
method: 'post', method: 'post',
params: this.loginForm params: this.loginForm
}) })

2
im-ui/src/view/Register.vue

@ -95,7 +95,7 @@
this.$refs[formName].validate((valid) => { this.$refs[formName].validate((valid) => {
if (valid) { if (valid) {
this.$http({ this.$http({
url: "/api/register", url: "/register",
method: 'post', method: 'post',
data: this.registerForm data: this.registerForm
}) })

24
pom.xml

@ -15,28 +15,10 @@
<module>commom</module> <module>commom</module>
</modules> </modules>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.16</version>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
</dependency>
<!--FastJson-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
</dependencies>
<properties> <properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version> <java.version>1.8</java.version>

Loading…
Cancel
Save