perf:发布版本1.0.2
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1,3 @@
|
|||||||
/.idea/
|
/.idea/
|
||||||
/package-lock.json
|
/package-lock.json
|
||||||
|
/node_modules/
|
||||||
|
|||||||
8
index.js
8
index.js
@@ -1,8 +1,8 @@
|
|||||||
import HttpUtil from "./src/https/HttpUtil";
|
const Common = require('./src/utils/Common')
|
||||||
import Common from "./src/utils/Common";
|
const Storage = require('./src/utils/Storage')
|
||||||
import Storage from "./src/utils/Storage";
|
const HttpUtil = require('./src/https/HttpUtil')
|
||||||
|
|
||||||
export default {
|
module.exports = {
|
||||||
HttpUtil,
|
HttpUtil,
|
||||||
Common,
|
Common,
|
||||||
Storage,
|
Storage,
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
{
|
{
|
||||||
"name": "@tiesheng/npm-tool",
|
"name": "@tiesheng/npm-tool",
|
||||||
"version": "1.0.2",
|
"version": "1.0.1",
|
||||||
"description": "npm tool package",
|
"description": "npm tool package",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"type": "commonjs",
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
},
|
},
|
||||||
@@ -21,6 +20,7 @@
|
|||||||
"@tiesheng:registry": "http://git.kepai365.com/api/v4/projects/417/packages/npm/"
|
"@tiesheng:registry": "http://git.kepai365.com/api/v4/projects/417/packages/npm/"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"cryptsm2-sm4": "^1.0.1",
|
||||||
"umi-request": "1.4.0"
|
"umi-request": "1.4.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,45 @@
|
|||||||
import request from 'umi-request';
|
const {extend} = require('umi-request');
|
||||||
import Storage from '../utils/Storage';
|
const Storage = require('../utils/Storage');
|
||||||
import Common from '../utils/Common';
|
const Common = require('../utils/Common');
|
||||||
|
|
||||||
|
const codeMessage = {
|
||||||
|
200: "服务器成功返回请求的数据。",
|
||||||
|
201: "新建或修改数据成功。",
|
||||||
|
202: "一个请求已经进入后台排队(异步任务)。",
|
||||||
|
204: "删除数据成功。",
|
||||||
|
400: "发出的请求有错误,服务器没有进行新建或修改数据的操作。",
|
||||||
|
401: "用户没有权限(令牌、用户名、密码错误)。",
|
||||||
|
403: "用户得到授权,但是访问是被禁止的。",
|
||||||
|
404: "发出的请求针对的是不存在的记录,服务器没有进行操作。",
|
||||||
|
406: "请求的格式不可得。",
|
||||||
|
410: "请求的资源被永久删除,且不会再得到的。",
|
||||||
|
422: "当创建一个对象时,发生一个验证错误。",
|
||||||
|
500: "服务器发生错误,请检查服务器。",
|
||||||
|
502: "网关错误。",
|
||||||
|
503: "服务不可用,服务器暂时过载或维护。",
|
||||||
|
504: "网关超时。",
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 异常处理程序
|
||||||
|
*/
|
||||||
|
const errorHandler = (error) => {
|
||||||
|
const {response = {}} = error;
|
||||||
|
let res = {code: -1, message: "参数错误或服务器异常"};
|
||||||
|
if (!Common.isEmpty(res)) {
|
||||||
|
res = {code: response.status, message: codeMessage[response.status] || response.statusText};
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 配置request请求时的默认参数
|
||||||
|
*/
|
||||||
|
const request = extend({
|
||||||
|
errorHandler, // 默认错误处理
|
||||||
|
credentials: "include", // 默认请求是否带上cookie,
|
||||||
|
requestType: "json", // 表单提交post请求
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通用数据处理
|
* 通用数据处理
|
||||||
@@ -45,7 +84,15 @@ async function req(url, options) {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
res.code == 200 ? resolve(res.data) : reject(res);
|
if (res.code == 200) {
|
||||||
|
let data = res.data;
|
||||||
|
if (res.encrypt) {
|
||||||
|
|
||||||
|
}
|
||||||
|
resolve(data)
|
||||||
|
} else {
|
||||||
|
reject(res)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
reject({code: err.data.status, message: err.data.error});
|
reject({code: err.data.status, message: err.data.error});
|
||||||
@@ -81,9 +128,10 @@ async function form(url, data = {}) {
|
|||||||
return req(url, {method: 'POST', data, requestType: 'form'});
|
return req(url, {method: 'POST', data, requestType: 'form'});
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
|
||||||
|
module.exports = {
|
||||||
req,
|
req,
|
||||||
get,
|
get,
|
||||||
post,
|
post,
|
||||||
form,
|
form,
|
||||||
};
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ const getParamFormUrl = (key, host) => {
|
|||||||
* @param value
|
* @param value
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
export const isEmpty = (value) => {
|
const isEmpty = (value) => {
|
||||||
return value === undefined || value === null || value === '';
|
return value === undefined || value === null || value === '';
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@ export const isEmpty = (value) => {
|
|||||||
* @param value
|
* @param value
|
||||||
* @param def
|
* @param def
|
||||||
*/
|
*/
|
||||||
export const parseJSON = (value, def = {}) => {
|
const parseJSON = (value, def = {}) => {
|
||||||
let obj;
|
let obj;
|
||||||
try {
|
try {
|
||||||
obj = JSON.parse(value);
|
obj = JSON.parse(value);
|
||||||
@@ -48,7 +48,7 @@ export const parseJSON = (value, def = {}) => {
|
|||||||
* @param obj
|
* @param obj
|
||||||
* @param seq
|
* @param seq
|
||||||
*/
|
*/
|
||||||
export const split = (obj, seq = ',') => {
|
const split = (obj, seq = ',') => {
|
||||||
if (obj) {
|
if (obj) {
|
||||||
return obj.split(seq);
|
return obj.split(seq);
|
||||||
}
|
}
|
||||||
@@ -60,7 +60,7 @@ export const split = (obj, seq = ',') => {
|
|||||||
* @param key
|
* @param key
|
||||||
* @param url
|
* @param url
|
||||||
*/
|
*/
|
||||||
export const isDevelopment = () => {
|
const isDevelopment = () => {
|
||||||
return process.env.NODE_ENV === 'development';
|
return process.env.NODE_ENV === 'development';
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -81,12 +81,12 @@ const replaceAll = (string, s1, s2) => {
|
|||||||
* @param endStr
|
* @param endStr
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
export const endWith = (string = '', endStr) => {
|
const endWith = (string = '', endStr) => {
|
||||||
let d = string.length - endStr.length;
|
let d = string.length - endStr.length;
|
||||||
return d >= 0 && string.lastIndexOf(endStr) == d;
|
return d >= 0 && string.lastIndexOf(endStr) == d;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default {
|
module.exports = {
|
||||||
getParamFormUrl,
|
getParamFormUrl,
|
||||||
isEmpty,
|
isEmpty,
|
||||||
parseJSON,
|
parseJSON,
|
||||||
|
|||||||
8
src/utils/Crypto.js
Normal file
8
src/utils/Crypto.js
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
const {SM4} = require('cryptsm2-sm4');
|
||||||
|
|
||||||
|
|
||||||
|
// let decryptByDataKey = app.decryptByDataKey("LT7Wd2k7tk0EXuGtUAyz0Q==", );
|
||||||
|
|
||||||
|
const sm4 = new SM4("WmdUzPJXbngVNiaSsQrihg==");
|
||||||
|
sm4.
|
||||||
|
console.log(sm4);
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import Common from "./Common";
|
const Common = require("./Common");
|
||||||
|
|
||||||
///////////////////////////////////////// 用户token
|
///////////////////////////////////////// 用户token
|
||||||
|
|
||||||
@@ -34,7 +34,7 @@ const get = (key) => {
|
|||||||
|
|
||||||
///////////////////////////////////////// 导出模块
|
///////////////////////////////////////// 导出模块
|
||||||
|
|
||||||
export default {
|
module.exports = {
|
||||||
save,
|
save,
|
||||||
get,
|
get,
|
||||||
saveUserToken,
|
saveUserToken,
|
||||||
|
|||||||
Reference in New Issue
Block a user