Compare commits
10 Commits
b313f11eb4
...
6d2a22f2b9
Author | SHA1 | Date |
---|---|---|
flykhan | 6d2a22f2b9 | |
flykhan | 0ed6c70139 | |
flykhan | 1c4deb2c3f | |
flykhan | 479883bc3e | |
flykhan | cc95f82b7f | |
flykhan | 304f2fbd0c | |
flykhan | dbbfb700e4 | |
flykhan | 748d015cb9 | |
flykhan | 38bcba6bdf | |
flykhan | 2b273a6ba6 |
|
@ -12,6 +12,28 @@
|
||||||
<groupId>com.kob.backend</groupId>
|
<groupId>com.kob.backend</groupId>
|
||||||
<artifactId>backend</artifactId>
|
<artifactId>backend</artifactId>
|
||||||
|
|
||||||
|
<!-- 项目打包类型 : jar -->
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
<!--这里写上main方法所在类的路径-->
|
||||||
|
<configuration>
|
||||||
|
<mainClass>com.kob.backend.BackendApplication</mainClass>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>repackage</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>8</maven.compiler.source>
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
<maven.compiler.target>8</maven.compiler.target>
|
<maven.compiler.target>8</maven.compiler.target>
|
||||||
|
|
|
@ -48,7 +48,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
||||||
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
|
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
|
||||||
.and()
|
.and()
|
||||||
.authorizeRequests()
|
.authorizeRequests()
|
||||||
.antMatchers("/user/account/token/", "/user/account/register/").permitAll()
|
.antMatchers("/api/user/account/token/", "/api/user/account/register/").permitAll()
|
||||||
.antMatchers("/pk/start/","/pk/receive/bot/move/").hasIpAddress("127.0.0.1")
|
.antMatchers("/pk/start/","/pk/receive/bot/move/").hasIpAddress("127.0.0.1")
|
||||||
.antMatchers(HttpMethod.OPTIONS).permitAll()
|
.antMatchers(HttpMethod.OPTIONS).permitAll()
|
||||||
.anyRequest().authenticated();
|
.anyRequest().authenticated();
|
||||||
|
|
|
@ -10,7 +10,6 @@ import com.kob.backend.mapper.UserMapper;
|
||||||
import com.kob.backend.pojo.User;
|
import com.kob.backend.pojo.User;
|
||||||
import com.kob.backend.service.impl.utils.UserDetailsImpl;
|
import com.kob.backend.service.impl.utils.UserDetailsImpl;
|
||||||
import com.kob.backend.utils.JwtUtil;
|
import com.kob.backend.utils.JwtUtil;
|
||||||
import com.sun.xml.internal.bind.v2.TODO;
|
|
||||||
import io.jsonwebtoken.Claims;
|
import io.jsonwebtoken.Claims;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
|
@ -46,8 +46,8 @@ public class WebSocketServer {
|
||||||
private User user;
|
private User user;
|
||||||
public Game game = null;
|
public Game game = null;
|
||||||
// addPlayer 添加用户到匹配池的 URL; removePlayer 从匹配池移除用户的 URL
|
// addPlayer 添加用户到匹配池的 URL; removePlayer 从匹配池移除用户的 URL
|
||||||
private final static String addPlayerUrl = "http://127.0.0.1:3001/player/add/";
|
private final static String addPlayerUrl = "http://127.0.0.1:3002/player/add/";
|
||||||
private final static String removePlayerUrl = "http://127.0.0.1:3001/player/remove/";
|
private final static String removePlayerUrl = "http://127.0.0.1:3002/player/remove/";
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public void setRestTemplate(RestTemplate restTemplate) {
|
public void setRestTemplate(RestTemplate restTemplate) {
|
||||||
|
|
|
@ -33,7 +33,7 @@ public class Game extends Thread {
|
||||||
// 定义失败者: all(平局), A(A输), B(B输)
|
// 定义失败者: all(平局), A(A输), B(B输)
|
||||||
private String loser = "";
|
private String loser = "";
|
||||||
// 传送消息给 BotRunningSystem 的链接
|
// 传送消息给 BotRunningSystem 的链接
|
||||||
private static final String addBotUrl = "http://127.0.0.1:3002/bot/add/";
|
private static final String addBotUrl = "http://127.0.0.1:3003/bot/add/";
|
||||||
|
|
||||||
|
|
||||||
// 初始化(有参)构造函数
|
// 初始化(有参)构造函数
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
// 微服务内部 api
|
||||||
package com.kob.backend.controller.pk;
|
package com.kob.backend.controller.pk;
|
||||||
|
|
||||||
import com.kob.backend.service.pk.ReceiveBotMoveService;
|
import com.kob.backend.service.pk.ReceiveBotMoveService;
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
// 微服务内部 api
|
||||||
package com.kob.backend.controller.pk;
|
package com.kob.backend.controller.pk;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ public class GetRankListController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private GetRankListService getRankListService;
|
private GetRankListService getRankListService;
|
||||||
|
|
||||||
@GetMapping("/ranklist/getranklist/")
|
@GetMapping("/api/ranklist/getranklist/")
|
||||||
JSONObject getRankList(@RequestParam Map<String, String> data) {
|
JSONObject getRankList(@RequestParam Map<String, String> data) {
|
||||||
Integer page = Integer.parseInt(data.get("page_index"));
|
Integer page = Integer.parseInt(data.get("page_index"));
|
||||||
Integer.parseInt(data.get("page_index"));
|
Integer.parseInt(data.get("page_index"));
|
||||||
|
|
|
@ -15,7 +15,7 @@ public class GetRecordListController {
|
||||||
private GetRecordListService getRecordListService;
|
private GetRecordListService getRecordListService;
|
||||||
|
|
||||||
// 这里只需要获取,因此只需要用 get 方法(需要新建和修改数据时,使用 post 方法)
|
// 这里只需要获取,因此只需要用 get 方法(需要新建和修改数据时,使用 post 方法)
|
||||||
@GetMapping("/record/getlist/")
|
@GetMapping("/api/record/getlist/")
|
||||||
public JSONObject getList(@RequestParam Map<String, String> data) {
|
public JSONObject getList(@RequestParam Map<String, String> data) {
|
||||||
// 解析出 page 信息
|
// 解析出 page 信息
|
||||||
Integer page = Integer.parseInt(data.get("page_index"));
|
Integer page = Integer.parseInt(data.get("page_index"));
|
||||||
|
|
|
@ -13,7 +13,7 @@ public class InfoController {
|
||||||
private InfoService infoService;
|
private InfoService infoService;
|
||||||
|
|
||||||
// 获取信息
|
// 获取信息
|
||||||
@GetMapping("/user/account/info/")
|
@GetMapping("/api/user/account/info/")
|
||||||
public Map<String,String> getInfo(){
|
public Map<String,String> getInfo(){
|
||||||
return infoService.getInfo();
|
return infoService.getInfo();
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ public class LoginController {
|
||||||
private LoginService loginService;
|
private LoginService loginService;
|
||||||
|
|
||||||
// 登录使用 POST 请求,密文传输,更安全
|
// 登录使用 POST 请求,密文传输,更安全
|
||||||
@PostMapping("/user/account/token/")
|
@PostMapping("/api/user/account/token/")
|
||||||
public Map<String,String> getToken(@RequestParam Map<String,String> map){
|
public Map<String,String> getToken(@RequestParam Map<String,String> map){
|
||||||
String username = map.get("username");
|
String username = map.get("username");
|
||||||
String password = map.get("password");
|
String password = map.get("password");
|
||||||
|
|
|
@ -13,7 +13,7 @@ public class RegisterController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private RegisterService registerService;
|
private RegisterService registerService;
|
||||||
|
|
||||||
@PostMapping("/user/account/register/")
|
@PostMapping("/api/user/account/register/")
|
||||||
public Map<String, String> register(@RequestParam Map<String, String> map) {
|
public Map<String, String> register(@RequestParam Map<String, String> map) {
|
||||||
String username = map.get("username");
|
String username = map.get("username");
|
||||||
String password = map.get("password");
|
String password = map.get("password");
|
||||||
|
|
|
@ -11,7 +11,7 @@ public class AddController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private AddService addService;
|
private AddService addService;
|
||||||
|
|
||||||
@PostMapping("/user/bot/add/")
|
@PostMapping("/api/user/bot/add/")
|
||||||
public Map<String,String> add(@RequestParam Map<String,String> data){
|
public Map<String,String> add(@RequestParam Map<String,String> data){
|
||||||
return addService.add(data);
|
return addService.add(data);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ public class GetListController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private GetListService getListService;
|
private GetListService getListService;
|
||||||
|
|
||||||
@GetMapping("/user/bot/getlist/")
|
@GetMapping("/api/user/bot/getlist/")
|
||||||
public List<Bot> getList(){
|
public List<Bot> getList(){
|
||||||
return getListService.getList();
|
return getListService.getList();
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ public class RemoveController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private RemoveService removeService;
|
private RemoveService removeService;
|
||||||
|
|
||||||
@PostMapping("/user/bot/remove/")
|
@PostMapping("/api/user/bot/remove/")
|
||||||
public Map<String,String> remove(@RequestParam Map<String,String> data){
|
public Map<String,String> remove(@RequestParam Map<String,String> data){
|
||||||
return removeService.remove(data);
|
return removeService.remove(data);
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ public class UpdateController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private UpdateService updateService;
|
private UpdateService updateService;
|
||||||
|
|
||||||
@PostMapping("/user/bot/update/")
|
@PostMapping("/api/user/bot/update/")
|
||||||
public Map<String,String> update(@RequestParam Map<String,String> data){
|
public Map<String,String> update(@RequestParam Map<String,String> data){
|
||||||
return updateService.update(data);
|
return updateService.update(data);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
#default server port
|
#default server port
|
||||||
server.port=3000
|
server.port=3001
|
||||||
|
|
||||||
#mysql database connect profile
|
#mysql database connect profile
|
||||||
spring.datasource.username=root
|
spring.datasource.username=root
|
||||||
spring.datasource.password=mysqlPassword
|
spring.datasource.password=mysqlpassword
|
||||||
spring.datasource.url=jdbc:mysql://localhost:3306/kob?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8
|
spring.datasource.url=jdbc:mysql://localhost:3306/kob?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8
|
||||||
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||||
|
|
|
@ -1,18 +0,0 @@
|
||||||
package com.kob.backend;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
|
||||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|
||||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
|
||||||
|
|
||||||
@SpringBootTest
|
|
||||||
class BackendApplicationTests {
|
|
||||||
|
|
||||||
// 测试明文加密
|
|
||||||
@Test
|
|
||||||
void contextLoads() {
|
|
||||||
PasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
|
|
||||||
System.out.println(passwordEncoder.encode("123"));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -12,6 +12,28 @@
|
||||||
<groupId>com.kob.botrunningsystem</groupId>
|
<groupId>com.kob.botrunningsystem</groupId>
|
||||||
<artifactId>botrunningsystem</artifactId>
|
<artifactId>botrunningsystem</artifactId>
|
||||||
|
|
||||||
|
<!-- 项目打包类型 : jar -->
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
<!--这里写上main方法所在类的路径-->
|
||||||
|
<configuration>
|
||||||
|
<mainClass>com.kob.botrunningsystem.BotRunningSystemApplication</mainClass>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>repackage</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>8</maven.compiler.source>
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
<maven.compiler.target>8</maven.compiler.target>
|
<maven.compiler.target>8</maven.compiler.target>
|
||||||
|
|
|
@ -19,7 +19,7 @@ import java.util.function.Supplier;
|
||||||
public class Consumer extends Thread {
|
public class Consumer extends Thread {
|
||||||
private Bot bot;
|
private Bot bot;
|
||||||
// 定义返回信息 URL
|
// 定义返回信息 URL
|
||||||
private final static String receiveBotMoveUrl = "http://127.0.0.1:3000/pk/receive/bot/move/";
|
private final static String receiveBotMoveUrl = "http://127.0.0.1:3001/pk/receive/bot/move/";
|
||||||
|
|
||||||
//注入 RestTemplate 用于给 backend 服务发送信息
|
//注入 RestTemplate 用于给 backend 服务发送信息
|
||||||
private static RestTemplate restTemplate;
|
private static RestTemplate restTemplate;
|
||||||
|
|
|
@ -47,8 +47,8 @@ public class Bot implements java.util.function.Supplier<Integer> {
|
||||||
// @Override
|
// @Override
|
||||||
public Integer nextMove(String input) {
|
public Integer nextMove(String input) {
|
||||||
String[] strs = input.split("#");
|
String[] strs = input.split("#");
|
||||||
int rows = 18;
|
int rows = 13;
|
||||||
int cols = 19;
|
int cols = 14;
|
||||||
int[][] g = new int[rows][cols];
|
int[][] g = new int[rows][cols];
|
||||||
for (int i = 0, k = 0; i < rows; i++) {
|
for (int i = 0, k = 0; i < rows; i++) {
|
||||||
for (int j = 0; j < cols; j++, k++) {
|
for (int j = 0; j < cols; j++, k++) {
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
server.port=3002
|
server.port=3003
|
|
@ -12,6 +12,28 @@
|
||||||
<groupId>com.kob.matchingsystem</groupId>
|
<groupId>com.kob.matchingsystem</groupId>
|
||||||
<artifactId>matchingsystem</artifactId>
|
<artifactId>matchingsystem</artifactId>
|
||||||
|
|
||||||
|
<!-- 项目打包类型 : jar -->
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
<!--这里写上main方法所在类的路径-->
|
||||||
|
<configuration>
|
||||||
|
<mainClass>com.kob.matchingsystem.MatchingSystemApplication</mainClass>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>repackage</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>8</maven.compiler.source>
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
<maven.compiler.target>8</maven.compiler.target>
|
<maven.compiler.target>8</maven.compiler.target>
|
||||||
|
|
|
@ -18,7 +18,7 @@ public class MatchingPool extends Thread {
|
||||||
// 定义一个锁, Reentrant Lock 是可重入锁
|
// 定义一个锁, Reentrant Lock 是可重入锁
|
||||||
private final ReentrantLock lock = new ReentrantLock();
|
private final ReentrantLock lock = new ReentrantLock();
|
||||||
// 定义微服务传值 URL
|
// 定义微服务传值 URL
|
||||||
private static final String startGameUrl = "http://127.0.0.1:3000/pk/start/";
|
private static final String startGameUrl = "http://127.0.0.1:3001/pk/start/";
|
||||||
// 定义 RestTemplate 用来微服务数据通信
|
// 定义 RestTemplate 用来微服务数据通信
|
||||||
private static RestTemplate restTemplate;
|
private static RestTemplate restTemplate;
|
||||||
|
|
||||||
|
@ -88,13 +88,15 @@ public class MatchingPool extends Thread {
|
||||||
// 尝试匹配所有玩家
|
// 尝试匹配所有玩家
|
||||||
private void matchPlayers() {
|
private void matchPlayers() {
|
||||||
// TODO 后端调试
|
// TODO 后端调试
|
||||||
System.out.println("match players: " + playerList.toString());
|
// System.out.println("match players: " + playerList.toString());
|
||||||
// havaMatched 表示玩家已经匹配过了
|
// havaMatched 表示玩家已经匹配过了
|
||||||
boolean[] haveMatched = new boolean[playerList.size()];
|
boolean[] haveMatched = new boolean[playerList.size()];
|
||||||
for (int i = 0; i < playerList.size(); i++) {
|
for (int i = 0; i < playerList.size(); i++) {
|
||||||
if (haveMatched[i]) continue; // 如果当前枚举到的玩家已经匹配过了,则跳过改玩家
|
if (haveMatched[i])
|
||||||
|
continue; // 如果当前枚举到的玩家已经匹配过了,则跳过改玩家
|
||||||
for (int j = i + 1; j < playerList.size(); j++) { // j 从 i+1 开始枚举
|
for (int j = i + 1; j < playerList.size(); j++) { // j 从 i+1 开始枚举
|
||||||
if (haveMatched[j]) continue;
|
if (haveMatched[j])
|
||||||
|
continue;
|
||||||
// 如果 i 和 j 都没有匹配,则将 a 和 b 玩家取出来
|
// 如果 i 和 j 都没有匹配,则将 a 和 b 玩家取出来
|
||||||
Player a = playerList.get(i);
|
Player a = playerList.get(i);
|
||||||
Player b = playerList.get(j);
|
Player b = playerList.get(j);
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
server.port=3001
|
server.port=3002
|
Binary file not shown.
Before Width: | Height: | Size: 49 KiB After Width: | Height: | Size: 264 KiB |
|
@ -5,7 +5,7 @@
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
<meta name="viewport" content="width=device-width,initial-scale=1.0">
|
<meta name="viewport" content="width=device-width,initial-scale=1.0">
|
||||||
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
|
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
|
||||||
<title><%= htmlWebpackPlugin.options.title %></title>
|
<title>KoS</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<noscript>
|
<noscript>
|
||||||
|
|
|
@ -104,7 +104,7 @@ div.user-select-bot {
|
||||||
width: 60vw;
|
width: 60vw;
|
||||||
height: 70vh;
|
height: 70vh;
|
||||||
/* 背景色: rgba 加上透明通道 */
|
/* 背景色: rgba 加上透明通道 */
|
||||||
background: rgba(70, 70, 70, 0.5);
|
/* background: rgba(70, 70, 70, 0.5); */
|
||||||
/* 距上边距40px,左右居中 */
|
/* 距上边距40px,左右居中 */
|
||||||
margin: 40px auto;
|
margin: 40px auto;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,59 @@
|
||||||
|
// 用户指示标签
|
||||||
|
<template>
|
||||||
|
<div class="playground">
|
||||||
|
<div class="user_state_config" v-if="parseInt($store.state.user.id) === parseInt($store.state.pk.a_id)">
|
||||||
|
<div style="color: #4876ec; ">
|
||||||
|
左下角: {{ $store.state.user.username }}
|
||||||
|
 
|
||||||
|
<img :src="$store.state.user.photo" alt="" class="pk_photo">
|
||||||
|
</div>
|
||||||
|
<div style="color: #f94848;">
|
||||||
|
右上角:{{ $store.state.pk.opponent_username }}
|
||||||
|
 
|
||||||
|
<img :src="$store.state.pk.opponent_photo" alt="" class="pk_photo">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="user_state_config" v-if="parseInt($store.state.user.id) === parseInt($store.state.pk.b_id)">
|
||||||
|
<div style="color: #4876ec;">
|
||||||
|
左下角: {{ $store.state.pk.opponent_username }}
|
||||||
|
 
|
||||||
|
<img :src="$store.state.pk.opponent_photo" alt="" class="pk_photo">
|
||||||
|
</div>
|
||||||
|
<div style="color: #f94848;">
|
||||||
|
右上角:{{ $store.state.user.username }}
|
||||||
|
 
|
||||||
|
<img :src="$store.state.user.photo" alt="" class="pk_photo">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.playground {
|
||||||
|
/* 60% 浏览器宽度, 70% 浏览器高度 */
|
||||||
|
width: 40vw;
|
||||||
|
/* 背景色 */
|
||||||
|
/* background: lightblue; */
|
||||||
|
/* 距上边距40px,左右居中 */
|
||||||
|
margin: 10px auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.user_state_config {
|
||||||
|
text-align: center;
|
||||||
|
color: white;
|
||||||
|
font-size: 30;
|
||||||
|
font-weight: 600;
|
||||||
|
margin-top: auto;
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-evenly;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pk_photo {
|
||||||
|
border-radius: 50%;
|
||||||
|
width: 3vw;
|
||||||
|
}
|
||||||
|
</style>
|
|
@ -11,7 +11,7 @@ export default {
|
||||||
add(context, data) {
|
add(context, data) {
|
||||||
// 新建 bot
|
// 新建 bot
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "http://localhost:3000/user/bot/add/",
|
url: "http://localhost:3001/api/user/bot/add/",
|
||||||
type: "POST",
|
type: "POST",
|
||||||
data: {
|
data: {
|
||||||
title: data.title,
|
title: data.title,
|
||||||
|
@ -33,7 +33,7 @@ export default {
|
||||||
remove(context, data) {
|
remove(context, data) {
|
||||||
// 移除 bot
|
// 移除 bot
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "http://localhost:3000/user/bot/remove/",
|
url: "http://localhost:3001/api/user/bot/remove/",
|
||||||
type: "POST",
|
type: "POST",
|
||||||
data: {
|
data: {
|
||||||
bot_id: data.bot_id,
|
bot_id: data.bot_id,
|
||||||
|
@ -57,7 +57,7 @@ export default {
|
||||||
update(context, data) {
|
update(context, data) {
|
||||||
// 更新 bot
|
// 更新 bot
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "http://localhost:3000/user/bot/update/",
|
url: "http://localhost:3001/api/user/bot/update/",
|
||||||
type: "POST",
|
type: "POST",
|
||||||
data: {
|
data: {
|
||||||
bot_id: data.bot_id,
|
bot_id: data.bot_id,
|
||||||
|
@ -80,7 +80,7 @@ export default {
|
||||||
getList(context, data) {
|
getList(context, data) {
|
||||||
// 获取 Bot 列表
|
// 获取 Bot 列表
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "http://localhost:3000/user/bot/getlist/",
|
url: "http://localhost:3001/api/user/bot/getlist/",
|
||||||
type: "GET",
|
type: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer " + store.state.user.token,
|
Authorization: "Bearer " + store.state.user.token,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import $ from "jquery";
|
// import $ from "jquery";
|
||||||
import store from ".";
|
// import store from ".";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
state: {
|
state: {
|
||||||
|
@ -22,25 +22,25 @@ export default {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
getRecordList(context, data) {
|
// getRecordList(context, data) {
|
||||||
// 获取 Bot 列表
|
// // 获取 Bot 列表
|
||||||
$.ajax({
|
// $.ajax({
|
||||||
url: "http://localhost:3000/record/getlist/",
|
// url: "http://localhost:3001/api/record/getlist/",
|
||||||
data: {
|
// data: {
|
||||||
page_index: data.page,
|
// page_index: data.page,
|
||||||
},
|
// },
|
||||||
type: "GET",
|
// type: "GET",
|
||||||
headers: {
|
// headers: {
|
||||||
Authorization: "Bearer " + store.state.user.token,
|
// Authorization: "Bearer " + store.state.user.token,
|
||||||
},
|
// },
|
||||||
success(resp) {
|
// success(resp) {
|
||||||
data.success(resp);
|
// data.success(resp);
|
||||||
},
|
// },
|
||||||
error(resp) {
|
// error(resp) {
|
||||||
data.error(resp);
|
// data.error(resp);
|
||||||
},
|
// },
|
||||||
});
|
// });
|
||||||
},
|
// },
|
||||||
},
|
},
|
||||||
modules: {},
|
modules: {},
|
||||||
};
|
};
|
||||||
|
|
|
@ -41,7 +41,7 @@ export default {
|
||||||
// 登录函数
|
// 登录函数
|
||||||
login(context, data) {
|
login(context, data) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "http://localhost:3000/user/account/token/",
|
url: "http://localhost:3001/api/user/account/token/",
|
||||||
type: "POST",
|
type: "POST",
|
||||||
data: {
|
data: {
|
||||||
username: data.username,
|
username: data.username,
|
||||||
|
@ -71,7 +71,7 @@ export default {
|
||||||
// 注册函数
|
// 注册函数
|
||||||
register(context, data) {
|
register(context, data) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "http://localhost:3000/user/account/register/",
|
url: "http://localhost:3001/api/user/account/register/",
|
||||||
type: "POST",
|
type: "POST",
|
||||||
data: {
|
data: {
|
||||||
username: data.username,
|
username: data.username,
|
||||||
|
@ -94,7 +94,7 @@ export default {
|
||||||
// 获取登录成功后的用户信息
|
// 获取登录成功后的用户信息
|
||||||
getinfo(context, data) {
|
getinfo(context, data) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "http://localhost:3000/user/account/info/",
|
url: "http://localhost:3001/api/user/account/info/",
|
||||||
type: "GET",
|
type: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "Bearer " + context.state.token,
|
Authorization: "Bearer " + context.state.token,
|
||||||
|
|
|
@ -1,13 +1,17 @@
|
||||||
<template>
|
<template>
|
||||||
|
<div>
|
||||||
<PlayGround v-if="$store.state.pk.status === 'playing'" />
|
<PlayGround v-if="$store.state.pk.status === 'playing'" />
|
||||||
|
<UserIndicator v-if="$store.state.pk.status === 'playing'" />
|
||||||
<MatchGround v-else-if="$store.state.pk.status === 'matching'" />
|
<MatchGround v-else-if="$store.state.pk.status === 'matching'" />
|
||||||
<ResultBoard v-if="$store.state.pk.loser !== 'none'" />
|
<ResultBoard v-if="$store.state.pk.loser !== 'none'" />
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import PlayGround from "../../components/PlayGround.vue";
|
import PlayGround from "../../components/PlayGround.vue";
|
||||||
import MatchGround from "../../components/MatchGround.vue";
|
import MatchGround from "../../components/MatchGround.vue";
|
||||||
import ResultBoard from "../../components/ResultBoard.vue";
|
import ResultBoard from "../../components/ResultBoard.vue";
|
||||||
|
import UserIndicator from "../../components/UserIndicator.vue"
|
||||||
|
|
||||||
// onMounted 用于组件被挂载时, onUnmounted 用于组件被解除挂载时
|
// onMounted 用于组件被挂载时, onUnmounted 用于组件被解除挂载时
|
||||||
import { onMounted, onUnmounted } from "vue";
|
import { onMounted, onUnmounted } from "vue";
|
||||||
|
@ -18,13 +22,14 @@ export default {
|
||||||
components: {
|
components: {
|
||||||
PlayGround,
|
PlayGround,
|
||||||
MatchGround,
|
MatchGround,
|
||||||
ResultBoard
|
ResultBoard,
|
||||||
|
UserIndicator
|
||||||
},
|
},
|
||||||
// 创建前后端连接:当当前页面组件被加载时,建立连接,故使用 onMounted 函数
|
// 创建前后端连接:当当前页面组件被加载时,建立连接,故使用 onMounted 函数
|
||||||
setup() {
|
setup() {
|
||||||
const store = useStore();
|
const store = useStore();
|
||||||
// 定义后端连接的 url, 使用 ws 协议
|
// 定义后端连接的 url, 使用 ws 协议
|
||||||
const socketUrl = `ws://127.0.0.1:3000/websocket/${store.state.user.token}/`;
|
const socketUrl = `ws://127.0.0.1:3001/websocket/${store.state.user.token}/`;
|
||||||
|
|
||||||
let socket = null;
|
let socket = null;
|
||||||
|
|
||||||
|
|
|
@ -91,7 +91,7 @@ export default {
|
||||||
const pull_ranklist_page = (page) => {
|
const pull_ranklist_page = (page) => {
|
||||||
current_page = page;
|
current_page = page;
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "http://127.0.0.1:3000/ranklist/getranklist/",
|
url: "http://localhost:3001/api/ranklist/getranklist/",
|
||||||
data: {
|
data: {
|
||||||
page_index: page,
|
page_index: page,
|
||||||
},
|
},
|
||||||
|
|
|
@ -5,9 +5,9 @@
|
||||||
<!-- <table class="table table-sm" style="text-align:center"> -->
|
<!-- <table class="table table-sm" style="text-align:center"> -->
|
||||||
<!-- 创建表头: th 表示列 -->
|
<!-- 创建表头: th 表示列 -->
|
||||||
<thead>
|
<thead>
|
||||||
<th>玩家A</th>
|
<th style="color: #4876ec">玩家A</th>
|
||||||
<th>玩家B</th>
|
<th style="color: #f94848">玩家B</th>
|
||||||
<th>赢家</th>
|
<th style="color: #FFD700">赢家</th>
|
||||||
<th>对局时间</th>
|
<th>对局时间</th>
|
||||||
<th></th>
|
<th></th>
|
||||||
</thead>
|
</thead>
|
||||||
|
@ -17,12 +17,12 @@
|
||||||
<td>
|
<td>
|
||||||
<img :src="record.a_photo" alt="" class="record-user-photo">
|
<img :src="record.a_photo" alt="" class="record-user-photo">
|
||||||
|
|
||||||
<span class="record-user-username"> {{ record.a_username }}</span>
|
<span class="record-user-username" style="color: #4876ec"> {{ record.a_username }}</span>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<img :src="record.b_photo" alt="" class="record-user-photo">
|
<img :src="record.b_photo" alt="" class="record-user-photo">
|
||||||
|
|
||||||
<span class="record-user-username"> {{ record.b_username }}</span>
|
<span class="record-user-username" style="color: #f94848"> {{ record.b_username }}</span>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{{ record.winner }}
|
{{ record.winner }}
|
||||||
|
@ -62,6 +62,7 @@ import ContentBase from "../../components/ContentBase.vue";
|
||||||
import { useStore } from 'vuex';
|
import { useStore } from 'vuex';
|
||||||
import { ref } from "vue";
|
import { ref } from "vue";
|
||||||
import router from "@/router/index";
|
import router from "@/router/index";
|
||||||
|
import $ from "jquery";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
|
@ -103,9 +104,15 @@ export default {
|
||||||
|
|
||||||
const pull_page = (page) => { // 加载分页
|
const pull_page = (page) => { // 加载分页
|
||||||
current_page = page; // 更新页面序号
|
current_page = page; // 更新页面序号
|
||||||
|
$.ajax({
|
||||||
store.dispatch("getRecordList", {
|
url: "http://localhost:3001/api/record/getlist/",
|
||||||
page,
|
data: {
|
||||||
|
page_index: page,
|
||||||
|
},
|
||||||
|
type: "GET",
|
||||||
|
headers: {
|
||||||
|
Authorization: "Bearer " + store.state.user.token,
|
||||||
|
},
|
||||||
success(resp) {
|
success(resp) {
|
||||||
console.log(resp.records);
|
console.log(resp.records);
|
||||||
records.value = resp.records;
|
records.value = resp.records;
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
const { defineConfig } = require('@vue/cli-service')
|
const { defineConfig } = require("@vue/cli-service");
|
||||||
module.exports = defineConfig({
|
module.exports = defineConfig({
|
||||||
transpileDependencies: true
|
transpileDependencies: true,
|
||||||
})
|
devServer: {
|
||||||
|
port: 80, // 启动端口号
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in New Issue