# e-mock **Repository Path**: MRLH/e-mock ## Basic Information - **Project Name**: e-mock - **Description**: 实现增删改查的完全模拟 - **Primary Language**: NodeJS - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2018-11-14 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # e-mock > An electron-vue project Mock项目,实现增删改查完全的模拟。 本项目以 electron、vue、koa2实现。 #### Build Setup ``` bash # install dependencies npm install # serve with hot reload at localhost:9080 npm run dev # build electron application for production npm run build # lint all JS/Vue component files in `src/` npm run lint ``` --- This project was generated with [electron-vue](https://github.com/SimulatedGREG/electron-vue)@[8fae476](https://github.com/SimulatedGREG/electron-vue/tree/8fae4763e9d225d3691b627e83b9e09b56f6c935) using [vue-cli](https://github.com/vuejs/vue-cli). Documentation about the original structure can be found [here](https://simulatedgreg.gitbooks.io/electron-vue/content/index.html). ## mock配置说明 ### 1. mock目录 选择目录(如根目录下的mock文件夹),点击载入按钮即可载入mock配置文件。 mock目录下必须有config.json文件。 每次点击载入按钮相当于重启服务器。 ### 2. config.json ```json { "http": [], "plugins": [] } ``` #### 2.1 http http为配置web请求映射 ```json { "http": [ { "context": "", "includes": [] } ] } ``` context为上下文路径 includes为web请求配置文件路径,均为json文件 ```json [ { "request": { "method": "get", "uri": "" }, "response": { "file": "" } } ] ``` method为配置请求类型,目前仅能配置get和post请求; uri为配置请求地址; file指定请求的返回值,是个文件路径;根据后缀名可以是一个json文件,或者是一个js文件。 其中js文件中必须有且只有一个函数, 且这个函数需有返回值,其函数的返回值既是请求的返回值。 ```js (param, plugins) => { /** * param: 请求参数 * plugins: 插件项 */ return '' } ``` #### 2.2 plugins 该项为配置可用插件列表,可自定义各种类型的插件,插件为js文件。 比如数据存储插件,以实现增删改查的模拟等等。 ```js plugins => { // plugins } ``` 插件文件中有且包含一个函数,且只有一个参数。这个参数为全局参数。所有的插件均通过这个函数挂载到这个全局参数上去。 ## 页面说明 本程序分为5个tab页。 其中: 1. 配置页用于配置服务器参数信息。 2. 请求管理页为加载完mock配置项后展示所有可用地址。 3. 请求模拟页为测试请求发送,这是真实的向服务器发请求。 3.1 url可以是不完全的url,完全的url必须带http:// 3.2 参数为json格式 4. 操作日志页可以看到操作信息以及一些服务启动过程中的报错信息,比如mock文件配置错误等等。 5. 访问日志可以看到向服务器发的一些请求的信息 ## 样例——学生的增删改查 先配置并载入根目录下的mock文件夹 查列表 ```text url get /student/list 参数 返回值 { "code": "0000", "msg": "成功", "data": [ { "id": "1", "name": "小王" }, { "id": "2", "name": "小李" } ] } ``` ```text url get /student/list 参数 { "name": "李" } 返回值 { "code": "0000", "msg": "成功", "data": [ { "id": "2", "name": "小李" } ] } ``` 查详情 ```text url get /student/detail 参数 { "id": "1" } 返回值 { "code": "0000", "msg": "成功", "data": { "id": "1", "name": "小王" } } ``` 增 ```text url post-json /student/add 参数 { "name": "小增" } 返回值 { "code": "0000", "msg": "新增成功", "data": null } ``` ```text url get /student/list 参数 返回值 { "code": "0000", "msg": "成功", "data": [ { "id": "1", "name": "小王" }, { "id": "2", "name": "小李" }, { "id": "NO1542187239140", "name": "小增" } ] } ``` 改 ```text url post-json /student/update 参数 { "id": "1", "name": "小改" } 返回值 { "code": "0000", "msg": "更新成功", "data": null } ``` ```text url post-json /student/detail 参数 { "id": "1" } 返回值 { "code": "0000", "msg": "成功", "data": { "id": "1", "name": "小改" } } ``` 删 ```text url post-json /student/delete 参数 { "id": "1" } 返回值 { "code": "0000", "msg": "删除成功", "data": null } ``` ```text url get /student/list 参数 返回值 { "code": "0000", "msg": "成功", "data": [ { "id": "2", "name": "小李" }, { "id": "NO1542187239140", "name": "小增" } ] } ```