gamemanage.vue 6.52 KB
Newer Older
孙谢炜's avatar
孙谢炜 committed
1
<template>
孙谢炜's avatar
孙谢炜 committed
2 3 4 5 6 7 8 9
  <div class="text-h4 headline">
    比赛管理
  </div>
  <v-card class="game-info-card">
    <v-container>
      <!-- <v-card-title color="indigo">
      提交比赛
    </v-card-title> -->
10
      <v-form ref="form" v-model="isValid">
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
          <v-row no-gutters>
            <v-col align-self="center">
              <v-autocomplete variant="underlined" v-model="player1" label="姓名"
                :rules="[rules.player_not_none, rules.player1]" :items="arr"></v-autocomplete>
            </v-col>
            <v-col cols="2" align-self="center">
              <div class="text-h6" style="text-align: center;">VS</div>
            </v-col>
            <v-col align-self="center">
              <v-autocomplete variant="underlined" v-model="player2" label="姓名"
                :rules="[rules.player_not_none, rules.player2]" :items="arr"></v-autocomplete>
            </v-col>
          </v-row>
          <v-row no-gutters>
            <v-col align-self="center">
              <v-select variant="underlined" v-model="score1" label="得分" :rules="[rules.score_not_none, rules.score1]"
                :items="['0', '1', '2', '3', '4', '5']"></v-select>
            </v-col>
            <v-col cols="2" align-self="center">
              <div class="text-h6" style="text-align: center;">:</div>
            </v-col>
            <v-col align-self="center">
              <v-select variant="underlined" v-model="score2" label="得分" :rules="[rules.score_not_none, rules.score2]"
                :items="['0', '1', '2', '3', '4', '5']"></v-select>
            </v-col>
          </v-row>
sunxiwei's avatar
sunxiwei committed
37 38
        <v-dialog>
          <template v-slot:activator="{ props: activatorProps }">
sunxiwei's avatar
sunxiwei committed
39
            <v-btn block v-bind="activatorProps" class="text-none mb-4" color="indigo" size="large" variant="outlined">
sunxiwei's avatar
sunxiwei committed
40
              <template v-slot:default>
sunxiwei's avatar
sunxiwei committed
41
                选择比赛日期:{{ selectedDate.toLocaleDateString() }}
sunxiwei's avatar
sunxiwei committed
42 43 44 45 46 47
              </template>
            </v-btn>
          </template>

          <template v-slot:default="{ isActive }">
            <v-card>
sunxiwei's avatar
sunxiwei committed
48 49 50 51
              <v-locale-provider locale="zhHans">
                <v-date-picker v-model="selectedDate" header="日期" title="选择比赛日期" color="indigo"
                  width="100%"></v-date-picker>
              </v-locale-provider>
sunxiwei's avatar
sunxiwei committed
52 53 54 55 56 57 58 59 60 61 62 63
              <v-card-actions>
                <v-spacer></v-spacer>
                <v-btn variant="flat" text="确定" color="indigo" @click="isActive.value = false"></v-btn>
              </v-card-actions>
            </v-card>
          </template>
        </v-dialog>
        <v-btn :disabled="!isValid" :loading="loading" class="text-none mb-4" color="indigo" size="large" variant="flat"
          block @click="submit">
          提交
        </v-btn>
      </v-form>
孙谢炜's avatar
孙谢炜 committed
64 65 66 67
    </v-container>

  </v-card>

sunxiwei's avatar
sunxiwei committed
68 69 70 71 72 73 74 75 76 77 78 79 80
  <v-dialog v-model="dialog" width="auto">
    <v-card width="300px">
      <v-card-title>
        {{ cardtitle }}
      </v-card-title>
      <v-card-text>
        {{ cardtext }}
      </v-card-text>
      <template v-slot:actions>
        <v-btn class="ms-auto" variant="flat" color="indigo" text="确认" @click="dialog = false"></v-btn>
      </template>
    </v-card>
  </v-dialog>
孙谢炜's avatar
孙谢炜 committed
81 82

  <div>
sunxiwei's avatar
sunxiwei committed
83
    <v-card class="mx-auto my-2" href="/lauched_games.html" width="95%" rel="noopener" target="_blank" title="已提交比赛"
孙谢炜's avatar
孙谢炜 committed
84
      append-icon="mdi-chevron-right"></v-card>
sunxiwei's avatar
sunxiwei committed
85
    <v-card class="mx-auto my-2" href="/audit_games.html" width="95%" rel="noopener" target="_blank" title="待审核比赛"
孙谢炜's avatar
孙谢炜 committed
86
      append-icon="mdi-chevron-right"></v-card>
孙谢炜's avatar
孙谢炜 committed
87 88 89 90 91 92
  </div>

</template>

