| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- import { UpdateServerRequestModule } from '@/api/RequestModules';
- import { DataModel } from '@imengyu/js-request-transform';
- import type { IHomeCommonCategoryDefine } from '../CommonCategoryDefine';
- export const CommonCategoryConfig = {
- /**
- * 应用id
- */
- appId: 2,
- appConfig: {
- dev: {
- id: 3,
- accessKey: '3hSiTCiGNiF2c3yyB6JNtA4eEf2jX8Yi2w87W2F6FYxH2W7e',
- },
- prod: {
- id: 5,
- accessKey: 'Cn7rTk8dtdciZsicrebKrrtwF44HFYmhc6NpSFdnD38d4XMS',
- },
- },
- getAppConfigId: (isDev: boolean) => {
- return isDev ? CommonCategoryConfig.appConfig.dev.id : CommonCategoryConfig.appConfig.prod.id;
- },
- getAccessKey: (isDev: boolean) => {
- return isDev ? CommonCategoryConfig.appConfig.dev.accessKey : CommonCategoryConfig.appConfig.prod.accessKey;
- },
- }
- export interface ICommonCategoryConfigItem {
- activeHistoryId: number;
- data: IHomeCommonCategoryDefine;
- }
- export interface ICommonCategoryConfigHistoryItem {
- data: IHomeCommonCategoryDefine;
- }
- export class CommonCategoryApi extends UpdateServerRequestModule<DataModel> {
- constructor() {
- super();
- }
- /**
- * 获取当前配置,有缓存,会根据激活的历史版本获取对应配置
- * @returns
- */
- async getConfig(isDev: boolean) {
- return (await this.get<ICommonCategoryConfigHistoryItem>('/app-configuration-get', '获取配置', {
- name: CommonCategoryConfig.getAppConfigId(isDev),
- appId: CommonCategoryConfig.appId,
- accessKey: CommonCategoryConfig.getAccessKey(isDev),
- })).data!.data as IHomeCommonCategoryDefine;
- }
- /**
- * 获取顶级配置,不使用缓存
- * @returns
- */
- async getConfigWithoutCache(isDev: boolean) {
- return (await this.get<ICommonCategoryConfigItem>('/app-configuration/' + CommonCategoryConfig.getAppConfigId(isDev), '获取配置')).data;
- }
- /**
- * 编辑配置
- * @param json 配置数据
- * @param saveToHistoryId 保存到历史版本id:为0时创建新历史版本;为空不保存到历史版本;为其他值时保存到指定ID历史版本
- * @param name 历史版本名称:为空时使用默认名称
- * @param autoSelectNewToActive 自动选择新创建的历史版本为活动版本:为true时自动选择新创建的历史版本为活动版本;为false时不自动选择;为空时不自动选择
- * @returns
- */
- async editConfig(
- isDev: boolean,
- json: ICommonCategoryConfigHistoryItem['data'],
- name?: string,
- saveToHistoryId?: number,
- autoSelectNewToActive?: boolean,
- ) {
- return (await this.post(`/app-configuration-edit/${CommonCategoryConfig.getAppConfigId(isDev)}?saveToHistoryId=${saveToHistoryId ?? ''}`, '编辑配置', {
- id: CommonCategoryConfig.getAppConfigId(isDev),
- name,
- data: json,
- accessKey: CommonCategoryConfig.getAccessKey(isDev),
- autoSelectNewToActive: autoSelectNewToActive ?? false,
- })).data;
- }
- /**
- * 获取配置历史版本列表
- * @param page 页码
- * @param pageSize 页大小
- * @returns
- */
- async getConfigHistoryList(isDev: boolean, page: number, pageSize = 10) {
- return (await this.get<{
- allCount: number;
- allPage: number;
- empty: boolean;
- items: ICommonCategoryConfigHistoryItem[];
- pageIndex: number;
- pageSize: number;
- }>(
- `/app-configuration-history/${page}/${pageSize}?appConfigurationId=${CommonCategoryConfig.getAppConfigId(isDev)}`,
- '获取配置历史版本列表'
- )).data;
- }
- /**
- * 删除配置历史版本
- * @param id 历史版本id
- * @returns
- */
- async deleteConfigHistory(isDev: boolean, id: number) {
- return (await this.delete(`/app-configuration-history/${id}`, '删除配置历史版本', {
- accessKey: CommonCategoryConfig.getAccessKey(isDev),
- appConfigurationId: CommonCategoryConfig.getAppConfigId(isDev),
- })).data;
- }
- /**
- * 设置配置历史版本为活动版本
- * @param historyId 历史版本id
- * @returns
- */
- async setActiveConfigHistory(isDev: boolean, historyId: number) {
- return (await this.post(`/app-configuration-set-active-history`, '设置配置历史版本为活动版本', {
- accessKey: CommonCategoryConfig.getAccessKey(isDev),
- id: CommonCategoryConfig.getAppConfigId(isDev),
- historyId,
- })).data;
- }
- }
- export default new CommonCategoryApi();
|