提交 07fa1bbf 作者: 潘亚楠

增加easymockcli及javaapi

上级 fb2cf178
module.exports = {
output: "../src/java_api",
template: "./",
host: "http://mock.allhome.com.cn",
env: 'development',
projects: [
{
id: "5db2630933901100102f2e2f",
name: "JavaLogTest"
}
]
};
{
"result": {},
"statusCode": 1000,
"message": "ok"
}
\ No newline at end of file
var convertUrl = exports.convertUrl = function (url) {
// /restful/:id/:list/{id} -> restful_id_list_id
// /restful/:id/:list/{id}.json -> restful_id_list_id
var _url = url
.replace(/:|{|}/g, '')
.replace(/-/g, '_')
.split('/')
.filter(value => !!value).join('_');
return _url.split('.')[0];
};
exports.convertMethod = function (mock) {
// 防止重名
// restful_id_list_id => restful_id_list_id_g
// or
// restful_id_list_id => restful_id_list_id_p
return convertUrl(mock.url) + '_' + mock.method.toLowerCase();
};
exports.joinUrl = function () {
// https://www.easy-mock.com//mock/.... => https://www.easy-mock.com/mock/....
var url = [].slice.call(arguments, 0).join('/');
url = url.replace(/:\//g, '://');
url = url.replace(/([^:\s\%\3\A])\/+/g, '$1/');
return url;
}
exports.isREST = function (url) {
return /(:|{|})/.test(url);
}
export default {
env: process.env.NODE_ENV || 'mock'
};
<% _.forEach(config.projects, function(project){ %>import * as {{$$.convertUrl(project.name)}} from './{{project.name}}';<% }) %>
export {<% _.forEach(config.projects, function(project, i){ %>
{{$$.convertUrl(project.name)}}<% if(config.projects.length - 1 !== i) { %>,<% } %><% }) %>
};
/* 根据opts中的属性替换url中相应的pathname */
function convertRESTAPI(url, opts) {
if (!opts) return url;
const pathKeys = Object.keys(opts);
pathKeys.forEach((key) => {
const r = new RegExp('(:' + key + '|{' + key + '})', 'g');
url = url.replace(r, opts[key]);
});
return url;
}
export {
convertRESTAPI
};
import instance from './instance';
import { convertRESTAPI } from '{{$$.relative("util")}}';
<% _.forEach(data.mocks, function(mock){ %>/** {{mock.description}} */
function {{$$.convertMethod(mock)}}(data) {
return instance['{{mock.method}}'](<% if($$.isREST(mock.url)) {%>convertRESTAPI('{{mock.url}}', data)<%} else {%> '{{mock.url}}'<% } %>, data)
}
<% }) %>export {<% _.forEach(data.mocks, function(mock, i){ %>
{{$$.convertMethod(mock)}}<% if(data.mocks.length - 1 !== i) { %>,<% } %><% }) %>
};
import config from '{{$$.relative("config")}}';
import { Request } from 'web_notebook-test1';
import commonInterceptors from '@/assets/js/common_interceptors';
const baseURL = {
mock: '{{$$.joinUrl(config.host, "mock", data.project._id, data.project.url)}}',
development : 'http://192.168.10.12:8991',
lan: `http://192.168.10.200:8009/projectName`,
pred: `https://dtgateway.allhome.com.cn/projectName`,
production: `https://gateway.allhome.com.cn/projectName`
}[config.env];
const request = new Request({
baseURL,
timeout: 60000,
}, process.env.NODE_ENV, 'web_log_test')
// 设置拦截器
request.interceptors(commonInterceptors)
export default request.axios;
......@@ -10,7 +10,8 @@
"unit": "cross-env BABEL_ENV=test karma start test/unit/karma.conf.js --single-run",
"e2e": "node test/e2e/runner.js",
"test": "npm run unit && npm run e2e",
"build": "node build/build.js"
"build": "node build/build.js",
"create-api": "easymock init easy_mock"
},
"dependencies": {
"axios": "^0.18.0",
......@@ -39,6 +40,7 @@
"cross-spawn": "^5.0.1",
"css-loader": "^0.28.0",
"debug": "^4.1.1",
"easy-mock-cli": "^0.4.3",
"eslint": "^4.15.0",
"eslint-config-standard": "^10.2.1",
"eslint-friendly-formatter": "^3.0.0",
......
import axios from 'axios'
import { Request } from 'web_notebook-test1';
let version = 'v1'
let path = {
// 开发
development: `http://192.168.10.200:8020/upaLogs`,
// 200
lan: `http://192.168.10.200:8009/projectName/${version}`,
// 测试
pred: `https://dtgateway.allhome.com.cn/projectName/${version}`,
// 线上
production: `https://gateway.allhome.com.cn/projectName/${version}`
}
// 组件库封装之后的请求
const request = new Request({
baseURL: path[process.env.NODE_ENV],
timeout: 60000,
}, process.env.NODE_ENV, 'web_log_test');
// token
const devToken = 'L2bhC0FyEWXo9zkt6mQ15lMzsSgS3dR/V+w5iWSiMmG0H0t1pL9lr4o+nSKXhjOm9qT+UrXqbLUpiWmITwS1q6TPmZvSumEkoEzpYFr0ylbxHafk+uE8yvK9OWiYl9WEH/JdnMw2LVnVYur7LOe/r57MMxw4e/NxGKPo07pqgn8=';
const token = window.token? window.token: (window.token = devToken);
// 设置拦截器
request.interceptors({
export default {
request: config => {
config.headers.token = token;
return config
......@@ -48,6 +25,4 @@ request.interceptors({
}
},
error: error => Promise.reject(error.response.data),
})
export default request;
\ No newline at end of file
}
\ No newline at end of file
import { Request } from 'web_notebook-test1';
import commonInterceptors from './common_interceptors';
let version = 'v1'
let path = {
// 开发
development: `http://192.168.10.200:8020/upaLogs`,
// 200
lan: `http://192.168.10.200:8009/projectName/${version}`,
// 测试
pred: `https://dtgateway.allhome.com.cn/projectName/${version}`,
// 线上
production: `https://gateway.allhome.com.cn/projectName/${version}`
}
// 组件库封装之后的请求
const request = new Request({
baseURL: path[process.env.NODE_ENV],
timeout: 60000,
}, process.env.NODE_ENV, 'web_log_test');
// 设置拦截器
request.interceptors(commonInterceptors)
export default request;
\ No newline at end of file
import instance from './instance';
import { convertRESTAPI } from '../util';
/** 获取用户列表 */
function test_user_page_page_pageSize_get(data) {
return instance['get'](convertRESTAPI('/test/user/page/{page}/{pageSize}', data), data)
}
/** 获取用户列表表头 */
function test_user_page_head_get(data) {
return instance['get']( '/test/user/page/head', data)
}
/** 修改用户 */
function test_user_put(data) {
return instance['put']( '/test/user', data)
}
/** 添加用户 */
function test_user_post(data) {
return instance['post']( '/test/user', data)
}
/** 获取用户 */
function test_user_get(data) {
return instance['get']( '/test/user', data)
}
/** 删除一个用户 */
function test_user_delete(data) {
return instance['delete']( '/test/user', data)
}
/** 服务异常接口测试 */
function test_error_put(data) {
return instance['put']( '/test/error', data)
}
export {
test_user_page_page_pageSize_get,
test_user_page_head_get,
test_user_put,
test_user_post,
test_user_get,
test_user_delete,
test_error_put
};
import config from '../config';
import { Request } from 'web_notebook-test1';
import commonInterceptors from '@/assets/js/common_interceptors';
const baseURL = {
mock: 'http://mock.allhome.com.cn/mock/5db2630933901100102f2e2f/javaLog',
development : 'http://192.168.10.12:8991',
lan: `http://192.168.10.200:8009/projectName`,
pred: `https://dtgateway.allhome.com.cn/projectName`,
production: `https://gateway.allhome.com.cn/projectName`
}[config.env];
const request = new Request({
baseURL,
timeout: 60000,
}, process.env.NODE_ENV, 'web_log_test')
// 设置拦截器
request.interceptors(commonInterceptors)
export default request.axios;
export default {
env: process.env.NODE_ENV || 'mock'
};
import * as JavaLogTest from './JavaLogTest';
export {
JavaLogTest
};
/* 根据opts中的属性替换url中相应的pathname */
function convertRESTAPI(url, opts) {
if (!opts) return url;
const pathKeys = Object.keys(opts);
pathKeys.forEach((key) => {
const r = new RegExp('(:' + key + '|{' + key + '})', 'g');
url = url.replace(r, opts[key]);
});
return url;
}
export {
convertRESTAPI
};
import request from '@/assets/js/axios.js';
import request from '@/assets/js/node_axios.js';
/**
* 数据接口层
* @author author
......
......@@ -12,7 +12,8 @@
* @information button点击操作日志手机测试页
*/
import createDebug from 'debug';
import nodeApi from '@/api/node'
import nodeApi from '@/node_api'
import * as javaApi from '@/java_api/JavaLogTest'
const debug = createDebug('testButtonClick')
export default {
......@@ -28,10 +29,11 @@ export default {
"userName": "string",
"password": "string"
}
let res = await nodeApi.rightServerPost({
let node = await nodeApi.rightServerPost({
param: [1, 2],
data: model
});
let java = await javaApi.test_error_put();
},
/**
* @date 2019.10.24
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论