瀏覽代碼

入口权限逻辑优化

xiaohaizhao 2 年之前
父節點
當前提交
89fdac6b48
共有 2 個文件被更改,包括 166 次插入237 次删除
  1. 164 218
      pages/tabbar/home/index.js
  2. 2 19
      pages/tabbar/home/index.wxml

+ 164 - 218
pages/tabbar/home/index.js

@@ -1,248 +1,148 @@
 const _Http = getApp().globalData.http;
-let DataCarousel = null;
+let DataCarousel = null,
+    funs = {};
+
 Page({
     data: {
-        bannerList: [], //banner列表
-        user: {},
-        annunciateList: [], //通告列表
-        gridList: [],
-        unreadNum: 0, //通告未读
-        notice: "",
         msgCount: 1,
         subassembly: [], //首页部件
         msgList: [], //消息列表
+        capsule: wx.getMenuButtonBoundingClientRect(), //胶囊位置信息
     },
     onLoad(options) {
         this.refreshData() //更新权限等信息
-        this.setData({ //获取胶囊位置信息
-            capsule: wx.getMenuButtonBoundingClientRect()
-        })
     },
     /* 更新站点信息 */
     refreshData() {
         this.setData({
             user: wx.getStorageSync('userMsg')
         })
-        /* 首页宫格授权查询 */
         if (wx.getStorageSync('userauth').length != 0) {
-            let auth = getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ['营销工具'], ['通告', '推广素材', '商学院', '提报', '销售线索', '营销物料', '销售预测', '销售目标']),
-                gridList = [],
-                subassembly = [];
-            auth.forEach(v => {
-                switch (v.systemmodulename) {
-                    case "通告":
-                        gridList.push({
-                            name: "通告",
-                            path: "/pages/annunciate/index",
-                            icon: "icon-a-shouyejingangqutonggao",
-                            apps: v.apps
-                        });
-                        if (v.apps[0].meta.wedgits.some(value => value.wedgit == 'homenoticelist')) subassembly.push('homenoticelist');
-                        this.setData({
-                            annunciateAuthList: v.apps[0].meta.auth.map(v => v.optionname)
+            let authList = {},
+                gridList = [];
+            const apps = getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ['营销工具'], ['通告', '推广素材', '商学院', '提报', '销售线索', '营销物料']),
+                paths = [{
+                    label: "通告",
+                    name: "wnotice",
+                    path: "/pages/annunciate/index",
+                    icon: "icon-a-shouyejingangqutonggao"
+                }, {
+                    label: "商学院",
+                    name: "warchives_sc",
+                    path: "/pages/classroom/index",
+                    icon: "icon-a-shangxueyuanxuexi"
+                }, {
+                    label: "营销物料",
+                    name: "warchives",
+                    path: "/pages/tabbar/smartStore/index",
+                    icon: "icon-a-shouyejingangquyingxiaowuliao"
+                }, {
+                    label: "销售线索",
+                    name: "worderclue",
+                    path: "/pages/threadedTree/index",
+                    icon: "icon-xiaoshouxiansuo"
+                }, {
+                    label: "推广素材",
+                    name: "wpopularize",
+                    path: "/pages/promotional/index",
+                    icon: "icon-a-shouyejingangqutuiguangsucai"
+                }, {
+                    label: "提报",
+                    name: "wsubmitedit",
+                    path: "/pages/submission/index",
+                    icon: "icon-a-tibaoguanlitibao"
+                }];
+            apps.forEach(v => {
+                v.apps.forEach(s => {
+                    authList[s.name] = {
+                        options: s.meta.auth.map(a => a.option),
+                        optionnames: s.meta.auth.map(a => a.optionname),
+                    }
+                    if (authList[s.name].options.some(s => s == "read")) {
+                        if (s.name == "worderclue") {
+                            //更新销售线索徽标数据
+                            funs.getCount = () => {
+                                const index = this.data.gridList.findIndex(v => v.label == '销售线索');
+                                if (index == -1) return;
+                                _Http.basic({
+                                    "classname": "saletool.orderclue.web.orderclue",
+                                    "method": "getCount",
+                                    "content": {
+                                        "nocache": true,
+                                        "status": "待跟进"
+                                    }
+                                }, false).then(res => {
+                                    if (res.data.count == 0) res.data.count = '';
+                                    if (res.data.count > 99) res.data.count = '99+';
+                                    try {
+                                        this.data.gridList[index].count = res.data.count;
+                                    } catch (e) {}
+                                    this.setData({
+                                        gridList: this.data.gridList
+                                    })
+                                })
+                            };
+                        } else if (s.name == "wnotice" && s.meta.wedgits.find(a => a.wedgit == 'homenoticelist')) {
+                            //更新通告数据
+                            funs.queryNoticeList = () => {
+                                _Http.basic({
+                                    "classname": "saletool.notice.notice",
+                                    "method": "queryNoticeList",
+                                    "content": {
+                                        "nocache": true,
+                                        "pageNumber": 1,
+                                        "pageSize": 3
+                                    }
+                                }, false).then(res => {
+                                    if (res.msg != '成功') return;
+                                    this.setData({
+                                        annunciateList: res.data,
+                                        unreadNum: res.total - res.tips.readNum
+                                    })
+                                });
+                            };
+                        }
+                        let data = paths.find(k => {
+                            return k.name == s.name
                         });
-                        break;
-                    case "推广素材":
-                        gridList.push({
-                            name: "推广素材",
-                            path: "/pages/promotional/index",
-                            icon: "icon-a-shouyejingangqutuiguangsucai",
-                            apps: v.apps
-                        })
-                        break;
-                    case "商学院":
-                        gridList.push({
-                            name: "商学院",
-                            path: "/pages/classroom/index",
-                            icon: "icon-a-shangxueyuanxuexi",
-                            apps: v.apps
-                        })
-                        break;
-                    case "提报":
-                        gridList.push({
-                            name: "提报",
-                            path: "/pages/submission/index",
-                            icon: "icon-a-tibaoguanlitibao",
-                            apps: v.apps
-                        })
-                        break;
-                    case "营销物料":
-                        gridList.push({
-                            name: "营销物料",
-                            path: "/pages/tabbar/smartStore/index",
-                            icon: "icon-a-shouyejingangquyingxiaowuliao",
-                            apps: v.apps
-                        })
-                        break;
-                    case "销售线索":
-                        gridList.push({
-                            name: "销售线索",
-                            path: "/pages/threadedTree/index",
-                            icon: "icon-xiaoshouxiansuo",
-                            apps: v.apps
-                        })
-                        //获取销售线索待办数量
-                        setTimeout(this.getCount, 100);
-                        break;
-                    case "销售预测":
-                        gridList.push({
-                            name: "销售预测",
-                            path: "/packageA/forecast/index",
-                            icon: "icon-xiaochengxu_xiaoshouyuce",
-                            apps: v.apps
-                        })
-                        break;
-                    case "销售目标":
-                        gridList.push({
-                            name: "销售目标",
-                            path: "/packageA/target/index",
-                            icon: "icon-xiaochengxu_xiaoshoumubiao",
-                            apps: v.apps
-                        })
-                        break;
-                };
-            });
-            /* 首页小组件查询 */
-            try {
-                let home = getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ['通用'], ['首页'])[0].apps[0].meta.wedgits;
-                if (home.some(v => v.wedgit == 'homedatadisplay')) subassembly.push('homedatadisplay');
-            } catch (e) {
-                this.setData({
-                    gridList,
-                    subassembly: []
+                        if (data) {
+                            data.isneedpay = s.isneedpay;
+                            gridList.push(data)
+                        }
+                    }
                 })
-            }
+            });
             this.setData({
-                gridList,
-                subassembly
-            })
+                gridList
+            });
+            for (const key in funs) {
+                funs[key]()
+            };
+            /* 获取首页banner */
+            let banner = wx.getStorageSync('banner_list').find(v => v.location == "index_top");
+            if (banner) this.setData({
+                bannerList: banner.ads
+            });
+            wx.setStorageSync('authList', authList)
         } else {
             setTimeout(this.refreshData, 10);
-            return;
         }
-        /* 获取首页banner */
-        let banner = wx.getStorageSync('banner_list').find(v => v.location == "index_top");
-        if (banner) this.setData({
-            bannerList: banner.ads
-        })
-        this.queryNoticeList(0); //获取通告列表
-    },
-    /* 销售线索待办 */
-    getCount() {
-        const index = this.data.gridList.findIndex(v => v.name == '销售线索');
-        if (index == -1) return;
-        _Http.basic({
-            "classname": "saletool.orderclue.web.orderclue",
-            "method": "getCount",
-            "content": {
-                "nocache": true,
-                "status": "待跟进"
-            }
-        }, false).then(res => {
-            if (res.data.count == 0) res.data.count = '';
-            if (res.data.count > 99) res.data.count = '99+';
-            try {
-                this.data.gridList[index].count = res.data.count;
-            } catch (e) {
-
-            }
-            this.setData({
-                gridList: this.data.gridList
-            })
-        })
-    },
-    /* 查看通告详情 */
-    toAnnunciateDetails(e) {
-        const {
-            item
-        } = e.currentTarget.dataset;
-        let authList = this.data.annunciateAuthList;
-        wx.navigateTo({
-            url: `/pages/annunciate/details?id=${item.sat_noticeid}&auth=${authList}`,
-        })
-    },
-    /* 获取通告列表 */
-    queryNoticeList(i) {
-        if (i == 5) return;
-        let obj = this.data.gridList.find(v => v.name == '通告');
-        if (!obj || obj.apps.length == 0) return;
-        _Http.basic({
-            "classname": "saletool.notice.notice",
-            "method": "queryNoticeList",
-            "content": {
-                "nocache": true,
-                "pageNumber": 1,
-                "pageSize": 3
-            }
-        }, false).then(res => {
-            if (res.msg != '成功') return this.queryNoticeList(i + 1);
-            this.setData({
-                annunciateList: res.data,
-                unreadNum: res.total - res.tips.readNum
-            })
-        });
-    },
-    /* 获取最新信息 */
-    queryMessage(i = 0) {
-        _Http.basic({
-            "classname": "system.message.Message",
-            "method": "queryMessage",
-            content: {
-                nocache: true,
-                pageNumber: 1,
-                pageSize: 5,
-                pageTotal: 1,
-                type: "",
-                where: {}
-            },
-        }, false).then(res => {
-            if (res.msg != '成功') return (i <= 5) ? this.queryMessage(i + 1) : wx.showToast({
-                title: res.msg,
-                icon: "none"
-            })
-            this.setData({
-                msgList: res.data,
-                notice: res.data[0]
-            })
-            if (this.data.msgList.length > 2) this.startDataCarousel();
-        })
-    },
-    /* 开启消息轮播 */
-    startDataCarousel() {
-        clearInterval(DataCarousel);
-        DataCarousel = setInterval(() => {
-            let count = this.data.msgCount < this.data.msgList.length ? this.data.msgCount : 0;
-            this.setData({
-                msgCount: count + 1,
-                notice: this.data.msgList[count]
-            })
-        }, 5000)
     },
     /* 宫格区域应用程序 */
     applications(e) {
         const {
             item
         } = e.currentTarget.dataset,
-            that = this, userType = wx.getStorageSync('userMsg').usertype,
+            userType = wx.getStorageSync('userMsg').usertype,
             isLeader = userType == 21 || userType == 22;
         console.log("跳转", item)
-        if (item.name == "营销物料") {
-            wx.switchTab({
-                url
-            });
-        } else {
-            wx.navigateTo({
-                url:item.path
-            });
-        }
-        return
         //应用是否开通,开通直接跳转
-        if (!item.apps[0].isneedpay) {
+        if (!item.isneedpay) {
             wx.showModal({
                 title: '提示',
                 content: `当前模块未付费,是否付费使用?`,
                 confirmText: "前往付费",
-                cancelColor: isLeader ? "取消" : "提醒付费",
+                cancelText: isLeader ? "取消" : "提醒付费",
                 complete: (res) => {
                     if (res.confirm) {
                         _Http.basic({
@@ -262,13 +162,31 @@ Page({
                         })
                     }
                     if (res.cancel) {
-                        if (!isLeader) console.log("提醒付费")
+                        if (!isLeader) _Http.basic({
+                            "classname": "system.payorder.payorder",
+                            "method": "sendMessage",
+                            "content": {
+                                "sys_payorderid": ""
+                            }
+                        }).then(s => {
+                            wx.showToast({
+                                title: '已发送消息到主体主账号',
+                                icon: "none"
+                            })
+                        })
                     }
                 }
             })
         } else {
-            const url = `${item.path}?auth=${JSON.stringify(item.apps)}`
-
+            if (item.label == "营销物料") {
+                wx.switchTab({
+                    url: item.path
+                });
+            } else {
+                wx.navigateTo({
+                    url: item.path
+                });
+            }
         }
     },
     /* 去消息详情 */
@@ -302,13 +220,41 @@ Page({
     },
     onShow() {
         this.getTabBar().init();
-        if (this.data.msgList.length > 2) this.startDataCarousel();
-        this.getCount(); //更新徽标数据
-        this.queryMessage(0); //更新最新消息
-        this.queryNoticeList(0); //获取通告列表
+        for (const key in funs) {
+            funs[key]()
+        }
+        /* 获取最新信息 */
+        _Http.basic({
+            "classname": "system.message.Message",
+            "method": "queryMessage",
+            content: {
+                nocache: true,
+                pageSize: 5,
+                type: "",
+                where: {}
+            },
+        }, false).then(res => {
+            if (res.msg != '成功') return wx.showToast({
+                title: res.msg,
+                icon: "none"
+            })
+            this.setData({
+                msgList: res.data,
+                notice: res.data[0]
+            })
+            if (this.data.msgList.length > 2) {
+                clearInterval(DataCarousel);
+                DataCarousel = setInterval(() => {
+                    let count = this.data.msgCount < this.data.msgList.length ? this.data.msgCount : 0;
+                    this.setData({
+                        msgCount: count + 1,
+                        notice: this.data.msgList[count]
+                    })
+                }, 5000)
+            }
+        });
     },
     onHide() {
         clearInterval(DataCarousel);
     },
-    onShareAppMessage() {}
 })

+ 2 - 19
pages/tabbar/home/index.wxml

@@ -30,27 +30,10 @@
 <My_card custom-class='grld'>
     <navigator url="#" class="item" wx:for="{{gridList}}" wx:key="index" data-item="{{item}}" catchtap="applications">
         <view class="iconfont {{item.icon}}" />
-        <text>{{item.name}}</text>
+        <text>{{item.label}}</text>
         <view wx:if="{{item.count}}" class="badge">{{item.count}}</view>
     </navigator>
 </My_card>
-<!-- 数据概况 
-<block wx:if="{{per.query(subassembly,'homedatadisplay')}}">
-    <view class="general-situation">
-        <view class="title">
-            <text class="iconfont icon-a-shouyeshujugaikuangzhanshishuju"></text>
-            数据概况
-        </view>
-        <view class="time">更新于:2022-02-12</view>
-    </view>
-    <My_card custom-class='data-display' hover>
-        <view class="item" wx:for="{{6}}" wx:key="index">
-            <view class="label">销售额(¥)</view>
-            <view class="nubmer">9999.99</view>
-        </view>
-    </My_card>
-</block>
--->
 <!-- 通告 -->
 <My_card wx:if="{{annunciateList.length>0 && per.query(subassembly,'homenoticelist')}}" title='最新通告' class="annunciate">
     <view class="unread" slot='title-r' bindtap="toAnnunciate">
@@ -62,7 +45,7 @@
         <van-icon class="icon" name="arrow" />
     </view>
     <block wx:for="{{annunciateList}}" wx:key="index">
-        <navigator url="#" class="item-box" data-item="{{item}}" bindtap="toAnnunciateDetails">
+        <navigator url="/pages/annunciate/details?id={{item.sat_noticeid}}" class="item-box">
             <Item item='{{item}}' />
         </navigator>
         <view wx:if="{{index!=annunciateList.length-1}}" style="width: 100%; border-top: 1rpx solid #EEEEEE; margin-left: 30rpx;" />