|
@@ -1,116 +1,229 @@
|
|
|
<template>
|
|
|
- <div class="login">
|
|
|
- <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form">
|
|
|
- <h3 class="title">若依后台管理系统</h3>
|
|
|
- <el-form-item prop="username">
|
|
|
- <el-input
|
|
|
- v-model="loginForm.username"
|
|
|
- type="text"
|
|
|
- auto-complete="off"
|
|
|
- placeholder="账号"
|
|
|
+ <div>
|
|
|
+ <div v-if="showLogin" class="login">
|
|
|
+ <el-form
|
|
|
+ ref="loginForm"
|
|
|
+ :model="loginForm"
|
|
|
+ :rules="loginRules"
|
|
|
+ class="login-form"
|
|
|
+ >
|
|
|
+ <h3 class="title">若依后台管理系统</h3>
|
|
|
+ <el-form-item prop="username">
|
|
|
+ <el-input
|
|
|
+ v-model="loginForm.username"
|
|
|
+ type="text"
|
|
|
+ auto-complete="off"
|
|
|
+ placeholder="账号"
|
|
|
+ >
|
|
|
+ <svg-icon
|
|
|
+ slot="prefix"
|
|
|
+ icon-class="user"
|
|
|
+ class="el-input__icon input-icon"
|
|
|
+ />
|
|
|
+ </el-input>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item prop="password">
|
|
|
+ <el-input
|
|
|
+ v-model="loginForm.password"
|
|
|
+ type="password"
|
|
|
+ auto-complete="off"
|
|
|
+ placeholder="密码"
|
|
|
+ @keyup.enter.native="handleLogin"
|
|
|
+ >
|
|
|
+ <svg-icon
|
|
|
+ slot="prefix"
|
|
|
+ icon-class="password"
|
|
|
+ class="el-input__icon input-icon"
|
|
|
+ />
|
|
|
+ </el-input>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item prop="code" v-if="captchaEnabled">
|
|
|
+ <el-input
|
|
|
+ v-model="loginForm.code"
|
|
|
+ auto-complete="off"
|
|
|
+ placeholder="验证码"
|
|
|
+ style="width: 63%"
|
|
|
+ @keyup.enter.native="handleLogin"
|
|
|
+ >
|
|
|
+ <svg-icon
|
|
|
+ slot="prefix"
|
|
|
+ icon-class="validCode"
|
|
|
+ class="el-input__icon input-icon"
|
|
|
+ />
|
|
|
+ </el-input>
|
|
|
+ <div class="login-code">
|
|
|
+ <img :src="codeUrl" @click="getCode" class="login-code-img" />
|
|
|
+ </div>
|
|
|
+ </el-form-item>
|
|
|
+ <el-checkbox
|
|
|
+ v-model="loginForm.rememberMe"
|
|
|
+ style="margin: 0px 0px 25px 0px"
|
|
|
+ >记住密码</el-checkbox
|
|
|
>
|
|
|
- <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" />
|
|
|
- </el-input>
|
|
|
- </el-form-item>
|
|
|
- <el-form-item prop="password">
|
|
|
- <el-input
|
|
|
- v-model="loginForm.password"
|
|
|
- type="password"
|
|
|
- auto-complete="off"
|
|
|
- placeholder="密码"
|
|
|
- @keyup.enter.native="handleLogin"
|
|
|
- >
|
|
|
- <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
|
|
|
- </el-input>
|
|
|
- </el-form-item>
|
|
|
- <el-form-item prop="code" v-if="captchaEnabled">
|
|
|
- <el-input
|
|
|
- v-model="loginForm.code"
|
|
|
- auto-complete="off"
|
|
|
- placeholder="验证码"
|
|
|
- style="width: 63%"
|
|
|
- @keyup.enter.native="handleLogin"
|
|
|
- >
|
|
|
- <svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon" />
|
|
|
- </el-input>
|
|
|
- <div class="login-code">
|
|
|
- <img :src="codeUrl" @click="getCode" class="login-code-img"/>
|
|
|
- </div>
|
|
|
- </el-form-item>
|
|
|
- <el-checkbox v-model="loginForm.rememberMe" style="margin:0px 0px 25px 0px;">记住密码</el-checkbox>
|
|
|
- <el-form-item style="width:100%;">
|
|
|
- <el-button
|
|
|
- :loading="loading"
|
|
|
- size="medium"
|
|
|
- type="primary"
|
|
|
- style="width:100%;"
|
|
|
- @click.native.prevent="handleLogin"
|
|
|
- >
|
|
|
- <span v-if="!loading">登 录</span>
|
|
|
- <span v-else>登 录 中...</span>
|
|
|
- </el-button>
|
|
|
- <div style="float: right;" v-if="register">
|
|
|
- <router-link class="link-type" :to="'/register'">立即注册</router-link>
|
|
|
- </div>
|
|
|
- </el-form-item>
|
|
|
- </el-form>
|
|
|
- <!-- 底部 -->
|
|
|
- <div class="el-login-footer">
|
|
|
- <span>Copyright © 2018-2023 ruoyi.vip All Rights Reserved.</span>
|
|
|
+ <el-form-item style="width: 100%">
|
|
|
+ <el-button
|
|
|
+ :loading="loading"
|
|
|
+ size="medium"
|
|
|
+ type="primary"
|
|
|
+ style="width: 100%"
|
|
|
+ @click.native.prevent="handleLogin"
|
|
|
+ >
|
|
|
+ <span v-if="!loading">登 录</span>
|
|
|
+ <span v-else>登 录 中...</span>
|
|
|
+ </el-button>
|
|
|
+ <div style="float: right" v-if="register">
|
|
|
+ <router-link class="link-type" :to="'/register'"
|
|
|
+ >立即注册</router-link
|
|
|
+ >
|
|
|
+ </div>
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
+ <div class="el-login-footer">
|
|
|
+ <span>Copyright © 2018-2023 ruoyi.vip All Rights Reserved.</span>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div v-else>
|
|
|
+ <el-button
|
|
|
+ type="primary"
|
|
|
+ plain
|
|
|
+ @click="handleModuleJump('myTaskIndex', 'crm', 'CRM系统')"
|
|
|
+ >
|
|
|
+ CRM系统
|
|
|
+ </el-button>
|
|
|
+ <el-button
|
|
|
+ type="primary"
|
|
|
+ plain
|
|
|
+ @click="handleModuleJump('Index', 'admin', '爱思系统')"
|
|
|
+ >
|
|
|
+ 系统管理
|
|
|
+ </el-button>
|
|
|
</div>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
-import { getCodeImg } from "@/api/login";
|
|
|
+import router from "../router";
|
|
|
+import store from "../store";
|
|
|
+import * as dd from "dingtalk-jsapi"; // 在此引入
|
|
|
+import { getCodeImg, avoidLogin, authToken } from "@/api/login";
|
|
|
import Cookies from "js-cookie";
|
|
|
-import { encrypt, decrypt } from '@/utils/jsencrypt'
|
|
|
+import { encrypt, decrypt } from "@/utils/jsencrypt";
|
|
|
+import { initDingH5RemoteDebug } from "dingtalk-h5-remote-debug";
|
|
|
+import { openAuth } from "dingtalk-design-libs/biz/openAuth";
|
|
|
+import { getENV } from "dingtalk-jsapi/lib/env";
|
|
|
+import { compareVersion } from "dingtalk-jsapi/lib/sdk/sdkLib";
|
|
|
|
|
|
+const { platform, version, appType } = getENV();
|
|
|
+/**
|
|
|
+ * 判断当前app版本是否支持使用SDK
|
|
|
+ * @return {boolean}
|
|
|
+ */
|
|
|
+function isAuthSDKSupport() {
|
|
|
+ return compareVersion(version, "6.3.35");
|
|
|
+}
|
|
|
+initDingH5RemoteDebug();
|
|
|
export default {
|
|
|
name: "Login",
|
|
|
data() {
|
|
|
return {
|
|
|
+ showLogin: false,
|
|
|
codeUrl: "",
|
|
|
loginForm: {
|
|
|
username: "admin",
|
|
|
password: "admin123",
|
|
|
rememberMe: false,
|
|
|
code: "",
|
|
|
- uuid: ""
|
|
|
+ uuid: "",
|
|
|
},
|
|
|
loginRules: {
|
|
|
username: [
|
|
|
- { required: true, trigger: "blur", message: "请输入您的账号" }
|
|
|
+ { required: true, trigger: "blur", message: "请输入您的账号" },
|
|
|
],
|
|
|
password: [
|
|
|
- { required: true, trigger: "blur", message: "请输入您的密码" }
|
|
|
+ { required: true, trigger: "blur", message: "请输入您的密码" },
|
|
|
],
|
|
|
- code: [{ required: true, trigger: "change", message: "请输入验证码" }]
|
|
|
+ code: [{ required: true, trigger: "change", message: "请输入验证码" }],
|
|
|
},
|
|
|
loading: false,
|
|
|
// 验证码开关
|
|
|
captchaEnabled: true,
|
|
|
// 注册开关
|
|
|
register: false,
|
|
|
- redirect: undefined
|
|
|
+ redirect: undefined,
|
|
|
};
|
|
|
},
|
|
|
watch: {
|
|
|
$route: {
|
|
|
- handler: function(route) {
|
|
|
+ handler: function (route) {
|
|
|
this.redirect = route.query && route.query.redirect;
|
|
|
},
|
|
|
- immediate: true
|
|
|
- }
|
|
|
+ immediate: true,
|
|
|
+ },
|
|
|
},
|
|
|
created() {
|
|
|
- this.getCode();
|
|
|
- this.getCookie();
|
|
|
+ console.log("环境=", dd.env.platform);
|
|
|
+ isAuthSDKSupport();
|
|
|
+ // 加上判断条件
|
|
|
+ if (dd.env.platform !== "notInDingTalk") {
|
|
|
+ this.showLogin = false;
|
|
|
+ dd.ready(function () {
|
|
|
+ console.log("-------------000");
|
|
|
+ // 钉钉免登录认证
|
|
|
+ // dd.getAuthCode({
|
|
|
+ // corpId: "ding4ab75ecd53106cde4ac5d6980864d335",
|
|
|
+ // success: (res) => {
|
|
|
+ // console.log("res=", res);
|
|
|
+ // avoidLogin(res.code).then((res) => {
|
|
|
+ // console.log("===avoidLogin_res=",res)
|
|
|
+ // });
|
|
|
+ // },
|
|
|
+ // fail: (err) => {
|
|
|
+ // console.log("err=", err);
|
|
|
+ // },
|
|
|
+ // complete: () => {},
|
|
|
+ // });
|
|
|
+ // 唤起授权
|
|
|
+ openAuth({
|
|
|
+ clientId: "dingwlimimzllguvqf8x", // 应用ID(唯一标识)
|
|
|
+ corpId: "ding4ab75ecd53106cde4ac5d6980864d335", // 当前组织的corpId
|
|
|
+ rpcScope: "Contact.User.Read",//通讯录
|
|
|
+ fieldScope: "Contact.User.mobile",//手机号
|
|
|
+ type: 0, // 0 标识授权个人信息;1 标识授权组织信息
|
|
|
+ }).then((res) => {
|
|
|
+ // 处理返回数据
|
|
|
+ console.log("res", res);
|
|
|
+ authToken(res.result.authCode).then((res) => {
|
|
|
+ console.log("===avoidLogin_res=", res);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ this.showLogin = true;
|
|
|
+ this.getCode();
|
|
|
+ this.getCookie();
|
|
|
+ }
|
|
|
+
|
|
|
+ console.log("-=====login=====");
|
|
|
},
|
|
|
methods: {
|
|
|
+ handleModuleJump(name, type, title) {
|
|
|
+ let that = this;
|
|
|
+ //更改侧边栏参数及title
|
|
|
+ this.$store.commit("SET_SYSTEMTYPE", type);
|
|
|
+ this.$store.commit("SET_SYSTEMTITLE", title);
|
|
|
+ //生成侧边栏
|
|
|
+ store.dispatch("GenerateRoutes").then((accessRoutes) => {
|
|
|
+ console.log("accessRoutes=", accessRoutes);
|
|
|
+ // 根据roles权限生成可访问的路由表
|
|
|
+ router.addRoutes(accessRoutes); // 动态添加可访问路由表
|
|
|
+ that.$router.push({ name, query: { type, title } });
|
|
|
+ });
|
|
|
+ },
|
|
|
getCode() {
|
|
|
- getCodeImg().then(res => {
|
|
|
- this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled;
|
|
|
+ getCodeImg().then((res) => {
|
|
|
+ this.captchaEnabled =
|
|
|
+ res.captchaEnabled === undefined ? true : res.captchaEnabled;
|
|
|
if (this.captchaEnabled) {
|
|
|
this.codeUrl = "data:image/gif;base64," + res.img;
|
|
|
this.loginForm.uuid = res.uuid;
|
|
@@ -120,38 +233,46 @@ export default {
|
|
|
getCookie() {
|
|
|
const username = Cookies.get("username");
|
|
|
const password = Cookies.get("password");
|
|
|
- const rememberMe = Cookies.get('rememberMe')
|
|
|
+ const rememberMe = Cookies.get("rememberMe");
|
|
|
this.loginForm = {
|
|
|
username: username === undefined ? this.loginForm.username : username,
|
|
|
- password: password === undefined ? this.loginForm.password : decrypt(password),
|
|
|
- rememberMe: rememberMe === undefined ? false : Boolean(rememberMe)
|
|
|
+ password:
|
|
|
+ password === undefined ? this.loginForm.password : decrypt(password),
|
|
|
+ rememberMe: rememberMe === undefined ? false : Boolean(rememberMe),
|
|
|
};
|
|
|
},
|
|
|
handleLogin() {
|
|
|
- this.$refs.loginForm.validate(valid => {
|
|
|
+ this.$refs.loginForm.validate((valid) => {
|
|
|
if (valid) {
|
|
|
this.loading = true;
|
|
|
if (this.loginForm.rememberMe) {
|
|
|
Cookies.set("username", this.loginForm.username, { expires: 30 });
|
|
|
- Cookies.set("password", encrypt(this.loginForm.password), { expires: 30 });
|
|
|
- Cookies.set('rememberMe', this.loginForm.rememberMe, { expires: 30 });
|
|
|
+ Cookies.set("password", encrypt(this.loginForm.password), {
|
|
|
+ expires: 30,
|
|
|
+ });
|
|
|
+ Cookies.set("rememberMe", this.loginForm.rememberMe, {
|
|
|
+ expires: 30,
|
|
|
+ });
|
|
|
} else {
|
|
|
Cookies.remove("username");
|
|
|
Cookies.remove("password");
|
|
|
- Cookies.remove('rememberMe');
|
|
|
+ Cookies.remove("rememberMe");
|
|
|
}
|
|
|
- this.$store.dispatch("Login", this.loginForm).then(() => {
|
|
|
- this.$router.push({ path: this.redirect || "/" }).catch(()=>{});
|
|
|
- }).catch(() => {
|
|
|
- this.loading = false;
|
|
|
- if (this.captchaEnabled) {
|
|
|
- this.getCode();
|
|
|
- }
|
|
|
- });
|
|
|
+ this.$store
|
|
|
+ .dispatch("Login", this.loginForm)
|
|
|
+ .then(() => {
|
|
|
+ this.$router.push({ path: this.redirect || "/" }).catch(() => {});
|
|
|
+ })
|
|
|
+ .catch(() => {
|
|
|
+ this.loading = false;
|
|
|
+ if (this.captchaEnabled) {
|
|
|
+ this.getCode();
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
});
|
|
|
- }
|
|
|
- }
|
|
|
+ },
|
|
|
+ },
|
|
|
};
|
|
|
</script>
|
|
|
|