mirror of
https://github.com/bufanyun/hotgo.git
synced 2025-11-12 04:03:44 +08:00
增加注册强制邀请码开关、微信内登录自动获取openid开关
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
import type { RouteRecordRaw } from 'vue-router';
|
||||
import { isNavigationFailure, Router } from 'vue-router';
|
||||
import { UserInfoState, useUserStoreWidthOut } from '@/store/modules/user';
|
||||
import { useUserStoreWidthOut } from '@/store/modules/user';
|
||||
import { useAsyncRouteStoreWidthOut } from '@/store/modules/asyncRoute';
|
||||
import { ACCESS_TOKEN } from '@/store/mutation-types';
|
||||
import { storage } from '@/utils/Storage';
|
||||
import { PageEnum } from '@/enums/pageEnum';
|
||||
import { ErrorPageRoute } from '@/router/base';
|
||||
import { isWechatBrowser } from '@/utils/is';
|
||||
import { jump } from '@/utils/http/axios';
|
||||
import { getNowUrl } from '@/utils/urlUtils';
|
||||
|
||||
const LOGIN_PATH = PageEnum.BASE_LOGIN;
|
||||
const whitePathList = [LOGIN_PATH]; // no redirect whitelist
|
||||
@@ -64,21 +64,20 @@ export function createRouterGuards(router: Router) {
|
||||
const redirect = decodeURIComponent(redirectPath);
|
||||
const nextData = to.path === redirect ? { ...to, replace: true } : { path: redirect };
|
||||
const userInfo = await userStore.GetInfo();
|
||||
await userStore.LoadLoginConfig();
|
||||
|
||||
// 如果是微信访问,则记录本次登录的openid
|
||||
if (isWechatBrowser() && (userInfo as UserInfoState).openId === '') {
|
||||
// 是否允许获取微信openid
|
||||
if (userStore.allowWxOpenId()) {
|
||||
let path = nextData.path;
|
||||
if (path === LOGIN_PATH) {
|
||||
path = PageEnum.BASE_HOME_REDIRECT;
|
||||
}
|
||||
|
||||
const w = window.location;
|
||||
const URI = w.protocol + '//' + w.host + w.pathname + '#' + path;
|
||||
const URI = getNowUrl() + '#' + path;
|
||||
jump('/wechat/authorize', { type: 'openId', syncRedirect: URI });
|
||||
return;
|
||||
}
|
||||
|
||||
await userStore.LoadLoginConfig();
|
||||
await userStore.GetConfig();
|
||||
const routes = await asyncRouteStore.generateRoutes(userInfo);
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ import {
|
||||
logout,
|
||||
mobileLogin,
|
||||
} from '@/api/system/user';
|
||||
import { isWechatBrowser } from '@/utils/is';
|
||||
const Storage = createStorage({ storage: localStorage });
|
||||
|
||||
export interface UserInfoState {
|
||||
@@ -59,6 +60,7 @@ export interface ConfigState {
|
||||
export interface LoginConfigState {
|
||||
loginRegisterSwitch: number;
|
||||
loginCaptchaSwitch: number;
|
||||
loginAutoOpenId: number;
|
||||
loginProtocol: string;
|
||||
loginPolicy: string;
|
||||
}
|
||||
@@ -218,6 +220,18 @@ export const useUserStore = defineStore({
|
||||
});
|
||||
});
|
||||
},
|
||||
// 是否允许获取微信openid
|
||||
allowWxOpenId(): boolean {
|
||||
if (!isWechatBrowser()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.loginConfig?.loginAutoOpenId !== 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return this.info?.openId === '';
|
||||
},
|
||||
// 登出
|
||||
async logout() {
|
||||
try {
|
||||
|
||||
@@ -41,3 +41,11 @@ export function getFileExt(fileName: string) {
|
||||
}
|
||||
return fileName.substring(fileName.lastIndexOf('.') + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当访问的url,不含参数
|
||||
*/
|
||||
export function getNowUrl(): string {
|
||||
const w = window.location;
|
||||
return w.protocol + '//' + w.host + w.pathname;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,11 @@
|
||||
</n-icon>
|
||||
</a>
|
||||
</div>
|
||||
<div class="flex-initial" style="margin-left: auto" v-if="userStore.loginConfig?.loginRegisterSwitch === 1">
|
||||
<div
|
||||
class="flex-initial"
|
||||
style="margin-left: auto"
|
||||
v-if="userStore.loginConfig?.loginRegisterSwitch === 1"
|
||||
>
|
||||
<a @click="updateActiveModule(moduleKey)">{{ tag }}</a>
|
||||
</div>
|
||||
</div>
|
||||
@@ -27,9 +31,8 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { LogoWechat, LogoTiktok } from '@vicons/ionicons5';
|
||||
|
||||
import { useUserStore } from '@/store/modules/user';
|
||||
import {useMessage} from "naive-ui";
|
||||
import { useMessage } from 'naive-ui';
|
||||
|
||||
const userStore = useUserStore();
|
||||
|
||||
|
||||
@@ -48,8 +48,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
.justify-between {
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@
|
||||
<n-button :text="true" @click="handleResetPassword">忘记密码?</n-button>
|
||||
</div>
|
||||
<n-button type="primary" size="large" :block="true" :loading="loading" @click="handleLogin">
|
||||
确定
|
||||
登录
|
||||
</n-button>
|
||||
|
||||
<FormOther moduleKey="register" tag="注册账号" @updateActiveModule="updateActiveModule" />
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
<template>
|
||||
<div>
|
||||
<n-checkbox v-model:checked="checked" class="text-14px">我已阅读并接受</n-checkbox>
|
||||
<n-button :text="true" type="primary" @click="handleClickProtocol" class="text-13px"
|
||||
>《用户协议》</n-button
|
||||
>
|
||||
<n-button :text="true" type="primary" @click="handleClickPolicy" class="text-13px"
|
||||
>《隐私权政策》</n-button
|
||||
>
|
||||
<n-button :text="true" type="primary" @click="handleClickProtocol">《用户协议》</n-button>
|
||||
<n-button :text="true" type="primary" @click="handleClickPolicy">《隐私权政策》</n-button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -41,6 +37,7 @@
|
||||
function handleClickProtocol() {
|
||||
emit('click-protocol');
|
||||
}
|
||||
|
||||
function handleClickPolicy() {
|
||||
emit('click-policy');
|
||||
}
|
||||
|
||||
@@ -263,6 +263,7 @@
|
||||
modalTitle.value = '用户协议';
|
||||
modalContent.value = userStore.loginConfig?.loginProtocol as string;
|
||||
}
|
||||
|
||||
function handleClickPolicy() {
|
||||
showModal.value = true;
|
||||
modalTitle.value = '隐私权政策';
|
||||
|
||||
@@ -229,7 +229,7 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { h, reactive, ref } from 'vue';
|
||||
import { SelectOption, TreeSelectOption, useDialog, useMessage } from 'naive-ui';
|
||||
import { useDialog, useMessage } from 'naive-ui';
|
||||
import { ActionItem, BasicTable, TableAction } from '@/components/Table';
|
||||
import { BasicForm } from '@/components/Form/index';
|
||||
import { Delete, Edit, List, Status, ResetPwd } from '@/api/org/user';
|
||||
@@ -245,9 +245,9 @@
|
||||
import AddIntegral from './addIntegral.vue';
|
||||
import { addNewState, addState, options, register, defaultState } from './model';
|
||||
import { usePermission } from '@/hooks/web/usePermission';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { useUserStore } from '@/store/modules/user';
|
||||
import { LoginRoute } from '@/router';
|
||||
import { getNowUrl } from '@/utils/urlUtils';
|
||||
|
||||
interface Props {
|
||||
type?: string;
|
||||
@@ -266,7 +266,6 @@
|
||||
};
|
||||
|
||||
const { hasPermission } = usePermission();
|
||||
const router = useRouter();
|
||||
const userStore = useUserStore();
|
||||
const showIntegralModal = ref(false);
|
||||
const showBalanceModal = ref(false);
|
||||
@@ -489,24 +488,15 @@
|
||||
});
|
||||
}
|
||||
|
||||
function handleUpdateDeptValue(
|
||||
value: string | number | Array<string | number> | null,
|
||||
_option: TreeSelectOption | null | Array<TreeSelectOption | null>
|
||||
) {
|
||||
function handleUpdateDeptValue(value) {
|
||||
formParams.value.deptId = Number(value);
|
||||
}
|
||||
|
||||
function handleUpdateRoleValue(
|
||||
value: string | number | Array<string | number> | null,
|
||||
_option: SelectOption | null | Array<SelectOption | null>
|
||||
) {
|
||||
function handleUpdateRoleValue(value) {
|
||||
formParams.value.roleId = Number(value);
|
||||
}
|
||||
|
||||
function handleUpdatePostValue(
|
||||
value: string | number | Array<string | number> | null,
|
||||
_option: SelectOption | null | Array<SelectOption | null>
|
||||
) {
|
||||
function handleUpdatePostValue(value) {
|
||||
formParams.value.postIds = value;
|
||||
}
|
||||
|
||||
@@ -529,8 +519,7 @@
|
||||
}
|
||||
|
||||
function handleInviteQR(code: string) {
|
||||
const w = window.location;
|
||||
const domain = w.protocol + '//' + w.host + w.pathname + '#';
|
||||
const domain = getNowUrl() + '#';
|
||||
qrParams.value.qrUrl = domain + LoginRoute.path + '?scope=register&inviteCode=' + code;
|
||||
showQrModal.value = true;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
<div>
|
||||
<n-spin :show="show" description="请稍候...">
|
||||
<n-form :label-width="100" :model="formValue" :rules="rules" ref="formRef">
|
||||
<n-divider title-placement="left">开关配置</n-divider>
|
||||
<n-form-item label="登录验证码开关" path="loginCaptchaSwitch">
|
||||
<n-radio-group v-model:value="formValue.loginCaptchaSwitch" name="loginCaptchaSwitch">
|
||||
<n-space>
|
||||
@@ -20,6 +21,31 @@
|
||||
</n-radio-group>
|
||||
</n-form-item>
|
||||
|
||||
<n-form-item label="强制邀请" path="loginForceInvite">
|
||||
<n-radio-group v-model:value="formValue.loginForceInvite" name="loginForceInvite">
|
||||
<n-space>
|
||||
<n-radio :value="1">开启</n-radio>
|
||||
<n-radio :value="2">关闭</n-radio>
|
||||
</n-space>
|
||||
</n-radio-group>
|
||||
<template #feedback>
|
||||
用户通过注册页面发起注册时是否必须填写邀请信息,用于上下级关系绑定</template
|
||||
>
|
||||
</n-form-item>
|
||||
|
||||
<n-form-item label="自动获取openId" path="loginAutoOpenId">
|
||||
<n-radio-group v-model:value="formValue.loginAutoOpenId" name="loginAutoOpenId">
|
||||
<n-space>
|
||||
<n-radio :value="1">开启</n-radio>
|
||||
<n-radio :value="2">关闭</n-radio>
|
||||
</n-space>
|
||||
</n-radio-group>
|
||||
<template #feedback>
|
||||
在微信内登录后台时,自动获取当前登录人的openid(如开启需要配置微信公众号参数)</template
|
||||
>
|
||||
</n-form-item>
|
||||
|
||||
<n-divider title-placement="left">注册默认信息配置</n-divider>
|
||||
<n-form-item label="默认注册头像" path="loginAvatar">
|
||||
<UploadImage :maxNumber="1" v-model:value="formValue.loginAvatar" />
|
||||
</n-form-item>
|
||||
@@ -46,6 +72,7 @@
|
||||
<n-select v-model:value="formValue.loginPostIds" multiple :options="options.post" />
|
||||
</n-form-item>
|
||||
|
||||
<n-divider title-placement="left">协议配置</n-divider>
|
||||
<n-form-item label="用户协议" path="loginProtocol">
|
||||
<Editor
|
||||
style="height: 320px"
|
||||
@@ -84,8 +111,10 @@
|
||||
const formRef: any = ref(null);
|
||||
const message = useMessage();
|
||||
const formValue = ref({
|
||||
loginRegisterSwitch: true,
|
||||
loginCaptchaSwitch: true,
|
||||
loginRegisterSwitch: 1,
|
||||
loginCaptchaSwitch: 1,
|
||||
loginForceInvite: 2,
|
||||
loginAutoOpenId: 2,
|
||||
loginAvatar: '',
|
||||
loginProtocol: '',
|
||||
loginPolicy: '',
|
||||
@@ -152,6 +181,7 @@
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
show.value = true;
|
||||
await loadOptions();
|
||||
load();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user