sunshineRun.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <template>
  2. <div class="login">
  3. <Transition :enter-active-class="proxy?.animate.error.enter">
  4. <div class="login-content" :key="key">
  5. <div class="login-content-center">
  6. <div class="login-title"> <img src="@/assets/images/login/login.png" /></div>
  7. <div class="login-input-box">
  8. <div class="login-item">
  9. <input class="login-input login-input-username" type="text" placeholder="请输入帐号"
  10. v-model.trim="loginForm.username" />
  11. </div>
  12. <div class="login-item">
  13. <input class="login-input login-input-password" type="password" autocomplete="off" placeholder="请输入密码"
  14. v-model.trim="loginForm.password" />
  15. </div>
  16. <!-- <div class="login-item">
  17. <input class="login-input login-input-username" type="text" placeholder="请输入IP"
  18. v-model.trim="loginForm.ip" />
  19. </div> -->
  20. <div @click="getLogin" class="login-btn">
  21. <el-icon class="is-loading" v-if="loading">
  22. <Loading />
  23. </el-icon>
  24. 登 录
  25. </div>
  26. </div>
  27. </div>
  28. </div>
  29. </Transition>
  30. </div>
  31. </template>
  32. <script setup name="SunshineRun" lang="ts">
  33. import CryptoJS from 'crypto-js';
  34. import useAppStore from '@/store/modules/app';
  35. const { proxy } = getCurrentInstance() as any;
  36. const router = useRouter();
  37. const route = useRoute();
  38. interface DataType {
  39. loginForm: {
  40. username: string,
  41. password: string,
  42. ip: string,
  43. },
  44. loading: boolean,
  45. key: number,
  46. }
  47. const data = reactive<DataType>({
  48. loginForm: {
  49. username: '',
  50. password: '',
  51. ip: ''
  52. },
  53. loading: false,
  54. key: 0,
  55. });
  56. const { loginForm, loading, key } = toRefs(data);
  57. // 登录
  58. const getLogin = () => {
  59. let username = loginForm.value.username;
  60. let password = loginForm.value.password;
  61. let ip = loginForm.value.ip;
  62. if (!username || !password) {
  63. return false;
  64. }
  65. loading.value = true;
  66. proxy?.$modal.loading();
  67. let params = {
  68. username,
  69. password,
  70. };
  71. proxy?.$http.common.login(params).then((res: any) => {
  72. if (res.access_token) {
  73. //保存token
  74. let token = res.access_token;
  75. let passwordStr = CryptoJS.AES.encrypt(password, 'trops').toString();
  76. localStorage.setItem('loginType', "3");
  77. localStorage.setItem("token", token);
  78. localStorage.setItem('username', username);
  79. localStorage.setItem('password', passwordStr);
  80. localStorage.setItem('ip', ip)
  81. router.push({ path: '/sunshineRun' });
  82. getUserInfo();
  83. }
  84. }).catch(() => {
  85. key.value++;
  86. }).finally(() => {
  87. loading.value = false;
  88. proxy?.$modal?.closeLoading()
  89. });
  90. };
  91. //获取个人信息
  92. const getUserInfo = () => {
  93. let params = {};
  94. proxy?.$http.common.getUserInfo(params).then((res: any) => {
  95. //保存信息
  96. if (res.data.length) {
  97. let myData = res.data[0];
  98. let info: any = JSON.stringify(myData);
  99. localStorage.setItem("userInfo", info);
  100. //修改收藏夹图标
  101. proxy?.$utils.setFavicon(myData?.logo_url);
  102. //跳转
  103. }
  104. });
  105. };
  106. onMounted(() => {
  107. //测试环境默认密码
  108. // if (import.meta.env.DEV) {
  109. // loginForm.value.username = 'manage1';
  110. // loginForm.value.password = 'trops@2022';
  111. // }
  112. let username = localStorage.getItem('username');
  113. let password = localStorage.getItem('password');
  114. let ip = localStorage.getItem('ip');
  115. if (username) {
  116. loginForm.value.username = username;
  117. }
  118. if (password) {
  119. let myPassword = CryptoJS.AES.decrypt(password, 'trops').toString(CryptoJS.enc.Utf8);
  120. loginForm.value.password = myPassword;
  121. }
  122. if (ip) {
  123. loginForm.value.ip = ip;
  124. }
  125. if(route.query?.auto){
  126. proxy?.$modal.msgWarning('自动登录');
  127. getLogin();
  128. }
  129. })
  130. </script>
  131. <style lang="scss" scoped>
  132. .login-title {
  133. img {
  134. width: 9.88rem;
  135. }
  136. margin-bottom: 1.8rem;
  137. }
  138. .login-content {
  139. width: 45%;
  140. height: 100vh;
  141. margin: 0 auto;
  142. display: flex;
  143. align-items: center;
  144. justify-content: center;
  145. .login-content-center {
  146. display: flex;
  147. text-align: center;
  148. justify-content: center;
  149. flex-wrap: wrap;
  150. width: 100%;
  151. .login-input-box {
  152. display: flex;
  153. justify-content: center;
  154. align-items: center;
  155. flex-direction: column;
  156. width: 100%;
  157. padding: 6.8vh 0;
  158. border-radius: 1.42rem;
  159. opacity: 1;
  160. background: linear-gradient(68deg, #1D2F3D -85%, #304453 96%);
  161. box-shadow: inset 0px 1px 0px 2px rgba(255, 255, 255, 0.3);
  162. .login-item {
  163. width: 100%;
  164. margin-bottom: 2rem;
  165. display: flex;
  166. justify-content: center;
  167. .login-input {
  168. width: 52.6%;
  169. height: 2.9rem;
  170. line-height: 2.9rem;
  171. border-radius: 0.83rem;
  172. padding: 0 1rem;
  173. text-align: center;
  174. font-size: 1.65rem;
  175. opacity: 1;
  176. background: #EAEAEA;
  177. box-sizing: border-box;
  178. border: 1px solid #FFFFFF;
  179. box-shadow: inset 0px 0px 10px 1px rgba(78, 78, 78, 0.5899);
  180. }
  181. }
  182. .login-btn {
  183. width: 36.7%;
  184. height: 3.59rem;
  185. line-height: 3.59rem;
  186. border-radius: 0.83rem;
  187. font-size: 2rem;
  188. opacity: 1;
  189. text-align: center;
  190. background: radial-gradient(141% 126% at 5% 93%, #8EFFA9 0%, #07FFE7 100%);
  191. box-shadow: inset 0px 1px 0px 2px rgba(255, 255, 255, 0.3);
  192. cursor: pointer;
  193. display: flex;
  194. align-items: center;
  195. justify-content: center;
  196. .is-loading {
  197. margin-right: 5px;
  198. }
  199. }
  200. }
  201. }
  202. }
  203. </style>