random-roll-call.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <template>
  2. <el-dialog :visible.sync="show" title="随机点名" custom-class="content" center :close-on-click-modal="false"
  3. style="background-color: #00142f63;backdrop-filter: blur(4px);" width="640px">
  4. <view style="min-height: 250px;" class="ui-flex-center ui-flex-row">
  5. <view class="text-center user-item" v-for="(item, index) in viewList" :key="item.id">
  6. <el-avatar :size="70" :src="item.student_cartoon_photo"></el-avatar>
  7. <view class="f34 text-center txt-white">{{item.title}}</view>
  8. </view>
  9. </view>
  10. <view class="text-center ui-mt40">
  11. <el-input-number v-model="num" :min="1" label="确认人数"></el-input-number>
  12. <el-button class="ui-ml20" type="" @click="makeRandom">确认人数</el-button>
  13. <el-button class="ui-ml20" type="primary" @click="$emit('comment', checkList)">批量点评</el-button>
  14. </view>
  15. </el-dialog>
  16. </template>
  17. <script>
  18. export default {
  19. props: {
  20. list: {},
  21. },
  22. data() {
  23. return {
  24. show: false,
  25. num: 3,
  26. checkList: []
  27. }
  28. },
  29. computed: {
  30. viewList() {
  31. let list = [];
  32. for (var i = 0; i < this.num; i++) {
  33. if (this.checkList[i]) {
  34. list.push(this.checkList[i])
  35. } else {
  36. list.push({
  37. id: i,
  38. student_cartoon_photo: 'https://zhxy.obs.cn-hz1.ctyun.cn/static/student_icon/B6.png',
  39. title: '匿名'
  40. })
  41. }
  42. }
  43. return list;
  44. }
  45. },
  46. methods: {
  47. open() {
  48. this.show = true;
  49. },
  50. makeRandom() {
  51. let max = this.list.length - 1;
  52. let numList = this.generateUniqueRandomNumbers(this.num, 0, max);
  53. this.checkList = [];
  54. this.viewList.forEach((item, index) => {
  55. setTimeout(() => {
  56. this.checkList.push(this.list[numList[index]])
  57. }, 40 * index);
  58. })
  59. },
  60. // 生成随机数
  61. makeRandomNum(max) {
  62. let min = 1;
  63. return Math.floor(Math.random() * (max - min + 1)) + min;
  64. },
  65. // 生成不同数值的随机数
  66. generateUniqueRandomNumbers(count, min, max) {
  67. let result = [];
  68. while (result.length < count) {
  69. let randomNum = Math.floor(Math.random() * (max - min + 1)) + min;
  70. if (result.indexOf(randomNum) === -1) {
  71. result.push(randomNum);
  72. }
  73. }
  74. return result;
  75. },
  76. }
  77. }
  78. </script>
  79. <style>
  80. /deep/ .content {
  81. background-image: url('https://zhxy.obs.cn-hz1.ctyun.cn:443/static/desk_bg/class_bj.jpg');
  82. background-size: auto;
  83. border: 1px solid #0d5396;
  84. }
  85. /deep/ .el-dialog__header {
  86. background: #022c5a80;
  87. border-bottom: 2px solid #051d37;
  88. }
  89. /deep/ .el-dialog__title {
  90. color: #fff;
  91. }
  92. /deep/ .el-dialog__body {
  93. background-color: rgba(255, 255, 255, .12);
  94. }
  95. .user-item {
  96. /* float: left; */
  97. margin: 20px;
  98. }
  99. </style>