feat: 看历史 7 天的手牌记录

This commit is contained in:
liutong.eric
2022-10-19 02:58:10 +08:00
parent b2acadda01
commit e073e556d2
14 changed files with 168 additions and 262 deletions
-205
View File
@@ -1,205 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="BranchesTreeState">
<expand>
<path>
<item name="ROOT" type="e8cecc67:BranchNodeDescriptor" />
<item name="LOCAL_ROOT" type="e8cecc67:BranchNodeDescriptor" />
</path>
<path>
<item name="ROOT" type="e8cecc67:BranchNodeDescriptor" />
<item name="REMOTE_ROOT" type="e8cecc67:BranchNodeDescriptor" />
</path>
<path>
<item name="ROOT" type="e8cecc67:BranchNodeDescriptor" />
<item name="REMOTE_ROOT" type="e8cecc67:BranchNodeDescriptor" />
<item name="GROUP_NODE:origin" type="e8cecc67:BranchNodeDescriptor" />
</path>
</expand>
<select>
<path>
<item name="ROOT" type="e8cecc67:BranchNodeDescriptor" />
<item name="LOCAL_ROOT" type="e8cecc67:BranchNodeDescriptor" />
<item name="BRANCH:master" type="e8cecc67:BranchNodeDescriptor" />
</path>
</select>
</component>
<component name="ChangeListManager">
<list default="true" id="f9039135-aa11-4abd-ad74-f40c84e4fdb2" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="Less File" />
<option value="TypeScript File" />
<option value="Vue Single File Component" />
<option value="Vue" />
</list>
</option>
</component>
<component name="Git.Settings">
<option name="RECENT_BRANCH_BY_REPOSITORY">
<map>
<entry key="$PROJECT_DIR$" value="bk" />
</map>
</option>
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
<option name="RESET_MODE" value="SOFT" />
</component>
<component name="JsFlowSettings">
<service-enabled>true</service-enabled>
<exe-path />
<other-services-enabled>true</other-services-enabled>
<auto-save>true</auto-save>
</component>
<component name="ProjectId" id="1ahwXO0WADZQzSECEEPPaWdpY8B" />
<component name="ProjectViewState">
<option name="autoscrollFromSource" value="true" />
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent">
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="js.linters.configure.manually.selectedtslint" value="true" />
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
<property name="list.type.of.created.stylesheet" value="Less" />
<property name="node.js.detected.package.eslint" value="true" />
<property name="node.js.detected.package.standard" value="true" />
<property name="node.js.detected.package.tslint" value="true" />
<property name="node.js.path.for.package.eslint" value="project" />
<property name="node.js.path.for.package.standard" value="project" />
<property name="node.js.path.for.package.tslint" value="project" />
<property name="node.js.selected.package.eslint" value="(autodetect)" />
<property name="node.js.selected.package.standard" value="" />
<property name="node.js.selected.package.tslint" value="$PROJECT_DIR$/server/node_modules/tslint" />
<property name="nodejs_package_manager_path" value="npm" />
<property name="settings.editor.selected.configurable" value="preferences.keymap" />
<property name="ts.external.directory.path" value="$PROJECT_DIR$/server/node_modules/typescript/lib" />
</component>
<component name="RecentsManager">
<key name="MoveFile.RECENT_KEYS">
<recent name="$PROJECT_DIR$" />
</key>
<key name="CopyFile.RECENT_KEYS">
<recent name="$PROJECT_DIR$/server/src/config" />
<recent name="$PROJECT_DIR$/client/src/interface" />
<recent name="$PROJECT_DIR$" />
<recent name="$PROJECT_DIR$/server" />
<recent name="$PROJECT_DIR$/database" />
</key>
</component>
<component name="SvnConfiguration">
<configuration />
</component>
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="f9039135-aa11-4abd-ad74-f40c84e4fdb2" name="Default Changelist" comment="" />
<created>1586870120922</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1586870120922</updated>
<workItem from="1586870126995" duration="5800000" />
<workItem from="1587201178537" duration="25531000" />
<workItem from="1587993480577" duration="4978000" />
<workItem from="1588119564722" duration="238000" />
<workItem from="1588166446649" duration="17000" />
<workItem from="1588166552136" duration="2062000" />
<workItem from="1588168659920" duration="21070000" />
<workItem from="1589475961634" duration="559000" />
<workItem from="1589732800789" duration="13203000" />
<workItem from="1590767628109" duration="39193000" />
<workItem from="1593066389745" duration="11136000" />
<workItem from="1593700616662" duration="8522000" />
<workItem from="1594050477603" duration="547000" />
<workItem from="1594228393975" duration="3051000" />
<workItem from="1598164265688" duration="598000" />
<workItem from="1598166189685" duration="679000" />
<workItem from="1598174892065" duration="407000" />
<workItem from="1599396370958" duration="518000" />
<workItem from="1599739988741" duration="1817000" />
<workItem from="1599904748126" duration="799000" />
<workItem from="1599912369521" duration="681000" />
<workItem from="1616871635424" duration="5010000" />
<workItem from="1616902156349" duration="4139000" />
<workItem from="1616907672434" duration="3493000" />
<workItem from="1616912343465" duration="84000" />
<workItem from="1616914665901" duration="956000" />
<workItem from="1618503206086" duration="6965000" />
<workItem from="1619847843794" duration="477000" />
<workItem from="1619848446975" duration="298000" />
<workItem from="1619848860699" duration="11720000" />
<workItem from="1622876620759" duration="234000" />
<workItem from="1625991704189" duration="1640000" />
<workItem from="1626598050251" duration="1027000" />
<workItem from="1628481482390" duration="13548000" />
<workItem from="1628783520074" duration="2544000" />
<workItem from="1629517950448" duration="175000" />
<workItem from="1629903360315" duration="5734000" />
<workItem from="1647001315115" duration="2876000" />
<workItem from="1665892838491" duration="5253000" />
</task>
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="2" />
</component>
<component name="Vcs.Log.History.Properties">
<option name="COLUMN_ORDER">
<list>
<option value="0" />
<option value="2" />
<option value="3" />
<option value="1" />
</list>
</option>
</component>
<component name="Vcs.Log.Tabs.Properties">
<option name="TAB_STATES">
<map>
<entry key="MAIN">
<value>
<State>
<option name="FILTERS">
<map>
<entry key="branch">
<value>
<list>
<option value="master" />
</list>
</value>
</entry>
</map>
</option>
</State>
</value>
</entry>
</map>
</option>
<option name="oldMeFiltersMigrated" value="true" />
</component>
<component name="WindowStateProjectService">
<state x="100" y="100" width="1240" height="700" key="DiffContextDialog" timestamp="1647002209329">
<screen x="0" y="0" width="1440" height="900" />
</state>
<state x="100" y="100" width="1240" height="700" key="DiffContextDialog/0.0.1440.900@0.0.1440.900" timestamp="1647002209329" />
<state x="528" y="156" key="RollbackChangesDialog" timestamp="1647068368012">
<screen x="0" y="0" width="1440" height="900" />
</state>
<state x="528" y="156" key="RollbackChangesDialog/0.0.1440.900@0.0.1440.900" timestamp="1647068368012" />
<state x="100" y="100" width="1240" height="700" key="com.intellij.history.integration.ui.views.FileHistoryDialog" timestamp="1647068977589">
<screen x="0" y="25" width="1440" height="814" />
</state>
<state x="100" y="100" width="1240" height="700" key="com.intellij.history.integration.ui.views.FileHistoryDialog/0.25.1440.814@0.25.1440.814" timestamp="1647068977589" />
<state x="385" y="196" width="670" height="676" key="search.everywhere.popup" timestamp="1647067452212">
<screen x="0" y="0" width="1440" height="900" />
</state>
<state x="385" y="196" width="670" height="676" key="search.everywhere.popup/0.0.1440.900@0.0.1440.900" timestamp="1647067452212" />
</component>
</project>
+13
View File
@@ -1,3 +1,16 @@
export interface IGameRecord {
gameId: number;
}
export interface ICommandRecord {
roomNumber: string;
gameId: number;
userId: string;
type: string;
pot: number;
commonCard: string;
handCard?: string;
gameStatus: number;
command: string;
counter: number;
}
+2 -1
View File
@@ -5,7 +5,7 @@ import Login from '../views/login.vue';
import Register from '../views/register.vue';
import Game from '../views/game.vue';
import service from '../service';
import origin from '../utils/origin';
import cookie from 'js-cookie';
Vue.use(VueRouter);
@@ -58,6 +58,7 @@ router.beforeEach(async (to, from, next) => {
try {
const result = await service.checkLogin();
console.log(result);
cookie.set('user_id', result.data.userId);
next();
} catch (e) {
await router.replace({ name: 'login' });
+4
View File
@@ -33,4 +33,8 @@ export default {
url: '/game/record/find/gameRecord',
body: { roomNumber },
}),
selfPast7DayGame: (userID: number) => request({
url: '/game/record/find/selfPast7DayGame',
body: { userID },
}),
};
+2 -4
View File
@@ -306,8 +306,7 @@
const sit = [];
for (let i = 0; i < 9; i++) {
sit.push(node.node);
const next = node.next;
node = next;
node = node.next;
}
return sit;
}
@@ -526,7 +525,7 @@
}
private closeAudio() {
this.audioStatus = !this.audioStatus
this.audioStatus = !this.audioStatus;
}
private play() {
@@ -594,7 +593,6 @@
this.$plugin.toast('can\'t find the room');
}
}
private created() {
try {
this.socketInit();
+23 -1
View File
@@ -32,6 +32,9 @@
<div class="btn"
@click="getRecord(0)"><span>test record</span>
</div>
<div class="btn" @click="selfPast7DayGame()">
<span>7 day game history</span>
</div>
</div>
<div class="room-number"
v-show="isJoin">
@@ -65,7 +68,7 @@
import gameRecord from '@/components/GameRecord.vue';
import service from '../service';
import cookie from 'js-cookie';
import {IGameRecord} from '@/interface/IGameRecord';
import { IGameRecord } from '@/interface/IGameRecord';
@Component({
components: {
@@ -128,6 +131,25 @@
}
}
private async selfPast7DayGame() {
try {
const userIDStr = cookie.get('user_id');
if (userIDStr) {
const userID = Number(userIDStr);
const {data} = await service.selfPast7DayGame(userID);
data.forEach((v: IGameRecord) => {
this.gameList.push({ gameId: v.gameId});
});
this.currGameIndex = data.length;
this.commandList = data[data.length - 1].gameCommandList;
this.showRecord = true;
}
} catch (e) {
console.log(e);
this.$plugin.toast('can\'t find the user command record list');
}
}
private async getRecord(index: number) {
try {
console.log('ccc');
+1 -1
View File
@@ -43,7 +43,7 @@
try {
const result = await service.login(this.userAccount, this.password);
const { token } = result.data;
cookie.set('token', token, {expires: 1});
cookie.set('token', token, { expires: 1 });
localStorage.setItem('token', token);
await this.$router.push({name: 'home'});
} catch (e) {
+46 -1
View File
@@ -35,7 +35,7 @@ export class GameRecordController extends BaseController {
try {
const { body } = this.getRequestBody();
const state = this.ctx.state;
const commandList = await this.commandService.findByRoomNumber(body.gameId);
const commandList = await this.commandService.findByGameID(body.gameId);
const gameList = await this.gameService.findByRoomNumber(body.roomNumber);
let result: IFindGameRecord;
console.log(state, 'user');
@@ -65,6 +65,51 @@ export class GameRecordController extends BaseController {
}
}
@post('/find/selfPast7DayGame')
async selfPast7DayGame() {
try {
const { body } = this.getRequestBody();
const gameIDList = await this.commandService.findPast7DayGameIDsByUserID(body.userID);
if (!gameIDList.length) {
this.success([]);
return;
}
const gameList = await this.gameService.findByIDs(gameIDList);
const commandList = await this.commandService.findByGameIDs(gameIDList);
const result: any = [];
gameList.forEach(g => {
if (g.status === EGameOverType.GAME_OVER) {
const winner = JSON.parse(g.winners || '')[0][0];
delete winner.handCard;
g.winners = JSON.stringify([[ winner ]]);
}
const gameCommandList = commandList.filter(c => {
return c.gameId === g.id;
});
// 过滤其他人手牌
gameCommandList.forEach(c => {
if (c.userId !== this.ctx.state.user.user.userId) {
c.handCard = '';
}
});
result.push({
gameCommandList,
winners: g.winners,
gameId: g.id,
});
});
this.success(result);
} catch (e) {
this.fail('find self command record error');
console.log(e);
}
}
@post('/find/gameRecord')
async index() {
try {
+1
View File
@@ -81,6 +81,7 @@ export default (appInfo: EggAppInfo) => {
redis: {
host: '127.0.0.1',
port: 6379,
password: '123456',
},
};
+3 -3
View File
@@ -1,4 +1,3 @@
export interface ICommandRecord {
roomNumber: string;
gameId: number;
@@ -13,7 +12,8 @@ export interface ICommandRecord {
}
export interface ICommandRecordService {
findById(gid: number): Promise<ICommandRecord>;
findByRoomNumber(gameId: number): Promise<ICommandRecord[]>;
findByGameID(gameID: number): Promise<ICommandRecord[]>;
findByGameIDs(gameIDs: number[]): Promise<ICommandRecord[]>;
add(commandRecord: ICommandRecord): Promise<any>;
findPast7DayGameIDsByUserID(userID: number): Promise<number []>;
}
+2 -1
View File
@@ -9,7 +9,8 @@ export interface IGame {
}
export interface IGameService {
findById(gid: number): Promise<IGame>;
findByID(gid: number): Promise<IGame>;
findByIDs(ids: number[]): Promise<IGame []>;
findByRoomNumber(roomNumber: number): Promise<IGame []>;
add(game: IGame): Promise<any>;
update(game: IGame): Promise<any>;
+1 -1
View File
@@ -2,5 +2,5 @@ export interface IUser {
nickName: string;
account: string;
password?: string;
id?: string;
id?: number;
}
+24 -4
View File
@@ -20,11 +20,31 @@ export class CommandRecord implements ICommandRecordService {
return { succeed: result.affectedRows === 1 };
}
async findById(gid: number): Promise<ICommandRecord> {
return await this.mysql.get('game_record', { id: gid });
async findPast7DayGameIDsByUserID(userID: number): Promise<number[]> {
const result = await this.mysql.query('SELECT\n' +
'DISTINCT gameId\n' +
'FROM command_record\n' +
'WHERE userId = ?\n' +
'AND create_time >= DATE_SUB(now(),interval 7 DAY)', [ userID ]);
const recordList = JSON.parse(JSON.stringify(result));
if (recordList) {
return recordList.map((item: ICommandRecord) => {
return item.gameId;
});
}
return [];
}
async findByRoomNumber(gameId: number): Promise<ICommandRecord []> {
async findByGameIDs(gameIDs: number[]): Promise<ICommandRecord []> {
const result = await this.mysql.select('command_record', {
where: {
gameId: gameIDs,
},
});
return JSON.parse(JSON.stringify(result));
}
async findByGameID(gameID: number): Promise<ICommandRecord []> {
const result = await this.mysql.query('SELECT\n' +
'\tcommand_record.counter,\n' +
'\tcommand_record.gameStatus,\n' +
@@ -39,7 +59,7 @@ export class CommandRecord implements ICommandRecordService {
'\tcommand_record\n' +
'INNER JOIN `user` ON `user`.id = command_record.userId\n' +
'INNER JOIN player ON player.userId = command_record.userId\n' +
'\twhere command_record.gameId = ? and player.gameId = ?', [ gameId, gameId ]);
'\twhere command_record.gameId = ? and player.gameId = ?', [ gameID, gameID ]);
console.log(result, '=============command');
return JSON.parse(JSON.stringify(result));
}
+7 -1
View File
@@ -27,10 +27,16 @@ export class GameService implements IGameService {
return { succeed: gameInfo.affectedRows === 1 };
}
async findById(gid: number): Promise<IGame> {
async findByID(gid: number): Promise<IGame> {
return await this.mysql.get('game', { id: gid });
}
async findByIDs(ids: number[]): Promise<IGame[]> {
return await this.mysql.select('game', {
where: { id: ids },
});
}
async findByRoomNumber(roomNumber: number): Promise<IGame []> {
const result = await this.mysql.select('game', {
where: { roomNumber },