| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598 |
- import { Request, Response } from 'express';
- const now = Math.floor(Date.now() / 1000);
- const deptTree = [
- {
- id: 1,
- parentId: 0,
- name: '研发部',
- path: '/1',
- sort: 1,
- deptType: 'DEV',
- remark: '',
- status: 1,
- createTime: now - 86400 * 30,
- children: [
- {
- id: 4,
- parentId: 1,
- name: '前端组',
- path: '/1/4',
- sort: 1,
- deptType: 'DEV',
- remark: '',
- status: 1,
- createTime: now - 86400 * 28,
- },
- {
- id: 5,
- parentId: 1,
- name: '后端组',
- path: '/1/5',
- sort: 2,
- deptType: 'DEV',
- remark: '',
- status: 1,
- createTime: now - 86400 * 28,
- },
- ],
- },
- {
- id: 2,
- parentId: 0,
- name: '市场部',
- path: '/2',
- sort: 2,
- deptType: 'NORMAL',
- remark: '',
- status: 1,
- createTime: now - 86400 * 30,
- },
- {
- id: 3,
- parentId: 0,
- name: '运营部',
- path: '/3',
- sort: 3,
- deptType: 'NORMAL',
- remark: '',
- status: 1,
- createTime: now - 86400 * 30,
- },
- ];
- const products = [
- {
- id: 1,
- code: 'crm',
- name: 'CRM 系统',
- appKey: 'ak_crm_001',
- remark: '客户关系管理',
- status: 1,
- createTime: now - 86400 * 20,
- },
- {
- id: 2,
- code: 'oa',
- name: 'OA 系统',
- appKey: 'ak_oa_002',
- remark: '办公自动化',
- status: 1,
- createTime: now - 86400 * 15,
- },
- {
- id: 3,
- code: 'mall',
- name: '电商后台',
- appKey: 'ak_mall_003',
- remark: '',
- status: 2,
- createTime: now - 86400 * 10,
- },
- ];
- const users = [
- {
- id: 1,
- username: 'superadmin',
- nickname: '超级管理员',
- avatar: '',
- email: '[email protected]',
- phone: '13800000001',
- remark: '',
- deptId: 0,
- status: 1,
- createTime: now - 86400 * 60,
- },
- {
- id: 2,
- username: 'zhangsan',
- nickname: '张三',
- avatar: '',
- email: '[email protected]',
- phone: '13800000002',
- remark: '前端开发',
- deptId: 4,
- status: 1,
- createTime: now - 86400 * 25,
- },
- {
- id: 3,
- username: 'lisi',
- nickname: '李四',
- avatar: '',
- email: '[email protected]',
- phone: '13800000003',
- remark: '销售',
- deptId: 2,
- status: 1,
- createTime: now - 86400 * 20,
- },
- {
- id: 4,
- username: 'wangwu',
- nickname: '王五',
- avatar: '',
- email: '[email protected]',
- phone: '13800000004',
- remark: '运营',
- deptId: 3,
- status: 2,
- createTime: now - 86400 * 18,
- },
- ];
- const roles = [
- {
- id: 1,
- productCode: 'crm',
- name: '销售经理',
- remark: '管理销售团队',
- status: 1,
- permsLevel: 10,
- createTime: now - 86400 * 15,
- },
- {
- id: 2,
- productCode: 'crm',
- name: '普通销售',
- remark: '',
- status: 1,
- permsLevel: 20,
- createTime: now - 86400 * 15,
- },
- {
- id: 3,
- productCode: 'crm',
- name: '客服',
- remark: '只读权限',
- status: 1,
- permsLevel: 30,
- createTime: now - 86400 * 15,
- },
- {
- id: 4,
- productCode: 'oa',
- name: '审批管理员',
- remark: '',
- status: 1,
- permsLevel: 10,
- createTime: now - 86400 * 10,
- },
- ];
- const perms = [
- {
- id: 1,
- productCode: 'crm',
- name: '查看客户列表',
- code: 'customer:list',
- remark: '',
- status: 1,
- createTime: now - 86400 * 14,
- },
- {
- id: 2,
- productCode: 'crm',
- name: '创建客户',
- code: 'customer:create',
- remark: '',
- status: 1,
- createTime: now - 86400 * 14,
- },
- {
- id: 3,
- productCode: 'crm',
- name: '编辑客户',
- code: 'customer:update',
- remark: '',
- status: 1,
- createTime: now - 86400 * 14,
- },
- {
- id: 4,
- productCode: 'crm',
- name: '删除客户',
- code: 'customer:delete',
- remark: '',
- status: 1,
- createTime: now - 86400 * 14,
- },
- {
- id: 5,
- productCode: 'crm',
- name: '查看订单',
- code: 'order:list',
- remark: '',
- status: 1,
- createTime: now - 86400 * 14,
- },
- {
- id: 6,
- productCode: 'crm',
- name: '创建订单',
- code: 'order:create',
- remark: '',
- status: 1,
- createTime: now - 86400 * 14,
- },
- {
- id: 7,
- productCode: 'crm',
- name: '导出报表',
- code: 'report:export',
- remark: '',
- status: 1,
- createTime: now - 86400 * 14,
- },
- ];
- const members = [
- {
- id: 1,
- productCode: 'crm',
- userId: 2,
- username: 'zhangsan',
- nickname: '张三',
- memberType: 'MEMBER',
- status: 1,
- createTime: now - 86400 * 12,
- },
- {
- id: 2,
- productCode: 'crm',
- userId: 3,
- username: 'lisi',
- nickname: '李四',
- memberType: 'MEMBER',
- status: 1,
- createTime: now - 86400 * 10,
- },
- {
- id: 3,
- productCode: 'oa',
- userId: 2,
- username: 'zhangsan',
- nickname: '张三',
- memberType: 'DEVELOPER',
- status: 1,
- createTime: now - 86400 * 8,
- },
- ];
- function ok(data: any) {
- return { success: true, errorCode: 0, errorMessage: 'ok', showType: 0, data };
- }
- function okList(list: any[], total?: number) {
- return {
- success: true,
- errorCode: 0,
- errorMessage: 'ok',
- showType: 0,
- data: { list, total: total ?? list.length },
- };
- }
- function fail(code: number, msg: string) {
- return { success: false, errorCode: code, errorMessage: msg, showType: 2 };
- }
- export default {
- 'POST /api/dept/tree': (_req: Request, res: Response) => {
- res.json(ok(deptTree));
- },
- 'POST /api/dept/create': (req: Request, res: Response) => {
- res.json(ok({ id: Math.floor(Math.random() * 1000) + 100 }));
- },
- 'POST /api/dept/update': (_req: Request, res: Response) => {
- res.json(ok(null));
- },
- 'POST /api/dept/delete': (req: Request, res: Response) => {
- const { id } = req.body;
- const dept = deptTree.find((d) => d.id === id);
- if (dept && dept.children && dept.children.length > 0) {
- res.json(fail(400, '该部门下存在子部门,无法删除'));
- return;
- }
- res.json(ok(null));
- },
- 'POST /api/product/list': (req: Request, res: Response) => {
- const { page = 1, pageSize = 20 } = req.body;
- const start = (page - 1) * pageSize;
- res.json(okList(products.slice(start, start + pageSize), products.length));
- },
- 'POST /api/product/detail': (req: Request, res: Response) => {
- const { id } = req.body;
- const item = products.find((p) => p.id === id);
- if (!item) {
- res.json(fail(404, '产品不存在'));
- return;
- }
- res.json(ok(item));
- },
- 'POST /api/product/create': (_req: Request, res: Response) => {
- res.json(
- ok({
- id: 100,
- code: 'new_product',
- appKey: 'ak_new_product_100',
- adminUser: 'admin_new_product',
- credentialsTicket: 'ticket_mock_abc123',
- credentialsExpiresAt: now + 300,
- }),
- );
- },
- 'POST /api/product/update': (_req: Request, res: Response) => {
- res.json(ok(null));
- },
- 'POST /api/product/fetchInitialCredentials': (_req: Request, res: Response) => {
- res.json(
- ok({
- appKey: 'ak_new_product_100',
- appSecret: 'sk_mock_secret_xyz789',
- adminUser: 'admin_new_product',
- adminPassword: 'P@ssw0rd123',
- }),
- );
- },
- 'POST /api/user/list': (req: Request, res: Response) => {
- const { page = 1, pageSize = 20, productCode } = req.body;
- const list = users.map((u) => ({
- ...u,
- memberType: productCode
- ? (members.find((m) => m.userId === u.id && m.productCode === productCode)?.memberType ??
- '')
- : undefined,
- }));
- const start = (page - 1) * pageSize;
- res.json(okList(list.slice(start, start + pageSize), list.length));
- },
- 'POST /api/user/detail': (req: Request, res: Response) => {
- const { id } = req.body;
- const item = users.find((u) => u.id === id);
- if (!item) {
- res.json(fail(404, '用户不存在'));
- return;
- }
- res.json(ok({ ...item, roleIds: id === 3 ? [2] : [] }));
- },
- 'POST /api/user/create': (_req: Request, res: Response) => {
- res.json(ok({ id: Math.floor(Math.random() * 1000) + 100 }));
- },
- 'POST /api/user/update': (_req: Request, res: Response) => {
- res.json(ok(null));
- },
- 'POST /api/user/updateStatus': (_req: Request, res: Response) => {
- res.json(ok(null));
- },
- 'POST /api/user/bindRoles': (_req: Request, res: Response) => {
- res.json(ok(null));
- },
- 'POST /api/user/setPerms': (_req: Request, res: Response) => {
- res.json(ok(null));
- },
- 'POST /api/user/userPerms': (req: Request, res: Response) => {
- const { userId } = req.body;
- const mockPerms =
- userId === 3
- ? [
- { permId: 7, effect: 'ALLOW' },
- { permId: 6, effect: 'DENY' },
- ]
- : [];
- res.json(ok({ perms: mockPerms }));
- },
- 'POST /api/role/list': (req: Request, res: Response) => {
- const { productCode, page = 1, pageSize = 20 } = req.body;
- const filtered = roles.filter((r) => r.productCode === productCode);
- const start = (page - 1) * pageSize;
- res.json(okList(filtered.slice(start, start + pageSize), filtered.length));
- },
- 'POST /api/role/detail': (req: Request, res: Response) => {
- const { id } = req.body;
- const item = roles.find((r) => r.id === id);
- if (!item) {
- res.json(fail(404, '角色不存在'));
- return;
- }
- const permIds = id === 1 ? [1, 2, 3, 4, 5, 6, 7] : id === 2 ? [1, 2, 5, 6] : [1, 5];
- res.json(ok({ ...item, permIds }));
- },
- 'POST /api/role/create': (_req: Request, res: Response) => {
- res.json(ok({ id: Math.floor(Math.random() * 1000) + 100 }));
- },
- 'POST /api/role/update': (_req: Request, res: Response) => {
- res.json(ok(null));
- },
- 'POST /api/role/delete': (_req: Request, res: Response) => {
- res.json(ok(null));
- },
- 'POST /api/role/bindPerms': (_req: Request, res: Response) => {
- res.json(ok(null));
- },
- 'POST /api/perm/list': (req: Request, res: Response) => {
- const { productCode, page = 1, pageSize = 20 } = req.body;
- const filtered = perms.filter((p) => p.productCode === productCode);
- const start = (page - 1) * pageSize;
- res.json(okList(filtered.slice(start, start + pageSize), filtered.length));
- },
- 'POST /api/member/list': (req: Request, res: Response) => {
- const { productCode, page = 1, pageSize = 20 } = req.body;
- const filtered = members.filter((m) => m.productCode === productCode);
- const start = (page - 1) * pageSize;
- res.json(okList(filtered.slice(start, start + pageSize), filtered.length));
- },
- 'POST /api/member/add': (_req: Request, res: Response) => {
- res.json(ok({ id: Math.floor(Math.random() * 1000) + 100 }));
- },
- 'POST /api/member/update': (_req: Request, res: Response) => {
- res.json(ok(null));
- },
- 'POST /api/member/remove': (_req: Request, res: Response) => {
- res.json(ok(null));
- },
- 'POST /api/captcha/get': (_req: Request, res: Response) => {
- res.json(
- ok({
- id: 'captcha_mock_001',
- base64image:
- 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==',
- }),
- );
- },
- 'POST /api/capjs/endpoint': (_req: Request, res: Response) => {
- res.json(ok({ data: '' }));
- },
- 'POST /api/auth/adminLogin': (req: Request, res: Response) => {
- const { username, password, managementKey } = req.body;
- if (managementKey !== 'mock-key') {
- res.json(fail(401, 'managementKey 无效'));
- return;
- }
- if (username === 'superadmin' && password === '123456') {
- res.json(
- ok({
- accessToken: 'mock_access_token_superadmin',
- refreshToken: 'mock_refresh_token_superadmin',
- expires: now + 7200,
- userInfo: {
- userId: 1,
- username: 'superadmin',
- nickname: '超级管理员',
- avatar: '',
- email: '[email protected]',
- phone: '13800000001',
- isSuperAdmin: 1,
- mustChangePassword: 0,
- memberType: '',
- perms: [],
- },
- }),
- );
- return;
- }
- res.json(fail(401, '用户名或密码错误'));
- },
- 'POST /api/auth/adminLogin/cap': (req: Request, res: Response) => {
- const { username, password, managementKey } = req.body;
- if (managementKey !== 'mock-key') {
- res.json(fail(401, 'managementKey 无效'));
- return;
- }
- if (username === 'superadmin' && password === '123456') {
- res.json(
- ok({
- accessToken: 'mock_access_token_superadmin',
- refreshToken: 'mock_refresh_token_superadmin',
- expires: now + 7200,
- userInfo: {
- userId: 1,
- username: 'superadmin',
- nickname: '超级管理员',
- avatar: '',
- email: '[email protected]',
- phone: '13800000001',
- isSuperAdmin: 1,
- mustChangePassword: 0,
- memberType: '',
- perms: [],
- },
- }),
- );
- return;
- }
- res.json(fail(401, '用户名或密码错误'));
- },
- 'POST /api/auth/logout': (_req: Request, res: Response) => {
- res.json(ok(null));
- },
- 'POST /api/auth/refreshToken': (_req: Request, res: Response) => {
- res.json(
- ok({
- accessToken: 'mock_access_token_refreshed',
- refreshToken: 'mock_refresh_token_refreshed',
- expires: now + 7200,
- userInfo: {
- userId: 1,
- username: 'superadmin',
- nickname: '超级管理员',
- avatar: '',
- email: '[email protected]',
- phone: '13800000001',
- isSuperAdmin: 1,
- mustChangePassword: 0,
- memberType: '',
- perms: [],
- },
- }),
- );
- },
- 'POST /api/auth/updateInfo': (_req: Request, res: Response) => {
- res.json(ok(null));
- },
- 'POST /api/auth/changePassword': (req: Request, res: Response) => {
- const { oldPassword } = req.body;
- if (oldPassword !== '123456') {
- res.json(fail(400, '原密码错误'));
- return;
- }
- res.json(ok(null));
- },
- };
|