Login.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <!--
  2. * @Author: your name
  3. * @Date: 2021-01-11 11:14:26
  4. * @LastEditTime: 2022-04-28 18:35:39
  5. * @LastEditors: Please set LastEditors
  6. * @Description: In User Settings Edit
  7. * @FilePath: \vue3-element-admin\src\views\Login.vue
  8. -->
  9. <template>
  10. <div class="backdrop-layer">
  11. <div class="head">
  12. <div class="logo"></div>
  13. <div class="title">
  14. 飞鸟智慧果园管理平台
  15. </div>
  16. </div>
  17. <div class="ve_container">
  18. <el-card style="height: 300px" :body-style="{ background: '#ffffff' }">
  19. <h1>用户登录</h1>
  20. <transition name="el-fade-in-linear">
  21. <el-form
  22. :model="form"
  23. :rules="rules"
  24. v-show="!success"
  25. class="ve_form"
  26. ref="ref_form"
  27. :inline="false"
  28. @keyup.enter="onSubmit"
  29. >
  30. <el-form-item prop="userName">
  31. <el-input
  32. size="large"
  33. v-model.trim="userName"
  34. placeholder="用户名"
  35. >
  36. <template #prepend>
  37. <el-icon :size="20"><Iphone /></el-icon>
  38. </template>
  39. </el-input>
  40. </el-form-item>
  41. <el-form-item prop="pwd">
  42. <el-input
  43. size="large"
  44. type="password"
  45. v-model.trim="pwd"
  46. placeholder="密码"
  47. >
  48. <template #prepend>
  49. <el-icon :size="20"><Key /></el-icon>
  50. </template>
  51. </el-input>
  52. </el-form-item>
  53. <el-form-item>
  54. <div style="width: 50%;float: left;text-align: left;"><el-checkbox >记住密码</el-checkbox></div>
  55. <div style="width: 50%;float: left;">
  56. <el-button
  57. class="ve_submit"
  58. type="primary"
  59. @click="onSubmit"
  60. >
  61. 登录
  62. </el-button>
  63. </div>
  64. </el-form-item>
  65. </el-form>
  66. </transition>
  67. </el-card>
  68. </div>
  69. </div>
  70. </template>
  71. <script setup>
  72. import {SET_TOKEN, SET_UNAME, SET_USER_INFO} from "@/store/modules/app/type";
  73. import Common from "@/components/Common";
  74. import { ref, reactive, toRefs } from "vue";
  75. import { useStore } from "vuex";
  76. import { useRouter } from "vue-router";
  77. // const rules = {
  78. // phone: [{ required: true, message: "请输入用户名", trigger: "blur" }]
  79. // };
  80. const rules = {
  81. userName: [{ required: true, message: "请输入用户名", trigger: "blur" }]
  82. ,
  83. pwd: [{ required: true, message: "请输入验证码", trigger: "blur" }
  84. ],
  85. };
  86. const store = useStore();
  87. const router = useRouter();
  88. // 定义两个账号
  89. const guestAccount = { "pwd": "游客", "userName": "游客" };
  90. const regularAccount = { "pwd": "", "userName": "13797066447" };
  91. // const form = reactive({
  92. // "pwd": "",
  93. // "userName": "13797066447"
  94. // });
  95. const form = reactive({
  96. "pwd": "",
  97. "userName": ""
  98. });
  99. const { userName, pwd } = toRefs(form);
  100. const ref_form = ref(null);
  101. const success = ref(false);
  102. sessionStorage.clear();
  103. store.commit(`app/${SET_TOKEN}`, "");
  104. router.options.isAddDynamicMenuRoutes = false;
  105. // 根据时间设置账号
  106. const setAccountByTime = () => {
  107. const now = new Date();
  108. const currentHour = now.getHours();
  109. if (currentHour >= 18 && currentHour < 24) {
  110. form.pwd = guestAccount.pwd;
  111. form.userName = guestAccount.userName;
  112. } else {
  113. form.pwd = regularAccount.pwd;
  114. form.userName = regularAccount.userName;
  115. }
  116. };
  117. // 初始化账号
  118. setAccountByTime();
  119. const onSubmit = () => {
  120. ref_form.value.validate(async (valid) => {
  121. if (valid) {
  122. const res = await VE_API.system.login(form);
  123. if (res.code == 0) {
  124. const { token, userName, djiCloudToken } = res.data;
  125. store.commit(`app/${SET_TOKEN}`, token);
  126. store.commit(`app/djiCloudToken`, djiCloudToken);
  127. store.commit(`app/${SET_UNAME}`, userName);
  128. res.data["token"] = undefined
  129. res.data["x-auth-token"] = undefined
  130. res.data["pwd"] = undefined
  131. store.commit(`app/${SET_USER_INFO}`, JSON.stringify(res.data));
  132. success.value = true;
  133. router.push({ name: "Home" });
  134. }
  135. } else {
  136. return;
  137. }
  138. });
  139. };
  140. </script>
  141. <style lang="scss" scoped>
  142. .ve_container {
  143. position: absolute;
  144. z-index: 1;
  145. width: 400px;
  146. top: calc(50%);
  147. left: calc(50% - 250px);
  148. transform: translateY(-50%);
  149. transition: all 1s;
  150. min-height: 273px;
  151. text-align: center;
  152. h1 {
  153. font-size: 24px;
  154. transition: all 1s;
  155. font-weight: normal;
  156. text-align: left;
  157. margin-bottom: 36px;
  158. }
  159. .ve_form {
  160. .ve_submit {
  161. width: 100%;
  162. height: 45px;
  163. background: #0BC678;
  164. }
  165. }
  166. }
  167. .backdrop-layer{
  168. position: absolute;
  169. top: 0px;
  170. bottom: 0px;
  171. left: 0px;
  172. right: 0px;
  173. background: url(@/assets/login_bg.jpg) no-repeat;
  174. background-size:100% 100%;
  175. z-index: 1;
  176. overflow: hidden;
  177. }
  178. .head{
  179. position: absolute;
  180. left: 300px;
  181. top: 100px;
  182. display: flex;
  183. align-items: center;
  184. padding: 50px;
  185. .title{
  186. font-size: 30px;
  187. font-weight: bold;
  188. color:#006600;
  189. float: left;
  190. line-height: 50px;
  191. margin-left: 20px;
  192. }
  193. .logo{
  194. width: calc(167px * 0.5);
  195. height: calc(245px * 0.5);
  196. background: url('@/assets/logo-verticle.png') no-repeat;
  197. background-size:100% 100%;
  198. float: left;
  199. z-index: 1000;
  200. }
  201. }
  202. </style>