From 13aad7b2ec95daebe093b1e4ba3708f1aee0c9a3 Mon Sep 17 00:00:00 2001 From: duanledexianxianxian Date: Tue, 2 Jul 2019 13:04:58 +0800 Subject: [PATCH] sync code --- config/defaultSettings.ts | 2 +- config/plugin.config.ts | 5 +- package.json | 1 - src/config.js | 4 +- src/layouts/BasicLayout.tsx | 10 ++- src/locales/zh-CN/menu.ts | 1 + src/models/setting.ts | 119 ++++++++++++------------------------ src/models/user.ts | 13 ---- src/services/user.ts | 7 ++- 9 files changed, 60 insertions(+), 102 deletions(-) diff --git a/config/defaultSettings.ts b/config/defaultSettings.ts index 1add9e22..338e9e4e 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 f4e54b6b..41c18f40 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 493169e9..50681f87 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 2b0cf60e..6e7a8e8b 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 ac74446b..04e98386 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 f851fe96..03ebd3c8 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 1b9b01ea..93907c3c 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 f528b98d..3274f699 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 03243f52..39d3c4f1 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); -- GitLab