Commit 13aad7b2 authored by duanledexianxianxian's avatar duanledexianxianxian

sync code

parent 40d489f4
...@@ -54,7 +54,7 @@ export interface DefaultSettings { ...@@ -54,7 +54,7 @@ export interface DefaultSettings {
export default { export default {
navTheme: 'dark', navTheme: 'dark',
primaryColor: '#43cec4', primaryColor: '#13C2C2',
layout: 'sidemenu', layout: 'sidemenu',
contentWidth: 'Fluid', contentWidth: 'Fluid',
fixedHeader: true, fixedHeader: true,
......
...@@ -4,7 +4,8 @@ ...@@ -4,7 +4,8 @@
import ThemeColorReplacer from 'webpack-theme-color-replacer'; import ThemeColorReplacer from 'webpack-theme-color-replacer';
import generate from '@ant-design/colors/lib/generate'; import generate from '@ant-design/colors/lib/generate';
import path from 'path'; import path from 'path';
import defaultSettings from './defaultSettings';
const { primaryColor } = defaultSettings;
function getModulePackageName(module: { context: string }) { function getModulePackageName(module: { context: string }) {
if (!module.context) return null; if (!module.context) return null;
...@@ -34,7 +35,7 @@ export default (config: any) => { ...@@ -34,7 +35,7 @@ export default (config: any) => {
config.plugin('webpack-theme-color-replacer').use(ThemeColorReplacer, [ config.plugin('webpack-theme-color-replacer').use(ThemeColorReplacer, [
{ {
fileName: 'css/theme-colors-[contenthash:8].css', fileName: 'css/theme-colors-[contenthash:8].css',
matchColors: getAntdSerials('#1890ff'), // 主色系列 matchColors: getAntdSerials(primaryColor), // 主色系列
// 改变样式选择器,解决样式覆盖问题 // 改变样式选择器,解决样式覆盖问题
changeSelector(selector: string): string { changeSelector(selector: string): string {
switch (selector) { switch (selector) {
......
...@@ -36,7 +36,6 @@ ...@@ -36,7 +36,6 @@
}, },
"husky": { "husky": {
"hooks": { "hooks": {
"pre-commit": "npm run lint-staged"
} }
}, },
"lint-staged": { "lint-staged": {
......
...@@ -2,7 +2,7 @@ export default { ...@@ -2,7 +2,7 @@ export default {
storeNameSpace: 'kim', storeNameSpace: 'kim',
request: { request: {
apiPrefix: '', apiPrefix: '',
baseUrl: 'http://platform.kuopu.net:9080', baseUrl: 'http://127.0.0.1:8080',
resCodeKey: 'code', // 后台正常返回错误编码 resCodeKey: 'code', // 后台正常返回错误编码
resMessageKey: 'message', // 后台正常返回错误编码 resMessageKey: 'message', // 后台正常返回错误编码
successCode: 'sys.success', // 后台正常返回错误编码 successCode: 'sys.success', // 后台正常返回错误编码
...@@ -12,6 +12,6 @@ export default { ...@@ -12,6 +12,6 @@ export default {
}, },
copyright: `${new Date().getFullYear()} KIM3.0技术中台部出品`, copyright: `${new Date().getFullYear()} KIM3.0技术中台部出品`,
homePage: '/dashboard/analysis', homePage: '/dashboard/analysis',
fileServerUrl: 'http://platform.kuopu.net:9008', fileServerUrl: 'http://127.0.0.1:8080',
defaultAvatar: '/images/default-avatar.png', defaultAvatar: '/images/default-avatar.png',
}; };
...@@ -155,12 +155,16 @@ const BasicLayout: React.FC<BasicLayoutProps> = props => { ...@@ -155,12 +155,16 @@ const BasicLayout: React.FC<BasicLayoutProps> = props => {
{/* 主题设置抽屉 */} {/* 主题设置抽屉 */}
<SettingDrawer <SettingDrawer
settings={settings} settings={settings}
onSettingChange={config => onSettingChange={config => {
dispatch({
type: 'settings/saveSettings',
payload: config,
});
dispatch({ dispatch({
type: 'settings/changeSetting', type: 'settings/changeSetting',
payload: config, payload: config,
}) });
} }}
/> />
</div> </div>
) )
......
...@@ -47,4 +47,5 @@ export default { ...@@ -47,4 +47,5 @@ export default {
'menu.editor.flow': '流程编辑器', 'menu.editor.flow': '流程编辑器',
'menu.editor.mind': '脑图编辑器', 'menu.editor.mind': '脑图编辑器',
'menu.editor.koni': '拓扑编辑器', 'menu.editor.koni': '拓扑编辑器',
'menu.parameter': '参数管理',
}; };
import { Reducer } from 'redux'; import { Reducer } from 'redux';
// eslint-disable-next-line eslint-comments/disable-enable-pair
/* eslint-disable promise/catch-or-return */
import { message } from 'antd'; import { message } from 'antd';
import defaultSettings, { DefaultSettings } from '../../config/defaultSettings'; import defaultSettings, { DefaultSettings } from '../../config/defaultSettings';
import themeColorClient from '../components/SettingDrawer/themeColorClient'; import themeColorClient from '../components/SettingDrawer/themeColorClient';
import { getCurrentUserSetting } from '@/services/user'; import { getCurrentUserSetting, saveCurrentUserSetting } from '@/services/user';
import { Effect } from 'dva'; import { Effect } from 'dva';
export interface UserSetting extends DefaultSettings {
settingId?: number;
userId?: number;
}
export interface SettingModelType { export interface SettingModelType {
namespace: 'settings'; namespace: 'settings';
state: DefaultSettings; state: UserSetting;
effects: { effects: {
getSettings: Effect; getSettings: Effect;
}; };
reducers: { reducers: {
saveSettings: Reducer<DefaultSettings>; getSetting: Reducer<UserSetting>;
getSetting: Reducer<DefaultSettings>; changeSetting: Reducer<UserSetting>;
changeSetting: Reducer<DefaultSettings>;
}; };
} }
const updateTheme = (newPrimaryColor?: string) => { const updateTheme = (newPrimaryColor?: string) => {
if (newPrimaryColor) { if (newPrimaryColor) {
console.log(newPrimaryColor);
const timeOut = 0; const timeOut = 0;
const hideMessage = message.loading('正在切换主题!', timeOut); const hideMessage = message.loading('正在切换主题!', timeOut);
themeColorClient.changeColor(newPrimaryColor).finally(() => hideMessage()); 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 updateColorWeak: (colorWeak: boolean) => void = colorWeak => {
const root = document.getElementById('root'); const root = document.getElementById('root');
if (root) { if (root) {
...@@ -103,9 +42,34 @@ const SettingModel: SettingModelType = { ...@@ -103,9 +42,34 @@ const SettingModel: SettingModelType = {
namespace: 'settings', namespace: 'settings',
state: defaultSettings, state: defaultSettings,
effects: { 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 }) { *getSettings({ payload }, { call, put }) {
const { data, code } = yield call(getCurrentUserSetting, payload); const { data, code } = yield call(getCurrentUserSetting, payload);
let settings = defaultSettings; let settings = defaultSettings;
console.log(data);
if (code === 'sys.success' && data) { if (code === 'sys.success' && data) {
const { const {
appStyle, appStyle,
...@@ -118,6 +82,7 @@ const SettingModel: SettingModelType = { ...@@ -118,6 +82,7 @@ const SettingModel: SettingModelType = {
} = data; } = data;
settings = { settings = {
...settings, ...settings,
...data,
navTheme: appStyle === 0 ? 'light' : 'dark', navTheme: appStyle === 0 ? 'light' : 'dark',
primaryColor: appTheme, primaryColor: appTheme,
layout: navigatorStyle === 0 ? 'sidemenu' : 'topmenu', layout: navigatorStyle === 0 ? 'sidemenu' : 'topmenu',
...@@ -134,13 +99,7 @@ const SettingModel: SettingModelType = { ...@@ -134,13 +99,7 @@ const SettingModel: SettingModelType = {
}, },
}, },
reducers: { reducers: {
saveSettings(state, { payload }) { saveSettings(state = defaultSettings, { payload }) {
return {
...state,
...payload,
};
},
getSetting(state = defaultSettings) {
const setting: Partial<DefaultSettings> = {}; const setting: Partial<DefaultSettings> = {};
const urlParams = new URL(window.location.href); const urlParams = new URL(window.location.href);
Object.keys(state).forEach(key => { Object.keys(state).forEach(key => {
...@@ -158,10 +117,12 @@ const SettingModel: SettingModelType = { ...@@ -158,10 +117,12 @@ const SettingModel: SettingModelType = {
return { return {
...state, ...state,
...setting, ...setting,
...payload,
}; };
}, },
changeSetting(state = defaultSettings, { payload }) { changeSetting(state = defaultSettings, { payload }) {
const urlParams = new URL(window.location.href); const urlParams = new URL(window.location.href);
Object.keys(defaultSettings).forEach(key => { Object.keys(defaultSettings).forEach(key => {
if (urlParams.searchParams.has(key)) { if (urlParams.searchParams.has(key)) {
urlParams.searchParams.delete(key); urlParams.searchParams.delete(key);
......
...@@ -60,19 +60,6 @@ export interface CurrentUser extends BaseModel { ...@@ -60,19 +60,6 @@ export interface CurrentUser extends BaseModel {
unreadCount?: number; 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 { export interface UserModelState {
currentUser?: CurrentUser; currentUser?: CurrentUser;
} }
......
import { get } from '@/utils/request'; import { get, put } from '@/utils/request';
export async function query(): Promise<any> { export async function query(): Promise<any> {
return get('/api/users'); return get('/api/users');
...@@ -24,3 +24,8 @@ export const getCurrentUserInfo = async () => get(`/api/v1/detail`); ...@@ -24,3 +24,8 @@ export const getCurrentUserInfo = async () => get(`/api/v1/detail`);
* 获取用户配置信息 * 获取用户配置信息
*/ */
export const getCurrentUserSetting = async () => get(`/api/v1/profile/settings`); 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