Browse Source
* commit 'e3476db6074891cadc734fc5bd9bf2dadda12fdb': DEC-12158 fix: 国际化测试,遇到的一些界面问题 fix: 由于容错率的关系,Number方法改成parseInt fix: DEC-11221 加入对可输入数值的区间验证 DEC-11995 feat:密码传输自定义接口 fix: 修改eslint fix: 修改eslint fix: DEC-12046 修复本地运行时报错的问题 DEC-11996 feat: 【华为安全】内存等敏感信息需要鉴权才能获得,前台websocket事件携带token参数 fix: 修改i18n的写法 fix: DEC-11815 修改数据连接名称的长度限制 fix: 修改写法 fix: 修复url为空时地址以/结尾的bug fix: DEC-11797 改用dec中自带的http请求方法 fix: DEC-11782 oracle数据连接url端口号和数据库之间可能是/或: fix: 更新数据连接解析 fix: 加一下国际化 DEC-11528 feat: ADS数据库改为阿里云AnalyticDBbugfix/10.0
Dailer|翠屏山最速下山传说
5 years ago
18 changed files with 268 additions and 142 deletions
@ -1,2 +1,6 @@
|
||||
export const CONSTANT_PLUGIN_TYPES = 'dec.constant.database.conf.connect.types'; |
||||
BI.constant(CONSTANT_PLUGIN_TYPES, []); |
||||
/** |
||||
* 数据连接名称的最大长度 |
||||
*/ |
||||
export const NAME_MAX_LENGTH = 150; |
||||
|
@ -1,121 +1,38 @@
|
||||
import 'es6-promise/auto'; |
||||
import axios, { AxiosResponse, AxiosError } from 'axios'; |
||||
import { CrudReqOpts, CrudParams, ResultType } from './crud.typings.d'; |
||||
import { ReqPrefix, errorCode } from '../constants/env'; |
||||
const defaultHeaders = { |
||||
'Content-Type': 'application/json', |
||||
'X-Requested-With': 'XMLHttpRequest', |
||||
}; |
||||
import { ResultType } from './crud.typings.d'; |
||||
import { ReqPath } from '../constants/env'; |
||||
|
||||
export function paramsSerializer(params: { [key: string]: any }) { |
||||
return Object.keys(params || {}) |
||||
.map(paramKey => { |
||||
const paramValue = params[paramKey]; |
||||
|
||||
let value = ''; |
||||
|
||||
if (BI.isObject(paramValue)) { |
||||
value = encodeURIComponent(JSON.stringify(paramValue)); |
||||
} else { |
||||
value = paramValue; |
||||
} |
||||
|
||||
return BI.isNull(value) ? '' : `${paramKey}=${value}`; |
||||
}) |
||||
.filter(v => v !== '') |
||||
.join('&'); |
||||
} |
||||
function getCookieByName(name: string):string { |
||||
let value = null; |
||||
const regExpName = new RegExp(name); |
||||
document.cookie.split(';').forEach((item: string) => { |
||||
if (item.match(regExpName)) { |
||||
value = item.split(`${name}=`)[1]; |
||||
|
||||
return false; |
||||
} |
||||
}); |
||||
|
||||
return value; |
||||
} |
||||
|
||||
function checkStatus(response: AxiosResponse) { |
||||
const status = response.status; |
||||
const noLoginErr = [errorCode.LOGIN_INFO_ERROR, errorCode.LOGIN_INFO_NOT_AVAILABLE, errorCode.TIMEOUT]; |
||||
|
||||
const resData = status === 200 |
||||
? typeof response.data === 'string' |
||||
? BI.jsonDecode(response.data) |
||||
: response.data |
||||
: {}; |
||||
if (noLoginErr.includes(BI.get(resData, 'errorCode'))) { |
||||
BI.Msg.alert(BI.i18nText('BI-Basic_Prompt'), BI.i18nText('Dec-Dcm_Login_Error'), () => { |
||||
window.location.reload(true); |
||||
}); |
||||
|
||||
return new Promise(() => {}); |
||||
} |
||||
|
||||
return resData; |
||||
function getFullUrl(url: string) { |
||||
return url ? `${ReqPath}/${url}` : ReqPath; |
||||
} |
||||
|
||||
export async function request(reqOptions: CrudReqOpts = {}): Promise<ResultType> { |
||||
const { url, type, headers, data, params } = reqOptions; |
||||
|
||||
return axios |
||||
.request({ |
||||
url, |
||||
baseURL: ReqPrefix, |
||||
method: type, |
||||
headers: { |
||||
...defaultHeaders, |
||||
...headers, |
||||
Authorization: `Bearer ${getCookieByName('fine_auth_token')}`, |
||||
'Content-Type': 'application/json;charset=UTF-8', |
||||
}, |
||||
params, |
||||
paramsSerializer, |
||||
data, |
||||
}) |
||||
.then(checkStatus) |
||||
.catch((error: AxiosError) => { |
||||
console.log(error); |
||||
export function requestGet(url: string, data?: any): Promise<ResultType> { |
||||
return new Promise(resolve => { |
||||
Dec.reqGet(getFullUrl(url), '', re => { |
||||
resolve(re); |
||||
}); |
||||
} |
||||
|
||||
export function requestGet(url: string, data?: any, params: CrudParams = {}) { |
||||
const timeStamp = new Date().getTime(); |
||||
|
||||
return request({ |
||||
url: url.includes('?') ? `${url}&_=${timeStamp}` : `${url}?_=${timeStamp}`, |
||||
type: 'GET', |
||||
data, |
||||
params, |
||||
}); |
||||
} |
||||
|
||||
export function requestPost(url: string, data = {}, params: CrudParams = {}) { |
||||
return request({ |
||||
url, |
||||
type: 'POST', |
||||
data, |
||||
params, |
||||
export function requestPost(url: string, data = {}): Promise<ResultType> { |
||||
return new Promise(resolve => { |
||||
Dec.reqPost(getFullUrl(url), data, re => { |
||||
resolve(re); |
||||
}); |
||||
}); |
||||
} |
||||
|
||||
export function requestDelete(url: string, data = {}) { |
||||
return request({ |
||||
url, |
||||
type: 'DELETE', |
||||
data, |
||||
return new Promise(resolve => { |
||||
Dec.reqDelete(getFullUrl(url), data, re => { |
||||
resolve(re); |
||||
}); |
||||
}); |
||||
} |
||||
|
||||
export function requestPut(url: string, data = {}, params: CrudParams = {}) { |
||||
return request({ |
||||
url, |
||||
type: 'PUT', |
||||
data, |
||||
params, |
||||
export function requestPut(url: string, data = {}) { |
||||
return new Promise(resolve => { |
||||
Dec.reqPut(getFullUrl(url), data, re => { |
||||
resolve(re); |
||||
}); |
||||
}); |
||||
} |
||||
|
@ -0,0 +1,118 @@
|
||||
import 'es6-promise/auto'; |
||||
import axios, { AxiosResponse, AxiosError } from 'axios'; |
||||
import { CrudReqOpts, ResultType } from './modules/crud/crud.typings'; |
||||
import { fineServletURL, errorCode } from './modules/constants/env'; |
||||
const defaultHeaders = { |
||||
'Content-Type': 'application/json', |
||||
'X-Requested-With': 'XMLHttpRequest', |
||||
}; |
||||
|
||||
export function paramsSerializer(params: { [key: string]: any }) { |
||||
return Object.keys(params || {}) |
||||
.map(paramKey => { |
||||
const paramValue = params[paramKey]; |
||||
|
||||
let value = ''; |
||||
|
||||
if (BI.isObject(paramValue)) { |
||||
value = encodeURIComponent(JSON.stringify(paramValue)); |
||||
} else { |
||||
value = paramValue; |
||||
} |
||||
|
||||
return BI.isNull(value) ? '' : `${paramKey}=${value}`; |
||||
}) |
||||
.filter(v => v !== '') |
||||
.join('&'); |
||||
} |
||||
function getCookieByName(name: string):string { |
||||
let value = null; |
||||
const regExpName = new RegExp(name); |
||||
document.cookie.split(';').forEach((item: string) => { |
||||
if (item.match(regExpName)) { |
||||
value = item.split(`${name}=`)[1]; |
||||
|
||||
return false; |
||||
} |
||||
}); |
||||
|
||||
return value; |
||||
} |
||||
|
||||
function checkStatus(response: AxiosResponse) { |
||||
const status = response.status; |
||||
const noLoginErr = [errorCode.LOGIN_INFO_ERROR, errorCode.LOGIN_INFO_NOT_AVAILABLE, errorCode.TIMEOUT]; |
||||
|
||||
const resData = status === 200 |
||||
? typeof response.data === 'string' |
||||
? BI.jsonDecode(response.data) |
||||
: response.data |
||||
: {}; |
||||
if (noLoginErr.includes(BI.get(resData, 'errorCode'))) { |
||||
BI.Msg.alert(BI.i18nText('BI-Basic_Prompt'), BI.i18nText('Dec-Dcm_Login_Error'), () => { |
||||
window.location.reload(true); |
||||
}); |
||||
|
||||
return new Promise(() => {}); |
||||
} |
||||
|
||||
return resData; |
||||
} |
||||
|
||||
export async function request(reqOptions: CrudReqOpts = {}): Promise<ResultType> { |
||||
const { url, type, headers, data, params } = reqOptions; |
||||
|
||||
return axios |
||||
.request({ |
||||
url, |
||||
baseURL: fineServletURL, |
||||
method: type, |
||||
headers: { |
||||
...defaultHeaders, |
||||
...headers, |
||||
Authorization: `Bearer ${getCookieByName('fine_auth_token')}`, |
||||
'Content-Type': 'application/json;charset=UTF-8', |
||||
}, |
||||
params, |
||||
paramsSerializer, |
||||
data, |
||||
}) |
||||
.then(checkStatus) |
||||
.catch((error: AxiosError) => { |
||||
console.log(error); |
||||
}); |
||||
} |
||||
|
||||
Dec.reqGet = (url: string, data: any, callback: (re: any) => void) => { |
||||
const timeStamp = new Date().getTime(); |
||||
|
||||
request({ |
||||
url: url.includes('?') ? `${url}&_=${timeStamp}` : `${url}?_=${timeStamp}`, |
||||
type: 'GET', |
||||
data, |
||||
}).then(re => callback(re)); |
||||
}; |
||||
|
||||
Dec.reqPost = (url: string, data: any, callback: (re: any) => void) => { |
||||
request({ |
||||
url, |
||||
type: 'POST', |
||||
data, |
||||
}).then(re => callback(re)); |
||||
}; |
||||
|
||||
Dec.reqDelete = (url: string, data: any, callback: (re: any) => void) => { |
||||
request({ |
||||
url, |
||||
type: 'DELETE', |
||||
data, |
||||
}).then(re => callback(re)); |
||||
}; |
||||
|
||||
Dec.reqPut = (url: string, data: any, callback: (re: any) => void) => { |
||||
request({ |
||||
url, |
||||
type: 'PUT', |
||||
data, |
||||
}).then(re => callback(re)); |
||||
}; |
Loading…
Reference in new issue