login.html 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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-affix-wrapper .ant-input-prefix {
  18. left: 23px;
  19. }
  20. .ant-input-affix-wrapper .ant-input:not(:first-child) {
  21. padding-left: 50px;
  22. }
  23. .selectLang{
  24. display: flex;
  25. text-align: center;
  26. justify-content: center;
  27. }
  28. </style>
  29. <body>
  30. <a-layout id="app" v-cloak>
  31. <transition name="list" appear>
  32. <a-layout-content>
  33. <a-row type="flex" justify="center">
  34. <a-col :xs="22" :sm="20" :md="16" :lg="12" :xl="8">
  35. <h1>{{ i18n "pages.login.title" }}</h1>
  36. </a-col>
  37. </a-row>
  38. <a-row type="flex" justify="center">
  39. <a-col :xs="22" :sm="20" :md="16" :lg="12" :xl="8">
  40. <a-form>
  41. <a-form-item>
  42. <a-input v-model.trim="user.username" placeholder='{{ i18n "username" }}'
  43. @keydown.enter.native="login" autofocus>
  44. <a-icon slot="prefix" type="user" style="color: rgba(0,0,0,.25)"/>
  45. </a-input>
  46. </a-form-item>
  47. <a-form-item>
  48. <a-input type="password" v-model.trim="user.password"
  49. placeholder='{{ i18n "password" }}' @keydown.enter.native="login">
  50. <a-icon slot="prefix" type="lock" style="color: rgba(0,0,0,.25)"/>
  51. </a-input>
  52. </a-form-item>
  53. <a-form-item v-if="secretEnable">
  54. <a-input type="text" placeholder='{{ i18n "secretToken" }}' v-model.trim="user.loginSecret" @keydown.enter.native="login">
  55. <a-icon slot="prefix" type="key" style="color: rgba(0,0,0,.25)"/>
  56. </a-input>
  57. </a-form-item>
  58. <a-form-item>
  59. <a-button block @click="login" :loading="loading">{{ i18n "login" }}</a-button>
  60. </a-form-item>
  61. <a-form-item>
  62. <a-row justify="center" class="selectLang">
  63. <a-col :span="5"><span>Language :</span></a-col>
  64. <a-col :span="7">
  65. <a-select
  66. ref="selectLang"
  67. v-model="lang"
  68. @change="setLang(lang)"
  69. >
  70. <a-select-option :value="l.value" label="English" v-for="l in supportLangs" >
  71. <span role="img" aria-label="l.name" v-text="l.icon"></span>
  72. &nbsp;&nbsp;<span v-text="l.name"></span>
  73. </a-select-option>
  74. </a-select>
  75. </a-col>
  76. </a-row>
  77. </a-form-item>
  78. </a-form>
  79. </a-col>
  80. </a-row>
  81. </a-layout-content>
  82. </transition>
  83. </a-layout>
  84. {{template "js" .}}
  85. <script>
  86. const leftColor = RandomUtil.randomIntRange(0x222222, 0xFFFFFF / 2).toString(16);
  87. const rightColor = RandomUtil.randomIntRange(0xFFFFFF / 2, 0xDDDDDD).toString(16);
  88. const deg = RandomUtil.randomIntRange(0, 360);
  89. const background = `linear-gradient(${deg}deg, #${leftColor} 10%, #${rightColor} 100%)`;
  90. document.querySelector('#app').style.background = background;
  91. const app = new Vue({
  92. delimiters: ['[[', ']]'],
  93. el: '#app',
  94. data: {
  95. loading: false,
  96. user: new User(),
  97. secretEnable: false,
  98. lang : ""
  99. },
  100. created(){
  101. this.lang = getLang();
  102. this.secretEnable = this.getSecretStatus();
  103. },
  104. methods: {
  105. async login() {
  106. this.loading = true;
  107. const msg = await HttpUtil.post('/login', this.user);
  108. this.loading = false;
  109. if (msg.success) {
  110. location.href = basePath + 'xui/';
  111. }
  112. },
  113. async getSecretStatus() {
  114. this.loading= true;
  115. const msg = await HttpUtil.post('/getSecretStatus');
  116. this.loading = false;
  117. if (msg.success){
  118. this.secretEnable = msg.obj;
  119. return msg.obj;
  120. }
  121. }
  122. }
  123. });
  124. </script>
  125. </body>
  126. </html>