Commit b8fde7aa by 姜雷

修改区域选择添加权限控制

parent c4da6c71
...@@ -8,7 +8,12 @@ export const fetchAreaList = req => ...@@ -8,7 +8,12 @@ export const fetchAreaList = req =>
method: 'get', method: 'get',
...req, ...req,
}); });
export const fetchAccessAreaList = req =>
fetch({
url: path + '/dcxy/baseArea/queryAll',
method: 'get',
...req,
});
//获取下拉列表 //获取下拉列表
export const fetchSelectList = req => export const fetchSelectList = req =>
fetch({ fetch({
......
...@@ -24,6 +24,11 @@ export default { ...@@ -24,6 +24,11 @@ export default {
value: Number, value: Number,
}, },
mixins: [areaMixin], mixins: [areaMixin],
computed: {
areaList() {
return this[`areaList${this.accessType}`];
},
},
methods: { methods: {
changeHandle(val) { changeHandle(val) {
if (val) { if (val) {
......
import { fetchAreaList } from '@/api/base/index'; import { fetchAreaList, fetchAccessAreaList } from '@/api/base/index';
import typeMapping from './typeMapping';
const GET_AREA_LIST = 'GET_AREA_LIST'; const GET_AREA_LIST = 'GET_AREA_LIST';
const FETCH_STATE = 'FETCH_STATE'; const FETCH_STATE = 'FETCH_STATE';
const FETCH_END = 'FETCH_END';
const state = () => ({ const state = () => {
list: [], let areaState = {};
fetching: false, typeMapping.map(type => {
}); areaState[`list${type.value}`] = [];
areaState[`fetching${type.value}`] = false;
});
return areaState;
};
const getters = { const initGetters = () => {
areaList: state => state.list, let getters = {};
typeMapping.map(type => {
getters[`areaList${type.value}`] = state => state[`list${type.value}`];
});
return getters;
}; };
const getters = initGetters();
const actions = { const initAction = () => {
fetchAreaList({ state, commit }) { let actions = {};
if (state.fetching) return; typeMapping.map(type => {
commit(FETCH_STATE, true); actions[`fetchAreaList${type.value}`] = ({ state, commit }) => {
return fetchAreaList().then(res => { if (state[`fetching${type.value}`]) return;
commit(FETCH_STATE, type.value);
let fetchHandle = null;
if (type.value == 0) {
fetchHandle = fetchAreaList;
} else {
fetchHandle = fetchAccessAreaList;
}
return fetchHandle().then(res => {
const list = res.data; const list = res.data;
commit(GET_AREA_LIST, list); commit(GET_AREA_LIST, { type: type.value, list });
commit(FETCH_STATE, false); commit(FETCH_END, type.value);
}); });
}, };
});
return actions;
}; };
const actions = initAction();
const mutations = { const mutations = {
[GET_AREA_LIST](state, list) { [GET_AREA_LIST](state, { type, list }) {
state.list = list; state[`list${type}`] = list;
},
[FETCH_STATE](state, type) {
state[`fetching${type}`] = true;
}, },
[FETCH_STATE](state, fetching) { [FETCH_END](state, type) {
state.fetching = fetching; state[`fetching${type}`] = false;
}, },
}; };
......
import { mapGetters, mapActions } from 'vuex'; import { mapGetters, mapActions } from 'vuex';
import store from './store'; import store from './store';
import typeMapping from './typeMapping';
const getterList = typeMapping.map(type => `areaList${type.value}`);
const actionsList = typeMapping.map(type => `fetchAreaList${type.value}`);
export default { export default {
props: {
accessType: {
type: Number,
default: 1, // 0 全部 1 权限
},
},
created() { created() {
store.install(this.$store); store.install(this.$store);
}, },
mounted() { mounted() {
if (!this.areaList.length) { if (
this.fetchAreaList(); this[`areaList${this.accessType}`] &&
!this[`areaList${this.accessType}`].length
) {
this[`fetchAreaList${this.accessType}`]();
} }
// if (!this.areaList.length) {
// this.fetchAreaList();
// }
}, },
computed: { computed: {
...mapGetters('area', ['areaList']), ...mapGetters('area', getterList),
}, },
methods: { methods: {
...mapActions('area', ['fetchAreaList']), ...mapActions('area', actionsList),
getAreaName(id) { getAreaName(id) {
let item = this.areaList.find(area => area.id === id); let item = this[`areaList${this.accessType}`].find(
area => area.id === id
);
if (item) { if (item) {
return item.areaName; return item.areaName;
} else { } else {
...@@ -24,7 +42,9 @@ export default { ...@@ -24,7 +42,9 @@ export default {
} }
}, },
getAreaOperatorInfo(id) { getAreaOperatorInfo(id) {
let item = this.areaList.find(area => area.id === id); let item = this[`areaList${this.accessType}`].find(
area => area.id === id
);
if (item) { if (item) {
return { return {
rechargeOperateId: item.rechargeOperateId, rechargeOperateId: item.rechargeOperateId,
......
const typeMapping = [{ value: 0, label: '全部' }, { value: 1, label: '权限' }];
export default typeMapping;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment