passwd.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <template>
  2. <el-form ref="loginForm" :model="form" :rules="rules" label-width="0" label-position="top" size="large" @keyup.enter="login_code">
  3. <el-form-item prop="user" :label="$t('login.userName')">
  4. <el-input v-model="form.user" clearable :placeholder="$t('login.userPlaceholder')"></el-input>
  5. </el-form-item>
  6. <el-form-item prop="password" :label="$t('login.PWName')">
  7. <el-input v-model="form.password" clearable show-password :placeholder="$t('login.PWPlaceholder')"></el-input>
  8. </el-form-item>
  9. <el-form-item prop="code" :label="$t('login.code')">
  10. <el-input v-model="form.code" :placeholder="$t('login.codeErr')">
  11. <template #suffix>
  12. <el-tooltip placement="top-start" :content="$t('login.codeTips')">
  13. <div class="captcha" @click="updateCaptcha"><img :src="captcha.base64" /></div>
  14. </el-tooltip>
  15. </template>
  16. </el-input>
  17. </el-form-item>
  18. <el-form-item>
  19. <el-button type="primary" size="large" style="width: 100%;" :loading="islogin" @click="onSuccess">{{ $t('login.signIn') }}</el-button>
  20. </el-form-item>
  21. </el-form>
  22. </template>
  23. <script>
  24. export default {
  25. emits: ['success', 'upCaptcha'],
  26. props: ['baseData',"captcha"],
  27. data(){
  28. return {
  29. visible:false,
  30. isShow:false,
  31. form: {},
  32. islogin:false,
  33. rules: {
  34. user: [
  35. { required: true, message: this.$t('login.userError'), trigger: 'blur' }
  36. ],
  37. password: [
  38. { required: true, message: this.$t('login.PWError'), trigger: 'blur' }
  39. ],
  40. code: [
  41. { required: true, message: this.$t('login.codeErr'), trigger: 'blur' }
  42. ]
  43. },
  44. }
  45. },
  46. methods: {
  47. updateCaptcha(){
  48. this.$emit("upCaptcha");
  49. },
  50. showPrivacy(){
  51. this.visible = true;
  52. },
  53. showPrivacyState(){
  54. if (this.form.privacy == false) {
  55. this.form.privacy = true;
  56. }
  57. this.visible = false;
  58. },
  59. async onSuccess() {
  60. this.isShow = false;
  61. var data = {
  62. username: this.form.user,
  63. code: this.form.code,
  64. key: this.captcha.key,
  65. password: this.$TOOL.crypto.MD5(this.form.password)
  66. }
  67. var validate = await this.$refs.loginForm.validate().catch(() => { })
  68. if (!validate) { return false }
  69. //获取token
  70. this.islogin = true
  71. var user = await this.$API.auth.login.post(data)
  72. if (user.code == 1) {
  73. this.$TOOL.cookie.set("TOKEN", user.data.access_token, {
  74. expires: user.data.expires_in
  75. })
  76. } else {
  77. this.islogin = false
  78. this.$message.error(user.msg)
  79. return false
  80. }
  81. //获取菜单
  82. var menu = await this.$API.menu.list.get()
  83. if (menu.code == 1) {
  84. if (menu.data.menu.length == 0) {
  85. this.islogin = false
  86. this.$alert("当前用户无任何菜单权限,请联系系统管理员", "无权限访问", {
  87. type: 'error',
  88. center: true
  89. })
  90. return false
  91. }
  92. var userData = await this.$API.auth.user.get()
  93. if (userData.code == 0) {
  94. this.islogin = false
  95. this.$alert("当前用户无任何菜单权限,请联系系统管理员", "无权限访问", {
  96. type: 'error',
  97. center: true
  98. })
  99. return false
  100. }
  101. this.$TOOL.data.set("USER_TYPE", userData.data.type)
  102. this.$TOOL.data.set("USER_INFO", userData.data)
  103. this.$TOOL.data.set("MENU", menu.data.menu)
  104. this.$TOOL.data.set("PERMISSIONS", menu.data.permissions)
  105. this.$TOOL.data.set("DASHBOARDGRID", menu.data.dashboardGrid)
  106. } else {
  107. this.islogin = false
  108. this.$message.warning(menu.message)
  109. return false
  110. }
  111. this.$emit("success");
  112. this.$message.success(user.msg)
  113. this.$router.replace({
  114. path: "/"
  115. })
  116. },
  117. onClose() {
  118. this.isShow = false;
  119. },
  120. async login_code() {
  121. var validate = await this.$refs.loginForm.validate().catch(() => { })
  122. if (!validate) { return false }
  123. this.isShow = true;
  124. }
  125. }
  126. }
  127. </script>
  128. <style>
  129. .login-forgot{text-align: right;}
  130. .privacy {
  131. color: #333;
  132. }
  133. .privacy span {
  134. color: #f00;
  135. }
  136. .showPrivacy {
  137. max-height: 500px;
  138. overflow: hidden;
  139. overflow-y: scroll;
  140. line-height: 1.5;
  141. }
  142. .el-input--large .el-input__wrapper{
  143. position: relative;
  144. }
  145. .captcha{
  146. display: flex;
  147. align-items: center;
  148. cursor: pointer;
  149. position: absolute;
  150. right: 1px;
  151. top: 1px;
  152. bottom: 1px;
  153. z-index: 99;
  154. }
  155. .captcha img{
  156. height: 38px;
  157. border-radius: 5px;
  158. }
  159. </style>