lrj
昨天 93eb6b470773bc49ea6e1a9d4cbd914eb95d525b
web/src/api/config.js
@@ -1,21 +1,49 @@
// 应用配置 API
const GRAPHQL_ENDPOINT = 'http://localhost:8080/api/graphql';
import { API_CONFIG, graphqlRequest } from '@/config/api';
const GET_APP_CONFIG = `
  query AppConfig {
  query GetAppConfig {
    appConfig {
      mediaBaseUrl
      id
      name
      value
      description
      type
      createTime
      updateTime
    }
  }
`;
export const fetchAppConfig = async () => {
  const resp = await fetch(GRAPHQL_ENDPOINT, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ query: GET_APP_CONFIG })
  });
  const result = await resp.json();
  if (result.errors) throw new Error(result.errors[0].message);
  return result.data.appConfig;
const SAVE_APP_CONFIG = `
  mutation SaveAppConfig($input: AppConfigInput!) {
    saveAppConfig(input: $input) {
      id
      name
      value
      description
      type
      createTime
      updateTime
    }
  }
`;
// API 函数
export const getAppConfig = async () => {
  try {
    const data = await graphqlRequest(GET_APP_CONFIG);
    return data.appConfig || [];
  } catch (error) {
    throw new Error(error.message || '获取应用配置失败');
  }
};
export const saveAppConfig = async (configData) => {
  try {
    const data = await graphqlRequest(SAVE_APP_CONFIG, { input: configData });
    return data.saveAppConfig;
  } catch (error) {
    throw new Error(error.message || '保存应用配置失败');
  }
};