mainfrm_pane.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. ////////////////////////////////////////////////////////////////////////////
  2. // System Pre-define Functions
  3. // 95099372-ef3e-11ea-9c81-bf848405c62e
  4. function OnInitializeData() {
  5. OnMulti();
  6. }
  7. function OnCloseForm() {
  8. }
  9. function OnException(err) {
  10. //ui.MessageBox('Error', '' + err, MessageBox.Icon.Critical, MessageBox.Button.Ok);
  11. }
  12. //////////////////////////////////////////////////////////////////////////
  13. // Callback Functions.
  14. // 641a254c-ef3e-11ea-bc8a-379bb908bdd7
  15. var g_studengs = [
  16. '汤鹏强',
  17. '沈佳琦',
  18. '李思翰',
  19. '张博铭#',
  20. '闫凯秀',
  21. '郭伟鹏',
  22. '刘帆',
  23. '王旭',
  24. '李丰冶',
  25. '桂董圆',
  26. '吴冠龙',
  27. '汪宇飞',
  28. '程果',
  29. '赵骏豪',
  30. '黄超',
  31. '刘佳强',
  32. '王骏杰',
  33. '陈立浩',
  34. '赵新晨',
  35. '王馨珞*',
  36. '马宇翔',
  37. '张宇',
  38. '杨永泉'
  39. ];
  40. function getRandomArrayElements(arr, count) {
  41. var shuffled = arr.slice(0),
  42. i = arr.length,
  43. min = i - count,
  44. temp, index;
  45. while (i-- > min) {
  46. index = Math.floor((i + 1) * Math.random());
  47. temp = shuffled[index];
  48. shuffled[index] = shuffled[i];
  49. shuffled[i] = temp;
  50. }
  51. return shuffled.slice(min);
  52. }
  53. function callStudent(num) {
  54. var students = getRandomArrayElements(g_studengs, num);
  55. ui.list.table = [
  56. ['姓名']
  57. ].concat((students.map(item => {
  58. return [item];
  59. })));
  60. var idx = 0;
  61. var colors = students.map(item => { //@item.@String colors.@Array
  62. if (item.indexOf('*') !== -1) {return [idx++, 0, '#00FF00'];}
  63. if (item.indexOf('#') !== -1) {return [idx++, 0, '#00FFFF'];}
  64. return [idx++, 0, '#FFFF00'];
  65. });
  66. colors.forEach(item => {
  67. ui.list.color = item;
  68. });
  69. ui.list.head_size = [0];
  70. }
  71. function OnSingle() {
  72. callStudent(1);
  73. ui.label.value = "<span style='color:blue'><h1><b>" + ui.list.table[1][0] + "</h1></b></span>";
  74. ui.index.index = 1;
  75. }
  76. function OnMulti() {
  77. callStudent(8);
  78. ui.index.index = 0;
  79. }
  80. function OnAbsent() {
  81. var name; //存储未到的学生
  82. // 提问模式:点击“未到”按钮使学生姓名变为红色
  83. if (ui.index.index === 1) {
  84. var name = ui.list.table?.[1]?.[0]; // 获取第1行第0列的姓名(提问学生)
  85. ui.label.value = "<span style='color:red'><h1><b>" + name + "</b></h1></span>";
  86. name = ui.list.table?.[1]?.[0];
  87. } else { // 点名模式:点击“未到”按钮标红对应学生姓名
  88. var selectedRow = ui.list.row; //获取选择的学生行数
  89. if (selectedRow === -1) {
  90. ui.MessageBox("提示", "未选中任何学生,无法标记为未到", MessageBox.Icon.Warning, MessageBox.Button.Ok);
  91. return;
  92. }
  93. name = ui.list.table?.[selectedRow+1]?.[0]; //表头索引为0
  94. if (name) {
  95. ui.list.color = [selectedRow, 0, "#FF0000"];
  96. }
  97. }
  98. if (name) {
  99. model.AddAbsentStudent(name);
  100. }
  101. }
  102. function OnSaveAbsent() {
  103. var filepath = model.ExportAbsentStudents();
  104. if (filepath) {
  105. ui.MessageBox("导出成功", "名单已保存至:" + filepath, MessageBox.Icon.Information, MessageBox.Button.Ok);
  106. model.ClearAbsentList(); // 导出后清空
  107. } else {
  108. ui.MessageBox("提示", "未标记任何学生为未到,无法导出", MessageBox.Icon.Warning, MessageBox.Button.Ok);
  109. }
  110. }
  111. //////////////////////////////////////////////////////////////////////////
  112. // Utils Functions.
  113. // 6c165ad6-ef3e-11ea-987c-b761a131c2fe
  114. /*Usage of BLOCK_EVENT
  115. BLOCK_EVENT(()=>{
  116. ui.[name].[var] = ...;
  117. });
  118. */
  119. function BLOCK_EVENT(cb) {
  120. ui.block_event = true;
  121. cb();
  122. ui.block_event = false;
  123. }