Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions template/tinyvue/config/vite.config.dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,31 @@ configDotenv({

// 加载环境变量(development 模式会读取 .env.development 和 .env)
const env = loadEnv('development', process.cwd())
const useMock = env.VITE_USE_MOCK === 'true'
const apiTarget = useMock ? env.VITE_MOCK_HOST : env.VITE_SERVER_HOST

const proxyConfig = {
[env.VITE_BASE_API]: {
target: env.VITE_SERVER_HOST,
target: apiTarget,
changeOrigin: true,
logLevel: 'debug',
rewrite: (path: string) =>
path.replace(
new RegExp(`${env.VITE_BASE_API}`),
'',
),
},
[env.VITE_MOCK_SERVER_HOST]: {
target: env.VITE_SERVER_HOST,
target: apiTarget,
changeOrigin: true,
rewrite: (path: string) => {
return path.replace(new RegExp(`${env.VITE_MOCK_SERVER_HOST}`), '/mock')
return path.replace(
new RegExp(`^${env.VITE_MOCK_SERVER_HOST}`),
useMock ? '' : `${env.VITE_BASE_API}/mock`,
)
},
},
}
export default mergeConfig(
{
mode: 'development',
server: {
open: true,
open: process.env.CI !== 'true',
fs: {
strict: true,
},
Expand Down
2 changes: 1 addition & 1 deletion template/tinyvue/dev.env
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ VITE_BASE_API=/api
VITE_SERVER_HOST= http://127.0.0.1:3000
VITE_MOCK_HOST= http://127.0.0.1:8848
VITE_USE_MOCK= false
VITE_MOCK_IGNORE= /api/user/userInfo,/api/user/login,/api/user/register,/api/employee/getEmployee
VITE_MOCK_IGNORE=

VITE_MOCK_SERVER_HOST=/mock
VITE_LOWCODE_DESIGNER_ENABLED=true
Expand Down
9 changes: 6 additions & 3 deletions template/tinyvue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
"author": "Tiny Team",
"license": "MIT",
"engines": {
"node": ">=14.0.0"
"node": ">=18.18.0"
},
"scripts": {
"start": "vite --config ./config/vite.config.dev.ts --port 3031",
"start": "cross-env VITE_USE_MOCK=true run-p mock dev:vite",
"dev:vite": "vite --config ./config/vite.config.dev.ts --port 3031",
"dev:full": "cross-env VITE_USE_MOCK=false pnpm dev:vite",
"build": "vite build --config ./config/vite.config.prod.ts",
"preview": "vite preview",
"build:wp": "webpack --config webpack.config.js",
Expand All @@ -20,14 +22,14 @@
"report": "cross-env REPORT=true npm run build",
"lint-staged": "npx lint-staged",
"mock": "tsx ./src/mock/index.ts",
"test:mock": "node --import tsx --test src/mock/*.test.ts",
"dev:fr": "farm",
"build:fr": "farm build",
"lint": "eslint",
"lint:fix": "eslint --fix"
},
"dependencies": {
"@babel/core": "^7.25.2",
"@gaonengwww/mock-server": "^1.0.5",
"@mcp-b/webmcp-polyfill": "^3.0.0",
"@mcp-b/webmcp-types": "^3.0.0",
"@opentiny/icons": "^0.1.3",
Expand Down Expand Up @@ -87,6 +89,7 @@
"less-loader": "^12.2.0",
"lint-staged": "^11.2.6",
"mockjs": "^1.1.0",
"npm-run-all": "^4.1.5",
"rollup-plugin-visualizer": "^5.12.0",
"style-loader": "^4.0.0",
"style-resources-loader": "1.5.0",
Expand Down
141 changes: 141 additions & 0 deletions template/tinyvue/src/mock/backend-data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
import { readFileSync } from 'node:fs'

export interface MenuNode {
children: MenuNode[]
component: string
customIcon: string
id: number
label: string
locale: string
menuType: string
order: number
parentId: number | null
url: string
}

const permissions = [
{ id: 1, name: '*', desc: '全部权限' },
{ id: 2, name: 'user::query', desc: '查询用户' },
{ id: 3, name: 'permission::get', desc: '查询权限' },
{ id: 4, name: 'role::query', desc: '查询角色' },
{ id: 5, name: 'menu::query', desc: '查询菜单' },
{ id: 6, name: 'i18n::query', desc: '查询国际化词条' },
]

let nextMenuId = 1

function menu(
label: string,
url: string,
component: string,
locale: string,
children: MenuNode[] = [],
customIcon = '',
): MenuNode {
const id = nextMenuId++
children.forEach((child) => {
child.parentId = id
})
return {
id,
label,
url,
component,
customIcon,
menuType: 'normal',
parentId: null,
order: id,
locale,
children,
}
}

export const menuTree = [
menu('Board', 'board', 'board/index', 'menu.board', [
menu('Home', 'home', 'board/home/index', 'menu.home'),
menu('Work', 'work', 'board/work/index', 'menu.work'),
], 'IconApplication'),
menu('List', 'list', 'list/index', 'menu.list', [
menu('Table', 'table', 'list/search-table/index', 'menu.list.searchTable'),
menu('Card', 'card', 'list/card-list/index', 'menu.list.cardList'),
], 'IconFiles'),
menu('Form', 'form', 'form/index', 'menu.form', [
menu('Base', 'base', 'form/base/index', 'menu.form.base'),
menu('Step', 'step', 'form/step/index', 'menu.form.step'),
], 'IconSetting'),
menu('Profile', 'profile', 'profile/index', 'menu.profile', [
menu('Detail', 'detail', 'profile/detail/index', 'menu.profile.detail'),
], 'IconFiletext'),
menu('Result', 'result', 'result/index', 'menu.result', [
menu('Success', 'success', 'result/success/index', 'menu.result.success'),
menu('Error', 'error', 'result/error/index', 'menu.result.error'),
], 'IconSuccessful'),
menu('Exception', 'exception', 'exception/index', 'menu.exception', [
menu('403', '403', 'exception/403/index', 'menu.exception.403'),
menu('404', '404', 'exception/404/index', 'menu.exception.404'),
menu('500', '500', 'exception/500/index', 'menu.exception.500'),
], 'IconCueL'),
menu('User', 'user', 'user/index', 'menu.user', [
menu('Info', 'info', 'user/info/index', 'menu.user.info'),
], 'IconUser'),
menu('SystemManager', '', 'menu/index', 'menu.systemManager', [
menu('AllMenu', 'menu/allMenu', 'menu/info/index', 'menu.menu.info'),
menu('AllPermission', 'permission/allPermission', 'permission/info/index', 'menu.permission.info'),
menu('AllRole', 'role/allRole', 'role/info/index', 'menu.role.info'),
menu('AllInfo', 'userManager/allInfo', 'userManager/info/index', 'menu.userManager.info'),
menu('Local', 'locale', 'locale/index', 'menu.i18n'),
], 'IconTotal'),
]

export const localeTable = JSON.parse(
readFileSync(new URL('../locales.json', import.meta.url), 'utf8'),
)

export function createBackendState() {
const role = {
id: 1,
name: 'admin',
permission: structuredClone(permissions),
menus: structuredClone(menuTree),
}
const user = {
id: '1',
name: 'admin',
email: 'admin@no-reply.com',
department: 'Tiny-Vue-Pro',
employeeType: 'social recruitment',
probationStart: '2021-04-19',
probationEnd: '2021-10-15',
probationDuration: '180',
protocolStart: '2021-04-19',
protocolEnd: '2024-04-19',
address: 'xian',
status: 'normal',
role: [role],
}
const localeRecords = Object.entries(localeTable).flatMap(
([language, messages]: [string, any]) => Object.entries(messages).map(
([key, content], index) => ({
id: language === 'enUS' ? index + 1 : index + 10001,
key,
content,
lang: language === 'enUS'
? { id: 1, name: 'enUS' }
: { id: 2, name: 'zhCN' },
}),
),
)

return {
credentials: new Map([['admin@no-reply.com', 'admin']]),
languages: [{ id: 1, name: 'enUS' }, { id: 2, name: 'zhCN' }],
localeTable: structuredClone(localeTable),
localeRecords,
menuTree: structuredClone(menuTree),
permissions: structuredClone(permissions),
roles: [role],
refreshTokens: new Map<string, string>(),
tokens: new Map<string, string>(),
users: [user],
}
}
Loading
Loading