App.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <template>
  2. <div class="app">
  3. <main-header></main-header>
  4. <home-body v-if="home.visible"></home-body>
  5. <station-body v-if="station.visible"></station-body>
  6. <main-footer></main-footer>
  7. </div>
  8. </template>
  9. <script>
  10. import MainHeader from './MainHeader.vue'
  11. import HomeBody from './HomeBody.vue'
  12. import StationBody from './StationBody.vue'
  13. import MainFooter from './MainFooter.vue'
  14. export default {
  15. data() {
  16. return {
  17. home: {
  18. visible: true
  19. },
  20. station: {
  21. visible: false
  22. },
  23. register: {
  24. email: "",
  25. username: "",
  26. password: ""
  27. },
  28. login: {
  29. email: "",
  30. password: ""
  31. },
  32. loggedIn: true
  33. }
  34. },
  35. methods: {
  36. goHome() {
  37. this.home.visible = true;
  38. for (let i = 0; i < this.length; i++) {
  39. this[i].visible = false;
  40. }
  41. },
  42. logout() {
  43. $.ajax({
  44. method: "GET",
  45. url: "/users/logout",
  46. dataType: "json",
  47. complete: function (msg) {
  48. console.log(1, msg);
  49. alert("Logged out!");
  50. //do something
  51. location.reload();
  52. }
  53. });
  54. }
  55. },
  56. ready: function () {
  57. this.socket = io();
  58. this.socket.on("ready", function(loggedIn) {
  59. this.loggedIn = loggedIn;
  60. });
  61. },
  62. components: { MainHeader, HomeBody, StationBody, MainFooter },
  63. events: {
  64. 'switchView': function(hide, show) {
  65. this[hide].visible = false;
  66. this[show].visible = true;
  67. },
  68. 'register': function() {
  69. console.log('registered');
  70. $.ajax({
  71. method: "POST",
  72. url: "/users/register",
  73. data: JSON.stringify({
  74. email: this.register.email,
  75. username: this.register.username,
  76. password: this.register.password,
  77. recaptcha: grecaptcha.getResponse()
  78. }),
  79. contentType: "application/json; charset=utf-8",
  80. dataType: "json",
  81. success: function (msg) {
  82. console.log(1, msg);
  83. alert("Registered!");
  84. //do something
  85. },
  86. error: function (errormessage) {
  87. console.log(2, errormessage);
  88. alert("Not registered!");
  89. //do something else
  90. }
  91. });
  92. },
  93. 'login': function() {
  94. console.log('login');
  95. $.ajax({
  96. method: "POST",
  97. url: "/users/login",
  98. data: JSON.stringify({
  99. email: this.login.email,
  100. password: this.login.password
  101. }),
  102. contentType: "application/json; charset=utf-8",
  103. dataType: "json",
  104. success: function (msg) {
  105. console.log(1, msg);
  106. alert("Logged in!");
  107. //do something
  108. location.reload();
  109. },
  110. error: function (errormessage) {
  111. console.log(2, errormessage);
  112. alert("Not logged in!");
  113. //do something else
  114. }
  115. });
  116. }
  117. }
  118. }
  119. </script>
  120. <style lang="sass">
  121. * { box-sizing: border-box; font-family: Roboto, sans-serif; }
  122. html {
  123. width: 100%;
  124. height: 100%;
  125. color: rgba(0, 0, 0, 0.87);
  126. body {
  127. width: 100%;
  128. height: 100%;
  129. margin: 0;
  130. padding: 0;
  131. }
  132. }
  133. @media only screen and (min-width: 1200px) {
  134. html {
  135. font-size: 15px;
  136. }
  137. }
  138. @media only screen and (min-width: 992px) {
  139. html {
  140. font-size: 14.5px;
  141. }
  142. }
  143. @media only screen and (min-width: 0) {
  144. html {
  145. font-size: 14px;
  146. }
  147. }
  148. </style>