login.html 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. <a-input type="password" v-model.trim="user.password"
  59. placeholder='{{ i18n "password" }}' @keydown.enter.native="login">
  60. <a-icon slot="prefix" type="lock" :style="'font-size: 16px;' + themeSwitcher.textStyle" />
  61. </a-input>
  62. </a-form-item>
  63. <a-form-item v-if="secretEnable">
  64. <a-input type="text" placeholder='{{ i18n "secretToken" }}' v-model.trim="user.loginSecret" @keydown.enter.native="login">
  65. <a-icon slot="prefix" type="key" :style="'font-size: 16px;' + themeSwitcher.textStyle" />
  66. </a-input>
  67. </a-form-item>
  68. <a-form-item>
  69. <a-button block @click="login" :loading="loading">{{ i18n "login" }}</a-button>
  70. </a-form-item>
  71. <a-form-item>
  72. <a-row justify="center" class="centered">
  73. <a-button type="primary" :loading="loading" @click="login" :icon="loading ? 'poweroff' : undefined"
  74. :style="loading ? { width: '50px' } : { display: 'block', width: '100%' }">
  75. [[ loading ? '' : '{{ i18n "login" }}' ]]
  76. </a-button>
  77. </a-row>
  78. </a-form-item>
  79. <a-form-item>
  80. <a-row justify="center" class="centered">
  81. <a-col :span="12">
  82. <a-select ref="selectLang" v-model="lang" @change="setLang(lang)" :dropdown-class-name="themeSwitcher.darkCardClass">
  83. <a-select-option :value="l.value" label="English" v-for="l in supportLangs">
  84. <span role="img" aria-label="l.name" v-text="l.icon"></span>
  85. &nbsp;&nbsp;<span v-text="l.name"></span>
  86. </a-select-option>
  87. </a-select>
  88. </a-col>
  89. </a-row>
  90. </a-form-item>
  91. <a-form-item>
  92. <a-row justify="center" class="centered">
  93. <theme-switch></theme-switch>
  94. </a-row>
  95. </a-form-item>
  96. </a-form>
  97. </a-col>
  98. </a-row>
  99. </a-layout-content>
  100. </transition>
  101. </a-layout>
  102. {{template "js" .}}
  103. {{template "component/themeSwitcher" .}}
  104. <script>
  105. const app = new Vue({
  106. delimiters: ['[[', ']]'],
  107. el: '#app',
  108. data: {
  109. themeSwitcher,
  110. loading: false,
  111. user: new User(),
  112. secretEnable: false,
  113. lang: ""
  114. },
  115. created() {
  116. this.updateBackground();
  117. this.lang = getLang();
  118. this.secretEnable = this.getSecretStatus();
  119. },
  120. methods: {
  121. async login() {
  122. this.loading = true;
  123. const msg = await HttpUtil.post('/login', this.user);
  124. this.loading = false;
  125. if (msg.success) {
  126. location.href = basePath + 'xui/';
  127. }
  128. },
  129. async getSecretStatus() {
  130. this.loading = true;
  131. const msg = await HttpUtil.post('/getSecretStatus');
  132. this.loading = false;
  133. if (msg.success) {
  134. this.secretEnable = msg.obj;
  135. return msg.obj;
  136. }
  137. },
  138. updateBackground() {
  139. const leftColor = RandomUtil.randomIntRange(0x222222, 0xFFFFFF / 2).toString(16);
  140. const rightColor = RandomUtil.randomIntRange(0xFFFFFF / 2, 0xDDDDDD).toString(16);
  141. const deg = RandomUtil.randomIntRange(0, 360);
  142. const background = `linear-gradient(${deg}deg, #${leftColor} 10%, #${rightColor} 100%)`;
  143. document.querySelector('#app').style.background = this.themeSwitcher.isDarkTheme ? colors.dark.bg : background;
  144. },
  145. },
  146. watch: {
  147. 'themeSwitcher.isDarkTheme'(newVal, oldVal) {
  148. this.updateBackground();
  149. },
  150. },
  151. });
  152. </script>
  153. </body>
  154. </html>