passwd.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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 prop="privacy">
  19. <el-checkbox :label="$t('login.rememberMe')" v-model="form.privacy">
  20. <template #default>
  21. <div class="privacy">我已阅读并同意<span @click="showPrivacy">《用户协议》</span></div>
  22. </template>
  23. </el-checkbox>
  24. </el-form-item>
  25. <el-form-item>
  26. <el-button type="primary" size="large" style="width: 100%;" :loading="islogin" @click="onSuccess">{{ $t('login.signIn') }}</el-button>
  27. </el-form-item>
  28. </el-form>
  29. <el-dialog title="用户协议" v-model="visible" :width="680" destroy-on-close :close-on-click-modal="false" :show-close="false">
  30. <div class="showPrivacy">
  31. <div v-html="baseData.privacy"></div>
  32. </div>
  33. <template #footer>
  34. <el-button type="primary" @click="showPrivacyState">我已阅读并同意</el-button>
  35. </template>
  36. </el-dialog>
  37. </template>
  38. <script>
  39. export default {
  40. emits: ['success', 'upCaptcha'],
  41. props: ['baseData',"captcha"],
  42. data(){
  43. return {
  44. visible:false,
  45. isShow:false,
  46. form: {},
  47. islogin:false,
  48. rules: {
  49. user: [
  50. { required: true, message: this.$t('login.userError'), trigger: 'blur' }
  51. ],
  52. password: [
  53. { required: true, message: this.$t('login.PWError'), trigger: 'blur' }
  54. ],
  55. code: [
  56. { required: true, message: this.$t('login.codeErr'), trigger: 'blur' }
  57. ],
  58. privacy: [
  59. { required: true, message: this.$t('login.privacy'), trigger: 'change' }
  60. ]
  61. },
  62. }
  63. },
  64. methods: {
  65. updateCaptcha(){
  66. this.$emit("upCaptcha");
  67. },
  68. showPrivacy(){
  69. this.visible = true;
  70. },
  71. showPrivacyState(){
  72. if (this.form.privacy == false) {
  73. this.form.privacy = true;
  74. }
  75. this.visible = false;
  76. },
  77. async onSuccess() {
  78. this.isShow = false;
  79. var data = {
  80. username: this.form.user,
  81. code: this.form.code,
  82. key: this.captcha.key,
  83. password: this.$TOOL.crypto.MD5(this.form.password)
  84. }
  85. var validate = await this.$refs.loginForm.validate().catch(() => { })
  86. if (!validate) { return false }
  87. //获取token
  88. this.islogin = true
  89. var user = await this.$API.auth.login.post(data)
  90. if (user.code == 1) {
  91. this.$TOOL.cookie.set("TOKEN", user.data.access_token, {
  92. expires: user.data.expires_in
  93. })
  94. } else {
  95. this.islogin = false
  96. this.$message.error(user.msg)
  97. return false
  98. }
  99. //获取菜单
  100. var menu = await this.$API.menu.list.get()
  101. if (menu.code == 1) {
  102. if (menu.data.menu.length == 0) {
  103. this.islogin = false
  104. this.$alert("当前用户无任何菜单权限,请联系系统管理员", "无权限访问", {
  105. type: 'error',
  106. center: true
  107. })
  108. return false
  109. }
  110. var userData = await this.$API.auth.user.get()
  111. if (userData.code == 0) {
  112. this.islogin = false
  113. this.$alert("当前用户无任何菜单权限,请联系系统管理员", "无权限访问", {
  114. type: 'error',
  115. center: true
  116. })
  117. return false
  118. }
  119. this.$TOOL.data.set("USER_TYPE", userData.data.type)
  120. this.$TOOL.data.set("USER_INFO", userData.data)
  121. this.$TOOL.data.set("MENU", menu.data.menu)
  122. this.$TOOL.data.set("PERMISSIONS", menu.data.permissions)
  123. this.$TOOL.data.set("DASHBOARDGRID", menu.data.dashboardGrid)
  124. } else {
  125. this.islogin = false
  126. this.$message.warning(menu.message)
  127. return false
  128. }
  129. var userType = userData.data.type;
  130. var dashboard = "/dashboard";
  131. if (userType == 1) {
  132. dashboard = "/manage/dashboard";
  133. } else if (userType == 2) {
  134. dashboard = "/merchant/dashboard";
  135. } else if (userType == 3) {
  136. dashboard = "/store/dashboard";
  137. }
  138. this.$emit("success");
  139. this.$message.success(user.msg)
  140. this.$router.replace({
  141. path: dashboard
  142. })
  143. },
  144. onClose() {
  145. this.isShow = false;
  146. },
  147. async login_code() {
  148. var validate = await this.$refs.loginForm.validate().catch(() => { })
  149. if (!validate) { return false }
  150. this.isShow = true;
  151. }
  152. }
  153. }
  154. </script>
  155. <style>
  156. .login-forgot{text-align: right;}
  157. .privacy {
  158. color: #333;
  159. }
  160. .privacy span {
  161. color: #f00;
  162. }
  163. .showPrivacy {
  164. max-height: 500px;
  165. overflow: hidden;
  166. overflow-y: scroll;
  167. line-height: 1.5;
  168. }
  169. .el-input--large .el-input__wrapper{
  170. position: relative;
  171. }
  172. .captcha{
  173. display: flex;
  174. align-items: center;
  175. cursor: pointer;
  176. position: absolute;
  177. right: 1px;
  178. top: 1px;
  179. bottom: 1px;
  180. z-index: 99;
  181. }
  182. .captcha img{
  183. height: 38px;
  184. border-radius: 5px;
  185. }
  186. </style>