zhangxiaoxu123
2022-07-19 0b2877a4b4bf90bec9bd46b78beedf211263a028
'权限优化'
4个文件已修改
1个文件已添加
135 ■■■■■ 已修改文件
components/common/popup-menu/popup-menu.vue 61 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
main.js 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/jihua/jihua.vue 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/login/login.vue 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
store/index.js 69 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
components/common/popup-menu/popup-menu.vue
@@ -10,7 +10,8 @@
                   <image src="@/static/menuIcon/menu-home.png" slot="icon" size="32" name="search"/>
                </u-cell>
                <u-cell
                    v-if="shenqingMenu"
                    v-if="$store.state.shenqingMenu"
                    v-cloak
                    title="我的申请"
                    isLink
                    url="/pages/my-application/my-application"
@@ -32,7 +33,8 @@
                    <image src="@/static/menuIcon/menu-havedo.png" slot="icon" size="32" name="search"/>
                </u-cell>
                <u-cell
                   v-if="rijihuaMenu"
                   v-if="$store.state.rijihuaMenu"
                   v-cloak
                    title="日发运计划"
                    isLink
                    url="/pages/jihua/jihua" style="color:blue"
@@ -63,70 +65,19 @@
    // },
    data() {
        return {
            menuShow:false,
            rijihuaMenu:false,
            shenqingMenu:false,
            menuShow:false
        };
    },
    onShow() {
        alert(111)
    },
    methods: {
        checkRijihua(data) {
            let labelArry = []
            let newObj = data.filter(e => e.label == '地销计量')
            newObj && newObj.forEach(e => {
                if(e.children.length > 0) {
                    e.children.forEach(item => {
                        labelArry.push(item.label)
                    })
                }else{
                    this.rijihuaMenu = false
                }
            })
            if(labelArry.indexOf('汽车日发运计划管理') > -1) {
                this.rijihuaMenu = true
            }else {
                this.rijihuaMenu = false
            }
        },
        checkShenqing(data) {
            let labelArry = []
            let newObj = data.filter(e => e.label == '工作审批')
            newObj && newObj.forEach(e => {
                if(e.children.length > 0) {
                    e.children.forEach(item => {
                        labelArry.push(item.label)
                    })
                }else{
                    this.shenqingMenu = false
                }
            })
            if(labelArry.indexOf('我的申请') > -1) {
                this.shenqingMenu = true
            }else {
                this.shenqingMenu = false
            }
        },
        menu() {
            // 权限判断
            this.$reqGet('menu').then(res => {
                if(res.data == null) {
                    this.rijihuaMenu = false
                    this.shenqingMenu = false
                }else {
                    this.checkRijihua(res.data)
                    this.checkShenqing(res.data)
                }
            })
        },
        menuClick(){
            this.menuShow = !this.menuShow
            this.$emit('menuShow',this.menuShow)
        },
        open() {
            console.log('open');
            this.menu()
            console.log(this.$store.state,'shenqingMenu====')
        },
        close() {
            this.menuShow = false;
main.js
@@ -2,6 +2,7 @@
import Vue from 'vue'
import uView from '@/uni_modules/uview-ui';
import '@/api/constant.js';
import store from './store'
uni.$u.config.unit = 'rpx'
Vue.use(uView)
@@ -13,6 +14,7 @@
Vue.prototype.$reqGet = reqGet;
Vue.prototype.$reqPost = reqPost;
Vue.prototype.$store = store
Vue.config.productionTip = false
@@ -20,6 +22,7 @@
App.mpType = 'app'
const app = new Vue({
    store,
    ...App
})
app.$mount()
pages/jihua/jihua.vue
@@ -180,6 +180,7 @@
                    title: '正在加载...'
                });
                let compId = uni.getStorageSync('userInfo').compId
                let params = {
                    current: 1,
                    size: 100,
pages/login/login.vue
@@ -46,6 +46,7 @@
                    setTokenType(token_type);
                    setRefreshToken(refresh_token);
                    setScope(scope);
                    this.$store.dispatch('menus')
                    redirectHome();
                    uni.hideLoading();
                } catch (e) {
store/index.js
New file
@@ -0,0 +1,69 @@
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
// 请求相关
import { reqAll, reqGet, reqPost } from '../utils/index.js';
const store = new Vuex.Store({
    state: {
        shenqingMenu: uni.getStorageSync('shenqingMenu') || false,  //申请菜单
        rijihuaMenu: uni.getStorageSync('rijihuaMenu') || false, //日计划菜单
    },
    mutations: {
        ISHAS_SHENQING: (state, data) => {
            let labelArry = []
            let newObj = data.filter(e => e.label == '工作审批')
            newObj && newObj.forEach(e => {
                if(e.children.length > 0) {
                    e.children.forEach(item => {
                        labelArry.push(item.label)
                    })
                }else{
                    state.shenqingMenu = false
                    uni.setStorageSync('shenqingMenu',state.shenqingMenu)
                }
            })
            if(labelArry.indexOf('我的申请') > -1) {
                state.shenqingMenu = true
                uni.setStorageSync('shenqingMenu',state.shenqingMenu)
            }else {
                state.shenqingMenu = false
                uni.setStorageSync('shenqingMenu',state.shenqingMenu)
            }
        },
        ISHAS_RIJIHUA: (state, data) => {
            let labelArry = []
            let newObj = data.filter(e => e.label == '地销计量')
            newObj && newObj.forEach(e => {
                if(e.children.length > 0) {
                    e.children.forEach(item => {
                        labelArry.push(item.label)
                    })
                }else{
                    state.rijihuaMenu = false
                    uni.setStorageSync('rijihuaMenu',state.rijihuaMenu)
                }
            })
            if(labelArry.indexOf('汽车日发运计划管理') > -1) {
                state.rijihuaMenu = true
                uni.setStorageSync('rijihuaMenu',state.rijihuaMenu)
            }else {
                state.rijihuaMenu = false
                uni.setStorageSync('rijihuaMenu',state.rijihuaMenu)
            }
        }
    },
    actions: {
        menus({commit}) {
            reqGet('menu').then(response => {
                console.log(response,'response=====response----')
                commit('ISHAS_SHENQING',response.data)
                commit('ISHAS_RIJIHUA',response.data)
            })
        }
    }
})
export default store