Commit c720b1dff9cb1f44719f8cd9ae84eca5e4cf4593

Authored by xingyu
1 parent 2513bbf0

fix: 三方登录未携带租户

yudao-ui-admin-vue3/src/api/login/index.ts
@@ -57,7 +57,7 @@ export const smsLoginApi = (data: SmsLoginVO) => { @@ -57,7 +57,7 @@ export const smsLoginApi = (data: SmsLoginVO) => {
57 } 57 }
58 58
59 // 社交授权的跳转 59 // 社交授权的跳转
60 -export const socialAuthRedirectApi = (type: string, redirectUri: string) => { 60 +export const socialAuthRedirectApi = (type: number, redirectUri: string) => {
61 return request.get({ 61 return request.get({
62 url: '/system/auth/social-auth-redirect?type=' + type + '&redirectUri=' + redirectUri 62 url: '/system/auth/social-auth-redirect?type=' + type + '&redirectUri=' + redirectUri
63 }) 63 })
yudao-ui-admin-vue3/src/views/Login/components/LoginForm.vue
@@ -16,7 +16,7 @@ @@ -16,7 +16,7 @@
16 </el-form-item> 16 </el-form-item>
17 </el-col> 17 </el-col>
18 <el-col :span="24" style="padding-left: 10px; padding-right: 10px"> 18 <el-col :span="24" style="padding-left: 10px; padding-right: 10px">
19 - <el-form-item prop="tenantName"> 19 + <el-form-item prop="tenantName" v-if="loginData.tenantEnable === 'true'">
20 <el-input 20 <el-input
21 type="text" 21 type="text"
22 v-model="loginData.loginForm.tenantName" 22 v-model="loginData.loginForm.tenantName"
@@ -65,9 +65,13 @@ @@ -65,9 +65,13 @@
65 </el-col> 65 </el-col>
66 <el-col :span="24" style="padding-left: 10px; padding-right: 10px"> 66 <el-col :span="24" style="padding-left: 10px; padding-right: 10px">
67 <el-form-item> 67 <el-form-item>
68 - <el-button :loading="loginLoading" type="primary" class="w-[100%]" @click="getCode()">  
69 - {{ t('login.login') }}  
70 - </el-button> 68 + <XButton
  69 + :loading="loginLoading"
  70 + type="primary"
  71 + class="w-[100%]"
  72 + :title="t('login.login')"
  73 + @click="getCode()"
  74 + />
71 </el-form-item> 75 </el-form-item>
72 </el-col> 76 </el-col>
73 <Verify 77 <Verify
@@ -81,19 +85,25 @@ @@ -81,19 +85,25 @@
81 <el-form-item> 85 <el-form-item>
82 <el-row justify="space-between" style="width: 100%" :gutter="5"> 86 <el-row justify="space-between" style="width: 100%" :gutter="5">
83 <el-col :span="8"> 87 <el-col :span="8">
84 - <el-button class="w-[100%]" @click="setLoginState(LoginStateEnum.MOBILE)">  
85 - {{ t('login.btnMobile') }}  
86 - </el-button> 88 + <XButton
  89 + class="w-[100%]"
  90 + :title="t('login.btnMobile')"
  91 + @click="setLoginState(LoginStateEnum.MOBILE)"
  92 + />
87 </el-col> 93 </el-col>
88 <el-col :span="8"> 94 <el-col :span="8">
89 - <el-button class="w-[100%]" @click="setLoginState(LoginStateEnum.QR_CODE)">  
90 - {{ t('login.btnQRCode') }}  
91 - </el-button> 95 + <XButton
  96 + class="w-[100%]"
  97 + :title="t('login.btnQRCode')"
  98 + @click="setLoginState(LoginStateEnum.QR_CODE)"
  99 + />
92 </el-col> 100 </el-col>
93 <el-col :span="8"> 101 <el-col :span="8">
94 - <el-button class="w-[100%]" @click="setLoginState(LoginStateEnum.REGISTER)">  
95 - {{ t('login.btnRegister') }}  
96 - </el-button> 102 + <XButton
  103 + class="w-[100%]"
  104 + :title="t('login.btnRegister')"
  105 + @click="setLoginState(LoginStateEnum.REGISTER)"
  106 + />
97 </el-col> 107 </el-col>
98 </el-row> 108 </el-row>
99 </el-form-item> 109 </el-form-item>
@@ -103,32 +113,13 @@ @@ -103,32 +113,13 @@
103 <el-form-item> 113 <el-form-item>
104 <div class="flex justify-between w-[100%]"> 114 <div class="flex justify-between w-[100%]">
105 <Icon 115 <Icon
106 - icon="ant-design:github-filled"  
107 - :size="30"  
108 - class="cursor-pointer anticon"  
109 - color="#999"  
110 - @click="doSocialLogin('github')"  
111 - />  
112 - <Icon  
113 - icon="ant-design:wechat-filled"  
114 - :size="30"  
115 - class="cursor-pointer anticon"  
116 - color="#999"  
117 - @click="doSocialLogin('wechat')"  
118 - />  
119 - <Icon  
120 - icon="ant-design:alipay-circle-filled" 116 + v-for="(item, key) in socialList"
  117 + :key="key"
  118 + :icon="item.icon"
121 :size="30" 119 :size="30"
122 - color="#999"  
123 class="cursor-pointer anticon" 120 class="cursor-pointer anticon"
124 - @click="doSocialLogin('alipay')"  
125 - />  
126 - <Icon  
127 - icon="ant-design:dingtalk-circle-filled"  
128 - :size="30"  
129 color="#999" 121 color="#999"
130 - class="cursor-pointer anticon"  
131 - @click="doSocialLogin('dingtalk')" 122 + @click="doSocialLogin(item.type)"
132 /> 123 />
133 </div> 124 </div>
134 </el-form-item> 125 </el-form-item>
@@ -154,6 +145,7 @@ import { useRouter } from &#39;vue-router&#39; @@ -154,6 +145,7 @@ import { useRouter } from &#39;vue-router&#39;
154 import type { RouteLocationNormalizedLoaded } from 'vue-router' 145 import type { RouteLocationNormalizedLoaded } from 'vue-router'
155 import { useI18n } from '@/hooks/web/useI18n' 146 import { useI18n } from '@/hooks/web/useI18n'
156 import { useIcon } from '@/hooks/web/useIcon' 147 import { useIcon } from '@/hooks/web/useIcon'
  148 +import { useMessage } from '@/hooks/web/useMessage'
157 import { required } from '@/utils/formRules' 149 import { required } from '@/utils/formRules'
158 import * as authUtil from '@/utils/auth' 150 import * as authUtil from '@/utils/auth'
159 import { decrypt } from '@/utils/jsencrypt' 151 import { decrypt } from '@/utils/jsencrypt'
@@ -162,8 +154,13 @@ import { Verify } from &#39;@/components/Verifition&#39; @@ -162,8 +154,13 @@ import { Verify } from &#39;@/components/Verifition&#39;
162 import { usePermissionStore } from '@/store/modules/permission' 154 import { usePermissionStore } from '@/store/modules/permission'
163 import * as LoginApi from '@/api/login' 155 import * as LoginApi from '@/api/login'
164 import { LoginStateEnum, useLoginState, useFormValid } from './useLogin' 156 import { LoginStateEnum, useLoginState, useFormValid } from './useLogin'
  157 +import { XButton } from '@/components/XButton'
165 158
166 const { t } = useI18n() 159 const { t } = useI18n()
  160 +const message = useMessage()
  161 +const iconHouse = useIcon({ icon: 'ep:house' })
  162 +const iconAvatar = useIcon({ icon: 'ep:avatar' })
  163 +const iconLock = useIcon({ icon: 'ep:lock' })
167 const formLogin = ref() 164 const formLogin = ref()
168 const { validForm } = useFormValid(formLogin) 165 const { validForm } = useFormValid(formLogin)
169 const { setLoginState, getLoginState } = useLoginState() 166 const { setLoginState, getLoginState } = useLoginState()
@@ -171,9 +168,6 @@ const { currentRoute, push } = useRouter() @@ -171,9 +168,6 @@ const { currentRoute, push } = useRouter()
171 const permissionStore = usePermissionStore() 168 const permissionStore = usePermissionStore()
172 const redirect = ref<string>('') 169 const redirect = ref<string>('')
173 const loginLoading = ref(false) 170 const loginLoading = ref(false)
174 -const iconHouse = useIcon({ icon: 'ep:house' })  
175 -const iconAvatar = useIcon({ icon: 'ep:avatar' })  
176 -const iconLock = useIcon({ icon: 'ep:lock' })  
177 const verify = ref() 171 const verify = ref()
178 const captchaType = ref('blockPuzzle') // blockPuzzle 滑块 clickWord 点击文字 172 const captchaType = ref('blockPuzzle') // blockPuzzle 滑块 clickWord 点击文字
179 173
@@ -201,6 +195,25 @@ const loginData = reactive({ @@ -201,6 +195,25 @@ const loginData = reactive({
201 } 195 }
202 }) 196 })
203 197
  198 +const socialList = [
  199 + {
  200 + icon: 'ant-design:github-filled',
  201 + type: 0
  202 + },
  203 + {
  204 + icon: 'ant-design:wechat-filled',
  205 + type: 30
  206 + },
  207 + {
  208 + icon: 'ant-design:alipay-circle-filled',
  209 + type: 0
  210 + },
  211 + {
  212 + icon: 'ant-design:dingtalk-circle-filled',
  213 + type: 20
  214 + }
  215 +]
  216 +
204 // 获取验证码 217 // 获取验证码
205 const getCode = async () => { 218 const getCode = async () => {
206 // 情况一,未开启:则直接登录 219 // 情况一,未开启:则直接登录
@@ -214,8 +227,10 @@ const getCode = async () =&gt; { @@ -214,8 +227,10 @@ const getCode = async () =&gt; {
214 } 227 }
215 //获取租户ID 228 //获取租户ID
216 const getTenantId = async () => { 229 const getTenantId = async () => {
217 - const res = await LoginApi.getTenantIdByNameApi(loginData.loginForm.tenantName)  
218 - authUtil.setTenantId(res) 230 + if (loginData.tenantEnable === 'true') {
  231 + const res = await LoginApi.getTenantIdByNameApi(loginData.loginForm.tenantName)
  232 + authUtil.setTenantId(res)
  233 + }
219 } 234 }
220 // 记住我 235 // 记住我
221 const getCookie = () => { 236 const getCookie = () => {
@@ -279,14 +294,24 @@ const handleLogin = async (params) =&gt; { @@ -279,14 +294,24 @@ const handleLogin = async (params) =&gt; {
279 } 294 }
280 295
281 // 社交登录 296 // 社交登录
282 -const doSocialLogin = async (type: string) => {  
283 - loginLoading.value = true  
284 - // 计算 redirectUri  
285 - const redirectUri =  
286 - location.origin + '/social-login?type=' + type + '&redirect=' + (redirect.value || '/')  
287 - // 进行跳转  
288 - const res = await LoginApi.socialAuthRedirectApi(type, encodeURIComponent(redirectUri))  
289 - window.location.href = res 297 +const doSocialLogin = async (type: number) => {
  298 + if (type === 0) {
  299 + message.error('此方式未配置')
  300 + } else {
  301 + loginLoading.value = true
  302 + if (loginData.tenantEnable === 'true') {
  303 + await message.prompt('请输入租户名称', t('common.reminder')).then(async ({ value }) => {
  304 + const res = await LoginApi.getTenantIdByNameApi(value)
  305 + authUtil.setTenantId(res)
  306 + })
  307 + }
  308 + // 计算 redirectUri
  309 + const redirectUri =
  310 + location.origin + '/social-login?type=' + type + '&redirect=' + (redirect.value || '/')
  311 + // 进行跳转
  312 + const res = await LoginApi.socialAuthRedirectApi(type, encodeURIComponent(redirectUri))
  313 + window.location.href = res
  314 + }
290 } 315 }
291 watch( 316 watch(
292 () => currentRoute.value, 317 () => currentRoute.value,
yudao-ui-admin/src/views/login.vue
@@ -53,10 +53,10 @@ @@ -53,10 +53,10 @@
53 <el-form-item prop="mobileCode"> 53 <el-form-item prop="mobileCode">
54 <el-input v-model="loginForm.mobileCode" type="text" auto-complete="off" placeholder="短信验证码" 54 <el-input v-model="loginForm.mobileCode" type="text" auto-complete="off" placeholder="短信验证码"
55 @keyup.enter.native="handleLogin"> 55 @keyup.enter.native="handleLogin">
56 - <template slot="icon"> 56 + <template v-slot="icon">
57 <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon"/> 57 <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon"/>
58 </template> 58 </template>
59 - <template slot="append"> 59 + <template v-slot="append">
60 <span v-if="mobileCodeTimer <= 0" class="getMobileCode" @click="getSmsCode" style="cursor: pointer;">获取验证码</span> 60 <span v-if="mobileCodeTimer <= 0" class="getMobileCode" @click="getSmsCode" style="cursor: pointer;">获取验证码</span>
61 <span v-if="mobileCodeTimer > 0" class="getMobileCode">{{ mobileCodeTimer }}秒后可重新获取</span> 61 <span v-if="mobileCodeTimer > 0" class="getMobileCode">{{ mobileCodeTimer }}秒后可重新获取</span>
62 </template> 62 </template>
@@ -115,6 +115,7 @@ import { @@ -115,6 +115,7 @@ import {
115 } from "@/utils/auth"; 115 } from "@/utils/auth";
116 116
117 import Verify from '@/components/Verifition/Verify'; 117 import Verify from '@/components/Verifition/Verify';
  118 +import {resetUserPwd} from "@/api/system/user";
118 119
119 export default { 120 export default {
120 name: "Login", 121 name: "Login",
@@ -254,19 +255,40 @@ export default { @@ -254,19 +255,40 @@ export default {
254 } 255 }
255 }); 256 });
256 }, 257 },
257 - doSocialLogin(socialTypeEnum) { 258 + async doSocialLogin(socialTypeEnum) {
258 // 设置登录中 259 // 设置登录中
259 this.loading = true; 260 this.loading = true;
260 - // 计算 redirectUri  
261 - const redirectUri = location.origin + '/social-login?'  
262 - + encodeURIComponent('type=' + socialTypeEnum.type + '&redirect=' + (this.redirect || "/")); // 重定向不能丢  
263 - // const redirectUri = 'http://127.0.0.1:48080/api/gitee/callback';  
264 - // const redirectUri = 'http://127.0.0.1:48080/api/dingtalk/callback';  
265 - // 进行跳转  
266 - socialAuthRedirect(socialTypeEnum.type, encodeURIComponent(redirectUri)).then((res) => {  
267 - // console.log(res.url);  
268 - window.location.href = res.data;  
269 - }); 261 + let tenant = false;
  262 + if (this.tenantEnable) {
  263 + await this.$prompt('请输入租户名称', "提示", {
  264 + confirmButtonText: "确定",
  265 + cancelButtonText: "取消"
  266 + }).then(({value}) => {
  267 + getTenantIdByName(value).then(res => {
  268 + const tenantId = res.data;
  269 + tenant = true
  270 + if (tenantId && tenantId >= 0) {
  271 + setTenantId(tenantId)
  272 + }
  273 + });
  274 + }).catch(() => {
  275 + return false
  276 + });
  277 + } else {
  278 + tenant = true
  279 + }
  280 + if(tenant){
  281 + // 计算 redirectUri
  282 + const redirectUri = location.origin + '/social-login?'
  283 + + encodeURIComponent('type=' + socialTypeEnum.type + '&redirect=' + (this.redirect || "/")); // 重定向不能丢
  284 + // const redirectUri = 'http://127.0.0.1:48080/api/gitee/callback';
  285 + // const redirectUri = 'http://127.0.0.1:48080/api/dingtalk/callback';
  286 + // 进行跳转
  287 + socialAuthRedirect(socialTypeEnum.type, encodeURIComponent(redirectUri)).then((res) => {
  288 + // console.log(res.url);
  289 + window.location.href = res.data;
  290 + });
  291 + }
270 }, 292 },
271 /** ========== 以下为升级短信登录 ========== */ 293 /** ========== 以下为升级短信登录 ========== */
272 getSmsCode() { 294 getSmsCode() {