mirror of
https://github.com/WeBankFinTech/fes.js.git
synced 2025-08-07 02:22:57 +08:00
feat: mock.js支持es6写法
This commit is contained in:
parent
b076db692e
commit
fd6429bbda
@ -19,7 +19,7 @@ Fes.js 约定 `src/mock.js` 为 mock 文件。
|
|||||||
|
|
||||||
可以参考如下 🌰:
|
可以参考如下 🌰:
|
||||||
``` js
|
``` js
|
||||||
module.exports = function ({ cgiMock, mockjs, utils }) {
|
export default function ({ cgiMock, mockjs, utils }) {
|
||||||
const { Random } = mockjs;
|
const { Random } = mockjs;
|
||||||
|
|
||||||
// 测试 proxy 与 mock 用例集合
|
// 测试 proxy 与 mock 用例集合
|
||||||
@ -160,7 +160,7 @@ module.exports = function ({ cgiMock, mockjs, utils }) {
|
|||||||
|
|
||||||
比如:
|
比如:
|
||||||
```js
|
```js
|
||||||
module.exports = function ({ cgiMock, mockjs, utils }) {
|
export default function ({ cgiMock, mockjs, utils }) {
|
||||||
cgiMock('/random', mockjs.mock({
|
cgiMock('/random', mockjs.mock({
|
||||||
'string|1-10': '★'
|
'string|1-10': '★'
|
||||||
}));
|
}));
|
||||||
|
@ -9,6 +9,8 @@
|
|||||||
- 搭配 [@fesjs/plugin-access](./access.html) 插件使用,可以完成对路由的权限控制。
|
- 搭配 [@fesjs/plugin-access](./access.html) 插件使用,可以完成对路由的权限控制。
|
||||||
- 搭配 [@fesjs/plugin-locale](./locale.html) 插件使用,提供切换语言的能力。
|
- 搭配 [@fesjs/plugin-locale](./locale.html) 插件使用,提供切换语言的能力。
|
||||||
- 支持自定义头部区域。
|
- 支持自定义头部区域。
|
||||||
|
- 菜单支持配置icon
|
||||||
|
- 菜单标题支持国际化
|
||||||
|
|
||||||
- 可配置页面是否需要 layout。
|
- 可配置页面是否需要 layout。
|
||||||
|
|
||||||
@ -156,9 +158,21 @@ export default {
|
|||||||
|
|
||||||
- **path**:菜单的路径,可配置第三方地址。
|
- **path**:菜单的路径,可配置第三方地址。
|
||||||
|
|
||||||
- **title**:菜单的标题。
|
- **title**:菜单的标题,如果同时使用[国际化插件](./locale.md),而且在 `locales` 中配置了 `title` ,则菜单的名称会根据语言自动切换。
|
||||||
|
|
||||||
- **icon**: 菜单的图标,只有一级标题展示图标,图标使用[antv icon](https://www.antdv.com/components/icon-cn/),在这里使用组件type。
|
- **icon**: 菜单的图标,只有一级标题展示图标。
|
||||||
|
- 图标使用[antv icon](https://www.antdv.com/components/icon-cn/),在这里使用组件type。
|
||||||
|
```js
|
||||||
|
{
|
||||||
|
name: "user"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
- 图表使用本地或者远程svg图片。
|
||||||
|
```js
|
||||||
|
{
|
||||||
|
name: "/wine-outline.svg"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
- **children**:子菜单配置。
|
- **children**:子菜单配置。
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ Fes.js 约定 `src/mock.js` 为 mock 文件。
|
|||||||
|
|
||||||
可以参考如下 🌰:
|
可以参考如下 🌰:
|
||||||
``` js
|
``` js
|
||||||
module.exports = function ({ cgiMock, mockjs, utils }) {
|
export default function ({ cgiMock, mockjs, utils }) {
|
||||||
const { Random } = mockjs;
|
const { Random } = mockjs;
|
||||||
|
|
||||||
// 测试 proxy 与 mock 用例集合
|
// 测试 proxy 与 mock 用例集合
|
||||||
@ -160,7 +160,7 @@ module.exports = function ({ cgiMock, mockjs, utils }) {
|
|||||||
|
|
||||||
比如:
|
比如:
|
||||||
```js
|
```js
|
||||||
module.exports = function ({ cgiMock, mockjs, utils }) {
|
export default function ({ cgiMock, mockjs, utils }) {
|
||||||
cgiMock('/random', mockjs.mock({
|
cgiMock('/random', mockjs.mock({
|
||||||
'string|1-10': '★'
|
'string|1-10': '★'
|
||||||
}));
|
}));
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { existsSync, readFileSync } from 'fs';
|
import { existsSync, readFileSync } from 'fs';
|
||||||
import { resolve } from 'path';
|
import { resolve } from 'path';
|
||||||
import { chokidar, lodash } from '@umijs/utils';
|
import { chokidar, lodash, parseRequireDeps } from '@umijs/utils';
|
||||||
import bodyParser from 'body-parser';
|
import bodyParser from 'body-parser';
|
||||||
import cookieParser from 'cookie-parser';
|
import cookieParser from 'cookie-parser';
|
||||||
import mockjs from 'mockjs';
|
import mockjs from 'mockjs';
|
||||||
@ -11,6 +11,24 @@ export default (api) => {
|
|||||||
let mockFile = ''; // mock 文件
|
let mockFile = ''; // mock 文件
|
||||||
let loadMock = ''; // mock 对象
|
let loadMock = ''; // mock 对象
|
||||||
|
|
||||||
|
const registerBabel = (paths) => {
|
||||||
|
// support
|
||||||
|
// clear require cache and set babel register
|
||||||
|
const requireDeps = paths.reduce((memo, file) => {
|
||||||
|
memo = memo.concat(parseRequireDeps(file));
|
||||||
|
return memo;
|
||||||
|
}, []);
|
||||||
|
requireDeps.forEach((f) => {
|
||||||
|
if (require.cache[f]) {
|
||||||
|
delete require.cache[f];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
api.babelRegister.setOnlyMap({
|
||||||
|
key: 'mock',
|
||||||
|
value: [...paths, ...requireDeps]
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
api.describe({
|
api.describe({
|
||||||
key: 'mock',
|
key: 'mock',
|
||||||
config: {
|
config: {
|
||||||
@ -96,11 +114,14 @@ export default (api) => {
|
|||||||
}
|
}
|
||||||
// require最新的 mock.js 文件
|
// require最新的 mock.js 文件
|
||||||
try {
|
try {
|
||||||
const projectMock = require(mockFile);
|
// register babel
|
||||||
if (!lodash.isFunction(projectMock)) {
|
registerBabel([mockFile]);
|
||||||
|
const _initFunction = require(mockFile);
|
||||||
|
const initFunction = _initFunction.default || _initFunction;
|
||||||
|
if (!lodash.isFunction(initFunction)) {
|
||||||
api.logger.info('mock.js should export Function'); return;
|
api.logger.info('mock.js should export Function'); return;
|
||||||
}
|
}
|
||||||
projectMock({ cgiMock, mockjs, utils });
|
initFunction({ cgiMock, mockjs, utils });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
api.logger.error('mock.js run fail!');
|
api.logger.error('mock.js run fail!');
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
module.exports = function ({ cgiMock, mockjs, utils }) {
|
export default function ({ cgiMock, mockjs, utils }) {
|
||||||
const { Random } = mockjs;
|
const { Random } = mockjs;
|
||||||
|
|
||||||
// 测试 proxy 与 mock 用例集合
|
// 测试 proxy 与 mock 用例集合
|
||||||
@ -127,4 +127,4 @@ module.exports = function ({ cgiMock, mockjs, utils }) {
|
|||||||
msg: '文件上传成功'
|
msg: '文件上传成功'
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user