Start.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <template>
  2. <div class="start">
  3. <form>
  4. <FormInput class="start-input" v-model="code" placeholder="房间密码"></FormInput>
  5. <FormRadio class="start-radio" v-model="identity" :list="list"></FormRadio>
  6. <div>
  7. <button class="start-button" @click.prevent="onSubmit">进入房间</button>
  8. <button class="start-button" @click.prevent="onToWords">添加新词</button>
  9. </div>
  10. <p class="start-tip">分<span class="red">红</span><span class="blue">蓝</span>两队,<span class="blue">蓝队</span>9个,<span class="red">红队</span>8个,所以<span class="blue">蓝队</span><strong>优先</strong>开始</p>
  11. </form>
  12. </div>
  13. </template>
  14. <script>
  15. import FormInput from '@/components/FormInput'
  16. import FormRadio from '@/components/FormRadio'
  17. import http from '@/http'
  18. export default {
  19. name: 'start',
  20. components: {
  21. FormInput,
  22. FormRadio
  23. },
  24. data() {
  25. return {
  26. code: '',
  27. identity: 'spy',
  28. list: [
  29. {
  30. label: '间谍',
  31. value: 'spy'
  32. },
  33. {
  34. label: '间谍头目',
  35. value: 'captain'
  36. }
  37. ]
  38. }
  39. },
  40. methods: {
  41. async onSubmit() {
  42. const { code: inputCode, identity } = this
  43. if (!inputCode) {
  44. alert('请输入房间密码')
  45. return
  46. } else if (!identity) {
  47. alert('请选择身份')
  48. return
  49. }
  50. const { code, data = [] } = await http.get('/api/list', { code: inputCode })
  51. this.$store.commit('SET_LIST', data)
  52. this.$store.commit('SET_CODE', code)
  53. this.$store.commit('SET_IDENTITY', identity)
  54. this.$emit('game')
  55. },
  56. onToWords() {
  57. this.$router.push('/words')
  58. }
  59. }
  60. }
  61. </script>
  62. <style lang="scss" scoped>
  63. .start {
  64. display: flex;
  65. justify-content: center;
  66. align-items: center;
  67. height: 100%;
  68. form {
  69. display: flex;
  70. justify-content: center;
  71. align-items: center;
  72. flex-direction: column;
  73. width: 90%;
  74. min-width: 300px;
  75. max-width: 800px;
  76. margin-top: -50px;
  77. }
  78. .start-input {
  79. width: 80%;
  80. max-width: 400px;
  81. }
  82. .start-radio {
  83. width: 80%;
  84. max-width: 400px;
  85. }
  86. .start-button {
  87. outline: none;
  88. border: none;
  89. background-color: #409EFF;
  90. color: #fff;
  91. border-radius: 5px;
  92. padding: 5px 15px;
  93. font-size: 16px;
  94. margin: 0 10px;
  95. }
  96. .start-tip {
  97. .red {
  98. color: red;
  99. }
  100. .blue {
  101. color: #409EFF;
  102. }
  103. }
  104. }
  105. </style>