mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-04 00:10:25 +08:00
refactor: oauth2登录重构
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
import request from './request';
|
||||
|
||||
export default {
|
||||
login: (param: any) => request.post('/sys/accounts/login', param),
|
||||
otpVerify: (param: any) => request.post('/sys/accounts/otp-verify', param),
|
||||
changePwd: (param: any) => request.post('/sys/accounts/change-pwd', param),
|
||||
login: (param: any) => request.post('/auth/accounts/login', param),
|
||||
otpVerify: (param: any) => request.post('/auth/accounts/otp-verify', param),
|
||||
getPublicKey: () => request.get('/common/public-key'),
|
||||
getConfigValue: (params: any) => request.get('/sys/configs/value', params),
|
||||
oauthConfig: () => request.get('/sys/configs/auth'),
|
||||
oauth2LoginConfig: () => request.get('/sys/configs/oauth2-login'),
|
||||
changePwd: (param: any) => request.post('/sys/accounts/change-pwd', param),
|
||||
captcha: () => request.get('/sys/captcha'),
|
||||
logout: () => request.post('/sys/accounts/logout/{token}'),
|
||||
logout: () => request.post('/auth/accounts/logout'),
|
||||
getPermissions: () => request.get('/sys/accounts/permissions'),
|
||||
};
|
||||
|
||||
@@ -25,8 +25,7 @@
|
||||
</el-icon>
|
||||
</div>
|
||||
<div class="layout-navbars-breadcrumb-user-icon">
|
||||
<el-popover placement="bottom" trigger="click" :visible="state.isShowUserNewsPopover" :width="300"
|
||||
popper-class="el-popover-pupop-user-news">
|
||||
<el-popover placement="bottom" trigger="click" :visible="state.isShowUserNewsPopover" :width="300" popper-class="el-popover-pupop-user-news">
|
||||
<template #reference>
|
||||
<el-badge :is-dot="false" @click="state.isShowUserNewsPopover = !state.isShowUserNewsPopover">
|
||||
<el-icon title="消息">
|
||||
@@ -70,14 +69,15 @@ import { ref, computed, reactive, onMounted } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { ElMessageBox, ElMessage } from 'element-plus';
|
||||
import screenfull from 'screenfull';
|
||||
import { resetRoute } from '@/router/index.ts';
|
||||
import { resetRoute } from '@/router/index';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { useUserInfo } from '@/store/userInfo';
|
||||
import { useThemeConfig } from '@/store/themeConfig';
|
||||
import { clearSession, setLocal, getLocal, removeLocal } from '@/common/utils/storage.ts';
|
||||
import { clearSession, setLocal, getLocal, removeLocal } from '@/common/utils/storage';
|
||||
import UserNews from '@/views/layout/navBars/breadcrumb/userNews.vue';
|
||||
import SearchMenu from '@/views/layout/navBars/breadcrumb/search.vue';
|
||||
import mittBus from '@/common/utils/mitt';
|
||||
import openApi from '@/common/openApi';
|
||||
|
||||
const router = useRouter();
|
||||
const searchRef = ref();
|
||||
@@ -122,8 +122,9 @@ const onHandleCommandClick = (path: string) => {
|
||||
showCancelButton: true,
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
beforeClose: (action, instance, done) => {
|
||||
beforeClose: async (action, instance, done) => {
|
||||
if (action === 'confirm') {
|
||||
await openApi.logout();
|
||||
instance.confirmButtonLoading = true;
|
||||
instance.confirmButtonText = '退出中';
|
||||
setTimeout(() => {
|
||||
@@ -145,7 +146,7 @@ const onHandleCommandClick = (path: string) => {
|
||||
ElMessage.success('安全退出成功!');
|
||||
}, 300);
|
||||
})
|
||||
.catch(() => { });
|
||||
.catch(() => {});
|
||||
} else {
|
||||
router.push(path);
|
||||
}
|
||||
@@ -244,4 +245,5 @@ onMounted(() => {
|
||||
::v-deep(.el-badge__content.is-fixed) {
|
||||
top: 12px;
|
||||
}
|
||||
}</style>
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -2,24 +2,37 @@
|
||||
<div>
|
||||
<el-form ref="loginFormRef" :model="loginForm" :rules="rules" class="login-content-form" size="large">
|
||||
<el-form-item prop="username">
|
||||
<el-input type="text" placeholder="请输入用户名" prefix-icon="user" v-model="loginForm.username" clearable
|
||||
autocomplete="off"> </el-input>
|
||||
<el-input type="text" placeholder="请输入用户名" prefix-icon="user" v-model="loginForm.username" clearable autocomplete="off"> </el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="password">
|
||||
<el-input type="password" placeholder="请输入密码" prefix-icon="lock" v-model="loginForm.password"
|
||||
autocomplete="off" @keyup.enter="login" show-password>
|
||||
<el-input
|
||||
type="password"
|
||||
placeholder="请输入密码"
|
||||
prefix-icon="lock"
|
||||
v-model="loginForm.password"
|
||||
autocomplete="off"
|
||||
@keyup.enter="login"
|
||||
show-password
|
||||
>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="accountLoginSecurity.useCaptcha" prop="captcha">
|
||||
<el-row :gutter="15">
|
||||
<el-col :span="16">
|
||||
<el-input type="text" maxlength="6" placeholder="请输入验证码" prefix-icon="position"
|
||||
v-model="loginForm.captcha" clearable autocomplete="off" @keyup.enter="login"></el-input>
|
||||
<el-input
|
||||
type="text"
|
||||
maxlength="6"
|
||||
placeholder="请输入验证码"
|
||||
prefix-icon="position"
|
||||
v-model="loginForm.captcha"
|
||||
clearable
|
||||
autocomplete="off"
|
||||
@keyup.enter="login"
|
||||
></el-input>
|
||||
</el-col>
|
||||
<el-col :span="8">
|
||||
<div class="login-content-code">
|
||||
<img class="login-content-code-img" @click="getCaptcha" width="130px" height="40px"
|
||||
:src="captchaImage" style="cursor: pointer" />
|
||||
<img class="login-content-code-img" @click="getCaptcha" width="130px" height="40px" :src="captchaImage" style="cursor: pointer" />
|
||||
</div>
|
||||
</el-col>
|
||||
</el-row>
|
||||
@@ -34,19 +47,21 @@
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<el-dialog title="修改密码" v-model="changePwdDialog.visible" :close-on-click-modal="false" width="450px"
|
||||
:destroy-on-close="true">
|
||||
<el-dialog title="修改密码" v-model="changePwdDialog.visible" :close-on-click-modal="false" width="450px" :destroy-on-close="true">
|
||||
<el-form :model="changePwdDialog.form" :rules="changePwdDialog.rules" ref="changePwdFormRef" label-width="auto">
|
||||
<el-form-item prop="username" label="用户名" required>
|
||||
<el-input v-model.trim="changePwdDialog.form.username" disabled></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="oldPassword" label="旧密码" required>
|
||||
<el-input v-model.trim="changePwdDialog.form.oldPassword" autocomplete="new-password"
|
||||
type="password"></el-input>
|
||||
<el-input v-model.trim="changePwdDialog.form.oldPassword" autocomplete="new-password" type="password"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="newPassword" label="新密码" required>
|
||||
<el-input v-model.trim="changePwdDialog.form.newPassword" placeholder="须为8位以上且包含字⺟⼤⼩写+数字+特殊符号"
|
||||
type="password" autocomplete="new-password"></el-input>
|
||||
<el-input
|
||||
v-model.trim="changePwdDialog.form.newPassword"
|
||||
placeholder="须为8位以上且包含字⺟⼤⼩写+数字+特殊符号"
|
||||
type="password"
|
||||
autocomplete="new-password"
|
||||
></el-input>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
@@ -58,17 +73,28 @@
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog title="OTP校验" v-model="otpDialog.visible" @close="loading.signIn = false" :close-on-click-modal="false"
|
||||
width="350px" :destroy-on-close="true">
|
||||
<el-form ref="otpFormRef" :model="otpDialog.form" :rules="otpDialog.rules" @submit.native.prevent
|
||||
label-width="auto">
|
||||
<el-dialog
|
||||
title="OTP校验"
|
||||
v-model="otpDialog.visible"
|
||||
@close="loading.signIn = false"
|
||||
:close-on-click-modal="false"
|
||||
width="350px"
|
||||
:destroy-on-close="true"
|
||||
>
|
||||
<el-form ref="otpFormRef" :model="otpDialog.form" :rules="otpDialog.rules" @submit.native.prevent label-width="auto">
|
||||
<el-form-item v-if="otpDialog.otpUrl" label="二维码">
|
||||
<qrcode-vue :value="otpDialog.otpUrl" :size="200" level="H" />
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item prop="code" label="OTP" required>
|
||||
<el-input style="width: 220px" ref="otpCodeInputRef" v-model.trim="otpDialog.form.code" clearable
|
||||
@keyup.enter="otpVerify" placeholder="请输入令牌APP中显示的授权码"></el-input>
|
||||
<el-input
|
||||
style="width: 220px"
|
||||
ref="otpCodeInputRef"
|
||||
v-model.trim="otpDialog.form.code"
|
||||
clearable
|
||||
@keyup.enter="otpVerify"
|
||||
placeholder="请输入令牌APP中显示的授权码"
|
||||
></el-input>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
@@ -240,7 +266,7 @@ const onSignIn = async () => {
|
||||
}
|
||||
state.showLoginFailTips = false;
|
||||
loginResDeal(loginRes);
|
||||
}
|
||||
};
|
||||
|
||||
const loginResDeal = (loginRes: any) => {
|
||||
// 用户信息
|
||||
@@ -248,9 +274,8 @@ const loginResDeal = (loginRes: any) => {
|
||||
name: loginRes.name,
|
||||
username: loginRes.username,
|
||||
// 头像
|
||||
photo: letterAvatar(state.loginForm.username),
|
||||
photo: letterAvatar(loginRes.username),
|
||||
time: new Date().getTime(),
|
||||
// permissions: loginRes.permissions,
|
||||
lastLoginTime: loginRes.lastLoginTime,
|
||||
lastLoginIp: loginRes.lastLoginIp,
|
||||
};
|
||||
@@ -276,7 +301,7 @@ const loginResDeal = (loginRes: any) => {
|
||||
};
|
||||
|
||||
defineExpose({
|
||||
loginResDeal
|
||||
loginResDeal,
|
||||
});
|
||||
|
||||
// 登录成功后的跳转
|
||||
|
||||
@@ -18,15 +18,12 @@
|
||||
</transition>
|
||||
</el-tab-pane> -->
|
||||
</el-tabs>
|
||||
<div class="mt10" v-show="authConfig.oauth2">
|
||||
<el-button type="text" size="small">第三方登录</el-button>
|
||||
<!-- <el-button type="text" size="small">友情链接</el-button> -->
|
||||
</div>
|
||||
<div class="mt10" v-show="authConfig.oauth2">
|
||||
<el-tooltip content="使用OAuth2登录" placement="top-start">
|
||||
<el-button type="text" size="small" @click="oauth2Login">
|
||||
<div class="mt20" v-show="authConfig.enable">
|
||||
<el-button link size="small">第三方登录: </el-button>
|
||||
<el-tooltip content="OAuth2登录" placement="top-start">
|
||||
<el-button link size="small" type="primary" @click="oauth2Login">
|
||||
<el-icon :size="18">
|
||||
<Menu />
|
||||
<Link />
|
||||
</el-icon>
|
||||
</el-button>
|
||||
</el-tooltip>
|
||||
@@ -52,14 +49,14 @@ const { themeConfig } = storeToRefs(useThemeConfig());
|
||||
const state = reactive({
|
||||
tabsActiveName: 'account',
|
||||
isTabPaneShow: true,
|
||||
authConfig: {
|
||||
oauth2: false,
|
||||
oauth2LoginConfig: {
|
||||
enable: false,
|
||||
},
|
||||
});
|
||||
|
||||
const loginForm = ref<{ loginResDeal: (data: any) => void } | null>(null);
|
||||
|
||||
const { isTabPaneShow, tabsActiveName, authConfig, } = toRefs(state);
|
||||
const { isTabPaneShow, tabsActiveName, oauth2LoginConfig: authConfig } = toRefs(state);
|
||||
|
||||
// 切换密码、手机登录
|
||||
const onTabsClick = () => {
|
||||
@@ -67,32 +64,28 @@ const onTabsClick = () => {
|
||||
};
|
||||
|
||||
onMounted(async () => {
|
||||
state.authConfig = await openApi.oauthConfig();
|
||||
|
||||
state.oauth2LoginConfig = await openApi.oauth2LoginConfig();
|
||||
});
|
||||
|
||||
const oauth2Login = () => {
|
||||
// 小窗口打开oauth2鉴权
|
||||
let oauthWindoe = window.open(config.baseApiUrl + "/sys/auth/oauth2/login", "oauth2", "width=600,height=600");
|
||||
let oauthWindoe = window.open(config.baseApiUrl + '/auth/oauth2/login', 'oauth2', 'width=600,height=600');
|
||||
if (oauthWindoe) {
|
||||
const handler = (e: any) => {
|
||||
if (e.data.action === "oauthLogin") {
|
||||
if (e.data.action === 'oauthLogin') {
|
||||
oauthWindoe!.close();
|
||||
window.removeEventListener("message", handler);
|
||||
// 处理登录token
|
||||
console.log(e.data);
|
||||
window.removeEventListener('message', handler);
|
||||
loginForm.value!.loginResDeal(e.data);
|
||||
}
|
||||
}
|
||||
window.addEventListener("message", handler);
|
||||
};
|
||||
window.addEventListener('message', handler);
|
||||
setInterval(() => {
|
||||
if (oauthWindoe!.closed) {
|
||||
window.removeEventListener("message", handler);
|
||||
window.removeEventListener('message', handler);
|
||||
}
|
||||
}, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
|
||||
@@ -3,6 +3,6 @@ import Api from '@/common/Api';
|
||||
export const personApi = {
|
||||
accountInfo: Api.newGet('/sys/accounts/self'),
|
||||
updateAccount: Api.newPut('/sys/accounts/self'),
|
||||
authStatus: Api.newGet('/sys/auth/status'),
|
||||
authStatus: Api.newGet('/auth/oauth2/status'),
|
||||
getMsgs: Api.newGet('/msgs/self'),
|
||||
};
|
||||
|
||||
@@ -12,16 +12,16 @@
|
||||
</div>
|
||||
<div class="personal-user-right">
|
||||
<el-row>
|
||||
<el-col :span="24" class="personal-title mb18">{{ currentTime }},{{ userInfo.name
|
||||
}},生活变的再糟糕,也不妨碍我变得更好!
|
||||
<el-col :span="24" class="personal-title mb18"
|
||||
>{{ currentTime }},{{ userInfo.name }},生活变的再糟糕,也不妨碍我变得更好!
|
||||
</el-col>
|
||||
<el-col :span="24">
|
||||
<el-row>
|
||||
<el-col :xs="24" :sm="8" class="personal-item mb6">
|
||||
<el-col :xs="24" :sm="12" class="personal-item mb6">
|
||||
<div class="personal-item-label">用户名:</div>
|
||||
<div class="personal-item-value">{{ userInfo.username }}</div>
|
||||
</el-col>
|
||||
<el-col :xs="24" :sm="16" class="personal-item mb6">
|
||||
<el-col :xs="24" :sm="12" class="personal-item mb6">
|
||||
<div class="personal-item-label">角色:</div>
|
||||
<div class="personal-item-value">{{ roleInfo }}</div>
|
||||
</el-col>
|
||||
@@ -29,11 +29,11 @@
|
||||
</el-col>
|
||||
<el-col :span="24">
|
||||
<el-row>
|
||||
<el-col :xs="24" :sm="8" class="personal-item mb6">
|
||||
<el-col :xs="24" :sm="12" class="personal-item mb6">
|
||||
<div class="personal-item-label">上次登录IP:</div>
|
||||
<div class="personal-item-value">{{ userInfo.lastLoginIp }}</div>
|
||||
</el-col>
|
||||
<el-col :xs="24" :sm="16" class="personal-item mb6">
|
||||
<el-col :xs="24" :sm="12" class="personal-item mb6">
|
||||
<div class="personal-item-label">上次登录时间:</div>
|
||||
<div class="personal-item-value">{{ dateFormat(userInfo.lastLoginTime) }}</div>
|
||||
</el-col>
|
||||
@@ -77,9 +77,16 @@
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<el-row type="flex" class="mt5" justify="center">
|
||||
<el-pagination small @current-change="getMsgs" style="text-align: center" background
|
||||
layout="prev, pager, next, total, jumper" :total="msgDialog.msgs.total"
|
||||
v-model:current-page="msgDialog.query.pageNum" :page-size="msgDialog.query.pageSize" />
|
||||
<el-pagination
|
||||
small
|
||||
@current-change="getMsgs"
|
||||
style="text-align: center"
|
||||
background
|
||||
layout="prev, pager, next, total, jumper"
|
||||
:total="msgDialog.msgs.total"
|
||||
v-model:current-page="msgDialog.query.pageNum"
|
||||
:page-size="msgDialog.query.pageSize"
|
||||
/>
|
||||
</el-row>
|
||||
</el-dialog>
|
||||
|
||||
@@ -108,8 +115,7 @@
|
||||
<el-row :gutter="35">
|
||||
<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="4" class="mb20">
|
||||
<el-form-item label="密码">
|
||||
<el-input type="password" show-password v-model="accountForm.password"
|
||||
placeholder="请输入新密码" clearable></el-input>
|
||||
<el-input type="password" show-password v-model="accountForm.password" placeholder="请输入新密码" clearable></el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<!-- -->
|
||||
@@ -121,19 +127,21 @@
|
||||
</el-row>
|
||||
</el-form>
|
||||
|
||||
<!-- <div class="personal-edit-title mb15">账号安全</div>
|
||||
<div class="personal-edit-safe-box">
|
||||
<div class="personal-edit-safe-item">
|
||||
<div class="personal-edit-safe-item-left">
|
||||
<div class="personal-edit-safe-item-left-label">账户密码</div>
|
||||
<div class="personal-edit-safe-item-left-value">当前密码强度:强</div>
|
||||
</div>
|
||||
<div class="personal-edit-safe-item-right">
|
||||
<el-button type="text">立即修改</el-button>
|
||||
<span v-show="authStatus.enable">
|
||||
<div class="personal-edit-title mb15">账号信息</div>
|
||||
<div class="personal-edit-safe-box">
|
||||
<div class="personal-edit-safe-item">
|
||||
<div class="personal-edit-safe-item-left">
|
||||
<div class="personal-edit-safe-item-left-label">Oauth2</div>
|
||||
<div class="personal-edit-safe-item-left-value">当前状态:{{ authStatus.bind ? '已绑定' : '未绑定' }}</div>
|
||||
</div>
|
||||
<div class="personal-edit-safe-item-right">
|
||||
<el-button link @click="bindOAuth2" :disabled="authStatus.bind" type="primary">立即绑定</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="personal-edit-safe-box">
|
||||
</span>
|
||||
<!-- <div class="personal-edit-safe-box">
|
||||
<div class="personal-edit-safe-item">
|
||||
<div class="personal-edit-safe-item-left">
|
||||
<div class="personal-edit-safe-item-left-label">密保手机</div>
|
||||
@@ -155,19 +163,6 @@
|
||||
</div>
|
||||
</div>
|
||||
</div> -->
|
||||
<div v-show="authStatus.enable.oauth2" class="personal-edit-safe-box">
|
||||
<div class="personal-edit-safe-item">
|
||||
<div class="personal-edit-safe-item-left">
|
||||
<div class="personal-edit-safe-item-left-label">绑定OAuth2</div>
|
||||
<div class="personal-edit-safe-item-left-value">
|
||||
{{ authStatus.bind.oauth2 ? '已绑定' : '未绑定' }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="personal-edit-safe-item-right">
|
||||
<el-button type="text" @click="bindOAuth2" :disabled="authStatus.bind.oauth2">立即绑定</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</el-card>
|
||||
</el-col>
|
||||
</el-row>
|
||||
@@ -208,8 +203,8 @@ const state = reactive({
|
||||
},
|
||||
authStatus: {
|
||||
enable: { oauth2: false },
|
||||
bind: { oauth2: false }
|
||||
}
|
||||
bind: { oauth2: false },
|
||||
},
|
||||
});
|
||||
|
||||
const { msgDialog, accountForm, authStatus } = toRefs(state);
|
||||
@@ -233,7 +228,7 @@ const roleInfo = computed(() => {
|
||||
onMounted(async () => {
|
||||
getAccountInfo();
|
||||
getMsgs();
|
||||
state.authStatus = await personApi.authStatus.request()
|
||||
state.authStatus = await personApi.authStatus.request();
|
||||
});
|
||||
|
||||
const getAccountInfo = async () => {
|
||||
@@ -247,28 +242,27 @@ const updateAccount = async () => {
|
||||
|
||||
const bindOAuth2 = () => {
|
||||
// 小窗口打开oauth2鉴权
|
||||
let oauthWindoe = window.open(config.baseApiUrl + "/sys/auth/oauth2/bind?token=" + getSession('token'), "oauth2", "width=600,height=600");
|
||||
if (oauthWindoe) {
|
||||
let oauthWindow = window.open(config.baseApiUrl + '/auth/oauth2/bind?token=' + getSession('token'), 'oauth2', 'width=600,height=600');
|
||||
if (oauthWindow) {
|
||||
const handler = (e: any) => {
|
||||
if (e.data.action === "oauthBind") {
|
||||
oauthWindoe!.close();
|
||||
window.removeEventListener("message", handler);
|
||||
if (e.data.action === 'oauthBind') {
|
||||
oauthWindow!.close();
|
||||
window.removeEventListener('message', handler);
|
||||
// 处理登录token
|
||||
console.log(e.data);
|
||||
ElMessage.success('绑定成功');
|
||||
setTimeout(() => {
|
||||
location.reload();
|
||||
}, 1000);
|
||||
}
|
||||
}
|
||||
window.addEventListener("message", handler);
|
||||
};
|
||||
window.addEventListener('message', handler);
|
||||
setInterval(() => {
|
||||
if (oauthWindoe!.closed) {
|
||||
window.removeEventListener("message", handler);
|
||||
if (oauthWindow!.closed) {
|
||||
window.removeEventListener('message', handler);
|
||||
}
|
||||
}, 1000);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const getMsgs = async () => {
|
||||
const res = await personApi.getMsgs.request(state.msgDialog.query);
|
||||
|
||||
@@ -1,105 +0,0 @@
|
||||
<template>
|
||||
<el-card>
|
||||
<template #header>
|
||||
<el-space>
|
||||
<span>登录认证</span>
|
||||
<el-text type="info">管理三方登录认证平台</el-text>
|
||||
</el-space>
|
||||
</template>
|
||||
<el-card>
|
||||
<template #header>
|
||||
<el-space>
|
||||
<span>OAuth2.0</span>
|
||||
<el-text type="info">自定义oauth2.0 server登录</el-text>
|
||||
</el-space>
|
||||
</template>
|
||||
<el-form ref="oauth2Form" :model="oauth2" label-width="160px" status-icon>
|
||||
<el-form-item prop="clientID" label="Client ID" required>
|
||||
<el-input v-model="oauth2.clientID" placeholder="客户端id"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="clientSecret" label="Client secret" required>
|
||||
<el-input v-model="oauth2.clientSecret" placeholder="客户端密钥"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="authorizationURL" label="Authorization URL" required>
|
||||
<el-input v-model="oauth2.authorizationURL"
|
||||
placeholder="授权码获取地址 例如: https://example.com/oauth/authorize"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="accessTokenURL" label="Access token URL" required>
|
||||
<el-input v-model="oauth2.accessTokenURL"
|
||||
placeholder="访问token获取地址 例如: https://example.com/oauth/token"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="resourceURL" label="Resource URL" required>
|
||||
<el-input v-model="oauth2.resourceURL"
|
||||
placeholder="获取用户信息地址 例如: https://example.com/api/v4/user"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="redirectURL" label="Redirect URL" required>
|
||||
<el-input v-model="oauth2.redirectURL" placeholder="mayfly地址 例如: http://localhost:8889/"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="userIdentifier" label="User identifier" required>
|
||||
<el-input v-model="oauth2.userIdentifier"
|
||||
placeholder="用户唯一标识key 例如:username,如果有多层可以写为: data.username"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="scopes" label="Scopes" required>
|
||||
<el-input v-model="oauth2.scopes" placeholder="read_user,read_api 多个使用,分割"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item prop="autoRegister" label="自动注册">
|
||||
<el-checkbox v-model="oauth2.autoRegister" label="开启自动注册将会自动注册账号, 否则需要手动创建账号后再进行绑定" />
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="onSubmit" :loading="btnLoading">保存</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-card>
|
||||
</el-card>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { onMounted, reactive, ref, toRefs } from 'vue';
|
||||
import { authApi } from '../api';
|
||||
import { ElMessage, FormInstance } from 'element-plus';
|
||||
|
||||
|
||||
const oauth2Form = ref<FormInstance>();
|
||||
|
||||
const state = reactive({
|
||||
oauth2: {
|
||||
clientID: '',
|
||||
clientSecret: '',
|
||||
authorizationURL: '',
|
||||
accessTokenURL: '',
|
||||
resourceURL: '',
|
||||
redirectURL: '',
|
||||
userIdentifier: '',
|
||||
scopes: '',
|
||||
autoRegister: false,
|
||||
},
|
||||
btnLoading: false,
|
||||
});
|
||||
|
||||
|
||||
const { oauth2, btnLoading } = toRefs(state);
|
||||
|
||||
onMounted(async () => {
|
||||
const resp = await authApi.info.request();
|
||||
console.log(resp);
|
||||
if (resp.oauth2) {
|
||||
state.oauth2 = resp.oauth2;
|
||||
}
|
||||
});
|
||||
|
||||
const onSubmit = () => {
|
||||
oauth2Form.value?.validate(async (valid) => {
|
||||
if (valid) {
|
||||
state.btnLoading = true;
|
||||
try {
|
||||
await authApi.saveOAuth2.request(oauth2.value);
|
||||
} catch (e) {
|
||||
}
|
||||
state.btnLoading = false;
|
||||
ElMessage.success('保存成功');
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
</script>
|
||||
<style lang="scss"></style>
|
||||
@@ -25,7 +25,7 @@
|
||||
</template>
|
||||
</page-table>
|
||||
|
||||
<el-dialog :before-close="closeSetConfigDialog" title="配置项设置" v-model="paramsDialog.visible" width="500px">
|
||||
<el-dialog :before-close="closeSetConfigDialog" title="配置项设置" v-model="paramsDialog.visible" width="600px">
|
||||
<el-form v-if="paramsDialog.paramsFormItem.length > 0" ref="paramsFormRef" :model="paramsDialog.params" label-width="auto">
|
||||
<el-form-item v-for="item in paramsDialog.paramsFormItem" :key="item.name" :prop="item.model" :label="item.name" required>
|
||||
<el-input
|
||||
@@ -35,11 +35,13 @@
|
||||
autocomplete="off"
|
||||
clearable
|
||||
></el-input>
|
||||
<el-checkbox v-else-if="item.type == 'checkbox'"
|
||||
<el-checkbox
|
||||
v-else-if="item.type == 'checkbox'"
|
||||
v-model="paramsDialog.params[item.model]"
|
||||
autocomplete="off"
|
||||
:label="item.placeholder"
|
||||
clearable/>
|
||||
autocomplete="off"
|
||||
:label="item.placeholder"
|
||||
clearable
|
||||
/>
|
||||
<el-select
|
||||
v-else
|
||||
v-model="paramsDialog.params[item.model]"
|
||||
|
||||
Reference in New Issue
Block a user