From 3f479664b6ed1b89af46556df703a9e981e5988e Mon Sep 17 00:00:00 2001 From: Pan Date: Tue, 19 Jun 2018 11:26:46 +0800 Subject: [PATCH 001/321] perf[utils.js]: Add code comments to deepClone and remove redundant code --- src/utils/index.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/utils/index.js b/src/utils/index.js index 431fda2d..31295122 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -246,6 +246,11 @@ export function debounce(func, wait, immediate) { } } +/** + * This is just a simple version of deep copy + * Has a lot of edge cases bug + * If you want to use a perfect deep copy, use lodash's _.cloneDeep + */ export function deepClone(source) { if (!source && typeof source !== 'object') { throw new Error('error arguments', 'shallowClone') @@ -253,7 +258,6 @@ export function deepClone(source) { const targetObj = source.constructor === Array ? [] : {} Object.keys(source).forEach((keys) => { if (source[keys] && typeof source[keys] === 'object') { - targetObj[keys] = source[keys].constructor === Array ? [] : {} targetObj[keys] = deepClone(source[keys]) } else { targetObj[keys] = source[keys] From 03691739e18ae00b8939d5703ca613e023e64225 Mon Sep 17 00:00:00 2001 From: Pan Date: Tue, 19 Jun 2018 17:52:05 +0800 Subject: [PATCH 002/321] add:[permission]: add checkPermission function --- src/utils/permission.js | 26 ++++++++++++++++++++++++++ src/views/permission/directive.vue | 13 +++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 src/utils/permission.js diff --git a/src/utils/permission.js b/src/utils/permission.js new file mode 100644 index 00000000..7bd22e01 --- /dev/null +++ b/src/utils/permission.js @@ -0,0 +1,26 @@ +import store from '@/store' + +/** + * @param {Array} value + * @returns {Boolean} + * @example see @/views/permission/directive.vue + */ +export default function checkPermission(value) { + if (value && value instanceof Array && value.length > 0) { + const roles = store.getters && store.getters.roles + const permissionRoles = value + + const hasPermission = roles.some(role => { + return permissionRoles.includes(role) + }) + + if (!hasPermission) { + return false + } + return true + } else { + console.error(`need roles! Like v-permission="['admin','editor']"`) + return false + } +} + diff --git a/src/views/permission/directive.vue b/src/views/permission/directive.vue index d6e6a928..c303e886 100644 --- a/src/views/permission/directive.vue +++ b/src/views/permission/directive.vue @@ -16,11 +16,23 @@ editor can see this + +
+ In some cases it is not suitable to use v-permission, such as element Tab component which can only be achieved by manually setting the v-if. +
e.g. +
+ + Admin can see this + Editor can see this + Both admin or editor can see this + +
+ From 9e04f581634e9489cf5d63d3bb52865bf1129b74 Mon Sep 17 00:00:00 2001 From: Pan Date: Sat, 7 Jul 2018 01:44:29 +0800 Subject: [PATCH 019/321] perf[login]: i18n of input placeholder #844 --- src/views/login/index.vue | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/views/login/index.vue b/src/views/login/index.vue index 0296b701..4d15c055 100644 --- a/src/views/login/index.vue +++ b/src/views/login/index.vue @@ -1,22 +1,27 @@