login.html 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. {{template "head" .}}
  4. <style>
  5. #app {
  6. padding-top: 100px;
  7. }
  8. h1 {
  9. text-align: center;
  10. color: #fff;
  11. margin: 20px 0 50px 0;
  12. }
  13. .ant-btn, .ant-input {
  14. height: 50px;
  15. border-radius: 30px;
  16. }
  17. .ant-input-group-addon {
  18. border-radius: 0 30px 30px 0;
  19. width: 50px;
  20. font-size: 18px;
  21. }
  22. .ant-input-affix-wrapper .ant-input-prefix {
  23. left: 23px;
  24. }
  25. .ant-input-affix-wrapper .ant-input:not(:first-child) {
  26. padding-left: 50px;
  27. }
  28. .centered {
  29. display: flex;
  30. text-align: center;
  31. align-items: center;
  32. justify-content: center;
  33. }
  34. .title {
  35. font-size: 32px;
  36. font-weight: bold;
  37. }
  38. </style>
  39. <body>
  40. <a-layout id="app" v-cloak :class="themeSwitcher.darkClass">
  41. <transition name="list" appear>
  42. <a-layout-content>
  43. <a-row type="flex" justify="center">
  44. <a-col :xs="22" :sm="20" :md="16" :lg="12" :xl="8">
  45. <h1 class="title">{{ i18n "pages.login.title" }}</h1>
  46. </a-col>
  47. </a-row>
  48. <a-row type="flex" justify="center">
  49. <a-col :xs="22" :sm="20" :md="16" :lg="12" :xl="8">
  50. <a-form>
  51. <a-form-item>
  52. <a-input v-model.trim="user.username" placeholder='{{ i18n "username" }}'
  53. @keydown.enter.native="login" autofocus>
  54. <a-icon slot="prefix" type="user" :style="'font-size: 16px;' + themeSwitcher.textStyle" />
  55. </a-input>
  56. </a-form-item>
  57. <a-form-item>
  58. <password-input icon="lock" v-model.trim="user.password"
  59. placeholder='{{ i18n "password" }}' @keydown.enter.native="login">
  60. </password-input>
  61. </a-form-item>
  62. <a-form-item v-if="secretEnable">
  63. <password-input icon="key" v-model.trim="user.loginSecret"
  64. placeholder='{{ i18n "secretToken" }}' @keydown.enter.native="login">
  65. </password-input>
  66. </a-input>
  67. </a-form-item>
  68. <a-form-item>
  69. <a-row justify="center" class="centered">
  70. <a-button type="primary" :loading="loading" @click="login" :icon="loading ? 'poweroff' : undefined"
  71. :style="loading ? { width: '50px' } : { display: 'block', width: '100%' }">
  72. [[ loading ? '' : '{{ i18n "login" }}' ]]
  73. </a-button>
  74. </a-row>
  75. </a-form-item>
  76. <a-form-item>
  77. <a-row justify="center" class="centered">
  78. <a-col :span="12">
  79. <a-select ref="selectLang" v-model="lang" @change="setLang(lang)" :dropdown-class-name="themeSwitcher.darkCardClass">
  80. <a-select-option :value="l.value" label="English" v-for="l in supportLangs">
  81. <span role="img" aria-label="l.name" v-text="l.icon"></span>
  82. &nbsp;&nbsp;<span v-text="l.name"></span>
  83. </a-select-option>
  84. </a-select>
  85. </a-col>
  86. </a-row>
  87. </a-form-item>
  88. <a-form-item>
  89. <a-row justify="center" class="centered">
  90. <theme-switch />
  91. </a-row>
  92. </a-form-item>
  93. </a-form>
  94. </a-col>
  95. </a-row>
  96. </a-layout-content>
  97. </transition>
  98. </a-layout>
  99. {{template "js" .}}
  100. {{template "component/themeSwitcher" .}}
  101. {{template "component/password" .}}
  102. <script>
  103. const app = new Vue({
  104. delimiters: ['[[', ']]'],
  105. el: '#app',
  106. data: {
  107. themeSwitcher,
  108. loading: false,
  109. user: new User(),
  110. secretEnable: false,
  111. lang: ""
  112. },
  113. async created() {
  114. this.updateBackground();
  115. this.lang = getLang();
  116. this.secretEnable = await this.getSecretStatus();
  117. },
  118. methods: {
  119. async login() {
  120. this.loading = true;
  121. const msg = await HttpUtil.post('/login', this.user);
  122. this.loading = false;
  123. if (msg.success) {
  124. location.href = basePath + 'panel/';
  125. }
  126. },
  127. async getSecretStatus() {
  128. this.loading = true;
  129. const msg = await HttpUtil.post('/getSecretStatus');
  130. this.loading = false;
  131. if (msg.success) {
  132. this.secretEnable = msg.obj;
  133. return msg.obj;
  134. }
  135. },
  136. updateBackground() {
  137. const leftColor = RandomUtil.randomIntRange(0x222222, 0xFFFFFF / 2).toString(16);
  138. const rightColor = RandomUtil.randomIntRange(0xFFFFFF / 2, 0xDDDDDD).toString(16);
  139. const deg = RandomUtil.randomIntRange(0, 360);
  140. const background = `linear-gradient(${deg}deg, #${leftColor} 10%, #${rightColor} 100%)`;
  141. document.querySelector('#app').style.background = this.themeSwitcher.isDarkTheme ? colors.dark.bg : background;
  142. },
  143. },
  144. watch: {
  145. 'themeSwitcher.isDarkTheme'(newVal, oldVal) {
  146. this.updateBackground();
  147. },
  148. },
  149. });
  150. </script>
  151. </body>
  152. </html>