import {AlertComponent, attachmentAdpator, makeTranslator, render, type Schema, ToastComponent} from 'amis' import 'amis/lib/themes/antd.css' import 'amis/lib/helper.css' import 'amis/sdk/iconfont.css' import '@fortawesome/fontawesome-free/css/all.min.css' import axios from 'axios' import {isEqual} from 'licia' export const commonInfo = { debug: isEqual(import.meta.env.MODE, 'development'), baseUrl: 'http://132.126.207.130:35690/hudi_services/service_web', // baseAiUrl: 'http://132.126.207.130:35690/hudi_services/service_ai_web', baseAiUrl: 'http://localhost:8080', authorizationHeaders: { 'Authorization': 'Basic QXhoRWJzY3dzSkRiWU1IMjpjWXhnM2I0UHRXb1ZENVNqRmF5V3h0blNWc2p6UnNnNA==', 'Content-Type': 'application/json', }, clusters: { // hudi同步运行集群和yarn队列名称 sync: { 'b12': 'default', }, sync_names() { return Object.keys(this.sync).join(',') }, // hudi压缩运行集群和yarn队列名称 compaction: { 'b12': 'default', 'b1': 'datalake', 'a4': 'ten_iap.datalake', }, compaction_names() { return Object.keys(this.compaction).join(',') }, }, loki: { // grafana链接,用于直接打开grafana日志查看 grafanaUrl: 'http://132.126.207.125:35700', // grafana对应hudi使用的loki配置的datasource id hudi: { datasource: 'f648174e-7593-45cf-8fe8-8f8d5cf0fdde', }, // grafana对应服务使用的loki配置的datasource id service: { datasource: 'b6fee51c-facd-4261-a0eb-8c69a975fba3', }, }, } const __ = makeTranslator('zh') const responseAdaptor = () => (response: any) => { let payload = response.data || {} // blob 下可能会返回内容为空? if (payload.hasOwnProperty('errno')) { payload.status = payload.errno payload.msg = payload.errmsg } else if (payload.hasOwnProperty('no')) { payload.status = payload.no payload.msg = payload.error } return { ...response, data: payload, } } export const amisRender = (schema: Schema, data: Record = {}) => { const theme = 'antd' const locale = 'zh-CN' return ( <> {render( schema, { data: data, theme: theme, }, { enableAMISDebug: commonInfo.debug, fetcher: async (api: any) => { let {url, method, data, responseType, config, headers} = api config = config || {} config.url = url config.withCredentials = true responseType && (config.responseType = responseType) if (config.cancelExecutor) { config.cancelToken = new (axios as any).CancelToken( config.cancelExecutor, ) } config.headers = headers || {} config.method = method config.data = data if (method === 'get' && data) { config.params = data } else if (data && data instanceof FormData) { // config.headers['Content-Type'] = 'multipart/form-data'; } else if ( data && typeof data !== 'string' && !(data instanceof Blob) && !(data instanceof ArrayBuffer) ) { data = JSON.stringify(data) config.headers['Content-Type'] = 'application/json' } // 支持返回各种报错信息 config.validateStatus = function () { return true } let response = await axios(config) response = await attachmentAdpator(response, __, api) response = responseAdaptor()(response) if (response.status >= 400) { if (response.data) { // 主要用于 raw: 模式下,后端自己校验登录, if ( response.status === 401 && response.data.location && response.data.location.startsWith('http') ) { location.href = response.data.location.replace( '{{redirect}}', encodeURIComponent(location.href), ) return new Promise(() => { }) } else if (response.data.msg) { throw new Error(response.data.msg) } else { throw new Error( 'System.requestError' + JSON.stringify(response.data, null, 2), ) } } else { throw new Error( `${'System.requestErrorStatus'} ${response.status}`, ) } } return response }, isCancel: (value: any) => (axios as any).isCancel(value), }, )} ) } function generateLokiPanel(queries: Array) { return { LWF: { queries: [ ...queries.map(item => { let name = item['name'] let datasource = item['datasource'] let queryMap = item['queryMap'] let query = Object.keys(queryMap) .sort() .map(key => `${key}="${queryMap[key]}"`) let match = '\\d{4}-(?P