login.html 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. {{ template "page/head_start" .}}
  2. {{ template "page/head_end" .}}
  3. {{ template "page/body_start" .}}
  4. <a-layout id="app" v-cloak :class="themeSwitcher.currentTheme + ' login-app'">
  5. <transition name="list" appear>
  6. <a-layout-content class="under min-h-0">
  7. <div class="waves-header">
  8. <div class="waves-inner-header"></div>
  9. <svg class="waves" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
  10. viewBox="0 24 150 28" preserveAspectRatio="none" shape-rendering="auto">
  11. <defs>
  12. <path id="gentle-wave" d="M-160 44c30 0 58-18 88-18s 58 18 88 18 58-18 88-18 58 18 88 18 v44h-352z" />
  13. </defs>
  14. <g class="parallax">
  15. <use xlink:href="#gentle-wave" x="48" y="0" fill="rgba(0, 135, 113, 0.08)" />
  16. <use xlink:href="#gentle-wave" x="48" y="3" fill="rgba(0, 135, 113, 0.08)" />
  17. <use xlink:href="#gentle-wave" x="48" y="5" fill="rgba(0, 135, 113, 0.08)" />
  18. <use xlink:href="#gentle-wave" x="48" y="7" fill="#c7ebe2" />
  19. </g>
  20. </svg>
  21. </div>
  22. <a-row type="flex" justify="center" align="middle" class="h-100 overflow-y-auto overflow-x-hidden">
  23. <a-col :xs="22" :sm="12" :md="10" :lg="8" :xl="6" :xxl="5" id="login" class="my-3rem">
  24. <template v-if="!loadingStates.fetched">
  25. <div class="text-center">
  26. <a-spin size="large" />
  27. </div>
  28. </template>
  29. <template v-else>
  30. <div class="setting-section">
  31. <a-popover :overlay-class-name="themeSwitcher.currentTheme" title='{{ i18n "menu.settings" }}'
  32. placement="bottomRight" trigger="click">
  33. <template slot="content">
  34. <a-space direction="vertical" :size="10">
  35. <a-theme-switch-login></a-theme-switch-login>
  36. <span>{{ i18n "pages.settings.language" }}</span>
  37. <a-select ref="selectLang" class="w-100" v-model="lang" @change="LanguageManager.setLanguage(lang)"
  38. :dropdown-class-name="themeSwitcher.currentTheme">
  39. <a-select-option :value="l.value" label="English" v-for="l in LanguageManager.supportedLanguages">
  40. <span role="img" aria-label="l.name" v-text="l.icon"></span>
  41. &nbsp;&nbsp;<span v-text="l.name"></span>
  42. </a-select-option>
  43. </a-select>
  44. </a-space>
  45. </template>
  46. <a-button shape="circle" icon="setting"></a-button>
  47. </a-popover>
  48. </div>
  49. <a-row type="flex" justify="center">
  50. <a-col :style="{ width: '100%' }">
  51. <h2 class="title headline zoom">
  52. <span class="words-wrapper">
  53. <b class="is-visible">{{ i18n "pages.login.hello" }}</b>
  54. <b>{{ i18n "pages.login.title" }}</b>
  55. </span>
  56. </h2>
  57. </a-col>
  58. </a-row>
  59. <a-row type="flex" justify="center">
  60. <a-col span="24">
  61. <a-form @submit.prevent="login">
  62. <a-space direction="vertical" size="middle">
  63. <a-form-item>
  64. <a-input autocomplete="username" name="username" v-model.trim="user.username"
  65. placeholder='{{ i18n "username" }}' autofocus required>
  66. <a-icon slot="prefix" type="user" class="fs-1rem"></a-icon>
  67. </a-input>
  68. </a-form-item>
  69. <a-form-item>
  70. <a-input-password autocomplete="current-password" name="password" v-model.trim="user.password"
  71. placeholder='{{ i18n "password" }}' required>
  72. <a-icon slot="prefix" type="lock" class="fs-1rem"></a-icon>
  73. </a-input-password>
  74. </a-form-item>
  75. <a-form-item v-if="twoFactorEnable">
  76. <a-input autocomplete="one-time-code" name="twoFactorCode" v-model.trim="user.twoFactorCode"
  77. placeholder='{{ i18n "twoFactorCode" }}' required>
  78. <a-icon slot="prefix" type="key" class="fs-1rem"></a-icon>
  79. </a-input>
  80. </a-form-item>
  81. <a-form-item>
  82. <a-row justify="center" class="centered">
  83. <div class="wave-btn-bg wave-btn-bg-cl h-50px mt-1rem"
  84. :style="loadingStates.spinning ? 'width: 52px' : 'display: inline-block'">
  85. <a-button class="ant-btn-primary-login" type="primary" :loading="loadingStates.spinning"
  86. :icon="loadingStates.spinning ? 'poweroff' : undefined" html-type="submit">
  87. [[ loadingStates.spinning ? '' : '{{ i18n "login" }}' ]]
  88. </a-button>
  89. </div>
  90. </a-row>
  91. </a-form-item>
  92. </a-space>
  93. </a-form>
  94. </a-col>
  95. </a-row>
  96. </template>
  97. </a-col>
  98. </a-row>
  99. </a-layout-content>
  100. </transition>
  101. </a-layout>
  102. {{template "page/body_scripts" .}}
  103. {{template "component/aThemeSwitch" .}}
  104. <script>
  105. const app = new Vue({
  106. delimiters: ['[[', ']]'],
  107. el: '#app',
  108. data: {
  109. themeSwitcher,
  110. loadingStates: {
  111. fetched: false,
  112. spinning: false
  113. },
  114. user: {
  115. username: "",
  116. password: "",
  117. twoFactorCode: ""
  118. },
  119. twoFactorEnable: false,
  120. lang: "",
  121. animationStarted: false
  122. },
  123. async mounted() {
  124. this.lang = LanguageManager.getLanguage();
  125. this.twoFactorEnable = await this.getTwoFactorEnable();
  126. },
  127. methods: {
  128. async login() {
  129. this.loadingStates.spinning = true;
  130. const msg = await HttpUtil.post('/login', this.user);
  131. if (msg.success) {
  132. location.href = basePath + 'panel/';
  133. }
  134. this.loadingStates.spinning = false;
  135. },
  136. async getTwoFactorEnable() {
  137. const msg = await HttpUtil.post('/getTwoFactorEnable');
  138. if (msg.success) {
  139. this.twoFactorEnable = msg.obj;
  140. this.loadingStates.fetched = true;
  141. this.$nextTick(() => {
  142. if (!this.animationStarted) {
  143. this.animationStarted = true;
  144. this.initHeadline();
  145. }
  146. });
  147. return msg.obj;
  148. }
  149. },
  150. initHeadline() {
  151. const animationDelay = 2000;
  152. const rootEl = this.$el instanceof Element ? this.$el : document.getElementById('app');
  153. if (!rootEl || typeof rootEl.querySelectorAll !== 'function') {
  154. return;
  155. }
  156. const headlines = rootEl.querySelectorAll('.headline');
  157. headlines.forEach((headline) => {
  158. const first = headline.querySelector('.is-visible');
  159. if (!first) return;
  160. setTimeout(() => this.hideWord(first, animationDelay), animationDelay);
  161. });
  162. },
  163. hideWord(word, delay) {
  164. const nextWord = this.takeNext(word);
  165. this.switchWord(word, nextWord);
  166. setTimeout(() => this.hideWord(nextWord, delay), delay);
  167. },
  168. takeNext(word) {
  169. return word.nextElementSibling || word.parentElement.firstElementChild;
  170. },
  171. switchWord(oldWord, newWord) {
  172. oldWord.classList.remove('is-visible');
  173. oldWord.classList.add('is-hidden');
  174. newWord.classList.remove('is-hidden');
  175. newWord.classList.add('is-visible');
  176. }
  177. },
  178. });
  179. const pm_input_selector = 'input.ant-input, textarea.ant-input';
  180. const pm_strip_props = [
  181. 'background',
  182. 'background-color',
  183. 'background-image',
  184. 'color'
  185. ];
  186. const pm_observed_forms = new WeakSet();
  187. function pm_strip_inline(el) {
  188. if (!el || el.nodeType !== 1 || !el.matches?.(pm_input_selector)) return;
  189. let did_change = false;
  190. for (const prop of pm_strip_props) {
  191. if (el.style.getPropertyValue(prop)) {
  192. el.style.removeProperty(prop);
  193. did_change = true;
  194. }
  195. }
  196. if (did_change && el.style.length === 0) {
  197. el.removeAttribute('style');
  198. }
  199. }
  200. function pm_attach_observer(form) {
  201. if (pm_observed_forms.has(form)) return;
  202. pm_observed_forms.add(form);
  203. form.querySelectorAll(pm_input_selector).forEach(pm_strip_inline);
  204. const pm_mo = new MutationObserver(mutations => {
  205. for (const m of mutations) {
  206. if (m.type === 'attributes') {
  207. pm_strip_inline(m.target);
  208. } else if (m.type === 'childList') {
  209. for (const n of m.addedNodes) {
  210. if (n.nodeType !== 1) continue;
  211. if (n.matches?.(pm_input_selector)) pm_strip_inline(n);
  212. n.querySelectorAll?.(pm_input_selector).forEach(pm_strip_inline);
  213. }
  214. }
  215. }
  216. });
  217. pm_mo.observe(form, {
  218. attributes: true,
  219. attributeFilter: ['style'],
  220. childList: true,
  221. subtree: true
  222. });
  223. }
  224. function pm_init() {
  225. document.querySelectorAll('form.ant-form').forEach(pm_attach_observer);
  226. const pm_host = document.getElementById('login') || document.body;
  227. const pm_wait_for_forms = new MutationObserver(mutations => {
  228. for (const m of mutations) {
  229. for (const n of m.addedNodes) {
  230. if (n.nodeType !== 1) continue;
  231. if (n.matches?.('form.ant-form')) pm_attach_observer(n);
  232. n.querySelectorAll?.('form.ant-form').forEach(pm_attach_observer);
  233. }
  234. }
  235. });
  236. pm_wait_for_forms.observe(pm_host, {
  237. childList: true,
  238. subtree: true
  239. });
  240. }
  241. if (document.readyState === 'loading') {
  242. document.addEventListener('DOMContentLoaded', pm_init, {
  243. once: true
  244. });
  245. } else {
  246. pm_init();
  247. }
  248. </script>
  249. {{ template "page/body_end" .}}