mirror of
https://gitee.com/yudaocode/yudao-ui-admin-vben.git
synced 2025-12-30 02:22:25 +00:00
chore: remove playground and backend-mock
This commit is contained in:
9
.vscode/launch.json
vendored
9
.vscode/launch.json
vendored
@@ -2,15 +2,6 @@
|
|||||||
"$schema": "https://json.schemastore.org/launchsettings.json",
|
"$schema": "https://json.schemastore.org/launchsettings.json",
|
||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
|
||||||
"type": "chrome",
|
|
||||||
"name": "vben admin playground dev",
|
|
||||||
"request": "launch",
|
|
||||||
"url": "http://localhost:5555",
|
|
||||||
"env": { "NODE_ENV": "development" },
|
|
||||||
"sourceMaps": true,
|
|
||||||
"webRoot": "${workspaceFolder}/playground"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"type": "chrome",
|
"type": "chrome",
|
||||||
"name": "vben admin antd dev",
|
"name": "vben admin antd dev",
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
PORT=5320
|
|
||||||
ACCESS_TOKEN_SECRET=access_token_secret
|
|
||||||
REFRESH_TOKEN_SECRET=refresh_token_secret
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
# @vben/backend-mock
|
|
||||||
|
|
||||||
## Description
|
|
||||||
|
|
||||||
Vben Admin 数据 mock 服务,没有对接任何的数据库,所有数据都是模拟的,用于前端开发时提供数据支持。线上环境不再提供 mock 集成,可自行部署服务或者对接真实数据,由于 `mock.js` 等工具有一些限制,比如上传文件不行、无法模拟复杂的逻辑等,所以这里使用了真实的后端服务来实现。唯一麻烦的是本地需要同时启动后端服务和前端服务,但是这样可以更好的模拟真实环境。该服务不需要手动启动,已经集成在 vite 插件内,随应用一起启用。
|
|
||||||
|
|
||||||
## Running the app
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# development
|
|
||||||
$ pnpm run start
|
|
||||||
|
|
||||||
# production mode
|
|
||||||
$ pnpm run build
|
|
||||||
```
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
import { eventHandler } from 'h3';
|
|
||||||
import { verifyAccessToken } from '~/utils/jwt-utils';
|
|
||||||
import { MOCK_CODES } from '~/utils/mock-data';
|
|
||||||
import { unAuthorizedResponse, useResponseSuccess } from '~/utils/response';
|
|
||||||
|
|
||||||
export default eventHandler((event) => {
|
|
||||||
const userinfo = verifyAccessToken(event);
|
|
||||||
if (!userinfo) {
|
|
||||||
return unAuthorizedResponse(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
const codes =
|
|
||||||
MOCK_CODES.find((item) => item.username === userinfo.username)?.codes ?? [];
|
|
||||||
|
|
||||||
return useResponseSuccess(codes);
|
|
||||||
});
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
import { defineEventHandler, readBody, setResponseStatus } from 'h3';
|
|
||||||
import {
|
|
||||||
clearRefreshTokenCookie,
|
|
||||||
setRefreshTokenCookie,
|
|
||||||
} from '~/utils/cookie-utils';
|
|
||||||
import { generateAccessToken, generateRefreshToken } from '~/utils/jwt-utils';
|
|
||||||
import { MOCK_USERS } from '~/utils/mock-data';
|
|
||||||
import {
|
|
||||||
forbiddenResponse,
|
|
||||||
useResponseError,
|
|
||||||
useResponseSuccess,
|
|
||||||
} from '~/utils/response';
|
|
||||||
|
|
||||||
export default defineEventHandler(async (event) => {
|
|
||||||
const { password, username } = await readBody(event);
|
|
||||||
if (!password || !username) {
|
|
||||||
setResponseStatus(event, 400);
|
|
||||||
return useResponseError(
|
|
||||||
'BadRequestException',
|
|
||||||
'Username and password are required',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const findUser = MOCK_USERS.find(
|
|
||||||
(item) => item.username === username && item.password === password,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!findUser) {
|
|
||||||
clearRefreshTokenCookie(event);
|
|
||||||
return forbiddenResponse(event, 'Username or password is incorrect.');
|
|
||||||
}
|
|
||||||
|
|
||||||
const accessToken = generateAccessToken(findUser);
|
|
||||||
const refreshToken = generateRefreshToken(findUser);
|
|
||||||
|
|
||||||
setRefreshTokenCookie(event, refreshToken);
|
|
||||||
|
|
||||||
return useResponseSuccess({
|
|
||||||
...findUser,
|
|
||||||
accessToken,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
import { defineEventHandler } from 'h3';
|
|
||||||
import {
|
|
||||||
clearRefreshTokenCookie,
|
|
||||||
getRefreshTokenFromCookie,
|
|
||||||
} from '~/utils/cookie-utils';
|
|
||||||
import { useResponseSuccess } from '~/utils/response';
|
|
||||||
|
|
||||||
export default defineEventHandler(async (event) => {
|
|
||||||
const refreshToken = getRefreshTokenFromCookie(event);
|
|
||||||
if (!refreshToken) {
|
|
||||||
return useResponseSuccess('');
|
|
||||||
}
|
|
||||||
|
|
||||||
clearRefreshTokenCookie(event);
|
|
||||||
|
|
||||||
return useResponseSuccess('');
|
|
||||||
});
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
import { defineEventHandler } from 'h3';
|
|
||||||
import {
|
|
||||||
clearRefreshTokenCookie,
|
|
||||||
getRefreshTokenFromCookie,
|
|
||||||
setRefreshTokenCookie,
|
|
||||||
} from '~/utils/cookie-utils';
|
|
||||||
import { generateAccessToken, verifyRefreshToken } from '~/utils/jwt-utils';
|
|
||||||
import { MOCK_USERS } from '~/utils/mock-data';
|
|
||||||
import { forbiddenResponse } from '~/utils/response';
|
|
||||||
|
|
||||||
export default defineEventHandler(async (event) => {
|
|
||||||
const refreshToken = getRefreshTokenFromCookie(event);
|
|
||||||
if (!refreshToken) {
|
|
||||||
return forbiddenResponse(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
clearRefreshTokenCookie(event);
|
|
||||||
|
|
||||||
const userinfo = verifyRefreshToken(refreshToken);
|
|
||||||
if (!userinfo) {
|
|
||||||
return forbiddenResponse(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
const findUser = MOCK_USERS.find(
|
|
||||||
(item) => item.username === userinfo.username,
|
|
||||||
);
|
|
||||||
if (!findUser) {
|
|
||||||
return forbiddenResponse(event);
|
|
||||||
}
|
|
||||||
const accessToken = generateAccessToken(findUser);
|
|
||||||
|
|
||||||
setRefreshTokenCookie(event, refreshToken);
|
|
||||||
|
|
||||||
return accessToken;
|
|
||||||
});
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
import { eventHandler, setHeader } from 'h3';
|
|
||||||
import { verifyAccessToken } from '~/utils/jwt-utils';
|
|
||||||
import { unAuthorizedResponse } from '~/utils/response';
|
|
||||||
|
|
||||||
export default eventHandler(async (event) => {
|
|
||||||
const userinfo = verifyAccessToken(event);
|
|
||||||
if (!userinfo) {
|
|
||||||
return unAuthorizedResponse(event);
|
|
||||||
}
|
|
||||||
const data = `
|
|
||||||
{
|
|
||||||
"code": 0,
|
|
||||||
"message": "success",
|
|
||||||
"data": [
|
|
||||||
{
|
|
||||||
"id": 123456789012345678901234567890123456789012345678901234567890,
|
|
||||||
"name": "John Doe",
|
|
||||||
"age": 30,
|
|
||||||
"email": "john-doe@demo.com"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": 987654321098765432109876543210987654321098765432109876543210,
|
|
||||||
"name": "Jane Smith",
|
|
||||||
"age": 25,
|
|
||||||
"email": "jane@demo.com"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
setHeader(event, 'Content-Type', 'application/json');
|
|
||||||
return data;
|
|
||||||
});
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
import { eventHandler } from 'h3';
|
|
||||||
import { verifyAccessToken } from '~/utils/jwt-utils';
|
|
||||||
import { MOCK_MENUS } from '~/utils/mock-data';
|
|
||||||
import { unAuthorizedResponse, useResponseSuccess } from '~/utils/response';
|
|
||||||
|
|
||||||
export default eventHandler(async (event) => {
|
|
||||||
const userinfo = verifyAccessToken(event);
|
|
||||||
if (!userinfo) {
|
|
||||||
return unAuthorizedResponse(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
const menus =
|
|
||||||
MOCK_MENUS.find((item) => item.username === userinfo.username)?.menus ?? [];
|
|
||||||
return useResponseSuccess(menus);
|
|
||||||
});
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
import { eventHandler, getQuery, setResponseStatus } from 'h3';
|
|
||||||
import { useResponseError } from '~/utils/response';
|
|
||||||
|
|
||||||
export default eventHandler((event) => {
|
|
||||||
const { status } = getQuery(event);
|
|
||||||
setResponseStatus(event, Number(status));
|
|
||||||
return useResponseError(`${status}`);
|
|
||||||
});
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
import { eventHandler } from 'h3';
|
|
||||||
import { verifyAccessToken } from '~/utils/jwt-utils';
|
|
||||||
import {
|
|
||||||
sleep,
|
|
||||||
unAuthorizedResponse,
|
|
||||||
useResponseSuccess,
|
|
||||||
} from '~/utils/response';
|
|
||||||
|
|
||||||
export default eventHandler(async (event) => {
|
|
||||||
const userinfo = verifyAccessToken(event);
|
|
||||||
if (!userinfo) {
|
|
||||||
return unAuthorizedResponse(event);
|
|
||||||
}
|
|
||||||
await sleep(600);
|
|
||||||
return useResponseSuccess(null);
|
|
||||||
});
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
import { eventHandler } from 'h3';
|
|
||||||
import { verifyAccessToken } from '~/utils/jwt-utils';
|
|
||||||
import {
|
|
||||||
sleep,
|
|
||||||
unAuthorizedResponse,
|
|
||||||
useResponseSuccess,
|
|
||||||
} from '~/utils/response';
|
|
||||||
|
|
||||||
export default eventHandler(async (event) => {
|
|
||||||
const userinfo = verifyAccessToken(event);
|
|
||||||
if (!userinfo) {
|
|
||||||
return unAuthorizedResponse(event);
|
|
||||||
}
|
|
||||||
await sleep(1000);
|
|
||||||
return useResponseSuccess(null);
|
|
||||||
});
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
import { eventHandler } from 'h3';
|
|
||||||
import { verifyAccessToken } from '~/utils/jwt-utils';
|
|
||||||
import {
|
|
||||||
sleep,
|
|
||||||
unAuthorizedResponse,
|
|
||||||
useResponseSuccess,
|
|
||||||
} from '~/utils/response';
|
|
||||||
|
|
||||||
export default eventHandler(async (event) => {
|
|
||||||
const userinfo = verifyAccessToken(event);
|
|
||||||
if (!userinfo) {
|
|
||||||
return unAuthorizedResponse(event);
|
|
||||||
}
|
|
||||||
await sleep(2000);
|
|
||||||
return useResponseSuccess(null);
|
|
||||||
});
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
import { faker } from '@faker-js/faker';
|
|
||||||
import { eventHandler } from 'h3';
|
|
||||||
import { verifyAccessToken } from '~/utils/jwt-utils';
|
|
||||||
import { unAuthorizedResponse, useResponseSuccess } from '~/utils/response';
|
|
||||||
|
|
||||||
const formatterCN = new Intl.DateTimeFormat('zh-CN', {
|
|
||||||
timeZone: 'Asia/Shanghai',
|
|
||||||
year: 'numeric',
|
|
||||||
month: '2-digit',
|
|
||||||
day: '2-digit',
|
|
||||||
hour: '2-digit',
|
|
||||||
minute: '2-digit',
|
|
||||||
second: '2-digit',
|
|
||||||
});
|
|
||||||
|
|
||||||
function generateMockDataList(count: number) {
|
|
||||||
const dataList = [];
|
|
||||||
|
|
||||||
for (let i = 0; i < count; i++) {
|
|
||||||
const dataItem: Record<string, any> = {
|
|
||||||
id: faker.string.uuid(),
|
|
||||||
pid: 0,
|
|
||||||
name: faker.commerce.department(),
|
|
||||||
status: faker.helpers.arrayElement([0, 1]),
|
|
||||||
createTime: formatterCN.format(
|
|
||||||
faker.date.between({ from: '2021-01-01', to: '2022-12-31' }),
|
|
||||||
),
|
|
||||||
remark: faker.lorem.sentence(),
|
|
||||||
};
|
|
||||||
if (faker.datatype.boolean()) {
|
|
||||||
dataItem.children = Array.from(
|
|
||||||
{ length: faker.number.int({ min: 1, max: 5 }) },
|
|
||||||
() => ({
|
|
||||||
id: faker.string.uuid(),
|
|
||||||
pid: dataItem.id,
|
|
||||||
name: faker.commerce.department(),
|
|
||||||
status: faker.helpers.arrayElement([0, 1]),
|
|
||||||
createTime: formatterCN.format(
|
|
||||||
faker.date.between({ from: '2023-01-01', to: '2023-12-31' }),
|
|
||||||
),
|
|
||||||
remark: faker.lorem.sentence(),
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
dataList.push(dataItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
return dataList;
|
|
||||||
}
|
|
||||||
|
|
||||||
const mockData = generateMockDataList(10);
|
|
||||||
|
|
||||||
export default eventHandler(async (event) => {
|
|
||||||
const userinfo = verifyAccessToken(event);
|
|
||||||
if (!userinfo) {
|
|
||||||
return unAuthorizedResponse(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
const listData = structuredClone(mockData);
|
|
||||||
|
|
||||||
return useResponseSuccess(listData);
|
|
||||||
});
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
import { eventHandler } from 'h3';
|
|
||||||
import { verifyAccessToken } from '~/utils/jwt-utils';
|
|
||||||
import { MOCK_MENU_LIST } from '~/utils/mock-data';
|
|
||||||
import { unAuthorizedResponse, useResponseSuccess } from '~/utils/response';
|
|
||||||
|
|
||||||
export default eventHandler(async (event) => {
|
|
||||||
const userinfo = verifyAccessToken(event);
|
|
||||||
if (!userinfo) {
|
|
||||||
return unAuthorizedResponse(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
return useResponseSuccess(MOCK_MENU_LIST);
|
|
||||||
});
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
import { eventHandler, getQuery } from 'h3';
|
|
||||||
import { verifyAccessToken } from '~/utils/jwt-utils';
|
|
||||||
import { MOCK_MENU_LIST } from '~/utils/mock-data';
|
|
||||||
import { unAuthorizedResponse, useResponseSuccess } from '~/utils/response';
|
|
||||||
|
|
||||||
const namesMap: Record<string, any> = {};
|
|
||||||
|
|
||||||
function getNames(menus: any[]) {
|
|
||||||
menus.forEach((menu) => {
|
|
||||||
namesMap[menu.name] = String(menu.id);
|
|
||||||
if (menu.children) {
|
|
||||||
getNames(menu.children);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
getNames(MOCK_MENU_LIST);
|
|
||||||
|
|
||||||
export default eventHandler(async (event) => {
|
|
||||||
const userinfo = verifyAccessToken(event);
|
|
||||||
if (!userinfo) {
|
|
||||||
return unAuthorizedResponse(event);
|
|
||||||
}
|
|
||||||
const { id, name } = getQuery(event);
|
|
||||||
|
|
||||||
return (name as string) in namesMap &&
|
|
||||||
(!id || namesMap[name as string] !== String(id))
|
|
||||||
? useResponseSuccess(true)
|
|
||||||
: useResponseSuccess(false);
|
|
||||||
});
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
import { eventHandler, getQuery } from 'h3';
|
|
||||||
import { verifyAccessToken } from '~/utils/jwt-utils';
|
|
||||||
import { MOCK_MENU_LIST } from '~/utils/mock-data';
|
|
||||||
import { unAuthorizedResponse, useResponseSuccess } from '~/utils/response';
|
|
||||||
|
|
||||||
const pathMap: Record<string, any> = { '/': 0 };
|
|
||||||
|
|
||||||
function getPaths(menus: any[]) {
|
|
||||||
menus.forEach((menu) => {
|
|
||||||
pathMap[menu.path] = String(menu.id);
|
|
||||||
if (menu.children) {
|
|
||||||
getPaths(menu.children);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
getPaths(MOCK_MENU_LIST);
|
|
||||||
|
|
||||||
export default eventHandler(async (event) => {
|
|
||||||
const userinfo = verifyAccessToken(event);
|
|
||||||
if (!userinfo) {
|
|
||||||
return unAuthorizedResponse(event);
|
|
||||||
}
|
|
||||||
const { id, path } = getQuery(event);
|
|
||||||
|
|
||||||
return (path as string) in pathMap &&
|
|
||||||
(!id || pathMap[path as string] !== String(id))
|
|
||||||
? useResponseSuccess(true)
|
|
||||||
: useResponseSuccess(false);
|
|
||||||
});
|
|
||||||
@@ -1,84 +0,0 @@
|
|||||||
import { faker } from '@faker-js/faker';
|
|
||||||
import { eventHandler, getQuery } from 'h3';
|
|
||||||
import { verifyAccessToken } from '~/utils/jwt-utils';
|
|
||||||
import { getMenuIds, MOCK_MENU_LIST } from '~/utils/mock-data';
|
|
||||||
import { unAuthorizedResponse, usePageResponseSuccess } from '~/utils/response';
|
|
||||||
|
|
||||||
const formatterCN = new Intl.DateTimeFormat('zh-CN', {
|
|
||||||
timeZone: 'Asia/Shanghai',
|
|
||||||
year: 'numeric',
|
|
||||||
month: '2-digit',
|
|
||||||
day: '2-digit',
|
|
||||||
hour: '2-digit',
|
|
||||||
minute: '2-digit',
|
|
||||||
second: '2-digit',
|
|
||||||
});
|
|
||||||
|
|
||||||
const menuIds = getMenuIds(MOCK_MENU_LIST);
|
|
||||||
|
|
||||||
function generateMockDataList(count: number) {
|
|
||||||
const dataList = [];
|
|
||||||
|
|
||||||
for (let i = 0; i < count; i++) {
|
|
||||||
const dataItem: Record<string, any> = {
|
|
||||||
id: faker.string.uuid(),
|
|
||||||
name: faker.commerce.product(),
|
|
||||||
status: faker.helpers.arrayElement([0, 1]),
|
|
||||||
createTime: formatterCN.format(
|
|
||||||
faker.date.between({ from: '2022-01-01', to: '2025-01-01' }),
|
|
||||||
),
|
|
||||||
permissions: faker.helpers.arrayElements(menuIds),
|
|
||||||
remark: faker.lorem.sentence(),
|
|
||||||
};
|
|
||||||
|
|
||||||
dataList.push(dataItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
return dataList;
|
|
||||||
}
|
|
||||||
|
|
||||||
const mockData = generateMockDataList(100);
|
|
||||||
|
|
||||||
export default eventHandler(async (event) => {
|
|
||||||
const userinfo = verifyAccessToken(event);
|
|
||||||
if (!userinfo) {
|
|
||||||
return unAuthorizedResponse(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
const {
|
|
||||||
page = 1,
|
|
||||||
pageSize = 20,
|
|
||||||
name,
|
|
||||||
id,
|
|
||||||
remark,
|
|
||||||
startTime,
|
|
||||||
endTime,
|
|
||||||
status,
|
|
||||||
} = getQuery(event);
|
|
||||||
let listData = structuredClone(mockData);
|
|
||||||
if (name) {
|
|
||||||
listData = listData.filter((item) =>
|
|
||||||
item.name.toLowerCase().includes(String(name).toLowerCase()),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (id) {
|
|
||||||
listData = listData.filter((item) =>
|
|
||||||
item.id.toLowerCase().includes(String(id).toLowerCase()),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (remark) {
|
|
||||||
listData = listData.filter((item) =>
|
|
||||||
item.remark?.toLowerCase()?.includes(String(remark).toLowerCase()),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (startTime) {
|
|
||||||
listData = listData.filter((item) => item.createTime >= startTime);
|
|
||||||
}
|
|
||||||
if (endTime) {
|
|
||||||
listData = listData.filter((item) => item.createTime <= endTime);
|
|
||||||
}
|
|
||||||
if (['0', '1'].includes(status as string)) {
|
|
||||||
listData = listData.filter((item) => item.status === Number(status));
|
|
||||||
}
|
|
||||||
return usePageResponseSuccess(page as string, pageSize as string, listData);
|
|
||||||
});
|
|
||||||
@@ -1,117 +0,0 @@
|
|||||||
import { faker } from '@faker-js/faker';
|
|
||||||
import { eventHandler, getQuery } from 'h3';
|
|
||||||
import { verifyAccessToken } from '~/utils/jwt-utils';
|
|
||||||
import {
|
|
||||||
sleep,
|
|
||||||
unAuthorizedResponse,
|
|
||||||
usePageResponseSuccess,
|
|
||||||
} from '~/utils/response';
|
|
||||||
|
|
||||||
function generateMockDataList(count: number) {
|
|
||||||
const dataList = [];
|
|
||||||
|
|
||||||
for (let i = 0; i < count; i++) {
|
|
||||||
const dataItem = {
|
|
||||||
id: faker.string.uuid(),
|
|
||||||
imageUrl: faker.image.avatar(),
|
|
||||||
imageUrl2: faker.image.avatar(),
|
|
||||||
open: faker.datatype.boolean(),
|
|
||||||
status: faker.helpers.arrayElement(['success', 'error', 'warning']),
|
|
||||||
productName: faker.commerce.productName(),
|
|
||||||
price: faker.commerce.price(),
|
|
||||||
currency: faker.finance.currencyCode(),
|
|
||||||
quantity: faker.number.int({ min: 1, max: 100 }),
|
|
||||||
available: faker.datatype.boolean(),
|
|
||||||
category: faker.commerce.department(),
|
|
||||||
releaseDate: faker.date.past(),
|
|
||||||
rating: faker.number.float({ min: 1, max: 5 }),
|
|
||||||
description: faker.commerce.productDescription(),
|
|
||||||
weight: faker.number.float({ min: 0.1, max: 10 }),
|
|
||||||
color: faker.color.human(),
|
|
||||||
inProduction: faker.datatype.boolean(),
|
|
||||||
tags: Array.from({ length: 3 }, () => faker.commerce.productAdjective()),
|
|
||||||
};
|
|
||||||
|
|
||||||
dataList.push(dataItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
return dataList;
|
|
||||||
}
|
|
||||||
|
|
||||||
const mockData = generateMockDataList(100);
|
|
||||||
|
|
||||||
export default eventHandler(async (event) => {
|
|
||||||
const userinfo = verifyAccessToken(event);
|
|
||||||
if (!userinfo) {
|
|
||||||
return unAuthorizedResponse(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
await sleep(600);
|
|
||||||
|
|
||||||
const { page, pageSize, sortBy, sortOrder } = getQuery(event);
|
|
||||||
// 规范化分页参数,处理 string[]
|
|
||||||
const pageRaw = Array.isArray(page) ? page[0] : page;
|
|
||||||
const pageSizeRaw = Array.isArray(pageSize) ? pageSize[0] : pageSize;
|
|
||||||
const pageNumber = Math.max(
|
|
||||||
1,
|
|
||||||
Number.parseInt(String(pageRaw ?? '1'), 10) || 1,
|
|
||||||
);
|
|
||||||
const pageSizeNumber = Math.min(
|
|
||||||
100,
|
|
||||||
Math.max(1, Number.parseInt(String(pageSizeRaw ?? '10'), 10) || 10),
|
|
||||||
);
|
|
||||||
const listData = structuredClone(mockData);
|
|
||||||
|
|
||||||
// 规范化 query 入参,兼容 string[]
|
|
||||||
const sortKeyRaw = Array.isArray(sortBy) ? sortBy[0] : sortBy;
|
|
||||||
const sortOrderRaw = Array.isArray(sortOrder) ? sortOrder[0] : sortOrder;
|
|
||||||
// 检查 sortBy 是否是 listData 元素的合法属性键
|
|
||||||
if (
|
|
||||||
typeof sortKeyRaw === 'string' &&
|
|
||||||
listData[0] &&
|
|
||||||
Object.prototype.hasOwnProperty.call(listData[0], sortKeyRaw)
|
|
||||||
) {
|
|
||||||
// 定义数组元素的类型
|
|
||||||
type ItemType = (typeof listData)[0];
|
|
||||||
const sortKey = sortKeyRaw as keyof ItemType; // 将 sortBy 断言为合法键
|
|
||||||
const isDesc = sortOrderRaw === 'desc';
|
|
||||||
listData.sort((a, b) => {
|
|
||||||
const aValue = a[sortKey] as unknown;
|
|
||||||
const bValue = b[sortKey] as unknown;
|
|
||||||
|
|
||||||
let result = 0;
|
|
||||||
|
|
||||||
if (typeof aValue === 'number' && typeof bValue === 'number') {
|
|
||||||
result = aValue - bValue;
|
|
||||||
} else if (aValue instanceof Date && bValue instanceof Date) {
|
|
||||||
result = aValue.getTime() - bValue.getTime();
|
|
||||||
} else if (typeof aValue === 'boolean' && typeof bValue === 'boolean') {
|
|
||||||
if (aValue === bValue) {
|
|
||||||
result = 0;
|
|
||||||
} else {
|
|
||||||
result = aValue ? 1 : -1;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
const aStr = String(aValue);
|
|
||||||
const bStr = String(bValue);
|
|
||||||
const aNum = Number(aStr);
|
|
||||||
const bNum = Number(bStr);
|
|
||||||
result =
|
|
||||||
Number.isFinite(aNum) && Number.isFinite(bNum)
|
|
||||||
? aNum - bNum
|
|
||||||
: aStr.localeCompare(bStr, undefined, {
|
|
||||||
numeric: true,
|
|
||||||
sensitivity: 'base',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return isDesc ? -result : result;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return usePageResponseSuccess(
|
|
||||||
String(pageNumber),
|
|
||||||
String(pageSizeNumber),
|
|
||||||
listData,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
import { defineEventHandler } from 'h3';
|
|
||||||
|
|
||||||
export default defineEventHandler(() => 'Test get handler');
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
import { defineEventHandler } from 'h3';
|
|
||||||
|
|
||||||
export default defineEventHandler(() => 'Test post handler');
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
import { eventHandler } from 'h3';
|
|
||||||
import { verifyAccessToken } from '~/utils/jwt-utils';
|
|
||||||
import { unAuthorizedResponse, useResponseSuccess } from '~/utils/response';
|
|
||||||
import { getTimezone } from '~/utils/timezone-utils';
|
|
||||||
|
|
||||||
export default eventHandler((event) => {
|
|
||||||
const userinfo = verifyAccessToken(event);
|
|
||||||
if (!userinfo) {
|
|
||||||
return unAuthorizedResponse(event);
|
|
||||||
}
|
|
||||||
return useResponseSuccess(getTimezone());
|
|
||||||
});
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
import { eventHandler } from 'h3';
|
|
||||||
import { TIME_ZONE_OPTIONS } from '~/utils/mock-data';
|
|
||||||
import { useResponseSuccess } from '~/utils/response';
|
|
||||||
|
|
||||||
export default eventHandler(() => {
|
|
||||||
const data = TIME_ZONE_OPTIONS.map((o) => ({
|
|
||||||
label: `${o.timezone} (GMT${o.offset >= 0 ? `+${o.offset}` : o.offset})`,
|
|
||||||
value: o.timezone,
|
|
||||||
}));
|
|
||||||
return useResponseSuccess(data);
|
|
||||||
});
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
import { eventHandler, readBody } from 'h3';
|
|
||||||
import { verifyAccessToken } from '~/utils/jwt-utils';
|
|
||||||
import { TIME_ZONE_OPTIONS } from '~/utils/mock-data';
|
|
||||||
import { unAuthorizedResponse, useResponseSuccess } from '~/utils/response';
|
|
||||||
import { setTimezone } from '~/utils/timezone-utils';
|
|
||||||
|
|
||||||
export default eventHandler(async (event) => {
|
|
||||||
const userinfo = verifyAccessToken(event);
|
|
||||||
if (!userinfo) {
|
|
||||||
return unAuthorizedResponse(event);
|
|
||||||
}
|
|
||||||
const body = await readBody<{ timezone?: unknown }>(event);
|
|
||||||
const timezone =
|
|
||||||
typeof body?.timezone === 'string' ? body.timezone : undefined;
|
|
||||||
const allowed = TIME_ZONE_OPTIONS.some((o) => o.timezone === timezone);
|
|
||||||
if (!timezone || !allowed) {
|
|
||||||
setResponseStatus(event, 400);
|
|
||||||
return useResponseError('Bad Request', 'Invalid timezone');
|
|
||||||
}
|
|
||||||
setTimezone(timezone);
|
|
||||||
return useResponseSuccess({});
|
|
||||||
});
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
import { eventHandler } from 'h3';
|
|
||||||
import { verifyAccessToken } from '~/utils/jwt-utils';
|
|
||||||
import { unAuthorizedResponse, useResponseSuccess } from '~/utils/response';
|
|
||||||
|
|
||||||
export default eventHandler((event) => {
|
|
||||||
const userinfo = verifyAccessToken(event);
|
|
||||||
if (!userinfo) {
|
|
||||||
return unAuthorizedResponse(event);
|
|
||||||
}
|
|
||||||
return useResponseSuccess({
|
|
||||||
url: 'https://unpkg.com/@vbenjs/static-source@0.1.7/source/logo-v1.webp',
|
|
||||||
});
|
|
||||||
// return useResponseError("test")
|
|
||||||
});
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
import { eventHandler } from 'h3';
|
|
||||||
import { verifyAccessToken } from '~/utils/jwt-utils';
|
|
||||||
import { unAuthorizedResponse, useResponseSuccess } from '~/utils/response';
|
|
||||||
|
|
||||||
export default eventHandler((event) => {
|
|
||||||
const userinfo = verifyAccessToken(event);
|
|
||||||
if (!userinfo) {
|
|
||||||
return unAuthorizedResponse(event);
|
|
||||||
}
|
|
||||||
return useResponseSuccess(userinfo);
|
|
||||||
});
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
import type { NitroErrorHandler } from 'nitropack';
|
|
||||||
|
|
||||||
const errorHandler: NitroErrorHandler = function (error, event) {
|
|
||||||
event.node.res.end(`[Error Handler] ${error.stack}`);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default errorHandler;
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
import { defineEventHandler } from 'h3';
|
|
||||||
import { forbiddenResponse, sleep } from '~/utils/response';
|
|
||||||
|
|
||||||
export default defineEventHandler(async (event) => {
|
|
||||||
event.node.res.setHeader(
|
|
||||||
'Access-Control-Allow-Origin',
|
|
||||||
event.headers.get('Origin') ?? '*',
|
|
||||||
);
|
|
||||||
if (event.method === 'OPTIONS') {
|
|
||||||
event.node.res.statusCode = 204;
|
|
||||||
event.node.res.statusMessage = 'No Content.';
|
|
||||||
return 'OK';
|
|
||||||
} else if (
|
|
||||||
['DELETE', 'PATCH', 'POST', 'PUT'].includes(event.method) &&
|
|
||||||
event.path.startsWith('/api/system/')
|
|
||||||
) {
|
|
||||||
await sleep(Math.floor(Math.random() * 2000));
|
|
||||||
return forbiddenResponse(event, '演示环境,禁止修改');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
import errorHandler from './error';
|
|
||||||
|
|
||||||
process.env.COMPATIBILITY_DATE = new Date().toISOString();
|
|
||||||
export default defineNitroConfig({
|
|
||||||
devErrorHandler: errorHandler,
|
|
||||||
errorHandler: '~/error',
|
|
||||||
routeRules: {
|
|
||||||
'/api/**': {
|
|
||||||
cors: true,
|
|
||||||
headers: {
|
|
||||||
'Access-Control-Allow-Credentials': 'true',
|
|
||||||
'Access-Control-Allow-Headers':
|
|
||||||
'Accept, Authorization, Content-Length, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-CSRF-TOKEN, X-Requested-With',
|
|
||||||
'Access-Control-Allow-Methods': 'GET,HEAD,PUT,PATCH,POST,DELETE',
|
|
||||||
'Access-Control-Allow-Origin': '*',
|
|
||||||
'Access-Control-Expose-Headers': '*',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "@vben/backend-mock",
|
|
||||||
"version": "0.0.1",
|
|
||||||
"description": "",
|
|
||||||
"private": true,
|
|
||||||
"license": "MIT",
|
|
||||||
"author": "",
|
|
||||||
"scripts": {
|
|
||||||
"build": "nitro build",
|
|
||||||
"start": "nitro dev"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"@faker-js/faker": "catalog:",
|
|
||||||
"jsonwebtoken": "catalog:",
|
|
||||||
"nitropack": "catalog:"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"@types/jsonwebtoken": "catalog:",
|
|
||||||
"h3": "catalog:"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
import { defineEventHandler } from 'h3';
|
|
||||||
|
|
||||||
export default defineEventHandler(() => {
|
|
||||||
return `
|
|
||||||
<h1>Hello Vben Admin</h1>
|
|
||||||
<h2>Mock service is starting</h2>
|
|
||||||
<ul>
|
|
||||||
<li><a href="/api/user">/api/user/info</a></li>
|
|
||||||
<li><a href="/api/menu">/api/menu/all</a></li>
|
|
||||||
<li><a href="/api/auth/codes">/api/auth/codes</a></li>
|
|
||||||
<li><a href="/api/auth/login">/api/auth/login</a></li>
|
|
||||||
<li><a href="/api/upload">/api/upload</a></li>
|
|
||||||
</ul>
|
|
||||||
`;
|
|
||||||
});
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": "./tsconfig.json",
|
|
||||||
"exclude": ["node_modules", "test", "dist", "**/*spec.ts"]
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": "./.nitro/types/tsconfig.json"
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
import type { EventHandlerRequest, H3Event } from 'h3';
|
|
||||||
|
|
||||||
import { deleteCookie, getCookie, setCookie } from 'h3';
|
|
||||||
|
|
||||||
export function clearRefreshTokenCookie(event: H3Event<EventHandlerRequest>) {
|
|
||||||
deleteCookie(event, 'jwt', {
|
|
||||||
httpOnly: true,
|
|
||||||
sameSite: 'none',
|
|
||||||
secure: true,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function setRefreshTokenCookie(
|
|
||||||
event: H3Event<EventHandlerRequest>,
|
|
||||||
refreshToken: string,
|
|
||||||
) {
|
|
||||||
setCookie(event, 'jwt', refreshToken, {
|
|
||||||
httpOnly: true,
|
|
||||||
maxAge: 24 * 60 * 60, // unit: seconds
|
|
||||||
sameSite: 'none',
|
|
||||||
secure: true,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getRefreshTokenFromCookie(event: H3Event<EventHandlerRequest>) {
|
|
||||||
const refreshToken = getCookie(event, 'jwt');
|
|
||||||
return refreshToken;
|
|
||||||
}
|
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
import type { EventHandlerRequest, H3Event } from 'h3';
|
|
||||||
|
|
||||||
import type { UserInfo } from './mock-data';
|
|
||||||
|
|
||||||
import { getHeader } from 'h3';
|
|
||||||
import jwt from 'jsonwebtoken';
|
|
||||||
|
|
||||||
import { MOCK_USERS } from './mock-data';
|
|
||||||
|
|
||||||
// TODO: Replace with your own secret key
|
|
||||||
const ACCESS_TOKEN_SECRET = 'access_token_secret';
|
|
||||||
const REFRESH_TOKEN_SECRET = 'refresh_token_secret';
|
|
||||||
|
|
||||||
export interface UserPayload extends UserInfo {
|
|
||||||
iat: number;
|
|
||||||
exp: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function generateAccessToken(user: UserInfo) {
|
|
||||||
return jwt.sign(user, ACCESS_TOKEN_SECRET, { expiresIn: '7d' });
|
|
||||||
}
|
|
||||||
|
|
||||||
export function generateRefreshToken(user: UserInfo) {
|
|
||||||
return jwt.sign(user, REFRESH_TOKEN_SECRET, {
|
|
||||||
expiresIn: '30d',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function verifyAccessToken(
|
|
||||||
event: H3Event<EventHandlerRequest>,
|
|
||||||
): null | Omit<UserInfo, 'password'> {
|
|
||||||
const authHeader = getHeader(event, 'Authorization');
|
|
||||||
if (!authHeader?.startsWith('Bearer')) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const tokenParts = authHeader.split(' ');
|
|
||||||
if (tokenParts.length !== 2) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
const token = tokenParts[1] as string;
|
|
||||||
try {
|
|
||||||
const decoded = jwt.verify(
|
|
||||||
token,
|
|
||||||
ACCESS_TOKEN_SECRET,
|
|
||||||
) as unknown as UserPayload;
|
|
||||||
|
|
||||||
const username = decoded.username;
|
|
||||||
const user = MOCK_USERS.find((item) => item.username === username);
|
|
||||||
if (!user) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
const { password: _pwd, ...userinfo } = user;
|
|
||||||
return userinfo;
|
|
||||||
} catch {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function verifyRefreshToken(
|
|
||||||
token: string,
|
|
||||||
): null | Omit<UserInfo, 'password'> {
|
|
||||||
try {
|
|
||||||
const decoded = jwt.verify(token, REFRESH_TOKEN_SECRET) as UserPayload;
|
|
||||||
const username = decoded.username;
|
|
||||||
const user = MOCK_USERS.find(
|
|
||||||
(item) => item.username === username,
|
|
||||||
) as UserInfo;
|
|
||||||
if (!user) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
const { password: _pwd, ...userinfo } = user;
|
|
||||||
return userinfo;
|
|
||||||
} catch {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,421 +0,0 @@
|
|||||||
export interface UserInfo {
|
|
||||||
id: number;
|
|
||||||
password: string;
|
|
||||||
realName: string;
|
|
||||||
roles: string[];
|
|
||||||
username: string;
|
|
||||||
homePath?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface TimezoneOption {
|
|
||||||
offset: number;
|
|
||||||
timezone: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const MOCK_USERS: UserInfo[] = [
|
|
||||||
{
|
|
||||||
id: 0,
|
|
||||||
password: '123456',
|
|
||||||
realName: 'Vben',
|
|
||||||
roles: ['super'],
|
|
||||||
username: 'vben',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 1,
|
|
||||||
password: '123456',
|
|
||||||
realName: 'Admin',
|
|
||||||
roles: ['admin'],
|
|
||||||
username: 'admin',
|
|
||||||
homePath: '/workspace',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 2,
|
|
||||||
password: '123456',
|
|
||||||
realName: 'Jack',
|
|
||||||
roles: ['user'],
|
|
||||||
username: 'jack',
|
|
||||||
homePath: '/analytics',
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
export const MOCK_CODES = [
|
|
||||||
// super
|
|
||||||
{
|
|
||||||
codes: ['AC_100100', 'AC_100110', 'AC_100120', 'AC_100010'],
|
|
||||||
username: 'vben',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
// admin
|
|
||||||
codes: ['AC_100010', 'AC_100020', 'AC_100030'],
|
|
||||||
username: 'admin',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
// user
|
|
||||||
codes: ['AC_1000001', 'AC_1000002'],
|
|
||||||
username: 'jack',
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
const dashboardMenus = [
|
|
||||||
{
|
|
||||||
meta: {
|
|
||||||
order: -1,
|
|
||||||
title: 'page.dashboard.title',
|
|
||||||
},
|
|
||||||
name: 'Dashboard',
|
|
||||||
path: '/dashboard',
|
|
||||||
redirect: '/analytics',
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
name: 'Analytics',
|
|
||||||
path: '/analytics',
|
|
||||||
component: '/dashboard/analytics/index',
|
|
||||||
meta: {
|
|
||||||
affixTab: true,
|
|
||||||
title: 'page.dashboard.analytics',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Workspace',
|
|
||||||
path: '/workspace',
|
|
||||||
component: '/dashboard/workspace/index',
|
|
||||||
meta: {
|
|
||||||
title: 'page.dashboard.workspace',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
const createDemosMenus = (role: 'admin' | 'super' | 'user') => {
|
|
||||||
const roleWithMenus = {
|
|
||||||
admin: {
|
|
||||||
component: '/demos/access/admin-visible',
|
|
||||||
meta: {
|
|
||||||
icon: 'mdi:button-cursor',
|
|
||||||
title: 'demos.access.adminVisible',
|
|
||||||
},
|
|
||||||
name: 'AccessAdminVisibleDemo',
|
|
||||||
path: '/demos/access/admin-visible',
|
|
||||||
},
|
|
||||||
super: {
|
|
||||||
component: '/demos/access/super-visible',
|
|
||||||
meta: {
|
|
||||||
icon: 'mdi:button-cursor',
|
|
||||||
title: 'demos.access.superVisible',
|
|
||||||
},
|
|
||||||
name: 'AccessSuperVisibleDemo',
|
|
||||||
path: '/demos/access/super-visible',
|
|
||||||
},
|
|
||||||
user: {
|
|
||||||
component: '/demos/access/user-visible',
|
|
||||||
meta: {
|
|
||||||
icon: 'mdi:button-cursor',
|
|
||||||
title: 'demos.access.userVisible',
|
|
||||||
},
|
|
||||||
name: 'AccessUserVisibleDemo',
|
|
||||||
path: '/demos/access/user-visible',
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
return [
|
|
||||||
{
|
|
||||||
meta: {
|
|
||||||
icon: 'ic:baseline-view-in-ar',
|
|
||||||
keepAlive: true,
|
|
||||||
order: 1000,
|
|
||||||
title: 'demos.title',
|
|
||||||
},
|
|
||||||
name: 'Demos',
|
|
||||||
path: '/demos',
|
|
||||||
redirect: '/demos/access',
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
name: 'AccessDemos',
|
|
||||||
path: '/demosaccess',
|
|
||||||
meta: {
|
|
||||||
icon: 'mdi:cloud-key-outline',
|
|
||||||
title: 'demos.access.backendPermissions',
|
|
||||||
},
|
|
||||||
redirect: '/demos/access/page-control',
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
name: 'AccessPageControlDemo',
|
|
||||||
path: '/demos/access/page-control',
|
|
||||||
component: '/demos/access/index',
|
|
||||||
meta: {
|
|
||||||
icon: 'mdi:page-previous-outline',
|
|
||||||
title: 'demos.access.pageAccess',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'AccessButtonControlDemo',
|
|
||||||
path: '/demos/access/button-control',
|
|
||||||
component: '/demos/access/button-control',
|
|
||||||
meta: {
|
|
||||||
icon: 'mdi:button-cursor',
|
|
||||||
title: 'demos.access.buttonControl',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'AccessMenuVisible403Demo',
|
|
||||||
path: '/demos/access/menu-visible-403',
|
|
||||||
component: '/demos/access/menu-visible-403',
|
|
||||||
meta: {
|
|
||||||
authority: ['no-body'],
|
|
||||||
icon: 'mdi:button-cursor',
|
|
||||||
menuVisibleWithForbidden: true,
|
|
||||||
title: 'demos.access.menuVisible403',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
roleWithMenus[role],
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
export const MOCK_MENUS = [
|
|
||||||
{
|
|
||||||
menus: [...dashboardMenus, ...createDemosMenus('super')],
|
|
||||||
username: 'vben',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
menus: [...dashboardMenus, ...createDemosMenus('admin')],
|
|
||||||
username: 'admin',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
menus: [...dashboardMenus, ...createDemosMenus('user')],
|
|
||||||
username: 'jack',
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
export const MOCK_MENU_LIST = [
|
|
||||||
{
|
|
||||||
id: 1,
|
|
||||||
name: 'Workspace',
|
|
||||||
status: 1,
|
|
||||||
type: 'menu',
|
|
||||||
icon: 'mdi:dashboard',
|
|
||||||
path: '/workspace',
|
|
||||||
component: '/dashboard/workspace/index',
|
|
||||||
meta: {
|
|
||||||
icon: 'carbon:workspace',
|
|
||||||
title: 'page.dashboard.workspace',
|
|
||||||
affixTab: true,
|
|
||||||
order: 0,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 2,
|
|
||||||
meta: {
|
|
||||||
icon: 'carbon:settings',
|
|
||||||
order: 9997,
|
|
||||||
title: 'system.title',
|
|
||||||
badge: 'new',
|
|
||||||
badgeType: 'normal',
|
|
||||||
badgeVariants: 'primary',
|
|
||||||
},
|
|
||||||
status: 1,
|
|
||||||
type: 'catalog',
|
|
||||||
name: 'System',
|
|
||||||
path: '/system',
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
id: 201,
|
|
||||||
pid: 2,
|
|
||||||
path: '/system/menu',
|
|
||||||
name: 'SystemMenu',
|
|
||||||
authCode: 'System:Menu:List',
|
|
||||||
status: 1,
|
|
||||||
type: 'menu',
|
|
||||||
meta: {
|
|
||||||
icon: 'carbon:menu',
|
|
||||||
title: 'system.menu.title',
|
|
||||||
},
|
|
||||||
component: '/system/menu/list',
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
id: 20_101,
|
|
||||||
pid: 201,
|
|
||||||
name: 'SystemMenuCreate',
|
|
||||||
status: 1,
|
|
||||||
type: 'button',
|
|
||||||
authCode: 'System:Menu:Create',
|
|
||||||
meta: { title: 'common.create' },
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 20_102,
|
|
||||||
pid: 201,
|
|
||||||
name: 'SystemMenuEdit',
|
|
||||||
status: 1,
|
|
||||||
type: 'button',
|
|
||||||
authCode: 'System:Menu:Edit',
|
|
||||||
meta: { title: 'common.edit' },
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 20_103,
|
|
||||||
pid: 201,
|
|
||||||
name: 'SystemMenuDelete',
|
|
||||||
status: 1,
|
|
||||||
type: 'button',
|
|
||||||
authCode: 'System:Menu:Delete',
|
|
||||||
meta: { title: 'common.delete' },
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 202,
|
|
||||||
pid: 2,
|
|
||||||
path: '/system/dept',
|
|
||||||
name: 'SystemDept',
|
|
||||||
status: 1,
|
|
||||||
type: 'menu',
|
|
||||||
authCode: 'System:Dept:List',
|
|
||||||
meta: {
|
|
||||||
icon: 'carbon:container-services',
|
|
||||||
title: 'system.dept.title',
|
|
||||||
},
|
|
||||||
component: '/system/dept/list',
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
id: 20_401,
|
|
||||||
pid: 202,
|
|
||||||
name: 'SystemDeptCreate',
|
|
||||||
status: 1,
|
|
||||||
type: 'button',
|
|
||||||
authCode: 'System:Dept:Create',
|
|
||||||
meta: { title: 'common.create' },
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 20_402,
|
|
||||||
pid: 202,
|
|
||||||
name: 'SystemDeptEdit',
|
|
||||||
status: 1,
|
|
||||||
type: 'button',
|
|
||||||
authCode: 'System:Dept:Edit',
|
|
||||||
meta: { title: 'common.edit' },
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 20_403,
|
|
||||||
pid: 202,
|
|
||||||
name: 'SystemDeptDelete',
|
|
||||||
status: 1,
|
|
||||||
type: 'button',
|
|
||||||
authCode: 'System:Dept:Delete',
|
|
||||||
meta: { title: 'common.delete' },
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 9,
|
|
||||||
meta: {
|
|
||||||
badgeType: 'dot',
|
|
||||||
order: 9998,
|
|
||||||
title: 'demos.vben.title',
|
|
||||||
icon: 'carbon:data-center',
|
|
||||||
},
|
|
||||||
name: 'Project',
|
|
||||||
path: '/vben-admin',
|
|
||||||
type: 'catalog',
|
|
||||||
status: 1,
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
id: 901,
|
|
||||||
pid: 9,
|
|
||||||
name: 'VbenDocument',
|
|
||||||
path: '/vben-admin/document',
|
|
||||||
component: 'IFrameView',
|
|
||||||
type: 'embedded',
|
|
||||||
status: 1,
|
|
||||||
meta: {
|
|
||||||
icon: 'carbon:book',
|
|
||||||
iframeSrc: 'https://doc.vben.pro',
|
|
||||||
title: 'demos.vben.document',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 902,
|
|
||||||
pid: 9,
|
|
||||||
name: 'VbenGithub',
|
|
||||||
path: '/vben-admin/github',
|
|
||||||
component: 'IFrameView',
|
|
||||||
type: 'link',
|
|
||||||
status: 1,
|
|
||||||
meta: {
|
|
||||||
icon: 'carbon:logo-github',
|
|
||||||
link: 'https://github.com/vbenjs/vue-vben-admin',
|
|
||||||
title: 'Github',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 903,
|
|
||||||
pid: 9,
|
|
||||||
name: 'VbenAntdv',
|
|
||||||
path: '/vben-admin/antdv',
|
|
||||||
component: 'IFrameView',
|
|
||||||
type: 'link',
|
|
||||||
status: 0,
|
|
||||||
meta: {
|
|
||||||
icon: 'carbon:hexagon-vertical-solid',
|
|
||||||
badgeType: 'dot',
|
|
||||||
link: 'https://ant.vben.pro',
|
|
||||||
title: 'demos.vben.antdv',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 10,
|
|
||||||
component: '_core/about/index',
|
|
||||||
type: 'menu',
|
|
||||||
status: 1,
|
|
||||||
meta: {
|
|
||||||
icon: 'lucide:copyright',
|
|
||||||
order: 9999,
|
|
||||||
title: 'demos.vben.about',
|
|
||||||
},
|
|
||||||
name: 'About',
|
|
||||||
path: '/about',
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
export function getMenuIds(menus: any[]) {
|
|
||||||
const ids: number[] = [];
|
|
||||||
menus.forEach((item) => {
|
|
||||||
ids.push(item.id);
|
|
||||||
if (item.children && item.children.length > 0) {
|
|
||||||
ids.push(...getMenuIds(item.children));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return ids;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 时区选项
|
|
||||||
*/
|
|
||||||
export const TIME_ZONE_OPTIONS: TimezoneOption[] = [
|
|
||||||
{
|
|
||||||
offset: -5,
|
|
||||||
timezone: 'America/New_York',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
offset: 0,
|
|
||||||
timezone: 'Europe/London',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
offset: 8,
|
|
||||||
timezone: 'Asia/Shanghai',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
offset: 9,
|
|
||||||
timezone: 'Asia/Tokyo',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
offset: 9,
|
|
||||||
timezone: 'Asia/Seoul',
|
|
||||||
},
|
|
||||||
];
|
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
import type { EventHandlerRequest, H3Event } from 'h3';
|
|
||||||
|
|
||||||
import { setResponseStatus } from 'h3';
|
|
||||||
|
|
||||||
export function useResponseSuccess<T = any>(data: T) {
|
|
||||||
return {
|
|
||||||
code: 0,
|
|
||||||
data,
|
|
||||||
error: null,
|
|
||||||
message: 'ok',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function usePageResponseSuccess<T = any>(
|
|
||||||
page: number | string,
|
|
||||||
pageSize: number | string,
|
|
||||||
list: T[],
|
|
||||||
{ message = 'ok' } = {},
|
|
||||||
) {
|
|
||||||
const pageData = pagination(
|
|
||||||
Number.parseInt(`${page}`),
|
|
||||||
Number.parseInt(`${pageSize}`),
|
|
||||||
list,
|
|
||||||
);
|
|
||||||
|
|
||||||
return {
|
|
||||||
...useResponseSuccess({
|
|
||||||
items: pageData,
|
|
||||||
total: list.length,
|
|
||||||
}),
|
|
||||||
message,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function useResponseError(message: string, error: any = null) {
|
|
||||||
return {
|
|
||||||
code: -1,
|
|
||||||
data: null,
|
|
||||||
error,
|
|
||||||
message,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function forbiddenResponse(
|
|
||||||
event: H3Event<EventHandlerRequest>,
|
|
||||||
message = 'Forbidden Exception',
|
|
||||||
) {
|
|
||||||
setResponseStatus(event, 403);
|
|
||||||
return useResponseError(message, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function unAuthorizedResponse(event: H3Event<EventHandlerRequest>) {
|
|
||||||
setResponseStatus(event, 401);
|
|
||||||
return useResponseError('Unauthorized Exception', 'Unauthorized Exception');
|
|
||||||
}
|
|
||||||
|
|
||||||
export function sleep(ms: number) {
|
|
||||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
||||||
}
|
|
||||||
|
|
||||||
export function pagination<T = any>(
|
|
||||||
pageNo: number,
|
|
||||||
pageSize: number,
|
|
||||||
array: T[],
|
|
||||||
): T[] {
|
|
||||||
const offset = (pageNo - 1) * Number(pageSize);
|
|
||||||
return offset + Number(pageSize) >= array.length
|
|
||||||
? array.slice(offset)
|
|
||||||
: array.slice(offset, offset + Number(pageSize));
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
let mockTimeZone: null | string = null;
|
|
||||||
|
|
||||||
export const setTimezone = (timeZone: string) => {
|
|
||||||
mockTimeZone = timeZone;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getTimezone = () => {
|
|
||||||
return mockTimeZone;
|
|
||||||
};
|
|
||||||
@@ -139,7 +139,7 @@ const customConfig: Linter.Config[] = [
|
|||||||
},
|
},
|
||||||
// 后端模拟代码,不需要太多规则
|
// 后端模拟代码,不需要太多规则
|
||||||
{
|
{
|
||||||
files: ['apps/backend-mock/**/**', 'docs/**/**'],
|
files: ['docs/**/**'],
|
||||||
rules: {
|
rules: {
|
||||||
'@typescript-eslint/no-extraneous-class': 'off',
|
'@typescript-eslint/no-extraneous-class': 'off',
|
||||||
'n/no-extraneous-import': 'off',
|
'n/no-extraneous-import': 'off',
|
||||||
|
|||||||
@@ -33,7 +33,6 @@
|
|||||||
"build:ele": "pnpm run build --filter=@vben/web-ele",
|
"build:ele": "pnpm run build --filter=@vben/web-ele",
|
||||||
"build:naive": "pnpm run build --filter=@vben/web-naive",
|
"build:naive": "pnpm run build --filter=@vben/web-naive",
|
||||||
"build:tdesign": "pnpm run build --filter=@vben/web-tdesign",
|
"build:tdesign": "pnpm run build --filter=@vben/web-tdesign",
|
||||||
"build:play": "pnpm run build --filter=@vben/playground",
|
|
||||||
"changeset": "pnpm exec changeset",
|
"changeset": "pnpm exec changeset",
|
||||||
"check": "pnpm run check:circular && pnpm run check:dep && pnpm run check:type && pnpm check:cspell",
|
"check": "pnpm run check:circular && pnpm run check:dep && pnpm run check:type && pnpm check:cspell",
|
||||||
"check:circular": "vsh check-circular",
|
"check:circular": "vsh check-circular",
|
||||||
@@ -48,7 +47,6 @@
|
|||||||
"dev:ele": "pnpm -F @vben/web-ele run dev",
|
"dev:ele": "pnpm -F @vben/web-ele run dev",
|
||||||
"dev:naive": "pnpm -F @vben/web-naive run dev",
|
"dev:naive": "pnpm -F @vben/web-naive run dev",
|
||||||
"dev:tdesign": "pnpm -F @vben/web-tdesign run dev",
|
"dev:tdesign": "pnpm -F @vben/web-tdesign run dev",
|
||||||
"dev:play": "pnpm -F @vben/playground run dev",
|
|
||||||
"format": "vsh lint --format",
|
"format": "vsh lint --format",
|
||||||
"lint": "vsh lint",
|
"lint": "vsh lint",
|
||||||
"postinstall": "pnpm -r run stub --if-present",
|
"postinstall": "pnpm -r run stub --if-present",
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
# 应用标题
|
|
||||||
VITE_APP_TITLE=Vben Admin
|
|
||||||
|
|
||||||
# 应用命名空间,用于缓存、store等功能的前缀,确保隔离
|
|
||||||
VITE_APP_NAMESPACE=vben-web-play
|
|
||||||
|
|
||||||
# 对store进行加密的密钥,在将store持久化到localStorage时会使用该密钥进行加密
|
|
||||||
VITE_APP_STORE_SECURE_KEY=please-replace-me-with-your-own-key
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
# public path
|
|
||||||
VITE_BASE=/
|
|
||||||
|
|
||||||
# Basic interface address SPA
|
|
||||||
VITE_GLOB_API_URL=/api
|
|
||||||
|
|
||||||
VITE_VISUALIZER=true
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
# 端口号
|
|
||||||
VITE_PORT=5555
|
|
||||||
|
|
||||||
VITE_BASE=/
|
|
||||||
|
|
||||||
# 接口地址
|
|
||||||
VITE_GLOB_API_URL=/api
|
|
||||||
|
|
||||||
# 是否开启 Nitro Mock服务,true 为开启,false 为关闭
|
|
||||||
VITE_NITRO_MOCK=true
|
|
||||||
|
|
||||||
# 是否打开 devtools,true 为打开,false 为关闭
|
|
||||||
VITE_DEVTOOLS=false
|
|
||||||
|
|
||||||
# 是否注入全局loading
|
|
||||||
VITE_INJECT_APP_LOADING=true
|
|
||||||
|
|
||||||
# 钉钉登录配置
|
|
||||||
VITE_GLOB_AUTH_DINGDING_CLIENT_ID=应用的clientId
|
|
||||||
VITE_GLOB_AUTH_DINGDING_CORP_ID=应用的corpId
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
VITE_BASE=/
|
|
||||||
|
|
||||||
# 接口地址
|
|
||||||
VITE_GLOB_API_URL=https://mock-napi.vben.pro/api
|
|
||||||
|
|
||||||
# 是否开启压缩,可以设置为 none, brotli, gzip
|
|
||||||
VITE_COMPRESS=none
|
|
||||||
|
|
||||||
# 是否开启 PWA
|
|
||||||
VITE_PWA=false
|
|
||||||
|
|
||||||
# vue-router 的模式
|
|
||||||
VITE_ROUTER_HISTORY=hash
|
|
||||||
|
|
||||||
# 是否注入全局loading
|
|
||||||
VITE_INJECT_APP_LOADING=true
|
|
||||||
|
|
||||||
# 打包后是否生成dist.zip
|
|
||||||
VITE_ARCHIVER=true
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
import { expect, test } from '@playwright/test';
|
|
||||||
|
|
||||||
import { authLogin } from './common/auth';
|
|
||||||
|
|
||||||
test.beforeEach(async ({ page }) => {
|
|
||||||
await page.goto('/');
|
|
||||||
});
|
|
||||||
|
|
||||||
test.describe('Auth Login Page Tests', () => {
|
|
||||||
test('check title and page elements', async ({ page }) => {
|
|
||||||
// 获取页面标题并断言标题包含 'Vben Admin'
|
|
||||||
const title = await page.title();
|
|
||||||
expect(title).toContain('Vben Admin');
|
|
||||||
});
|
|
||||||
|
|
||||||
// 测试用例: 成功登录
|
|
||||||
test('should successfully login with valid credentials', async ({ page }) => {
|
|
||||||
await authLogin(page);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
import type { Page } from '@playwright/test';
|
|
||||||
|
|
||||||
import { expect } from '@playwright/test';
|
|
||||||
|
|
||||||
export async function authLogin(page: Page) {
|
|
||||||
// 确保登录表单正常
|
|
||||||
const usernameInput = await page.locator(`input[name='username']`);
|
|
||||||
await expect(usernameInput).toBeVisible();
|
|
||||||
|
|
||||||
const passwordInput = await page.locator(`input[name='password']`);
|
|
||||||
await expect(passwordInput).toBeVisible();
|
|
||||||
|
|
||||||
const sliderCaptcha = await page.locator(`div[name='captcha']`);
|
|
||||||
const sliderCaptchaAction = await page.locator(`div[name='captcha-action']`);
|
|
||||||
await expect(sliderCaptcha).toBeVisible();
|
|
||||||
await expect(sliderCaptchaAction).toBeVisible();
|
|
||||||
|
|
||||||
// 拖动验证码滑块
|
|
||||||
// 获取拖动按钮的位置
|
|
||||||
const sliderCaptchaBox = await sliderCaptcha.boundingBox();
|
|
||||||
if (!sliderCaptchaBox) throw new Error('滑块未找到');
|
|
||||||
|
|
||||||
const actionBoundingBox = await sliderCaptchaAction.boundingBox();
|
|
||||||
if (!actionBoundingBox) throw new Error('要拖动的按钮未找到');
|
|
||||||
|
|
||||||
// 计算起始位置和目标位置
|
|
||||||
const startX = actionBoundingBox.x + actionBoundingBox.width / 2; // div 中心的 x 坐标
|
|
||||||
const startY = actionBoundingBox.y + actionBoundingBox.height / 2; // div 中心的 y 坐标
|
|
||||||
|
|
||||||
const targetX = startX + sliderCaptchaBox.width + actionBoundingBox.width; // 向右拖动容器的宽度
|
|
||||||
const targetY = startY; // y 坐标保持不变
|
|
||||||
|
|
||||||
// 模拟鼠标拖动
|
|
||||||
await page.mouse.move(startX, startY); // 移动到 action 的中心
|
|
||||||
await page.mouse.down(); // 按下鼠标
|
|
||||||
await page.mouse.move(targetX, targetY, { steps: 20 }); // 拖动到目标位置
|
|
||||||
await page.mouse.up(); // 松开鼠标
|
|
||||||
|
|
||||||
// 在拖动后进行断言,检查action是否在预期位置,
|
|
||||||
const newActionBoundingBox = await sliderCaptchaAction.boundingBox();
|
|
||||||
expect(newActionBoundingBox?.x).toBeGreaterThan(actionBoundingBox.x);
|
|
||||||
|
|
||||||
// 到这里已经校验成功,点击进行登录
|
|
||||||
await page.waitForTimeout(300);
|
|
||||||
await page.getByRole('button', { name: 'login' }).click();
|
|
||||||
}
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
<!doctype html>
|
|
||||||
<html lang="zh">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8" />
|
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
|
|
||||||
<meta name="renderer" content="webkit" />
|
|
||||||
<meta name="description" content="A Modern Back-end Management System" />
|
|
||||||
<meta name="keywords" content="Vben Admin Vue3 Vite" />
|
|
||||||
<meta name="author" content="Vben" />
|
|
||||||
<meta
|
|
||||||
name="viewport"
|
|
||||||
content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=0"
|
|
||||||
/>
|
|
||||||
<!-- 由 vite 注入 VITE_APP_TITLE 变量,在 .env 文件内配置 -->
|
|
||||||
<title><%= VITE_APP_TITLE %></title>
|
|
||||||
<link rel="icon" href="/favicon.ico" />
|
|
||||||
<script>
|
|
||||||
// 生产环境下注入百度统计
|
|
||||||
if (window._VBEN_ADMIN_PRO_APP_CONF_) {
|
|
||||||
var _hmt = _hmt || [];
|
|
||||||
(function () {
|
|
||||||
var hm = document.createElement('script');
|
|
||||||
hm.src =
|
|
||||||
'https://hm.baidu.com/hm.js?d20a01273820422b6aa2ee41b6c9414d';
|
|
||||||
var s = document.getElementsByTagName('script')[0];
|
|
||||||
s.parentNode.insertBefore(hm, s);
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div id="app"></div>
|
|
||||||
<script type="module" src="/src/main.ts"></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "@vben/playground",
|
|
||||||
"version": "5.5.9",
|
|
||||||
"homepage": "https://vben.pro",
|
|
||||||
"bugs": "https://github.com/vbenjs/vue-vben-admin/issues",
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "git+https://github.com/vbenjs/vue-vben-admin.git",
|
|
||||||
"directory": "playground"
|
|
||||||
},
|
|
||||||
"license": "MIT",
|
|
||||||
"author": {
|
|
||||||
"name": "vben",
|
|
||||||
"email": "ann.vben@gmail.com",
|
|
||||||
"url": "https://github.com/anncwb"
|
|
||||||
},
|
|
||||||
"type": "module",
|
|
||||||
"scripts": {
|
|
||||||
"build": "pnpm vite build --mode production",
|
|
||||||
"build:analyze": "pnpm vite build --mode analyze",
|
|
||||||
"dev": "pnpm vite --mode development",
|
|
||||||
"preview": "vite preview",
|
|
||||||
"typecheck": "vue-tsc --noEmit --skipLibCheck",
|
|
||||||
"test:e2e": "playwright test",
|
|
||||||
"test:e2e-ui": "playwright test --ui",
|
|
||||||
"test:e2e-codegen": "playwright codegen"
|
|
||||||
},
|
|
||||||
"imports": {
|
|
||||||
"#/*": "./src/*"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"@tanstack/vue-query": "catalog:",
|
|
||||||
"@vben-core/menu-ui": "workspace:*",
|
|
||||||
"@vben/access": "workspace:*",
|
|
||||||
"@vben/common-ui": "workspace:*",
|
|
||||||
"@vben/constants": "workspace:*",
|
|
||||||
"@vben/hooks": "workspace:*",
|
|
||||||
"@vben/icons": "workspace:*",
|
|
||||||
"@vben/layouts": "workspace:*",
|
|
||||||
"@vben/locales": "workspace:*",
|
|
||||||
"@vben/plugins": "workspace:*",
|
|
||||||
"@vben/preferences": "workspace:*",
|
|
||||||
"@vben/request": "workspace:*",
|
|
||||||
"@vben/stores": "workspace:*",
|
|
||||||
"@vben/styles": "workspace:*",
|
|
||||||
"@vben/types": "workspace:*",
|
|
||||||
"@vben/utils": "workspace:*",
|
|
||||||
"@vueuse/core": "catalog:",
|
|
||||||
"ant-design-vue": "catalog:",
|
|
||||||
"dayjs": "catalog:",
|
|
||||||
"json-bigint": "catalog:",
|
|
||||||
"pinia": "catalog:",
|
|
||||||
"vue": "catalog:",
|
|
||||||
"vue-router": "catalog:"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"@types/json-bigint": "catalog:"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,108 +0,0 @@
|
|||||||
import type { PlaywrightTestConfig } from '@playwright/test';
|
|
||||||
|
|
||||||
import { devices } from '@playwright/test';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Read environment variables from file.
|
|
||||||
* https://github.com/motdotla/dotenv
|
|
||||||
*/
|
|
||||||
// require('dotenv').config();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* See https://playwright.dev/docs/test-configuration.
|
|
||||||
*/
|
|
||||||
const config: PlaywrightTestConfig = {
|
|
||||||
expect: {
|
|
||||||
/**
|
|
||||||
* Maximum time expect() should wait for the condition to be met.
|
|
||||||
* For example in `await expect(locator).toHaveText();`
|
|
||||||
*/
|
|
||||||
timeout: 5000,
|
|
||||||
},
|
|
||||||
/* Fail the build on CI if you accidentally left test.only in the source code. */
|
|
||||||
forbidOnly: !!process.env.CI,
|
|
||||||
/* Folder for test artifacts such as screenshots, videos, traces, etc. */
|
|
||||||
outputDir: 'node_modules/.e2e/test-results/',
|
|
||||||
/* Configure projects for major browsers */
|
|
||||||
projects: [
|
|
||||||
{
|
|
||||||
name: 'chromium',
|
|
||||||
use: {
|
|
||||||
...devices['Desktop Chrome'],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
// {
|
|
||||||
// name: 'firefox',
|
|
||||||
// use: {
|
|
||||||
// ...devices['Desktop Firefox'],
|
|
||||||
// },
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// name: 'webkit',
|
|
||||||
// use: {
|
|
||||||
// ...devices['Desktop Safari'],
|
|
||||||
// },
|
|
||||||
// },
|
|
||||||
|
|
||||||
/* Test against mobile viewports. */
|
|
||||||
// {
|
|
||||||
// name: 'Mobile Chrome',
|
|
||||||
// use: {
|
|
||||||
// ...devices['Pixel 5'],
|
|
||||||
// },
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// name: 'Mobile Safari',
|
|
||||||
// use: {
|
|
||||||
// ...devices['iPhone 12'],
|
|
||||||
// },
|
|
||||||
// },
|
|
||||||
|
|
||||||
/* Test against branded browsers. */
|
|
||||||
// {
|
|
||||||
// name: 'Microsoft Edge',
|
|
||||||
// use: {
|
|
||||||
// channel: 'msedge',
|
|
||||||
// },
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// name: 'Google Chrome',
|
|
||||||
// use: {
|
|
||||||
// channel: 'chrome',
|
|
||||||
// },
|
|
||||||
// },
|
|
||||||
],
|
|
||||||
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
|
|
||||||
reporter: [
|
|
||||||
['list'],
|
|
||||||
['html', { outputFolder: 'node_modules/.e2e/test-results' }],
|
|
||||||
],
|
|
||||||
/* Retry on CI only */
|
|
||||||
retries: process.env.CI ? 2 : 0,
|
|
||||||
testDir: './__tests__/e2e',
|
|
||||||
/* Maximum time one test can run for. */
|
|
||||||
timeout: 30 * 1000,
|
|
||||||
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
|
|
||||||
use: {
|
|
||||||
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
|
|
||||||
actionTimeout: 0,
|
|
||||||
/* Base URL to use in actions like `await page.goto('/')`. */
|
|
||||||
baseURL: 'http://localhost:5555',
|
|
||||||
/* Only on CI systems run the tests headless */
|
|
||||||
headless: !!process.env.CI,
|
|
||||||
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
|
|
||||||
trace: 'retain-on-failure',
|
|
||||||
},
|
|
||||||
|
|
||||||
/* Run your local dev server before starting the tests */
|
|
||||||
webServer: {
|
|
||||||
command: process.env.CI ? 'pnpm preview --port 5555' : 'pnpm dev',
|
|
||||||
port: 5555,
|
|
||||||
reuseExistingServer: !process.env.CI,
|
|
||||||
},
|
|
||||||
|
|
||||||
/* Opt out of parallel tests on CI. */
|
|
||||||
workers: process.env.CI ? 1 : undefined,
|
|
||||||
};
|
|
||||||
|
|
||||||
export default config;
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
export { default } from '@vben/tailwind-config/postcss';
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 5.3 KiB |
@@ -1,207 +0,0 @@
|
|||||||
/**
|
|
||||||
* 通用组件共同的使用的基础组件,原先放在 adapter/form 内部,限制了使用范围,这里提取出来,方便其他地方使用
|
|
||||||
* 可用于 vben-form、vben-modal、vben-drawer 等组件使用,
|
|
||||||
*/
|
|
||||||
|
|
||||||
import type { Component } from 'vue';
|
|
||||||
|
|
||||||
import type { BaseFormComponentType } from '@vben/common-ui';
|
|
||||||
import type { Recordable } from '@vben/types';
|
|
||||||
|
|
||||||
import { defineAsyncComponent, defineComponent, h, ref } from 'vue';
|
|
||||||
|
|
||||||
import { ApiComponent, globalShareState, IconPicker } from '@vben/common-ui';
|
|
||||||
import { $t } from '@vben/locales';
|
|
||||||
|
|
||||||
import { notification } from 'ant-design-vue';
|
|
||||||
|
|
||||||
const AutoComplete = defineAsyncComponent(
|
|
||||||
() => import('ant-design-vue/es/auto-complete'),
|
|
||||||
);
|
|
||||||
const Button = defineAsyncComponent(() => import('ant-design-vue/es/button'));
|
|
||||||
const Checkbox = defineAsyncComponent(
|
|
||||||
() => import('ant-design-vue/es/checkbox'),
|
|
||||||
);
|
|
||||||
const CheckboxGroup = defineAsyncComponent(() =>
|
|
||||||
import('ant-design-vue/es/checkbox').then((res) => res.CheckboxGroup),
|
|
||||||
);
|
|
||||||
const DatePicker = defineAsyncComponent(
|
|
||||||
() => import('ant-design-vue/es/date-picker'),
|
|
||||||
);
|
|
||||||
const Divider = defineAsyncComponent(() => import('ant-design-vue/es/divider'));
|
|
||||||
const Input = defineAsyncComponent(() => import('ant-design-vue/es/input'));
|
|
||||||
const InputNumber = defineAsyncComponent(
|
|
||||||
() => import('ant-design-vue/es/input-number'),
|
|
||||||
);
|
|
||||||
const InputPassword = defineAsyncComponent(() =>
|
|
||||||
import('ant-design-vue/es/input').then((res) => res.InputPassword),
|
|
||||||
);
|
|
||||||
const Mentions = defineAsyncComponent(
|
|
||||||
() => import('ant-design-vue/es/mentions'),
|
|
||||||
);
|
|
||||||
const Radio = defineAsyncComponent(() => import('ant-design-vue/es/radio'));
|
|
||||||
const RadioGroup = defineAsyncComponent(() =>
|
|
||||||
import('ant-design-vue/es/radio').then((res) => res.RadioGroup),
|
|
||||||
);
|
|
||||||
const RangePicker = defineAsyncComponent(() =>
|
|
||||||
import('ant-design-vue/es/date-picker').then((res) => res.RangePicker),
|
|
||||||
);
|
|
||||||
const Rate = defineAsyncComponent(() => import('ant-design-vue/es/rate'));
|
|
||||||
const Select = defineAsyncComponent(() => import('ant-design-vue/es/select'));
|
|
||||||
const Space = defineAsyncComponent(() => import('ant-design-vue/es/space'));
|
|
||||||
const Switch = defineAsyncComponent(() => import('ant-design-vue/es/switch'));
|
|
||||||
const Textarea = defineAsyncComponent(() =>
|
|
||||||
import('ant-design-vue/es/input').then((res) => res.Textarea),
|
|
||||||
);
|
|
||||||
const TimePicker = defineAsyncComponent(
|
|
||||||
() => import('ant-design-vue/es/time-picker'),
|
|
||||||
);
|
|
||||||
const TreeSelect = defineAsyncComponent(
|
|
||||||
() => import('ant-design-vue/es/tree-select'),
|
|
||||||
);
|
|
||||||
const Upload = defineAsyncComponent(() => import('ant-design-vue/es/upload'));
|
|
||||||
|
|
||||||
const withDefaultPlaceholder = <T extends Component>(
|
|
||||||
component: T,
|
|
||||||
type: 'input' | 'select',
|
|
||||||
componentProps: Recordable<any> = {},
|
|
||||||
) => {
|
|
||||||
return defineComponent({
|
|
||||||
name: component.name,
|
|
||||||
inheritAttrs: false,
|
|
||||||
setup: (props: any, { attrs, expose, slots }) => {
|
|
||||||
const placeholder =
|
|
||||||
props?.placeholder ||
|
|
||||||
attrs?.placeholder ||
|
|
||||||
$t(`ui.placeholder.${type}`);
|
|
||||||
// 透传组件暴露的方法
|
|
||||||
const innerRef = ref();
|
|
||||||
// const publicApi: Recordable<any> = {};
|
|
||||||
expose(
|
|
||||||
new Proxy(
|
|
||||||
{},
|
|
||||||
{
|
|
||||||
get: (_target, key) => innerRef.value?.[key],
|
|
||||||
has: (_target, key) => key in (innerRef.value || {}),
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
// const instance = getCurrentInstance();
|
|
||||||
// instance?.proxy?.$nextTick(() => {
|
|
||||||
// for (const key in innerRef.value) {
|
|
||||||
// if (typeof innerRef.value[key] === 'function') {
|
|
||||||
// publicApi[key] = innerRef.value[key];
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
return () =>
|
|
||||||
h(
|
|
||||||
component,
|
|
||||||
{ ...componentProps, placeholder, ...props, ...attrs, ref: innerRef },
|
|
||||||
slots,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
// 这里需要自行根据业务组件库进行适配,需要用到的组件都需要在这里类型说明
|
|
||||||
export type ComponentType =
|
|
||||||
| 'ApiSelect'
|
|
||||||
| 'ApiTreeSelect'
|
|
||||||
| 'AutoComplete'
|
|
||||||
| 'Checkbox'
|
|
||||||
| 'CheckboxGroup'
|
|
||||||
| 'DatePicker'
|
|
||||||
| 'DefaultButton'
|
|
||||||
| 'Divider'
|
|
||||||
| 'IconPicker'
|
|
||||||
| 'Input'
|
|
||||||
| 'InputNumber'
|
|
||||||
| 'InputPassword'
|
|
||||||
| 'Mentions'
|
|
||||||
| 'PrimaryButton'
|
|
||||||
| 'Radio'
|
|
||||||
| 'RadioGroup'
|
|
||||||
| 'RangePicker'
|
|
||||||
| 'Rate'
|
|
||||||
| 'Select'
|
|
||||||
| 'Space'
|
|
||||||
| 'Switch'
|
|
||||||
| 'Textarea'
|
|
||||||
| 'TimePicker'
|
|
||||||
| 'TreeSelect'
|
|
||||||
| 'Upload'
|
|
||||||
| BaseFormComponentType;
|
|
||||||
|
|
||||||
async function initComponentAdapter() {
|
|
||||||
const components: Partial<Record<ComponentType, Component>> = {
|
|
||||||
// 如果你的组件体积比较大,可以使用异步加载
|
|
||||||
// Button: () =>
|
|
||||||
// import('xxx').then((res) => res.Button),
|
|
||||||
|
|
||||||
ApiSelect: withDefaultPlaceholder(ApiComponent, 'select', {
|
|
||||||
component: Select,
|
|
||||||
loadingSlot: 'suffixIcon',
|
|
||||||
modelPropName: 'value',
|
|
||||||
visibleEvent: 'onVisibleChange',
|
|
||||||
}),
|
|
||||||
ApiTreeSelect: withDefaultPlaceholder(ApiComponent, 'select', {
|
|
||||||
component: TreeSelect,
|
|
||||||
fieldNames: { label: 'label', value: 'value', children: 'children' },
|
|
||||||
loadingSlot: 'suffixIcon',
|
|
||||||
modelPropName: 'value',
|
|
||||||
optionsPropName: 'treeData',
|
|
||||||
visibleEvent: 'onVisibleChange',
|
|
||||||
}),
|
|
||||||
AutoComplete,
|
|
||||||
Checkbox,
|
|
||||||
CheckboxGroup,
|
|
||||||
DatePicker,
|
|
||||||
// 自定义默认按钮
|
|
||||||
DefaultButton: (props, { attrs, slots }) => {
|
|
||||||
return h(Button, { ...props, attrs, type: 'default' }, slots);
|
|
||||||
},
|
|
||||||
Divider,
|
|
||||||
IconPicker: withDefaultPlaceholder(IconPicker, 'select', {
|
|
||||||
iconSlot: 'addonAfter',
|
|
||||||
inputComponent: Input,
|
|
||||||
modelValueProp: 'value',
|
|
||||||
}),
|
|
||||||
Input: withDefaultPlaceholder(Input, 'input'),
|
|
||||||
InputNumber: withDefaultPlaceholder(InputNumber, 'input'),
|
|
||||||
InputPassword: withDefaultPlaceholder(InputPassword, 'input'),
|
|
||||||
Mentions: withDefaultPlaceholder(Mentions, 'input'),
|
|
||||||
// 自定义主要按钮
|
|
||||||
PrimaryButton: (props, { attrs, slots }) => {
|
|
||||||
return h(Button, { ...props, attrs, type: 'primary' }, slots);
|
|
||||||
},
|
|
||||||
Radio,
|
|
||||||
RadioGroup,
|
|
||||||
RangePicker,
|
|
||||||
Rate,
|
|
||||||
Select: withDefaultPlaceholder(Select, 'select'),
|
|
||||||
Space,
|
|
||||||
Switch,
|
|
||||||
Textarea: withDefaultPlaceholder(Textarea, 'input'),
|
|
||||||
TimePicker,
|
|
||||||
TreeSelect: withDefaultPlaceholder(TreeSelect, 'select'),
|
|
||||||
Upload,
|
|
||||||
};
|
|
||||||
|
|
||||||
// 将组件注册到全局共享状态中
|
|
||||||
globalShareState.setComponents(components);
|
|
||||||
|
|
||||||
// 定义全局共享状态中的消息提示
|
|
||||||
globalShareState.defineMessage({
|
|
||||||
// 复制成功消息提示
|
|
||||||
copyPreferencesSuccess: (title, content) => {
|
|
||||||
notification.success({
|
|
||||||
description: content,
|
|
||||||
message: title,
|
|
||||||
placement: 'bottomRight',
|
|
||||||
});
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export { initComponentAdapter };
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
import type {
|
|
||||||
VbenFormSchema as FormSchema,
|
|
||||||
VbenFormProps,
|
|
||||||
} from '@vben/common-ui';
|
|
||||||
|
|
||||||
import type { ComponentType } from './component';
|
|
||||||
|
|
||||||
import { setupVbenForm, useVbenForm as useForm, z } from '@vben/common-ui';
|
|
||||||
import { $t } from '@vben/locales';
|
|
||||||
|
|
||||||
async function initSetupVbenForm() {
|
|
||||||
setupVbenForm<ComponentType>({
|
|
||||||
config: {
|
|
||||||
// ant design vue组件库默认都是 v-model:value
|
|
||||||
baseModelPropName: 'value',
|
|
||||||
// 一些组件是 v-model:checked 或者 v-model:fileList
|
|
||||||
modelPropNameMap: {
|
|
||||||
Checkbox: 'checked',
|
|
||||||
Radio: 'checked',
|
|
||||||
Switch: 'checked',
|
|
||||||
Upload: 'fileList',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
defineRules: {
|
|
||||||
// 输入项目必填国际化适配
|
|
||||||
required: (value, _params, ctx) => {
|
|
||||||
if (value === undefined || value === null || value.length === 0) {
|
|
||||||
return $t('ui.formRules.required', [ctx.label]);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
},
|
|
||||||
// 选择项目必填国际化适配
|
|
||||||
selectRequired: (value, _params, ctx) => {
|
|
||||||
if (value === undefined || value === null) {
|
|
||||||
return $t('ui.formRules.selectRequired', [ctx.label]);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const useVbenForm = useForm<ComponentType>;
|
|
||||||
|
|
||||||
export { initSetupVbenForm, useVbenForm, z };
|
|
||||||
export type VbenFormSchema = FormSchema<ComponentType>;
|
|
||||||
export type { VbenFormProps };
|
|
||||||
@@ -1,297 +0,0 @@
|
|||||||
import type { VxeTableGridOptions } from '@vben/plugins/vxe-table';
|
|
||||||
import type { Recordable } from '@vben/types';
|
|
||||||
|
|
||||||
import type { ComponentType } from './component';
|
|
||||||
|
|
||||||
import { h } from 'vue';
|
|
||||||
|
|
||||||
import { IconifyIcon } from '@vben/icons';
|
|
||||||
import { $te } from '@vben/locales';
|
|
||||||
import {
|
|
||||||
setupVbenVxeTable,
|
|
||||||
useVbenVxeGrid as useGrid,
|
|
||||||
} from '@vben/plugins/vxe-table';
|
|
||||||
import { get, isFunction, isString } from '@vben/utils';
|
|
||||||
|
|
||||||
import { objectOmit } from '@vueuse/core';
|
|
||||||
import { Button, Image, Popconfirm, Switch, Tag } from 'ant-design-vue';
|
|
||||||
|
|
||||||
import { $t } from '#/locales';
|
|
||||||
|
|
||||||
import { useVbenForm } from './form';
|
|
||||||
|
|
||||||
setupVbenVxeTable({
|
|
||||||
configVxeTable: (vxeUI) => {
|
|
||||||
vxeUI.setConfig({
|
|
||||||
grid: {
|
|
||||||
align: 'center',
|
|
||||||
border: false,
|
|
||||||
columnConfig: {
|
|
||||||
resizable: true,
|
|
||||||
},
|
|
||||||
|
|
||||||
formConfig: {
|
|
||||||
// 全局禁用vxe-table的表单配置,使用formOptions
|
|
||||||
enabled: false,
|
|
||||||
},
|
|
||||||
minHeight: 180,
|
|
||||||
proxyConfig: {
|
|
||||||
autoLoad: true,
|
|
||||||
response: {
|
|
||||||
result: 'items',
|
|
||||||
total: 'total',
|
|
||||||
list: '',
|
|
||||||
},
|
|
||||||
showActiveMsg: true,
|
|
||||||
showResponseMsg: false,
|
|
||||||
},
|
|
||||||
round: true,
|
|
||||||
showOverflow: true,
|
|
||||||
size: 'small',
|
|
||||||
} as VxeTableGridOptions,
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 解决vxeTable在热更新时可能会出错的问题
|
|
||||||
*/
|
|
||||||
vxeUI.renderer.forEach((_item, key) => {
|
|
||||||
if (key.startsWith('Cell')) {
|
|
||||||
vxeUI.renderer.delete(key);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// 表格配置项可以用 cellRender: { name: 'CellImage' },
|
|
||||||
vxeUI.renderer.add('CellImage', {
|
|
||||||
renderTableDefault(_renderOpts, params) {
|
|
||||||
const { column, row } = params;
|
|
||||||
return h(Image, { src: row[column.field] });
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
// 表格配置项可以用 cellRender: { name: 'CellLink' },
|
|
||||||
vxeUI.renderer.add('CellLink', {
|
|
||||||
renderTableDefault(renderOpts) {
|
|
||||||
const { props } = renderOpts;
|
|
||||||
return h(
|
|
||||||
Button,
|
|
||||||
{ size: 'small', type: 'link' },
|
|
||||||
{ default: () => props?.text },
|
|
||||||
);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
// 单元格渲染: Tag
|
|
||||||
vxeUI.renderer.add('CellTag', {
|
|
||||||
renderTableDefault({ options, props }, { column, row }) {
|
|
||||||
const value = get(row, column.field);
|
|
||||||
const tagOptions = options ?? [
|
|
||||||
{ color: 'success', label: $t('common.enabled'), value: 1 },
|
|
||||||
{ color: 'error', label: $t('common.disabled'), value: 0 },
|
|
||||||
];
|
|
||||||
const tagItem = tagOptions.find((item) => item.value === value);
|
|
||||||
return h(
|
|
||||||
Tag,
|
|
||||||
{
|
|
||||||
...props,
|
|
||||||
...objectOmit(tagItem ?? {}, ['label']),
|
|
||||||
},
|
|
||||||
{ default: () => tagItem?.label ?? value },
|
|
||||||
);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
vxeUI.renderer.add('CellSwitch', {
|
|
||||||
renderTableDefault({ attrs, props }, { column, row }) {
|
|
||||||
const loadingKey = `__loading_${column.field}`;
|
|
||||||
const finallyProps = {
|
|
||||||
checkedChildren: $t('common.enabled'),
|
|
||||||
checkedValue: 1,
|
|
||||||
unCheckedChildren: $t('common.disabled'),
|
|
||||||
unCheckedValue: 0,
|
|
||||||
...props,
|
|
||||||
checked: row[column.field],
|
|
||||||
loading: row[loadingKey] ?? false,
|
|
||||||
'onUpdate:checked': onChange,
|
|
||||||
};
|
|
||||||
async function onChange(newVal: any) {
|
|
||||||
row[loadingKey] = true;
|
|
||||||
try {
|
|
||||||
const result = await attrs?.beforeChange?.(newVal, row);
|
|
||||||
if (result !== false) {
|
|
||||||
row[column.field] = newVal;
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
row[loadingKey] = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return h(Switch, finallyProps);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 注册表格的操作按钮渲染器
|
|
||||||
*/
|
|
||||||
vxeUI.renderer.add('CellOperation', {
|
|
||||||
renderTableDefault({ attrs, options, props }, { column, row }) {
|
|
||||||
const defaultProps = { size: 'small', type: 'link', ...props };
|
|
||||||
let align = 'end';
|
|
||||||
switch (column.align) {
|
|
||||||
case 'center': {
|
|
||||||
align = 'center';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 'left': {
|
|
||||||
align = 'start';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default: {
|
|
||||||
align = 'end';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const presets: Recordable<Recordable<any>> = {
|
|
||||||
delete: {
|
|
||||||
danger: true,
|
|
||||||
text: $t('common.delete'),
|
|
||||||
},
|
|
||||||
edit: {
|
|
||||||
text: $t('common.edit'),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
const operations: Array<Recordable<any>> = (
|
|
||||||
options || ['edit', 'delete']
|
|
||||||
)
|
|
||||||
.map((opt) => {
|
|
||||||
if (isString(opt)) {
|
|
||||||
return presets[opt]
|
|
||||||
? { code: opt, ...presets[opt], ...defaultProps }
|
|
||||||
: {
|
|
||||||
code: opt,
|
|
||||||
text: $te(`common.${opt}`) ? $t(`common.${opt}`) : opt,
|
|
||||||
...defaultProps,
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
return { ...defaultProps, ...presets[opt.code], ...opt };
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.map((opt) => {
|
|
||||||
const optBtn: Recordable<any> = {};
|
|
||||||
Object.keys(opt).forEach((key) => {
|
|
||||||
optBtn[key] = isFunction(opt[key]) ? opt[key](row) : opt[key];
|
|
||||||
});
|
|
||||||
return optBtn;
|
|
||||||
})
|
|
||||||
.filter((opt) => opt.show !== false);
|
|
||||||
|
|
||||||
function renderBtn(opt: Recordable<any>, listen = true) {
|
|
||||||
return h(
|
|
||||||
Button,
|
|
||||||
{
|
|
||||||
...props,
|
|
||||||
...opt,
|
|
||||||
icon: undefined,
|
|
||||||
onClick: listen
|
|
||||||
? () =>
|
|
||||||
attrs?.onClick?.({
|
|
||||||
code: opt.code,
|
|
||||||
row,
|
|
||||||
})
|
|
||||||
: undefined,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
default: () => {
|
|
||||||
const content = [];
|
|
||||||
if (opt.icon) {
|
|
||||||
content.push(
|
|
||||||
h(IconifyIcon, { class: 'size-5', icon: opt.icon }),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
content.push(opt.text);
|
|
||||||
return content;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function renderConfirm(opt: Recordable<any>) {
|
|
||||||
let viewportWrapper: HTMLElement | null = null;
|
|
||||||
return h(
|
|
||||||
Popconfirm,
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* 当popconfirm用在固定列中时,将固定列作为弹窗的容器时可能会因为固定列较窄而无法容纳弹窗
|
|
||||||
* 将表格主体区域作为弹窗容器时又会因为固定列的层级较高而遮挡弹窗
|
|
||||||
* 将body或者表格视口区域作为弹窗容器时又会导致弹窗无法跟随表格滚动。
|
|
||||||
* 鉴于以上各种情况,一种折中的解决方案是弹出层展示时,禁止操作表格的滚动条。
|
|
||||||
* 这样既解决了弹窗的遮挡问题,又不至于让弹窗随着表格的滚动而跑出视口区域。
|
|
||||||
*/
|
|
||||||
getPopupContainer(el) {
|
|
||||||
viewportWrapper = el.closest('.vxe-table--viewport-wrapper');
|
|
||||||
return document.body;
|
|
||||||
},
|
|
||||||
placement: 'topLeft',
|
|
||||||
title: $t('ui.actionTitle.delete', [attrs?.nameTitle || '']),
|
|
||||||
...props,
|
|
||||||
...opt,
|
|
||||||
icon: undefined,
|
|
||||||
onOpenChange: (open: boolean) => {
|
|
||||||
// 当弹窗打开时,禁止表格的滚动
|
|
||||||
if (open) {
|
|
||||||
viewportWrapper?.style.setProperty('pointer-events', 'none');
|
|
||||||
} else {
|
|
||||||
viewportWrapper?.style.removeProperty('pointer-events');
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onConfirm: () => {
|
|
||||||
attrs?.onClick?.({
|
|
||||||
code: opt.code,
|
|
||||||
row,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
default: () => renderBtn({ ...opt }, false),
|
|
||||||
description: () =>
|
|
||||||
h(
|
|
||||||
'div',
|
|
||||||
{ class: 'truncate' },
|
|
||||||
$t('ui.actionMessage.deleteConfirm', [
|
|
||||||
row[attrs?.nameField || 'name'],
|
|
||||||
]),
|
|
||||||
),
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const btns = operations.map((opt) =>
|
|
||||||
opt.code === 'delete' ? renderConfirm(opt) : renderBtn(opt),
|
|
||||||
);
|
|
||||||
return h(
|
|
||||||
'div',
|
|
||||||
{
|
|
||||||
class: 'flex table-operations',
|
|
||||||
style: { justifyContent: align },
|
|
||||||
},
|
|
||||||
btns,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
// 这里可以自行扩展 vxe-table 的全局配置,比如自定义格式化
|
|
||||||
// vxeUI.formats.add
|
|
||||||
},
|
|
||||||
useVbenForm,
|
|
||||||
});
|
|
||||||
|
|
||||||
export const useVbenVxeGrid = <T extends Record<string, any>>(
|
|
||||||
...rest: Parameters<typeof useGrid<T, ComponentType>>
|
|
||||||
) => useGrid<T, ComponentType>(...rest);
|
|
||||||
|
|
||||||
export type OnActionClickParams<T = Recordable<any>> = {
|
|
||||||
code: string;
|
|
||||||
row: T;
|
|
||||||
};
|
|
||||||
export type OnActionClickFn<T = Recordable<any>> = (
|
|
||||||
params: OnActionClickParams<T>,
|
|
||||||
) => void;
|
|
||||||
export type * from '@vben/plugins/vxe-table';
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
import { baseRequestClient, requestClient } from '#/api/request';
|
|
||||||
|
|
||||||
export namespace AuthApi {
|
|
||||||
/** 登录接口参数 */
|
|
||||||
export interface LoginParams {
|
|
||||||
password?: string;
|
|
||||||
username?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 登录接口返回值 */
|
|
||||||
export interface LoginResult {
|
|
||||||
accessToken: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface RefreshTokenResult {
|
|
||||||
data: string;
|
|
||||||
status: number;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 登录
|
|
||||||
*/
|
|
||||||
export async function loginApi(data: AuthApi.LoginParams) {
|
|
||||||
return requestClient.post<AuthApi.LoginResult>('/auth/login', data, {
|
|
||||||
withCredentials: true,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 刷新accessToken
|
|
||||||
*/
|
|
||||||
export async function refreshTokenApi() {
|
|
||||||
return baseRequestClient.post<AuthApi.RefreshTokenResult>(
|
|
||||||
'/auth/refresh',
|
|
||||||
null,
|
|
||||||
{
|
|
||||||
withCredentials: true,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 退出登录
|
|
||||||
*/
|
|
||||||
export async function logoutApi() {
|
|
||||||
return baseRequestClient.post('/auth/logout', null, {
|
|
||||||
withCredentials: true,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取用户权限码
|
|
||||||
*/
|
|
||||||
export async function getAccessCodesApi() {
|
|
||||||
return requestClient.get<string[]>('/auth/codes');
|
|
||||||
}
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
export * from './auth';
|
|
||||||
export * from './menu';
|
|
||||||
export * from './timezone';
|
|
||||||
export * from './user';
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
import type { RouteRecordStringComponent } from '@vben/types';
|
|
||||||
|
|
||||||
import { requestClient } from '#/api/request';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取用户所有菜单
|
|
||||||
*/
|
|
||||||
export async function getAllMenusApi() {
|
|
||||||
return requestClient.get<RouteRecordStringComponent[]>('/menu/all');
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
import { requestClient } from '#/api/request';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取系统支持的时区列表
|
|
||||||
*/
|
|
||||||
export async function getTimezoneOptionsApi() {
|
|
||||||
return await requestClient.get<
|
|
||||||
{
|
|
||||||
label: string;
|
|
||||||
value: string;
|
|
||||||
}[]
|
|
||||||
>('/timezone/getTimezoneOptions');
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* 获取用户时区
|
|
||||||
*/
|
|
||||||
export async function getTimezoneApi(): Promise<null | string | undefined> {
|
|
||||||
return requestClient.get<null | string | undefined>('/timezone/getTimezone');
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* 设置用户时区
|
|
||||||
* @param timezone 时区
|
|
||||||
*/
|
|
||||||
export async function setTimezoneApi(timezone: string): Promise<void> {
|
|
||||||
return requestClient.post('/timezone/setTimezone', { timezone });
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
import type { UserInfo } from '@vben/types';
|
|
||||||
|
|
||||||
import { requestClient } from '#/api/request';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取用户信息
|
|
||||||
*/
|
|
||||||
export async function getUserInfoApi() {
|
|
||||||
return requestClient.get<UserInfo>('/user/info');
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
import type { RequestResponse } from '@vben/request';
|
|
||||||
|
|
||||||
import { requestClient } from '../request';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 下载文件,获取Blob
|
|
||||||
* @returns Blob
|
|
||||||
*/
|
|
||||||
async function downloadFile1() {
|
|
||||||
return requestClient.download<Blob>(
|
|
||||||
'https://unpkg.com/@vbenjs/static-source@0.1.7/source/logo-v1.webp',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 下载文件,获取完整的Response
|
|
||||||
* @returns RequestResponse<Blob>
|
|
||||||
*/
|
|
||||||
async function downloadFile2() {
|
|
||||||
return requestClient.download<RequestResponse<Blob>>(
|
|
||||||
'https://unpkg.com/@vbenjs/static-source@0.1.7/source/logo-v1.webp',
|
|
||||||
{
|
|
||||||
responseReturn: 'raw',
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export { downloadFile1, downloadFile2 };
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
export * from './status';
|
|
||||||
export * from './table';
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
import { requestClient } from '#/api/request';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 发起请求
|
|
||||||
*/
|
|
||||||
async function getBigIntData() {
|
|
||||||
return requestClient.get('/demo/bigint');
|
|
||||||
}
|
|
||||||
|
|
||||||
export { getBigIntData };
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
import type { Recordable } from '@vben/types';
|
|
||||||
|
|
||||||
import { requestClient } from '#/api/request';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 发起数组请求
|
|
||||||
*/
|
|
||||||
async function getParamsData(
|
|
||||||
params: Recordable<any>,
|
|
||||||
type: 'brackets' | 'comma' | 'indices' | 'repeat',
|
|
||||||
) {
|
|
||||||
return requestClient.get('/status', {
|
|
||||||
params,
|
|
||||||
paramsSerializer: type,
|
|
||||||
responseReturn: 'raw',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export { getParamsData };
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
import { requestClient } from '#/api/request';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 模拟任意状态码
|
|
||||||
*/
|
|
||||||
async function getMockStatusApi(status: string) {
|
|
||||||
return requestClient.get('/status', { params: { status } });
|
|
||||||
}
|
|
||||||
|
|
||||||
export { getMockStatusApi };
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
import { requestClient } from '#/api/request';
|
|
||||||
|
|
||||||
export namespace DemoTableApi {
|
|
||||||
export interface PageFetchParams {
|
|
||||||
[key: string]: any;
|
|
||||||
page: number;
|
|
||||||
pageSize: number;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取示例表格数据
|
|
||||||
*/
|
|
||||||
async function getExampleTableApi(params: DemoTableApi.PageFetchParams) {
|
|
||||||
return requestClient.get('/table/list', { params });
|
|
||||||
}
|
|
||||||
|
|
||||||
export { getExampleTableApi };
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
import { requestClient } from '#/api/request';
|
|
||||||
|
|
||||||
interface UploadFileParams {
|
|
||||||
file: File;
|
|
||||||
onError?: (error: Error) => void;
|
|
||||||
onProgress?: (progress: { percent: number }) => void;
|
|
||||||
onSuccess?: (data: any, file: File) => void;
|
|
||||||
}
|
|
||||||
export async function upload_file({
|
|
||||||
file,
|
|
||||||
onError,
|
|
||||||
onProgress,
|
|
||||||
onSuccess,
|
|
||||||
}: UploadFileParams) {
|
|
||||||
try {
|
|
||||||
onProgress?.({ percent: 0 });
|
|
||||||
|
|
||||||
const data = await requestClient.upload('/upload', { file });
|
|
||||||
|
|
||||||
onProgress?.({ percent: 100 });
|
|
||||||
onSuccess?.(data, file);
|
|
||||||
} catch (error) {
|
|
||||||
onError?.(error instanceof Error ? error : new Error(String(error)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
export * from './core';
|
|
||||||
export * from './examples';
|
|
||||||
export * from './system';
|
|
||||||
@@ -1,133 +0,0 @@
|
|||||||
/**
|
|
||||||
* 该文件可自行根据业务逻辑进行调整
|
|
||||||
*/
|
|
||||||
import type { AxiosResponseHeaders, RequestClientOptions } from '@vben/request';
|
|
||||||
|
|
||||||
import { useAppConfig } from '@vben/hooks';
|
|
||||||
import { preferences } from '@vben/preferences';
|
|
||||||
import {
|
|
||||||
authenticateResponseInterceptor,
|
|
||||||
defaultResponseInterceptor,
|
|
||||||
errorMessageResponseInterceptor,
|
|
||||||
RequestClient,
|
|
||||||
} from '@vben/request';
|
|
||||||
import { useAccessStore } from '@vben/stores';
|
|
||||||
import { cloneDeep } from '@vben/utils';
|
|
||||||
|
|
||||||
import { message } from 'ant-design-vue';
|
|
||||||
import JSONBigInt from 'json-bigint';
|
|
||||||
|
|
||||||
import { useAuthStore } from '#/store';
|
|
||||||
|
|
||||||
import { refreshTokenApi } from './core';
|
|
||||||
|
|
||||||
const { apiURL } = useAppConfig(import.meta.env, import.meta.env.PROD);
|
|
||||||
|
|
||||||
function createRequestClient(baseURL: string, options?: RequestClientOptions) {
|
|
||||||
const client = new RequestClient({
|
|
||||||
...options,
|
|
||||||
baseURL,
|
|
||||||
transformResponse: (data: any, header: AxiosResponseHeaders) => {
|
|
||||||
// storeAsString指示将BigInt存储为字符串,设为false则会存储为内置的BigInt类型
|
|
||||||
if (
|
|
||||||
header.getContentType()?.toString().includes('application/json') &&
|
|
||||||
typeof data === 'string'
|
|
||||||
) {
|
|
||||||
return cloneDeep(
|
|
||||||
JSONBigInt({ storeAsString: true, strict: true }).parse(data),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return data;
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 重新认证逻辑
|
|
||||||
*/
|
|
||||||
async function doReAuthenticate() {
|
|
||||||
console.warn('Access token or refresh token is invalid or expired. ');
|
|
||||||
const accessStore = useAccessStore();
|
|
||||||
const authStore = useAuthStore();
|
|
||||||
accessStore.setAccessToken(null);
|
|
||||||
if (
|
|
||||||
preferences.app.loginExpiredMode === 'modal' &&
|
|
||||||
accessStore.isAccessChecked
|
|
||||||
) {
|
|
||||||
accessStore.setLoginExpired(true);
|
|
||||||
} else {
|
|
||||||
await authStore.logout();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 刷新token逻辑
|
|
||||||
*/
|
|
||||||
async function doRefreshToken() {
|
|
||||||
const accessStore = useAccessStore();
|
|
||||||
const resp = await refreshTokenApi();
|
|
||||||
const newToken = resp.data;
|
|
||||||
accessStore.setAccessToken(newToken);
|
|
||||||
return newToken;
|
|
||||||
}
|
|
||||||
|
|
||||||
function formatToken(token: null | string) {
|
|
||||||
return token ? `Bearer ${token}` : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 请求头处理
|
|
||||||
client.addRequestInterceptor({
|
|
||||||
fulfilled: async (config) => {
|
|
||||||
const accessStore = useAccessStore();
|
|
||||||
|
|
||||||
config.headers.Authorization = formatToken(accessStore.accessToken);
|
|
||||||
config.headers['Accept-Language'] = preferences.app.locale;
|
|
||||||
return config;
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
// 处理返回的响应数据格式
|
|
||||||
client.addResponseInterceptor(
|
|
||||||
defaultResponseInterceptor({
|
|
||||||
codeField: 'code',
|
|
||||||
dataField: 'data',
|
|
||||||
successCode: 0,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
// token过期的处理
|
|
||||||
client.addResponseInterceptor(
|
|
||||||
authenticateResponseInterceptor({
|
|
||||||
client,
|
|
||||||
doReAuthenticate,
|
|
||||||
doRefreshToken,
|
|
||||||
enableRefreshToken: preferences.app.enableRefreshToken,
|
|
||||||
formatToken,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
// 通用的错误处理,如果没有进入上面的错误处理逻辑,就会进入这里
|
|
||||||
client.addResponseInterceptor(
|
|
||||||
errorMessageResponseInterceptor((msg: string, error) => {
|
|
||||||
// 这里可以根据业务进行定制,你可以拿到 error 内的信息进行定制化处理,根据不同的 code 做不同的提示,而不是直接使用 message.error 提示 msg
|
|
||||||
// 当前mock接口返回的错误字段是 error 或者 message
|
|
||||||
const responseData = error?.response?.data ?? {};
|
|
||||||
const errorMessage = responseData?.error ?? responseData?.message ?? '';
|
|
||||||
// 如果没有错误信息,则会根据状态码进行提示
|
|
||||||
message.error(errorMessage || msg);
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
return client;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const requestClient = createRequestClient(apiURL, {
|
|
||||||
responseReturn: 'data',
|
|
||||||
});
|
|
||||||
|
|
||||||
export const baseRequestClient = new RequestClient({ baseURL: apiURL });
|
|
||||||
|
|
||||||
export interface PageFetchParams {
|
|
||||||
[key: string]: any;
|
|
||||||
pageNo?: number;
|
|
||||||
pageSize?: number;
|
|
||||||
}
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
import { requestClient } from '#/api/request';
|
|
||||||
|
|
||||||
export namespace SystemDeptApi {
|
|
||||||
export interface SystemDept {
|
|
||||||
[key: string]: any;
|
|
||||||
children?: SystemDept[];
|
|
||||||
id: string;
|
|
||||||
name: string;
|
|
||||||
remark?: string;
|
|
||||||
status: 0 | 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取部门列表数据
|
|
||||||
*/
|
|
||||||
async function getDeptList() {
|
|
||||||
return requestClient.get<Array<SystemDeptApi.SystemDept>>(
|
|
||||||
'/system/dept/list',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建部门
|
|
||||||
* @param data 部门数据
|
|
||||||
*/
|
|
||||||
async function createDept(
|
|
||||||
data: Omit<SystemDeptApi.SystemDept, 'children' | 'id'>,
|
|
||||||
) {
|
|
||||||
return requestClient.post('/system/dept', data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新部门
|
|
||||||
*
|
|
||||||
* @param id 部门 ID
|
|
||||||
* @param data 部门数据
|
|
||||||
*/
|
|
||||||
async function updateDept(
|
|
||||||
id: string,
|
|
||||||
data: Omit<SystemDeptApi.SystemDept, 'children' | 'id'>,
|
|
||||||
) {
|
|
||||||
return requestClient.put(`/system/dept/${id}`, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除部门
|
|
||||||
* @param id 部门 ID
|
|
||||||
*/
|
|
||||||
async function deleteDept(id: string) {
|
|
||||||
return requestClient.delete(`/system/dept/${id}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
export { createDept, deleteDept, getDeptList, updateDept };
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
export * from './dept';
|
|
||||||
export * from './menu';
|
|
||||||
export * from './role';
|
|
||||||
@@ -1,158 +0,0 @@
|
|||||||
import type { Recordable } from '@vben/types';
|
|
||||||
|
|
||||||
import { requestClient } from '#/api/request';
|
|
||||||
|
|
||||||
export namespace SystemMenuApi {
|
|
||||||
/** 徽标颜色集合 */
|
|
||||||
export const BadgeVariants = [
|
|
||||||
'default',
|
|
||||||
'destructive',
|
|
||||||
'primary',
|
|
||||||
'success',
|
|
||||||
'warning',
|
|
||||||
] as const;
|
|
||||||
/** 徽标类型集合 */
|
|
||||||
export const BadgeTypes = ['dot', 'normal'] as const;
|
|
||||||
/** 菜单类型集合 */
|
|
||||||
export const MenuTypes = [
|
|
||||||
'catalog',
|
|
||||||
'menu',
|
|
||||||
'embedded',
|
|
||||||
'link',
|
|
||||||
'button',
|
|
||||||
] as const;
|
|
||||||
/** 系统菜单 */
|
|
||||||
export interface SystemMenu {
|
|
||||||
[key: string]: any;
|
|
||||||
/** 后端权限标识 */
|
|
||||||
authCode: string;
|
|
||||||
/** 子级 */
|
|
||||||
children?: SystemMenu[];
|
|
||||||
/** 组件 */
|
|
||||||
component?: string;
|
|
||||||
/** 菜单ID */
|
|
||||||
id: string;
|
|
||||||
/** 菜单元数据 */
|
|
||||||
meta?: {
|
|
||||||
/** 激活时显示的图标 */
|
|
||||||
activeIcon?: string;
|
|
||||||
/** 作为路由时,需要激活的菜单的Path */
|
|
||||||
activePath?: string;
|
|
||||||
/** 固定在标签栏 */
|
|
||||||
affixTab?: boolean;
|
|
||||||
/** 在标签栏固定的顺序 */
|
|
||||||
affixTabOrder?: number;
|
|
||||||
/** 徽标内容(当徽标类型为normal时有效) */
|
|
||||||
badge?: string;
|
|
||||||
/** 徽标类型 */
|
|
||||||
badgeType?: (typeof BadgeTypes)[number];
|
|
||||||
/** 徽标颜色 */
|
|
||||||
badgeVariants?: (typeof BadgeVariants)[number];
|
|
||||||
/** 在菜单中隐藏下级 */
|
|
||||||
hideChildrenInMenu?: boolean;
|
|
||||||
/** 在面包屑中隐藏 */
|
|
||||||
hideInBreadcrumb?: boolean;
|
|
||||||
/** 在菜单中隐藏 */
|
|
||||||
hideInMenu?: boolean;
|
|
||||||
/** 在标签栏中隐藏 */
|
|
||||||
hideInTab?: boolean;
|
|
||||||
/** 菜单图标 */
|
|
||||||
icon?: string;
|
|
||||||
/** 内嵌Iframe的URL */
|
|
||||||
iframeSrc?: string;
|
|
||||||
/** 是否缓存页面 */
|
|
||||||
keepAlive?: boolean;
|
|
||||||
/** 外链页面的URL */
|
|
||||||
link?: string;
|
|
||||||
/** 同一个路由最大打开的标签数 */
|
|
||||||
maxNumOfOpenTab?: number;
|
|
||||||
/** 无需基础布局 */
|
|
||||||
noBasicLayout?: boolean;
|
|
||||||
/** 是否在新窗口打开 */
|
|
||||||
openInNewWindow?: boolean;
|
|
||||||
/** 菜单排序 */
|
|
||||||
order?: number;
|
|
||||||
/** 额外的路由参数 */
|
|
||||||
query?: Recordable<any>;
|
|
||||||
/** 菜单标题 */
|
|
||||||
title?: string;
|
|
||||||
};
|
|
||||||
/** 菜单名称 */
|
|
||||||
name: string;
|
|
||||||
/** 路由路径 */
|
|
||||||
path: string;
|
|
||||||
/** 父级ID */
|
|
||||||
pid: string;
|
|
||||||
/** 重定向 */
|
|
||||||
redirect?: string;
|
|
||||||
/** 菜单类型 */
|
|
||||||
type: (typeof MenuTypes)[number];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取菜单数据列表
|
|
||||||
*/
|
|
||||||
async function getMenuList() {
|
|
||||||
return requestClient.get<Array<SystemMenuApi.SystemMenu>>(
|
|
||||||
'/system/menu/list',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function isMenuNameExists(
|
|
||||||
name: string,
|
|
||||||
id?: SystemMenuApi.SystemMenu['id'],
|
|
||||||
) {
|
|
||||||
return requestClient.get<boolean>('/system/menu/name-exists', {
|
|
||||||
params: { id, name },
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async function isMenuPathExists(
|
|
||||||
path: string,
|
|
||||||
id?: SystemMenuApi.SystemMenu['id'],
|
|
||||||
) {
|
|
||||||
return requestClient.get<boolean>('/system/menu/path-exists', {
|
|
||||||
params: { id, path },
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建菜单
|
|
||||||
* @param data 菜单数据
|
|
||||||
*/
|
|
||||||
async function createMenu(
|
|
||||||
data: Omit<SystemMenuApi.SystemMenu, 'children' | 'id'>,
|
|
||||||
) {
|
|
||||||
return requestClient.post('/system/menu', data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新菜单
|
|
||||||
*
|
|
||||||
* @param id 菜单 ID
|
|
||||||
* @param data 菜单数据
|
|
||||||
*/
|
|
||||||
async function updateMenu(
|
|
||||||
id: string,
|
|
||||||
data: Omit<SystemMenuApi.SystemMenu, 'children' | 'id'>,
|
|
||||||
) {
|
|
||||||
return requestClient.put(`/system/menu/${id}`, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除菜单
|
|
||||||
* @param id 菜单 ID
|
|
||||||
*/
|
|
||||||
async function deleteMenu(id: string) {
|
|
||||||
return requestClient.delete(`/system/menu/${id}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
export {
|
|
||||||
createMenu,
|
|
||||||
deleteMenu,
|
|
||||||
getMenuList,
|
|
||||||
isMenuNameExists,
|
|
||||||
isMenuPathExists,
|
|
||||||
updateMenu,
|
|
||||||
};
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
import type { Recordable } from '@vben/types';
|
|
||||||
|
|
||||||
import { requestClient } from '#/api/request';
|
|
||||||
|
|
||||||
export namespace SystemRoleApi {
|
|
||||||
export interface SystemRole {
|
|
||||||
[key: string]: any;
|
|
||||||
id: string;
|
|
||||||
name: string;
|
|
||||||
permissions: string[];
|
|
||||||
remark?: string;
|
|
||||||
status: 0 | 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取角色列表数据
|
|
||||||
*/
|
|
||||||
async function getRoleList(params: Recordable<any>) {
|
|
||||||
return requestClient.get<Array<SystemRoleApi.SystemRole>>(
|
|
||||||
'/system/role/list',
|
|
||||||
{ params },
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建角色
|
|
||||||
* @param data 角色数据
|
|
||||||
*/
|
|
||||||
async function createRole(data: Omit<SystemRoleApi.SystemRole, 'id'>) {
|
|
||||||
return requestClient.post('/system/role', data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新角色
|
|
||||||
*
|
|
||||||
* @param id 角色 ID
|
|
||||||
* @param data 角色数据
|
|
||||||
*/
|
|
||||||
async function updateRole(
|
|
||||||
id: string,
|
|
||||||
data: Omit<SystemRoleApi.SystemRole, 'id'>,
|
|
||||||
) {
|
|
||||||
return requestClient.put(`/system/role/${id}`, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除角色
|
|
||||||
* @param id 角色 ID
|
|
||||||
*/
|
|
||||||
async function deleteRole(id: string) {
|
|
||||||
return requestClient.delete(`/system/role/${id}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
export { createRole, deleteRole, getRoleList, updateRole };
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
<script lang="ts" setup>
|
|
||||||
import { computed } from 'vue';
|
|
||||||
|
|
||||||
import { useAntdDesignTokens } from '@vben/hooks';
|
|
||||||
import { preferences, usePreferences } from '@vben/preferences';
|
|
||||||
|
|
||||||
import { App, ConfigProvider, theme } from 'ant-design-vue';
|
|
||||||
|
|
||||||
import { antdLocale } from '#/locales';
|
|
||||||
|
|
||||||
defineOptions({ name: 'App' });
|
|
||||||
|
|
||||||
const { isDark } = usePreferences();
|
|
||||||
const { tokens } = useAntdDesignTokens();
|
|
||||||
|
|
||||||
const tokenTheme = computed(() => {
|
|
||||||
const algorithm = isDark.value
|
|
||||||
? [theme.darkAlgorithm]
|
|
||||||
: [theme.defaultAlgorithm];
|
|
||||||
|
|
||||||
// antd 紧凑模式算法
|
|
||||||
if (preferences.app.compact) {
|
|
||||||
algorithm.push(theme.compactAlgorithm);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
algorithm,
|
|
||||||
token: tokens,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<ConfigProvider :locale="antdLocale" :theme="tokenTheme">
|
|
||||||
<App>
|
|
||||||
<RouterView />
|
|
||||||
</App>
|
|
||||||
</ConfigProvider>
|
|
||||||
</template>
|
|
||||||
@@ -1,84 +0,0 @@
|
|||||||
import { createApp, watchEffect } from 'vue';
|
|
||||||
|
|
||||||
import { registerAccessDirective } from '@vben/access';
|
|
||||||
import { registerLoadingDirective } from '@vben/common-ui';
|
|
||||||
import { preferences } from '@vben/preferences';
|
|
||||||
import { initStores } from '@vben/stores';
|
|
||||||
import '@vben/styles';
|
|
||||||
import '@vben/styles/antd';
|
|
||||||
|
|
||||||
import { useTitle } from '@vueuse/core';
|
|
||||||
|
|
||||||
import { $t, setupI18n } from '#/locales';
|
|
||||||
import { router } from '#/router';
|
|
||||||
|
|
||||||
import { initComponentAdapter } from './adapter/component';
|
|
||||||
import { initSetupVbenForm } from './adapter/form';
|
|
||||||
import App from './app.vue';
|
|
||||||
import { initTimezone } from './timezone-init';
|
|
||||||
|
|
||||||
async function bootstrap(namespace: string) {
|
|
||||||
// 初始化组件适配器
|
|
||||||
await initComponentAdapter();
|
|
||||||
|
|
||||||
// 初始化表单组件
|
|
||||||
await initSetupVbenForm();
|
|
||||||
|
|
||||||
// 设置弹窗的默认配置
|
|
||||||
// setDefaultModalProps({
|
|
||||||
// fullscreenButton: false,
|
|
||||||
// });
|
|
||||||
// 设置抽屉的默认配置
|
|
||||||
// setDefaultDrawerProps({
|
|
||||||
// zIndex: 1020,
|
|
||||||
// });
|
|
||||||
|
|
||||||
const app = createApp(App);
|
|
||||||
|
|
||||||
// 注册v-loading指令
|
|
||||||
registerLoadingDirective(app, {
|
|
||||||
loading: 'loading', // 在这里可以自定义指令名称,也可以明确提供false表示不注册这个指令
|
|
||||||
spinning: 'spinning',
|
|
||||||
});
|
|
||||||
|
|
||||||
// 国际化 i18n 配置
|
|
||||||
await setupI18n(app);
|
|
||||||
|
|
||||||
// 配置 pinia-tore
|
|
||||||
await initStores(app, { namespace });
|
|
||||||
|
|
||||||
// 初始化时区HANDLER
|
|
||||||
initTimezone();
|
|
||||||
|
|
||||||
// 安装权限指令
|
|
||||||
registerAccessDirective(app);
|
|
||||||
|
|
||||||
// 初始化 tippy
|
|
||||||
const { initTippy } = await import('@vben/common-ui/es/tippy');
|
|
||||||
initTippy(app);
|
|
||||||
|
|
||||||
// 配置路由及路由守卫
|
|
||||||
app.use(router);
|
|
||||||
|
|
||||||
// 配置@tanstack/vue-query
|
|
||||||
const { VueQueryPlugin } = await import('@tanstack/vue-query');
|
|
||||||
app.use(VueQueryPlugin);
|
|
||||||
|
|
||||||
// 配置Motion插件
|
|
||||||
const { MotionPlugin } = await import('@vben/plugins/motion');
|
|
||||||
app.use(MotionPlugin);
|
|
||||||
|
|
||||||
// 动态更新标题
|
|
||||||
watchEffect(() => {
|
|
||||||
if (preferences.app.dynamicTitle) {
|
|
||||||
const routeTitle = router.currentRoute.value.meta?.title;
|
|
||||||
const pageTitle =
|
|
||||||
(routeTitle ? `${$t(routeTitle)} - ` : '') + preferences.app.name;
|
|
||||||
useTitle(pageTitle);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
app.mount('#app');
|
|
||||||
}
|
|
||||||
|
|
||||||
export { bootstrap };
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
<script lang="ts" setup>
|
|
||||||
import { computed } from 'vue';
|
|
||||||
|
|
||||||
import { AuthPageLayout } from '@vben/layouts';
|
|
||||||
import { preferences } from '@vben/preferences';
|
|
||||||
|
|
||||||
import { $t } from '#/locales';
|
|
||||||
|
|
||||||
const appName = computed(() => preferences.app.name);
|
|
||||||
const logo = computed(() => preferences.logo.source);
|
|
||||||
const clickLogo = () => {};
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<AuthPageLayout
|
|
||||||
:app-name="appName"
|
|
||||||
:logo="logo"
|
|
||||||
:page-description="$t('authentication.pageDesc')"
|
|
||||||
:page-title="$t('authentication.pageTitle')"
|
|
||||||
:click-logo="clickLogo"
|
|
||||||
>
|
|
||||||
<!-- 自定义工具栏 -->
|
|
||||||
<!-- <template #toolbar></template> -->
|
|
||||||
</AuthPageLayout>
|
|
||||||
</template>
|
|
||||||
@@ -1,188 +0,0 @@
|
|||||||
<script lang="ts" setup>
|
|
||||||
import type { NotificationItem } from '@vben/layouts';
|
|
||||||
|
|
||||||
import { computed, onBeforeMount, ref, watch } from 'vue';
|
|
||||||
|
|
||||||
import { AuthenticationLoginExpiredModal } from '@vben/common-ui';
|
|
||||||
import { VBEN_DOC_URL, VBEN_GITHUB_URL } from '@vben/constants';
|
|
||||||
import { useWatermark } from '@vben/hooks';
|
|
||||||
import { BookOpenText, CircleHelp, SvgGithubIcon } from '@vben/icons';
|
|
||||||
import {
|
|
||||||
BasicLayout,
|
|
||||||
LockScreen,
|
|
||||||
Notification,
|
|
||||||
UserDropdown,
|
|
||||||
} from '@vben/layouts';
|
|
||||||
import { preferences } from '@vben/preferences';
|
|
||||||
import { useAccessStore, useTabbarStore, useUserStore } from '@vben/stores';
|
|
||||||
import { openWindow } from '@vben/utils';
|
|
||||||
|
|
||||||
import { $t } from '#/locales';
|
|
||||||
import { useAuthStore } from '#/store';
|
|
||||||
import LoginForm from '#/views/_core/authentication/login.vue';
|
|
||||||
|
|
||||||
const { setMenuList } = useTabbarStore();
|
|
||||||
setMenuList([
|
|
||||||
'close',
|
|
||||||
'affix',
|
|
||||||
'maximize',
|
|
||||||
'reload',
|
|
||||||
'open-in-new-window',
|
|
||||||
'close-left',
|
|
||||||
'close-right',
|
|
||||||
'close-other',
|
|
||||||
'close-all',
|
|
||||||
]);
|
|
||||||
|
|
||||||
const notifications = ref<NotificationItem[]>([
|
|
||||||
{
|
|
||||||
avatar: 'https://avatar.vercel.sh/vercel.svg?text=VB',
|
|
||||||
date: '3小时前',
|
|
||||||
isRead: true,
|
|
||||||
message: '描述信息描述信息描述信息',
|
|
||||||
title: '收到了 14 份新周报',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
avatar: 'https://avatar.vercel.sh/1',
|
|
||||||
date: '刚刚',
|
|
||||||
isRead: false,
|
|
||||||
message: '描述信息描述信息描述信息',
|
|
||||||
title: '朱偏右 回复了你',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
avatar: 'https://avatar.vercel.sh/1',
|
|
||||||
date: '2024-01-01',
|
|
||||||
isRead: false,
|
|
||||||
message: '描述信息描述信息描述信息',
|
|
||||||
title: '曲丽丽 评论了你',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
avatar: 'https://avatar.vercel.sh/satori',
|
|
||||||
date: '1天前',
|
|
||||||
isRead: false,
|
|
||||||
message: '描述信息描述信息描述信息',
|
|
||||||
title: '代办提醒',
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
|
|
||||||
const userStore = useUserStore();
|
|
||||||
const authStore = useAuthStore();
|
|
||||||
const accessStore = useAccessStore();
|
|
||||||
const { destroyWatermark, updateWatermark } = useWatermark();
|
|
||||||
const showDot = computed(() =>
|
|
||||||
notifications.value.some((item) => !item.isRead),
|
|
||||||
);
|
|
||||||
|
|
||||||
const menus = computed(() => [
|
|
||||||
{
|
|
||||||
handler: () => {
|
|
||||||
openWindow(VBEN_DOC_URL, {
|
|
||||||
target: '_blank',
|
|
||||||
});
|
|
||||||
},
|
|
||||||
icon: BookOpenText,
|
|
||||||
text: $t('ui.widgets.document'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
handler: () => {
|
|
||||||
openWindow(VBEN_GITHUB_URL, {
|
|
||||||
target: '_blank',
|
|
||||||
});
|
|
||||||
},
|
|
||||||
icon: SvgGithubIcon,
|
|
||||||
text: 'GitHub',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
handler: () => {
|
|
||||||
openWindow(`${VBEN_GITHUB_URL}/issues`, {
|
|
||||||
target: '_blank',
|
|
||||||
});
|
|
||||||
},
|
|
||||||
icon: CircleHelp,
|
|
||||||
text: $t('ui.widgets.qa'),
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
|
|
||||||
const avatar = computed(() => {
|
|
||||||
return userStore.userInfo?.avatar ?? preferences.app.defaultAvatar;
|
|
||||||
});
|
|
||||||
|
|
||||||
async function handleLogout() {
|
|
||||||
await authStore.logout(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleNoticeClear() {
|
|
||||||
notifications.value = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleMakeAll() {
|
|
||||||
notifications.value.forEach((item) => (item.isRead = true));
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleClickLogo() {}
|
|
||||||
|
|
||||||
watch(
|
|
||||||
() => ({
|
|
||||||
enable: preferences.app.watermark,
|
|
||||||
content: preferences.app.watermarkContent,
|
|
||||||
}),
|
|
||||||
async ({ enable, content }) => {
|
|
||||||
if (enable) {
|
|
||||||
await updateWatermark({
|
|
||||||
content:
|
|
||||||
content ||
|
|
||||||
`${userStore.userInfo?.username} - ${userStore.userInfo?.realName}`,
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
destroyWatermark();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
immediate: true,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
onBeforeMount(() => {
|
|
||||||
if (preferences.app.watermark) {
|
|
||||||
destroyWatermark();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<BasicLayout
|
|
||||||
@clear-preferences-and-logout="handleLogout"
|
|
||||||
@click-logo="handleClickLogo"
|
|
||||||
>
|
|
||||||
<template #user-dropdown>
|
|
||||||
<UserDropdown
|
|
||||||
:avatar
|
|
||||||
:menus
|
|
||||||
:text="userStore.userInfo?.realName"
|
|
||||||
description="ann.vben@gmail.com"
|
|
||||||
tag-text="Pro"
|
|
||||||
trigger="both"
|
|
||||||
@logout="handleLogout"
|
|
||||||
/>
|
|
||||||
</template>
|
|
||||||
<template #notification>
|
|
||||||
<Notification
|
|
||||||
:dot="showDot"
|
|
||||||
:notifications="notifications"
|
|
||||||
@clear="handleNoticeClear"
|
|
||||||
@make-all="handleMakeAll"
|
|
||||||
/>
|
|
||||||
</template>
|
|
||||||
<template #extra>
|
|
||||||
<AuthenticationLoginExpiredModal
|
|
||||||
v-model:open="accessStore.loginExpired"
|
|
||||||
:avatar
|
|
||||||
>
|
|
||||||
<LoginForm />
|
|
||||||
</AuthenticationLoginExpiredModal>
|
|
||||||
</template>
|
|
||||||
<template #lock-screen>
|
|
||||||
<LockScreen :avatar @to-login="handleLogout" />
|
|
||||||
</template>
|
|
||||||
</BasicLayout>
|
|
||||||
</template>
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
const BasicLayout = () => import('./basic.vue');
|
|
||||||
const AuthPageLayout = () => import('./auth.vue');
|
|
||||||
|
|
||||||
const IFrameView = () => import('@vben/layouts').then((m) => m.IFrameView);
|
|
||||||
|
|
||||||
export { AuthPageLayout, BasicLayout, IFrameView };
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
# locale
|
|
||||||
|
|
||||||
每个app使用的国际化可能不同,这里用于扩展国际化的功能,例如扩展 dayjs、antd组件库的多语言切换,以及app本身的国际化文件。
|
|
||||||
@@ -1,102 +0,0 @@
|
|||||||
import type { Locale } from 'ant-design-vue/es/locale';
|
|
||||||
|
|
||||||
import type { App } from 'vue';
|
|
||||||
|
|
||||||
import type { LocaleSetupOptions, SupportedLanguagesType } from '@vben/locales';
|
|
||||||
|
|
||||||
import { ref } from 'vue';
|
|
||||||
|
|
||||||
import {
|
|
||||||
$t,
|
|
||||||
setupI18n as coreSetup,
|
|
||||||
loadLocalesMapFromDir,
|
|
||||||
} from '@vben/locales';
|
|
||||||
import { preferences } from '@vben/preferences';
|
|
||||||
|
|
||||||
import antdEnLocale from 'ant-design-vue/es/locale/en_US';
|
|
||||||
import antdDefaultLocale from 'ant-design-vue/es/locale/zh_CN';
|
|
||||||
import dayjs from 'dayjs';
|
|
||||||
|
|
||||||
const antdLocale = ref<Locale>(antdDefaultLocale);
|
|
||||||
|
|
||||||
const modules = import.meta.glob('./langs/**/*.json');
|
|
||||||
|
|
||||||
const localesMap = loadLocalesMapFromDir(
|
|
||||||
/\.\/langs\/([^/]+)\/(.*)\.json$/,
|
|
||||||
modules,
|
|
||||||
);
|
|
||||||
/**
|
|
||||||
* 加载应用特有的语言包
|
|
||||||
* 这里也可以改造为从服务端获取翻译数据
|
|
||||||
* @param lang
|
|
||||||
*/
|
|
||||||
async function loadMessages(lang: SupportedLanguagesType) {
|
|
||||||
const [appLocaleMessages] = await Promise.all([
|
|
||||||
localesMap[lang]?.(),
|
|
||||||
loadThirdPartyMessage(lang),
|
|
||||||
]);
|
|
||||||
return appLocaleMessages?.default;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 加载第三方组件库的语言包
|
|
||||||
* @param lang
|
|
||||||
*/
|
|
||||||
async function loadThirdPartyMessage(lang: SupportedLanguagesType) {
|
|
||||||
await Promise.all([loadAntdLocale(lang), loadDayjsLocale(lang)]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 加载dayjs的语言包
|
|
||||||
* @param lang
|
|
||||||
*/
|
|
||||||
async function loadDayjsLocale(lang: SupportedLanguagesType) {
|
|
||||||
let locale;
|
|
||||||
switch (lang) {
|
|
||||||
case 'en-US': {
|
|
||||||
locale = await import('dayjs/locale/en');
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 'zh-CN': {
|
|
||||||
locale = await import('dayjs/locale/zh-cn');
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
// 默认使用英语
|
|
||||||
default: {
|
|
||||||
locale = await import('dayjs/locale/en');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (locale) {
|
|
||||||
dayjs.locale(locale);
|
|
||||||
} else {
|
|
||||||
console.error(`Failed to load dayjs locale for ${lang}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 加载antd的语言包
|
|
||||||
* @param lang
|
|
||||||
*/
|
|
||||||
async function loadAntdLocale(lang: SupportedLanguagesType) {
|
|
||||||
switch (lang) {
|
|
||||||
case 'en-US': {
|
|
||||||
antdLocale.value = antdEnLocale;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 'zh-CN': {
|
|
||||||
antdLocale.value = antdDefaultLocale;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function setupI18n(app: App, options: LocaleSetupOptions = {}) {
|
|
||||||
await coreSetup(app, {
|
|
||||||
defaultLocale: preferences.app.locale,
|
|
||||||
loadMessages,
|
|
||||||
missingWarn: !import.meta.env.PROD,
|
|
||||||
...options,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export { $t, antdLocale, setupI18n };
|
|
||||||
@@ -1,71 +0,0 @@
|
|||||||
{
|
|
||||||
"title": "Demos",
|
|
||||||
"access": {
|
|
||||||
"frontendPermissions": "Frontend Permissions",
|
|
||||||
"backendPermissions": "Backend Permissions",
|
|
||||||
"pageAccess": "Page Access",
|
|
||||||
"buttonControl": "Button Control",
|
|
||||||
"menuVisible403": "Menu Visible(403)",
|
|
||||||
"superVisible": "Visible to Super",
|
|
||||||
"adminVisible": "Visible to Admin",
|
|
||||||
"userVisible": "Visible to User"
|
|
||||||
},
|
|
||||||
"nested": {
|
|
||||||
"title": "Nested Menu",
|
|
||||||
"menu1": "Menu 1",
|
|
||||||
"menu2": "Menu 2",
|
|
||||||
"menu2_1": "Menu 2-1",
|
|
||||||
"menu3": "Menu 3",
|
|
||||||
"menu3_1": "Menu 3-1",
|
|
||||||
"menu3_2": "Menu 3-2",
|
|
||||||
"menu3_2_1": "Menu 3-2-1"
|
|
||||||
},
|
|
||||||
"outside": {
|
|
||||||
"title": "External Pages",
|
|
||||||
"embedded": "Embedded",
|
|
||||||
"externalLink": "External Link"
|
|
||||||
},
|
|
||||||
"badge": {
|
|
||||||
"title": "Menu Badge",
|
|
||||||
"dot": "Dot Badge",
|
|
||||||
"text": "Text Badge",
|
|
||||||
"color": "Badge Color"
|
|
||||||
},
|
|
||||||
"activeIcon": {
|
|
||||||
"title": "Active Menu Icon",
|
|
||||||
"children": "Children Active Icon"
|
|
||||||
},
|
|
||||||
"fallback": {
|
|
||||||
"title": "Fallback Page"
|
|
||||||
},
|
|
||||||
"features": {
|
|
||||||
"title": "Features",
|
|
||||||
"hideChildrenInMenu": "Hide Menu Children",
|
|
||||||
"loginExpired": "Login Expired",
|
|
||||||
"icons": "Icons",
|
|
||||||
"watermark": "Watermark",
|
|
||||||
"tabs": "Tabs",
|
|
||||||
"tabDetail": "Tab Detail Page",
|
|
||||||
"fullScreen": "FullScreen",
|
|
||||||
"clipboard": "Clipboard",
|
|
||||||
"menuWithQuery": "Menu With Query",
|
|
||||||
"openInNewWindow": "Open in New Window",
|
|
||||||
"fileDownload": "File Download"
|
|
||||||
},
|
|
||||||
"breadcrumb": {
|
|
||||||
"navigation": "Breadcrumb Navigation",
|
|
||||||
"lateral": "Lateral Mode",
|
|
||||||
"lateralDetail": "Lateral Mode Detail",
|
|
||||||
"level": "Level Mode",
|
|
||||||
"levelDetail": "Level Mode Detail"
|
|
||||||
},
|
|
||||||
"vben": {
|
|
||||||
"title": "Project",
|
|
||||||
"about": "About",
|
|
||||||
"document": "Document",
|
|
||||||
"antdv": "Ant Design Vue Version",
|
|
||||||
"naive-ui": "Naive UI Version",
|
|
||||||
"element-plus": "Element Plus Version",
|
|
||||||
"tdesign": "TDesign Vue Version"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,76 +0,0 @@
|
|||||||
{
|
|
||||||
"title": "Examples",
|
|
||||||
"modal": {
|
|
||||||
"title": "Modal"
|
|
||||||
},
|
|
||||||
"drawer": {
|
|
||||||
"title": "Drawer"
|
|
||||||
},
|
|
||||||
"ellipsis": {
|
|
||||||
"title": "EllipsisText"
|
|
||||||
},
|
|
||||||
"form": {
|
|
||||||
"title": "Form",
|
|
||||||
"basic": "Basic Form",
|
|
||||||
"layout": "Custom Layout",
|
|
||||||
"query": "Query Form",
|
|
||||||
"rules": "Form Rules",
|
|
||||||
"dynamic": "Dynamic Form",
|
|
||||||
"custom": "Custom Component",
|
|
||||||
"api": "Api",
|
|
||||||
"merge": "Merge Form",
|
|
||||||
"scrollToError": "Scroll to Error Field",
|
|
||||||
"upload-error": "Partial file upload failed",
|
|
||||||
"upload-urls": "Urls after file upload",
|
|
||||||
"file": "file",
|
|
||||||
"upload-image": "Click to upload image"
|
|
||||||
},
|
|
||||||
"vxeTable": {
|
|
||||||
"title": "Vxe Table",
|
|
||||||
"basic": "Basic Table",
|
|
||||||
"remote": "Remote Load",
|
|
||||||
"tree": "Tree Table",
|
|
||||||
"fixed": "Fixed Header/Column",
|
|
||||||
"virtual": "Virtual Scroll",
|
|
||||||
"editCell": "Edit Cell",
|
|
||||||
"editRow": "Edit Row",
|
|
||||||
"custom-cell": "Custom Cell",
|
|
||||||
"form": "Form Table"
|
|
||||||
},
|
|
||||||
"captcha": {
|
|
||||||
"title": "Captcha",
|
|
||||||
"pointSelection": "Point Selection Captcha",
|
|
||||||
"sliderCaptcha": "Slider Captcha",
|
|
||||||
"sliderRotateCaptcha": "Rotate Captcha",
|
|
||||||
"sliderTranslateCaptcha": "Translate Captcha",
|
|
||||||
"captchaCardTitle": "Please complete the security verification",
|
|
||||||
"pageDescription": "Verify user identity by clicking on specific locations in the image.",
|
|
||||||
"pageTitle": "Captcha Component Example",
|
|
||||||
"basic": "Basic Usage",
|
|
||||||
"titlePlaceholder": "Captcha Title Text",
|
|
||||||
"captchaImageUrlPlaceholder": "Captcha Image (supports img tag src attribute value)",
|
|
||||||
"hintImage": "Hint Image",
|
|
||||||
"hintText": "Hint Text",
|
|
||||||
"hintImagePlaceholder": "Hint Image (supports img tag src attribute value)",
|
|
||||||
"hintTextPlaceholder": "Hint Text",
|
|
||||||
"showConfirm": "Show Confirm",
|
|
||||||
"hideConfirm": "Hide Confirm",
|
|
||||||
"widthPlaceholder": "Captcha Image Width Default 300px",
|
|
||||||
"heightPlaceholder": "Captcha Image Height Default 220px",
|
|
||||||
"paddingXPlaceholder": "Horizontal Padding Default 12px",
|
|
||||||
"paddingYPlaceholder": "Vertical Padding Default 16px",
|
|
||||||
"index": "Index:",
|
|
||||||
"timestamp": "Timestamp:",
|
|
||||||
"x": "x:",
|
|
||||||
"y": "y:"
|
|
||||||
},
|
|
||||||
"resize": {
|
|
||||||
"title": "Resize"
|
|
||||||
},
|
|
||||||
"layout": {
|
|
||||||
"col-page": "ColPage Layout"
|
|
||||||
},
|
|
||||||
"button-group": {
|
|
||||||
"title": "Button Group"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
{
|
|
||||||
"auth": {
|
|
||||||
"login": "Login",
|
|
||||||
"register": "Register",
|
|
||||||
"codeLogin": "Code Login",
|
|
||||||
"qrcodeLogin": "Qr Code Login",
|
|
||||||
"forgetPassword": "Forget Password",
|
|
||||||
"sendingCode": "SMS Code is sending...",
|
|
||||||
"codeSentTo": "Code has been sent to {0}"
|
|
||||||
},
|
|
||||||
"dashboard": {
|
|
||||||
"title": "Dashboard",
|
|
||||||
"analytics": "Analytics",
|
|
||||||
"workspace": "Workspace"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
{
|
|
||||||
"title": "System Management",
|
|
||||||
"dept": {
|
|
||||||
"name": "Department",
|
|
||||||
"title": "Department Management",
|
|
||||||
"deptName": "Department Name",
|
|
||||||
"status": "Status",
|
|
||||||
"createTime": "Create Time",
|
|
||||||
"remark": "Remark",
|
|
||||||
"operation": "Operation",
|
|
||||||
"parentDept": "Parent Department"
|
|
||||||
},
|
|
||||||
"menu": {
|
|
||||||
"title": "Menu Management",
|
|
||||||
"parent": "Parent Menu",
|
|
||||||
"menuTitle": "Title",
|
|
||||||
"menuName": "Menu Name",
|
|
||||||
"name": "Menu",
|
|
||||||
"type": "Type",
|
|
||||||
"typeCatalog": "Catalog",
|
|
||||||
"typeMenu": "Menu",
|
|
||||||
"typeButton": "Button",
|
|
||||||
"typeLink": "Link",
|
|
||||||
"typeEmbedded": "Embedded",
|
|
||||||
"icon": "Icon",
|
|
||||||
"activeIcon": "Active Icon",
|
|
||||||
"activePath": "Active Path",
|
|
||||||
"path": "Route Path",
|
|
||||||
"component": "Component",
|
|
||||||
"status": "Status",
|
|
||||||
"authCode": "Auth Code",
|
|
||||||
"badge": "Badge",
|
|
||||||
"operation": "Operation",
|
|
||||||
"linkSrc": "Link Address",
|
|
||||||
"affixTab": "Affix In Tabs",
|
|
||||||
"keepAlive": "Keep Alive",
|
|
||||||
"hideInMenu": "Hide In Menu",
|
|
||||||
"hideInTab": "Hide In Tabbar",
|
|
||||||
"hideChildrenInMenu": "Hide Children In Menu",
|
|
||||||
"hideInBreadcrumb": "Hide In Breadcrumb",
|
|
||||||
"advancedSettings": "Other Settings",
|
|
||||||
"activePathMustExist": "The path could not find a valid menu",
|
|
||||||
"activePathHelp": "When jumping to the current route, \nthe menu path that needs to be activated must be specified when it does not display in the navigation menu.",
|
|
||||||
"badgeType": {
|
|
||||||
"title": "Badge Type",
|
|
||||||
"dot": "Dot",
|
|
||||||
"normal": "Text",
|
|
||||||
"none": "None"
|
|
||||||
},
|
|
||||||
"badgeVariants": "Badge Style"
|
|
||||||
},
|
|
||||||
"role": {
|
|
||||||
"title": "Role Management",
|
|
||||||
"list": "Role List",
|
|
||||||
"name": "Role",
|
|
||||||
"roleName": "Role Name",
|
|
||||||
"id": "Role ID",
|
|
||||||
"status": "Status",
|
|
||||||
"remark": "Remark",
|
|
||||||
"createTime": "Creation Time",
|
|
||||||
"operation": "Operation",
|
|
||||||
"permissions": "Permissions",
|
|
||||||
"setPermissions": "Permissions"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,72 +0,0 @@
|
|||||||
{
|
|
||||||
"title": "演示",
|
|
||||||
"access": {
|
|
||||||
"frontendPermissions": "前端权限",
|
|
||||||
"backendPermissions": "后端权限",
|
|
||||||
"pageAccess": "页面访问",
|
|
||||||
"buttonControl": "按钮控制",
|
|
||||||
"menuVisible403": "菜单可见(403)",
|
|
||||||
"superVisible": "Super 可见",
|
|
||||||
"adminVisible": "Admin 可见",
|
|
||||||
"userVisible": "User 可见"
|
|
||||||
},
|
|
||||||
"nested": {
|
|
||||||
"title": "嵌套菜单",
|
|
||||||
"menu1": "菜单 1",
|
|
||||||
"menu2": "菜单 2",
|
|
||||||
"menu2_1": "菜单 2-1",
|
|
||||||
"menu3": "菜单 3",
|
|
||||||
"menu3_1": "菜单 3-1",
|
|
||||||
"menu3_2": "菜单 3-2",
|
|
||||||
"menu3_2_1": "菜单 3-2-1"
|
|
||||||
},
|
|
||||||
"outside": {
|
|
||||||
"title": "外部页面",
|
|
||||||
"embedded": "内嵌",
|
|
||||||
"externalLink": "外链"
|
|
||||||
},
|
|
||||||
"badge": {
|
|
||||||
"title": "菜单徽标",
|
|
||||||
"dot": "点徽标",
|
|
||||||
"text": "文本徽标",
|
|
||||||
"color": "徽标颜色"
|
|
||||||
},
|
|
||||||
"activeIcon": {
|
|
||||||
"title": "菜单激活图标",
|
|
||||||
"children": "子级激活图标"
|
|
||||||
},
|
|
||||||
"fallback": {
|
|
||||||
"title": "缺省页"
|
|
||||||
},
|
|
||||||
"features": {
|
|
||||||
"title": "功能",
|
|
||||||
"hideChildrenInMenu": "隐藏子菜单",
|
|
||||||
"loginExpired": "登录过期",
|
|
||||||
"icons": "图标",
|
|
||||||
"watermark": "水印",
|
|
||||||
"tabs": "标签页",
|
|
||||||
"tabDetail": "标签详情页",
|
|
||||||
"fullScreen": "全屏",
|
|
||||||
"clipboard": "剪贴板",
|
|
||||||
"menuWithQuery": "带参菜单",
|
|
||||||
"openInNewWindow": "新窗口打开",
|
|
||||||
"fileDownload": "文件下载",
|
|
||||||
"requestParamsSerializer": "参数序列化"
|
|
||||||
},
|
|
||||||
"breadcrumb": {
|
|
||||||
"navigation": "面包屑导航",
|
|
||||||
"lateral": "平级模式",
|
|
||||||
"level": "层级模式",
|
|
||||||
"levelDetail": "层级模式详情",
|
|
||||||
"lateralDetail": "平级模式详情"
|
|
||||||
},
|
|
||||||
"vben": {
|
|
||||||
"title": "项目",
|
|
||||||
"about": "关于",
|
|
||||||
"document": "文档",
|
|
||||||
"antdv": "Ant Design Vue 版本",
|
|
||||||
"naive-ui": "Naive UI 版本",
|
|
||||||
"element-plus": "Element Plus 版本",
|
|
||||||
"tdesign": "TDesign Vue 版本"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,76 +0,0 @@
|
|||||||
{
|
|
||||||
"title": "示例",
|
|
||||||
"modal": {
|
|
||||||
"title": "弹窗"
|
|
||||||
},
|
|
||||||
"drawer": {
|
|
||||||
"title": "抽屉"
|
|
||||||
},
|
|
||||||
"ellipsis": {
|
|
||||||
"title": "文本省略"
|
|
||||||
},
|
|
||||||
"resize": {
|
|
||||||
"title": "拖动调整"
|
|
||||||
},
|
|
||||||
"form": {
|
|
||||||
"title": "表单",
|
|
||||||
"basic": "基础表单",
|
|
||||||
"layout": "自定义布局",
|
|
||||||
"query": "查询表单",
|
|
||||||
"rules": "表单校验",
|
|
||||||
"dynamic": "动态表单",
|
|
||||||
"custom": "自定义组件",
|
|
||||||
"api": "Api",
|
|
||||||
"merge": "合并表单",
|
|
||||||
"scrollToError": "滚动到错误字段",
|
|
||||||
"upload-error": "部分文件上传失败",
|
|
||||||
"upload-urls": "文件上传后的网址",
|
|
||||||
"file": "文件",
|
|
||||||
"upload-image": "点击上传图片"
|
|
||||||
},
|
|
||||||
"vxeTable": {
|
|
||||||
"title": "Vxe 表格",
|
|
||||||
"basic": "基础表格",
|
|
||||||
"remote": "远程加载",
|
|
||||||
"tree": "树形表格",
|
|
||||||
"fixed": "固定表头/列",
|
|
||||||
"virtual": "虚拟滚动",
|
|
||||||
"editCell": "单元格编辑",
|
|
||||||
"editRow": "行编辑",
|
|
||||||
"custom-cell": "自定义单元格",
|
|
||||||
"form": "搜索表单"
|
|
||||||
},
|
|
||||||
"captcha": {
|
|
||||||
"title": "验证码",
|
|
||||||
"pointSelection": "点选验证",
|
|
||||||
"sliderCaptcha": "滑块验证",
|
|
||||||
"sliderRotateCaptcha": "旋转验证",
|
|
||||||
"sliderTranslateCaptcha": "拼图滑块验证",
|
|
||||||
"captchaCardTitle": "请完成安全验证",
|
|
||||||
"pageDescription": "通过点击图片中的特定位置来验证用户身份。",
|
|
||||||
"pageTitle": "验证码组件示例",
|
|
||||||
"basic": "基本使用",
|
|
||||||
"titlePlaceholder": "验证码标题文案",
|
|
||||||
"captchaImageUrlPlaceholder": "验证码图片(支持img标签src属性值)",
|
|
||||||
"hintImage": "提示图片",
|
|
||||||
"hintText": "提示文本",
|
|
||||||
"hintImagePlaceholder": "提示图片(支持img标签src属性值)",
|
|
||||||
"hintTextPlaceholder": "提示文本",
|
|
||||||
"showConfirm": "展示确认",
|
|
||||||
"hideConfirm": "隐藏确认",
|
|
||||||
"widthPlaceholder": "验证码图片宽度 默认300px",
|
|
||||||
"heightPlaceholder": "验证码图片高度 默认220px",
|
|
||||||
"paddingXPlaceholder": "水平内边距 默认12px",
|
|
||||||
"paddingYPlaceholder": "垂直内边距 默认16px",
|
|
||||||
"index": "索引:",
|
|
||||||
"timestamp": "时间戳:",
|
|
||||||
"x": "x:",
|
|
||||||
"y": "y:"
|
|
||||||
},
|
|
||||||
"layout": {
|
|
||||||
"col-page": "双列布局"
|
|
||||||
},
|
|
||||||
"button-group": {
|
|
||||||
"title": "按钮组"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
{
|
|
||||||
"auth": {
|
|
||||||
"login": "登录",
|
|
||||||
"register": "注册",
|
|
||||||
"codeLogin": "验证码登录",
|
|
||||||
"qrcodeLogin": "二维码登录",
|
|
||||||
"forgetPassword": "忘记密码",
|
|
||||||
"sendingCode": "正在发送验证码",
|
|
||||||
"codeSentTo": "验证码已发送至{0}"
|
|
||||||
},
|
|
||||||
"dashboard": {
|
|
||||||
"title": "概览",
|
|
||||||
"analytics": "分析页",
|
|
||||||
"workspace": "工作台"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
{
|
|
||||||
"title": "系统管理",
|
|
||||||
"dept": {
|
|
||||||
"list": "部门列表",
|
|
||||||
"createTime": "创建时间",
|
|
||||||
"deptName": "部门名称",
|
|
||||||
"name": "部门",
|
|
||||||
"operation": "操作",
|
|
||||||
"parentDept": "上级部门",
|
|
||||||
"remark": "备注",
|
|
||||||
"status": "状态",
|
|
||||||
"title": "部门管理"
|
|
||||||
},
|
|
||||||
"menu": {
|
|
||||||
"list": "菜单列表",
|
|
||||||
"activeIcon": "激活图标",
|
|
||||||
"activePath": "激活路径",
|
|
||||||
"activePathHelp": "跳转到当前路由时,需要激活的菜单路径。\n当不在导航菜单中显示时,需要指定激活路径",
|
|
||||||
"activePathMustExist": "该路径未能找到有效的菜单",
|
|
||||||
"advancedSettings": "其它设置",
|
|
||||||
"affixTab": "固定在标签",
|
|
||||||
"authCode": "权限标识",
|
|
||||||
"badge": "徽章内容",
|
|
||||||
"badgeVariants": "徽标样式",
|
|
||||||
"badgeType": {
|
|
||||||
"dot": "点",
|
|
||||||
"none": "无",
|
|
||||||
"normal": "文字",
|
|
||||||
"title": "徽标类型"
|
|
||||||
},
|
|
||||||
"component": "页面组件",
|
|
||||||
"hideChildrenInMenu": "隐藏子菜单",
|
|
||||||
"hideInBreadcrumb": "在面包屑中隐藏",
|
|
||||||
"hideInMenu": "隐藏菜单",
|
|
||||||
"hideInTab": "在标签栏中隐藏",
|
|
||||||
"icon": "图标",
|
|
||||||
"keepAlive": "缓存标签页",
|
|
||||||
"linkSrc": "链接地址",
|
|
||||||
"menuName": "菜单名称",
|
|
||||||
"menuTitle": "标题",
|
|
||||||
"name": "菜单",
|
|
||||||
"operation": "操作",
|
|
||||||
"parent": "上级菜单",
|
|
||||||
"path": "路由地址",
|
|
||||||
"status": "状态",
|
|
||||||
"title": "菜单管理",
|
|
||||||
"type": "类型",
|
|
||||||
"typeButton": "按钮",
|
|
||||||
"typeCatalog": "目录",
|
|
||||||
"typeEmbedded": "内嵌",
|
|
||||||
"typeLink": "外链",
|
|
||||||
"typeMenu": "菜单"
|
|
||||||
},
|
|
||||||
"role": {
|
|
||||||
"title": "角色管理",
|
|
||||||
"list": "角色列表",
|
|
||||||
"name": "角色",
|
|
||||||
"roleName": "角色名称",
|
|
||||||
"id": "角色ID",
|
|
||||||
"status": "状态",
|
|
||||||
"remark": "备注",
|
|
||||||
"createTime": "创建时间",
|
|
||||||
"operation": "操作",
|
|
||||||
"permissions": "权限",
|
|
||||||
"setPermissions": "授权"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
import { initPreferences } from '@vben/preferences';
|
|
||||||
import { unmountGlobalLoading } from '@vben/utils';
|
|
||||||
|
|
||||||
import { overridesPreferences } from './preferences';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 应用初始化完成之后再进行页面加载渲染
|
|
||||||
*/
|
|
||||||
async function initApplication() {
|
|
||||||
// name用于指定项目唯一标识
|
|
||||||
// 用于区分不同项目的偏好设置以及存储数据的key前缀以及其他一些需要隔离的数据
|
|
||||||
const env = import.meta.env.PROD ? 'prod' : 'dev';
|
|
||||||
const appVersion = import.meta.env.VITE_APP_VERSION;
|
|
||||||
const namespace = `${import.meta.env.VITE_APP_NAMESPACE}-${appVersion}-${env}`;
|
|
||||||
|
|
||||||
// app偏好设置初始化
|
|
||||||
await initPreferences({
|
|
||||||
namespace,
|
|
||||||
overrides: overridesPreferences,
|
|
||||||
});
|
|
||||||
|
|
||||||
// 启动应用并挂载
|
|
||||||
// vue应用主要逻辑及视图
|
|
||||||
const { bootstrap } = await import('./bootstrap');
|
|
||||||
await bootstrap(namespace);
|
|
||||||
|
|
||||||
// 移除并销毁loading
|
|
||||||
unmountGlobalLoading();
|
|
||||||
}
|
|
||||||
|
|
||||||
initApplication();
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
import { defineOverridesPreferences } from '@vben/preferences';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description 项目配置文件
|
|
||||||
* 只需要覆盖项目中的一部分配置,不需要的配置不用覆盖,会自动使用默认配置
|
|
||||||
* !!! 更改配置后请清空缓存,否则可能不生效
|
|
||||||
*/
|
|
||||||
export const overridesPreferences = defineOverridesPreferences({
|
|
||||||
// overrides
|
|
||||||
app: {
|
|
||||||
name: import.meta.env.VITE_APP_TITLE,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
import type {
|
|
||||||
ComponentRecordType,
|
|
||||||
GenerateMenuAndRoutesOptions,
|
|
||||||
} from '@vben/types';
|
|
||||||
|
|
||||||
import { generateAccessible } from '@vben/access';
|
|
||||||
import { preferences } from '@vben/preferences';
|
|
||||||
|
|
||||||
import { message } from 'ant-design-vue';
|
|
||||||
|
|
||||||
import { getAllMenusApi } from '#/api';
|
|
||||||
import { BasicLayout, IFrameView } from '#/layouts';
|
|
||||||
import { $t } from '#/locales';
|
|
||||||
|
|
||||||
const forbiddenComponent = () => import('#/views/_core/fallback/forbidden.vue');
|
|
||||||
|
|
||||||
async function generateAccess(options: GenerateMenuAndRoutesOptions) {
|
|
||||||
const pageMap: ComponentRecordType = import.meta.glob('../views/**/*.vue');
|
|
||||||
|
|
||||||
const layoutMap: ComponentRecordType = {
|
|
||||||
BasicLayout,
|
|
||||||
IFrameView,
|
|
||||||
};
|
|
||||||
|
|
||||||
return await generateAccessible(preferences.app.accessMode, {
|
|
||||||
...options,
|
|
||||||
fetchMenuListAsync: async () => {
|
|
||||||
message.loading({
|
|
||||||
content: `${$t('common.loadingMenu')}...`,
|
|
||||||
duration: 1.5,
|
|
||||||
});
|
|
||||||
return await getAllMenusApi();
|
|
||||||
},
|
|
||||||
// 可以指定没有权限跳转403页面
|
|
||||||
forbiddenComponent,
|
|
||||||
// 如果 route.meta.menuVisibleWithForbidden = true
|
|
||||||
layoutMap,
|
|
||||||
pageMap,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export { generateAccess };
|
|
||||||
@@ -1,136 +0,0 @@
|
|||||||
import type { Router } from 'vue-router';
|
|
||||||
|
|
||||||
import { LOGIN_PATH } from '@vben/constants';
|
|
||||||
import { preferences } from '@vben/preferences';
|
|
||||||
import { useAccessStore, useUserStore } from '@vben/stores';
|
|
||||||
import { startProgress, stopProgress } from '@vben/utils';
|
|
||||||
|
|
||||||
import { accessRoutes, coreRouteNames } from '#/router/routes';
|
|
||||||
import { useAuthStore } from '#/store';
|
|
||||||
|
|
||||||
import { generateAccess } from './access';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 通用守卫配置
|
|
||||||
* @param router
|
|
||||||
*/
|
|
||||||
function setupCommonGuard(router: Router) {
|
|
||||||
// 记录已经加载的页面
|
|
||||||
const loadedPaths = new Set<string>();
|
|
||||||
|
|
||||||
router.beforeEach((to) => {
|
|
||||||
to.meta.loaded = loadedPaths.has(to.path);
|
|
||||||
|
|
||||||
// 页面加载进度条
|
|
||||||
if (!to.meta.loaded && preferences.transition.progress) {
|
|
||||||
startProgress();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
|
|
||||||
router.afterEach((to) => {
|
|
||||||
// 记录页面是否加载,如果已经加载,后续的页面切换动画等效果不在重复执行
|
|
||||||
loadedPaths.add(to.path);
|
|
||||||
|
|
||||||
// 关闭页面加载进度条
|
|
||||||
if (preferences.transition.progress) {
|
|
||||||
stopProgress();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 权限访问守卫配置
|
|
||||||
* @param router
|
|
||||||
*/
|
|
||||||
function setupAccessGuard(router: Router) {
|
|
||||||
router.beforeEach(async (to, from) => {
|
|
||||||
const accessStore = useAccessStore();
|
|
||||||
const userStore = useUserStore();
|
|
||||||
const authStore = useAuthStore();
|
|
||||||
// 基本路由,这些路由不需要进入权限拦截
|
|
||||||
if (coreRouteNames.includes(to.name as string)) {
|
|
||||||
if (to.path === LOGIN_PATH && accessStore.accessToken) {
|
|
||||||
return decodeURIComponent(
|
|
||||||
(to.query?.redirect as string) ||
|
|
||||||
userStore.userInfo?.homePath ||
|
|
||||||
preferences.app.defaultHomePath,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// accessToken 检查
|
|
||||||
if (!accessStore.accessToken) {
|
|
||||||
// 明确声明忽略权限访问权限,则可以访问
|
|
||||||
if (to.meta.ignoreAccess) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 没有访问权限,跳转登录页面
|
|
||||||
if (to.fullPath !== LOGIN_PATH) {
|
|
||||||
return {
|
|
||||||
path: LOGIN_PATH,
|
|
||||||
// 如不需要,直接删除 query
|
|
||||||
query:
|
|
||||||
to.fullPath === preferences.app.defaultHomePath
|
|
||||||
? {}
|
|
||||||
: { redirect: encodeURIComponent(to.fullPath) },
|
|
||||||
// 携带当前跳转的页面,登录后重新跳转该页面
|
|
||||||
replace: true,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return to;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 是否已经生成过动态路由
|
|
||||||
if (accessStore.isAccessChecked) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 生成路由表
|
|
||||||
// 当前登录用户拥有的角色标识列表
|
|
||||||
const userInfo = userStore.userInfo || (await authStore.fetchUserInfo());
|
|
||||||
const userRoles = userInfo.roles ?? [];
|
|
||||||
|
|
||||||
// 生成菜单和路由
|
|
||||||
const { accessibleMenus, accessibleRoutes } = await generateAccess({
|
|
||||||
roles: userRoles,
|
|
||||||
router,
|
|
||||||
// 则会在菜单中显示,但是访问会被重定向到403
|
|
||||||
routes: accessRoutes,
|
|
||||||
});
|
|
||||||
|
|
||||||
// 保存菜单信息和路由信息
|
|
||||||
accessStore.setAccessMenus(accessibleMenus);
|
|
||||||
accessStore.setAccessRoutes(accessibleRoutes);
|
|
||||||
accessStore.setIsAccessChecked(true);
|
|
||||||
let redirectPath: string;
|
|
||||||
if (from.query.redirect) {
|
|
||||||
redirectPath = from.query.redirect as string;
|
|
||||||
} else if (to.path === preferences.app.defaultHomePath) {
|
|
||||||
redirectPath = preferences.app.defaultHomePath;
|
|
||||||
} else if (userInfo.homePath && to.path === userInfo.homePath) {
|
|
||||||
redirectPath = userInfo.homePath;
|
|
||||||
} else {
|
|
||||||
redirectPath = to.fullPath;
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
...router.resolve(decodeURIComponent(redirectPath)),
|
|
||||||
replace: true,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 项目守卫配置
|
|
||||||
* @param router
|
|
||||||
*/
|
|
||||||
function createRouterGuard(router: Router) {
|
|
||||||
/** 通用 */
|
|
||||||
setupCommonGuard(router);
|
|
||||||
/** 权限访问 */
|
|
||||||
setupAccessGuard(router);
|
|
||||||
}
|
|
||||||
|
|
||||||
export { createRouterGuard };
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
import {
|
|
||||||
createRouter,
|
|
||||||
createWebHashHistory,
|
|
||||||
createWebHistory,
|
|
||||||
} from 'vue-router';
|
|
||||||
|
|
||||||
import { resetStaticRoutes } from '@vben/utils';
|
|
||||||
|
|
||||||
import { createRouterGuard } from './guard';
|
|
||||||
import { routes } from './routes';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @zh_CN 创建vue-router实例
|
|
||||||
*/
|
|
||||||
const router = createRouter({
|
|
||||||
history:
|
|
||||||
import.meta.env.VITE_ROUTER_HISTORY === 'hash'
|
|
||||||
? createWebHashHistory(import.meta.env.VITE_BASE)
|
|
||||||
: createWebHistory(import.meta.env.VITE_BASE),
|
|
||||||
// 应该添加到路由的初始路由列表。
|
|
||||||
routes,
|
|
||||||
scrollBehavior: (to, _from, savedPosition) => {
|
|
||||||
if (savedPosition) {
|
|
||||||
return savedPosition;
|
|
||||||
}
|
|
||||||
return to.hash ? { behavior: 'smooth', el: to.hash } : { left: 0, top: 0 };
|
|
||||||
},
|
|
||||||
// 是否应该禁止尾部斜杠。
|
|
||||||
// strict: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
const resetRoutes = () => resetStaticRoutes(router, routes);
|
|
||||||
|
|
||||||
// 创建路由守卫
|
|
||||||
createRouterGuard(router);
|
|
||||||
|
|
||||||
export { resetRoutes, router };
|
|
||||||
@@ -1,97 +0,0 @@
|
|||||||
import type { RouteRecordRaw } from 'vue-router';
|
|
||||||
|
|
||||||
import { LOGIN_PATH } from '@vben/constants';
|
|
||||||
import { preferences } from '@vben/preferences';
|
|
||||||
|
|
||||||
import { $t } from '#/locales';
|
|
||||||
|
|
||||||
const BasicLayout = () => import('#/layouts/basic.vue');
|
|
||||||
const AuthPageLayout = () => import('#/layouts/auth.vue');
|
|
||||||
/** 全局404页面 */
|
|
||||||
const fallbackNotFoundRoute: RouteRecordRaw = {
|
|
||||||
component: () => import('#/views/_core/fallback/not-found.vue'),
|
|
||||||
meta: {
|
|
||||||
hideInBreadcrumb: true,
|
|
||||||
hideInMenu: true,
|
|
||||||
hideInTab: true,
|
|
||||||
title: '404',
|
|
||||||
},
|
|
||||||
name: 'FallbackNotFound',
|
|
||||||
path: '/:path(.*)*',
|
|
||||||
};
|
|
||||||
|
|
||||||
/** 基本路由,这些路由是必须存在的 */
|
|
||||||
const coreRoutes: RouteRecordRaw[] = [
|
|
||||||
/**
|
|
||||||
* 根路由
|
|
||||||
* 使用基础布局,作为所有页面的父级容器,子级就不必配置BasicLayout。
|
|
||||||
* 此路由必须存在,且不应修改
|
|
||||||
*/
|
|
||||||
{
|
|
||||||
component: BasicLayout,
|
|
||||||
meta: {
|
|
||||||
hideInBreadcrumb: true,
|
|
||||||
title: 'Root',
|
|
||||||
},
|
|
||||||
name: 'Root',
|
|
||||||
path: '/',
|
|
||||||
redirect: preferences.app.defaultHomePath,
|
|
||||||
children: [],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
component: AuthPageLayout,
|
|
||||||
meta: {
|
|
||||||
hideInTab: true,
|
|
||||||
title: 'Authentication',
|
|
||||||
},
|
|
||||||
name: 'Authentication',
|
|
||||||
path: '/auth',
|
|
||||||
redirect: LOGIN_PATH,
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
name: 'Login',
|
|
||||||
path: 'login',
|
|
||||||
component: () => import('#/views/_core/authentication/login.vue'),
|
|
||||||
meta: {
|
|
||||||
title: $t('page.auth.login'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'CodeLogin',
|
|
||||||
path: 'code-login',
|
|
||||||
component: () => import('#/views/_core/authentication/code-login.vue'),
|
|
||||||
meta: {
|
|
||||||
title: $t('page.auth.codeLogin'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'QrCodeLogin',
|
|
||||||
path: 'qrcode-login',
|
|
||||||
component: () =>
|
|
||||||
import('#/views/_core/authentication/qrcode-login.vue'),
|
|
||||||
meta: {
|
|
||||||
title: $t('page.auth.qrcodeLogin'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'ForgetPassword',
|
|
||||||
path: 'forget-password',
|
|
||||||
component: () =>
|
|
||||||
import('#/views/_core/authentication/forget-password.vue'),
|
|
||||||
meta: {
|
|
||||||
title: $t('page.auth.forgetPassword'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Register',
|
|
||||||
path: 'register',
|
|
||||||
component: () => import('#/views/_core/authentication/register.vue'),
|
|
||||||
meta: {
|
|
||||||
title: $t('page.auth.register'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
export { coreRoutes, fallbackNotFoundRoute };
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
import type { RouteRecordRaw } from 'vue-router';
|
|
||||||
|
|
||||||
import { mergeRouteModules, traverseTreeValues } from '@vben/utils';
|
|
||||||
|
|
||||||
import { coreRoutes, fallbackNotFoundRoute } from './core';
|
|
||||||
|
|
||||||
const dynamicRouteFiles = import.meta.glob('./modules/**/*.ts', {
|
|
||||||
eager: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
// 有需要可以自行打开注释,并创建文件夹
|
|
||||||
// const externalRouteFiles = import.meta.glob('./external/**/*.ts', { eager: true });
|
|
||||||
// const staticRouteFiles = import.meta.glob('./static/**/*.ts', { eager: true });
|
|
||||||
|
|
||||||
/** 动态路由 */
|
|
||||||
const dynamicRoutes: RouteRecordRaw[] = mergeRouteModules(dynamicRouteFiles);
|
|
||||||
|
|
||||||
/** 外部路由列表,访问这些页面可以不需要Layout,可能用于内嵌在别的系统(不会显示在菜单中) */
|
|
||||||
// const externalRoutes: RouteRecordRaw[] = mergeRouteModules(externalRouteFiles);
|
|
||||||
// const staticRoutes: RouteRecordRaw[] = mergeRouteModules(staticRouteFiles);
|
|
||||||
const staticRoutes: RouteRecordRaw[] = [];
|
|
||||||
const externalRoutes: RouteRecordRaw[] = [];
|
|
||||||
|
|
||||||
/** 路由列表,由基本路由、外部路由和404兜底路由组成
|
|
||||||
* 无需走权限验证(会一直显示在菜单中) */
|
|
||||||
const routes: RouteRecordRaw[] = [
|
|
||||||
...coreRoutes,
|
|
||||||
...externalRoutes,
|
|
||||||
fallbackNotFoundRoute,
|
|
||||||
];
|
|
||||||
|
|
||||||
/** 基本路由列表,这些路由不需要进入权限拦截 */
|
|
||||||
const coreRouteNames = traverseTreeValues(coreRoutes, (route) => route.name);
|
|
||||||
|
|
||||||
/** 有权限校验的路由列表,包含动态路由和静态路由 */
|
|
||||||
const accessRoutes = [...dynamicRoutes, ...staticRoutes];
|
|
||||||
|
|
||||||
const componentKeys: string[] = Object.keys(
|
|
||||||
import.meta.glob('../../views/**/*.vue'),
|
|
||||||
)
|
|
||||||
.filter((item) => !item.includes('/modules/'))
|
|
||||||
.map((v) => {
|
|
||||||
const path = v.replace('../../views/', '/');
|
|
||||||
return path.endsWith('.vue') ? path.slice(0, -4) : path;
|
|
||||||
});
|
|
||||||
|
|
||||||
export { accessRoutes, componentKeys, coreRouteNames, routes };
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
import type { RouteRecordRaw } from 'vue-router';
|
|
||||||
|
|
||||||
import { $t } from '#/locales';
|
|
||||||
|
|
||||||
const routes: RouteRecordRaw[] = [
|
|
||||||
{
|
|
||||||
meta: {
|
|
||||||
icon: 'lucide:layout-dashboard',
|
|
||||||
order: -1,
|
|
||||||
title: $t('page.dashboard.title'),
|
|
||||||
},
|
|
||||||
name: 'Dashboard',
|
|
||||||
path: '/dashboard',
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
name: 'Analytics',
|
|
||||||
path: '/analytics',
|
|
||||||
component: () => import('#/views/dashboard/analytics/index.vue'),
|
|
||||||
meta: {
|
|
||||||
affixTab: true,
|
|
||||||
icon: 'lucide:area-chart',
|
|
||||||
title: $t('page.dashboard.analytics'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Workspace',
|
|
||||||
path: '/workspace',
|
|
||||||
component: () => import('#/views/dashboard/workspace/index.vue'),
|
|
||||||
meta: {
|
|
||||||
icon: 'carbon:workspace',
|
|
||||||
title: $t('page.dashboard.workspace'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
export default routes;
|
|
||||||
@@ -1,594 +0,0 @@
|
|||||||
import type { RouteRecordRaw } from 'vue-router';
|
|
||||||
|
|
||||||
import { IFrameView } from '#/layouts';
|
|
||||||
import { $t } from '#/locales';
|
|
||||||
|
|
||||||
const routes: RouteRecordRaw[] = [
|
|
||||||
{
|
|
||||||
meta: {
|
|
||||||
icon: 'ic:baseline-view-in-ar',
|
|
||||||
keepAlive: true,
|
|
||||||
order: 1000,
|
|
||||||
title: $t('demos.title'),
|
|
||||||
},
|
|
||||||
name: 'Demos',
|
|
||||||
path: '/demos',
|
|
||||||
children: [
|
|
||||||
// 权限控制
|
|
||||||
{
|
|
||||||
meta: {
|
|
||||||
icon: 'mdi:shield-key-outline',
|
|
||||||
title: $t('demos.access.frontendPermissions'),
|
|
||||||
},
|
|
||||||
name: 'AccessDemos',
|
|
||||||
path: '/demos/access',
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
name: 'AccessPageControlDemo',
|
|
||||||
path: '/demos/access/page-control',
|
|
||||||
component: () => import('#/views/demos/access/index.vue'),
|
|
||||||
meta: {
|
|
||||||
icon: 'mdi:page-previous-outline',
|
|
||||||
title: $t('demos.access.pageAccess'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'AccessButtonControlDemo',
|
|
||||||
path: '/demos/access/button-control',
|
|
||||||
component: () => import('#/views/demos/access/button-control.vue'),
|
|
||||||
meta: {
|
|
||||||
icon: 'mdi:button-cursor',
|
|
||||||
title: $t('demos.access.buttonControl'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'AccessMenuVisible403Demo',
|
|
||||||
path: '/demos/access/menu-visible-403',
|
|
||||||
component: () =>
|
|
||||||
import('#/views/demos/access/menu-visible-403.vue'),
|
|
||||||
meta: {
|
|
||||||
authority: ['no-body'],
|
|
||||||
icon: 'mdi:button-cursor',
|
|
||||||
menuVisibleWithForbidden: true,
|
|
||||||
title: $t('demos.access.menuVisible403'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'AccessSuperVisibleDemo',
|
|
||||||
path: '/demos/access/super-visible',
|
|
||||||
component: () => import('#/views/demos/access/super-visible.vue'),
|
|
||||||
meta: {
|
|
||||||
authority: ['super'],
|
|
||||||
icon: 'mdi:button-cursor',
|
|
||||||
title: $t('demos.access.superVisible'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'AccessAdminVisibleDemo',
|
|
||||||
path: '/demos/access/admin-visible',
|
|
||||||
component: () => import('#/views/demos/access/admin-visible.vue'),
|
|
||||||
meta: {
|
|
||||||
authority: ['admin'],
|
|
||||||
icon: 'mdi:button-cursor',
|
|
||||||
title: $t('demos.access.adminVisible'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'AccessUserVisibleDemo',
|
|
||||||
path: '/demos/access/user-visible',
|
|
||||||
component: () => import('#/views/demos/access/user-visible.vue'),
|
|
||||||
meta: {
|
|
||||||
authority: ['user'],
|
|
||||||
icon: 'mdi:button-cursor',
|
|
||||||
title: $t('demos.access.userVisible'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
// 功能
|
|
||||||
{
|
|
||||||
meta: {
|
|
||||||
icon: 'mdi:feature-highlight',
|
|
||||||
title: $t('demos.features.title'),
|
|
||||||
},
|
|
||||||
name: 'FeaturesDemos',
|
|
||||||
path: '/demos/features',
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
name: 'LoginExpiredDemo',
|
|
||||||
path: '/demos/features/login-expired',
|
|
||||||
component: () =>
|
|
||||||
import('#/views/demos/features/login-expired/index.vue'),
|
|
||||||
meta: {
|
|
||||||
icon: 'mdi:encryption-expiration',
|
|
||||||
title: $t('demos.features.loginExpired'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'IconsDemo',
|
|
||||||
path: '/demos/features/icons',
|
|
||||||
component: () => import('#/views/demos/features/icons/index.vue'),
|
|
||||||
meta: {
|
|
||||||
icon: 'lucide:annoyed',
|
|
||||||
title: $t('demos.features.icons'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'WatermarkDemo',
|
|
||||||
path: '/demos/features/watermark',
|
|
||||||
component: () =>
|
|
||||||
import('#/views/demos/features/watermark/index.vue'),
|
|
||||||
meta: {
|
|
||||||
icon: 'lucide:tags',
|
|
||||||
title: $t('demos.features.watermark'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'FeatureTabsDemo',
|
|
||||||
path: '/demos/features/tabs',
|
|
||||||
component: () => import('#/views/demos/features/tabs/index.vue'),
|
|
||||||
meta: {
|
|
||||||
icon: 'lucide:app-window',
|
|
||||||
title: $t('demos.features.tabs'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'FeatureTabDetailDemo',
|
|
||||||
path: '/demos/features/tabs/detail/:id',
|
|
||||||
component: () =>
|
|
||||||
import('#/views/demos/features/tabs/tab-detail.vue'),
|
|
||||||
meta: {
|
|
||||||
activePath: '/demos/features/tabs',
|
|
||||||
hideInMenu: true,
|
|
||||||
maxNumOfOpenTab: 3,
|
|
||||||
title: $t('demos.features.tabDetail'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'HideChildrenInMenuParentDemo',
|
|
||||||
path: '/demos/features/hide-menu-children',
|
|
||||||
meta: {
|
|
||||||
hideChildrenInMenu: true,
|
|
||||||
icon: 'ic:round-menu',
|
|
||||||
title: $t('demos.features.hideChildrenInMenu'),
|
|
||||||
},
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
name: 'HideChildrenInMenuDemo',
|
|
||||||
path: '',
|
|
||||||
component: () =>
|
|
||||||
import(
|
|
||||||
'#/views/demos/features/hide-menu-children/parent.vue'
|
|
||||||
),
|
|
||||||
meta: {
|
|
||||||
// hideInMenu: true,
|
|
||||||
title: $t('demos.features.hideChildrenInMenu'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'HideChildrenInMenuChildrenDemo',
|
|
||||||
path: '/demos/features/hide-menu-children/children',
|
|
||||||
component: () =>
|
|
||||||
import(
|
|
||||||
'#/views/demos/features/hide-menu-children/children.vue'
|
|
||||||
),
|
|
||||||
meta: {
|
|
||||||
activePath: '/demos/features/hide-menu-children',
|
|
||||||
title: $t('demos.features.hideChildrenInMenu'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'FullScreenDemo',
|
|
||||||
path: '/demos/features/full-screen',
|
|
||||||
component: () =>
|
|
||||||
import('#/views/demos/features/full-screen/index.vue'),
|
|
||||||
meta: {
|
|
||||||
icon: 'lucide:fullscreen',
|
|
||||||
title: $t('demos.features.fullScreen'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'FileDownloadDemo',
|
|
||||||
path: '/demos/features/file-download',
|
|
||||||
component: () =>
|
|
||||||
import('#/views/demos/features/file-download/index.vue'),
|
|
||||||
meta: {
|
|
||||||
icon: 'lucide:hard-drive-download',
|
|
||||||
title: $t('demos.features.fileDownload'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'ClipboardDemo',
|
|
||||||
path: '/demos/features/clipboard',
|
|
||||||
component: () =>
|
|
||||||
import('#/views/demos/features/clipboard/index.vue'),
|
|
||||||
meta: {
|
|
||||||
icon: 'lucide:copy',
|
|
||||||
title: $t('demos.features.clipboard'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'MenuQueryDemo',
|
|
||||||
path: '/demos/menu-query',
|
|
||||||
component: () =>
|
|
||||||
import('#/views/demos/features/menu-query/index.vue'),
|
|
||||||
meta: {
|
|
||||||
icon: 'lucide:curly-braces',
|
|
||||||
query: {
|
|
||||||
id: 1,
|
|
||||||
},
|
|
||||||
title: $t('demos.features.menuWithQuery'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'NewWindowDemo',
|
|
||||||
path: '/demos/new-window',
|
|
||||||
component: () =>
|
|
||||||
import('#/views/demos/features/new-window/index.vue'),
|
|
||||||
meta: {
|
|
||||||
icon: 'lucide:app-window',
|
|
||||||
openInNewWindow: true,
|
|
||||||
title: $t('demos.features.openInNewWindow'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'VueQueryDemo',
|
|
||||||
path: '/demos/features/vue-query',
|
|
||||||
component: () =>
|
|
||||||
import('#/views/demos/features/vue-query/index.vue'),
|
|
||||||
meta: {
|
|
||||||
icon: 'lucide:git-pull-request-arrow',
|
|
||||||
title: 'Tanstack Query',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'RequestParamsSerializerDemo',
|
|
||||||
path: '/demos/features/request-params-serializer',
|
|
||||||
component: () =>
|
|
||||||
import(
|
|
||||||
'#/views/demos/features/request-params-serializer/index.vue'
|
|
||||||
),
|
|
||||||
meta: {
|
|
||||||
icon: 'lucide:git-pull-request-arrow',
|
|
||||||
title: $t('demos.features.requestParamsSerializer'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'BigIntDemo',
|
|
||||||
path: '/demos/features/json-bigint',
|
|
||||||
component: () =>
|
|
||||||
import('#/views/demos/features/json-bigint/index.vue'),
|
|
||||||
meta: {
|
|
||||||
icon: 'lucide:grape',
|
|
||||||
title: 'JSON BigInt',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
// 面包屑导航
|
|
||||||
{
|
|
||||||
name: 'BreadcrumbDemos',
|
|
||||||
path: '/demos/breadcrumb',
|
|
||||||
meta: {
|
|
||||||
icon: 'lucide:navigation',
|
|
||||||
title: $t('demos.breadcrumb.navigation'),
|
|
||||||
},
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
name: 'BreadcrumbLateralDemo',
|
|
||||||
path: '/demos/breadcrumb/lateral',
|
|
||||||
component: () => import('#/views/demos/breadcrumb/lateral.vue'),
|
|
||||||
meta: {
|
|
||||||
icon: 'lucide:navigation',
|
|
||||||
title: $t('demos.breadcrumb.lateral'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'BreadcrumbLateralDetailDemo',
|
|
||||||
path: '/demos/breadcrumb/lateral-detail',
|
|
||||||
component: () =>
|
|
||||||
import('#/views/demos/breadcrumb/lateral-detail.vue'),
|
|
||||||
meta: {
|
|
||||||
activePath: '/demos/breadcrumb/lateral',
|
|
||||||
hideInMenu: true,
|
|
||||||
title: $t('demos.breadcrumb.lateralDetail'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'BreadcrumbLevelDemo',
|
|
||||||
path: '/demos/breadcrumb/level',
|
|
||||||
meta: {
|
|
||||||
icon: 'lucide:navigation',
|
|
||||||
title: $t('demos.breadcrumb.level'),
|
|
||||||
},
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
name: 'BreadcrumbLevelDetailDemo',
|
|
||||||
path: '/demos/breadcrumb/level/detail',
|
|
||||||
component: () =>
|
|
||||||
import('#/views/demos/breadcrumb/level-detail.vue'),
|
|
||||||
meta: {
|
|
||||||
title: $t('demos.breadcrumb.levelDetail'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
// 缺省页
|
|
||||||
{
|
|
||||||
meta: {
|
|
||||||
icon: 'mdi:lightbulb-error-outline',
|
|
||||||
title: $t('demos.fallback.title'),
|
|
||||||
},
|
|
||||||
name: 'FallbackDemos',
|
|
||||||
path: '/demos/fallback',
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
name: 'Fallback403Demo',
|
|
||||||
path: '/demos/fallback/403',
|
|
||||||
component: () => import('#/views/_core/fallback/forbidden.vue'),
|
|
||||||
meta: {
|
|
||||||
icon: 'mdi:do-not-disturb-alt',
|
|
||||||
title: '403',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Fallback404Demo',
|
|
||||||
path: '/demos/fallback/404',
|
|
||||||
component: () => import('#/views/_core/fallback/not-found.vue'),
|
|
||||||
meta: {
|
|
||||||
icon: 'mdi:table-off',
|
|
||||||
title: '404',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Fallback500Demo',
|
|
||||||
path: '/demos/fallback/500',
|
|
||||||
component: () =>
|
|
||||||
import('#/views/_core/fallback/internal-error.vue'),
|
|
||||||
meta: {
|
|
||||||
icon: 'mdi:server-network-off',
|
|
||||||
title: '500',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'FallbackOfflineDemo',
|
|
||||||
path: '/demos/fallback/offline',
|
|
||||||
component: () => import('#/views/_core/fallback/offline.vue'),
|
|
||||||
meta: {
|
|
||||||
icon: 'mdi:offline',
|
|
||||||
title: $t('ui.fallback.offline'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
// 菜单徽标
|
|
||||||
{
|
|
||||||
meta: {
|
|
||||||
badgeType: 'dot',
|
|
||||||
badgeVariants: 'destructive',
|
|
||||||
icon: 'lucide:circle-dot',
|
|
||||||
title: $t('demos.badge.title'),
|
|
||||||
},
|
|
||||||
name: 'BadgeDemos',
|
|
||||||
path: '/demos/badge',
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
name: 'BadgeDotDemo',
|
|
||||||
component: () => import('#/views/demos/badge/index.vue'),
|
|
||||||
path: '/demos/badge/dot',
|
|
||||||
meta: {
|
|
||||||
badgeType: 'dot',
|
|
||||||
icon: 'lucide:square-dot',
|
|
||||||
title: $t('demos.badge.dot'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'BadgeTextDemo',
|
|
||||||
component: () => import('#/views/demos/badge/index.vue'),
|
|
||||||
path: '/demos/badge/text',
|
|
||||||
meta: {
|
|
||||||
badge: '10',
|
|
||||||
icon: 'lucide:square-dot',
|
|
||||||
title: $t('demos.badge.text'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'BadgeColorDemo',
|
|
||||||
component: () => import('#/views/demos/badge/index.vue'),
|
|
||||||
path: '/demos/badge/color',
|
|
||||||
meta: {
|
|
||||||
badge: 'Hot',
|
|
||||||
badgeVariants: 'destructive',
|
|
||||||
icon: 'lucide:square-dot',
|
|
||||||
title: $t('demos.badge.color'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
// 菜单激活图标
|
|
||||||
{
|
|
||||||
meta: {
|
|
||||||
activeIcon: 'fluent-emoji:radioactive',
|
|
||||||
icon: 'bi:radioactive',
|
|
||||||
title: $t('demos.activeIcon.title'),
|
|
||||||
},
|
|
||||||
name: 'ActiveIconDemos',
|
|
||||||
path: '/demos/active-icon',
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
name: 'ActiveIconDemo',
|
|
||||||
component: () => import('#/views/demos/active-icon/index.vue'),
|
|
||||||
path: '/demos/active-icon/children',
|
|
||||||
meta: {
|
|
||||||
activeIcon: 'fluent-emoji:radioactive',
|
|
||||||
icon: 'bi:radioactive',
|
|
||||||
title: $t('demos.activeIcon.children'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
// 外部链接
|
|
||||||
{
|
|
||||||
meta: {
|
|
||||||
icon: 'ic:round-settings-input-composite',
|
|
||||||
title: $t('demos.outside.title'),
|
|
||||||
},
|
|
||||||
name: 'OutsideDemos',
|
|
||||||
path: '/demos/outside',
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
name: 'IframeDemos',
|
|
||||||
path: '/demos/outside/iframe',
|
|
||||||
meta: {
|
|
||||||
icon: 'mdi:newspaper-variant-outline',
|
|
||||||
title: $t('demos.outside.embedded'),
|
|
||||||
},
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
name: 'VueDocumentDemo',
|
|
||||||
path: '/demos/outside/iframe/vue-document',
|
|
||||||
component: IFrameView,
|
|
||||||
meta: {
|
|
||||||
icon: 'logos:vue',
|
|
||||||
iframeSrc: 'https://cn.vuejs.org/',
|
|
||||||
keepAlive: true,
|
|
||||||
title: 'Vue',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'TailwindcssDemo',
|
|
||||||
path: '/demos/outside/iframe/tailwindcss',
|
|
||||||
component: IFrameView,
|
|
||||||
meta: {
|
|
||||||
icon: 'devicon:tailwindcss',
|
|
||||||
iframeSrc: 'https://tailwindcss.com/',
|
|
||||||
// keepAlive: true,
|
|
||||||
title: 'Tailwindcss',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'ExternalLinkDemos',
|
|
||||||
path: '/demos/outside/external-link',
|
|
||||||
meta: {
|
|
||||||
icon: 'mdi:newspaper-variant-multiple-outline',
|
|
||||||
title: $t('demos.outside.externalLink'),
|
|
||||||
},
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
name: 'ViteDemo',
|
|
||||||
path: '/demos/outside/external-link/vite',
|
|
||||||
component: IFrameView,
|
|
||||||
meta: {
|
|
||||||
icon: 'logos:vitejs',
|
|
||||||
link: 'https://vitejs.dev/',
|
|
||||||
title: 'Vite',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'VueUseDemo',
|
|
||||||
path: '/demos/outside/external-link/vue-use',
|
|
||||||
component: IFrameView,
|
|
||||||
meta: {
|
|
||||||
icon: 'logos:vueuse',
|
|
||||||
link: 'https://vueuse.org',
|
|
||||||
title: 'VueUse',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
// 嵌套菜单
|
|
||||||
{
|
|
||||||
meta: {
|
|
||||||
icon: 'ic:round-menu',
|
|
||||||
title: $t('demos.nested.title'),
|
|
||||||
},
|
|
||||||
name: 'NestedDemos',
|
|
||||||
path: '/demos/nested',
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
name: 'Menu1Demo',
|
|
||||||
path: '/demos/nested/menu1',
|
|
||||||
component: () => import('#/views/demos/nested/menu-1.vue'),
|
|
||||||
meta: {
|
|
||||||
icon: 'ic:round-menu',
|
|
||||||
keepAlive: true,
|
|
||||||
title: $t('demos.nested.menu1'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Menu2Demo',
|
|
||||||
path: '/demos/nested/menu2',
|
|
||||||
meta: {
|
|
||||||
icon: 'ic:round-menu',
|
|
||||||
keepAlive: true,
|
|
||||||
title: $t('demos.nested.menu2'),
|
|
||||||
},
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
name: 'Menu21Demo',
|
|
||||||
path: '/demos/nested/menu2/menu2-1',
|
|
||||||
component: () => import('#/views/demos/nested/menu-2-1.vue'),
|
|
||||||
meta: {
|
|
||||||
icon: 'ic:round-menu',
|
|
||||||
keepAlive: true,
|
|
||||||
title: $t('demos.nested.menu2_1'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Menu3Demo',
|
|
||||||
path: '/demos/nested/menu3',
|
|
||||||
meta: {
|
|
||||||
icon: 'ic:round-menu',
|
|
||||||
title: $t('demos.nested.menu3'),
|
|
||||||
},
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
name: 'Menu31Demo',
|
|
||||||
path: '/demos/nested/menu3/menu3-1',
|
|
||||||
component: () => import('#/views/demos/nested/menu-3-1.vue'),
|
|
||||||
meta: {
|
|
||||||
icon: 'ic:round-menu',
|
|
||||||
keepAlive: true,
|
|
||||||
title: $t('demos.nested.menu3_1'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Menu32Demo',
|
|
||||||
path: '/demos/nested/menu3/menu3-2',
|
|
||||||
meta: {
|
|
||||||
icon: 'ic:round-menu',
|
|
||||||
title: $t('demos.nested.menu3_2'),
|
|
||||||
},
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
name: 'Menu321Demo',
|
|
||||||
path: '/demos/nested/menu3/menu3-2/menu3-2-1',
|
|
||||||
component: () =>
|
|
||||||
import('#/views/demos/nested/menu-3-2-1.vue'),
|
|
||||||
meta: {
|
|
||||||
icon: 'ic:round-menu',
|
|
||||||
keepAlive: true,
|
|
||||||
title: $t('demos.nested.menu3_2_1'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
export default routes;
|
|
||||||
@@ -1,335 +0,0 @@
|
|||||||
import type { RouteRecordRaw } from 'vue-router';
|
|
||||||
|
|
||||||
import { $t } from '#/locales';
|
|
||||||
|
|
||||||
const routes: RouteRecordRaw[] = [
|
|
||||||
{
|
|
||||||
meta: {
|
|
||||||
icon: 'ion:layers-outline',
|
|
||||||
keepAlive: true,
|
|
||||||
order: 1000,
|
|
||||||
title: $t('examples.title'),
|
|
||||||
},
|
|
||||||
name: 'Examples',
|
|
||||||
path: '/examples',
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
name: 'FormExample',
|
|
||||||
path: '/examples/form',
|
|
||||||
meta: {
|
|
||||||
icon: 'mdi:form-select',
|
|
||||||
title: $t('examples.form.title'),
|
|
||||||
},
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
name: 'FormBasicExample',
|
|
||||||
path: '/examples/form/basic',
|
|
||||||
component: () => import('#/views/examples/form/basic.vue'),
|
|
||||||
meta: {
|
|
||||||
title: $t('examples.form.basic'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'FormQueryExample',
|
|
||||||
path: '/examples/form/query',
|
|
||||||
component: () => import('#/views/examples/form/query.vue'),
|
|
||||||
meta: {
|
|
||||||
title: $t('examples.form.query'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'FormRulesExample',
|
|
||||||
path: '/examples/form/rules',
|
|
||||||
component: () => import('#/views/examples/form/rules.vue'),
|
|
||||||
meta: {
|
|
||||||
title: $t('examples.form.rules'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'FormDynamicExample',
|
|
||||||
path: '/examples/form/dynamic',
|
|
||||||
component: () => import('#/views/examples/form/dynamic.vue'),
|
|
||||||
meta: {
|
|
||||||
title: $t('examples.form.dynamic'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'FormLayoutExample',
|
|
||||||
path: '/examples/form/custom-layout',
|
|
||||||
component: () => import('#/views/examples/form/custom-layout.vue'),
|
|
||||||
meta: {
|
|
||||||
title: $t('examples.form.layout'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'FormCustomExample',
|
|
||||||
path: '/examples/form/custom',
|
|
||||||
component: () => import('#/views/examples/form/custom.vue'),
|
|
||||||
meta: {
|
|
||||||
title: $t('examples.form.custom'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'FormApiExample',
|
|
||||||
path: '/examples/form/api',
|
|
||||||
component: () => import('#/views/examples/form/api.vue'),
|
|
||||||
meta: {
|
|
||||||
title: $t('examples.form.api'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'FormMergeExample',
|
|
||||||
path: '/examples/form/merge',
|
|
||||||
component: () => import('#/views/examples/form/merge.vue'),
|
|
||||||
meta: {
|
|
||||||
title: $t('examples.form.merge'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'FormScrollToErrorExample',
|
|
||||||
path: '/examples/form/scroll-to-error-test',
|
|
||||||
component: () =>
|
|
||||||
import('#/views/examples/form/scroll-to-error-test.vue'),
|
|
||||||
meta: {
|
|
||||||
title: $t('examples.form.scrollToError'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'VxeTableExample',
|
|
||||||
path: '/examples/vxe-table',
|
|
||||||
meta: {
|
|
||||||
icon: 'lucide:table',
|
|
||||||
title: $t('examples.vxeTable.title'),
|
|
||||||
},
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
name: 'VxeTableBasicExample',
|
|
||||||
path: '/examples/vxe-table/basic',
|
|
||||||
component: () => import('#/views/examples/vxe-table/basic.vue'),
|
|
||||||
meta: {
|
|
||||||
title: $t('examples.vxeTable.basic'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'VxeTableRemoteExample',
|
|
||||||
path: '/examples/vxe-table/remote',
|
|
||||||
component: () => import('#/views/examples/vxe-table/remote.vue'),
|
|
||||||
meta: {
|
|
||||||
title: $t('examples.vxeTable.remote'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'VxeTableTreeExample',
|
|
||||||
path: '/examples/vxe-table/tree',
|
|
||||||
component: () => import('#/views/examples/vxe-table/tree.vue'),
|
|
||||||
meta: {
|
|
||||||
title: $t('examples.vxeTable.tree'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'VxeTableFixedExample',
|
|
||||||
path: '/examples/vxe-table/fixed',
|
|
||||||
component: () => import('#/views/examples/vxe-table/fixed.vue'),
|
|
||||||
meta: {
|
|
||||||
title: $t('examples.vxeTable.fixed'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'VxeTableCustomCellExample',
|
|
||||||
path: '/examples/vxe-table/custom-cell',
|
|
||||||
component: () =>
|
|
||||||
import('#/views/examples/vxe-table/custom-cell.vue'),
|
|
||||||
meta: {
|
|
||||||
title: $t('examples.vxeTable.custom-cell'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'VxeTableFormExample',
|
|
||||||
path: '/examples/vxe-table/form',
|
|
||||||
component: () => import('#/views/examples/vxe-table/form.vue'),
|
|
||||||
meta: {
|
|
||||||
title: $t('examples.vxeTable.form'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'VxeTableEditCellExample',
|
|
||||||
path: '/examples/vxe-table/edit-cell',
|
|
||||||
component: () => import('#/views/examples/vxe-table/edit-cell.vue'),
|
|
||||||
meta: {
|
|
||||||
title: $t('examples.vxeTable.editCell'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'VxeTableEditRowExample',
|
|
||||||
path: '/examples/vxe-table/edit-row',
|
|
||||||
component: () => import('#/views/examples/vxe-table/edit-row.vue'),
|
|
||||||
meta: {
|
|
||||||
title: $t('examples.vxeTable.editRow'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'VxeTableVirtualExample',
|
|
||||||
path: '/examples/vxe-table/virtual',
|
|
||||||
component: () => import('#/views/examples/vxe-table/virtual.vue'),
|
|
||||||
meta: {
|
|
||||||
title: $t('examples.vxeTable.virtual'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'CaptchaExample',
|
|
||||||
path: '/examples/captcha',
|
|
||||||
meta: {
|
|
||||||
icon: 'logos:recaptcha',
|
|
||||||
title: $t('examples.captcha.title'),
|
|
||||||
},
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
name: 'DragVerifyExample',
|
|
||||||
path: '/examples/captcha/slider',
|
|
||||||
component: () =>
|
|
||||||
import('#/views/examples/captcha/slider-captcha.vue'),
|
|
||||||
meta: {
|
|
||||||
title: $t('examples.captcha.sliderCaptcha'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'RotateVerifyExample',
|
|
||||||
path: '/examples/captcha/slider-rotate',
|
|
||||||
component: () =>
|
|
||||||
import('#/views/examples/captcha/slider-rotate-captcha.vue'),
|
|
||||||
meta: {
|
|
||||||
title: $t('examples.captcha.sliderRotateCaptcha'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'TranslateVerifyExample',
|
|
||||||
path: '/examples/captcha/slider-translate',
|
|
||||||
component: () =>
|
|
||||||
import('#/views/examples/captcha/slider-translate-captcha.vue'),
|
|
||||||
meta: {
|
|
||||||
title: $t('examples.captcha.sliderTranslateCaptcha'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'CaptchaPointSelectionExample',
|
|
||||||
path: '/examples/captcha/point-selection',
|
|
||||||
component: () =>
|
|
||||||
import('#/views/examples/captcha/point-selection-captcha.vue'),
|
|
||||||
meta: {
|
|
||||||
title: $t('examples.captcha.pointSelection'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'ModalExample',
|
|
||||||
path: '/examples/modal',
|
|
||||||
component: () => import('#/views/examples/modal/index.vue'),
|
|
||||||
meta: {
|
|
||||||
icon: 'system-uicons:window-content',
|
|
||||||
keepAlive: true,
|
|
||||||
title: $t('examples.modal.title'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'DrawerExample',
|
|
||||||
path: '/examples/drawer',
|
|
||||||
component: () => import('#/views/examples/drawer/index.vue'),
|
|
||||||
meta: {
|
|
||||||
icon: 'iconoir:drawer',
|
|
||||||
keepAlive: true,
|
|
||||||
title: $t('examples.drawer.title'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'EllipsisExample',
|
|
||||||
path: '/examples/ellipsis',
|
|
||||||
component: () => import('#/views/examples/ellipsis/index.vue'),
|
|
||||||
meta: {
|
|
||||||
icon: 'ion:ellipsis-horizontal',
|
|
||||||
title: $t('examples.ellipsis.title'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'VueResizeDemo',
|
|
||||||
path: '/demos/resize/basic',
|
|
||||||
component: () => import('#/views/examples/resize/basic.vue'),
|
|
||||||
meta: {
|
|
||||||
icon: 'material-symbols:resize',
|
|
||||||
title: $t('examples.resize.title'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'ColPageDemo',
|
|
||||||
path: '/examples/layout/col-page',
|
|
||||||
component: () => import('#/views/examples/layout/col-page.vue'),
|
|
||||||
meta: {
|
|
||||||
badge: 'Alpha',
|
|
||||||
badgeVariants: 'destructive',
|
|
||||||
icon: 'material-symbols:horizontal-distribute',
|
|
||||||
title: $t('examples.layout.col-page'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'TippyDemo',
|
|
||||||
path: '/examples/tippy',
|
|
||||||
component: () => import('#/views/examples/tippy/index.vue'),
|
|
||||||
meta: {
|
|
||||||
icon: 'mdi:message-settings-outline',
|
|
||||||
title: 'Tippy',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'JsonViewer',
|
|
||||||
path: '/examples/json-viewer',
|
|
||||||
component: () => import('#/views/examples/json-viewer/index.vue'),
|
|
||||||
meta: {
|
|
||||||
icon: 'tabler:json',
|
|
||||||
title: 'JsonViewer',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Motion',
|
|
||||||
path: '/examples/motion',
|
|
||||||
component: () => import('#/views/examples/motion/index.vue'),
|
|
||||||
meta: {
|
|
||||||
icon: 'mdi:animation-play',
|
|
||||||
title: 'Motion',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'CountTo',
|
|
||||||
path: '/examples/count-to',
|
|
||||||
component: () => import('#/views/examples/count-to/index.vue'),
|
|
||||||
meta: {
|
|
||||||
icon: 'mdi:animation-play',
|
|
||||||
title: 'CountTo',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Loading',
|
|
||||||
path: '/examples/loading',
|
|
||||||
component: () => import('#/views/examples/loading/index.vue'),
|
|
||||||
meta: {
|
|
||||||
icon: 'mdi:circle-double',
|
|
||||||
title: 'Loading',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'ButtonGroup',
|
|
||||||
path: '/examples/button-group',
|
|
||||||
component: () => import('#/views/examples/button-group/index.vue'),
|
|
||||||
meta: {
|
|
||||||
icon: 'mdi:check-circle',
|
|
||||||
title: $t('examples.button-group.title'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
export default routes;
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
import type { RouteRecordRaw } from 'vue-router';
|
|
||||||
|
|
||||||
import { $t } from '#/locales';
|
|
||||||
|
|
||||||
const routes: RouteRecordRaw[] = [
|
|
||||||
{
|
|
||||||
meta: {
|
|
||||||
icon: 'ion:settings-outline',
|
|
||||||
order: 9997,
|
|
||||||
title: $t('system.title'),
|
|
||||||
},
|
|
||||||
name: 'System',
|
|
||||||
path: '/system',
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
path: '/system/role',
|
|
||||||
name: 'SystemRole',
|
|
||||||
meta: {
|
|
||||||
icon: 'mdi:account-group',
|
|
||||||
title: $t('system.role.title'),
|
|
||||||
},
|
|
||||||
component: () => import('#/views/system/role/list.vue'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: '/system/menu',
|
|
||||||
name: 'SystemMenu',
|
|
||||||
meta: {
|
|
||||||
icon: 'mdi:menu',
|
|
||||||
title: $t('system.menu.title'),
|
|
||||||
},
|
|
||||||
component: () => import('#/views/system/menu/list.vue'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: '/system/dept',
|
|
||||||
name: 'SystemDept',
|
|
||||||
meta: {
|
|
||||||
icon: 'charm:organisation',
|
|
||||||
title: $t('system.dept.title'),
|
|
||||||
},
|
|
||||||
component: () => import('#/views/system/dept/list.vue'),
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
export default routes;
|
|
||||||
@@ -1,106 +0,0 @@
|
|||||||
import type { RouteRecordRaw } from 'vue-router';
|
|
||||||
|
|
||||||
import {
|
|
||||||
VBEN_ANT_PREVIEW_URL,
|
|
||||||
VBEN_DOC_URL,
|
|
||||||
VBEN_ELE_PREVIEW_URL,
|
|
||||||
VBEN_GITHUB_URL,
|
|
||||||
VBEN_LOGO_URL,
|
|
||||||
VBEN_NAIVE_PREVIEW_URL,
|
|
||||||
VBEN_TD_PREVIEW_URL,
|
|
||||||
} from '@vben/constants';
|
|
||||||
import { SvgAntdvLogoIcon, SvgTDesignIcon } from '@vben/icons';
|
|
||||||
|
|
||||||
import { IFrameView } from '#/layouts';
|
|
||||||
import { $t } from '#/locales';
|
|
||||||
|
|
||||||
const routes: RouteRecordRaw[] = [
|
|
||||||
{
|
|
||||||
meta: {
|
|
||||||
badgeType: 'dot',
|
|
||||||
icon: VBEN_LOGO_URL,
|
|
||||||
order: 9998,
|
|
||||||
title: $t('demos.vben.title'),
|
|
||||||
},
|
|
||||||
name: 'VbenProject',
|
|
||||||
path: '/vben-admin',
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
name: 'VbenDocument',
|
|
||||||
path: '/vben-admin/document',
|
|
||||||
component: IFrameView,
|
|
||||||
meta: {
|
|
||||||
icon: 'lucide:book-open-text',
|
|
||||||
link: VBEN_DOC_URL,
|
|
||||||
title: $t('demos.vben.document'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'VbenGithub',
|
|
||||||
path: '/vben-admin/github',
|
|
||||||
component: IFrameView,
|
|
||||||
meta: {
|
|
||||||
icon: 'mdi:github',
|
|
||||||
link: VBEN_GITHUB_URL,
|
|
||||||
title: 'Github',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'VbenAntdv',
|
|
||||||
path: '/vben-admin/antdv',
|
|
||||||
component: IFrameView,
|
|
||||||
meta: {
|
|
||||||
badgeType: 'dot',
|
|
||||||
icon: SvgAntdvLogoIcon,
|
|
||||||
link: VBEN_ANT_PREVIEW_URL,
|
|
||||||
title: $t('demos.vben.antdv'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'VbenNaive',
|
|
||||||
path: '/vben-admin/naive',
|
|
||||||
component: IFrameView,
|
|
||||||
meta: {
|
|
||||||
badgeType: 'dot',
|
|
||||||
icon: 'logos:naiveui',
|
|
||||||
link: VBEN_NAIVE_PREVIEW_URL,
|
|
||||||
title: $t('demos.vben.naive-ui'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'VbenElementPlus',
|
|
||||||
path: '/vben-admin/ele',
|
|
||||||
component: IFrameView,
|
|
||||||
meta: {
|
|
||||||
badgeType: 'dot',
|
|
||||||
icon: 'logos:element',
|
|
||||||
link: VBEN_ELE_PREVIEW_URL,
|
|
||||||
title: $t('demos.vben.element-plus'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'VbenTDesign',
|
|
||||||
path: '/vben-admin/tdesign',
|
|
||||||
component: IFrameView,
|
|
||||||
meta: {
|
|
||||||
badgeType: 'dot',
|
|
||||||
icon: SvgTDesignIcon,
|
|
||||||
link: VBEN_TD_PREVIEW_URL,
|
|
||||||
title: $t('demos.vben.tdesign'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
component: () => import('#/views/_core/about/index.vue'),
|
|
||||||
meta: {
|
|
||||||
icon: 'lucide:copyright',
|
|
||||||
order: 9999,
|
|
||||||
title: $t('demos.vben.about'),
|
|
||||||
},
|
|
||||||
name: 'VbenAbout',
|
|
||||||
path: '/vben-admin/about',
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
export default routes;
|
|
||||||
@@ -1,120 +0,0 @@
|
|||||||
import type { Recordable, UserInfo } from '@vben/types';
|
|
||||||
|
|
||||||
import { ref } from 'vue';
|
|
||||||
import { useRouter } from 'vue-router';
|
|
||||||
|
|
||||||
import { LOGIN_PATH } from '@vben/constants';
|
|
||||||
import { preferences } from '@vben/preferences';
|
|
||||||
import { resetAllStores, useAccessStore, useUserStore } from '@vben/stores';
|
|
||||||
|
|
||||||
import { notification } from 'ant-design-vue';
|
|
||||||
import { defineStore } from 'pinia';
|
|
||||||
|
|
||||||
import { getAccessCodesApi, getUserInfoApi, loginApi, logoutApi } from '#/api';
|
|
||||||
import { $t } from '#/locales';
|
|
||||||
|
|
||||||
export const useAuthStore = defineStore('auth', () => {
|
|
||||||
const accessStore = useAccessStore();
|
|
||||||
const userStore = useUserStore();
|
|
||||||
const router = useRouter();
|
|
||||||
|
|
||||||
const loginLoading = ref(false);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 异步处理登录操作
|
|
||||||
* Asynchronously handle the login process
|
|
||||||
* @param params 登录表单数据
|
|
||||||
* @param onSuccess 成功之后的回调函数
|
|
||||||
*/
|
|
||||||
async function authLogin(
|
|
||||||
params: Recordable<any>,
|
|
||||||
onSuccess?: () => Promise<void> | void,
|
|
||||||
) {
|
|
||||||
// 异步处理用户登录操作并获取 accessToken
|
|
||||||
let userInfo: null | UserInfo = null;
|
|
||||||
try {
|
|
||||||
loginLoading.value = true;
|
|
||||||
const { accessToken } = await loginApi(params);
|
|
||||||
|
|
||||||
// 如果成功获取到 accessToken
|
|
||||||
if (accessToken) {
|
|
||||||
accessStore.setAccessToken(accessToken);
|
|
||||||
|
|
||||||
// 获取用户信息并存储到 accessStore 中
|
|
||||||
const [fetchUserInfoResult, accessCodes] = await Promise.all([
|
|
||||||
fetchUserInfo(),
|
|
||||||
getAccessCodesApi(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
userInfo = fetchUserInfoResult;
|
|
||||||
|
|
||||||
userStore.setUserInfo(userInfo);
|
|
||||||
accessStore.setAccessCodes(accessCodes);
|
|
||||||
|
|
||||||
if (accessStore.loginExpired) {
|
|
||||||
accessStore.setLoginExpired(false);
|
|
||||||
} else {
|
|
||||||
onSuccess
|
|
||||||
? await onSuccess?.()
|
|
||||||
: await router.push(
|
|
||||||
userInfo.homePath || preferences.app.defaultHomePath,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (userInfo?.realName) {
|
|
||||||
notification.success({
|
|
||||||
description: `${$t('authentication.loginSuccessDesc')}:${userInfo?.realName}`,
|
|
||||||
duration: 3,
|
|
||||||
message: $t('authentication.loginSuccess'),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
loginLoading.value = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
userInfo,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
async function logout(redirect: boolean = true) {
|
|
||||||
try {
|
|
||||||
await logoutApi();
|
|
||||||
} catch {
|
|
||||||
// 不做任何处理
|
|
||||||
}
|
|
||||||
|
|
||||||
resetAllStores();
|
|
||||||
accessStore.setLoginExpired(false);
|
|
||||||
|
|
||||||
// 回登录页带上当前路由地址
|
|
||||||
await router.replace({
|
|
||||||
path: LOGIN_PATH,
|
|
||||||
query: redirect
|
|
||||||
? {
|
|
||||||
redirect: encodeURIComponent(router.currentRoute.value.fullPath),
|
|
||||||
}
|
|
||||||
: {},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async function fetchUserInfo() {
|
|
||||||
let userInfo: null | UserInfo = null;
|
|
||||||
userInfo = await getUserInfoApi();
|
|
||||||
userStore.setUserInfo(userInfo);
|
|
||||||
return userInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
function $reset() {
|
|
||||||
loginLoading.value = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
$reset,
|
|
||||||
authLogin,
|
|
||||||
fetchUserInfo,
|
|
||||||
loginLoading,
|
|
||||||
logout,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user