1
0
mirror of https://github.com/PanJiaChen/vue-element-admin.git synced 2025-08-10 20:39:48 +08:00

Add support to set warehouse and organization for current role (#455)

This commit is contained in:
Yamel Senih 2020-04-22 03:08:09 -04:00 committed by GitHub
parent b6450dc406
commit a52d2ee0de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 285 additions and 65 deletions

View File

@ -45,8 +45,8 @@
},
"dependencies": {
"@adempiere/grpc-access-client": "^1.1.8",
"@adempiere/grpc-data-client": "^2.2.1",
"@adempiere/grpc-pos-client": "^1.0.3",
"@adempiere/grpc-data-client": "^2.2.3",
"@adempiere/grpc-pos-client": "^1.0.4",
"@adempiere/grpc-dictionary-client": "^1.3.9",
"@adempiere/grpc-enrollment-client": "^1.0.7",
"autoprefixer": "^9.5.1",

View File

@ -1,15 +1,17 @@
import { getLanguage } from '@/lang/index'
import { getToken } from '@/utils/auth'
import { getToken, getCurrentOrganization, getCurrentWarehouse } from '@/utils/auth'
import BusinessData from '@adempiere/grpc-data-client'
import { BUSINESS_DATA_ADDRESS } from '@/api/ADempiere/constants'
// Get Instance for connection
function Instance() {
return new BusinessData(
BUSINESS_DATA_ADDRESS,
getToken(),
getLanguage() || 'en_US'
)
return new BusinessData({
host: BUSINESS_DATA_ADDRESS,
sessionUuid: getToken(),
organizationUuid: getCurrentOrganization(),
warehouseUuid: getCurrentWarehouse(),
language: getLanguage() || 'en_US'
})
}
/**
@ -91,6 +93,36 @@ export function getEntitiesList({
})
}
// Get Organization list from role
export function getOrganizationsList({
roleUuid,
roleId,
pageToken,
pageSize
}) {
return Instance.call(this).requestListOrganizations({
roleUuid,
roleId,
pageToken,
pageSize
})
}
// Get Warehouses of Organization
export function getWarehousesList({
organizationUuid,
organizationId,
pageToken,
pageSize
}) {
return Instance.call(this).requestListWarehouses({
organizationUuid,
organizationId,
pageToken,
pageSize
})
}
/**
* Get all operator or get key value type from value
* @param {number} keyToFind

View File

@ -3,7 +3,7 @@
<transition name="sidebarLogoFade">
<router-link v-if="collapse" key="collapse" class="sidebar-logo-link sidebar-logo-link-close" to="/">
<el-tooltip placement="right">
<div slot="content">{{ getRol.name }} | {{ getRol.clientName }}</div>
<div slot="content">{{ getRole.name }} | {{ getRole.clientName }}</div>
<img v-if="logo" :src="logo" class="sidebar-logo">
<h1 v-else class="sidebar-title">{{ title }} </h1>
</el-tooltip>
@ -12,9 +12,9 @@
<img v-if="logo" :src="logo" class="sidebar-logo" @click="dashboard()">
<h1 class="sidebar-title" @click="dashboard()">{{ title }}</h1><br>
<el-tooltip placement="right">
<div slot="content">{{ getRol.name }} | {{ getRol.clientName }}</div>
<div slot="content">{{ getRole.name }} | {{ getRole.clientName }}</div>
<p class="sidebar-sub-title" @click="profile()">
{{ getRol.name }} | {{ getRol.clientName }}
{{ getRole.name }} | {{ getRole.clientName }}
</p>
</el-tooltip>
</div>
@ -40,8 +40,8 @@ export default {
}
},
computed: {
getRol() {
return this.$store.getters['user/getRol']
getRole() {
return this.$store.getters['user/getRole']
}
},
methods: {

View File

@ -12,7 +12,7 @@ const getters = {
router: state => state.permission.addRoutes,
introduction: state => state.user.introduction,
currentRole: state => state.user.currentRole,
getRoleUuid: state => state.user.rol.uuid,
getRoleUuid: state => state.user.role.uuid,
roles: state => state.user.roles,
permission_routes: state => state.permission.routes,
errorLogs: state => state.errorLog.logs

View File

@ -1,5 +1,19 @@
import { login, logout, requestUserInfoFromSession, getSessionInfo, changeRole } from '@/api/user'
import { getToken, setToken, removeToken, getCurrentRole, setCurrentRole, removeCurrentRole } from '@/utils/auth'
import {
getToken,
setToken,
removeToken,
getCurrentRole,
setCurrentRole,
removeCurrentRole,
getCurrentOrganization,
setCurrentOrganization,
getCurrentWarehouse,
setCurrentWarehouse,
removeCurrentWarehouse,
removeCurrentOrganization
} from '@/utils/auth'
import { getOrganizationsList, getWarehousesList } from '@/api/ADempiere/data'
import router, { resetRouter } from '@/router'
import { showMessage } from '@/utils/ADempiere/notification'
import { isEmptyValue } from '@/utils/ADempiere/valueUtils'
@ -11,9 +25,13 @@ const state = {
userUuid: '',
avatar: '',
introduction: '',
rol: {}, // info current rol
role: {}, // info current role
rolesList: [],
roles: [],
organizationsList: [],
organization: {},
warehousesList: [],
warehouse: {},
isSession: false,
sessionInfo: {}
}
@ -37,8 +55,20 @@ const mutations = {
SET_ROLES_LIST: (state, payload) => {
state.rolesList = payload
},
SET_ROL: (state, rol) => {
state.rol = rol
SET_ORGANIZATIONS_LIST: (state, payload) => {
state.organizationsList = payload
},
SET_ORGANIZATION: (state, organization) => {
state.organization = organization
},
SET_WAREHOUSES_LIST: (state, payload) => {
state.warehousesList = payload
},
SET_WAREHOUSE: (state, warehouse) => {
state.warehouse = warehouse
},
SET_ROLE: (state, role) => {
state.role = role
},
SET_USER_UUID: (state, payload) => {
state.userUuid = payload
@ -110,9 +140,47 @@ const actions = {
defaultContext: responseGetInfo.defaultContextMap
}
commit('SET_ROL', role)
commit('SET_ROLE', role)
setCurrentRole(role.uuid)
getOrganizationsList({ roleUuid: role.uuid })
.then(response => {
commit('SET_ORGANIZATIONS_LIST', response.organizationsList)
let organization = response.organizationsList.find(item => item.uuid === getCurrentOrganization())
if (isEmptyValue(organization)) {
organization = response.organizationsList[0]
}
if (isEmptyValue(organization)) {
removeCurrentOrganization()
commit('SET_ORGANIZATION', undefined)
} else {
setCurrentOrganization(organization.uuid)
commit('SET_ORGANIZATION', organization)
}
getWarehousesList({ organizationUuid: getCurrentOrganization() })
.then(response => {
commit('SET_WAREHOUSES_LIST', response.warehousesList)
let warehouse = response.warehousesList.find(item => item.uuid === getCurrentWarehouse())
if (isEmptyValue(warehouse)) {
warehouse = response.warehousesList[0]
}
if (isEmptyValue(warehouse)) {
removeCurrentWarehouse()
commit('SET_WAREHOUSE', undefined)
} else {
setCurrentWarehouse(warehouse.uuid)
commit('SET_WAREHOUSE', warehouse)
}
})
.catch(error => {
console.warn(`Error ${error.code} getting user info value: ${error.message}.`)
reject(error)
})
})
.catch(error => {
console.warn(`Error ${error.code} getting user info value: ${error.message}.`)
reject(error)
})
//
resolve(sessionResponse)
dispatch('getUserInfoFromSession', sessionUuid)
@ -155,12 +223,12 @@ const actions = {
})
commit('SET_ROLES', rolesName)
if (isEmptyValue(state.rol)) {
if (isEmptyValue(state.role)) {
const role = responseGetInfo.rolesList.find(itemRole => {
return itemRole.uuid === getCurrentRole()
})
if (!isEmptyValue(role)) {
commit('SET_ROL', role)
commit('SET_ROLE', role)
}
}
@ -211,9 +279,40 @@ const actions = {
resolve()
})
},
changeOrganization({ commit, dispatch }, {
organizationUuid
}) {
setCurrentOrganization(organizationUuid)
getWarehousesList({ organizationUuid: organizationUuid })
.then(response => {
commit('SET_WAREHOUSES_LIST', response.warehousesList)
let warehouse = response.warehousesList.find(item => item.uuid === getCurrentWarehouse())
if (isEmptyValue(warehouse)) {
warehouse = response.warehousesList[0]
}
if (isEmptyValue(warehouse)) {
removeCurrentWarehouse()
commit('SET_WAREHOUSE', undefined)
} else {
setCurrentWarehouse(warehouse.uuid)
commit('SET_WAREHOUSE', warehouse)
}
})
.catch(error => {
console.warn(`Error ${error.code} getting user info value: ${error.message}.`)
})
},
changeWarehouse({ commit, state }, {
warehouseUuid
}) {
setCurrentWarehouse(warehouseUuid)
commit('SET_WAREHOUSE', state.warehousesList.find(warehouse => warehouse.uuid === warehouseUuid))
},
// dynamically modify permissions
changeRoles({ commit, dispatch }, {
changeRole({ commit, dispatch }, {
roleUuid,
organizationUuid,
warehouseUuid,
isCloseAllViews = true
}) {
const route = router.app._route
@ -238,12 +337,12 @@ const actions = {
return changeRole({
sessionUuid: getToken(),
roleUuid,
organizationUuid: null,
warehouseUuid: null
organizationUuid,
warehouseUuid
})
.then(changeRoleResponse => {
const { role } = changeRoleResponse
commit('SET_ROL', role)
commit('SET_ROLE', role)
setCurrentRole(role.uuid)
commit('SET_TOKEN', changeRoleResponse.uuid)
setToken(changeRoleResponse.uuid)
@ -303,9 +402,21 @@ const getters = {
getRoles: (state) => {
return state.rolesList
},
// current rol info
getRol: (state) => {
return state.rol
getOrganizations: (state) => {
return state.organizationsList
},
getWarehouses: (state) => {
return state.warehousesList
},
// current role info
getRole: (state) => {
return state.role
},
getOrganization: (state) => {
return state.organization
},
getWarehouse: (state) => {
return state.warehouse
},
getIsSession: (state) => {
return state.isSession
@ -314,7 +425,7 @@ const getters = {
return state.userUuid
},
getIsPersonalLock: (state) => {
return state.rol.isPersonalLock
return state.role.isPersonalLock
}
}

View File

@ -1,6 +1,8 @@
import Cookies from 'js-cookie'
const roleKey = 'roleUuid'
const organizationKey = 'organizationUuid'
const warehouseKey = 'warehouseUuid'
export function setCurrentRole(currentRole) {
return Cookies.set(roleKey, currentRole)
@ -10,6 +12,30 @@ export function getCurrentRole() {
return Cookies.get(roleKey)
}
export function setCurrentOrganization(currentOrganization) {
return Cookies.set(organizationKey, currentOrganization)
}
export function getCurrentOrganization() {
return Cookies.get(organizationKey)
}
export function removeCurrentOrganization() {
return Cookies.remove(organizationKey)
}
export function setCurrentWarehouse(currentWarehouse) {
return Cookies.set(warehouseKey, currentWarehouse)
}
export function getCurrentWarehouse() {
return Cookies.get(warehouseKey)
}
export function removeCurrentWarehouse() {
return Cookies.remove(warehouseKey)
}
export function removeCurrentRole() {
return Cookies.remove(roleKey)
}

View File

@ -22,7 +22,7 @@ export default {
return this.roles[0]
},
set(val) {
this.$store.dispatch('user/changeRoles', val).then(() => {
this.$store.dispatch('user/changeRole', val).then(() => {
this.$emit('change')
})
}

View File

@ -3,7 +3,7 @@
<router-link to="/profile/index">
<img v-if="logo" :src="logo" class="sidebar-logo">
<p style="float: right;max-width: 150px;text-overflow: ellipsis;white-space: nowrap;overflow: hidden;">
{{ getRol.clientName }}
{{ getRole.clientName }}
</p>
</router-link>
<roles-navbar />
@ -33,8 +33,8 @@ export default {
}
},
computed: {
getRol() {
return this.$store.getters['user/getRol']
getRole() {
return this.$store.getters['user/getRole']
},
getRoles() {
return this.$store.getters['user/getRoles']

View File

@ -1,17 +1,45 @@
<template>
<el-form>
<el-select
v-model="value"
v-model="roleUuid"
:filterable="!isMobile"
value-key="key"
@change="handleChange"
@change="changeRole"
>
<el-option
v-for="(rol, key) in getRolesList"
v-for="(role, key) in getRolesList"
:key="key"
:label="rol.name"
:value="rol.uuid"
:disabled="isEmptyValue(rol.uuid)"
:label="role.name"
:value="role.uuid"
:disabled="isEmptyValue(role.uuid)"
/>
</el-select>
<el-select
v-model="organizationUuid"
:filterable="!isMobile"
value-key="key"
@change="changeOrganization"
>
<el-option
v-for="(organization, key) in getOrganizationsList"
:key="key"
:label="organization.name"
:value="organization.uuid"
:disabled="isEmptyValue(organization.uuid)"
/>
</el-select>
<el-select
v-model="warehouseUuid"
:filterable="!isMobile"
value-key="key"
@change="changeWarehouse"
>
<el-option
v-for="(warehouse, key) in getWarehousesList"
:key="key"
:label="warehouse.name"
:value="warehouse.uuid"
:disabled="isEmptyValue(warehouse.uuid)"
/>
</el-select>
</el-form>
@ -24,17 +52,30 @@ export default {
name: 'RolesNavbar',
data() {
return {
value: '',
options: []
roleUuid: '',
organizationUuid: '',
warehouseUuid: ''
}
},
computed: {
getRol() {
return this.$store.getters['user/getRol']
getRole() {
return this.$store.getters['user/getRole']
},
getOrganization() {
return this.$store.getters['user/getOrganization']
},
getWarehouse() {
return this.$store.getters['user/getWarehouse']
},
getRolesList() {
return this.$store.getters['user/getRoles']
},
getOrganizationsList() {
return this.$store.getters['user/getOrganizations']
},
getWarehousesList() {
return this.$store.getters['user/getWarehouses']
},
isMobile() {
return this.$store.state.app.device === 'mobile'
},
@ -42,30 +83,40 @@ export default {
return this.$store.getters.permission_routes
}
},
watch: {
'getRol.uuid'(uuidRol) {
this.value = uuidRol
}
},
created() {
this.value = this.getRol.uuid
this.roleUuid = this.getRole.uuid
this.organizationUuid = this.getOrganization.uuid
this.warehouseUuid = this.getWarehouse.uuid
this.getLanguageData()
},
methods: {
showMessage,
handleChange(valueSelected) {
changeRole(roleUuid) {
this.$message({
message: this.$t('notifications.loading'),
iconClass: 'el-icon-loading'
})
this.$store.dispatch('user/changeRoles', {
roleUuid: valueSelected
this.$store.dispatch('user/changeRole', {
roleUuid,
organizationUuid: this.organizationUuid,
warehouseUuid: this.warehouseUuid
})
.then(response => {
this.$store.dispatch('listDashboard', response.uuid)
})
this.$router.push({ path: '/' })
},
changeOrganization(organizationUuid) {
this.$store.dispatch('user/changeOrganization', {
organizationUuid
})
this.warehouseUuid = this.getWarehouse
},
changeWarehouse(warehouseUuid) {
this.$store.dispatch('user/changeWarehouse', {
warehouseUuid
})
},
getLanguageData() {
this.$store.dispatch('getLanguagesFromServer')
}

View File

@ -8,11 +8,11 @@
<div class="box-center">
<pan-thumb :image="user.avatar" :height="'100px'" :width="'100px'" :hoverable="false">
<div>Hello</div>
{{ getRol.name }}
{{ getRole.name }}
</pan-thumb>
</div>
<div class="box-center">
<div class="user-name text-center">{{ getRol.name }}</div>
<div class="user-name text-center">{{ getRole.name }}</div>
<div class="user-role text-muted">
{{ $t('profile.availableRoles') }}
<li v-for="(item, key) in getRoles" :key="key">
@ -76,8 +76,8 @@ export default {
}
},
computed: {
getRol() {
return this.$store.getters['user/getRol']
getRole() {
return this.$store.getters['user/getRole']
},
getRoles() {
return this.$store.getters['user/getRoles']

View File

@ -1,15 +1,15 @@
<template>
<el-form>
<el-form-item :label="$t('profile.currentRole')">
{{ getRol.name }}
{{ getRole.name }}
</el-form-item>
<el-form-item :label="$t('profile.clientName')">
{{ getRol.clientName }}
{{ getRole.clientName }}
</el-form-item>
<el-form-item :label="$t('profile.description')">
{{ getRol.description }}
{{ getRole.description }}
</el-form-item>
<el-form-item :label="$t('profile.changeRole')">
@ -62,8 +62,8 @@ export default {
}
},
computed: {
getRol() {
return this.$store.getters['user/getRol']
getRole() {
return this.$store.getters['user/getRole']
},
getRolesList() {
return this.$store.getters['user/getRoles']
@ -79,12 +79,12 @@ export default {
}
},
watch: {
'getRol.uuid'(uuidRol) {
'getRole.uuid'(uuidRol) {
this.valueRol = uuidRol
}
},
created() {
this.valueRol = this.getRol.uuid
this.valueRol = this.getRole.uuid
this.getLanguageData()
},
methods: {
@ -94,7 +94,7 @@ export default {
message: this.$t('notifications.loading'),
iconClass: 'el-icon-loading'
})
this.$store.dispatch('user/changeRoles', {
this.$store.dispatch('user/changeRole', {
roleUuid: valueSelected,
isCloseAllViews: false
})