| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- ////////////////////////////////////////////////////////////////////////////
- // System Pre-define Functions
- // 95099372-ef3e-11ea-9c81-bf848405c62e
- function OnInitializeData() {
- OnMulti();
- }
- function OnCloseForm() {
- }
- function OnException(err) {
- //ui.MessageBox('Error', '' + err, MessageBox.Icon.Critical, MessageBox.Button.Ok);
- }
- //////////////////////////////////////////////////////////////////////////
- // Callback Functions.
- // 641a254c-ef3e-11ea-bc8a-379bb908bdd7
- var g_studengs = [
- '汤鹏强',
- '沈佳琦',
- '李思翰',
- '张博铭#',
- '闫凯秀',
- '郭伟鹏',
- '刘帆',
- '王旭',
- '李丰冶',
- '桂董圆',
- '吴冠龙',
- '汪宇飞',
- '程果',
- '赵骏豪',
- '黄超',
- '刘佳强',
- '王骏杰',
- '陈立浩',
- '赵新晨',
- '王馨珞*',
- '马宇翔',
- '张宇',
- '杨永泉'
- ];
- function getRandomArrayElements(arr, count) {
- var shuffled = arr.slice(0),
- i = arr.length,
- min = i - count,
- temp, index;
- while (i-- > min) {
- index = Math.floor((i + 1) * Math.random());
- temp = shuffled[index];
- shuffled[index] = shuffled[i];
- shuffled[i] = temp;
- }
- return shuffled.slice(min);
- }
- function callStudent(num) {
- var students = getRandomArrayElements(g_studengs, num);
- ui.list.table = [
- ['姓名']
- ].concat((students.map(item => {
- return [item];
- })));
- var idx = 0;
- var colors = students.map(item => { //@item.@String colors.@Array
- if (item.indexOf('*') !== -1) {return [idx++, 0, '#00FF00'];}
- if (item.indexOf('#') !== -1) {return [idx++, 0, '#00FFFF'];}
- return [idx++, 0, '#FFFF00'];
- });
- colors.forEach(item => {
- ui.list.color = item;
- });
- ui.list.head_size = [0];
- }
- function OnSingle() {
- callStudent(1);
- ui.label.value = "<span style='color:blue'><h1><b>" + ui.list.table[1][0] + "</h1></b></span>";
- ui.index.index = 1;
- }
- function OnMulti() {
- callStudent(8);
- ui.index.index = 0;
- }
- function OnAbsent() {
- var name; //存储未到的学生
- // 提问模式:点击“未到”按钮使学生姓名变为红色
- if (ui.index.index === 1) {
- var name = ui.list.table?.[1]?.[0]; // 获取第1行第0列的姓名(提问学生)
- ui.label.value = "<span style='color:red'><h1><b>" + name + "</b></h1></span>";
- name = ui.list.table?.[1]?.[0];
- } else { // 点名模式:点击“未到”按钮标红对应学生姓名
- var selectedRow = ui.list.row; //获取选择的学生行数
- if (selectedRow === -1) {
- ui.MessageBox("提示", "未选中任何学生,无法标记为未到", MessageBox.Icon.Warning, MessageBox.Button.Ok);
- return;
- }
- name = ui.list.table?.[selectedRow+1]?.[0]; //表头索引为0
- if (name) {
- ui.list.color = [selectedRow, 0, "#FF0000"];
- }
- }
- if (name) {
- model.AddAbsentStudent(name);
- }
- }
- function OnSaveAbsent() {
- var filepath = model.ExportAbsentStudents();
- if (filepath) {
- ui.MessageBox("导出成功", "名单已保存至:" + filepath, MessageBox.Icon.Information, MessageBox.Button.Ok);
- model.ClearAbsentList(); // 导出后清空
- } else {
- ui.MessageBox("提示", "未标记任何学生为未到,无法导出", MessageBox.Icon.Warning, MessageBox.Button.Ok);
- }
- }
- //////////////////////////////////////////////////////////////////////////
- // Utils Functions.
- // 6c165ad6-ef3e-11ea-987c-b761a131c2fe
- /*Usage of BLOCK_EVENT
- BLOCK_EVENT(()=>{
- ui.[name].[var] = ...;
- });
- */
- function BLOCK_EVENT(cb) {
- ui.block_event = true;
- cb();
- ui.block_event = false;
- }
|