mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-03-06 02:11:56 +00:00
Merge branch feat/ali-npm into 2.x
Title: feat: delete @ali npm used code Link: https://code.aone.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/codereview/7187960
This commit is contained in:
commit
b1383fa773
@ -13,9 +13,6 @@
|
|||||||
"build": "build-scripts build --skip-demo"
|
"build": "build-scripts build --skip-demo"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ali/b3-one": "^0.0.17",
|
|
||||||
"@ali/bzb-request": "^2.6.0-beta.13",
|
|
||||||
"@ali/lib-mtop": "^2.5.1",
|
|
||||||
"@ali/lowcode-datasource-engine": "^1.0.22",
|
"@ali/lowcode-datasource-engine": "^1.0.22",
|
||||||
"@ali/lowcode-types": "1.0.74",
|
"@ali/lowcode-types": "1.0.74",
|
||||||
"@ali/lowcode-utils": "1.0.74",
|
"@ali/lowcode-utils": "1.0.74",
|
||||||
|
|||||||
4
packages/renderer-core/src/module.d.ts
vendored
4
packages/renderer-core/src/module.d.ts
vendored
@ -1,4 +0,0 @@
|
|||||||
// tips: Q29weXJpZ2h0IChjKSAyMDIwLXByZXNlbnQgQWxpYmFiYSBJbmMuIFYz
|
|
||||||
declare module '@ali/b3-one/lib/obj';
|
|
||||||
declare module '@ali/b3-one/lib/url';
|
|
||||||
declare module '@ali/lib-mtop';
|
|
||||||
@ -1,8 +1,7 @@
|
|||||||
import Debug from 'debug';
|
import Debug from 'debug';
|
||||||
import { isEmpty } from '@ali/b3-one/lib/obj';
|
|
||||||
import adapter from '../adapter';
|
import adapter from '../adapter';
|
||||||
import contextFactory from '../context';
|
import contextFactory from '../context';
|
||||||
import { isFileSchema, goldlog } from '../utils';
|
import { isFileSchema, goldlog, isEmpty } from '../utils';
|
||||||
import baseRendererFactory from './base';
|
import baseRendererFactory from './base';
|
||||||
import divFactory from '../components/Div';
|
import divFactory from '../components/Div';
|
||||||
import { IProps, ISchema, IState } from '../types';
|
import { IProps, ISchema, IState } from '../types';
|
||||||
|
|||||||
@ -1,7 +1,5 @@
|
|||||||
/* eslint-disable no-new-func */
|
/* eslint-disable no-new-func */
|
||||||
import Debug from 'debug';
|
import Debug from 'debug';
|
||||||
import { forEach as _forEach, shallowEqual as _shallowEqual } from '@ali/b3-one/lib/obj';
|
|
||||||
import { serialize as serializeParams } from '@ali/b3-one/lib/url';
|
|
||||||
// moment对象配置
|
// moment对象配置
|
||||||
import _moment from 'moment';
|
import _moment from 'moment';
|
||||||
import 'moment/locale/zh-cn';
|
import 'moment/locale/zh-cn';
|
||||||
@ -21,8 +19,6 @@ import IntlMessageFormat from 'intl-messageformat';
|
|||||||
|
|
||||||
import { ISchema } from '../types';
|
import { ISchema } from '../types';
|
||||||
|
|
||||||
export const forEach = _forEach;
|
|
||||||
export const shallowEqual = _shallowEqual;
|
|
||||||
export const moment = _moment;
|
export const moment = _moment;
|
||||||
moment.locale('zh-cn');
|
moment.locale('zh-cn');
|
||||||
(window as any).sdkVersion = pkg.version;
|
(window as any).sdkVersion = pkg.version;
|
||||||
@ -455,3 +451,41 @@ export function parseI18n(i18nInfo: any, self: any) {
|
|||||||
value: `this.i18n('${i18nInfo.key}')`,
|
value: `this.i18n('${i18nInfo.key}')`,
|
||||||
}, self);
|
}, self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function forEach(obj: any, fn: any, context?: any) {
|
||||||
|
obj = obj || {};
|
||||||
|
Object.keys(obj).forEach(key => fn.call(context, obj[key], key));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function shallowEqual(objA: any, objB: any) {
|
||||||
|
if (objA === objB) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const keysA = Object.keys(objA);
|
||||||
|
if (keysA.length !== Object.keys(objB).length) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let i = 0, key; i < keysA.length; i++) {
|
||||||
|
key = keysA[i];
|
||||||
|
if (!objB.hasOwnProperty(key) || objA[key] !== objB[key]) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function serializeParams(obj: any) {
|
||||||
|
let rst: any = [];
|
||||||
|
forEach(obj, (val: any, key: any) => {
|
||||||
|
if (val === null || val === undefined || val === '') return;
|
||||||
|
if (typeof val === 'object') rst.push(`${key}=${encodeURIComponent(JSON.stringify(val))}`);
|
||||||
|
else rst.push(`${key}=${encodeURIComponent(val)}`);
|
||||||
|
});
|
||||||
|
return rst.join('&');
|
||||||
|
}
|
||||||
@ -1,6 +1,6 @@
|
|||||||
/* eslint-disable object-curly-newline */
|
/* eslint-disable object-curly-newline */
|
||||||
import { transformArrayToMap, isJSFunction, transformStringToFunction, clone } from './common';
|
import { transformArrayToMap, isJSFunction, transformStringToFunction, clone } from './common';
|
||||||
import { jsonp, mtop, request, get, post, bzb } from './request';
|
import { jsonp, request, get, post } from './request';
|
||||||
import { DataSource, DataSourceItem } from '../types';
|
import { DataSource, DataSourceItem } from '../types';
|
||||||
|
|
||||||
const DS_STATUS = {
|
const DS_STATUS = {
|
||||||
@ -211,8 +211,8 @@ export class DataHelper {
|
|||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
const { type, id, dataHandler, options } = item;
|
const { type, id, dataHandler, options } = item;
|
||||||
const doFetch = (type: string, options: any) => {
|
const doFetch = (type: string, options: any) => {
|
||||||
this.fetchOne(type, options)
|
this.fetchOne(type as any, options)
|
||||||
.then((data: any) => {
|
?.then((data: any) => {
|
||||||
if (afterRequest) {
|
if (afterRequest) {
|
||||||
this.appHelper.utils.afterRequest(item, data, undefined, (data: any, error: any) => {
|
this.appHelper.utils.afterRequest(item, data, undefined, (data: any, error: any) => {
|
||||||
fetchHandler(data, error);
|
fetchHandler(data, error);
|
||||||
@ -290,38 +290,27 @@ export class DataHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchOne(type: string, options: any) {
|
fetchOne(type: DataSourceType, options: any) {
|
||||||
// eslint-disable-next-line prefer-const
|
// eslint-disable-next-line prefer-const
|
||||||
let { uri, url, method = 'GET', headers, params, ...otherProps } = options;
|
let { uri, url, method = 'GET', headers, params, ...otherProps } = options;
|
||||||
otherProps = otherProps || {};
|
otherProps = otherProps || {};
|
||||||
switch (type) {
|
if (type === 'jsonp') {
|
||||||
case 'mtop':
|
return jsonp(uri, params, otherProps);
|
||||||
method && (otherProps.method = method);
|
|
||||||
return mtop(uri, params, otherProps);
|
|
||||||
case 'jsonp':
|
|
||||||
return jsonp(uri, params, otherProps);
|
|
||||||
case 'bzb':
|
|
||||||
return bzb(uri, params, {
|
|
||||||
method,
|
|
||||||
headers,
|
|
||||||
...otherProps,
|
|
||||||
});
|
|
||||||
// todo:
|
|
||||||
case 'legao':
|
|
||||||
if (method === 'JSONP') {
|
|
||||||
return jsonp(url, params, otherProps);
|
|
||||||
}
|
|
||||||
// return webTable(uri, params, otherProps);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
method = method.toUpperCase();
|
|
||||||
if (method === 'GET') {
|
|
||||||
return get(uri, params, headers, otherProps);
|
|
||||||
}
|
|
||||||
if (method === 'POST') {
|
|
||||||
return post(uri, params, headers, otherProps);
|
|
||||||
}
|
|
||||||
return request(uri, method, params, headers, otherProps);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (type === 'fetch') {
|
||||||
|
switch (method.toUpperCase()) {
|
||||||
|
case 'GET':
|
||||||
|
return get(uri, params, headers, otherProps);
|
||||||
|
case 'POST':
|
||||||
|
return post(uri, params, headers, otherProps);
|
||||||
|
default:
|
||||||
|
return request(uri, method, params, headers, otherProps);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.error(`Engine default dataSource not support type:[${type}] dataSource request!`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type DataSourceType = 'fetch' | 'jsonp';
|
||||||
@ -1,3 +1,3 @@
|
|||||||
export * from './common';
|
export * from './common';
|
||||||
export * from './dataHelper';
|
export * from './data-helper';
|
||||||
export * from './request';
|
export * from './request';
|
||||||
|
|||||||
@ -1,8 +1,14 @@
|
|||||||
import 'whatwg-fetch';
|
import 'whatwg-fetch';
|
||||||
import fetchMtop from '@ali/lib-mtop';
|
|
||||||
import fetchJsonp from 'fetch-jsonp';
|
import fetchJsonp from 'fetch-jsonp';
|
||||||
import bzbRequest from '@ali/bzb-request';
|
import { serializeParams } from '.';
|
||||||
import { serialize, buildUrl, parseUrl } from '@ali/b3-one/lib/url';
|
|
||||||
|
function buildUrl(dataAPI: any, params: any) {
|
||||||
|
const paramStr = serializeParams(params);
|
||||||
|
if (paramStr) {
|
||||||
|
return dataAPI.indexOf('?') > 0 ? `${dataAPI}&${paramStr}` : `${dataAPI}?${paramStr}`;
|
||||||
|
}
|
||||||
|
return dataAPI;
|
||||||
|
}
|
||||||
|
|
||||||
export function get(dataAPI: any, params = {}, headers = {}, otherProps = {}) {
|
export function get(dataAPI: any, params = {}, headers = {}, otherProps = {}) {
|
||||||
headers = {
|
headers = {
|
||||||
@ -24,7 +30,7 @@ export function post(dataAPI: any, params = {}, headers: any = {}, otherProps =
|
|||||||
'POST',
|
'POST',
|
||||||
headers['Content-Type'].indexOf('application/json') > -1 || Array.isArray(params)
|
headers['Content-Type'].indexOf('application/json') > -1 || Array.isArray(params)
|
||||||
? JSON.stringify(params)
|
? JSON.stringify(params)
|
||||||
: serialize(params),
|
: serializeParams(params),
|
||||||
headers,
|
headers,
|
||||||
otherProps,
|
otherProps,
|
||||||
);
|
);
|
||||||
@ -132,40 +138,3 @@ export function jsonp(dataAPI: any, params = {}, otherProps = {}) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function mtop(dataAPI: any, params: any, otherProps: any = {}) {
|
|
||||||
fetchMtop.config.subDomain = otherProps.subDomain || 'm';
|
|
||||||
return fetchMtop.request({
|
|
||||||
api: dataAPI,
|
|
||||||
v: '1.0',
|
|
||||||
data: params,
|
|
||||||
ecode: otherProps.ecode || 0,
|
|
||||||
type: otherProps.method || 'GET',
|
|
||||||
dataType: otherProps.dataType || 'jsonp',
|
|
||||||
AntiFlood: true, // 防刷
|
|
||||||
timeout: otherProps.timeout || 20000,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function bzb(apiCode: string, params: any, otherProps: any = {}) {
|
|
||||||
// 通过url参数设置小二工作台请求环境
|
|
||||||
const getUrlEnv = () => {
|
|
||||||
try {
|
|
||||||
if (window.parent && window.parent.location.host === window.location.host) {
|
|
||||||
const urlInfo = parseUrl(window.parent && window.parent.location.href);
|
|
||||||
return urlInfo && urlInfo.params && urlInfo.params._env;
|
|
||||||
}
|
|
||||||
const urlInfo = parseUrl(window.location.href);
|
|
||||||
return urlInfo && urlInfo.params && urlInfo.params._env;
|
|
||||||
} catch (e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
otherProps.method = otherProps.method || 'GET';
|
|
||||||
otherProps.env = getUrlEnv() || otherProps.env || 'prod';
|
|
||||||
return bzbRequest(apiCode, {
|
|
||||||
data: params,
|
|
||||||
...otherProps,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user