From e855f6a121ceb347d3daa2d350379eceaa76eed6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8A=B1=E8=A3=A4=E8=A1=A9?= Date: Thu, 14 Mar 2019 17:11:25 +0800 Subject: [PATCH] add settings (#1707) --- src/components/RightPanel/index.vue | 140 +++++++++++++++++++++++ src/layout/Layout.vue | 27 +++-- src/layout/components/AppMain.vue | 9 +- src/layout/components/Navbar.vue | 8 ++ src/layout/components/Settings/index.vue | 68 +++++++++++ src/layout/components/index.js | 1 + src/settings.js | 22 ++++ src/store/index.js | 2 + src/store/modules/settings.js | 23 ++++ src/utils/index.js | 13 +++ 10 files changed, 301 insertions(+), 12 deletions(-) create mode 100644 src/components/RightPanel/index.vue create mode 100644 src/layout/components/Settings/index.vue create mode 100644 src/settings.js create mode 100644 src/store/modules/settings.js diff --git a/src/components/RightPanel/index.vue b/src/components/RightPanel/index.vue new file mode 100644 index 00000000..77a9d0d9 --- /dev/null +++ b/src/components/RightPanel/index.vue @@ -0,0 +1,140 @@ + + + + + + + diff --git a/src/layout/Layout.vue b/src/layout/Layout.vue index 4d0eaa2b..c0befd4b 100644 --- a/src/layout/Layout.vue +++ b/src/layout/Layout.vue @@ -2,34 +2,41 @@
-
+
- + + + +
diff --git a/src/layout/components/index.js b/src/layout/components/index.js index 5262e113..e9f79ddd 100644 --- a/src/layout/components/index.js +++ b/src/layout/components/index.js @@ -2,3 +2,4 @@ export { default as Navbar } from './Navbar' export { default as Sidebar } from './Sidebar/index.vue' export { default as TagsView } from './TagsView/index.vue' export { default as AppMain } from './AppMain' +export { default as Settings } from './Settings' diff --git a/src/settings.js b/src/settings.js new file mode 100644 index 00000000..27e7e65a --- /dev/null +++ b/src/settings.js @@ -0,0 +1,22 @@ +export default { + + /** + * @type {boolean} true | false + * @description Whether show the settings right-panel + */ + showSettings: true, + + /** + * @type {boolean} true | false + * @description Whether need tagsView + */ + tagsView: true, + + /** + * @type {string | array} 'production' | ['production','development'] + * @description Need show err logs component. + * The default is only used in the production env + * If you want to use it in dev, you can pass ['production','development'] + */ + errorLog: 'production' +} diff --git a/src/store/index.js b/src/store/index.js index 24778fad..4842ea7e 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -4,6 +4,7 @@ import app from './modules/app' import errorLog from './modules/errorLog' import permission from './modules/permission' import tagsView from './modules/tagsView' +import settings from './modules/settings' import user from './modules/user' import getters from './getters' @@ -15,6 +16,7 @@ const store = new Vuex.Store({ errorLog, permission, tagsView, + settings, user }, getters diff --git a/src/store/modules/settings.js b/src/store/modules/settings.js new file mode 100644 index 00000000..d47505c4 --- /dev/null +++ b/src/store/modules/settings.js @@ -0,0 +1,23 @@ +import defaultSettings from '@/settings' +const { showSettings, tagsView } = defaultSettings + +const settings = { + state: { + showSettings: showSettings, + tagsView: tagsView + }, + mutations: { + CHANGE_SETTING: (state, { key, value }) => { + if (state.hasOwnProperty(key)) { + state[key] = value + } + } + }, + actions: { + changeSetting({ commit }, data) { + commit('CHANGE_SETTING', data) + } + } +} + +export default settings diff --git a/src/utils/index.js b/src/utils/index.js index 263108b4..2fcbba79 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -299,3 +299,16 @@ export function createUniqueString() { const randomNum = parseInt((1 + Math.random()) * 65536) + '' return (+(randomNum + timestamp)).toString(32) } + +export function hasClass(ele, cls) { + return !!ele.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)')) +} +export function addClass(ele, cls) { + if (!hasClass(ele, cls)) ele.className += ' ' + cls +} +export function removeClass(ele, cls) { + if (hasClass(ele, cls)) { + const reg = new RegExp('(\\s|^)' + cls + '(\\s|$)') + ele.className = ele.className.replace(reg, ' ') + } +}