Merge branch 'abp' of https://gitee.com/ccnetcore/Yi into abp

This commit is contained in:
陈淳
2024-01-10 09:12:54 +08:00
6 changed files with 96 additions and 33 deletions

View File

@@ -66,7 +66,7 @@ namespace Yi.Framework.Rbac.Application.Services.Authentication
{
(var openId, var name) = await GetOpenIdAndNameAsync(scheme);
var userId = CurrentUser.Id;
var authEntityAny = await _repository.AnyAsync(x => x.OpenId == openId && x.AuthType == scheme);
var authEntityAny = await _repository.IsAnyAsync(x => x.OpenId == openId && x.AuthType == scheme);
if (authEntityAny)
{
throw new UserFriendlyException("绑定失败,该第三方账号已被注册");

View File

@@ -115,3 +115,16 @@ export function getOtherAuthInfo(params) {
params: params,
});
}
/**
* 删除第三方授权
* @param {*} ids
* @returns
*/
export function delOtherAuth(ids) {
return request({
url: `/auth`,
method: "delete",
params: { id: ids },
});
}

View File

@@ -13,6 +13,8 @@ const code = ref(route.query.code);
const type = ref(route.query.state);
const message = ref("");
const scheme = ref("");
const authData = ref("");
watch(
() => code.value,
async (val) => {
@@ -20,15 +22,28 @@ watch(
// 使用正则表达式提取路由参数
const regex = /\/auth\/([\w-]+)[?]?/;
const result = regex.exec(route.fullPath);
const authParam = result != null ? result[1].toUpperCase() : null;
console.log(type.value, "类型");
if (type.value === "0") {
const res = await authOtherLogin({ code: val }, authParam);
} else if (type.value === "1") {
const res = await authOtherBind({ code: val }, authParam);
const authParam = result != null ? result[1] : null;
switch (authParam) {
case "gitee":
scheme.value = "Gitee";
break;
case "qq":
scheme.value = "QQ";
break;
}
if (type.value === "0") {
const { data } = await authOtherLogin({ code: val }, scheme.value);
authData.value = data;
} else if (type.value === "1") {
const { data } = await authOtherBind({ code: val }, scheme.value);
authData.value = data;
}
window.opener.postMessage({
authData: JSON.stringify(authData.value),
type: scheme.value,
});
console.log(authData.value, "我是打开的窗口页");
message.value = "授权成功";
// window.close();
}
},
{ immediate: true }

View File

@@ -215,7 +215,7 @@ const isPointFinished = ref(false);
const friendList = ref([]);
const isFriendFinished = ref(false);
const themeList = ref([]);
const isThemeFinished = ref([]);
const isThemeFinished = ref(false);
const allDiscussList = ref([]);
const isAllDiscussFinished = ref(false);
const userAnalyseInfo = ref({});

View File

@@ -1,7 +1,7 @@
<template>
<div class="friend-box">
<div class="left">
<div class="icon"><img :src="userImageSrc" alt="" /></div>
<UserInfoCard :userInfo="friendData" :iconUrl="userImageSrc" />
</div>
<div class="center">
<div class="top">
@@ -34,6 +34,7 @@
<script setup name="RecommendFriend">
import { defineProps, computed } from "vue";
import UserInfoCard from "@/components/UserInfoCard/index.vue";
const props = defineProps({
friendData: {

View File

@@ -21,14 +21,15 @@
:table-data="tableData"
:options="tableOptions"
:columns="tableColumn"
@command="handleAction"
></yi-table>
</div>
</div>
</template>
<script setup>
import { computed, onMounted } from "vue";
import { getOtherAuthInfo } from "@/apis/auth.js";
import { ref, computed, onMounted } from "vue";
import { getOtherAuthInfo, delOtherAuth } from "@/apis/auth.js";
import YiTable from "@/components/yi-table/index.vue";
import useUserStore from "@/stores/user";
@@ -48,29 +49,23 @@ const tableColumn = [
align: "center",
},
{
prop: "timeInterval",
prop: "authType",
label: "绑定账号信息",
minWidth: "110",
align: "center",
},
{
prop: "timeInterval",
prop: "name",
label: "详情",
minWidth: "110",
align: "center",
},
{
prop: "timeInterval",
prop: "creationTime",
label: "绑定时间",
minWidth: "110",
align: "center",
},
{
prop: "timeInterval",
label: "状态",
minWidth: "110",
align: "center",
},
{
label: "操作",
align: "center",
@@ -78,18 +73,46 @@ const tableColumn = [
fixed: "right",
buttons: [
{
name: "绑定",
type: "text",
command: "edit",
name: "解除绑定",
type: "danger",
command: "delete",
},
],
},
];
onMounted(async () => {
const tableData = ref([]);
const checkList = async () => {
const { data } = await getOtherAuthInfo({ userId: userInfo.id });
tableData.value = data;
};
onMounted(() => {
checkList();
});
// 操作事件
const handleAction = (command, row) => {
switch (command) {
case "delete":
ElMessageBox.confirm(`确定解除${row.authType}的绑定吗?`, "警告", {
confirmButtonText: "确认",
cancelButtonText: "取消",
type: "warning",
}).then(async () => {
await delOtherAuth(row.id);
await checkList();
ElMessage({
message: `已解除${row.authType}绑定!`,
type: "success",
});
});
break;
default:
break;
}
};
const handleQQLogin = () => {
window.open(
"https://graph.qq.com/oauth2.0/authorize?response_type=code&client_id=102087446&redirect_uri=https://ccnetcore.com/auth/qq&state=1&scope=get_user_info",
@@ -102,29 +125,40 @@ const handleGiteeLogin = () => {
window.open(
"https://gitee.com/oauth/authorize?client_id=949f3519969adc5cfe82c209b71300e8e0868e8536f3d7f59195c8f1e5b72502&redirect_uri=https%3A%2F%2Fccnetcore.com%2Fauth%2Fgitee&state=1&response_type=code",
undefined,
"width=500,height=500,left=50,top=50"
"width=500,height=500,left=50,top=50",
"_black"
);
};
window.addEventListener("message", async (e) => {
console.log(e, "我是账号设置页");
const { authData, type } = e.data;
if (e.data) {
console.log(authData, type, "2333");
await checkList();
window.close();
}
});
</script>
<style lang="scss" scoped>
.account-box {
.title {
font-size: 20px;
font-size: 1.25rem;
font-weight: bold;
}
.image-list {
margin: 10px;
margin: 0.625rem;
display: flex;
.item {
cursor: pointer;
display: flex;
flex-direction: column;
align-items: center;
margin-right: 20px;
margin-right: 1.25rem;
.image {
width: 30px;
height: 30px;
width: 1.875rem;
height: 1.875rem;
img {
width: 100%;
height: 100%;
@@ -133,10 +167,10 @@ const handleGiteeLogin = () => {
}
}
.table {
margin-top: 10px;
margin-top: 0.625rem;
:deep(.yi-table) {
width: 100%;
height: 200px;
height: 12.5rem;
}
}
}