微信小程序实现考场座位号随机

447 阅读1分钟

random_seat.jpg

需求介绍:

实现考场座位号随机排布,1-30号,按照 7,8,8,7排布。 第一排左边是窗口,右边是门口。

设计思路

  1. 核心代码是座位号随机。

  2. 脚本主要有三个:

  • 主界面
  • 座位组件
  • 一排座位组件
  1. git地址:

e.coding.net/dtid_4a3b08…

代码摘要:

随机座位号

  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
  }