| | |
| | | const auth = function(authConfig, permission, role, permissions, roles) { |
| | | const {check, type} = authConfig |
| | | if (check && typeof check === 'function') { |
| | | return check(permission, role, permissions, roles) |
| | | return check.apply(this, [permission, role, permissions, roles]) |
| | | } else { |
| | | if (type === 'permission') { |
| | | return permission && permission.operation && permission.operation.indexOf(check) !== -1 |
| | |
| | | this.$options.methods[key] = function () { |
| | | //--auth-inject |
| | | if (this.$auth(check, type)) { |
| | | return method(...arguments) |
| | | return method.apply(this, arguments) |
| | | } else { |
| | | if (onFailure && typeof onFailure === 'function') { |
| | | this[`$${check}Failure`] = onFailure |
| | |
| | | if (!type) { |
| | | type = permission ? 'permission' : 'role' |
| | | } |
| | | return auth({check, type}, permission, role, permissions, roles) |
| | | return auth.apply(this, [{check, type}, permission, role, permissions, roles]) |
| | | } |
| | | } |
| | | }) |