将上报游戏结果的接口统一到webapi中
This commit is contained in:
parent
17ea5b847e
commit
a577f28ceb
@ -1,5 +1,6 @@
|
||||
import axios from "axios";
|
||||
import {Config} from "../cfg/Config";
|
||||
import {debugRoom, error} from "./Debug";
|
||||
|
||||
let config: Config = require('../../config/config.json');
|
||||
|
||||
@ -33,4 +34,30 @@ export function requestUnlockHero(accountid: string, heroid: number | string) {
|
||||
return axios.post(`${config.info_svr}/${accountid}/hero/unlock/${heroid}`, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上报游戏结果
|
||||
* @param data
|
||||
*/
|
||||
export function reportGameResult(data: any) {
|
||||
let dataStr = JSON.stringify(data);
|
||||
|
||||
let reqConfig = {
|
||||
method: 'post',
|
||||
url: `${config.info_svr}/record/save`,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
data : dataStr
|
||||
};
|
||||
|
||||
// @ts-ignore
|
||||
axios(reqConfig)
|
||||
.then(function (response) {
|
||||
debugRoom(JSON.stringify(response.data));
|
||||
})
|
||||
.catch(function (err) {
|
||||
error(err);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
@ -9,11 +9,9 @@ import gameUtil from "../../utils/game.util";
|
||||
import {Card} from "../schema/Card";
|
||||
import {MapSchema, SetSchema} from "@colyseus/schema";
|
||||
import {StateTypeEnum} from "../enums/StateTypeEnum";
|
||||
import axios from "axios";
|
||||
import {Config} from "../../cfg/Config";
|
||||
import {reportGameResult} from "../../common/WebApi";
|
||||
|
||||
|
||||
let config: Config = require('../../../config/config.json');
|
||||
/**
|
||||
* 游戏结束
|
||||
*/
|
||||
@ -207,25 +205,7 @@ export class GameResultCommand extends Command<CardGameState, {}> {
|
||||
});
|
||||
}
|
||||
data.players = players;
|
||||
let dataStr = JSON.stringify(data);
|
||||
|
||||
let reqConfig = {
|
||||
method: 'post',
|
||||
url: `${config.info_svr}/record/save`,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
data : dataStr
|
||||
};
|
||||
|
||||
// @ts-ignore
|
||||
axios(reqConfig)
|
||||
.then(function (response) {
|
||||
debugRoom(JSON.stringify(response.data));
|
||||
})
|
||||
.catch(function (err) {
|
||||
error(err);
|
||||
});
|
||||
reportGameResult(data);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user