需求介绍:
实现考场座位号随机排布,1-30号,按照 7,8,8,7排布。 第一排左边是窗口,右边是门口。
设计思路
-
核心代码是座位号随机。
-
脚本主要有三个:
- 主界面
- 座位组件
- 一排座位组件
- git地址:
代码摘要:
随机座位号
getRandomNumbers: function (bottom, top) {
// 有效数字判断
if (!isFinite(bottom) || isNaN(bottom)) return
if (!isFinite(top) || isNaN(top)) return
let max = Math.max(bottom, top)
let min = Math.min(bottom, top)
let arr = new Array(max - min + 1);
let index = 0;
arr[index] = min;
for (let i = min; i <= max; i++) {
let rnd = Math.floor(Math.random() * (index + 1));
arr[index] = arr[rnd];
arr[rnd] = i;
index++;
}
return arr
}