How to use formatArray method in Cypress

Best JavaScript code snippet using cypress

accountant.js

Source:accountant.js Github

copy

Full Screen

1/**2 * 排序數字(避免1, 10, 2...等排列)3 * @param {*} first 第一位數4 * @param {*} second 第二位數5 */6function sortNumber(first, second) {7 return first - second;8}9/**10 * ˊ陣列不重複排列組合11 * @param {*} arr 一維陣列12 * @param {*} size 排列個數13 */14function getArrange(arr, size) {15 const result = [];16 function createTree(rootArr, remainArr, sizeCount) {17 if (remainArr.length <= 0 || sizeCount === 0) {18 result.push(rootArr);19 return;20 }21 for (let i = 0; i <= remainArr.length - sizeCount; i += 1) {22 const root = remainArr[i];23 const other = remainArr.slice(i + 1);24 createTree(rootArr.concat(root), other, sizeCount - 1);25 }26 }27 createTree([], arr, size);28 return result;29}30/**31 * 判斷文字為空32 * @param {需判斷文字} str33 */34function isEmpty(str) {35 return (!str || str.length === 0);36}37/**38 * 兩個陣列不重複排列組合39 */40function twoArrayCombinate(firstArray, secondArray) {41 const result = [];42 firstArray.forEach((number) => {43 const filteredItems = secondArray.filter(item => item !== number);44 filteredItems.forEach((item) => {45 result.push(`${number} ${item}`);46 });47 });48 return result;49}50/**51 * 三陣列不重複排列組合52 * @param {*} firstArray53 * @param {*} secondArray54 * @param {*} thirdArray55 */56function threeArrayCombinate(firstArray, secondArray, thirdArray) {57 const result = [];58 const conbinateArray = twoArrayCombinate(firstArray, secondArray);59 conbinateArray.forEach((number) => {60 const filteredItems = thirdArray.filter(item => !number.split(' ').includes(item));61 filteredItems.forEach((item) => {62 result.push(`${number} ${item}`);63 });64 });65 return result;66}67/**68 * 彩種類型69 */70const LotteryClassType = Object.freeze({71 TYPE_SSC: 1,72 TYPE_11X5: 2,73 TYPE_3D: 3,74 TYPE_HK6: 4,75 TYPE_K3: 5,76 TYPE_PCEGG: 6,77 TYPE_PK10: 10,78});79/**80 * 一般彩種投注計算81 */82export const lotteryService = {83 makeBetItem(gameId, bet, amount) {84 return {85 id: gameId,86 name: bet,87 amount,88 };89 },90 /**91 * 重組投注內容92 * @param {*} lotteryClassId 彩種類型ID93 * @param {*} playName 玩法名稱94 * @param {*} playMatchType 玩法類型95 * @param {*} playDigitPanel 玩法位數96 * @param {*} betNumber 投注內容97 * @param {*} selectedRegex 投注內容驗證格式98 */99 formatBetContent(lotteryClassId, betTypeId, playId, playName, playMatchType, playDigitPanel, selectedRegex,100 betUnitAmount, betContent) {101 const formatArray = {102 status: false,103 message: '',104 betCount: 0,105 betTotalAmount: 0,106 betContent: [],107 postContent: '',108 };109 if (playMatchType === '单式' || playMatchType === '混合') {110 if (betContent.trim().length === 0) {111 formatArray.message = '号码输入不为空!';112 return formatArray;113 }114 const strs = betContent.split(/[\s,;\n]+/);115 const arr = [];116 let tmp = '';117 for (let i = 0; i < strs.length; i += 1) {118 if (playMatchType === '混合' && (strs[i] = strs[i].sortAsc()), tmp = strs[i], !eval(`/^${selectedRegex}$/`).test(tmp)) {119 formatArray.message = `第${i + 1}个号码[${tmp}]输入格式错误!`;120 return formatArray;121 }122 let number = '';123 for (let j = 0; j < tmp.length; j += 1) {124 number += tmp[j];125 }126 arr[i] = number;127 }128 formatArray.status = true;129 formatArray.betCount = arr.length;130 formatArray.betUnitAmount = betUnitAmount;131 formatArray.betTotalAmount = parseFloat(betUnitAmount) * arr.length;132 formatArray.betContent = arr;133 formatArray.postContent = JSON.stringify({134 rule_id: playId,135 bet_type_id: betTypeId,136 bet_total_count: arr.length,137 unit_price: betUnitAmount,138 bet_content: arr.join('|'),139 });140 return formatArray;141 }142 let count = 0;143 Object.keys(betContent).forEach((item) => {144 if (betContent[item] !== undefined) {145 count += betContent[item].length;146 }147 });148 if (betContent === undefined || count <= 0) {149 formatArray.message = '号码输入不为空!';150 return formatArray;151 }152 const validationResult = this.validateBetContent(lotteryClassId, playMatchType, playDigitPanel, playName, betContent);153 if (!validationResult.status) {154 formatArray.message = validationResult.message;155 return formatArray;156 }157 let formatNumber = [];158 let postContent = '';159 switch (playMatchType) {160 case '斗牛':161 formatNumber = playName === '牛牛' ? betContent.niuniu : playName === '斗牛大小单双' ? betContent.niuBigOrSmall : '';162 postContent = formatNumber.join('|');163 break;164 case '龙虎':165 formatNumber = betContent.dragonTiger;166 postContent = formatNumber.join('|');167 break;168 default:169 let combinatedNumber = '';170 if (playMatchType === '定位胆') {171 let tenThousand = '';172 let thousand = '';173 let hundred = '';174 let ten = '';175 let unit = '';176 if (betContent.tenThousand !== undefined && betContent.tenThousand.length > 0) {177 tenThousand = ` ${betContent.tenThousand.sort().join(' ')}`;178 }179 if (betContent.thousand !== undefined && betContent.thousand.length > 0) {180 thousand = ` ${betContent.thousand.sort().join(' ')}`;181 }182 if (betContent.hundred !== undefined && betContent.hundred.length > 0) {183 hundred = ` ${betContent.hundred.sort().join(' ')}`;184 }185 if (betContent.ten !== undefined && betContent.ten.length > 0) {186 ten = ` ${betContent.ten.sort().join(' ')}`;187 }188 if (betContent.unit !== undefined && betContent.unit.length > 0) {189 unit = ` ${betContent.unit.sort().join(' ')}`;190 }191 combinatedNumber = `${tenThousand},${thousand},${hundred},${ten},${unit}`;192 formatNumber.push(combinatedNumber);193 postContent = combinatedNumber;194 } else {195 if (playDigitPanel.includes('0')) {196 combinatedNumber = `${betContent.tenThousand.sort().join(' ')}`;197 }198 if (playDigitPanel.includes('1')) {199 if (combinatedNumber) {200 combinatedNumber = `${combinatedNumber},${betContent.thousand.sort().join(' ')}`;201 } else {202 combinatedNumber = `${betContent.thousand.sort().join(' ')}`;203 }204 }205 if (playDigitPanel.includes('2')) {206 if (combinatedNumber) {207 combinatedNumber = `${combinatedNumber},${betContent.hundred.sort().join(' ')}`;208 } else {209 combinatedNumber = `${betContent.hundred.sort().join(' ')}`;210 }211 }212 if (playDigitPanel.includes('3')) {213 if (combinatedNumber) {214 combinatedNumber = `${combinatedNumber},${betContent.ten.sort().join(' ')}`;215 } else {216 combinatedNumber = `${betContent.ten.sort().join(' ')}`;217 }218 }219 if (playDigitPanel.includes('4')) {220 if (combinatedNumber) {221 combinatedNumber = `${combinatedNumber},${betContent.unit.sort().join(' ')}`;222 } else {223 combinatedNumber = `${betContent.unit.sort().join(' ')}`;224 }225 }226 if (playDigitPanel.includes('5')) {227 combinatedNumber = `${betContent.group.sort().join(' ')}`;228 }229 if (playDigitPanel.includes('6')) {230 combinatedNumber = `${betContent.unfixed.sort().join(' ')}`;231 }232 formatNumber.push(combinatedNumber);233 postContent = ` ${formatNumber.join(' ')}`;234 }235 break;236 }237 const betCount = this.calculateBetCount(lotteryClassId, playMatchType, formatNumber);238 formatArray.status = true;239 formatArray.betUnitAmount = parseFloat(betUnitAmount);240 formatArray.betCount = betCount;241 formatArray.betTotalAmount = parseFloat(betUnitAmount) * betCount;242 formatArray.betContent = formatNumber;243 formatArray.postContent = JSON.stringify({244 rule_id: playId,245 bet_type_id: betTypeId,246 bet_total_count: betCount,247 unit_price: parseFloat(betUnitAmount),248 bet_content: postContent,249 });250 return formatArray;251 },252 /**253 * 檢查投注號碼254 * @param {彩種類型ID} lotteryClassId255 * @param {玩法類型} playMatchType256 * @param {玩法位數} playDigitPanel257 * @param {玩法名稱} playName258 * @param {投注內容} betContent259 */260 validateBetContent(lotteryClassId, playMatchType, playDigitPanel, playName, betContent) {261 const formatArray = {262 status: false,263 message: '',264 };265 if (betContent === undefined266 && betContent.tenThousand === undefined267 && betContent.thousand === undefined268 && betContent.hundred === undefined269 && betContent.ten === undefined270 && betContent.unit === undefined271 && betContent.group === undefined272 && betContent.unfixed === undefined273 && betContent.niuniu === undefined274 && betContent.niuBigOrSmall === undefined275 && betContent.dragonTiger === undefined) {276 formatArray.message = '请先选择号码!!';277 return formatArray;278 }279 if (playMatchType === '组六' && betContent.group.length < 3) {280 formatArray.message = '[组六]至少选择3位!';281 return formatArray;282 } if (playMatchType === '组二' && (betContent.group === undefined || betContent.group.length < 2)) {283 formatArray.message = '[组二]至少选择2位!';284 return formatArray;285 } if (playMatchType === '组三') {286 if (betContent.group === undefined) {287 formatArray.message = '[组选]请先选择号码';288 return formatArray;289 } if ((lotteryClassId === LotteryClassType.TYPE_SSC || lotteryClassId === LotteryClassType.TYPE_3D)290 && betContent.group.length < 2) {291 formatArray.message = '[组三]至少选择2位!';292 return formatArray;293 } if (betContent.group.length < 3) {294 formatArray.message = '[组三]至少选择3位!';295 return formatArray;296 }297 } else if (playMatchType !== '定位胆') {298 if (playDigitPanel.includes('0') && (betContent.tenThousand === undefined || betContent.tenThousand.length <= 0)) {299 formatArray.message = '万位号码选择不全!!';300 return formatArray;301 }302 if (playDigitPanel.includes('1') && (betContent.thousand === undefined || betContent.thousand.length <= 0)) {303 formatArray.message = '千位号码选择不全!!';304 return formatArray;305 }306 if (playDigitPanel.includes('2') && (betContent.hundred === undefined || betContent.hundred.length <= 0)) {307 formatArray.message = '百位号码选择不全!!';308 return formatArray;309 }310 if (playDigitPanel.includes('3') && (betContent.ten === undefined || betContent.ten.length <= 0)) {311 formatArray.message = '十位号码选择不全!!';312 return formatArray;313 }314 if (playDigitPanel.includes('4') && (betContent.unit === undefined || betContent.unit.length <= 0)) {315 formatArray.message = '个位号码选择不全!!';316 return formatArray;317 }318 if (playDigitPanel.includes('5') && (betContent.group === undefined || betContent.group.length <= 0)) {319 formatArray.message = '组选号码选择不全!!';320 return formatArray;321 }322 if (playDigitPanel.includes('6') && (betContent.unfixed === undefined || betContent.unfixed.length <= 0)) {323 formatArray.message = '不定位号码选择不全!!';324 return formatArray;325 }326 if (playDigitPanel.includes('7') && playName === '牛牛' && (betContent.niuniu === undefined || betContent.niuniu.length <= 0)) {327 formatArray.message = '牛牛号码选择不全!!';328 return formatArray;329 }330 if (playDigitPanel.includes('8') && playName === '斗牛大小单双' && (betContent.niuBigOrSmall === undefined || betContent.niuBigOrSmall.length <= 0)) {331 formatArray.message = '大小单双号码选择不全!!';332 return formatArray;333 }334 if (playDigitPanel.includes('9') && (betContent.dragonTiger === undefined || betContent.dragonTiger.length <= 0)) {335 formatArray.message = '龙虎和号码选择不全!!';336 return formatArray;337 }338 }339 formatArray.status = true;340 return formatArray;341 },342 /**343 * 計算投注注數344 * @param {*} lotteryClassId 彩種類型ID345 * @param {*} playMatchType 玩法類型346 * @param {*} betNumber 投注號碼347 */348 calculateBetCount(lotteryClassId, playMatchType, betNumber) {349 let count = 0;350 if (lotteryClassId === LotteryClassType.TYPE_SSC || lotteryClassId === LotteryClassType.TYPE_3D) {351 const numberArr = betNumber;352 const digitLength = numberArr[0].split(',');353 switch (playMatchType) {354 case '复式':355 count = digitLength[0].trim().split(/\s+/).length;356 for (let u = 1; u < digitLength.length; u += 1) {357 count *= digitLength[u].trim().split(/\s+/).length;358 }359 break;360 case '不定位':361 case '定位胆':362 for (let u = 0; u < digitLength.length; u += 1) {363 if (digitLength[u].trim().length > 0) {364 count += digitLength[u].trim().split(/\s+/).length;365 }366 }367 break;368 case '组六':369 count = this.computeCombinationsVariations(numberArr[0].trim().split(/\s+/).length, 6) / 6;370 break;371 case '组三':372 count = this.computeCombinationsVariations(numberArr[0].trim().split(/\s+/).length, 3) / 3;373 break;374 case '组二':375 count = this.computeCombinationsVariations(numberArr[0].trim().split(/\s+/).length, 2) / 2;376 break;377 case '混合':378 const { length } = numberArr[0].toArray().distinct().length;379 if (numberArr[0].length === 3) {380 if (length === 3) {381 count = 6;382 } else if (length === 2) {383 count = 3;384 } else if (length === 1) {385 count = 1;386 }387 } else if (numberArr[0].length === 2) {388 if (length === 2) {389 count = 2;390 } else if (length === 1) {391 count = 1;392 }393 }394 break;395 case '斗牛':396 case '龙虎':397 count = numberArr.length;398 break;399 default:400 break;401 }402 }403 if (lotteryClassId === LotteryClassType.TYPE_11X5) {404 const numberArr = betNumber[0].split(',');405 switch (playMatchType) {406 case '复式':407 if (numberArr.length === 1) {408 const r0 = numberArr[0].trim().split(/\s+/);409 count = 0;410 for (let x = 0; x < r0.length; x += 1) {411 count += 1;412 }413 }414 if (numberArr.length === 2) {415 const r0 = numberArr[0].trim().split(/\s+/);416 const r1 = numberArr[1].trim().split(/\s+/);417 count = 0;418 for (let x = 0; x < r0.length; x += 1) {419 for (let y = 0; y < r1.length; y += 1) {420 if (r0[x] !== r1[y]) {421 count += 1;422 }423 }424 }425 }426 if (numberArr.length === 3) {427 const r0 = numberArr[0].trim().split(/\s+/);428 const r1 = numberArr[1].trim().split(/\s+/);429 const r2 = numberArr[2].trim().split(/\s+/);430 count = 0;431 for (let x = 0; x < r0.length; x += 1) {432 for (let y = 0; y < r1.length; y += 1) {433 for (let z = 0; z < r2.length; z += 1) {434 if (r0[x] !== r1[y] && r0[x] !== r2[z] && r1[y] !== r2[z]) {435 count += 1;436 }437 }438 }439 }440 }441 break;442 case '单式':443 count = 1;444 break;445 case '不定位':446 case '定位胆':447 for (let u = 0; u < numberArr.length; u += 1) {448 if (numberArr[u].trim().length > 0) {449 count += numberArr[u].trim().split(/\s+/).length;450 }451 }452 break;453 case '组三':454 const r0 = numberArr[0].trim().split(/\s+/);455 const r1 = numberArr[0].trim().split(/\s+/);456 const r2 = numberArr[0].trim().split(/\s+/);457 count = 0;458 for (let x = 0; x < r0.length; x += 1) {459 for (let y = x; y < r1.length; y += 1) {460 for (let z = y; z < r2.length; z += 1) {461 if (r0[x] !== r1[y] && r0[x] !== r2[z] && r1[y] !== r2[z]) {462 count += 1;463 }464 }465 }466 }467 break;468 case '组二':469 const numberArr0 = numberArr[0].trim().split(/\s+/);470 const numberArr1 = numberArr[0].trim().split(/\s+/);471 count = 0;472 for (let x = 0; x < numberArr0.length; x += 1) {473 for (let y = x; y < numberArr1.length; y += 1) {474 if (numberArr0[x] !== numberArr1[y]) {475 count += 1;476 }477 }478 }479 break;480 case '混合':481 const { length } = numberArr[0].toArray().distinct().length;482 if (numberArr[0].length === 3) {483 if (length === 3) {484 count = 6;485 } else if (length === 2) {486 count = 3;487 } else if (length === 1) {488 count = 1;489 }490 } else if (numberArr[0].length === 2) {491 if (length === 2) {492 count = 2;493 } else if (length === 1) {494 count = 1;495 }496 }497 break;498 default:499 break;500 }501 }502 return count;503 },504 /**505 * 計算組選注數506 * @param {*} number 下注號碼507 * @param {*} type 組選類型508 */509 computeCombinationsVariations(number, type) {510 let count = 0;511 if (type === 6) {512 if (number < 3) {513 return 0;514 }515 for (let r = 1; r <= number - 2; r += 1) {516 count += this.getSum(r);517 }518 return count * 6;519 }520 if (type === 3) {521 if (number < 2) {522 return 0;523 }524 count = this.getSum(number - 1) * 6;525 } else if (type === 2) {526 if (number < 2) {527 return 0;528 }529 count = this.getSum(number - 1) * 2;530 } else {531 return 0;532 }533 return count;534 },535 getSum(length) {536 let count = 0;537 for (let index = 1; index <= length; index += 1) {538 count += index;539 }540 return count;541 },542};543/**544 * 快三玩法類型545 */546const K3BetType = Object.freeze({547 SUM: 0,548 TWO_IDENTICAL_SINGLE: 1,549 TWO_IDENTICAL_MULTIPLE: 2,550 TWO_DIFFERENT: 3,551 THREE_DIFFERENT: 4,552 THREE_IDENTICAL_SINGLE: 5,553 THREE_IDENTICAL_ALL: 6,554 THREE_CONTINUOUS_ALL: 7,555});556export const k3Service = {557 /**558 * 計算投注結果559 * 和值: [{id:0,name:號碼,amount:0},{id:0,name:號碼,amount:0},..]560 * 二不同號: [{id:3,name:號碼,amount:0},{id:0,name:號碼,amount:0},..]561 * 三不同號 [{id:4,name:號碼,amount:0},{id:0,name:號碼,amount:0},..]562 * 三同号通选: [{id:6,name:'同号通选',amount:0}]563 * 三连号通选:[{id:7,name:'连号通选',amount:0}]564 * 返回物件{ status: 狀態, message: 錯誤訊息, betCount:注數,565 * betTotalAmount:投注總額, betContent:投注內容, postContent:POST投注格式 }566 * @param {玩法類型ID} betTypeId567 * @param {投注內容} betContent : {id : int, name: name, amount: int}568 */569 formatBetContent(betTypeId, betContent) {570 let formatArray = { status: false, message: '' };571 if (betContent.length <= 0) {572 formatArray.message = '请选择号码!!';573 return formatArray;574 }575 switch (betTypeId) {576 case K3BetType.SUM:577 formatArray = this.getSum(betContent[0]);578 break;579 case K3BetType.TWO_IDENTICAL_SINGLE:580 formatArray = this.getTwoIdenticalSingle(betContent);581 break;582 case K3BetType.TWO_IDENTICAL_MULTIPLE:583 formatArray = this.getTwoIdenticalMultiple(betContent[0]);584 break;585 case K3BetType.TWO_DIFFERENT:586 formatArray = this.getTwoDifferent(betContent[0]);587 break;588 case K3BetType.THREE_DIFFERENT:589 formatArray = this.getThreeDifferent(betContent[0]);590 break;591 case K3BetType.THREE_IDENTICAL_SINGLE:592 formatArray = this.getThreeIdenticalSingle(betContent);593 break;594 case K3BetType.THREE_IDENTICAL_ALL:595 formatArray = this.getThreeIdenticalAll(betContent);596 break;597 case K3BetType.THREE_CONTINUOUS_ALL:598 formatArray = this.getThreeContinuousAll(betContent);599 break;600 default:601 break;602 }603 return formatArray;604 },605 /**606 * 計算和值注數607 * @param {和值玩法} betContent608 */609 getSum(betContent) {610 const formatArray = {611 status: false,612 message: '',613 betCount: 0,614 betTotalAmount: 0,615 betContent: [],616 postContent: '',617 };618 let totalAmount = 0;619 const content = [];620 betContent.forEach((number) => {621 totalAmount += parseInt(number.amount, Number);622 formatArray.betContent.push(`${number.name}:${number.amount}`);623 content.push(number.name);624 });625 if (totalAmount === 0) {626 formatArray.message = '投注发生错误,请重新投注!!';627 return formatArray;628 }629 formatArray.status = true;630 formatArray.betCount = betContent.length;631 formatArray.betTotalAmount = totalAmount;632 formatArray.postContent = `${content.join(' ')}`;633 return formatArray;634 },635 /**636 * 二同號單選637 * @param {和值玩法} betContent638 */639 getTwoIdenticalSingle(betContent) {640 const formatArray = {641 status: false,642 message: '',643 betCount: 0,644 betTotalAmount: 0,645 betContent: [],646 postContent: '',647 };648 if (betContent.length !== 2) {649 formatArray.message = '号码选择不足!!';650 return formatArray;651 }652 if (betContent[0].length <= 0 || betContent[1].length <= 0) {653 formatArray.message = '号码选择不足!!';654 return formatArray;655 }656 const content = [];657 const sameNumberArray = betContent[0];658 const diffNumberArray = betContent[1];659 sameNumberArray.forEach((sameNumber) => {660 diffNumberArray.forEach((diffNumber) => {661 if (sameNumber.name === diffNumber.name) {662 return;663 }664 content.push(`${sameNumber.name}${sameNumber.name}${diffNumber.name}`);665 });666 });667 if (content.length <= 0) {668 formatArray.message = '号码选择不足!!';669 return formatArray;670 }671 const betUnitAmount = parseInt(betContent[0][0].amount, Number);672 formatArray.status = true;673 formatArray.betCount = content.length;674 formatArray.betTotalAmount = betUnitAmount * content.length;675 formatArray.betContent = content;676 formatArray.postContent = `${content.join(' ')}`;677 return formatArray;678 },679 /**680 * 二同號複選681 * @param {和值玩法} betContent682 */683 getTwoIdenticalMultiple(betContent) {684 const formatArray = {685 status: false,686 message: '',687 betCount: 0,688 betTotalAmount: 0,689 betContent: [],690 postContent: '',691 };692 const uniqueBetContent = [...new Set(betContent)];693 if (betContent.length <= 0 || uniqueBetContent.length !== betContent.length) {694 formatArray.message = '投注发生错误,请重新投注!!';695 return formatArray;696 }697 const content = [];698 betContent.forEach((number) => {699 content.push(`${number.name}${number.name}*`);700 });701 const betUnitAmount = parseInt(betContent[0].amount, Number);702 formatArray.status = true;703 formatArray.betCount = content.length;704 formatArray.betTotalAmount = betUnitAmount * content.length;705 formatArray.betContent = content;706 formatArray.postContent = `${content.join(' ')}`;707 return formatArray;708 },709 /**710 * 二不同號玩法711 * @param {投注內容} betContent712 */713 getTwoDifferent(betContent) {714 const formatArray = {715 status: false,716 message: '',717 betCount: 0,718 betTotalAmount: 0,719 betContent: [],720 postContent: '',721 };722 if (betContent.length < 2) {723 formatArray.message = '号码不足2位!!';724 return formatArray;725 }726 const uniqueBetContent = [...new Set(betContent)];727 if (betContent.length <= 0 || uniqueBetContent.length !== betContent.length) {728 formatArray.message = '投注发生错误,请重新投注!!';729 return formatArray;730 }731 const content = [];732 betContent.forEach((number) => {733 content.push(number.name);734 });735 let combinatedNumber = [];736 combinatedNumber = getArrange(content, 2);737 const betUnitAmount = parseInt(betContent[0].amount, Number);738 formatArray.status = true;739 formatArray.betCount = combinatedNumber.length;740 formatArray.betTotalAmount = betUnitAmount * combinatedNumber.length;741 formatArray.betContent = combinatedNumber;742 formatArray.postContent = `${content.join(' ')}`;743 return formatArray;744 },745 /**746 * 三不同號玩法747 * @param {投注內容} betContent748 */749 getThreeDifferent(betContent) {750 const formatArray = {751 status: false,752 message: '',753 betCount: 0,754 betTotalAmount: 0,755 betContent: [],756 postContent: '',757 };758 if (betContent.length < 3) {759 formatArray.message = '号码不足3位!!';760 return formatArray;761 }762 const uniqueBetContent = [...new Set(betContent)];763 if (betContent.length <= 0 || uniqueBetContent.length !== betContent.length) {764 formatArray.message = '投注发生错误,请重新投注!!';765 return formatArray;766 }767 const content = [];768 betContent.forEach((number) => {769 content.push(number.name);770 });771 let combinatedNumber = [];772 combinatedNumber = getArrange(content, 3);773 const betUnitAmount = parseInt(betContent[0].amount, Number);774 formatArray.status = true;775 formatArray.betCount = combinatedNumber.length;776 formatArray.betTotalAmount = betUnitAmount * combinatedNumber.length;777 formatArray.betContent = combinatedNumber;778 formatArray.postContent = `${content.join(' ')}`;779 return formatArray;780 },781 /**782 * 三同號單選783 * @param {和值玩法} betContent784 */785 getThreeIdenticalSingle(betContent) {786 const formatArray = {787 status: false,788 message: '',789 betCount: 0,790 betTotalAmount: 0,791 betContent: [],792 postContent: '',793 };794 const uniqueBetContent = [...new Set(betContent)];795 if (betContent.length <= 0 || uniqueBetContent.length !== betContent.length) {796 formatArray.message = '投注发生错误,请重新投注!!';797 return formatArray;798 }799 const content = [];800 betContent.forEach((number) => {801 content.push(`${number.name}${number.name}${number.name}`);802 });803 const betUnitAmount = parseInt(betContent[0].amount, Number);804 formatArray.status = true;805 formatArray.betCount = content.length;806 formatArray.betTotalAmount = betUnitAmount * content.length;807 formatArray.betContent = content;808 formatArray.postContent = `${content.join(' ')}`;809 return formatArray;810 },811 /**812 * 三同號通選玩法813 * @param {投注內容} betContent814 */815 getThreeIdenticalAll(betContent) {816 const formatArray = {817 status: false,818 message: '',819 betCount: 0,820 betTotalAmount: 0,821 betContent: [],822 postContent: '',823 };824 if (betContent < 1 || betContent > 1) {825 formatArray.message = '号码不足!!';826 return formatArray;827 }828 if (betContent[0].name !== '同号通选') {829 formatArray.message = '号码不正确!!';830 return formatArray;831 }832 const betUnitAmount = parseInt(betContent[0].amount, Number);833 const number = ['111', '222', '333', '444', '555', '666'];834 formatArray.status = true;835 formatArray.betCount = 1;836 formatArray.betTotalAmount = betUnitAmount;837 formatArray.betContent = number;838 formatArray.postContent = `${number.join(',')}`;839 return formatArray;840 },841 /**842 * 三連號通選玩法843 * @param {投注內容} betContent844 */845 getThreeContinuousAll(betContent) {846 const formatArray = {847 status: false,848 message: '',849 betCount: 0,850 betTotalAmount: 0,851 betContent: [],852 postContent: '',853 };854 if (betContent < 1 || betContent > 1) {855 formatArray.message = '号码不足!!';856 return formatArray;857 }858 if (betContent[0].name !== '连号通选') {859 formatArray.message = '号码不正确!!';860 return formatArray;861 }862 const betUnitAmount = parseInt(betContent[0].amount, Number);863 const number = ['123', '234', '345', '456'];864 formatArray.status = true;865 formatArray.betCount = 1;866 formatArray.betTotalAmount = betUnitAmount;867 formatArray.betContent = number;868 formatArray.postContent = `${number.join(',')}`;869 return formatArray;870 },871};872/**873 * 六合彩玩法類型874 */875const HK6BetType = Object.freeze({876 EXTRA: 1000,877 TWO_SIDE: 2000,878 CONTINUOUS_CHIP: 3000,879 ZODIAC: 4000,880 COLOR_BALL: 5000,881 ELEMENT: 6000,882 HEADTOTAIL: 7000,883});884/**885 * 六合彩彩種投注計算886 */887export const hk6Service = {888 /**889 * 組合投注內容890 * @param {*} betTypeId891 * @param {*} bet_id892 * @param {*} betContent893 * 返回物件{betCount:注數,betTotalAmount:投注總額,894 * betContent:投注內容,postContent:POST投注格式}895 */896 formatBetContent(betTypeId, betContent) {897 let formatArray = { status: false, message: '' };898 if (betContent === undefined || betContent.length <= 0) {899 formatArray.message = '请选择号码!!';900 return formatArray;901 }902 switch (betTypeId) {903 case HK6BetType.EXTRA:904 formatArray = this.getExtra(betContent);905 break;906 case HK6BetType.TWO_SIDE:907 formatArray = this.getTwoSide(betContent);908 break;909 case HK6BetType.CONTINUOUS_CHIP:910 formatArray = this.getContinuousChip(betContent);911 break;912 case HK6BetType.ZODIAC:913 formatArray = this.getZodiac(betContent);914 break;915 case HK6BetType.COLOR_BALL:916 formatArray = this.getColorBall(betContent);917 break;918 case HK6BetType.ELEMENT:919 formatArray = this.getElement(betContent);920 break;921 case HK6BetType.HEADTOTAIL:922 formatArray = this.getHeadToTail(betContent);923 break;924 default:925 break;926 }927 return formatArray;928 },929 /**930 * 特碼玩法931 * @param {投注號碼} betContent932 */933 getExtra(betContent) {934 const formatArray = {935 status: false,936 message: '',937 betCount: 0,938 betTotalAmount: 0,939 betContent: [],940 postContent: '',941 };942 let totalAmount = 0;943 const content = [];944 betContent.forEach((item) => {945 totalAmount += parseInt(item.amount, Number);946 content.push(`${item.id}|${item.name}|${item.amount}`);947 formatArray.betContent.push(`号码:${item.name},投注:${item.amount}元`);948 });949 if (totalAmount === 0) {950 formatArray.message = '投注发生错误,请重新投注!!';951 return formatArray;952 }953 formatArray.status = true;954 formatArray.betCount = betContent.length;955 formatArray.betTotalAmount = totalAmount;956 formatArray.postContent = content.join(',');957 return formatArray;958 },959 /**960 * 兩面玩法961 * @param {投注號碼} betContent962 */963 getTwoSide(betContent) {964 const formatArray = {965 status: false,966 message: '',967 betCount: 0,968 betTotalAmount: 0,969 betContent: [],970 postContent: '',971 };972 let totalAmount = 0;973 const content = [];974 betContent.forEach((item) => {975 totalAmount += parseFloat(item.amount);976 const betId = parseInt(item.id.toString().slice(0, 2), Number);977 let id = '';978 switch (betId) {979 case 27:980 id = '7';981 break;982 case 20:983 id = '0';984 break;985 case 21:986 id = '1';987 break;988 case 22:989 id = '2';990 break;991 case 23:992 id = '3';993 break;994 case 24:995 id = '4';996 break;997 case 25:998 id = '5';999 break;1000 case 26:1001 id = '6';1002 break;1003 default:1004 formatArray.message = '投注发生错误,请重新投注!!';1005 return formatArray;1006 }1007 content.push(`${id}|${item.id}|${item.amount}`);1008 formatArray.betContent.push(`号码:${item.name},投注:${item.amount}`);1009 });1010 if (totalAmount === 0) {1011 formatArray.message = '投注发生错误,请重新投注!!';1012 return formatArray;1013 }1014 formatArray.status = true;1015 formatArray.betCount = betContent.length;1016 formatArray.betTotalAmount = totalAmount;1017 formatArray.postContent = content.join(',');1018 return formatArray;1019 },1020 /**1021 * 連碼玩法1022 * @param {投注號碼} betContent1023 */1024 getContinuousChip(betContent) {1025 const formatArray = {1026 status: false,1027 message: '',1028 betCount: 0,1029 betTotalAmount: 0,1030 betContent: [],1031 postContent: '',1032 };1033 const { length } = betContent;1034 if (length <= 0) {1035 return { status: false, message: '号码选择不全!!' };1036 }1037 if (length > 10) {1038 return { status: false, message: '最多只能选择10个号码' };1039 }1040 let combinationNumber = [];1041 const { id } = betContent[0];1042 switch (id) {1043 case 3001:1044 if (length < 4) {1045 return { status: false, message: '最少选择4个号码' };1046 }1047 combinationNumber = getArrange(betContent, 4);1048 break;1049 case 3002:1050 case 3003:1051 if (length < 3) {1052 return { status: false, message: '最少选择3个号码' };1053 }1054 combinationNumber = getArrange(betContent, 3);1055 break;1056 case 3004:1057 case 3005:1058 case 3006:1059 if (length < 2) {1060 return { status: false, message: '最少选择2个号码' };1061 }1062 combinationNumber = getArrange(betContent, 2);1063 break;1064 default:1065 break;1066 }1067 const totalAmount = parseInt(betContent[0].amount, Number) * combinationNumber.length;1068 let content = '';1069 betContent.forEach((element) => {1070 content === '' ? content = `${element.name}` : content = `${content} ${element.name}`;1071 });1072 if (totalAmount === 0) {1073 formatArray.message = '投注发生错误,请重新投注!!';1074 return formatArray;1075 }1076 combinationNumber.forEach((numbers) => {1077 const number = [];1078 numbers.forEach((item) => {1079 number.push(item.name);1080 });1081 formatArray.betContent.push(number.join(','));1082 });1083 formatArray.status = true;1084 formatArray.betCount = combinationNumber.length;1085 formatArray.betTotalAmount = totalAmount;1086 formatArray.postContent = `9|${id}|${content}`;1087 return formatArray;1088 },1089 /**1090 * 生肖玩法1091 * @param {玩法ID} bet_id1092 * @param {投注號碼} betContent1093 */1094 getZodiac(betContent) {1095 const formatArray = {1096 status: false,1097 betCount: 0,1098 betTotalAmount: 0,1099 betContent: [],1100 postContent: '',1101 };1102 const betId = betContent[0].id;1103 const { betName } = betContent[0];1104 const content = [];1105 switch (betId) {1106 case 4100:1107 case 4200:1108 case 4300:1109 const postContent = [];1110 betContent.forEach((item) => {1111 formatArray.betCount += 1;1112 formatArray.betTotalAmount += item.amount;1113 content.push(`${item.number} : ${item.amount} 元`);1114 postContent.push(`${0}|${item.name}|${item.amount}`);1115 });1116 formatArray.betContent = content;1117 formatArray.postContent = postContent.join(',');1118 break;1119 case 4400:1120 if (betContent.length < 2) {1121 return { status: false, message: '至少选择2个生肖' };1122 }1123 if (betContent.length > 11) {1124 return { status: false, message: '最多只能选择11个生肖!' };1125 }1126 betContent.forEach((item) => {1127 formatArray.betContent.push(`${item.name}`);1128 });1129 formatArray.betCount = 1;1130 formatArray.betTotalAmount = parseFloat(betContent[0].amount);1131 formatArray.postContent = `${betName}|${betId}|${formatArray.betContent.join(' ')}`;1132 break;1133 case 4401:1134 case 4501:1135 if (betContent.length < 2) {1136 return { status: false, message: '至少选择2个生肖' };1137 }1138 if (betContent.length > 6) {1139 return { status: false, message: '最多只能选择6个生肖!' };1140 }1141 betContent.forEach((item) => {1142 content.push(`${item.name}`);1143 });1144 const conbination = getArrange(content, 2);1145 formatArray.betContent = conbination.join(' ');1146 formatArray.betCount = formatArray.betContent.length;1147 formatArray.betTotalAmount = parseFloat(betContent[0].amount) * formatArray.betContent.length;1148 formatArray.postContent = `${betName}|${betId}|${content.join(' ')}`;1149 break;1150 case 4402:1151 case 4502:1152 if (betContent.length < 3) {1153 return { status: false, message: '至少选择3个生肖' };1154 }1155 if (betContent.length > 6) {1156 return { status: false, message: '最多只能选择6个生肖!' };1157 }1158 betContent.forEach((item) => {1159 content.push(`${item.name}`);1160 });1161 formatArray.betContent = getArrange(content, 3);1162 formatArray.betCount = formatArray.betContent.length;1163 formatArray.betTotalAmount = parseFloat(betContent[0].amount) * formatArray.betContent.length;1164 formatArray.postContent = `${betName}|${betId}|${content.join(' ')}`;1165 break;1166 case 4403:1167 case 4503:1168 if (betContent.length < 4) {1169 return { status: false, message: '至少选择4个生肖' };1170 }1171 if (betContent.length > 6) {1172 return { status: false, message: '最多只能选择6个生肖!' };1173 }1174 betContent.forEach((item) => {1175 content.push(`${item.name}`);1176 });1177 formatArray.betContent = getArrange(content, 4);1178 formatArray.betCount = formatArray.betContent.length;1179 formatArray.betTotalAmount = parseFloat(betContent[0].amount) * formatArray.betContent.length;1180 formatArray.postContent = `${betName}|${betId}|${content.join(' ')}`;1181 break;1182 case 4404:1183 case 4504:1184 if (betContent.length < 5) {1185 return { status: false, message: '至少选择5个生肖' };1186 }1187 if (betContent.length > 6) {1188 return { status: false, message: '最多只能选择6个生肖!' };1189 }1190 betContent.forEach((item) => {1191 content.push(`${item.name}`);1192 });1193 formatArray.betContent = getArrange(content, 5);1194 formatArray.betCount = formatArray.betContent.length;1195 formatArray.betTotalAmount = parseFloat(betContent[0].amount) * formatArray.betContent.length;1196 formatArray.postContent = `${betName}|${betId}|${content.join(' ')}`;1197 break;1198 default:1199 break;1200 }1201 formatArray.status = true;1202 return formatArray;1203 },1204 /**1205 * 色波玩法1206 * @param {投注號碼} betContent1207 */1208 getColorBall(betContent) {1209 const formatArray = {1210 status: false,1211 betCount: 0,1212 betTotalAmount: 0,1213 betContent: [],1214 postContent: '',1215 };1216 const content = [];1217 betContent.forEach((element) => {1218 formatArray.betCount += 1;1219 formatArray.betTotalAmount += parseFloat(element.amount);1220 formatArray.betContent.push(`${element.name}:${element.amount} 元`);1221 content.push(`0|${element.id}|${element.amount}`);1222 });1223 formatArray.status = true;1224 formatArray.postContent = content.join(',');1225 return formatArray;1226 },1227 /**1228 * 五行玩法1229 * @param {投注號碼} betContent1230 */1231 getElement(betContent) {1232 const formatArray = {1233 status: false,1234 betCount: 0,1235 betTotalAmount: 0,1236 betContent: [],1237 postContent: '',1238 };1239 const content = [];1240 betContent.forEach((element) => {1241 formatArray.betCount += 1;1242 formatArray.betTotalAmount += parseFloat(element.amount);1243 formatArray.betContent.push(`号码:${element.name},投注:${element.amount}元`);1244 content.push(`0|${element.id}|${element.amount}`);1245 });1246 formatArray.status = true;1247 formatArray.postContent = content.join(',');1248 return formatArray;1249 },1250 /**1251 * 頭尾玩法1252 * @param {投注號碼} betContent1253 */1254 getHeadToTail(betContent) {1255 const formatArray = {1256 status: false,1257 betCount: 0,1258 betTotalAmount: 0,1259 betContent: [],1260 postContent: '',1261 };1262 const content = [];1263 let digit = 0;1264 betContent.forEach((element) => {1265 formatArray.betCount += 1;1266 formatArray.betTotalAmount += parseFloat(element.amount);1267 switch (element.id) {1268 case 7701:1269 case 7702:1270 case 7703:1271 case 7704:1272 case 7705:1273 case 7001:1274 case 7002:1275 case 7003:1276 case 7004:1277 case 7005:1278 case 7006:1279 case 7007:1280 case 7008:1281 case 7009:1282 case 7010:1283 digit = 0;1284 break;1285 case 7101:1286 case 7102:1287 case 7103:1288 case 7104:1289 case 7105:1290 case 7106:1291 case 7107:1292 case 7108:1293 case 7109:1294 case 7110:1295 digit = 1;1296 break;1297 case 7201:1298 case 7202:1299 case 7203:1300 case 7204:1301 case 7205:1302 case 7206:1303 case 7207:1304 case 7208:1305 case 7209:1306 case 7210:1307 digit = 2;1308 break;1309 case 7301:1310 case 7302:1311 case 7303:1312 case 7304:1313 case 7305:1314 case 7306:1315 case 7307:1316 case 7308:1317 case 7309:1318 case 7310:1319 digit = 3;1320 break;1321 case 7401:1322 case 7402:1323 case 7403:1324 case 7404:1325 case 7405:1326 case 7406:1327 case 7407:1328 case 7408:1329 case 7409:1330 case 7410:1331 digit = 4;1332 break;1333 case 7501:1334 case 7502:1335 case 7503:1336 case 7504:1337 case 7505:1338 case 7506:1339 case 7507:1340 case 7508:1341 case 7509:1342 case 7510:1343 digit = 5;1344 break;1345 case 7601:1346 case 7602:1347 case 7603:1348 case 7604:1349 case 7605:1350 case 7606:1351 case 7607:1352 case 7608:1353 case 7609:1354 case 7610:1355 digit = 6;1356 break;1357 default:1358 break;1359 }1360 formatArray.betContent.push(`${element.name},投注:${element.amount}元`);1361 content.push(`${digit}|${element.id}|${element.amount}`);1362 });1363 formatArray.status = true;1364 formatArray.postContent = content.join(',');1365 return formatArray;1366 },1367 /**1368 * 返回玩法列表1369 * @param {1000:特正碼,2000:兩面,3000:連碼,4000:生肖,5000:色波,6000:五行,7000:頭尾數} type1370 * @param {由API獲取對應號碼陣列} gameRates1371 */1372 getPlayArray(type, gameRates, numberArray) {1373 const playArray = [];1374 switch (type) {1375 case '4000':1376 gameRates.forEach((element) => {1377 let playObj = {};1378 if (element.bet_name === '合肖' || element.bet_name === '二合肖'1379 || element.bet_name === '三合肖' || element.bet_name === '四合肖'1380 || element.bet_name === '五合肖' || element.bet_name === '二连肖'1381 || element.bet_name === '三连肖' || element.bet_name === '四连肖'1382 || element.bet_name === '五连肖') {1383 playObj.bet_id = element.bet_id;1384 playObj.bet_name = element.bet_name;1385 playObj.bet_rate = element.bet_rate;1386 playObj.play_list = [];1387 playArray[playObj.bet_id] = playObj;1388 const number = element.bet_number.split(',');1389 number.forEach((index) => {1390 playObj = {};1391 playObj.bet_id = element.bet_id;1392 playObj.bet_name = index;1393 playObj.bet_rate = 0;1394 playObj.bet_number = numberArray[index];1395 playArray[playObj.bet_id].play_list.push(playObj);1396 });1397 }1398 if (element.bet_name === '特肖'1399 || element.bet_name === '正肖'1400 || element.bet_name === '一肖') {1401 playObj.bet_id = element.bet_id;1402 playObj.bet_name = element.bet_name;1403 playObj.bet_rate = element.bet_rate;1404 playObj.play_list = [];1405 playArray[playObj.bet_id] = playObj;1406 }1407 if (element.bet_id >= 4101 && element.bet_id <= 4199) {1408 playObj.bet_id = element.bet_id;1409 playObj.bet_name = element.bet_name;1410 playObj.bet_rate = element.bet_rate;1411 playObj.bet_number = numberArray[element.bet_name];1412 playArray[4100].play_list.push(playObj);1413 } else if (element.bet_id >= 4201 && element.bet_id <= 4299) {1414 playObj.bet_id = element.bet_id;1415 playObj.bet_name = element.bet_name;1416 playObj.bet_rate = element.bet_rate;1417 playObj.bet_number = numberArray[element.bet_name];1418 playArray[4200].play_list.push(playObj);1419 } else if (element.bet_id >= 4301 && element.bet_id <= 4399) {1420 playObj.bet_id = element.bet_id;1421 playObj.bet_name = element.bet_name;1422 playObj.bet_rate = element.bet_rate;1423 playObj.bet_number = numberArray[element.bet_name];1424 playArray[4300].play_list.push(playObj);1425 }1426 });1427 break;1428 case '7000':1429 break;1430 default:1431 break;1432 }1433 return playArray.filter(n => n !== null);1434 },1435};1436/**1437 * PK10玩法類型1438 */1439const PK10BetType = Object.freeze({1440 CHAMPION: 100,1441 CHAMPION_SECOND: 200,1442 FRONT_THREE: 300,1443 FIX_DIGIT: 400,1444 TWO_SIDE: 500,1445 COMBINATION: 600,1446});1447/**1448 * PK10彩種投注計算1449 */1450export const pk10Service = {1451 makeBetItem(gameId, bet, amount) {1452 return {1453 id: gameId,1454 name: bet,1455 amount,1456 };1457 },1458 /**1459 * 官方投注 SSC & PK10 && K31460 * @param {*} lotteryId 彩種ID1461 * @param {*} betTypeId 玩法類型ID1462 * @param {*} betUnitMoney 單注金額1463 * @param {*} betContent 投注號碼1464 */1465 officalBet(lotteryId, betTypeId, betUnitMoney, betCount, betContent) {1466 if (betContent === '' || betContent === null) {1467 return {1468 status: false,1469 message: '您还没有选择任何号码!请在选号面板选择您的号码,点击添加到投注列表!',1470 };1471 }1472 const content = JSON.stringify({1473 rule_id: betTypeId,1474 bet_type_id: betTypeId,1475 bet_total_count: betCount,1476 unit_price: betUnitMoney,1477 bet_content: betContent,1478 });1479 const postData = {1480 lottery_id: lotteryId,1481 bet_type_id: betTypeId,1482 bet_count: betCount,1483 bet_unit_money: betUnitMoney,1484 bet_total_money: betCount * betUnitMoney,1485 bet_content: content,1486 };1487 return {1488 status: true,1489 message: postData,1490 };1491 },1492 /**1493 * 依類型ID回傳投注格式1494 */1495 formatBetContent(betTypeId, betContent) {1496 const formatArray = {1497 status: false,1498 message: '',1499 betCount: 0,1500 betTotalAmount: 0,1501 betContent: [],1502 postContent: '',1503 };1504 if (betContent.length <= 0) {1505 formatArray.message = '号码选择不足!!';1506 return formatArray;1507 }1508 let content = [];1509 let postContent = '';1510 let betUnitAmount = 0;1511 let betCount = 0;1512 switch (betTypeId) {1513 case PK10BetType.CHAMPION:1514 case PK10BetType.COMBINATION:1515 betUnitAmount = parseInt(betContent[0].amount, Number);1516 betContent[0].forEach((number) => {1517 content.push(number.name);1518 });1519 postContent = content.join(' ');1520 betCount = content.length;1521 break;1522 case PK10BetType.CHAMPION_SECOND:1523 if (betContent[0] === undefined || betContent[0].length === 01524 || betContent[1] === undefined || betContent[1].length === 0) {1525 formatArray.message = '号码选择不足!!';1526 return formatArray;1527 }1528 betUnitAmount = parseInt(betContent[0][0].amount, Number);1529 const champion = [];1530 const second = [];1531 betContent[0].forEach((number) => {1532 champion.push(number.name);1533 });1534 betContent[1].forEach((number) => {1535 second.push(number.name);1536 });1537 content = twoArrayCombinate(champion, second);1538 betCount = content.length;1539 postContent = `${champion.join(' ')},${second.join(' ')}`;1540 break;1541 case PK10BetType.FRONT_THREE:1542 if (betContent[0] === undefined || betContent[0].length <= 01543 || betContent[1] === undefined || betContent[1].length <= 01544 || betContent[2] === undefined || betContent[2].length <= 0) {1545 formatArray.message = '号码选择不足!!';1546 return formatArray;1547 }1548 betUnitAmount = parseInt(betContent[0][0].amount, Number);1549 const threeChampion = [];1550 const threeSecond = [];1551 const threeThird = [];1552 betContent[0].forEach((number) => {1553 threeChampion.push(number.name);1554 });1555 betContent[1].forEach((number) => {1556 threeSecond.push(number.name);1557 });1558 betContent[2].forEach((number) => {1559 threeThird.push(number.name);1560 });1561 content = threeArrayCombinate(threeChampion, threeSecond, threeThird);1562 betCount = content.length;1563 postContent = `${threeChampion.join(' ')},${threeSecond.join(' ')},${threeThird.join(' ')}`;1564 break;1565 case PK10BetType.FIX_DIGIT:1566 if (betContent[0] && betContent[0].length > 0) {1567 const fixedFirst = [];1568 betContent[0].forEach((number) => {1569 betUnitAmount = parseInt(number.amount, Number);1570 fixedFirst.push(number.name);1571 });1572 content.push(`第1名:${fixedFirst.map(Number).sort(sortNumber).join(',')}`);1573 betCount += fixedFirst.length;1574 }1575 if (betContent[1] && betContent[1].length > 0) {1576 const fixedSecond = [];1577 betContent[1].forEach((number) => {1578 betUnitAmount = parseInt(number.amount, Number);1579 fixedSecond.push(number.name);1580 });1581 content.push(`第2名:${fixedSecond.map(Number).sort(sortNumber).join(',')}`);1582 betCount += fixedSecond.length;1583 }1584 if (betContent[2] && betContent[2].length > 0) {1585 const fixedThird = [];1586 betContent[2].forEach((number) => {1587 betUnitAmount = parseInt(number.amount, Number);1588 fixedThird.push(number.name);1589 });1590 content.push(`第3名:${fixedThird.map(Number).sort(sortNumber).join(',')}`);1591 betCount += fixedThird.length;1592 }1593 if (betContent[3] && betContent[3].length > 0) {1594 const fixedFourth = [];1595 betContent[3].forEach((number) => {1596 betUnitAmount = parseInt(number.amount, Number);1597 fixedFourth.push(number.name);1598 });1599 content.push(`第4名:${fixedFourth.map(Number).sort(sortNumber).join(',')}`);1600 betCount += fixedFourth.length;1601 }1602 if (betContent[4] && betContent[4].length > 0) {1603 const fixedFifth = [];1604 betContent[4].forEach((number) => {1605 betUnitAmount = parseInt(number.amount, Number);1606 fixedFifth.push(number.name);1607 });1608 content.push(`第5名:${fixedFifth.map(Number).sort(sortNumber).join(',')}`);1609 betCount += fixedFifth.length;1610 }1611 if (betContent[5] && betContent[5].length > 0) {1612 const fixedSixth = [];1613 betContent[5].forEach((number) => {1614 betUnitAmount = parseInt(number.amount, Number);1615 fixedSixth.push(number.name);1616 });1617 content.push(`第6名:${fixedSixth.map(Number).sort(sortNumber).join(',')}`);1618 betCount += fixedSixth.length;1619 }1620 if (betContent[6] && betContent[6].length > 0) {1621 const fixedSeventh = [];1622 betContent[6].forEach((number) => {1623 betUnitAmount = parseInt(number.amount, Number);1624 fixedSeventh.push(number.name);1625 });1626 content.push(`第7名:${fixedSeventh.map(Number).sort(sortNumber).join(',')}`);1627 betCount += fixedSeventh.length;1628 }1629 if (betContent[7] && betContent[7].length > 0) {1630 const fixedEighth = [];1631 betContent[7].forEach((number) => {1632 betUnitAmount = parseInt(number.amount, Number);1633 fixedEighth.push(number.name);1634 });1635 content.push(`第8名:${fixedEighth.map(Number).sort(sortNumber).join(',')}`);1636 betCount += fixedEighth.length;1637 }1638 if (betContent[8] && betContent[8].length > 0) {1639 const fixedNinth = [];1640 betContent[8].forEach((number) => {1641 betUnitAmount = parseInt(number.amount, Number);1642 fixedNinth.push(number.name);1643 });1644 content.push(`第9名:${fixedNinth.map(Number).sort(sortNumber).join(',')}`);1645 betCount += fixedNinth.length;1646 }1647 if (betContent[9] && betContent[9].length > 0) {1648 const fixedTenth = [];1649 betContent[9].forEach((number) => {1650 betUnitAmount = parseInt(number.amount, Number);1651 fixedTenth.push(number.name);1652 });1653 content.push(`第10名:${fixedTenth.map(Number).sort(sortNumber).join(',')}`);1654 betCount += fixedTenth.length;1655 }1656 if (betCount === 0) {1657 formatArray.message = '号码选择不足!!';1658 return formatArray;1659 }1660 postContent = content.join(' ');1661 break;1662 case PK10BetType.TWO_SIDE:1663 if (betContent[0] && betContent[0].length > 0) {1664 const twoSideFirst = [];1665 betContent[0].forEach((number) => {1666 betUnitAmount = parseInt(number.amount, Number);1667 twoSideFirst.push(number.name);1668 });1669 content.push(`第1名:${twoSideFirst.join(',')}`);1670 betCount += twoSideFirst.length;1671 }1672 if (betContent[1] && betContent[1].length > 0) {1673 const twoSideSecond = [];1674 betContent[1].forEach((number) => {1675 betUnitAmount = parseInt(number.amount, Number);1676 twoSideSecond.push(number.name);1677 });1678 content.push(`第2名:${twoSideSecond.join(',')}`);1679 betCount += twoSideSecond.length;1680 }1681 if (betContent[2] && betContent[2].length > 0) {1682 const twoSideThird = [];1683 betContent[2].forEach((number) => {1684 betUnitAmount = parseInt(number.amount, Number);1685 twoSideThird.push(number.name);1686 });1687 content.push(`第3名:${twoSideThird.join(',')}`);1688 betCount += twoSideThird.length;1689 }1690 if (betContent[3] && betContent[3].length > 0) {1691 const twoSideFourth = [];1692 betContent[3].forEach((number) => {1693 betUnitAmount = parseInt(number.amount, Number);1694 twoSideFourth.push(number.name);1695 });1696 content.push(`第4名:${twoSideFourth.join(',')}`);1697 betCount += twoSideFourth.length;1698 }1699 if (betContent[4] && betContent[4].length > 0) {1700 const twoSideFifth = [];1701 betContent[4].forEach((number) => {1702 betUnitAmount = parseInt(number.amount, Number);1703 twoSideFifth.push(number.name);1704 });1705 content.push(`第5名:${twoSideFifth.join(',')}`);1706 betCount += twoSideFifth.length;1707 }1708 if (betContent[5] && betContent[5].length > 0) {1709 const twoSideSixth = [];1710 betContent[5].forEach((number) => {1711 betUnitAmount = parseInt(number.amount, Number);1712 twoSideSixth.push(number.name);1713 });1714 content.push(`第6名:${twoSideSixth.join(',')}`);1715 betCount += twoSideSixth.length;1716 }1717 if (betContent[6] && betContent[6].length > 0) {1718 const twoSideSeventh = [];1719 betContent[6].forEach((number) => {1720 betUnitAmount = parseInt(number.amount, Number);1721 twoSideSeventh.push(number.name);1722 });1723 content.push(`第7名:${twoSideSeventh.join(',')}`);1724 betCount += twoSideSeventh.length;1725 }1726 if (betContent[7] && betContent[7].length > 0) {1727 const twoSideEighth = [];1728 betContent[7].forEach((number) => {1729 betUnitAmount = parseInt(number.amount, Number);1730 twoSideEighth.push(number.name);1731 });1732 content.push(`第8名:${twoSideEighth.join(',')}`);1733 betCount += twoSideEighth.length;1734 }1735 if (betContent[8] && betContent[8].length > 0) {1736 const twoSideNinth = [];1737 betContent[8].forEach((number) => {1738 betUnitAmount = parseInt(number.amount, Number);1739 twoSideNinth.push(number.name);1740 });1741 content.push(`第9名:${twoSideNinth.join(',')}`);1742 betCount += twoSideNinth.length;1743 }1744 if (betContent[9] && betContent[9].length > 0) {1745 const twoSideTenth = [];1746 betContent[9].forEach((number) => {1747 betUnitAmount = parseInt(number.amount, Number);1748 twoSideTenth.push(number.name);1749 });1750 content.push(`第10名:${twoSideTenth.join(',')}`);1751 betCount += twoSideTenth.length;1752 }1753 if (betCount === 0) {1754 formatArray.message = '号码选择不足!!';1755 return formatArray;1756 }1757 postContent = content.join(' ');1758 break;1759 default:1760 break;1761 }1762 formatArray.status = true;1763 formatArray.betContent = content;1764 formatArray.betCount = betCount;1765 formatArray.betUnitAmount = betUnitAmount;1766 formatArray.betTotalAmount = betCount * betUnitAmount;1767 formatArray.postContent = JSON.stringify({1768 rule_id: betTypeId,1769 bet_type_id: betTypeId,1770 bet_total_count: content.length,1771 unit_price: betUnitAmount,1772 bet_content: postContent,1773 });1774 return formatArray;1775 },1776};1777/**1778 * PCEGG玩法類型1779 */1780const PCEGGBetType = Object.freeze({1781 SUM: 100,1782 MIX: 200,1783});1784export const pceggService = {1785 /**1786 * 計算及回傳投注格式1787 * @param {類型ID} betTypeId1788 * @param {投注內容} betContent1789 */1790 formatBetContent(betTypeId, betContent) {1791 if (betContent === undefined || betContent.length <= 0) {1792 return { status: false, message: '号码选择不足!!' };1793 }1794 let formatArray = {};1795 switch (betTypeId) {1796 case PCEGGBetType.SUM:1797 formatArray = this.getSum(betContent);1798 break;1799 case PCEGGBetType.MIX:1800 formatArray = this.getMix(betContent);1801 break;1802 default:1803 break;1804 }1805 return formatArray;1806 },1807 /**1808 * 和值玩法1809 * @param {投注內容} betContent1810 */1811 getSum(betContent) {1812 const formatArray = {1813 status: false,1814 message: '',1815 betCount: 0,1816 betTotalAmount: 0,1817 betContent: [],1818 postContent: '',1819 };1820 let totalAmount = 0;1821 const content = [];1822 betContent.forEach((number) => {1823 totalAmount += parseInt(number.amount, Number);1824 formatArray.betContent.push(`号码:${number.name} ${number.amount}元`);1825 content.push(`${number.name}|${number.name}|${number.amount}`);1826 });1827 if (totalAmount === 0) {1828 formatArray.message = '投注发生错误,请重新投注!!';1829 return formatArray;1830 }1831 formatArray.status = true;1832 formatArray.betCount = betContent.length;1833 formatArray.betTotalAmount = totalAmount;1834 formatArray.postContent = `${content.join(',')}`;1835 return formatArray;1836 },1837 /**1838 * 混合玩法1839 * @param {投注內容} betContent1840 */1841 getMix(betContent) {1842 const formatArray = {1843 status: false,1844 message: '',1845 betCount: 0,1846 betTotalAmount: 0,1847 betContent: [],1848 postContent: '',1849 };1850 let totalAmount = 0;1851 const content = [];1852 betContent.forEach((number) => {1853 totalAmount += parseInt(number.amount, Number);1854 formatArray.betContent.push(`号码:${number.name} ${number.amount}元`);1855 content.push(`${number.id}|${number.name}|${number.amount}`);1856 });1857 if (totalAmount === 0) {1858 formatArray.message = '投注发生错误,请重新投注!!';1859 return formatArray;1860 }1861 formatArray.status = true;1862 formatArray.betCount = betContent.length;1863 formatArray.betTotalAmount = totalAmount;1864 formatArray.postContent = `${content.join(',')}`;1865 return formatArray;1866 },1867};1868export const mobileService = {1869 /**1870 * 獲取手機版遊戲選單1871 * @param {*} betTypeArray1872 */1873 getLotteryMenu(classId, betTypeArray) {1874 const betTypes = [];1875 switch (classId) {1876 case LotteryClassType.TYPE_SSC:1877 case LotteryClassType.TYPE_11X5:1878 case LotteryClassType.TYPE_3D:1879 betTypeArray.forEach((betType) => {1880 betTypes.push({1881 betTypeName: betType.bet_type_name,1882 betTypeId: betType.bet_type_id,1883 description: betType.description,1884 plays: betType.lottery_play_list,1885 });1886 });1887 break;1888 case LotteryClassType.TYPE_HK6:1889 betTypeArray.forEach((betType) => {1890 betTypes.push({1891 betTypeName: betType.bet_type_name,1892 betTypeId: betType.bet_type_id,1893 description: betType.description,1894 plays: [],1895 });1896 });1897 break;1898 case LotteryClassType.TYPE_K3:1899 betTypeArray.forEach((betType) => {1900 betTypes.push({1901 lotteryId: betType.lottery_id,1902 betTypeName: betType.bet_type_name,1903 betTypeId: betType.bet_type_id,1904 description: betType.description,1905 plays: betType.lottery_play_list,1906 });1907 });1908 break;1909 case LotteryClassType.TYPE_PK10:1910 case LotteryClassType.TYPE_PCEGG:1911 betTypeArray.forEach((betType) => {1912 betTypes.push({1913 betTypeName: betType.bet_type_name,1914 betTypeId: betType.bet_type_id,1915 plays: [],1916 });1917 });1918 break;1919 default:1920 break;1921 }1922 return betTypes;1923 },...

Full Screen

Full Screen

joinBs.js

Source:joinBs.js Github

copy

Full Screen

1//정규식2const regId = /(?=.*\d{0,})(?=.*[a-z]{1,}).{6,15}/;3const regPw = /^.*(?=^.{8,15}$)(?=.*\d)(?=.*[a-zA-Z])(?=.*[!@#$%^&+=]).*$/;4const regName = /^[가-힝a-zA-Z]{1,}$/;5const regEmail = /^[0-9a-zA-Z]([-_.]?[0-9a-zA-Z])*@[0-9a-zA-Z]([-_.]?[0-9a-zA-Z])*\.[a-zA-Z]{2,3}$/;6const regBno = /^[0-9]{10}$/;7const regPhone = /^[0-9]{3}\-[0-9]{3,4}\-[0-9]{4}$/;8const regAccount = /^[0-9,\-]{3,6}\-[0-9,\-]{2,6}\-[0-9,\-]{3,6}(\-[0-9]{1,3})?$/;9const regPrice = /^[0-9]+$/;10const regMailCode = /^[0-9]{6}$/;11//비교객체12const id = document.getElementById("id");13const pw = document.getElementById("pw");14const repw = document.getElementById("repw");15const email = document.getElementById("email");16const bno = document.getElementById("bno");17const account = document.getElementById("account");18const phone = document.getElementById("phoneNum");19//유효성 통과 여부 체크 객체 (false&true)20var formatArray = [false, false, false, false, false, false, false];21var alertArray = [22 "아이디",23 "비밀번호",24 "비밀번호 확인",25 "이메일",26 "휴대폰 번호",27 "사업자등록번호",28 "계좌번호",29];30var focusArray = [id, pw, repw, email, phone, bno, account];31var mailCode;32//요일 출력 배열33const week = [34 "월요일",35 "화요일",36 "수요일",37 "목요일",38 "금요일",39 "토요일",40 "일요일",41 "매일",42 "평일",43 "주말",44];45//타이머 전역변수 지정46function $ComTimer() {}47$ComTimer.prototype = {48 comSecond: "",49 timer: "",50 domId: "",51 fnTimer: function () {52 var min = Math.floor(this.comSecond / 60);53 var sec = this.comSecond % 60;54 this.domId.innerText = `${min}:${sec < 10 ? `0${sec}` : sec}`;55 this.comSecond--; // 1초씩 감소56 if (this.comSecond < 0) {57 // 시간이 종료 되었으면..58 clearInterval(this.timer); // 타이머 해제59 alert("인증시간이 초과하였습니다. 다시 인증해주시기 바랍니다.");60 mailCode = null; //인증코드 초기화61 }62 },63};64var AuthTimer = new $ComTimer();65$(document).ready(function () {66 //console.log("레디완료");67 scheduleHtml(); //운영시간 html 출력68 initEvent();69});70function scheduleHtml() {71 //운영시간 html 생성72 var opt;73 for (var idx = 0; idx < 10; idx++) {74 $(".weekBox ul").append(75 "<li class='hide' style='order:" +76 (idx + 1) +77 "'><button>" +78 week[idx] +79 "</button><span>시간<span>" +80 "<select></select>~<select></select></li>"81 );82 opt = $(".weekBox li[style='order:" + (idx + 1) + "'] select");83 for (var i = 0; i < 25; i++) {84 opt.append("<option>" + (i < 10 ? "0" + i : i) + ":00</option>");85 if (i != 24) {86 opt.append("<option>" + (i < 10 ? "0" + i : i) + ":30</option>");87 }88 }89 }90}91function initEvent() {92 $(".selectbox select").change(function () {93 //셀렉트 옵션이 바뀔 때 라벨에 반영되는 이벤트94 var select_name = $(this).children("option:selected").text();95 $(this).siblings("label").text(select_name);96 });97 $(".bizType div").click(function () {98 //세탁소&코인세탁소 선택 반영 이벤트99 $(this).addClass("selected");100 $(this).removeClass("unselected");101 if ($(this).index() == 0) {102 $(".bizType div").eq(1).removeClass("selected");103 $(".bizType div").eq(1).addClass("unselected");104 $(".laundry").removeClass("hide");105 $(".coinLaundry").addClass("hide");106 $(".bizType input")[0].value = 1; //비즈니스 타입값 반영107 } else {108 $(".bizType div").eq(0).removeClass("selected");109 $(".bizType div").eq(0).addClass("unselected");110 $(".laundry").addClass("hide");111 $(".coinLaundry").removeClass("hide");112 $(".bizType input")[0].value = 2; //비즈니스 타입값 반영113 }114 });115 $(".week button").click(function () {116 //요일 보이기&숨기기117 var idx = $(this).index();118 $(this).toggleClass("selected");119 $(".weekBox ul li[style='order:" + (idx + 1) + "']").toggleClass("hide");120 });121 $(".laundry input[type='checkbox']").change(function () {122 //취급품목-금액 활성화&비활성화123 var idx = $(this).attr("value");124 if ($(".laundry input.won").eq(idx).attr("disabled") == "disabled") {125 $(".laundry input.won").eq(idx).attr("disabled", false);126 } else {127 $(".laundry input.won").eq(idx).attr("disabled", true);128 $(".laundry input.won")[idx].value = "";129 }130 });131 $(".coinLaundry input[type='checkbox']").change(function () {132 //사양정보-금액 활성화&비활성화133 var idx = $(this).attr("value");134 if ($(".coinLaundry input.won").eq(idx).attr("disabled") == "disabled") {135 $(".coinLaundry input.won").eq(idx).attr("disabled", false);136 if (idx <= 2) {137 $(".coinLaundry select").eq(idx).attr("disabled", false);138 }139 } else {140 $(".coinLaundry input.won").eq(idx).attr("disabled", true);141 $(".coinLaundry input.won")[idx].value = "";142 if (idx <= 2) {143 $(".coinLaundry select").eq(idx).attr("disabled", true);144 $(".coinLaundry select")[idx].value = 0;145 $(".coinLaundry label[for='select']").eq(idx).text("");146 }147 }148 });149 $("#emailChkBtn").click(function () {150 if (regEmail.test(email.value)) {151 //이메일이 양식에 맞을 경우152 mailDuplChk();153 } else {154 alert("이메일이 양식에 맞지 않습니다.");155 email.focus();156 }157 });158159 $("#id").focusout(function () {160 document.getElementById("idchk").style.color = "var(--text-red)";161 $("#idchk").removeClass("hide");162 if ($("#id").val() == "") {163 // alert("아이디를 입력하세요.");164 document.getElementById("idchk").innerText =165 "아이디는 필수 입력사항입니다.";166 $("#id").focus();167 return false;168 }169 if ($("#id").val().length < 6) {170 // alert("아이디를 6자 이상으로 입력해 주세요.");171 document.getElementById("idchk").innerText =172 "아이디를 6자 이상으로 입력해 주세요.";173 $("#id").focus();174 return false;175 }176 if (!regId.test(id.value)) {177 // alert("아이디는 6자 이상, 최소 하나의 알파벳(a-z)을 포함해야 합니다.");178 document.getElementById("idchk").innerText =179 "아이디는 6자 이상, 최소 하나의 알파벳(a-z)을 포함해야 합니다.";180 $("#id").focus();181 return false;182 }183184 $.ajax({185 url: "/idchk.do",186 type: "POST",187 data: {188 id: $("#id").val(),189 },190 success: function (data) {191 // console.log(data);192 var key = JSON.parse(data);193 if (key == 1) {194 formatArray[0] = false;195 document.getElementById("idchk").innerText =196 "중복된 아이디가 있습니다.";197 // alert("중복된 아이디가 있습니다.");198 } else if (key == 0) {199 formatArray[0] = true;200 // alert("사용 가능한 아이디입니다.");201 document.getElementById("idchk").style.color = "var(--key-text)";202 document.getElementById("idchk").innerText =203 "사용 가능한 아이디입니다.";204 }205 },206 });207 });208209 // $("#idChkBtn").click(function () {210 // if (regId.test(id.value)) {211 // idAjax(id.value);212 // } else {213 // alert("ID가 양식에 맞지 않습니다.");214 // id.focus();215 // }216 // });217 // function idAjax(data) {218 // console.log("ajax진입");219 // $.post({220 // url: "/idchk.do",221 // data: { id: data },222 // success: function (result) {223 // console.log("ajax완료");224 // if (result == 0) {225 // alert("사용가능한 아이디입니다.");226 // formatArray[0] = true;227 // } else {228 // alert("중복된 아이디입니다.");229 // }230 // },231 // error: function () {232 // alert("에러발생");233 // },234 // });235 // }236237 // function chkId() {238 // //ID 유효성 체크239 // if (regId.test(id.value)) {240 // //ID유효성 체크241 // $("#idchk").addClass("hide");242 // } else {243 // $("#idchk").removeClass("hide");244 // formatArray[0] = false;245 // }246 // }247248 $("#id").keyup(function () {249 //만약 중복검사를 통과했는데 키 입력을 했을 경우250 if (formatArray[0] == true) {251 //통과된 상태 취소252 formatArray[0] = false;253 }254 });255256 $("#certified").click(function () {257 //이메일 인증번호 확인란258 if (regMailCode.test($("#mailCodeChk")[0].value)) {259 //코드 표현식 검사260 if (mailCode == $("#mailCodeChk")[0].value) {261 //코드가 일치한다면,262 timeStop();263 alert("메일 인증이 완료되었습니다.");264 formatArray[3] = true;265 $("#timeout")[0].innerText = "";266 } else if ($("#timeout")[0].innerText == "0:00") {267 //시간이 다 됐는데 인증을 누른다면268 alert("인증번호가 만료되었습니다.");269 } else if ($("#timeout")[0].innerText.length != 0) {270 //시간이 남았는데 코드가 일치하지 않는다면271 alert("인증번호가 일치하지 않습니다.");272 } else if (formatArray[3] == false) {273 //타이머가 공백인데 인증이 되지 않았다면274 alert("이메일 인증을 먼저 진행해주세요.");275 } else {276 // 그 외에 경우는 어떻게 정의할 지 잘 모르겠음277 }278 } else {279 //코드가 숫자 6자리가 아니라면280 alert("인증코드의 양식과 일치하지 않습니다.");281 }282 });283 $("#email").keyup(function () {284 //이메일 인증을 마쳤는데 다시 입력할 경우285 if (formatArray[3] == true) {286 formatArray[3] = false; //인증 초기화287 }288 });289290 // Jquery, 입력시 불가 문자 삭제291 //아이디 한글입력 안되게 처리 */292 $("input[name=id]").keyup(function (event) {293 if (!(event.keyCode >= 37 && event.keyCode <= 40)) {294 var inputVal = $(this).val();295 $(this).val(inputVal.replace(/[^a-z0-9]/gi, ""));296 }297 });298 299 // 이름 영어+한글만 입력 -> 업체는 이름이 바뀔 수 있으니까 비활성화함300 // $("input[name=bname]").keyup(function (event) {301 // if (!(event.keyCode >= 37 && event.keyCode <= 40)) {302 // var inputVal = $(this).val();303 // $(this).val(304 // inputVal.replace(/^[0-9]+$|[ \[\]{}()<>?|`~!@#$%^&*-_+=,.;:\"\\]/gi, "")305 // // 이름 한글만 입력 가능306 // // inputVal.replace(/[a-z0-9]|[ \[\]{}()<>?|`~!@#$%^&*-_+=,.;:\"\\]/g, "")307 // );308 // }309 // });310311 // 폰넘버 숫자+하이픈312 $("input[name=phone]").keyup(function (event) {313 if (!(event.keyCode >= 37 && event.keyCode <= 40)) {314 var inputVal = $(this).val();315 $(this).val(inputVal.replace(/[^0-9-]$/gi, ""));316 }317 });318 // 계좌 숫자+하이픈319 $("input[name=bankAccountNum]").keyup(function (event) {320 if (!(event.keyCode >= 37 && event.keyCode <= 40)) {321 var inputVal = $(this).val();322 $(this).val(inputVal.replace(/[^0-9-]$/gi, ""));323 }324 });325326 //사업자 등록 번호 숫자만327 $("input[name=bno]").keyup(function (event) {328 if (!(event.keyCode >= 37 && event.keyCode <= 40)) {329 var inputVal = $(this).val();330 $(this).val(inputVal.replace(/[^0-9]/gi, ""));331 }332 });333 //생일 숫자만334 $("input[name=bno]").keyup(function (event) {335 if (!(event.keyCode >= 37 && event.keyCode <= 40)) {336 var inputVal = $(this).val();337 $(this).val(inputVal.replace(/[^0-9]/gi, ""));338 }339 });340341 // 계좌번호342 $("input[name=email]").keyup(function (event) {343 if (!(event.keyCode >= 37 && event.keyCode <= 40)) {344 var inputVal = $(this).val();345 $(this).val(346 inputVal.replace(347 /[^a-z0-9+$|[ \[\]{}()<>?|`~!#$%^&*-_+=,.;:\"\\]/gi,348 ""349 )350 );351 }352 });353}354function timerStart() {355 AuthTimer.comSecond = 180;356 AuthTimer.timer = setInterval(function () {357 AuthTimer.fnTimer();358 }, 1000);359 AuthTimer.domId = document.getElementById("timeout");360}361function timeStop() {362 clearInterval(AuthTimer.timer);363}364function mailDuplChk() {365 $.post({366 url: "/findemail.do",367 data: { email: email.value },368 success: function (result) {369 if (result == 0) {370 emailAjax(email.value);371 } else {372 alert("중복된 이메일이 존재합니다.");373 email.focus();374 }375 },376 });377}378function mailChk() {379 if ($("#mailCodeChk")[0].value == mailCode) {380 alert("인증되었습니다.");381 formatArray[3] = true;382 } else {383 alert("인증번호가 일치하지 않습니다.");384 }385}386387function emailAjax(email) {388 //이메일인증검사389 $.get({390 url: "/mailCheck.do",391 data: { email: email },392 success: function (code) {393 mailCode = code;394 alert("인증번호가 전송되었습니다.");395 timerStart();396 },397 });398}399400function chkPw() {401 if (regPw.test(pw.value)) {402 //PW유효성 체크403 $("#pwchk").addClass("hide");404 chkRePw();405 } else {406 $("#pwchk").removeClass("hide");407 formatArray[1] = false;408 }409}410function chkRePw() {411 if (pw.value == repw.value) {412 $("#pwRechk").addClass("hide");413 formatArray[2] = true;414 if ($("#pwchk").hasClass("hide")) {415 //위의 비밀번호가 정상입력상태라면,416 formatArray[1] = true;417 }418 } else {419 $("#pwRechk").removeClass("hide");420 formatArray[2] = false;421 }422}423function chkEmail() {424 if (regEmail.test(email.value)) {425 $("#emailchk").addClass("hide");426 } else {427 $("#emailchk").removeClass("hide");428 }429}430function chkPhone() {431 if (regPhone.test(phone.value)) {432 $("#phonechk").addClass("hide");433 formatArray[4] = true;434 } else {435 $("#phonechk").removeClass("hide");436 formatArray[4] = false;437 }438}439440$("#bno").focusout(function () {441 // function chkBno() {442 // if (!regBno.test($("#bno").val())) {443 if (!regBno.test(bno.value)) {444 $("#bnochk").removeClass("hide");445 document.getElementById("bnochk").innerText = "10자리 숫자만 입력하세요 ";446 $("#bno").focus();447 return false;448 // formatArray[5] = true;449 } else {450 $("#bnochk").addClass("hide");451452 $.ajax({453 url: "/bnoChk.do",454 type: "POST",455 data: {456 bno: $("#bno").val(),457 },458 success: function (data) {459 // console.log(data);460 var key = JSON.parse(data);461 if (key != 0) {462 // formatArray[0] = false;463 document.getElementById("bnochk").innerText =464 "해당 사업자등록번호로 가입된 아이디가 있습니다.";465 $("#bnochk").removeClass("hide");466 $("#bno").focus();467 return false;468 // alert("중복된 아이디가 있습니다.");469 } else if (key == 0) {470 $("#bnochk").addClass("hide");471 formatArray[5] = true;472 }473 },474 });475 }476});477478function chkAccount() {479 if (regAccount.test(account.value)) {480 $("#accountchk").addClass("hide");481 formatArray[6] = true;482 } else {483 $("#accountchk").removeClass("hide");484 formatArray[6] = false;485 }486}487488// bnkChk변경됨489// function bnoChk() {490// var bno = $("#bno").val();491// $.post({492// url: "/bnoChk.do",493// data: { bno: bno },494// success: function (result) {495// if (result == 0) {496// formatArray[5] = true;497// } else {498// formatArray[5] = false;499// }500// },501// });502// }503504function formatChk() {505 //유효성검사가 걸린 차례대로 input값 체크506 // bnoChk(); //임시로 bno 검사 위치함507 for (var i = 0; i < formatArray.length; i++) {508 if (!formatArray[i]) {509 //false가 반환된다면510 if (i == 0) {511 alert("ID 중복검사를 진행해주세요.");512 return false;513 } else if (i == 3) {514 alert("이메일 인증을 진행해주세요");515 focusArray[i].focus();516 return false;517 } else {518 alert(alertArray[i] + "의 입력을 확인해주세요.");519 focusArray[i].focus();520 return false;521 }522 }523 }524 return true; //유효성검사를 전부 통과했을 경우525}526function nullchk() {527 if (formatChk()) {528 //유효성검사 true 반환시 null체크 진입529 if ($("#bname")[0].value == "") {530 //업체명 null체크531 alert("업체명은 필수입력사항입니다.");532 $("#bname").focus();533 return false;534 }535 if ($("#postcode")[0].value.length == 0) {536 //주소 null체크537 alert("주소는 필수입력사항입니다.");538 return false;539 }540541 return true; //유효성과 null체크 전부 통과할 경우 true반환542 } else {543 //유효성 통과못했을 경우 false반환544 return false;545 }546}547function clicked() {548 if (nullchk()) {549 //유효성 검사를 통과했다면550 //주소 데이터 처리 - 우편번호, 도로명주소, 상세주소, 부가주소551 var postcode = $('#postcode').val();552 var roadAddress = $("#roadAddress").val();553 var detailAddress = $("#detailAddress").val();554 var extraAddress = $('#extraAddress').val();555 $("#address")[0].value = postcode+", "+roadAddress + ", " + detailAddress+", "+extraAddress;556 // 운영시간 데이터 처리557 var weekLi = $(".weekBox ul li");558 var time = $(".weekBox select");559 var list = new Array();560 for (var i = 0; i < weekLi.size(); i++) {561 var open = time[i * 2].value;562 var close = time[i * 2 + 1].value;563 list.push({564 schno: JSON.parse(weekLi.eq(i).css("order")),565 time: open + "~" + close,566 });567 }568 $(".weekBox input[name='schedule']")[0].value = JSON.stringify(list);569 if ($(".bizType input")[0].value == 1) {570 //일반 세탁소를 작성했다면,571 var chkCount = 0; //입력된 품목 개수 검사 변수 초기화 (0 이면 null 체크)572 // 품목 리스트 데이터 처리573 var chkBox = $(".laundry input[type='checkbox']");574 var priceBox = $(".laundry input[class='won']");575 list = []; //위에서 쓰인 리스트 초기화576 for (var i = 0; i < chkBox.size(); i++) {577 if (chkBox[i].checked) {578 //체크가 되어 있다면579 chkCount++; //입력된 품목 개수 카운트 증가580 if (!regPrice.test(priceBox[i].value)) {581 //유효성에 맞지 않다면582 alert("금액엔 숫자를 입력해주세요.");583 priceBox[i].focus();584 return;585 }586 }587 list.push({588 lno: JSON.parse(chkBox[i].value) + 1,589 price: chkBox[i].checked == false ? 0 : JSON.parse(priceBox[i].value), //체크가 안되어있다면 0, 되어있다면 숫자로 변환하여 저장590 });591 }592 if (chkCount == 0) {593 //입력된 품목 중 하나라도 체크가 되어있지 않다면,594 alert("취급품목은 하나 이상 입력되어야 합니다.");595 return;596 } else {597 //하나 이상의 품목을 취급하고 있다면,598 $("input[name='laundry']")[0].value = JSON.stringify(list);599 }600 } else {601 //코인 세탁소를 작성했다면,602 // 설비 리스트 데이터 처리603 var chkBox = $(".coinLaundry .equipment input[type='checkbox']");604 var priceBox = $(".coinLaundry .equipment input[class='won']");605 var selectBox = $(".coinLaundry select");606 list = []; //리스트 초기화607 for (var i = 0; i < chkBox.size(); i++) {608 if (chkBox[i].checked) {609 if (!regPrice.test(priceBox[i].value)) {610 //유효성에 맞지 않다면611 alert("금액엔 숫자를 입력해주세요.");612 priceBox[i].focus();613 return;614 }615 }616 list.push({617 //코인세탁 사양정보 입력618 eno: i + 1,619 cnt: JSON.parse(selectBox[i].value.substr(0, 1)),620 price: chkBox[i].checked == false ? 0 : JSON.parse(priceBox[i].value), //체크가 안되어있다면 0, 되어있다면 숫자로 변환하여 저장621 });622 }623 list.push({624 eno: 4,625 cnt: JSON.parse($(".coinLaundry .dry select")[0].value.substr(0, 1)),626 price:627 $(".coinLaundry .dry input[class='won']")[0].value.length == 0628 ? 0 //건조기 가격이 입력되어있지 않다면 0을 입력629 : JSON.parse($(".coinLaundry .dry input[class='won']")[0].value), //건조기 가격이 입력되어있다면 숫자로 변환하여 입력630 }); //건조기 입력631632 $("input[name='equipment']")[0].value = JSON.stringify(list);633 //console.log($("input[name='equipment']")[0].value);634 // 부가서비스 데이터 처리635 chkBox = $(".coinLaundry .etc input[type='checkbox']");636 priceBox = $(".coinLaundry .etc input[class='won']");637 list = []; //리스트 초기화638 for (var i = 0; i < chkBox.size(); i++) {639 if (chkBox[i].checked) {640 list.push({ etcno: i + 1, price: JSON.parse(priceBox[i].value) });641 }642 }643 $("input[name='etc']")[0].value = JSON.stringify(list);644 }645 $("form").submit();646 } ...

Full Screen

Full Screen

FieldFormatEdit.js

Source:FieldFormatEdit.js Github

copy

Full Screen

1/*global define*/2/*jshint maxlen: 250*/3define(4 ['dojo/_base/declare',5 'dojo/_base/lang',6 'dojo/_base/array',7 'dojo/on',8 'dojo/dom-style',9 'dojo/query',10 'dijit/_WidgetsInTemplateMixin',11 'jimu/BaseWidgetSetting',12 'dojo/text!./FieldFormatEdit.html',13 'dijit/form/NumberSpinner',14 'jimu/dijit/CheckBox',15 'dijit/form/FilteringSelect',16 'dijit/form/ValidationTextBox',17 'dijit/_WidgetBase',18 'dijit/_TemplatedMixin'19 ],20 function(21 declare,22 lang,23 array,24 on,25 domStyle,26 query,27 _WidgetsInTemplateMixin,28 BaseWidgetSetting,29 template30 ){31 return declare([BaseWidgetSetting, _WidgetsInTemplateMixin], {32 baseClass: 'jimu-Identify-Field-Format-Edit',33 templateString: template,34 formatString: '',35 formatArray: null,36 returnfieldInfo: null,37 tr: null,38 postCreate: function(){39 this.inherited(arguments);40 this.dateFormat.set('disabled', true);41 this.percisionSpinner.set('disabled', true);42 this.percisionSymbol.set('disabled', true);43 this.thousandsSymbol.set('disabled', true);44 this.currencyCbx.set('status', false);45 this.currencySymboltxt.set('disabled', true);46 this.percisionCbx.onChange = lang.hitch(this, '_onPercisionCbxChange');47 this.currencyCbx.onChange = lang.hitch(this, '_onCurrencyCbxChange');48 this.useThousandsCbx.onChange = lang.hitch(this, '_onUseThousandsCbxChange');49 this.own(on(this.selectDateFormat, 'change', lang.hitch(this, '_onSelectDateFormatChange')));50 if (this.popup){51 this.popup.enableButton(0);52 }53 },54 setConfig: function(fieldInfo){55 console.info(fieldInfo);56 this.returnfieldInfo = fieldInfo;57 if(fieldInfo.isdate || this._isDateType(fieldInfo.type)){58 var numerics = query('.numeric', this.inputTable);59 array.forEach(numerics, function(tr) {60 domStyle.set(tr, 'display', 'none');61 });62 //need to search the selectDateFormat for a match to the dateformat if there is one else switch to custom63 if (fieldInfo.dateformat){64 this.formatString = fieldInfo.dateformat;65 var store = this.selectDateFormat.store;66 store.fetch({67 query: {name: '*'},68 onComplete: lang.hitch(this, function(items){69 if (array.some(items, function (item){ return item.value === fieldInfo.dateformat; })){70 this.selectDateFormat.set('value', fieldInfo.dateformat);71 } else {72 this.selectDateFormat.set('value', this.nls.custom);73 this.dateFormat.set('value', fieldInfo.dateformat);74 }75 })76 });77 } else {78 this.selectDateFormat.set('value', 'd MMM yyyy');79 this.dateFormat.set('value', 'd MMM yyyy');80 }81 this.utcCbx.setValue(fieldInfo.useutc || false);82 }else if (fieldInfo.isnumber || this._isNumberType(fieldInfo.type)){83 var dates = query('.date', this.inputTable);84 array.forEach(dates, function(tr) {85 domStyle.set(tr, 'display', 'none');86 });87 this.currencyCbx.set('status', true);88 this.currencyCbx.set('disabled', false);89 if(fieldInfo.currencyformat){90 this.formatString = fieldInfo.currencyformat;91 this.formatArray = this.formatString.split('|');92 this.currencyCbx.setValue(true);93 this.currencySymboltxt.set('disabled', false);94 this.currencySymboltxt.set('value', this.formatArray[0]);95 if (this.formatArray[1]){96 this.percisionSpinner.set('disabled', false);97 this.percisionCbx.setValue(true);98 this.percisionSpinner.set('value', parseInt(this.formatArray[1], 10));99 }100 if (this.formatArray[3]){101 this.percisionSymbol.set('disabled', false);102 this.percisionSymbol.set('value', this.formatArray[3]);103 }104 if (this.formatArray[2]){105 this.useThousandsCbx.setValue(true);106 this.thousandsSymbol.set('disabled', false);107 this.thousandsSymbol.set('value', this.formatArray[2]);108 }109 }else if (fieldInfo.numberformat){110 this.formatString = fieldInfo.numberformat;111 this.formatArray = this.formatString.split('|');112 this.currencyCbx.set('disabled', true);113 this.currencySymboltxt.set('disabled', true);114 //this.percisionSpinner.set('value', parseInt(this.formatArray[0]));115 //this.percisionSymbol.set('value', this.formatArray[2]);116 //this.thousandsSymbol.set('value', this.formatArray[1]);117 if (this.formatArray[0] !== ''){118 this.percisionSpinner.set('disabled', false);119 this.percisionCbx.setValue(true);120 this.percisionSpinner.set('value', parseInt(this.formatArray[0], 10));121 }122 if (this.formatArray[1]){123 this.useThousandsCbx.setValue(true);124 this.thousandsSymbol.set('disabled', false);125 this.thousandsSymbol.set('value', this.formatArray[1]);126 }127 if (this.formatArray[2]){128 this.percisionSymbol.set('disabled', false);129 this.percisionSymbol.set('value', this.formatArray[2]);130 }131 }132 }133 },134 _isNumberType:function(type){135 var numberTypes = ['esriFieldTypeOID',136 'esriFieldTypeSmallInteger',137 'esriFieldTypeInteger',138 'esriFieldTypeSingle',139 'esriFieldTypeDouble'];140 return array.indexOf(numberTypes,type) >= 0;141 },142 _isDateType:function(type){143 var dateTypes = ['esriFieldTypeDate'];144 return array.indexOf(dateTypes,type) >= 0;145 },146 getConfig: function(){147 if(this.returnfieldInfo.isdate || this._isDateType(this.returnfieldInfo.type)){148 if(this.selectDateFormat.get('value') === this.nls.custom){149 this.returnfieldInfo.dateformat = this.dateFormat.get('value');150 }else{151 this.returnfieldInfo.dateformat = this.selectDateFormat.get('value');152 }153 if(this.utcCbx.getValue()){154 this.returnfieldInfo.useutc = true;155 }156 }else if (this.returnfieldInfo.isnumber || this._isNumberType(this.returnfieldInfo.type)){157 var currencyformat = '';158 var numberformat = '';159 if(this.currencyCbx.getValue()){160 currencyformat += this.currencySymboltxt.get('value') + '|';161 if(this.percisionCbx.getValue()){162 currencyformat += this.percisionSpinner.get('value').toString() + '|';163 }else{164 currencyformat += '|';165 }166 if(this.useThousandsCbx.getValue()){167 currencyformat += this.thousandsSymbol.get('value') + '|';168 }else{169 currencyformat += '|';170 }171 if(this.percisionCbx.getValue()){172 currencyformat += this.percisionSymbol.get('value');173 }174 this.returnfieldInfo.currencyformat = currencyformat;175 }else{176 if(this.percisionCbx.getValue()){177 numberformat += this.percisionSpinner.get('value').toString() + '|';178 }else{179 numberformat += '|';180 }181 if(this.useThousandsCbx.getValue()){182 numberformat += this.thousandsSymbol.get('value') + '|';183 }else{184 numberformat += '|';185 }186 if(this.percisionCbx.getValue()){187 numberformat += this.percisionSymbol.get('value');188 }189 this.returnfieldInfo.numberformat = numberformat;190 }191 }192 return this.returnfieldInfo;193 },194 _onPercisionCbxChange: function(){195 var pcbx = this.percisionCbx.getValue();196 this.percisionSpinner.set('disabled', !pcbx);197 this.percisionSymbol.set('disabled', !pcbx);198 },199 _onCurrencyCbxChange: function(){200 var ccbxv = this.currencyCbx.getValue();201 this.currencySymboltxt.set('disabled', !ccbxv);202 },203 _onUseThousandsCbxChange: function(){204 var utcbx = this.useThousandsCbx.getValue();205 this.thousandsSymbol.set('disabled', !utcbx);206 },207 _onSelectDateFormatChange: function(){208 if(this.selectDateFormat.get('value') === this.nls.custom){209 if(!this.returnfieldInfo.dateformat){210 this.dateFormat.set('value', this.nls.friendlyDatePattern);211 }212 this.dateFormat.set('disabled', false);213 } else {214 this.dateFormat.set('value', this.selectDateFormat.get('value'));215 if (!this.dateFormat.disabled){216 this.dateFormat.set('disabled', true);217 }218 }219 }220 });...

Full Screen

Full Screen

DescribeProcessResponse.js

Source:DescribeProcessResponse.js Github

copy

Full Screen

1var DescribeProcessResponse = BaseResponse.extend({2 init : function(wpsResponse) {3 this.responseDocument = wpsResponse;4 5 /*6 * empty process description7 */8 this.processOffering = new Object();9 10 /*11 * service and version12 */13 this.processOffering.service = "WPS";14 this.processOffering.version = "";15 16 /*17 * process18 */19 this.processOffering.process = new Object();20 this.processOffering.process.title = "";21 this.processOffering.process.abstractValue = "";22 this.processOffering.process.identifier = "";23 this.processOffering.process.inputs = new Array();24 this.processOffering.process.outputs = new Array();25 26 /*27 * attributes28 */29 this.processOffering.processVersion = "";30 this.processOffering.jobControlOptions = [];31 this.processOffering.outputTransmissionModes = [];32 33 this.instantiate(wpsResponse); 34 },35 36 instantiate: function(wpsResponse){37 /*38 * override this method in child classes to instantiate the object39 */40 },41 createLiteralDataInput : function(title, abstractValue, identifier,42 minOccurs, maxOccurs, formatArray, literalDataDomainArray) {43 var literalDataInput = new Object();44 this.instantiateCommonInputValues(title, abstractValue, identifier,45 minOccurs, maxOccurs, literalDataInput);46 //TODO what about metadata node?47 literalDataInput.literalData = new Object();48 literalDataInput.literalData.formats = formatArray;49 literalDataInput.literalData.literalDataDomains = literalDataDomainArray;50 51 return literalDataInput;52 },53 createComplexDataInput : function(title, abstractValue, identifier,54 minOccurs, maxOccurs, formatArray) {55 var complexDataInput = new Object();56 this.instantiateCommonInputValues(title, abstractValue, identifier,57 minOccurs, maxOccurs, complexDataInput);58 //TODO what about metadata node?59 complexDataInput.complexData = new Object();60 complexDataInput.complexData.formats = formatArray;61 62 return complexDataInput;63 },64 65 createBboxInput : function(title, abstractValue, identifier, minOccurs, 66 maxOccurs, formatArray, crsArray) {67 68 var bboxInput = new Object();69 70 this.instantiateCommonInputValues(title, abstractValue, identifier,71 minOccurs, maxOccurs, bboxInput);72 //TODO what about metadata node?73 bboxInput.boundingBoxData = new Object();74 bboxInput.boundingBoxData.formats = formatArray;75 76 bboxInput.boundingBoxData.supportedCRSs = crsArray;77 78 return bboxInput;79 },80 createFormat : function(mimeType, encoding, schema) {81 var format = new Object();82 format.mimeType = mimeType;83 format.encoding = encoding;84 format.schema = schema;85 return format;86 },87 instantiateCommonInputValues : function(title, abstractValue, identifier,88 minOccurs, maxOccurs, inputObject) {89 inputObject.title = title;90 inputObject.abstractValue = abstractValue;91 inputObject.identifier = identifier;92 inputObject.minOccurs = minOccurs;93 inputObject.maxOccurs = maxOccurs;94 },95 96 instantiateCommonOutputValues : function(title, abstractValue, identifier,97 outputObject){98 outputObject.title = title;99 outputObject.abstractValue = abstractValue;100 outputObject.identifier = identifier;101 },102 103 createLiteralDataOutput : function(title, abstractValue, identifier,104 formatArray, literalDataDomainArray) {105 var literalDataOutput = new Object();106 this.instantiateCommonOutputValues(title, abstractValue, identifier,107 literalDataOutput);108 //TODO what about metadata node?109 literalDataOutput.literalData = new Object();110 literalDataOutput.literalData.formats = formatArray;111 literalDataOutput.literalData.literalDataDomains = literalDataDomainArray;112 113 return literalDataOutput;114 },115 createComplexDataOutput : function(title, abstractValue, identifier,116 formatArray) {117 var complexDataOutput = new Object();118 this.instantiateCommonOutputValues(title, abstractValue, identifier,119 complexDataOutput);120 //TODO what about metadata node?121 complexDataOutput.complexData = new Object();122 complexDataOutput.complexData.formats = formatArray;123 124 return complexDataOutput;125 },126 127 createBboxOutput : function(title, abstractValue, identifier, 128 formatArray, crsArray) {129 130 var bboxOutput = new Object();131 132 this.instantiateCommonOutputValues(title, abstractValue, identifier,133 bboxOutput);134 //TODO what about metadata node?135 bboxOutput.boundingBoxData = new Object();136 bboxOutput.boundingBoxData.formats = formatArray;137 138 bboxOutput.boundingBoxData.supportedCRSs = crsArray;139 140 return bboxOutput;141 },...

Full Screen

Full Screen

regress-96526-delelem.js

Source:regress-96526-delelem.js Github

copy

Full Screen

...28f(2,1,[-1,0,[1,2,[3,4]]]);29function f(j,k,a)30{31 status = inSection(1);32 actual = formatArray(a[2]);33 expect = formatArray([1,2,[3,4]]);34 addThis();35 status = inSection(2);36 actual = formatArray(a[2][j]);37 expect = formatArray([3,4]);38 addThis();39 status = inSection(3);40 actual = a[2][j][k];41 expect = 4;42 addThis();43 status = inSection(4);44 actual = a[2][j][k][z];45 expect = 42;46 addThis();47 delete a[2][j][k];48 status = inSection(5);49 actual = formatArray(a[2][j]);50 expect = formatArray([3, ,]);51 addThis();52}53//-----------------------------------------------------------------------------54test();55//-----------------------------------------------------------------------------56function addThis()57{58 statusitems[UBound] = status;59 actualvalues[UBound] = actual;60 expectedvalues[UBound] = expect;61 UBound++;62}63function test()64{...

Full Screen

Full Screen

Api.js

Source:Api.js Github

copy

Full Screen

1import axios from 'axios'2// import Cookies from 'js-cookie'3import route from './config/route'4let stringformat = require('stringformat');5// let token = Cookies.get('token');6const config = {7 baseURL: route,8 headers: {9 'Content-Type': 'application/json',10 'Accept': 'application/json',11 // "Authorization": `Bearer ${token}`12 }13};14class Api {15 static get(url, formatArray) {16 let string = this.urlFormat(url, formatArray)17 return this.server.get(string).catch(err => err)18 }19 static delete(url, formatArray) {20 let string = this.urlFormat(url, formatArray)21 this.server.delete(string).catch(err => err)22 }23 static put(url, data) {24 return this.server.put(url, data).catch(err => err)25 }26 static post(url, data) {27 return this.server.post(url, data).catch(err => err)28 }29 static urlFormat(url, formatArray) {30 if (formatArray) {31 let array = [url, ...formatArray]32 let urls = stringformat.apply(this, array)33 return urls34 } else {35 return url36 }37 }38}39export class Http extends Api {40 static server = axios.create(config);...

Full Screen

Full Screen

app.js

Source:app.js Github

copy

Full Screen

1$(document).ready(function () {2 $("#submitButton").click(function () {3 var numbArray = $("#numArray").val();4 var kValString = $("#kVar").val();5 if(numbArray.includes(kValString)) {6 numbArray = numbArray.replace(kValString, '');7 }8 var kVal = parseInt($("#kVar").val());9 var formatArray = numbArray.split(",");10 formatArray.sort();11 12 formatArray = formatArray.filter(item => item);13 for (var i = 0, j = formatArray.length - 1; i < j;) {14 var sum = parseInt(formatArray[i]) + parseInt(formatArray[j]);15 if (sum < kVal) {16 i++;17 }18 19 else if (sum > kVal) {20 j--;21 }22 else {23 alert(formatArray[i] + ' and ' + formatArray[j] + ' are a sum of ' + kVal);24 return true;25 }26 }27 alert('Nothing in the number array are a sum of ' + kVal);28 return false;29 });...

Full Screen

Full Screen

graphql-formatter.test.js

Source:graphql-formatter.test.js Github

copy

Full Screen

1import { formatArray } from './graphql-formatter';2describe('GraphQL Formatter', () => {3 test('formatArray', () => {4 expect(formatArray(null)).toEqual('[]');5 expect(formatArray(undefined)).toEqual('[]');6 expect(formatArray([])).toEqual('[]');7 expect(formatArray([{ name: 'endDate', op: 'is null' }])).toEqual('[{name: "endDate", op: "is null"}]');8 expect(formatArray([{ name: 'createDate', direction: 'desc' }])).toEqual('[{name: "createDate", direction: "desc"}]');9 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('My First Test', function() {2 it('Does not do much!', function() {3 cy.contains('type').click()4 cy.url().should('include', '/commands/actions')5 cy.get('.action-email')6 .type('

Full Screen

Using AI Code Generation

copy

Full Screen

1Cypress._.formatArray(['foo', 'bar'])2Cypress._.formatArray(['foo', 'bar'])3Cypress._.formatArray(['foo', 'bar'])4Cypress._.formatArray(['foo', 'bar'])5Cypress._.formatArray(['foo', 'bar'])6Cypress._.formatArray(['foo', 'bar'])7Cypress._.formatArray(['foo', 'bar'])8Cypress._.formatArray(['foo', 'bar'])9Cypress._.formatArray(['foo', 'bar'])10Cypress._.formatArray(['foo', 'bar'])11Cypress._.formatArray(['foo', 'bar'])12Cypress._.formatArray(['foo', 'bar'])13Cypress._.formatArray(['foo', 'bar'])14Cypress._.formatArray(['foo', 'bar'])15Cypress._.formatArray(['

Full Screen

Using AI Code Generation

copy

Full Screen

1Cypress.Commands.add('formatArray', (data, key) => {2 return data.map((item) => {3 return item[key];4 });5});6Cypress.Commands.add('formatArray', (data, key) => {7 return data.map((item) => {8 return item[key];9 });10});11Cypress.Commands.add('formatArray', (data, key) => {12 return data.map((item) => {13 return item[key];14 });15});16Cypress.Commands.add('formatArray', (data, key) => {17 return data.map((item) => {18 return item[key];19 });20});21Cypress.Commands.add('formatArray', (data, key) => {22 return data.map((item) => {23 return item[key];24 });25});26Cypress.Commands.add('formatArray', (data, key) => {27 return data.map((item) => {28 return item[key];29 });30});31Cypress.Commands.add('formatArray', (data, key) => {32 return data.map((item) => {33 return item[key];34 });35});36Cypress.Commands.add('formatArray', (data, key) => {37 return data.map((item) => {38 return item[key];39 });40});41Cypress.Commands.add('formatArray', (data, key) => {42 return data.map((item) => {43 return item[key];44 });45});46Cypress.Commands.add('formatArray', (data, key) => {47 return data.map((item) => {48 return item[key];49 });50});51Cypress.Commands.add('formatArray', (data, key) => {

Full Screen

Using AI Code Generation

copy

Full Screen

1import {formatArray} from "cypress/support/index.js"2describe('My First Test', () => {3 it('Does not do much!', () => {4 expect(true).to.equal(true)5 })6 it('formats an array', () => {7 const formattedArr = formatArray(arr)8 })9})10My question is, why do I have to import the method in the test file? I thought the support file was automatically imported in every test file. Is there some way to make this work without importing the method in the test file?11cy.get('.css-1dbjc4n.r-1awozwy.r-1udh08x.r-1j3t67a.r-dnmrzs.r-1ny4l3l.r-1fneopy.r-o7ynqc.r-6416eg.r-lrvibr').should('contain', 'test')12cy.get('[data-testid="confirmation-dialog-title"]').should('contain', 'test')

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('test', () => {2 it('test', () => {3 cy.get('input[name="q"]').type('cypress')4 cy.get('[name="btnK"]').click()5 cy.get('h3').then((elements) => {6 const textArray = formatArray(elements)7 cy.log(textArray)8 })9 })10})11Cypress.Commands.add('formatArray', (elements) => {12 elements.each((index, element) => {13 })14})

Full Screen

Using AI Code Generation

copy

Full Screen

1cy.get('select').select('a', {force: true})2cy.get('select').select('a', {force: true}).invoke('val').then((val) => {cy.wrap(val).should('eq', 'a')})3cy.get('select').select('a', {force: true}).invoke('val').then((val) => {cy.wrap(val).should('eq', 'a')})4cy.get('select').select('a', {force: true}).invoke('val').then((val) => {cy.wrap(val).should('eq', 'a')})5cy.get('select').select('a', {force: true}).invoke('val').then((val) => {cy.wrap(val).should('eq', 'a')})6cy.get('select').select('a', {force: true}).invoke('val').then((val) => {cy.wrap(val).should('eq', 'a')})7cy.get('select').select('a', {force: true}).invoke('val').then((val) => {cy.wrap(val).should('eq', 'a')})8cy.get('select').select('a', {force: true}).invoke('val').then((val) => {cy.wrap(val).should('eq', 'a')})9cy.get('select').select('a', {force: true}).invoke('val').then((val) => {cy.wrap(val).should('eq', 'a')})10cy.get('select').select('a', {force: true}).invoke('val').then((val) => {cy.wrap(val).should('eq', 'a')})11cy.get('select').select('a', {force: true}).invoke('val').then((val) => {cy.wrap(val).should('eq', 'a')})12cy.get('select').select('a', {force: true})13cy.get('select').select('a', {force: true}).invoke('val').then((val) => {cy.wrap(val).should('eq', 'a')})14cy.get('select').select('a', {force: true}).invoke('val').then((val) => {cy.wrap(val).should('eq', 'a')})15cy.get('select').select('a', {force: true}).invoke('val').then((val) =>

Full Screen

Using AI Code Generation

copy

Full Screen

1Cypress.Commands.add('formatArray', (array) => {2 let table = '';3 const keys = Object.keys(array[0]);4 table += keys.join(' | ') + ' |';5 table += '\n';6 table += keys.map(() => '----').join(' | ') + ' |';7 table += '\n';8 for (let i = 0; i < array.length; i++) {9 for (let j = 0; j < keys.length; j++) {10 table += array[i][keys[j]] + ' | ';11 }12 table += '\n';13 }14 return table;15});16Cypress.Commands.add('formatArray', (array) => {17 let table = '';18 const keys = Object.keys(array[0]);19 table += keys.join(' | ') + ' |';20 table += '\n';21 table += keys.map(() => '----').join(' | ') + ' |';22 table += '\n';23 for (let i = 0; i < array.length; i++) {24 for (let j = 0; j < keys.length; j++) {25 table += array[i][keys[j]] + ' | ';26 }27 table += '\n';28 }29 return table;30});31Cypress.Commands.add('formatArray', (array) => {32 let table = '';33 const keys = Object.keys(array[0]);34 table += keys.join(' | ') + ' |';35 table += '\n';36 table += keys.map(() => '----').join(' | ') + ' |';37 table += '\n';38 for (let i = 0; i < array.length; i++) {39 for (let j = 0; j < keys.length; j++) {

Full Screen

Cypress Tutorial

Cypress is a renowned Javascript-based open-source, easy-to-use end-to-end testing framework primarily used for testing web applications. Cypress is a relatively new player in the automation testing space and has been gaining much traction lately, as evidenced by the number of Forks (2.7K) and Stars (42.1K) for the project. LambdaTest’s Cypress Tutorial covers step-by-step guides that will help you learn from the basics till you run automation tests on LambdaTest.

Chapters:

  1. What is Cypress? -
  2. Why Cypress? - Learn why Cypress might be a good choice for testing your web applications.
  3. Features of Cypress Testing - Learn about features that make Cypress a powerful and flexible tool for testing web applications.
  4. Cypress Drawbacks - Although Cypress has many strengths, it has a few limitations that you should be aware of.
  5. Cypress Architecture - Learn more about Cypress architecture and how it is designed to be run directly in the browser, i.e., it does not have any additional servers.
  6. Browsers Supported by Cypress - Cypress is built on top of the Electron browser, supporting all modern web browsers. Learn browsers that support Cypress.
  7. Selenium vs Cypress: A Detailed Comparison - Compare and explore some key differences in terms of their design and features.
  8. Cypress Learning: Best Practices - Take a deep dive into some of the best practices you should use to avoid anti-patterns in your automation tests.
  9. How To Run Cypress Tests on LambdaTest? - Set up a LambdaTest account, and now you are all set to learn how to run Cypress tests.

Certification

You can elevate your expertise with end-to-end testing using the Cypress automation framework and stay one step ahead in your career by earning a Cypress certification. Check out our Cypress 101 Certification.

YouTube

Watch this 3 hours of complete tutorial to learn the basics of Cypress and various Cypress commands with the Cypress testing at LambdaTest.

Run Cypress automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful