Commit 13aad7b2 authored by duanledexianxianxian's avatar duanledexianxianxian

sync code

parent 40d489f4
......@@ -54,7 +54,7 @@ export interface DefaultSettings {
export default {
navTheme: 'dark',
primaryColor: '#43cec4',
primaryColor: '#13C2C2',
layout: 'sidemenu',
contentWidth: 'Fluid',
fixedHeader: true,
......
......@@ -4,7 +4,8 @@
import ThemeColorReplacer from 'webpack-theme-color-replacer';
import generate from '@ant-design/colors/lib/generate';
import path from 'path';
import defaultSettings from './defaultSettings';
const { primaryColor } = defaultSettings;
function getModulePackageName(module: { context: string }) {
if (!module.context) return null;
......@@ -34,7 +35,7 @@ export default (config: any) => {
config.plugin('webpack-theme-color-replacer').use(ThemeColorReplacer, [
{
fileName: 'css/theme-colors-[contenthash:8].css',
matchColors: getAntdSerials('#1890ff'), // 主色系列
matchColors: getAntdSerials(primaryColor), // 主色系列
// 改变样式选择器,解决样式覆盖问题
changeSelector(selector: string): string {
switch (selector) {
......
......@@ -36,7 +36,6 @@
},
"husky": {
"hooks": {
"pre-commit": "npm run lint-staged"
}
},
"lint-staged": {
......
......@@ -2,7 +2,7 @@ export default {
storeNameSpace: 'kim',
request: {
apiPrefix: '',
baseUrl: 'http://platform.kuopu.net:9080',
baseUrl: 'http://127.0.0.1:8080',
resCodeKey: 'code', // 后台正常返回错误编码
resMessageKey: 'message', // 后台正常返回错误编码
successCode: 'sys.success', // 后台正常返回错误编码
......@@ -12,6 +12,6 @@ export default {
},
copyright: `${new Date().getFullYear()} KIM3.0技术中台部出品`,
homePage: '/dashboard/analysis',
fileServerUrl: 'http://platform.kuopu.net:9008',
fileServerUrl: 'http://127.0.0.1:8080',
defaultAvatar: '/images/default-avatar.png',
};
......@@ -155,12 +155,16 @@ const BasicLayout: React.FC<BasicLayoutProps> = props => {
{/* 主题设置抽屉 */}
<SettingDrawer
settings={settings}
onSettingChange={config =>
onSettingChange={config => {
dispatch({
type: 'settings/saveSettings',
payload: config,
});
dispatch({
type: 'settings/changeSetting',
payload: config,
})
}
});
}}
/>
</div>
)
......
......@@ -47,4 +47,5 @@ export default {
'menu.editor.flow': '流程编辑器',
'menu.editor.mind': '脑图编辑器',
'menu.editor.koni': '拓扑编辑器',
'menu.parameter': '参数管理',
};
import { Reducer } from 'redux';
// eslint-disable-next-line eslint-comments/disable-enable-pair
/* eslint-disable promise/catch-or-return */
import { message } from 'antd';
import defaultSettings, { DefaultSettings } from '../../config/defaultSettings';
import themeColorClient from '../components/SettingDrawer/themeColorClient';
import { getCurrentUserSetting } from '@/services/user';
import { getCurrentUserSetting, saveCurrentUserSetting } from '@/services/user';
import { Effect } from 'dva';
export interface UserSetting extends DefaultSettings {
settingId?: number;
userId?: number;
}
export interface SettingModelType {
namespace: 'settings';
state: DefaultSettings;
state: UserSetting;
effects: {
getSettings: Effect;
};
reducers: {
saveSettings: Reducer<DefaultSettings>;
getSetting: Reducer<DefaultSettings>;
changeSetting: Reducer<DefaultSettings>;
getSetting: Reducer<UserSetting>;
changeSetting: Reducer<UserSetting>;
};
}
const updateTheme = (newPrimaryColor?: string) => {
if (newPrimaryColor) {
console.log(newPrimaryColor);
const timeOut = 0;
const hideMessage = message.loading('正在切换主题!', timeOut);
themeColorClient.changeColor(newPrimaryColor).finally(() => hideMessage());
}
};
/*
let lessNodesAppended: boolean;
const updateTheme: (primaryColor?: string) => void = primaryColor => {
// Don't compile less in production!
// preview.pro.ant.design only do not use in your production;
// preview.pro.ant.design 专用环境变量,请不要在你的项目中使用它。
if (ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION !== 'site') {
return;
}
// Determine if the component is remounted
if (!primaryColor) {
return;
}
const hideMessage = message.loading('正在编译主题!', 0);
function buildIt() {
if (!(window as any).less) {
console.log('no less');
return;
}
setTimeout(() => {
(window as any).less
.modifyVars({
'@primary-color': primaryColor,
})
.then(() => {
hideMessage();
return true;
})
.catch(() => {
message.error('Failed to update theme');
hideMessage();
});
}, 200);
}
if (!lessNodesAppended) {
// insert less.js and color.less
const lessStyleNode = document.createElement('link');
const lessConfigNode = document.createElement('script');
const lessScriptNode = document.createElement('script');
lessStyleNode.setAttribute('rel', 'stylesheet/less');
lessStyleNode.setAttribute('href', '/color.less');
lessConfigNode.innerHTML = `
window.less = {
async: true,
env: 'production',
javascriptEnabled: true
};
`;
lessScriptNode.src = 'https://gw.alipayobjects.com/os/lib/less.js/3.8.1/less.min.js';
lessScriptNode.async = true;
lessScriptNode.onload = () => {
buildIt();
lessScriptNode.onload = null;
};
document.body.appendChild(lessStyleNode);
document.body.appendChild(lessConfigNode);
document.body.appendChild(lessScriptNode);
lessNodesAppended = true;
} else {
buildIt();
}
};
*/
const updateColorWeak: (colorWeak: boolean) => void = colorWeak => {
const root = document.getElementById('root');
if (root) {
......@@ -103,9 +42,34 @@ const SettingModel: SettingModelType = {
namespace: 'settings',
state: defaultSettings,
effects: {
*saveSettings({ payload }, { call, put }) {
const {
navTheme,
primaryColor,
layout,
contentWidth,
fixedHeader,
autoHideHeader,
fixSiderbar,
userId,
settingId,
} = payload;
yield call(saveCurrentUserSetting, {
userId,
settingId,
appStyle: navTheme === 'light' ? 0 : 1,
appTheme: primaryColor,
navigatorStyle: layout === 'sidemenu' ? 0 : 1,
contentWidth: navTheme === 'Fluid' ? 0 : 1,
fixedHead: fixedHeader ? 1 : 0,
fixedSide: fixSiderbar ? 1 : 0,
hideHead: autoHideHeader ? 1 : 0,
});
},
*getSettings({ payload }, { call, put }) {
const { data, code } = yield call(getCurrentUserSetting, payload);
let settings = defaultSettings;
console.log(data);
if (code === 'sys.success' && data) {
const {
appStyle,
......@@ -118,6 +82,7 @@ const SettingModel: SettingModelType = {
} = data;
settings = {
...settings,
...data,
navTheme: appStyle === 0 ? 'light' : 'dark',
primaryColor: appTheme,
layout: navigatorStyle === 0 ? 'sidemenu' : 'topmenu',
......@@ -134,13 +99,7 @@ const SettingModel: SettingModelType = {
},
},
reducers: {
saveSettings(state, { payload }) {
return {
...state,
...payload,
};
},
getSetting(state = defaultSettings) {
saveSettings(state = defaultSettings, { payload }) {
const setting: Partial<DefaultSettings> = {};
const urlParams = new URL(window.location.href);
Object.keys(state).forEach(key => {
......@@ -158,10 +117,12 @@ const SettingModel: SettingModelType = {
return {
...state,
...setting,
...payload,
};
},
changeSetting(state = defaultSettings, { payload }) {
const urlParams = new URL(window.location.href);
Object.keys(defaultSettings).forEach(key => {
if (urlParams.searchParams.has(key)) {
urlParams.searchParams.delete(key);
......
......@@ -60,19 +60,6 @@ export interface CurrentUser extends BaseModel {
unreadCount?: number;
}
export interface UserSetting {
enabled?: number;
appTheme?: string;
contentWidth?: number;
fixedHead?: number;
fixedSide?: number;
hideHead?: number;
navigatorStyle?: number;
settingId?: number;
userId?: number;
userSetting?: UserSetting;
}
export interface UserModelState {
currentUser?: CurrentUser;
}
......
import { get } from '@/utils/request';
import { get, put } from '@/utils/request';
export async function query(): Promise<any> {
return get('/api/users');
......@@ -24,3 +24,8 @@ export const getCurrentUserInfo = async () => get(`/api/v1/detail`);
* 获取用户配置信息
*/
export const getCurrentUserSetting = async () => get(`/api/v1/profile/settings`);
/**
* 保存用户配置信息
*/
export const saveCurrentUserSetting = data => put('/api/v1/profile/settings', data);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment