mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-10-31 10:18:42 +08:00 
			
		
		
		
	进一步重构社交登陆的实现
This commit is contained in:
		| @@ -9,7 +9,7 @@ export function login(username, password, code, uuid) { | ||||
|     uuid | ||||
|   } | ||||
|   return request({ | ||||
|     url: '/system/login', | ||||
|     url: '/system/auth/login', | ||||
|     method: 'post', | ||||
|     data: data | ||||
|   }) | ||||
| @@ -18,7 +18,7 @@ export function login(username, password, code, uuid) { | ||||
| // 获取用户详细信息 | ||||
| export function getInfo() { | ||||
|   return request({ | ||||
|     url: '/system/get-permission-info', | ||||
|     url: '/system/auth/get-permission-info', | ||||
|     method: 'get' | ||||
|   }) | ||||
| } | ||||
| @@ -43,15 +43,15 @@ export function getCodeImg() { | ||||
| // 社交授权的跳转 | ||||
| export function socialAuthRedirect(type, redirectUri) { | ||||
|   return request({ | ||||
|     url: '/system/social-auth-redirect?type=' + type + '&redirectUri=' + redirectUri, | ||||
|     url: '/system/auth/social-auth-redirect?type=' + type + '&redirectUri=' + redirectUri, | ||||
|     method: 'get' | ||||
|   }) | ||||
| } | ||||
|  | ||||
| // 社交登录,使用 code 授权码 | ||||
| export function socialLogin(type, code, state) { | ||||
| // 社交快捷登录,使用 code 授权码 | ||||
| export function socialQuickLogin(type, code, state) { | ||||
|   return request({ | ||||
|     url: '/system/social-login', | ||||
|     url: '/system/auth/social-quick-login', | ||||
|     method: 'post', | ||||
|     data: { | ||||
|       type, | ||||
| @@ -61,10 +61,10 @@ export function socialLogin(type, code, state) { | ||||
|   }) | ||||
| } | ||||
|  | ||||
| // 社交登录,使用 code 授权码 + + 账号密码 | ||||
| export function socialLogin2(type, code, state, username, password) { | ||||
| // 社交绑定登录,使用 code 授权码 + + 账号密码 | ||||
| export function socialBindLogin(type, code, state, username, password) { | ||||
|   return request({ | ||||
|     url: '/system/social-login2', | ||||
|     url: '/system/auth/social-bind-login', | ||||
|     method: 'post', | ||||
|     data: { | ||||
|       type, | ||||
| @@ -75,28 +75,3 @@ export function socialLogin2(type, code, state, username, password) { | ||||
|     } | ||||
|   }) | ||||
| } | ||||
|  | ||||
| // 社交绑定,使用 code 授权码 | ||||
| export function socialBind(type, code, state) { | ||||
|   return request({ | ||||
|     url: '/system/social-bind', | ||||
|     method: 'post', | ||||
|     data: { | ||||
|       type, | ||||
|       code, | ||||
|       state, | ||||
|     } | ||||
|   }) | ||||
| } | ||||
|  | ||||
| // 取消社交绑定 | ||||
| export function socialUnbind(type, unionId) { | ||||
|   return request({ | ||||
|     url: '/system/social-unbind', | ||||
|     method: 'delete', | ||||
|     data: { | ||||
|       type, | ||||
|       unionId | ||||
|     } | ||||
|   }) | ||||
| } | ||||
|   | ||||
| @@ -3,7 +3,7 @@ import request from '@/utils/request' | ||||
| // 获取路由 | ||||
| export const getRouters = () => { | ||||
|   return request({ | ||||
|     url: '/system/list-menus', | ||||
|     url: '/system/auth/list-menus', | ||||
|     method: 'get' | ||||
|   }) | ||||
| } | ||||
|   | ||||
							
								
								
									
										26
									
								
								yudao-ui-admin/src/api/system/socialUser.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								yudao-ui-admin/src/api/system/socialUser.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,26 @@ | ||||
| import request from "@/utils/request"; | ||||
|  | ||||
| // 社交绑定,使用 code 授权码 | ||||
| export function socialBind(type, code, state) { | ||||
|   return request({ | ||||
|     url: '/system/social-user/bind', | ||||
|     method: 'post', | ||||
|     data: { | ||||
|       type, | ||||
|       code, | ||||
|       state, | ||||
|     } | ||||
|   }) | ||||
| } | ||||
|  | ||||
| // 取消社交绑定 | ||||
| export function socialUnbind(type, unionId) { | ||||
|   return request({ | ||||
|     url: '/system/social-user/unbind', | ||||
|     method: 'delete', | ||||
|     data: { | ||||
|       type, | ||||
|       unionId | ||||
|     } | ||||
|   }) | ||||
| } | ||||
| @@ -1,4 +1,4 @@ | ||||
| import {login, logout, getInfo, socialLogin, socialLogin2} from '@/api/login' | ||||
| import {login, logout, getInfo, socialQuickLogin, socialBindLogin} from '@/api/login' | ||||
| import { getToken, setToken, removeToken } from '@/utils/auth' | ||||
|  | ||||
| const user = { | ||||
| @@ -57,7 +57,7 @@ const user = { | ||||
|       const state = userInfo.state | ||||
|       const type = userInfo.type | ||||
|       return new Promise((resolve, reject) => { | ||||
|         socialLogin(type, code, state).then(res => { | ||||
|         socialQuickLogin(type, code, state).then(res => { | ||||
|           res = res.data; | ||||
|           setToken(res.token) | ||||
|           commit('SET_TOKEN', res.token) | ||||
| @@ -76,7 +76,7 @@ const user = { | ||||
|       const username = userInfo.username.trim() | ||||
|       const password = userInfo.password | ||||
|       return new Promise((resolve, reject) => { | ||||
|         socialLogin2(type, code, state, username, password).then(res => { | ||||
|         socialBindLogin(type, code, state, username, password).then(res => { | ||||
|           res = res.data; | ||||
|           setToken(res.token) | ||||
|           commit('SET_TOKEN', res.token) | ||||
|   | ||||
| @@ -71,12 +71,6 @@ export const InfraApiErrorLogProcessStatusEnum = { | ||||
|  * 用户的社交平台的类型枚举 | ||||
|  */ | ||||
| export const SystemUserSocialTypeEnum = { | ||||
|   // GITEE: { | ||||
|   //   title: "码云", | ||||
|   //   type: 10, | ||||
|   //   source: "gitee", | ||||
|   //   img: "https://cdn.jsdelivr.net/gh/justauth/justauth-oauth-logo@1.11/gitee.png", | ||||
|   // }, | ||||
|   DINGTALK: { | ||||
|     title: "钉钉", | ||||
|     type: 20, | ||||
|   | ||||
| @@ -176,7 +176,6 @@ export default { | ||||
|       }); | ||||
|     }, | ||||
|     doSocialLogin(socialTypeEnum) { | ||||
|       // console.log("开始Oauth登录...%o", socialTypeEnum.code); | ||||
|       // 设置登录中 | ||||
|       this.loading = true; | ||||
|       // 计算 redirectUri | ||||
|   | ||||
| @@ -7,7 +7,7 @@ | ||||
|     </el-table-column> | ||||
|     <el-table-column label="操作" align="left" > | ||||
|       <template slot-scope="scope"> | ||||
|         <div v-if="scope.row.unionId"> | ||||
|         <div v-if="scope.row.openid"> | ||||
|           已绑定 | ||||
|           <el-button size="large" type="text" @click="unbind(scope.row)">(解绑)</el-button> | ||||
|         </div> | ||||
| @@ -23,7 +23,8 @@ | ||||
| <script> | ||||
|  | ||||
| import {SystemUserSocialTypeEnum} from "@/utils/constants"; | ||||
| import {socialAuthRedirect, socialBind, socialUnbind} from "@/api/login"; | ||||
| import {socialAuthRedirect} from "@/api/login"; | ||||
| import {socialBind, socialUnbind} from "@/api/system/socialUser"; | ||||
|  | ||||
| export default { | ||||
|   props: { | ||||
| @@ -50,7 +51,7 @@ export default { | ||||
|         if (this.user.socialUsers) { | ||||
|           for (const j in this.user.socialUsers) { | ||||
|             if (socialUser.type === this.user.socialUsers[j].type) { | ||||
|               socialUser.unionId = this.user.socialUsers[j].unionId; | ||||
|               socialUser.openid = this.user.socialUsers[j].openid; | ||||
|               break; | ||||
|             } | ||||
|           } | ||||
| @@ -86,9 +87,9 @@ export default { | ||||
|       }); | ||||
|     }, | ||||
|     unbind(socialUser) { | ||||
|       socialUnbind(socialUser.type, socialUser.unionId).then(resp => { | ||||
|       socialUnbind(socialUser.type, socialUser.openid).then(resp => { | ||||
|         this.$modal.msgSuccess("解绑成功"); | ||||
|         socialUser.unionId = undefined; | ||||
|         socialUser.openid = undefined; | ||||
|       }); | ||||
|     }, | ||||
|     close() { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 YunaiV
					YunaiV