import { WebStyleType } from '@/pages/Home/hooks/useHome';
import { UI_REST_LOGIN, UI_REST_KEEPALIVE, UI_REST_RSAKEY } from '../api/api';
import $http from './http-service';
import CustomizeService from '@/services/customize/customize.service';
import Color from '@/components/Customize/color';
import { DefaultColorConfig } from '@/components/Customize/customize.model';
const CustomizeConfig = new CustomizeService();
const colorConfig = JSON.parse(JSON.stringify(DefaultColorConfig));
export function getLoginInfo(): Promise<any> {
return new Promise((resolve, reject) => {
$http
.get(UI_REST_LOGIN)
.then(res => {
resolve(res);
})
.catch(error => {
reject(error);
});
});
}
export function getStyleConfig(): Promise<any> {
return new Promise((resolve, reject) => {
const url = `/style_config.json?t=${Date.now()}`;
$http.get(url).then(
(res: any) => {
resolve(res.data);
},
error => {
resolve(null);
}
);
});
}
export function getStyleInfo(): Promise<any> {
return new Promise((resolve, reject) => {
const url = `/extern/custom/style_config.json?t=${Date.now()}`;
$http.get(url).then(
(res: any) => {
resolve(res.data);
},
error => {
if (localStorage.getItem('ptc2')) {
const pageStyle = JSON.parse(localStorage.getItem('customizeStyle') || '{}')?.pageStyle;
resolve({ pageStyle: pageStyle || WebStyleType.DEFAULT });
} else {
resolve({ pageStyle: WebStyleType.DEFAULT });
}
}
);
});
}
export function keepAlive(mode: 'Activate' | 'Deactivate'): Promise<any> {
return $http.post(UI_REST_KEEPALIVE, { Mode: mode });
}
let mixColor = colorConfig.themeMode === 'dark' ? '#000' : '#FFF';
const colorList = [
{
text: '浪漫蓝紫',
label: 'romantic',
color1: '#3F51B5',
color2: new Color(mixColor).mixin('#3F51B5', 0.32),
color3: new Color(mixColor).mixin('#3F51B5', 0.72)
},
{
text: '经典蓝',
label: 'classic',
color1: '#004EB5',
color2: new Color(mixColor).mixin('#004EB5', 0.32),
color3: new Color(mixColor).mixin('#004EB5', 0.72)
},
{
text: '科技蓝',
label: 'technology',
color1: '#0077FF',
color2: new Color(mixColor).mixin('#0077FF', 0.32),
color3: new Color(mixColor).mixin('#0077FF', 0.72)
}
];
const styleList = {
standard: 'technology',
ibma: 'classic',
simple: 'technology',
beautiful: 'romantic'
};
export function changeColor(val: string): void {
let color1 = '';
let color2 = '';
let color3 = '';
colorList.forEach(item => {
if (item.label === styleList[val]) {
color1 = item.color1;
color2 = item.color2.origin;
color3 = item.color3.origin;
}
});
if (color1 !== '' && color2 !== '' && color3 !== '') {
CustomizeConfig.setVar('--o-color-primary', color1);
CustomizeConfig.setVar('--o-color-primary-secondary', color2);
CustomizeConfig.setVar('--o-color-primary-fourth', color3);
CustomizeConfig.setVar('--o-color-video-primary', `${color1}B3`);
const color = new Color(color1);
CustomizeConfig.setVar('--o-color-customize-shadow', `${color.mixin('#000', 0.52).value}66`);
}
}
export function getEncryptKey(): Promise<any> {
return new Promise((resolve, reject) => {
$http
.get(UI_REST_RSAKEY)
.then(res => {
resolve(res);
})
.catch(error => {
reject(error);
});
});
}