Login.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. <template>
  2. <div>
  3. <div class="pageBox">
  4. <div class="loginBox">
  5. <div class="loginTitle">
  6. <p class="loginTitleP">请登录您的账号</p>
  7. </div>
  8. <el-form ref="form" :model="form">
  9. <el-form-item class="loginItem">
  10. <p class="loginItemP">账号</p>
  11. <input class="loginInput" v-model="form.username" @change="userRule" placeholder="请输入账号">
  12. <p class="blurP" v-if="userBlur">账号不能为空</p>
  13. </el-form-item>
  14. <el-form-item class="loginItem">
  15. <p class="loginItemP">密码</p>
  16. <input class="loginInput" v-model="form.password" @change="passRule" placeholder="请输入密码"
  17. :type="inputType">
  18. <img class="imgEyes" src="../../assets/font/fluent:eye-20-regular.png" alt="" @click="changeType">
  19. <p class="blurP" v-if="passBlur">密码不能为空</p>
  20. </el-form-item>
  21. <el-form-item class="loginItem">
  22. <el-checkbox v-model="rememberUser" @change="rememberNow">记住账号</el-checkbox><br>
  23. <el-button class="loginButton" @click="loginNow">登录</el-button>
  24. </el-form-item>
  25. </el-form>
  26. </div>
  27. </div>
  28. </div>
  29. </template>
  30. <script>
  31. import { login } from '../../api/login/login.js'
  32. import sm from 'sm-crypto';
  33. export default {
  34. data() {
  35. return {
  36. form: {
  37. username: "",
  38. password: ""
  39. },//账号密码表单
  40. rememberUser: false,//是否记住账号
  41. userBlur: false,//用户名验证
  42. passBlur: false,//密码验证
  43. inputType: "password",//密码输入框性质
  44. }
  45. },
  46. methods: {
  47. // 用户验证
  48. userRule(e) {
  49. if (e.target._value) {
  50. this.userBlur = false
  51. } else {
  52. this.userBlur = true
  53. }
  54. },
  55. // 密码验证
  56. passRule(e) {
  57. if (e.target._value) {
  58. this.passBlur = false
  59. } else {
  60. this.passBlur = true
  61. }
  62. },
  63. // 登录按钮
  64. async loginNow() {
  65. if (this.form.username != '' && this.form.password != "") {
  66. if (!this.userBlur && !this.passBlur) {
  67. const wordType = this.encryptPassword(this.form.password)
  68. let res = await login({ login_account: this.form.username, pwd: wordType })
  69. if (res.returncode == 200) {
  70. this.$message({
  71. type: "success",
  72. message: "登陆成功"
  73. })
  74. this.$router.push("/")
  75. localStorage.setItem('userInfo', JSON.stringify(res.data))
  76. localStorage.setItem('userToken', JSON.stringify(res.data.sessionid))
  77. this.rememberUser = false
  78. } else if (res.returncode == 500) {
  79. console.log(500);
  80. this.$message({
  81. type: "error",
  82. message: res.msg
  83. })
  84. }
  85. } else {
  86. this.$message({
  87. message: '账号或密码错误',
  88. type: 'error'
  89. });
  90. }
  91. } else {
  92. this.$message({
  93. message: '账号或密码不能为空',
  94. type: 'error'
  95. });
  96. }
  97. },
  98. // 记住账号
  99. rememberNow(e) {
  100. this.rememberUser = e
  101. if (this.rememberUser) {
  102. localStorage.setItem('username', JSON.stringify(this.form.username))
  103. } else {
  104. localStorage.removeItem('username')
  105. }
  106. },
  107. // 拿到已经保存的用户名
  108. getSaveUser() {
  109. let user = localStorage.getItem("username")
  110. if (user) {
  111. user = JSON.parse(user)
  112. this.form.username = user
  113. }
  114. },
  115. // ,密码框小眼睛
  116. changeType() {
  117. if (this.inputType === 'password') {
  118. this.inputType = 'text'
  119. } else {
  120. this.inputType = 'password'
  121. }
  122. },
  123. // 密码加密
  124. encryptPassword(password) {
  125. let val = SmCrypto.doSm3AndSm2Encrypt(password) + '0000'
  126. let ascCode = 0
  127. for (var i = 0; i < password.length; i++) {
  128. ascCode = password.charCodeAt(i).toString(16);
  129. // console.log(ascCode,'asc');
  130. if (ascCode.length == 1) {
  131. val += '00' + ascCode
  132. } else if (ascCode.length == 2) {
  133. val += '0' + ascCode
  134. } else {
  135. val += ascCode
  136. }
  137. }
  138. console.log(val, 'val');
  139. return val
  140. },
  141. },
  142. created() {
  143. // 通过本地使用户名显示
  144. this.getSaveUser()
  145. },
  146. }
  147. </script>
  148. <style scoped>
  149. p {
  150. margin: 0;
  151. padding: 0;
  152. }
  153. /* 整个大盒子css */
  154. .pageBox {
  155. width: 100vw;
  156. height: 100vh;
  157. background-image: url("../../assets/loginNewBack.png");
  158. background-repeat: no-repeat;
  159. background-size: 100% 100%;
  160. /* background-color: #14093E; */
  161. position: relative;
  162. overflow: hidden;
  163. }
  164. /* 登录盒子css */
  165. .loginBox {
  166. width: 640px;
  167. height: 650px;
  168. position: absolute;
  169. top: 140px;
  170. right: 0px;
  171. }
  172. .loginItem {
  173. width: 432px;
  174. }
  175. /* 表单内输入框css */
  176. .loginInput {
  177. width: 432px;
  178. height: 44px;
  179. border-radius: 5px 5px 5px 5px;
  180. opacity: 1;
  181. border: 1px solid #dbdbdb;
  182. background-color: transparent;
  183. /* color: white; */
  184. position: relative;
  185. }
  186. /* 密码框小眼睛css */
  187. .imgEyes {
  188. position: absolute;
  189. top: 50px;
  190. right: 0px;
  191. }
  192. /* 表单内标题p标签css */
  193. .loginTitleP {
  194. width: 210px;
  195. height: 42px;
  196. font-size: 30px;
  197. font-family: PingFang SC-Medium, PingFang SC;
  198. font-weight: 500;
  199. /* color: #FFFFFF; */
  200. line-height: 35px;
  201. margin-left: 100px;
  202. margin-bottom: 52px;
  203. }
  204. /* 表单内p标签css */
  205. .loginItemP {
  206. width: 40px;
  207. height: 28px;
  208. font-size: 20px;
  209. font-family: PingFang SC-Medium, PingFang SC;
  210. font-weight: 500;
  211. /* color: #FFFFFF; */
  212. line-height: 23px;
  213. margin-bottom: 12px;
  214. }
  215. /* 登录按钮css */
  216. .loginButton {
  217. width: 434px;
  218. height: 44px;
  219. background: blue;
  220. border-radius: 5px 5px 5px 5px;
  221. opacity: 1;
  222. border: none;
  223. color: white;
  224. }
  225. /* 表单验证p标签css */
  226. .blurP {
  227. width: 84px;
  228. height: 20px;
  229. font-size: 12px;
  230. font-family: PingFang SC-Regular, PingFang SC;
  231. font-weight: 400;
  232. color: #FF0000;
  233. line-height: 16px;
  234. }
  235. </style>