<script setup>
import { ref } from 'vue';
sunxiwei's avatar
sunxiwei committed
93 94
import { reactive } from 'vue';
import axios from 'axios';
95
import { watch } from 'vue';
孙谢炜's avatar
孙谢炜 committed
96

sunxiwei's avatar
sunxiwei committed
97
const isValid = ref(false);
孙谢炜's avatar
孙谢炜 committed
98 99 100 101 102
const player1 = ref(null);
const player2 = ref(null);
const score1 = ref(null);
const score2 = ref(null);
const loading = ref(false);
sunxiwei's avatar
sunxiwei committed
103
const selectedDate = ref(new Date());
sunxiwei's avatar
sunxiwei committed
104 105
const arr = ref(new Array());
const id = ref(null);
106
const form = ref(null);
107 108
const form1 = ref(null);
const form2 = ref(null);
sunxiwei's avatar
sunxiwei committed
109 110 111 112 113 114
var s1;
var s2;
var p1_id;
var p2_id;


sunxiwei's avatar
sunxiwei committed
115 116 117 118

const rules = reactive({
  email: v => !!(v || '').match(/@/) || 'Please enter a valid email',
  length: len => v => (v || '').length >= len || `Invalid character length, required ${len}`,
sunxiwei's avatar
sunxiwei committed
119 120 121 122 123

  player_not_none: v => !!v || '姓名不能为空',
  player1: v => v != player2.value || '姓名不能相同',
  player2: v => v != player1.value || '姓名不能相同',

sunxiwei's avatar
sunxiwei committed
124
  required: v => !!v || 'This field is required',
sunxiwei's avatar
sunxiwei committed
125 126 127
  score_not_none: v => !!v || '得分不能为空',
  score1: v => v != score2.value || '得分不能相同',
  score2: v => v != score1.value || '得分不能相同',
sunxiwei's avatar
sunxiwei committed
128 129
});

130 131
// 监听 player1 的变化,并更新 player2 的验证规则
watch(player1, (newVal, oldVal) => {
132 133 134
    if (newVal !== oldVal) {
      form.value.validate(); // 触发表单验证
    }
135 136 137
});

watch(player2, (newVal, oldVal) => {
138 139 140
    if (newVal !== oldVal) {
      form.value.validate(); // 触发表单验证
    }
141 142 143
});

watch(score1, (newVal, oldVal) => {
144 145 146
    if (newVal !== oldVal) {
      form.value.validate(); // 触发表单验证
    }
147 148 149
});

watch(score2, (newVal, oldVal) => {
150 151 152
    if (newVal !== oldVal) {
      form.value.validate(); // 触发表单验证
    }
153 154
});

sunxiwei's avatar
sunxiwei committed
155 156 157 158 159 160 161 162 163
axios.get('/api/players')
  .then(function (response) {
    const data = response.data;
    for (var i = 0; i < data.Players.length; i++) {
      arr.value[i] = data.Players[i].player_id.toString() + '-' + data.Players[i].player_real_name;
    }
  })
  .catch(function (error) {
    console.log(error);
sunxiwei's avatar
sunxiwei committed
164 165
  })

sunxiwei's avatar
sunxiwei committed
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
function submit() {
  loading.value = true;
  p1_id = parseInt(player1.value);
  p2_id = parseInt(player2.value);
  s1 = parseInt(score1.value);
  s2 = parseInt(score2.value);
  if (s1 < s2) {
    id.value = p1_id;
  }
  else {
    id.value = p2_id;
  }
  axios.post('/api/launchGame', {
    player1_id: p1_id,
    score1: s1,
    player2_id: p2_id,
    score2: s2,
    confirmer_id: id.value,
    game_date: selectedDate.value.toLocaleDateString(),
sunxiwei's avatar
sunxiwei committed
185 186
  })
    .then(function (response) {
sunxiwei's avatar
sunxiwei committed
187 188 189 190 191
      const data = response.data;
      console.log(data)
      if (data.status == 'SUCCESS') {
        info('提交成功!', "");
      }
sunxiwei's avatar
sunxiwei committed
192 193 194 195 196 197
    })
    .catch(function (error) {
      console.log(error);
    });
  loading.value = false;
}
孙谢炜's avatar
孙谢炜 committed
198 199


sunxiwei's avatar
sunxiwei committed
200 201 202 203 204 205 206 207 208
const cardtitle = ref(null);
const cardtext = ref(null);
const dialog = ref(false);
function info(title, text) {
  cardtitle.value = title;
  cardtext.value = text;
  dialog.value = true;
}

孙谢炜's avatar
孙谢炜 committed
209
</script>
孙谢炜's avatar
孙谢炜 committed
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226

<style>
.game-info-card {
  width: 95%;
  margin: auto;
  margin-top: 20px;
  /* padding: 5px; */
}

.headline {
  margin-left: 5%;
  margin-top: 5%;
  margin-bottom: 2%;


}
</style>