login.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. <template>
  2. <div class="login">
  3. <el-form ref="loginRef" :model="loginForm" :rules="loginRules" class="login-form">
  4. <h3 class="title">南宁北排管理系统</h3>
  5. <el-form-item prop="username">
  6. <el-input
  7. v-model="loginForm.username"
  8. type="text"
  9. size="large"
  10. auto-complete="off"
  11. placeholder="账号"
  12. >
  13. <template #prefix><svg-icon icon-class="user" class="el-input__icon input-icon" /></template>
  14. </el-input>
  15. </el-form-item>
  16. <el-form-item prop="password">
  17. <el-input
  18. v-model="loginForm.password"
  19. type="password"
  20. size="large"
  21. auto-complete="off"
  22. placeholder="密码"
  23. @keyup.enter="handleLogin"
  24. >
  25. <template #prefix><svg-icon icon-class="password" class="el-input__icon input-icon" /></template>
  26. </el-input>
  27. </el-form-item>
  28. <el-form-item prop="code" v-if="captchaOnOff">
  29. <el-input
  30. v-model="loginForm.code"
  31. size="large"
  32. auto-complete="off"
  33. placeholder="验证码"
  34. style="width: 63%"
  35. @keyup.enter="handleLogin"
  36. >
  37. <template #prefix><svg-icon icon-class="validCode" class="el-input__icon input-icon" /></template>
  38. </el-input>
  39. <div class="login-code">
  40. <img :src="codeUrl" @click="getCode" class="login-code-img"/>
  41. </div>
  42. </el-form-item>
  43. <el-checkbox v-model="loginForm.rememberMe" style="margin:0px 0px 25px 0px;">记住密码</el-checkbox>
  44. <el-form-item style="width:100%;">
  45. <el-button
  46. :loading="loading"
  47. size="large"
  48. type="primary"
  49. style="width:100%;"
  50. @click.prevent="handleLogin"
  51. >
  52. <span v-if="!loading">登 录</span>
  53. <span v-else>登 录 中...</span>
  54. </el-button>
  55. <div style="float: right;" v-if="register">
  56. <router-link class="link-type" :to="'/register'">立即注册</router-link>
  57. </div>
  58. </el-form-item>
  59. </el-form>
  60. <!-- 底部 -->
  61. <div class="el-login-footer">
  62. <span>Copyright © 2018-2022 ruoyi.vip All Rights Reserved.</span>
  63. </div>
  64. </div>
  65. </template>
  66. <script setup>
  67. import { getCodeImg } from "@/api/login";
  68. import Cookies from "js-cookie";
  69. import { encrypt, decrypt } from "@/utils/jsencrypt";
  70. import dd from 'dingtalk-jsapi';
  71. const store = useStore();
  72. const router = useRouter();
  73. const { proxy } = getCurrentInstance();
  74. const loginForm = ref({
  75. username: "admin",
  76. password: "admin123",
  77. rememberMe: false,
  78. code: "",
  79. uuid: ""
  80. });
  81. const loginRules = {
  82. username: [{ required: true, trigger: "blur", message: "请输入您的账号" }],
  83. password: [{ required: true, trigger: "blur", message: "请输入您的密码" }],
  84. code: [{ required: true, trigger: "change", message: "请输入验证码" }]
  85. };
  86. const codeUrl = ref("");
  87. const loading = ref(false);
  88. // 验证码开关
  89. const captchaOnOff = ref(true);
  90. // 注册开关
  91. const register = ref(false);
  92. const redirect = ref('/task/list/1');
  93. function ddtologin(){
  94. try{
  95. dd.runtime.permission.requestAuthCode({
  96. corpId: "dingb9991e173e3ef14fa1320dcb25e91351",
  97. onSuccess: function(result) {
  98. store.dispatch("DDTOLogin", result.code).then(() => {
  99. debugger
  100. router.push({ path: redirect.value || "/" });
  101. }).catch((e) => {
  102. console.log( e)
  103. loading.value = false;
  104. });
  105. console.log(result);
  106. },
  107. onFail : function(err) {}
  108. })
  109. }catch (e){
  110. }
  111. }
  112. function handleLogin() {
  113. proxy.$refs.loginRef.validate(valid => {
  114. if (valid) {
  115. loading.value = true;
  116. // 勾选了需要记住密码设置在cookie中设置记住用户明和名命
  117. if (loginForm.value.rememberMe) {
  118. Cookies.set("username", loginForm.value.username, { expires: 30 });
  119. Cookies.set("password", encrypt(loginForm.value.password), { expires: 30 });
  120. Cookies.set("rememberMe", loginForm.value.rememberMe, { expires: 30 });
  121. } else {
  122. // 否则移除
  123. Cookies.remove("username");
  124. Cookies.remove("password");
  125. Cookies.remove("rememberMe");
  126. }
  127. // 调用action的登录方法
  128. store.dispatch("Login", loginForm.value).then(() => {
  129. router.push({ path: redirect.value || "/" });
  130. }).catch(() => {
  131. loading.value = false;
  132. // 重新获取验证码
  133. if (captchaOnOff.value) {
  134. getCode();
  135. }
  136. });
  137. }
  138. });
  139. }
  140. function getCode() {
  141. getCodeImg().then(res => {
  142. captchaOnOff.value = res.captchaOnOff === undefined ? false : res.captchaOnOff;
  143. if (captchaOnOff.value) {
  144. codeUrl.value = "data:image/gif;base64," + res.img;
  145. loginForm.value.uuid = res.uuid;
  146. }
  147. });
  148. }
  149. function getCookie() {
  150. const username = Cookies.get("username");
  151. const password = Cookies.get("password");
  152. const rememberMe = Cookies.get("rememberMe");
  153. loginForm.value = {
  154. username: username === undefined ? loginForm.value.username : username,
  155. password: password === undefined ? loginForm.value.password : decrypt(password),
  156. rememberMe: rememberMe === undefined ? false : Boolean(rememberMe)
  157. };
  158. }
  159. getCode();
  160. getCookie();
  161. ddtologin();
  162. </script>
  163. <style lang='scss' scoped>
  164. .login {
  165. display: flex;
  166. justify-content: center;
  167. align-items: center;
  168. height: 100%;
  169. background-image: url("../assets/images/bg.webp");
  170. background-size: cover;
  171. }
  172. .title {
  173. margin: 0px auto 30px auto;
  174. text-align: center;
  175. color: #707070;
  176. }
  177. .login-form {
  178. border-radius: 6px;
  179. background: #ffffff;
  180. width: 400px;
  181. padding: 25px 25px 5px 25px;
  182. .el-input {
  183. height: 40px;
  184. input {
  185. height: 40px;
  186. }
  187. }
  188. .input-icon {
  189. height: 39px;
  190. width: 14px;
  191. margin-left: 0px;
  192. }
  193. }
  194. .login-tip {
  195. font-size: 13px;
  196. text-align: center;
  197. color: #bfbfbf;
  198. }
  199. .login-code {
  200. width: 33%;
  201. height: 40px;
  202. float: right;
  203. img {
  204. cursor: pointer;
  205. vertical-align: middle;
  206. }
  207. }
  208. .el-login-footer {
  209. display: none;
  210. height: 40px;
  211. line-height: 40px;
  212. position: fixed;
  213. bottom: 0;
  214. width: 100%;
  215. text-align: center;
  216. color: #fff;
  217. font-family: Arial;
  218. font-size: 12px;
  219. letter-spacing: 1px;
  220. }
  221. .login-code-img {
  222. height: 40px;
  223. padding-left: 12px;
  224. }
  225. </style>