import Units from "../units"; import Super from "./superagent"; import { message } from "antd"; import EncryptUtils from "../units/EncryptUtils"; import "dayjs/locale/en"; import dayjs from "dayjs"; import utc from "dayjs/plugin/utc"; import timezone from "dayjs/plugin/timezone"; import { CodeSource, CommonFilePath, DtmplConfig, MenuConfigAPIType, PageInfo, SelectedRow, } from "./interface"; import { ProgramConfig } from "../index"; import translate from "../locale/translate"; dayjs.extend(utc); dayjs.extend(timezone); export default class HcserviceV3 { static async requestEnum(serverKey: string, mstrucIds, path: string) { if (!path) { return await this.requestEnumWithPath(serverKey, mstrucIds, "/enum"); } else { return await this.requestEnumWithPath(serverKey, mstrucIds, path); } } static getJsonValue = (file) => { let jsonFile = file; if (!file) { return undefined; } else if (typeof (file) == 'string') { jsonFile = JSON.parse(file); } return jsonFile; } static toFilePath(value, serverKey) { if (!value) { return null; } let filePath: CommonFilePath = {}; if (typeof (value) == 'string') { if (value.toLowerCase().startsWith("http")) { filePath.path = value; filePath.fileName = this.getFileNameFrom(value); filePath.contentType = this.getFileSuffixFrom(filePath.fileName); } else if (value.toLowerCase().startsWith("/")) { filePath.path = this.getFileUrl(serverKey, value); filePath.fileName = this.getFileNameFrom(value); filePath.contentType = this.getFileSuffixFrom(filePath.fileName); } else { let jsonValue = this.getJsonValue(value); filePath = this.toFilePathObject(jsonValue, serverKey); } } else if (value.base) { filePath = this.toFilePathObject(value, serverKey); } return filePath; } static toFilePathObject(jsonValue, serverKey: string) { let filePath: any = {}; if (jsonValue) { filePath.path = this.getFileUrl(serverKey, jsonValue.base?.path); filePath.iconPath = jsonValue.icon?.path ? this.getFileUrl(serverKey, jsonValue.icon?.path) : null; filePath.fileName = jsonValue.fileName ? jsonValue.fileName : this.getFileNameFrom(jsonValue.base?.path); filePath.contentType = this.getFileSuffixFrom(filePath.fileName); filePath.valid = jsonValue.valid; filePath.baseType = jsonValue.base?.type; filePath.basePath = jsonValue.base?.path; return filePath; } return null; } static async requestEnumWithPath(serverKey: string, mstrucIds, path) { if (mstrucIds.length > 0) { let res = await Super.super({ url: Units.joinPath("/v3", path), serverKey, data: { mstrucIds, }, }); return res.enumMap; } else { return {}; } } static async requestOptions(serverKey: string, mstrucId) { //有下拉菜单时,请求下拉选项操作 return await this.requestEnum(serverKey, [mstrucId], null); } static async requestDtmplConfig( serverKey: string, sourceId: string, code: string ) { let url = `/v3/dtmpl/config`; let res = await Super.super({ url, serverKey, method: "GET", query: { sourceId, code }, }); return res.dtmplConfig; } static async requestTtmplConfig(serverKey: string, sourceId: string) { let url = `/v3/ttmpl/config`; let res = await Super.super({ url, serverKey, method: "GET", query: { sourceId }, }); return res.ttmplConfig; } static async requestEttmplConfig(serverKey: string, sourceId: string) { let url = `/v3/ettmpl/config`; let res = await Super.super({ url, serverKey, method: "GET", query: { sourceId }, }); return res.ettmplConfig; } static async requestViewDtmplConfig(serverKey: string, sourceId: string) { let url = `/v3/view-dtmpl/config`; let res = await Super.super({ url, serverKey, method: "GET", query: { sourceId }, }); return res.dtmplConfig; } static async requestAddDtmplConfig( serverKey: string, sourceId: string, addTmplId: string ) { let url = `/v3/add-dtmpl/config`; let res = await Super.super({ url, serverKey, method: "GET", query: { sourceId, addTmplId }, }); return res.dtmplConfig; } static async requestSelectConfig(serverKey: string, sourceId) { let url = `/v3/select/config`; let res = await Super.super({ url, serverKey, method: "GET", query: { sourceId }, }); return res.selectConfig; } static async requestLtmplConfig(serverKey: string, sourceId: string) { let url = `/v3/ltmpl/config`; let res = await Super.super({ url, serverKey, method: "GET", query: { sourceId }, }); return res; } static async requestL2LtmplConfig(serverKey: string, sourceId) { let url = `/v3/l2/ltmpl/config`; let res = await Super.super({ url, serverKey, method: "GET", query: { sourceId }, }); return res; } static async requestLtmplQueryKey( serverKey: string, sourceId: string, condition? ) { //console.log('condition:',condition); let url = `/v3/ltmpl/query/key`; let res = await Super.super({ url: url, serverKey, method: "GET", query: { ...condition, sourceId }, }); return res; } static async requestGttRootQueryKey( serverKey: string, sourceId: string, condition? ) { let url = `/v3/gtt/root-query/key`; let res = await Super.super({ url: url, serverKey, method: "GET", query: { ...condition, sourceId }, }); return res; } static async requestLtmplQueryTop( serverKey: string, sourceId: string, condition ) { // console.log('condition:',condition); let url = `/v3/ltmpl/top-data`; return await this.requestCommonLtmplQueryTop( serverKey, sourceId, condition, url ); } static async requestQueryReportData( serverKey: string, queryKey: string, language: string ) { let url = "/v3/ltmpl/report-data"; let res = await Super.super({ url: url, serverKey, method: "GET", query: { queryKey, language }, }); return res; } static async requestTtmplRootData( serverKey: string, sourceId: string, condition ) { let url = `/v3/ttmpl/root-data`; return await this.requestCommonLtmplQueryTop( serverKey, sourceId, condition, url ); } static async requestMstrucLtmplQueryTop( serverKey: string, sourceId: string, condition ) { //console.log('condition:',condition); let url = `/v3/mstruc/ltmpl/top-data`; return await this.requestCommonLtmplQueryTop( serverKey, sourceId, condition, url ); } static async queryTop1(serverKey: string, sourceId: string) { let data = await this.requestMstrucLtmplQueryTop(serverKey, sourceId, { top: 1, }); let queriedCode = null; if (data && data.entities && data.entities[0]) { queriedCode = data.entities[0].code; } return queriedCode; } static async requestCommonLtmplQueryTop( serverKey: string, sourceId: string, condition, url ) { if (!sourceId) { message.error("SourceId is undefined!", 5); } else { let res = await Super.super({ url: url, serverKey, method: "GET", query: { ...condition, sourceId }, }); return res; } } static async requestSelectedData(serverKey: string, sourceId: string, codes) { if (!codes) { message.warning(translate("${没有选择实体}")); return null; } let url = `/v3/field-group/data/selected`; let res = await Super.super({ url: url, serverKey, query: { codes, sourceId }, method: "GET", }); if (res.status === "success") { return res.entities; } else { message.error(translate("${没有找到实体}!"), 5); return null; } } static isForeignLanguageMode() { if (translate("${保存}") == "保存") { return false; } else { return true; } } static async requestVersionList(serverKey: string, sourceId: string, code, pageNo?: number) { let res = await Super.super({ url: `/v3/dtmpl/data/versions`, serverKey, query: { pageNo: pageNo ? pageNo : 1, sourceId, code, }, method: "GET", }); return res.versions; } static async requestFieldVersionList( serverKey: string, sourceId: string, code ) { let res = await Super.super({ url: `/v3/dtmpl/field-data/versions`, serverKey, query: { pageNo: 1, sourceId, code, }, method: "GET", }); return res.versions; } static async requestCommonDtmplData( serverKey: string, sourceId: string, code, versionId, url ) { let res = await Super.super({ url, serverKey, query: { code, versionId, sourceId, }, method: "GET", }); if (res?.status === "success") { return { sourceId, ...res.entity }; } else { //message.error(translate("${实体不存在}!"),5); return null; } } static async requestDtmplData( serverKey: string, sourceId: string, code, versionId ) { let url = `/v3/dtmpl/data`; return await this.requestCommonDtmplData( serverKey, sourceId, code, versionId, url ); } static async getDtmplData( dtmplConfig: DtmplConfig, serverKey: string, sourceId: string, code ) { let dtmplData_; if (dtmplConfig && dtmplConfig.dynamic) { dtmplData_ = dtmplConfig.entity; } if (!dtmplData_) { dtmplData_ = await this.requestDtmplData(serverKey, sourceId, code, null); } return dtmplData_; } static async requestMstrucDtmplData( serverKey: string, sourceId: string, code, versionId ) { let url = `/v3/mstruc/dtmpl/data`; return await this.requestCommonDtmplData( serverKey, sourceId, code, versionId, url ); } static async requestViewDtmplData( serverKey: string, sourceId: string, code, versionId ) { let url = `/v3/view-dtmpl/data`; return await this.requestCommonDtmplData( serverKey, sourceId, code, versionId, url ); } // 查询审计数据 static async requestViewDtmplAuditData(serverKey: string, sourceId: string, code, versionId) { let url = `/v3/dtmpl/audit-data`; let res = await Super.super({ url, serverKey, query: { code, versionId, sourceId }, method: "GET" }); if (res?.status === "success") { return { sourceId, ...res }; } else { return null; } } static async requestMstrucViewDtmplData( serverKey: string, sourceId, code, versionId ) { let url = `/v3/mstruc/view-dtmpl/data`; return await this.requestCommonDtmplData( serverKey, sourceId, code, versionId, url ); } static async postCommonDtmplData( serverKey: string, sourceId: string, formDataObj, message, url ) { const formData = new FormData(); for (let k in formDataObj) { if (!k.startsWith("$virtual")) { formData.append( k, formDataObj[k] || formDataObj[k] == 0 ? formDataObj[k] : "" ); } } formData.append("sourceId", sourceId.toString()); let res = await Super.super( { url, serverKey, data: formData, method: "POST", }, "formdata" ); let code = null; if (res) { if (res.status === "success") { if (message) { if (res.message) { message.warning(translate("${保存成功}!") + res.message, 4); } else { message.success(translate("${保存成功}!"), 1); } } code = res.entityCode ? res.entityCode : res.code; } // else { // if (message) { // message.error("保存失败"); // } // } } else { if (message) { message.error(translate("${保存失败}!"), 5); } } return { code, status: res ? res.status : "error" }; } static async postDtmplData( serverKey: string, sourceId: string, formDataObj, message ) { let url = `/v3/dtmpl/data`; return await this.postCommonDtmplData( serverKey, sourceId, formDataObj, message, url ); } static async postLtmplData( serverKey: string, sourceId: string, formDataObj, message ) { let url = `/v3/ltmpl/data`; return await this.postCommonDtmplData( serverKey, sourceId, formDataObj, message, url ); } static async postLtmplMultiData( serverKey: string, sourceId: string, formDataObj, message ) { let url = `/v3/ltmpl/multi-data`; return await this.postCommonDtmplData( serverKey, sourceId, formDataObj, message, url ); } static async postMstrucDtmplData( serverKey: string, sourceId: string, formDataObj, message ) { let url = `/v3/mstruc/dtmpl/data`; return await this.postCommonDtmplData( serverKey, sourceId, formDataObj, message, url ); } static postFileAction(serverKey: string, file) { return Units.joinPath(Units.api(serverKey), "/v3/upload"); } static async postFile(formData) { let res = await Super.super({ url: `/v3/upload`, data: formData, method: 'POST' }, 'formdata'); return res; } static async requestL2LtmplQueryKey(serverKey: string, sourceId, condition) { let url = `v3/l2/ltmpl/query/key`; let res = await Super.super({ url, serverKey, method: "GET", query: { ...condition, sourceId }, }); return res; } static async requestLtmplCount(serverKey: string, sourceId) { let url = `/v3/ltmpl/data/count`; let res = await Super.super({ url, serverKey, query: { sourceId }, method: "GET", }); return res.count; } static async requestQueryData( serverKey: string, queryKey: string, pageInfo: PageInfo ) { let res = await Super.super({ url: `/v3/ltmpl/query/data`, serverKey, method: "GET", query: { queryKey, ...pageInfo }, }); return res; } static getCodesOfSelectedRows(selectedRows: SelectedRow[]) { let codes: string[] = []; if (!selectedRows || selectedRows.length < 1) { return; } for (let item of selectedRows) { if (item.code) { codes.push(item.code); } else { message.error(translate("${没找到所选数据的Code}!!"), 5); } } if (codes.length < 1) { message.error(translate("${没找到所选数据的Code}!!"), 5); } return codes; } static async deleteData( serverKey: string, sourceId, selectedRows: SelectedRow[], mainCode? ) { const codes = this.getCodesOfSelectedRows(selectedRows); return await this.deleteByCode(serverKey, sourceId, codes, mainCode); } static async deleteByCode( serverKey: string, sourceId, codes: string[], mainCode? ) { let res = await Super.super({ url: `/v3/ltmpl/data`, serverKey, data: { codes, sourceId, mainCode, }, method: "DELETE", }); if (res && res.status == "success") { message.success(translate("${删除成功}"), 1); return true; } else { message.error(translate("${删除失败}"), 3); //console.log("删除失败消息",res.message); return false; } } static async requestQueryAggregates(serverKey: string, queryKey: string) { let res = await Super.super({ url: `/v3/ltmpl/query/count`, serverKey, method: "GET", query: { queryKey }, }); return res; } static async doPostRequest(serverKey: string, url: string, params?: object) { let res = await Super.super({ url, serverKey, method: "POST", data: { ...params }, }); return res; } static async doGetRequest(serverKey: string, url: string, params?: object) { let res = await Super.super({ url, serverKey, method: "GET", query: { ...params }, }); return res; } static async requestChartData( serverKey: string, sourceId: string, params?: object ) { let res = await Super.super({ url: `/v3/chart/data`, serverKey, method: "GET", query: { sourceId, ...params }, }); return res; } static async requestCharMultitData( serverKey: string, dataSourceConfigs: string ) { let res = await Super.super({ url: `/v3/chart/multi-data`, serverKey, method: "GET", query: { dataSourceConfigs }, }); return res; } static async requestCharWSConfig( serverKey: string, sourceIds: string[] ) { let res = await Super.super({ url: `/v3/chart/ws/config`, serverKey, method: "GET", query: { sourceIds }, }); return res; } static async postActions( serverKey: string, actionId: string, selectedRows: SelectedRow[], actionDataObj?: Object ) { const codes = this.getCodesOfSelectedRows(selectedRows); const formData = new FormData(); for (let k in actionDataObj) { formData.append(k, actionDataObj[k] ? actionDataObj[k] : ""); } formData.append("sourceId", actionId.toString()); formData.append("codes", codes.join(",")); let res = await Super.super( { url: `/v3/action`, serverKey, data: formData, method: "POST", }, "formdata", null ); return res; } static async increCalc(serverKey: string, sourceId: string, params = {}) { let res = await Super.super({ url: `/v3/stat/increcalc`, serverKey, method: "POST", data: { ...params, sourceId }, }); if (res && res.status === "success") { message.success(translate("${统计成功}"), 1); } else { message.error(translate("${统计失败}")); } return res; } static async saveRatmplSelectCodes( serverKey: string, sourceId: string, mainCode, codes: string[] ) { let res = await Super.super({ url: `/v3/ratmpl-select/data`, serverKey, method: "POST", data: { codes, mainCode, sourceId }, }); if (res && res.status != "success") { message.error(translate("${" + res.message + "}")); } return res; } static async doCopy( serverKey: string, sourceId: string, code: string, copyRelation?, copyOpp2One? ) { let res = await Super.super( { url: `/v3/mstruc/copy-data`, serverKey, method: "POST", query: { sourceId, code, copyRelation, copyOpp2One, }, }, null, null ); if (res && res.status == "success") { if (res.message) { message.info(res.message, 4); } } return res.entityCode; } // static downloadDetailExcel(sourceId, entityCode) { // const hydrocarbonToken = Units.hydrocarbonToken(); // let url = Units.joinPath(Units.api(), `/v3/dtmpl/excel`)+`?sourceId=${sourceId}&code=${entityCode}&@token=${hydrocarbonToken}&@programToken=${Units.programCode()}`; // Units.downloadFile(url, "详情"); // } static async queryCode( sourceId: string, codeSource: CodeSource, serverKey?: string ) { let queriedCode = undefined; if (codeSource) { if (codeSource == "listop") { queriedCode = await this.queryTop1(serverKey, sourceId); if (!queriedCode) { queriedCode = "bad-code"; } } else if (codeSource == "listop-new") { queriedCode = await this.queryTop1(serverKey, sourceId); } else if (codeSource == "new") { queriedCode = null; } } return queriedCode; } static download(serverKey: string, path: string, fileName?: string) { let vars = path.split("/"); let temFileName = fileName || vars[vars.length - 1]; this.downloadDir(this.getFileUrl(serverKey, path), temFileName); // let vars = path.split("/"); // let fileName = vars[vars.length - 1]; // Units.downloadFile( // this.getFileUrl(serverKey, path) + `&disposition=attachment`, // fileName // ); } static downloadDir(path, fileName) { // let fileName = this.getFileNameFrom(path); Units.downloadFile(path + `&disposition=attachment`, fileName); } static openfile(serverKey: string, path, toolbar) { let vars = path.split("/"); let fileName = vars[vars.length - 1]; this.openfileDir(fileName, this.getFileUrl(serverKey, path), toolbar); // Units.openFile(this.getFileUrl(serverKey, path), fileName, toolbar); } static getFileNameFrom(path) { if (!path) { return undefined; } let vars = path.split("/"); let fileName = vars[vars.length - 1]; return fileName; } static getFileSuffixFrom(fileName) { if (!fileName) { return undefined; } let ss = fileName.split("."); if (ss.length > 1) { return ss.pop(); } else { return undefined; } } static openfileDir(path, fileName, toolbar) { //let fileName = this.getFileNameFrom(path); Units.openFile(path, fileName, toolbar); } static getFileUrl(serverKey: string, path: string) { const hydrocarbonToken = Units.serverHydrocarbonToken(serverKey); const programCode = Units.programCode(serverKey); const applicationCode = Units.applicationCode(serverKey); let root; let url; //判断是否为全URL if (path?.startsWith("http") || path?.startsWith("HTTP")) { root = path; if (path.indexOf("?") > 0) { url = root + `&@token=${hydrocarbonToken}&@programToken=${programCode}&@applicationToken=${applicationCode}`; } else { url = root + `?@token=${hydrocarbonToken}&@programToken=${programCode}&@applicationToken=${applicationCode}`; } } else { root = Units.joinPath(Units.api(serverKey), Units.joinPath("/v3/files", path)); url = root + `?@token=${hydrocarbonToken}&@programToken=${programCode}&@applicationToken=${applicationCode}`; } let encodeUri = encodeURI(url); return encodeUri; } static async loadFileTxt(serverKey: string, path) { let res = await Super.super({ url: encodeURI(Units.joinPath("/v3/files/text", path)), serverKey, method: "GET", }); return res.text; } static async requestBlocks( l2MenuId: string, blockId: string, programCode?: string, applicationCode?: string ): Promise { let url = `/v3/menu/blocks`; let res = await Super.super({ url: url, method: "GET", header: { programCode, applicationCode }, query: { l2MenuId, blockId, }, }); return res; } static async requestBlockMenuAuths() { let url = `/v3/menu/block-menu-auths`; let res = await Super.super({ url: url, method: "GET", query: {}, }); return res?.blocks; } static async requestRoleAuths(roleCode: string) { let url = `/v3/auth/role-auths`; let res = await Super.super({ url: url, method: "GET", query: { roleCode, }, }); return res; } static async postRoleAuths(roleCode: string, auths: string[]) { let url = `/v3/auth/role-auths`; let res = await Super.super({ url: url, method: "POST", query: { roleCode, auths, }, }); return res; } static async logout() { Super.super({ url: "/v3/auth/token", method: "DELETE", }).then((res) => { Units.toLogin(); }); } static async logout2() { return Super.super({ url: "/v3/auth/token", method: "DELETE", }); } static async resetPassword( serverKey: string, oPassword: string, nPassword: string, pubkey ) { let oldPassword = EncryptUtils.rsaEncrypt(oPassword, pubkey); let newPassword = EncryptUtils.rsaEncrypt(nPassword, pubkey); let res = await Super.super({ url: "/v3/auth/password", serverKey, query: { oldPassword, newPassword, }, method: "POST", }); return res; } static async resetPassword2( serverKey: string, userName: string, oPassword: string, nPassword: string, pubkey ) { let oldPassword = EncryptUtils.rsaEncrypt(oPassword, pubkey); let newPassword = EncryptUtils.rsaEncrypt(nPassword, pubkey); let res = await Super.super({ url: "/v3/auth/password2", serverKey, query: { userName, oldPassword, newPassword, }, method: "POST", }); return res; } static async getContextSourceConfig() { let res = await Super.super({ url: "/v3/context-source-config", method: "GET", }); if (res) { return res.config; } else { return null; } } static async getContextSourceValue() { let res = await Super.super({ url: "/v3/auth/context-source-value", method: "GET", }); return res ? res.value : null; } static async loginServer(serverKey: string, username: string, password: string) { let pubkey = await this.getRasPubkey(serverKey); if (pubkey) { let json = { username, password }; let res = await this.login(json, null, null, pubkey, null, serverKey); if (res.status == "success") { Units.setServerHydrocarbonToken(serverKey, res.token); return res; } else { return { status: "error", message: "登陆失败" } } } else { return { status: "error", message: "登陆失败" } } } static async login( json, kaptchaToken, kaptchaText, pubkey, programCode?: string, serverKey?: string, applicationCode?: string ) { let datetime = dayjs(new Date()) .tz("Europe/London") .format("YYYY-MM-DD HH:mm:ss"); json["datetime"] = datetime; let userInfo = EncryptUtils.rsaEncrypt(JSON.stringify(json), pubkey); let res = await Super.super({ url: "/v3/auth/hctoken", serverKey, header: { programCode, applicationCode }, query: { userInfo, kaptchaToken, kaptchaText, }, method: "GET", }); if (res.passwordState) { if (res.passwordState == "expiry") { message.warning(translate("${" + res.message + "}"), 10); } else if (res.passwordState == "expiried") { message.error(translate("${" + res.message + "}"), 10) } else if (res.passwordState == "restricted") { message.error(translate("${" + res.message + "}"), 15) } } return { status: res.status, token: res.token }; } static async setContext(json) { const formData = new FormData(); formData.append("context", JSON.stringify(json)); let res = await Super.super( { url: "/v3/auth/context", data: formData, method: "POST", }, "formdata" ); if (res && res.status === "success") { window.location.hash = "#/home"; } return res; } static async getKaptchaToken(programCode?: string, applicationCode?: string) { let res = await Super.super({ url: "/v3/auth/kaptcha", header: { programCode, applicationCode }, method: "POST", }); if (res && res.status === "success") { return res; } else { return null; } } static async getRasPubkey(serverKey?: string, programCode?: string, applicationCode?: string) { let res = await Super.super({ url: "/v3/auth/ras-pubkey", header: { programCode, applicationCode }, serverKey, method: "GET", }); if (res && res.status === "success") { return res.rasPubkey; } else { return null; } } static async getUser(programCode?: string, hydrocarbonToken?: string, applicationCode?: string) { let res = await Super.super({ header: { programCode, hydrocarbonToken, applicationCode }, url: "/v3/current-user", }); return res ? res.user : null; } static async requestFastMenu() { let url = `/v3/menu/fast-menu`; let res = await Super.super({ url: url, method: "GET", }); return res ? res.fastMenu : null; } static async reload() { let url = `/v3/tmpl/reload`; let res = await Super.super({ url: url, method: "GET", }); return res; } static async getAllLang(serverKey?: string) { let url = "/v3/languages"; const data = { url, method: "GET", }; if (serverKey !== undefined) data["serverKey"] = serverKey; let res = await Super.super(data); return res; } static async getLocale(lang, serverKey?: string) { let url = "/v3/multilingual"; const data = { url: `${url}?language=${lang}`, method: "GET", }; if (serverKey !== undefined) data["serverKey"] = serverKey; let res = await Super.super(data); return res; } static async initProgramConfig(ProgramConfigJson) { //设置项目配置信息 if (ProgramConfigJson["programCode"]) { ProgramConfig.setProgramCode(ProgramConfigJson["programCode"]); } if (ProgramConfigJson["applicationCode"]) { ProgramConfig.setApplicationCode(ProgramConfigJson["applicationCode"]); } if (ProgramConfigJson["hydrocarbonServer"]) { ProgramConfig.setHydrocarbonServer( ProgramConfigJson["hydrocarbonServer"] ); } //注册扩展服务器 if (ProgramConfigJson["extendServer"]) { let extend = ProgramConfigJson["extendServer"]; if (typeof extend == "object") { let extendServers = []; if (Array.isArray(extend)) { extendServers = extend; } else { extendServers.push(extend); } ProgramConfig.putExtendServers(extendServers); } } ProgramConfig.setProgramName(ProgramConfigJson["programName"]); ProgramConfig.setProgramName_sub(ProgramConfigJson["programName_sub"]); ProgramConfig.setProgramName_NavLeft( ProgramConfigJson["programName_NavLeft"] ); ProgramConfig.setProgramName_Logo(ProgramConfigJson["programName_Logo"]); ProgramConfig.setThemes(ProgramConfigJson["themes"]); ProgramConfig.setDefaultTheme(ProgramConfigJson["defaultTheme"]); let result = await Super.getProramConfig(); if (result) { //console.log('result',result) //先放入programCode ProgramConfig.setProgramCode(result.programCode); ProgramConfig.setApplicationCode(result.applicationCode); ProgramConfig.setHydrocarbonServer(result.hydrocarbonServer); ProgramConfig.setProgramName(result.programName); ProgramConfig.setProgramName_sub(result.programName_sub); ProgramConfig.setProgramName_NavLeft(result.programName_NavLeft); ProgramConfig.setProgramName_Logo(result.programName_Logo); ProgramConfig.setThemes(result.themes); ProgramConfig.setDefaultTheme(result.defaultTheme); //注册扩展服务器 if (result.extendServer) { let extend = result.extendServer; if (typeof extend == "object") { let extendServers = []; if (Array.isArray(extend)) { extendServers = extend; } else { extendServers.push(extend); } ProgramConfig.putExtendServers(extendServers); } } } } static async requestDDpageData(ddpageId: string) { let res = await Super.super({ url: "/v3/ddpage/data", method: "GET", query: { ddpageId, }, }); return res; } static async ssoTokenLogin(json: { username: string, ssoToken: string }, programCode?: string, serverKey?: string, applicationCode?: string) { let res = await Super.super({ url: "/v3/auth/sso/token", serverKey, header: { programCode, applicationCode }, query: json, method: "GET", }); return res; } static async getThemeConfig(serverKey?: string, programCode?: string, applicationCode?: string) { let res = await Super.super({ url: "/v3/theme-config", header: { programCode, applicationCode }, serverKey, method: "GET", }); if (res && res.status === "success") { return res; } else { return null; } } // 获取列表页统计数据 static async getLtmplDataGroupCount(sourceId: string) { let res = await Super.super({ url: "v3/ltmpl/data/group-count", method: "GET", query: { sourceId } }); if (res?.status === "success") { return res["group-aggregates"] || []; } else { return []; } } // 设置页面默认配置 static async setPageConfigDefault(name: string, menuCode: string, content: string) { let res = await Super.super({ url: `/v3/devops/page-config/default`, method: "POST", data: { name, menuCode, content }, }); if (res?.status === "success") { message.success(translate("${保存成功}"), 1); return true; } else { message.error(translate("${保存失败}"), 3); return false; } } // 获取页面默认配置 static async getPageConfigDefault() { let res = await Super.super({ url: `/v3/devops/page-config/default`, method: "GET", }); if (res?.status === "success") { message.success(translate("${拉取成功}"), 1); return res.configs; } else { message.error(translate("${拉取失败}"), 3); return null; } } static async deletePageConfigDefault(menuCode: string) { let res = await Super.super({ url: `/v3/devops/page-config/default`, data: { menuCode }, method: "DELETE", }); if (res?.status === "success") { message.success(translate("${删除成功}"), 1); return true; } else { message.error(translate("${删除失败}"), 3); return false; } } // 设置页面用户自定义配置 static async setPageConfigCommon(name: string, menuCode: string, content: string, configCode?: string) { let res = await Super.super({ url: `/v3/devops/page-config/common`, method: "POST", data: { name, menuCode, content, configCode }, }); if (res?.status === "success") { message.success(translate("${保存成功}"), 1); return true; } else { message.error(translate("${保存失败}"), 3); return false; } } // 获取用户页面自定义配置 static async getPageConfigCommon(menuCode?: string) { let res = await Super.super({ url: `/v3/devops/page-config/common`, method: "GET", query: { menuCode } }); if (res?.status === "success") { return res.configs; } else { return null; } } static async deletePageConfigCommon(configCode: string) { let res = await Super.super({ url: `/v3/devops/page-config/common`, data: { configCode }, method: "DELETE", }); if (res?.status === "success") { message.success(translate("${删除成功}"), 1); return true; } else { message.error(translate("${删除失败}"), 3); return false; } } // 请求用户我的菜单 static async getQuickMenu() { let res = await Super.super({ url: `/v3/devops/menu-config/quick-menu`, method: "GET", }); if (res?.status === "success") { return res.configs; } else { return null; } } // 添加用户我的菜单 static async postQuickMenu(menuCodes: string[]) { let res = await Super.super({ url: `/v3/devops/menu-config/quick-menu`, method: "POST", data: { menuCodes }, }); if (res?.status === "success") { message.success(translate("${保存成功}"), 1); return true; } else { message.error(translate("${保存失败}"), 3); return false; } } // 删除用户我的菜单 static async deleteQuickMenu(menuCode: string) { let res = await Super.super({ url: `/v3/devops/menu-config/quick-menu`, data: { menuCode }, method: "DELETE", }); if (res?.status === "success") { message.success(translate("${删除成功}"), 1); return true; } else { message.error(translate("${删除失败}"), 3); return false; } } // ws发送消息 // data:{ message: "测试数据", destination: "/user/queue/dashboard" } static async wsPush(hydrocarbonToken, data) { const res = await Super.super({ url: `/v3/ws-push/${hydrocarbonToken}`, data, method: "POST", }); if (res.code === 200) { message.success(translate("${已发送}")); } else { message.error(translate("${发送失败}"), 3); } } static async wsPushTopic(hydrocarbonToken, data) { const res = await Super.super({ url: `/v3/ws-push-topic/${hydrocarbonToken}`, data, method: "POST", }); if (res.code === 200) { message.success(translate("${已发送}")); } else { message.error(translate("${发送失败}"), 3); } } // 请求2D图组件 static async get2DComponent(groups: string[]) { let { status, ...res } = await Super.super({ url: `/v3/component/2d-config`, method: "GET", query: { groups } }); if (status === "success") { return res; } else { return {}; } } // 保存2D图 static async postDiagram2DConfig(recordCode: string, content: string) { let res = await Super.super({ url: `/v3/devops/diagram-2d-config`, method: "POST", data: { recordCode, content }, }); if (res?.status === "success") { message.success(translate("${保存成功}"), 1); return true; } else { message.error(translate("${保存失败}"), 3); return false; } } // 查询2D图 static async getDiagram2DConfig(recordCode: string) { let res = await Super.super({ url: `/v3/devops/diagram-2d-config`, method: "GET", query: { recordCode } }); if (res?.status === "success") { return res?.configs || []; } else { return []; } } // 列表-展开树顶层数据查询 static async requestEttmplQueryKey(serverKey: string, sourceId, condition) { let url = `v3/ettmpl/query/key`; let res = await Super.super({ url, serverKey, method: "GET", query: { ...condition, sourceId }, }); return res; } static async requestEttmplLtmplConfig(serverKey: string, ettmplId: string, sourceId: string) { let url = `v3/ettmpl/ltmpl/config`; let res = await Super.super({ url, serverKey, method: "GET", query: { ettmplId, sourceId }, }); return res; } }