import { ModelCache } from '@oinone/kunlun-engine';
import { http } from '@oinone/kunlun-service';
export enum AppBindType {
MENU = 'MENU',
VIEW = 'VIEW',
URL = 'URL'
}
export const CreateAppForm = 'CreateAppForm';
export const UpdateAppForm = 'UpdateAppForm';
export const BindAppHomepageForm = 'BindAppHomepageForm';
export const EditAppModelModel = 'apps.AppsManagementModule';
export const CreateAppFormXml = `
`;
export const UpdateAppFormXml = `
`;
export const BindAppHomepageFormXml = `
`;
export async function bindHomePageByView(id, viewId) {
const body = `
mutation {
appsManagementModuleMutation {
bindHomePage(
data: {
id: ${id}
bindHomePageView: { id: ${viewId} }
}
) {
homePage {
id
model
name
displayName
}
}
}
}
`;
await http.mutate('apps', body);
}
export async function bindHomePageByMenu(id, menuId) {
const body = `
mutation {
appsManagementModuleMutation {
bindHomePage(
data: {
id: ${id}
bindHomePageMenu: { id: ${menuId} }
}
) {
homePage {
id
model
name
displayName
}
}
}
}
`;
await http.mutate('apps', body);
}
export async function bindHomePageByURL(id, url, target) {
const body = `
mutation {
appsManagementModuleMutation {
bindHomePage(
data: {
id: ${id}
urlHomePage: {
target: ${target}
url: "${url}"
}
}
) {
homePage {
id
model
name
displayName
}
}
}
}
`;
await http.mutate('apps', body);
}
export async function appQueryOne(id) {
const model = await ModelCache.get(EditAppModelModel);
const hasAppsModuleUpstreamList = !!model?.modelFields.find((v) => v.data === 'appsModuleUpstreamList');
const hasUrlHomePage = !!model?.modelFields.find((it) => it.data === 'urlHomePage');
const body = `
query{
appsManagementModuleQuery{
queryOne(query:{
id:${id}
}) {
id
moduleType
clientTypes
bindHomePageModel {
id
model
name
displayName
}
bindHomePageView {
id
title
name
model
}
bindHomePageMenu {
id
displayName
name
model
module
}
${
hasUrlHomePage
? `
urlHomePage {
target
url
}
`
: ''
}
homePageModel
homePageName
appsModuleDependencyList {
id
name
module
displayName
}
${
hasAppsModuleUpstreamList
? `
appsModuleUpstreamList {
id
name
module
displayName
}
`
: ''
}
application
displayName
module
name
moduleCategory{
id
name
code
}
logo
description
}
}
}
`;
const result = await http.query('apps', body);
return result.data.appsManagementModuleQuery.queryOne;
}
export async function installAppFun(id) {
const body = `
mutation{
appsManagementModuleMutation {
install(module: { id: ${id} }) {
id
status
state
}
}
}
`;
const result = await http.mutate('apps', body);
return result.data.appsManagementModuleMutation.install;
}
export async function uninstallAppFun(id) {
const body = `
mutation{
appsManagementModuleMutation {
uninstall(module: { id: ${id} }) {
id
status
state
}
}
}
`;
const result = await http.mutate('apps', body);
return result.data.appsManagementModuleMutation.uninstall;
}