1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339
| <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width,initial-scale=1.0, user-scalable=no"> <script src="js.package/vue.js"></script> <script src="https://unpkg.com/element-ui@2.15.7/lib/index.js"></script> <link rel="stylesheet" href="https://unpkg.com/element-ui@2.15.7/lib/theme-chalk/index.css"> <link rel="shortcut icon" type="image/x-icon" href="pic/monster/jsz.webp"> <title>巴西eshop余额清零计算器</title> </head> <style> ... </style> <body id="box"> <div id="app"> <div id="title">
</div> <div id=top> <div id="left"></div> <div id="cen"> <div class="goods"> <div v-for="(good, index) in goods" :key="index" class="input-box"> <div class="input-box"> <p class="p-class"><i class="el-icon-s-goods"></i> 游戏{{index + 1}}价格(BRL):</p> <el-input class="input-class" class="top-in" v-model="good.price" oninput="value=value.replace(/[^\d\.]/g,'')" maxLength='9' placeholder="请输入" :disabled="good.init"></el-input> </div> <div> <el-button class="clear" type="warning" plain @click="resetOne" v-if="good.clear"><i class="el-icon-delete"></i> 清除</el-button> </div> </div> </div> <div id="inits"> <div id="balance" class="input-box"> <p class="p-class"><i class="el-icon-bank-card"></i> 余额(BRL):</p> <el-input class="input-class-last" v-model="balance" oninput="value=value.replace(/[^\d\.]/g,'')" maxLength='9' placeholder="请输入初始余额" :disabled="init"></el-input> </div> <div id="coin" class="input-box"> <p class="p-class"><i class="el-icon-coin"></i> 金币:</p> <el-input class="input-class-last" v-model="coin" oninput="value=value.replace(/[^\d]/g,'')" maxLength='9' placeholder="请输入初始金币数" :disabled="init"></el-input> </div> </div> </div> <div id="right"></div> </div> <div id=mid> <p v-if="msg0">可购买价格区间 {{balance}}~{{realBalance}} (BRL) 的游戏</p> <p v-if="msg1">余额不足!</p> <p v-if="msg2" class="msg2"> *** 恭喜余额已清零! *** </p> </div> <div id=bot> <el-button type="danger" plain @click="resetAll"><i class="el-icon-refresh-left"></i> 全部重置</el-button> <el-button type="primary" plain @click="startBuy" :disabled="cannotBuy"><i class="el-icon-shopping-cart-2"></i> {{start}}</el-button> </div> <div id="explain"> <el-card class="box-card"> <div slot="header" class="clearfix"> <span><h3>使用说明</h3></span> <el-button style="float: right; padding: 3px 0" type="text"></el-button> </div> <div class="text item"> - 本页面所有货币单位均为巴西雷亚尔(BRL) </div> <div class="text item"> - 输入eshop余额与金币数量,点击“开始”按钮开始 </div> <div class="text item"> - 依次输入想要购买的游戏价格,并点击“购买”,将自动计算余额与金币数 </div> <div class="text item"> - 每次购买遵循:优先使用余额,不足部分使用金币补齐,1金币=0.05BRL </div> <div class="text item"> - 可点击“清除”,撤销上一次购买 </div> <div class="text item"> - 当余额为0时计算结束 </div> <div class="text item"> - 点击“全部重置”删除所有记录 </div>
<div class="text item"> - 联系我:<a href="mailto:thbb268@live.com">thbb268@live.com</a> </div>
</el-card> </div> </div> </body> <script> var floatObj = function () {
function isInteger(obj) { return Math.floor(obj) === obj }
function toInteger(floatNum) { var ret = {times: 1, num: 0}; if (isInteger(floatNum)) { ret.num = floatNum; return ret } var strfi = floatNum + ''; var dotPos = strfi.indexOf('.'); var len = strfi.substr(dotPos + 1).length; var times = Math.pow(10, len); var intNum = parseInt(floatNum * times + 0.5, 10); ret.times = times; ret.num = intNum; return ret }
function operation(a, b, op) { var o1 = toInteger(a); var o2 = toInteger(b); var n1 = o1.num; var n2 = o2.num; var t1 = o1.times; var t2 = o2.times; var max = t1 > t2 ? t1 : t2; var result = null; switch (op) { case 'add': if (t1 === t2) { result = n1 + n2 } else if (t1 > t2) { result = n1 + n2 * (t1 / t2) } else { result = n1 * (t2 / t1) + n2 } return result / max; case 'subtract': if (t1 === t2) { result = n1 - n2 } else if (t1 > t2) { result = n1 - n2 * (t1 / t2) } else { result = n1 * (t2 / t1) - n2 } return result / max; case 'multiply': result = (n1 * n2) / (t1 * t2); return result; case 'divide': result = (n1 / n2) * (t2 / t1); return result } } function add(a, b) { return operation(a, b, 'add') } function subtract(a, b) { return operation(a, b, 'subtract') } function multiply(a, b) { return operation(a, b, 'multiply') } function divide(a, b) { return operation(a, b, 'divide') } return { add: add, subtract: subtract, multiply: multiply, divide: divide } }(); const rate = 0.05
const initData = { start: '开始', balance: '', coin: '', goods: [], realBalance: '', msg0: false, msg1: false, msg2: false, records: [], init: false, cannotBuy: false } function calRealBalance(balance, coin) { var coinPrice = floatObj.multiply(coin, rate) return floatObj.add(balance, coinPrice) } function getCoin(price) { var temp = Math.floor(price) if (temp == price) { return temp } return temp + 1 } var vm = new Vue({ el: '#app', data: JSON.parse(JSON.stringify(initData)), methods: { startBuy: function() { this.start = '购买' this.init = true this.goods.push({price: '', init: false, clear: false}) var currentIndex = this.goods.length - 1 this.records.push({index: currentIndex, balance: this.balance, coin: this.coin}) if (currentIndex > 0) { var goodIndex = currentIndex - 1 var goodPrice = this.goods[goodIndex].price if (!goodPrice) { this.goods.pop() this.records.pop() this.$message({ message: '请输入游戏价格!', type: 'warning' }) return } var goodCoin = getCoin(goodPrice) var tempBalance = floatObj.subtract(this.balance, goodPrice) if (tempBalance < 0) { tempBalance = floatObj.subtract(goodPrice, this.balance) var needCoin = floatObj.divide(tempBalance, rate) needCoin = getCoin(needCoin) if (needCoin > this.coin) {
this.goods.pop() this.records.pop() this.$message({ message: '余额不足!', type: 'warning' }) return } else { var coinPrice = floatObj.multiply(needCoin, rate) var needBalance = floatObj.subtract(goodPrice, coinPrice) if (needBalance > 0) { this.balance = floatObj.subtract(this.balance, needBalance) } else { needBalance = 0 } this.coin = floatObj.subtract(this.coin, needCoin) goodCoin = getCoin(needBalance) this.coin = floatObj.add(this.coin, goodCoin) this.goods[goodIndex].init = true this.goods[goodIndex].clear = true if (goodIndex > 0) { this.goods[goodIndex-1].clear = false } } } else { this.balance = tempBalance this.coin = floatObj.add(this.coin, goodCoin) this.goods[goodIndex].init = true this.goods[goodIndex].clear = true if (goodIndex > 0) { this.goods[goodIndex-1].clear = false } } } if (this.balance == 0) { this.msg2 = true this.cannotBuy = true this.$message({ message: '恭喜你,余额已清零!', type: 'success' }) } this.realBalance = calRealBalance(this.balance, this.coin) this.msg0 = true }, resetAll: function() { const temp = JSON.parse(JSON.stringify(initData)); Object.assign(this.$data, temp); }, resetOne: function() { this.goods.pop() this.goods.pop() this.goods.push({price: '', init: false, clear: false}) var currentIndex = this.goods.length - 1 if (currentIndex > 0) { this.goods[currentIndex-1].clear = true } var record = this.records.pop() this.balance = record.balance this.coin = record.coin this.realBalance = calRealBalance(this.balance, this.coin) this.msg2 = false this.cannotBuy = false } } }) </script> </html>
|