index.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <script lang='ts' setup>
  2. import { nextTick, ref } from 'vue'
  3. import NetService from '../../../services/net.service'
  4. import useStore from '../../store'
  5. const netService = new NetService()
  6. const store = useStore()
  7. const formRef = ref()
  8. const model = ref({
  9. account: '',
  10. password: ''
  11. })
  12. const rules = {
  13. account: [ {
  14. required: true,
  15. trigger: [ 'blur', 'input' ],
  16. message: '请输入用户名'
  17. } ],
  18. password: [ {
  19. required: true,
  20. trigger: [ 'blur', 'input' ],
  21. message: '请输入密码'
  22. } ]
  23. }
  24. const labelStyle = {
  25. height: '50px',
  26. fontSize: '20px'
  27. }
  28. /** 登录 */
  29. async function login() {
  30. formRef.value?.validate(async (errors?: Array<any>) => {
  31. if (!errors) {
  32. const params = {
  33. account: model.value.account.trim(),
  34. password: model.value.password.trim()
  35. }
  36. const { success, data, message } = await netService.post('/sys/login', params)
  37. if (!success) throw message
  38. store.setUserInfo(data)
  39. sessionStorage.setItem('token', data.satoken)
  40. await nextTick()
  41. // 页面跳转
  42. window.location.href = '/'
  43. }
  44. })
  45. }
  46. </script>
  47. <template>
  48. <div class="login">
  49. <div
  50. class="form"
  51. @keydown.enter="login"
  52. >
  53. <div class="title">
  54. 雅安可视化管控中心
  55. </div>
  56. <n-form
  57. ref="formRef"
  58. :model="model"
  59. :rules="rules"
  60. label-placement="left"
  61. label-width="80px"
  62. :show-require-mark="false"
  63. >
  64. <n-form-item
  65. label="用户名"
  66. path="account"
  67. :label-style="labelStyle"
  68. >
  69. <n-input
  70. v-model:value="model.account"
  71. placeholder="请输入用户名"
  72. size="large"
  73. round
  74. >
  75. <template #prefix>
  76. <icon
  77. name="user"
  78. :size="16"
  79. />
  80. </template>
  81. </n-input>
  82. </n-form-item>
  83. <n-form-item
  84. label="密码"
  85. path="password"
  86. :label-style="labelStyle"
  87. >
  88. <n-input
  89. v-model:value="model.password"
  90. placeholder="请输入密码"
  91. size="large"
  92. round
  93. type="password"
  94. >
  95. <template #prefix>
  96. <icon
  97. name="lock"
  98. :size="16"
  99. />
  100. </template>
  101. </n-input>
  102. </n-form-item>
  103. <n-form-item
  104. label=" "
  105. :label-style="labelStyle"
  106. >
  107. <n-button
  108. v-debounce
  109. round
  110. :bordered="false"
  111. @click="login"
  112. >
  113. 登 录
  114. </n-button>
  115. </n-form-item>
  116. </n-form>
  117. </div>
  118. </div>
  119. </template>
  120. <style lang='scss' scoped>
  121. .login {
  122. width: 100vw;
  123. height: 100vh;
  124. background: #030E25;
  125. display: flex;
  126. align-items: center;
  127. justify-content: center;
  128. gap: 0 160px;
  129. .form {
  130. width: 711px;
  131. height: 576px;
  132. background: linear-gradient(229deg, #050f25, #535c66);
  133. border-radius: 30px;
  134. border: 2px solid #FFFFFF;
  135. display: flex;
  136. flex-direction: column;
  137. align-items: center;
  138. .title {
  139. display: flex;
  140. gap: 30px;
  141. margin-top: 81px;
  142. font-size: 36px;
  143. color: #FFFFFF;
  144. line-height: 41px;
  145. letter-spacing: 2px;
  146. }
  147. .n-form-item {
  148. &:first-child {
  149. margin-top: 110px;
  150. }
  151. margin-top: 16px;
  152. margin-bottom: 0;
  153. }
  154. :deep(.n-form-item-label__text) {
  155. text-align-last: justify;
  156. }
  157. .n-input,
  158. .n-button {
  159. width: 415px;
  160. --n-height: 50px
  161. }
  162. .n-button {
  163. background: #030E25;
  164. color: #FFFFFF;
  165. border-color: #fff;
  166. font-size: 20px;
  167. }
  168. }
  169. }
  170. </style>