From 738758d7534e0308fcb708e7c83559ddaa2d26c7 Mon Sep 17 00:00:00 2001 From: hide_d Date: Sat, 21 Aug 2021 20:38:15 +0900 Subject: [PATCH] js2ts: betting --- hwe/b_betting.php | 7 +++---- hwe/ts/betting.ts | 47 +++++++++++++++++++++++++++++++++++++++++++++++ webpack.config.js | 1 + 3 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 hwe/ts/betting.ts diff --git a/hwe/b_betting.php b/hwe/b_betting.php index f0a46032..e4e347a1 100644 --- a/hwe/b_betting.php +++ b/hwe/b_betting.php @@ -65,7 +65,6 @@ if($str3){ <?=UniqueConst::$serverName?>: 베팅장 - @@ -311,7 +310,7 @@ for ($i=0; $i < 16; $i++) { else{ $gold[$i] = Util::round($myBet[$i] * $bet[$i]); } - + } ?> @@ -446,8 +445,8 @@ foreach($tournamentType as $tournamentTypeText=>[$statTypeText,$statFunc,$rankCo $result = -($lhs->getRankVar($gameColumn) <=> $rhs->getRankVar($gameColumn)); if($result !== 0) return $result; $result = -( - ($lhs->getRankVar($winColumn)+$lhs->getRankVar($drawColumn)+$lhs->getRankVar($loseColumn)) - <=> + ($lhs->getRankVar($winColumn)+$lhs->getRankVar($drawColumn)+$lhs->getRankVar($loseColumn)) + <=> ($rhs->getRankVar($winColumn)+$rhs->getRankVar($drawColumn)+$rhs->getRankVar($loseColumn)) ); if($result !== 0) return $result; diff --git a/hwe/ts/betting.ts b/hwe/ts/betting.ts new file mode 100644 index 00000000..8a27a581 --- /dev/null +++ b/hwe/ts/betting.ts @@ -0,0 +1,47 @@ +import $ from 'jquery'; +import axios from 'axios'; +import { setAxiosXMLHttpRequest } from './util/setAxiosXMLHttpRequest'; +import { InvalidResponse } from './defs'; +import { convertFormData } from './util/convertFormData'; +import { unwrap_any } from './util/unwrap_any'; + +$(function($){ + setAxiosXMLHttpRequest(); + + $('.submitBtn').on('click', async function(e){ + e.preventDefault(); + + const $this = $(this); + const target = parseInt($this.data('target')); + const amount = parseInt(unwrap_any($(`#target_${target}`).val())); + + let result: InvalidResponse; + + try{ + const response = await axios({ + url: 'j_betting.php', + responseType: 'json', + method: 'post', + data: convertFormData({ + target: target, + amount: amount + }) + }); + result = response.data; + }catch(e){ + console.error(e); + alert(`에러: ${e}`); + location.reload(); + return; + } + + if(!result.result){ + alert(`베팅을 실패했습니다: ${result.reason}`); + location.reload(); + return; + } + + location.reload(); + return; + }); +}); \ No newline at end of file diff --git a/webpack.config.js b/webpack.config.js index 94502b90..8a912a8e 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -20,6 +20,7 @@ module.exports = [ recent_map: './hwe/ts/recent_map.ts', processing: './hwe/ts/processing.ts', select_npc: './hwe/ts/select_npc.ts', + betting: './hwe/ts/betting.ts', //FORM 입력용, frontend 변경후 제거