移动端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

login.vue 6.2 KiB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <template>
  2. <div class="app-container" :style="{ height: windowHeight + 'px' }">
  3. <div class="login_header"></div>
  4. <div class="login_content">
  5. <div class="homestead_wrap">
  6. <div class="key_title">环翠区两清三化</div>
  7. <div class="slogan">数据调查系统</div>
  8. </div>
  9. <div class="from_wrap">
  10. <div class="from_content">
  11. <div class="signIn_container">
  12. <div class="signIn_input_wrap">
  13. <van-field
  14. autosize
  15. v-model="formData.username"
  16. placeholder="请输入用户名"
  17. />
  18. </div>
  19. </div>
  20. <div class="signIn_container">
  21. <div class="signIn_input_wrap">
  22. <van-field
  23. autosize
  24. type="password"
  25. placeholder="请输入密码"
  26. v-model="formData.password"
  27. />
  28. </div>
  29. </div>
  30. <div class="signIn_container">
  31. <div class="signIn_input_wrap">
  32. <div class="verification_code">
  33. <van-field
  34. autosize
  35. placeholder="请输入验证码"
  36. v-model="formData.code"
  37. />
  38. </div>
  39. <div class="verification_images">
  40. <img class="code-img" :src="codeUrl" @click="getCode" />
  41. </div>
  42. </div>
  43. </div>
  44. <div class="signIn_container">
  45. <div class="remember_num">
  46. <van-checkbox
  47. v-model="rememberPassword"
  48. icon-size="16px"
  49. checked-color="#3CBF5B"
  50. >记住密码</van-checkbox
  51. >
  52. </div>
  53. </div>
  54. </div>
  55. <div class="from_btn" @click="handleLogin">登录</div>
  56. </div>
  57. </div>
  58. </div>
  59. </template>
  60. <script>
  61. import { getCodeImg } from "@/api/login";
  62. import Cookies from "js-cookie";
  63. export default {
  64. name: "homesteadLogin",
  65. data() {
  66. return {
  67. formData: {
  68. username: "", //账号
  69. password: "", //密码
  70. code: null, //图片验证码
  71. uuid: null, //识别uuid
  72. },
  73. codeUrl: "", //图片验证码
  74. rememberPassword: false, //记住密码 1记住 2不记住
  75. windowHeight: 0,
  76. };
  77. },
  78. created() {
  79. this.getCode();
  80. let userName = Cookies.get("homesteadUserName"); // => 'value'
  81. let password = Cookies.get("homesteadPassword"); // => undefined
  82. if (userName != undefined) {
  83. this.formData.username = userName;
  84. this.rememberPassword = true;
  85. }
  86. if (password != undefined) {
  87. this.formData.password = password;
  88. }
  89. },
  90. mounted() {
  91. let windowHeight = document.documentElement.clientHeight;
  92. this.windowHeight = windowHeight;
  93. },
  94. methods: {
  95. getCode() {
  96. getCodeImg().then((res) => {
  97. this.formData.uuid = res.uuid;
  98. this.codeUrl = "data:image/gif;base64," + res.img;
  99. });
  100. },
  101. handleLogin() {
  102. //账号密码登录
  103. if (this.formData.username == "") {
  104. this.$dialog.alert({
  105. message: "账号不能为空",
  106. });
  107. return false;
  108. } else if (this.formData.password == "") {
  109. this.$dialog.alert({
  110. message: "密码不能为空",
  111. });
  112. return false;
  113. } else if (this.formData.code == "") {
  114. this.$dialog.alert({
  115. message: "图片验证码不能为空",
  116. });
  117. return false;
  118. }
  119. this.$store
  120. .dispatch("Login", this.formData)
  121. .then(() => {
  122. if (this.rememberPassword == true) {
  123. Cookies.set("homesteadUserName", this.formData.username, {
  124. expires: 30,
  125. });
  126. Cookies.set("homesteadPassword", this.formData.password, {
  127. expires: 30,
  128. });
  129. }
  130. this.$router
  131. .push({ path: this.redirect || "/homestead/index" })
  132. .catch(() => {});
  133. })
  134. .catch(() => {
  135. this.loading = false;
  136. this.getCode();
  137. });
  138. },
  139. },
  140. };
  141. </script>
  142. <style scoped lang="scss">
  143. .app-container {
  144. display: flex;
  145. width: 100vw;
  146. height: 100vh;
  147. flex-direction: column;
  148. .login_header {
  149. flex: 0.35;
  150. background: url("../../assets/images/homestead/login_bg.jpg") center bottom
  151. no-repeat;
  152. background-size: 100% 100%;
  153. }
  154. .login_content {
  155. flex: 0.65;
  156. display: flex;
  157. flex-direction: column;
  158. .homestead_wrap {
  159. flex: 0.28;
  160. display: flex;
  161. justify-content: center; /* 相对父元素水平居中 */
  162. align-items: center; /* 子元素相对父元素垂直居中 */
  163. flex-direction: column;
  164. .key_title {
  165. font-size: 56px;
  166. margin-bottom: 10px;
  167. }
  168. .slogan {
  169. font-size: 32px;
  170. color: #9f9f9f;
  171. }
  172. }
  173. .from_wrap {
  174. flex: 0.72;
  175. padding-bottom: 14%;
  176. flex-direction: column;
  177. display: flex;
  178. margin: 0 40px;
  179. .from_content {
  180. flex: 1;
  181. display: flex;
  182. flex-direction: column;
  183. padding-bottom: 14%;
  184. .signIn_container {
  185. flex: 1;
  186. display: flex;
  187. max-height: 90px;
  188. margin-bottom: 24px;
  189. &:last-child {
  190. margin-bottom: 0;
  191. }
  192. .signIn_input_wrap {
  193. flex: 1;
  194. display: flex;
  195. .verification_code {
  196. flex: 1;
  197. }
  198. .verification_images {
  199. flex: 0 0 220px;
  200. margin-left: 20px;
  201. img {
  202. width: 100%;
  203. height: 100%;
  204. }
  205. }
  206. .van-cell {
  207. border: 2px solid #f1f0f5;
  208. border-radius: 46px;
  209. font-size: 32px;
  210. }
  211. }
  212. .remember_num {
  213. margin-left: 14px;
  214. font-size: 28px;
  215. color: #3cbf5b;
  216. }
  217. }
  218. }
  219. .from_btn {
  220. display: flex;
  221. flex: 0 0 80px;
  222. background: #3cbf5b;
  223. border-radius: 40px;
  224. font-size: 36px;
  225. justify-content: center; /* 相对父元素水平居中 */
  226. align-items: center; /* 子元素相对父元素垂直居中 */
  227. color: #fff;
  228. }
  229. }
  230. }
  231. }
  232. </style>