diff --git a/config/defaultSettings.ts b/config/defaultSettings.ts index 1add9e2290488bd94ba42c3022309e51592543f5..338e9e4e46809d76f319a8e0149a23eacec9a27f 100644 --- a/config/defaultSettings.ts +++ b/config/defaultSettings.ts @@ -54,7 +54,7 @@ export interface DefaultSettings { export default { navTheme: 'dark', - primaryColor: '#43cec4', + primaryColor: '#13C2C2', layout: 'sidemenu', contentWidth: 'Fluid', fixedHeader: true, diff --git a/config/plugin.config.ts b/config/plugin.config.ts index f4e54b6b50dbaf1817a3a20998ac52a37ce5f529..41c18f40b90ebd90aa4e11e4369288e07993fa7c 100644 --- a/config/plugin.config.ts +++ b/config/plugin.config.ts @@ -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) { diff --git a/package.json b/package.json index 493169e97f74b4f3597b6a40364e04bfa1a0ac7f..50681f8799a5452b9d9829d72b4c03b4f6d8e18a 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,6 @@ }, "husky": { "hooks": { - "pre-commit": "npm run lint-staged" } }, "lint-staged": { diff --git a/src/config.js b/src/config.js index 2b0cf60e9db8246844a94d3d4d5aa91886fe1109..6e7a8e8b921b8c9fb6d5a7b66094325ad8620a0f 100644 --- a/src/config.js +++ b/src/config.js @@ -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', }; diff --git a/src/layouts/BasicLayout.tsx b/src/layouts/BasicLayout.tsx index ac74446bd752dc60162eca2fa9d0ea6f02440acb..04e98386dd5f1f5ece677461ee6fa576c590b6ef 100644 --- a/src/layouts/BasicLayout.tsx +++ b/src/layouts/BasicLayout.tsx @@ -155,12 +155,16 @@ const BasicLayout: React.FC = props => { {/* 主题设置抽屉 */} + onSettingChange={config => { + dispatch({ + type: 'settings/saveSettings', + payload: config, + }); dispatch({ type: 'settings/changeSetting', payload: config, - }) - } + }); + }} /> ) diff --git a/src/locales/zh-CN/menu.ts b/src/locales/zh-CN/menu.ts index f851fe967537e3af58c0bec054ee200e747bef10..03ebd3c85393317e69de632e4256898b8068a46d 100644 --- a/src/locales/zh-CN/menu.ts +++ b/src/locales/zh-CN/menu.ts @@ -47,4 +47,5 @@ export default { 'menu.editor.flow': '流程编辑器', 'menu.editor.mind': '脑图编辑器', 'menu.editor.koni': '拓扑编辑器', + 'menu.parameter': '参数管理', }; diff --git a/src/models/setting.ts b/src/models/setting.ts index 1b9b01eae740c1e43bd306be7307f4843fb38b75..93907c3cd9322c7daccdfac2139435fcaf95127f 100644 --- a/src/models/setting.ts +++ b/src/models/setting.ts @@ -1,97 +1,36 @@ 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; - getSetting: Reducer; - changeSetting: Reducer; + getSetting: Reducer; + changeSetting: Reducer; }; } 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 = {}; 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); diff --git a/src/models/user.ts b/src/models/user.ts index f528b98da8f0a67dcb33ba3bf2038e9f92417788..3274f6999ea3d17de3a87d8b430e049b53519eeb 100644 --- a/src/models/user.ts +++ b/src/models/user.ts @@ -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; } diff --git a/src/services/user.ts b/src/services/user.ts index 03243f5266e0845d231b81d016d5ff6b63afdef4..39d3c4f11c050ca3118d3beca539c3745f2db90f 100644 --- a/src/services/user.ts +++ b/src/services/user.ts @@ -1,4 +1,4 @@ -import { get } from '@/utils/request'; +import { get, put } from '@/utils/request'; export async function query(): Promise { 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);