mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 07:49:20 +08:00
refactor: 移除初始化向导
This commit is contained in:
-1
@@ -46,7 +46,6 @@ public class SecurityConfig {
|
|||||||
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
|
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
|
||||||
.authorizeHttpRequests(auth -> auth
|
.authorizeHttpRequests(auth -> auth
|
||||||
.requestMatchers("/auth/login", "/auth/register", "/auth/refresh").permitAll()
|
.requestMatchers("/auth/login", "/auth/register", "/auth/refresh").permitAll()
|
||||||
.requestMatchers("/init/**").permitAll()
|
|
||||||
.requestMatchers("/uploads/**").permitAll() // 允许直接访问上传的文件
|
.requestMatchers("/uploads/**").permitAll() // 允许直接访问上传的文件
|
||||||
.requestMatchers("/doc.html", "/webjars/**", "/v3/api-docs/**", "/swagger-resources/**",
|
.requestMatchers("/doc.html", "/webjars/**", "/v3/api-docs/**", "/swagger-resources/**",
|
||||||
"/swagger-ui/**", "/swagger-ui.html")
|
"/swagger-ui/**", "/swagger-ui.html")
|
||||||
|
|||||||
-31
@@ -1,31 +0,0 @@
|
|||||||
package top.xyquan.ecomdmbbackend.modules.sys.init.controller;
|
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
import top.xyquan.ecomdmbbackend.common.response.ApiResponse;
|
|
||||||
import top.xyquan.ecomdmbbackend.modules.sys.init.model.vo.InitStatusVO;
|
|
||||||
import top.xyquan.ecomdmbbackend.modules.sys.init.service.SysInitService;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 系统初始化状态查询 API(无需登录,用于诊断首次部署状态)
|
|
||||||
*/
|
|
||||||
@Tag(name = "系统初始化", description = "首次部署初始化状态")
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/init")
|
|
||||||
public class InitController {
|
|
||||||
|
|
||||||
private final SysInitService sysInitService;
|
|
||||||
|
|
||||||
public InitController(SysInitService sysInitService) {
|
|
||||||
this.sysInitService = sysInitService;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Operation(summary = "获取初始化状态")
|
|
||||||
@GetMapping("/status")
|
|
||||||
public ApiResponse<InitStatusVO> status() {
|
|
||||||
return ApiResponse.success(sysInitService.getStatus());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-18
@@ -1,18 +0,0 @@
|
|||||||
package top.xyquan.ecomdmbbackend.modules.sys.init.model.vo;
|
|
||||||
|
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 初始化状态
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@Builder
|
|
||||||
public class InitStatusVO {
|
|
||||||
|
|
||||||
private boolean initialized;
|
|
||||||
|
|
||||||
private String systemCompanyName;
|
|
||||||
|
|
||||||
private String adminLoginCode;
|
|
||||||
}
|
|
||||||
-22
@@ -12,7 +12,6 @@ import top.xyquan.ecomdmbbackend.modules.org.company.service.CompanyService;
|
|||||||
import top.xyquan.ecomdmbbackend.modules.sys.init.config.SysInitProperties;
|
import top.xyquan.ecomdmbbackend.modules.sys.init.config.SysInitProperties;
|
||||||
import top.xyquan.ecomdmbbackend.modules.sys.init.mapper.SysInitMapper;
|
import top.xyquan.ecomdmbbackend.modules.sys.init.mapper.SysInitMapper;
|
||||||
import top.xyquan.ecomdmbbackend.modules.sys.init.model.po.SysInitPO;
|
import top.xyquan.ecomdmbbackend.modules.sys.init.model.po.SysInitPO;
|
||||||
import top.xyquan.ecomdmbbackend.modules.sys.init.model.vo.InitStatusVO;
|
|
||||||
import top.xyquan.ecomdmbbackend.modules.sys.user.mapper.UserMapper;
|
import top.xyquan.ecomdmbbackend.modules.sys.user.mapper.UserMapper;
|
||||||
import top.xyquan.ecomdmbbackend.modules.sys.user.model.po.UserPO;
|
import top.xyquan.ecomdmbbackend.modules.sys.user.model.po.UserPO;
|
||||||
|
|
||||||
@@ -94,17 +93,6 @@ public class SysInitService {
|
|||||||
log.info("系统初始化完成:系统公司=[{}],超管账号=[{}]", companyDTO.getName(), admin.getLoginCode());
|
log.info("系统初始化完成:系统公司=[{}],超管账号=[{}]", companyDTO.getName(), admin.getLoginCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
public InitStatusVO getStatus() {
|
|
||||||
SysInitPO init = getOrCreateInitRow();
|
|
||||||
boolean initialized = Boolean.TRUE.equals(init.getInitialized())
|
|
||||||
|| (init.getStep() != null && init.getStep() >= 3);
|
|
||||||
return InitStatusVO.builder()
|
|
||||||
.initialized(initialized)
|
|
||||||
.systemCompanyName(init.getCompanyName())
|
|
||||||
.adminLoginCode(resolveAdminLoginCode(init))
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
private UserPO createSuperAdmin() {
|
private UserPO createSuperAdmin() {
|
||||||
String loginCode = initProperties.getAdminLoginCode();
|
String loginCode = initProperties.getAdminLoginCode();
|
||||||
if (!StringUtils.hasText(loginCode)) {
|
if (!StringUtils.hasText(loginCode)) {
|
||||||
@@ -165,14 +153,4 @@ public class SysInitService {
|
|||||||
}
|
}
|
||||||
return init;
|
return init;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String resolveAdminLoginCode(SysInitPO init) {
|
|
||||||
if (init.getAdminId() != null) {
|
|
||||||
UserPO user = userMapper.selectById(init.getAdminId());
|
|
||||||
if (user != null) {
|
|
||||||
return user.getLoginCode();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return initProperties.getAdminLoginCode();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,23 +1,11 @@
|
|||||||
import type { LicenseDTO, LicenseVO } from './types';
|
import type { LicenseDTO, LicenseVO } from './types';
|
||||||
|
|
||||||
import { baseRequestClient, requestClient } from '#/api/request';
|
import { requestClient } from '#/api/request';
|
||||||
|
|
||||||
/** 初始化相关 API(无需登录) */
|
/** 已登录用户的 License 管理 API */
|
||||||
|
|
||||||
export async function getInitStatusApi() {
|
export async function getLicenseInfoApi() {
|
||||||
return baseRequestClient.get<LicenseVO.InitStatus>('/init/status');
|
return requestClient.get<LicenseVO.LicenseSummary>('/system/license');
|
||||||
}
|
|
||||||
|
|
||||||
export async function createInitAdminApi(data: LicenseDTO.InitAdmin) {
|
|
||||||
return baseRequestClient.post<void>('/init/admin', data);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function saveInitCompanyApi(data: LicenseDTO.InitCompany) {
|
|
||||||
return baseRequestClient.post<void>('/init/company', data);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getInitFingerprintApi() {
|
|
||||||
return baseRequestClient.get<LicenseVO.Fingerprint>('/init/fingerprint');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function activateLicenseApi(data: LicenseDTO.ActivateLicense) {
|
export async function activateLicenseApi(data: LicenseDTO.ActivateLicense) {
|
||||||
@@ -27,20 +15,6 @@ export async function activateLicenseApi(data: LicenseDTO.ActivateLicense) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @deprecated 初始化向导用,后端若未实现可忽略 */
|
|
||||||
export async function activateInitLicenseApi(data: LicenseDTO.ActivateLicense) {
|
|
||||||
return baseRequestClient.post<LicenseVO.LicenseSummary>(
|
|
||||||
'/init/activate',
|
|
||||||
data,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 已登录用户的 License 管理 API */
|
|
||||||
|
|
||||||
export async function getLicenseInfoApi() {
|
|
||||||
return requestClient.get<LicenseVO.LicenseSummary>('/system/license');
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function updateLicenseApi(data: LicenseDTO.ActivateLicense) {
|
export async function updateLicenseApi(data: LicenseDTO.ActivateLicense) {
|
||||||
return requestClient.put<LicenseVO.LicenseSummary>('/system/license', data);
|
return requestClient.put<LicenseVO.LicenseSummary>('/system/license', data);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,19 +2,6 @@
|
|||||||
* License 模块 — 请求 DTO
|
* License 模块 — 请求 DTO
|
||||||
*/
|
*/
|
||||||
export namespace LicenseDTO {
|
export namespace LicenseDTO {
|
||||||
export interface InitAdmin {
|
|
||||||
loginCode: string;
|
|
||||||
phone?: string;
|
|
||||||
password: string;
|
|
||||||
realName: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface InitCompany {
|
|
||||||
companyName: string;
|
|
||||||
contactPhone?: string;
|
|
||||||
contactEmail?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ActivateLicense {
|
export interface ActivateLicense {
|
||||||
licenseKey: string;
|
licenseKey: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,20 +2,11 @@
|
|||||||
* License 模块 — 响应 VO
|
* License 模块 — 响应 VO
|
||||||
*/
|
*/
|
||||||
export namespace LicenseVO {
|
export namespace LicenseVO {
|
||||||
/** 初始化状态 */
|
|
||||||
export interface InitStatus {
|
|
||||||
initialized: boolean;
|
|
||||||
currentStep: number;
|
|
||||||
adminCreated: boolean;
|
|
||||||
companySaved: boolean;
|
|
||||||
licenseActivated: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 机器指纹 */
|
/** 机器指纹 */
|
||||||
export interface Fingerprint {
|
export interface Fingerprint {
|
||||||
fingerprint: string;
|
fingerprint: string;
|
||||||
machineId: string;
|
machineId?: string;
|
||||||
hostname: string;
|
hostname?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** License 摘要 */
|
/** License 摘要 */
|
||||||
|
|||||||
@@ -5,45 +5,11 @@ import { preferences } from '@vben/preferences';
|
|||||||
import { useAccessStore, useUserStore } from '@vben/stores';
|
import { useAccessStore, useUserStore } from '@vben/stores';
|
||||||
import { startProgress, stopProgress } from '@vben/utils';
|
import { startProgress, stopProgress } from '@vben/utils';
|
||||||
|
|
||||||
import { getInitStatusApi } from '#/api/system/license';
|
import { accessRoutes, coreRouteNames } from '#/router/routes';
|
||||||
import { INIT_PATH, accessRoutes, coreRouteNames } from '#/router/routes';
|
|
||||||
import { useAuthStore } from '#/store';
|
import { useAuthStore } from '#/store';
|
||||||
|
|
||||||
import { generateAccess } from './access';
|
import { generateAccess } from './access';
|
||||||
|
|
||||||
/** 缓存初始化状态,避免每次路由切换都请求 */
|
|
||||||
let initStatusCache: { checked: boolean; initialized: boolean } = {
|
|
||||||
checked: false,
|
|
||||||
initialized: true,
|
|
||||||
};
|
|
||||||
|
|
||||||
/** 初始化完成后清除缓存(激活成功后可由页面调用) */
|
|
||||||
export function resetInitStatusCache() {
|
|
||||||
initStatusCache = { checked: false, initialized: true };
|
|
||||||
}
|
|
||||||
|
|
||||||
async function ensureInitialized(toPath: string): Promise<boolean | { path: string; replace: boolean }> {
|
|
||||||
if (toPath === INIT_PATH || toPath.startsWith(`${INIT_PATH}/`)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (!initStatusCache.checked) {
|
|
||||||
try {
|
|
||||||
const status = await getInitStatusApi();
|
|
||||||
initStatusCache = {
|
|
||||||
checked: true,
|
|
||||||
initialized: status.initialized,
|
|
||||||
};
|
|
||||||
} catch {
|
|
||||||
// 后端不可达时不阻断(本地纯前端开发)
|
|
||||||
initStatusCache = { checked: true, initialized: true };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!initStatusCache.initialized) {
|
|
||||||
return { path: INIT_PATH, replace: true };
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通用守卫配置
|
* 通用守卫配置
|
||||||
* @param router
|
* @param router
|
||||||
@@ -84,12 +50,6 @@ function setupAccessGuard(router: Router) {
|
|||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
const authStore = useAuthStore();
|
const authStore = useAuthStore();
|
||||||
|
|
||||||
// 未初始化则强制进入初始化向导(Init 路由本身跳过)
|
|
||||||
const initCheck = await ensureInitialized(to.path);
|
|
||||||
if (initCheck !== true) {
|
|
||||||
return initCheck;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 基本路由,这些路由不需要进入权限拦截
|
// 基本路由,这些路由不需要进入权限拦截
|
||||||
if (coreRouteNames.includes(to.name as string)) {
|
if (coreRouteNames.includes(to.name as string)) {
|
||||||
if (to.path === LOGIN_PATH && accessStore.accessToken) {
|
if (to.path === LOGIN_PATH && accessStore.accessToken) {
|
||||||
|
|||||||
@@ -20,9 +20,6 @@ const fallbackNotFoundRoute: RouteRecordRaw = {
|
|||||||
path: '/:path(.*)*',
|
path: '/:path(.*)*',
|
||||||
};
|
};
|
||||||
|
|
||||||
/** 系统初始化路径(未初始化时强制跳转) */
|
|
||||||
export const INIT_PATH = '/init';
|
|
||||||
|
|
||||||
/** 基本路由,这些路由是必须存在的 */
|
/** 基本路由,这些路由是必须存在的 */
|
||||||
const coreRoutes: RouteRecordRaw[] = [
|
const coreRoutes: RouteRecordRaw[] = [
|
||||||
/**
|
/**
|
||||||
@@ -41,17 +38,6 @@ const coreRoutes: RouteRecordRaw[] = [
|
|||||||
redirect: preferences.app.defaultHomePath,
|
redirect: preferences.app.defaultHomePath,
|
||||||
children: [],
|
children: [],
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: 'Init',
|
|
||||||
path: INIT_PATH,
|
|
||||||
component: () => import('#/views/init/InitWizard.vue'),
|
|
||||||
meta: {
|
|
||||||
hideInBreadcrumb: true,
|
|
||||||
hideInMenu: true,
|
|
||||||
hideInTab: true,
|
|
||||||
title: '系统初始化',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
component: AuthPageLayout,
|
component: AuthPageLayout,
|
||||||
meta: {
|
meta: {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import type { RouteRecordRaw } from 'vue-router';
|
|||||||
|
|
||||||
import { mergeRouteModules, traverseTreeValues } from '@vben/utils';
|
import { mergeRouteModules, traverseTreeValues } from '@vben/utils';
|
||||||
|
|
||||||
import { coreRoutes, fallbackNotFoundRoute, INIT_PATH } from './core';
|
import { coreRoutes, fallbackNotFoundRoute } from './core';
|
||||||
|
|
||||||
const dynamicRouteFiles = import.meta.glob('./modules/**/*.ts', {
|
const dynamicRouteFiles = import.meta.glob('./modules/**/*.ts', {
|
||||||
eager: true,
|
eager: true,
|
||||||
@@ -41,4 +41,4 @@ const routes: RouteRecordRaw[] = [
|
|||||||
|
|
||||||
/** 有权限校验的路由列表,包含动态路由 */
|
/** 有权限校验的路由列表,包含动态路由 */
|
||||||
const accessRoutes = [...dynamicRoutes];
|
const accessRoutes = [...dynamicRoutes];
|
||||||
export { accessRoutes, coreRouteNames, INIT_PATH, routes };
|
export { accessRoutes, coreRouteNames, routes };
|
||||||
|
|||||||
@@ -1,85 +0,0 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
import type { LicenseDTO } from '#/api/system/license';
|
|
||||||
|
|
||||||
import { reactive, ref } from 'vue';
|
|
||||||
|
|
||||||
import { Button, Form, Input, message } from 'ant-design-vue';
|
|
||||||
|
|
||||||
import { createInitAdminApi } from '#/api/system/license';
|
|
||||||
|
|
||||||
defineOptions({ name: 'InitStepAdmin' });
|
|
||||||
|
|
||||||
const emit = defineEmits<{
|
|
||||||
next: [];
|
|
||||||
}>();
|
|
||||||
|
|
||||||
const submitting = ref(false);
|
|
||||||
|
|
||||||
const formState = reactive<LicenseDTO.InitAdmin>({
|
|
||||||
loginCode: '',
|
|
||||||
phone: '',
|
|
||||||
password: '',
|
|
||||||
realName: '',
|
|
||||||
});
|
|
||||||
|
|
||||||
const rules = {
|
|
||||||
loginCode: [{ required: true, message: '请输入登录账号' }],
|
|
||||||
password: [{ required: true, message: '请输入密码' }],
|
|
||||||
realName: [{ required: true, message: '请输入姓名' }],
|
|
||||||
};
|
|
||||||
|
|
||||||
async function handleSubmit() {
|
|
||||||
submitting.value = true;
|
|
||||||
const hide = message.loading('正在创建超级管理员...', 0);
|
|
||||||
try {
|
|
||||||
await createInitAdminApi({
|
|
||||||
...formState,
|
|
||||||
phone: formState.phone || undefined,
|
|
||||||
});
|
|
||||||
message.success('超级管理员创建成功');
|
|
||||||
emit('next');
|
|
||||||
} finally {
|
|
||||||
hide();
|
|
||||||
submitting.value = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<Form
|
|
||||||
layout="vertical"
|
|
||||||
:model="formState"
|
|
||||||
:rules="rules"
|
|
||||||
@finish="handleSubmit"
|
|
||||||
>
|
|
||||||
<Form.Item label="登录账号" name="loginCode">
|
|
||||||
<Input
|
|
||||||
v-model:value="formState.loginCode"
|
|
||||||
placeholder="超级管理员登录账号"
|
|
||||||
autocomplete="username"
|
|
||||||
/>
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item label="手机号码" name="phone">
|
|
||||||
<Input
|
|
||||||
v-model:value="formState.phone"
|
|
||||||
placeholder="选填"
|
|
||||||
autocomplete="tel"
|
|
||||||
/>
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item label="姓名" name="realName">
|
|
||||||
<Input v-model:value="formState.realName" placeholder="管理员姓名" />
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item label="登录密码" name="password">
|
|
||||||
<Input.Password
|
|
||||||
v-model:value="formState.password"
|
|
||||||
placeholder="设置登录密码"
|
|
||||||
autocomplete="new-password"
|
|
||||||
/>
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item>
|
|
||||||
<Button type="primary" html-type="submit" :loading="submitting" block>
|
|
||||||
下一步
|
|
||||||
</Button>
|
|
||||||
</Form.Item>
|
|
||||||
</Form>
|
|
||||||
</template>
|
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
import type { LicenseDTO } from '#/api/system/license';
|
|
||||||
|
|
||||||
import { reactive, ref } from 'vue';
|
|
||||||
|
|
||||||
import { Button, Form, Input, message } from 'ant-design-vue';
|
|
||||||
|
|
||||||
import { saveInitCompanyApi } from '#/api/system/license';
|
|
||||||
|
|
||||||
defineOptions({ name: 'InitStepCompany' });
|
|
||||||
|
|
||||||
const emit = defineEmits<{
|
|
||||||
back: [];
|
|
||||||
next: [];
|
|
||||||
}>();
|
|
||||||
|
|
||||||
const submitting = ref(false);
|
|
||||||
|
|
||||||
const formState = reactive<LicenseDTO.InitCompany>({
|
|
||||||
companyName: '',
|
|
||||||
contactPhone: '',
|
|
||||||
contactEmail: '',
|
|
||||||
});
|
|
||||||
|
|
||||||
const rules = {
|
|
||||||
companyName: [{ required: true, message: '请输入公司名称' }],
|
|
||||||
};
|
|
||||||
|
|
||||||
async function handleSubmit() {
|
|
||||||
submitting.value = true;
|
|
||||||
const hide = message.loading('正在保存公司信息...', 0);
|
|
||||||
try {
|
|
||||||
await saveInitCompanyApi({
|
|
||||||
...formState,
|
|
||||||
contactPhone: formState.contactPhone || undefined,
|
|
||||||
contactEmail: formState.contactEmail || undefined,
|
|
||||||
});
|
|
||||||
message.success('公司信息保存成功');
|
|
||||||
emit('next');
|
|
||||||
} finally {
|
|
||||||
hide();
|
|
||||||
submitting.value = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<Form
|
|
||||||
layout="vertical"
|
|
||||||
:model="formState"
|
|
||||||
:rules="rules"
|
|
||||||
@finish="handleSubmit"
|
|
||||||
>
|
|
||||||
<Form.Item label="公司名称" name="companyName">
|
|
||||||
<Input v-model:value="formState.companyName" placeholder="公司全称" />
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item label="联系电话" name="contactPhone">
|
|
||||||
<Input v-model:value="formState.contactPhone" placeholder="选填" />
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item label="联系邮箱" name="contactEmail">
|
|
||||||
<Input v-model:value="formState.contactEmail" placeholder="选填" />
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item>
|
|
||||||
<div class="flex gap-3">
|
|
||||||
<Button class="flex-1" @click="emit('back')">上一步</Button>
|
|
||||||
<Button
|
|
||||||
type="primary"
|
|
||||||
html-type="submit"
|
|
||||||
class="flex-1"
|
|
||||||
:loading="submitting"
|
|
||||||
>
|
|
||||||
下一步
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</Form.Item>
|
|
||||||
</Form>
|
|
||||||
</template>
|
|
||||||
@@ -1,103 +0,0 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
import type { LicenseVO } from '#/api/system/license';
|
|
||||||
|
|
||||||
import { onMounted, ref } from 'vue';
|
|
||||||
import { useRouter } from 'vue-router';
|
|
||||||
|
|
||||||
import { LOGIN_PATH } from '@vben/constants';
|
|
||||||
|
|
||||||
import { Button, Form, Input, message, Typography } from 'ant-design-vue';
|
|
||||||
|
|
||||||
import {
|
|
||||||
activateInitLicenseApi,
|
|
||||||
getInitFingerprintApi,
|
|
||||||
} from '#/api/system/license';
|
|
||||||
import { resetInitStatusCache } from '#/router/guard';
|
|
||||||
|
|
||||||
import FingerprintDisplay from './components/FingerprintDisplay.vue';
|
|
||||||
|
|
||||||
defineOptions({ name: 'InitStepLicense' });
|
|
||||||
|
|
||||||
const emit = defineEmits<{
|
|
||||||
back: [];
|
|
||||||
}>();
|
|
||||||
|
|
||||||
const router = useRouter();
|
|
||||||
const submitting = ref(false);
|
|
||||||
const fingerprintLoading = ref(false);
|
|
||||||
const fingerprint = ref<LicenseVO.Fingerprint | null>(null);
|
|
||||||
const licenseKey = ref('');
|
|
||||||
|
|
||||||
async function loadFingerprint() {
|
|
||||||
fingerprintLoading.value = true;
|
|
||||||
try {
|
|
||||||
fingerprint.value = await getInitFingerprintApi();
|
|
||||||
} finally {
|
|
||||||
fingerprintLoading.value = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function handleActivate() {
|
|
||||||
if (!licenseKey.value.trim()) {
|
|
||||||
message.warning('请输入 License Key');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
submitting.value = true;
|
|
||||||
const hide = message.loading('正在激活 License...', 0);
|
|
||||||
try {
|
|
||||||
await activateInitLicenseApi({ licenseKey: licenseKey.value.trim() });
|
|
||||||
resetInitStatusCache();
|
|
||||||
message.success('系统初始化完成,请登录');
|
|
||||||
await router.replace(LOGIN_PATH);
|
|
||||||
} finally {
|
|
||||||
hide();
|
|
||||||
submitting.value = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onMounted(() => {
|
|
||||||
loadFingerprint();
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<div class="space-y-4">
|
|
||||||
<Typography.Paragraph type="secondary" class="!mb-0 text-sm">
|
|
||||||
将机器指纹提供给运营方,获取 License Key 后粘贴到下方完成激活。
|
|
||||||
</Typography.Paragraph>
|
|
||||||
|
|
||||||
<div v-if="fingerprintLoading" class="py-6 text-center text-gray-400">
|
|
||||||
正在获取机器指纹...
|
|
||||||
</div>
|
|
||||||
<FingerprintDisplay
|
|
||||||
v-else-if="fingerprint"
|
|
||||||
:fingerprint="fingerprint.fingerprint"
|
|
||||||
:hostname="fingerprint.hostname"
|
|
||||||
:machine-id="fingerprint.machineId"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<Form layout="vertical" @finish="handleActivate">
|
|
||||||
<Form.Item label="License Key" required>
|
|
||||||
<Input.TextArea
|
|
||||||
v-model:value="licenseKey"
|
|
||||||
:rows="4"
|
|
||||||
placeholder="粘贴运营方签发的 License JWT"
|
|
||||||
class="font-mono text-xs"
|
|
||||||
/>
|
|
||||||
</Form.Item>
|
|
||||||
<Form.Item>
|
|
||||||
<div class="flex gap-3">
|
|
||||||
<Button class="flex-1" @click="emit('back')">上一步</Button>
|
|
||||||
<Button
|
|
||||||
type="primary"
|
|
||||||
html-type="submit"
|
|
||||||
class="flex-1"
|
|
||||||
:loading="submitting"
|
|
||||||
>
|
|
||||||
激活并完成
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</Form.Item>
|
|
||||||
</Form>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
@@ -1,91 +0,0 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
import { onMounted, ref } from 'vue';
|
|
||||||
import { useRouter } from 'vue-router';
|
|
||||||
|
|
||||||
import { LOGIN_PATH } from '@vben/constants';
|
|
||||||
import { preferences } from '@vben/preferences';
|
|
||||||
|
|
||||||
import { Card, Spin, Steps, Typography } from 'ant-design-vue';
|
|
||||||
|
|
||||||
import { getInitStatusApi } from '#/api/system/license';
|
|
||||||
|
|
||||||
import InitStepAdmin from './InitStepAdmin.vue';
|
|
||||||
import InitStepCompany from './InitStepCompany.vue';
|
|
||||||
import InitStepLicense from './InitStepLicense.vue';
|
|
||||||
|
|
||||||
defineOptions({ name: 'InitWizard' });
|
|
||||||
|
|
||||||
const router = useRouter();
|
|
||||||
const currentStep = ref(0);
|
|
||||||
const statusLoading = ref(true);
|
|
||||||
|
|
||||||
const stepItems = [
|
|
||||||
{ title: '超级管理员' },
|
|
||||||
{ title: '公司信息' },
|
|
||||||
{ title: 'License 激活' },
|
|
||||||
];
|
|
||||||
|
|
||||||
async function loadStatus() {
|
|
||||||
statusLoading.value = true;
|
|
||||||
try {
|
|
||||||
const status = await getInitStatusApi();
|
|
||||||
if (status.initialized) {
|
|
||||||
await router.replace(LOGIN_PATH);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// 根据后端进度定位到对应步骤
|
|
||||||
if (status.licenseActivated || status.currentStep >= 3) {
|
|
||||||
currentStep.value = 2;
|
|
||||||
} else if (status.companySaved || status.currentStep >= 2) {
|
|
||||||
currentStep.value = 2;
|
|
||||||
} else if (status.adminCreated || status.currentStep >= 1) {
|
|
||||||
currentStep.value = 1;
|
|
||||||
} else {
|
|
||||||
currentStep.value = 0;
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
statusLoading.value = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function goNext() {
|
|
||||||
currentStep.value = Math.min(currentStep.value + 1, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
function goBack() {
|
|
||||||
currentStep.value = Math.max(currentStep.value - 1, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
onMounted(() => {
|
|
||||||
loadStatus();
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<div
|
|
||||||
class="flex min-h-screen flex-col items-center justify-center bg-gradient-to-b from-background to-muted/30 px-4 py-10"
|
|
||||||
>
|
|
||||||
<div class="mb-8 text-center">
|
|
||||||
<Typography.Title :level="3" class="!mb-1">
|
|
||||||
{{ preferences.app.name }} 系统初始化
|
|
||||||
</Typography.Title>
|
|
||||||
<Typography.Text type="secondary">
|
|
||||||
首次部署请按步骤完成配置
|
|
||||||
</Typography.Text>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<Card class="w-full max-w-lg shadow-sm">
|
|
||||||
<Steps :current="currentStep" :items="stepItems" class="mb-8" />
|
|
||||||
|
|
||||||
<Spin :spinning="statusLoading">
|
|
||||||
<InitStepAdmin v-if="currentStep === 0" @next="goNext" />
|
|
||||||
<InitStepCompany
|
|
||||||
v-else-if="currentStep === 1"
|
|
||||||
@back="goBack"
|
|
||||||
@next="goNext"
|
|
||||||
/>
|
|
||||||
<InitStepLicense v-else @back="goBack" />
|
|
||||||
</Spin>
|
|
||||||
</Card>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
@@ -7,7 +7,7 @@ import { Card, Spin } from 'ant-design-vue';
|
|||||||
|
|
||||||
import { getSystemFingerprintApi } from '#/api/system/license';
|
import { getSystemFingerprintApi } from '#/api/system/license';
|
||||||
|
|
||||||
import FingerprintDisplay from '#/views/init/components/FingerprintDisplay.vue';
|
import FingerprintDisplay from './FingerprintDisplay.vue';
|
||||||
|
|
||||||
defineOptions({ name: 'FingerprintInfo' });
|
defineOptions({ name: 'FingerprintInfo' });
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ import {
|
|||||||
getSystemFingerprintApi,
|
getSystemFingerprintApi,
|
||||||
} from '#/api/system/license';
|
} from '#/api/system/license';
|
||||||
|
|
||||||
import FingerprintDisplay from '#/views/init/components/FingerprintDisplay.vue';
|
import FingerprintDisplay from './FingerprintDisplay.vue';
|
||||||
|
|
||||||
defineOptions({ name: 'SystemLicensePage' });
|
defineOptions({ name: 'SystemLicensePage' });
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user