Przeglądaj źródła

fix: 5513 移动端菜单权限配置不生效 来源Bug-6923

johnsen 4 miesięcy temu
rodzic
commit
0eead9b2d7
1 zmienionych plików z 155 dodań i 74 usunięć
  1. 155 74
      src/views/system/dashboard/index.vue

+ 155 - 74
src/views/system/dashboard/index.vue

@@ -6,10 +6,10 @@
     /> -->
 
     <!--幻灯片-->
-    <div class="dashboard-swipe ">
+    <div class="dashboard-swipe">
       <img
         v-lazy="swipes[3].image || blankImage"
-        style="width:100%;height:170px"
+        style="width: 100%; height: 170px"
       />
       <!-- <van-swipe :autoplay="11000">
         <van-swipe-item v-for="(swipe, index) in swipes" :key="index">
@@ -20,19 +20,19 @@
 
     <!--通知-->
     <template v-if="noticeList && noticeList.length > 0">
-      <div class="dashboard-notice" style="height: 52px;background: #F3F3F3;">
+      <div class="dashboard-notice" style="height: 52px; background: #f3f3f3">
         <van-swipe
           :autoplay="6000"
           :height="44"
           :show-indicators="false"
           :initial-swipe="initialNotice()"
-          style="height:44px;"
+          style="height: 44px"
           vertical
         >
           <van-swipe-item v-for="(notice, index) in noticeList" :key="index">
             <van-notice-bar
               background="#ffffff"
-              style="height:44px;"
+              style="height: 44px"
               color="#979797"
               mode="link"
               @click="onNotice(notice)"
@@ -95,9 +95,8 @@
               :text="getText(menu)"
               @click.native="onClick(menu)"
             >
-
-            <!-- 过滤原因暂时隐藏总数 -->
-            <!-- <van-grid-item
+              <!-- 过滤原因暂时隐藏总数 -->
+              <!-- <van-grid-item
               v-for="menu in dashboard[childrenKey]"
               :key="menu[aliasKey]"
               :text="getText(menu)"
@@ -151,7 +150,7 @@
       :id="noticeId"
       :visible="noticeVisible"
       readonly
-      @close="visible => (noticeVisible = visible)"
+      @close="(visible) => (noticeVisible = visible)"
     />
   </div>
 </template>
@@ -163,19 +162,18 @@ import ActionUtils from '@/utils/action'
 // import navbar from '@/mixins/navbar'
 import { Lazyload } from 'vant'
 Vue.use(Lazyload)
-import TreeUtils from '@/utils/tree'
+// import TreeUtils from '@/utils/tree'
 import i18n from '@/utils/i18n' // Internationalization 国际化
 import IbpsAvatar from '@/components/ibps-avatar'
 import NoticeDialog from '@/views/platform/notice/edit'
 import menu from './menu.json'
 import { findAllByCurrUserId } from '@/api/platform/system/desktop'
-import { dbSqlConfig } from '@/constant'
 
 // 透明图片
 const BLANK =
   'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'
 export default {
-  name: 'dashboard',
+  name: 'Dashboard',
   // mixins: [navbar],
   components: {
     IbpsAvatar,
@@ -229,7 +227,8 @@ export default {
       return i18n.generateTitle(menu[this.aliasKey], menu[this.labelKey])
     },
     getBadge(menu) {
-      const info = menu.alias === 'mySchedule' ? this.countInfo[menu[this.aliasKey]] : '0'
+      const info =
+        menu.alias === 'mySchedule' ? this.countInfo[menu[this.aliasKey]] : '0'
 
       if (this.$utils.isNotEmpty(info)) {
         return info > 99 ? '99+' : info === '0' ? '' : info
@@ -256,7 +255,7 @@ export default {
         // this.dashboards = this.outList
         if (this.$utils.isNotEmpty(this.dashboards)) {
           const activeDashboards = []
-          this.dashboards.forEach(d => {
+          this.dashboards.forEach((d) => {
             activeDashboards.push(d[this.aliasKey])
           })
           this.activeDashboards = activeDashboards
@@ -264,40 +263,86 @@ export default {
         this.emptyData = !(this.dashboards.length > 0)
       } else {
         getMenuData({}, false)
-          .then(response => {
+          .then((response) => {
             const data = response.data
-            const listData = data.filter(d => {
-              return d.id !== '0'
+            const listData = data.filter((d) => {
+              return d.id !== '0' && d.displayInMenu === 'Y'
             })
-            listData.sort((a, b) => a.id * 1 - b.id * 1)
-            this.dashboards = TreeUtils.transformToTreeFormat(listData, {
+            // listData.sort((a, b) => a.id * 1 - b.id * 1)
+            this.dashboards = this.toTree(listData, {
               idKey: this.idKey,
               parentIdKey: this.parentIdKey,
               childrenKey: this.childrenKey
             })
             if (this.$utils.isNotEmpty(this.dashboards)) {
               const activeDashboards = []
-              this.dashboards.forEach(d => {
+              this.dashboards.forEach((d) => {
                 activeDashboards.push(d[this.aliasKey])
               })
               this.activeDashboards = activeDashboards
             }
             this.emptyData = !(listData.length > 0)
           })
-          .catch(e => {
+          .catch((e) => {
             this.emptyData = true
             this.resultType = 'error'
             this.resultMessage = e.message
           })
       }
     },
+    toTree(
+      data,
+      options = {
+        idKey: 'id',
+        parentIdKey: 'parentId',
+        childrenKey: 'children'
+      }
+    ) {
+      // return TreeUtils.transformToTreeFormat(data, {
+      //   idKey: 'id',
+      //   pIdKey: 'parentId',
+      //   childrenKey: 'children'
+      // })
+      const data1 = JSON.parse(JSON.stringify(data))
+      const map = new Map()
+      const tree = []
+      // 第一遍遍历:将所有节点存入映射表,并初始化children数组
+      data1.forEach((item) => {
+        item[options.childrenKey] = [] // 初始化子节点数组
+        map.set(item[options.idKey], item)
+      })
+      // 第二遍遍历:建立父子关系
+      data1.forEach((item) => {
+        const parentId = item[options.parentIdKey]
+        // 处理根节点(parentId为null)
+        if (parentId === null) {
+          // 检查根节点是否已存在(id为"0"的节点)
+          if (item.id === '0') {
+            tree.push(item)
+          }
+          return
+        }
+        // 查找父节点
+        if (map.has(parentId)) {
+          const parent = map.get(parentId)
+          // console.log('22222==>', parent)
+          parent.children.push(item)
+          // 更新父节点的hasChild属性
+          parent.hasChild = true
+        } else {
+          // 处理孤立节点(没有找到父节点)
+          tree.push(item)
+        }
+      })
+      return tree
+    },
     loadCountInfo() {
       getInfoCount({}, false)
-        .then(response => {
-          this.scheduleNum().then(r => {
+        .then((response) => {
+          this.scheduleNum().then((r) => {
             const data = response.data
             const countInfo = {}
-            data.forEach(d => {
+            data.forEach((d) => {
               countInfo[d.alias] = d.dataText
             })
             countInfo['mySchedule'] = r + ''
@@ -305,7 +350,7 @@ export default {
             this.countInfo = countInfo
           })
         })
-        .catch(e => {})
+        .catch(() => {})
     },
 
     loadNotice() {
@@ -315,11 +360,11 @@ export default {
         { page: 1, limit: 5 }
       )
       queryPageList(params, false)
-        .then(response => {
+        .then((response) => {
           this.noticeList = response.data.dataResult
           this.emptyNoticeData = !(this.noticeList.length > 0)
         })
-        .catch(e => {
+        .catch(() => {
           this.emptyNoticeData = true
         })
     },
@@ -368,60 +413,94 @@ export default {
       const that = this
       let mid = []
       let objArr1 = {}
-      return new Promise((resolve, reject) => {
-        findAllByCurrUserId({}, false).then(res => {
-          const data = res.data || []
-          if (data.length > 0) {
-            mid = []
-            const maxt = new Date(this.$common.getFormatDate('string', 10, timeTime) + ' 24:00:00').getTime()
-            const mint = new Date(this.$common.getFormatDate('string', 19, timeTime)).getTime()
-            data.forEach((item, i) => {
-              const st = new Date(item.startTime + ' 00:00:00').getTime()
-              const et = new Date(item.endTime + ' 24:00:00').getTime()
-              if (item.startTime.indexOf(time) !== -1 || item.endTime.indexOf(time) !== -1 || ((st <= mint) && (et >= maxt))) {
-                mid.push(item)
-              }
-            })
-          }
-
-          const sql = `select a.id_ as fid, a.start_date_, a.end_date_, a.config_, a.overview_, b.* from t_schedule_detail b join t_schedule a on a.id_ = b.parent_id_ where a.status_='已发布' and b.user_id_ = '${that.userInfo.user.id}' and (CAST(a.start_date_ AS DATE) like '%${time}%' or  CAST(a.end_date_ AS DATE) like '%${time}%' or (CAST(a.start_date_ AS DATE) < '${time}' and CAST(a.end_date_ AS DATE)>'${time}') )`
-          this.$common.request(dbSqlConfig ? 'query' : 'sql', dbSqlConfig ? { key: 'yddsywdpbhqdtzs', params: [that.userInfo.user.id, time, time, time, time] } : sql).then(resp => {
-            const vdata = resp.variables.data || []
-            if (vdata.length > 0) {
-              objArr1 = {}
-              vdata.forEach((item, i) => {
-                const dArr = this.generationDate(item.start_date_, item.end_date_)
-                dArr.forEach((t, n) => {
-                  if (objArr1.hasOwnProperty(t)) {
-                    // const strArr = objArr1[t].name.split(',')
-                    // if (strArr.findIndex(e => e === (item['d' + (n + 1) + '_'] ? item['d' + (n + 1) + '_'] : '')) === -1) {
-                    const mid = item['d' + (n + 1) + '_'] ? item['d' + (n + 1) + '_'] : ''
-                    objArr1[t].name = objArr1[t].name + (item['d' + (n + 1) + '_'] !== '' && objArr1[t].name !== '' ? ',' : '') + mid
-                    objArr1[t].num = objArr1[t].name === '' ? 0 : objArr1[t].name.split(',').length
-                    // }
-                  } else {
-                    const name = item['d' + (n + 1) + '_'] ? item['d' + (n + 1) + '_'] : ''
-                    const num = name === '' ? 0 : name.split(',').length
-                    objArr1[t] = { name: name, num: num }
-                  }
-                })
+      return new Promise((resolve) => {
+        findAllByCurrUserId({}, false)
+          .then((res) => {
+            const data = res.data || []
+            if (data.length > 0) {
+              mid = []
+              const maxt = new Date(
+                this.$common.getFormatDate('string', 10, timeTime) + ' 24:00:00'
+              ).getTime()
+              const mint = new Date(
+                this.$common.getFormatDate('string', 19, timeTime)
+              ).getTime()
+              data.forEach((item) => {
+                const st = new Date(item.startTime + ' 00:00:00').getTime()
+                const et = new Date(item.endTime + ' 24:00:00').getTime()
+                if (
+                  item.startTime.indexOf(time) !== -1 ||
+                  item.endTime.indexOf(time) !== -1 ||
+                  (st <= mint && et >= maxt)
+                ) {
+                  mid.push(item)
+                }
               })
             }
-            console.log(objArr1)
-            resolve(mid.length + objArr1[time].num)
-          }).catch(e => {
+
+            const sql = `select a.id_ as fid, a.start_date_, a.end_date_, a.config_, a.overview_, b.* from t_schedule_detail b join t_schedule a on a.id_ = b.parent_id_ where a.status_='已发布' and b.user_id_ = '${that.userInfo.user.id}' and (CAST(a.start_date_ AS DATE) like '%${time}%' or  CAST(a.end_date_ AS DATE) like '%${time}%' or (CAST(a.start_date_ AS DATE) < '${time}' and CAST(a.end_date_ AS DATE)>'${time}') )`
+            this.$common
+              .request('sql', sql)
+              .then((resp) => {
+                const vdata = resp.variables.data || []
+                if (vdata.length > 0) {
+                  objArr1 = {}
+                  vdata.forEach((item) => {
+                    const dArr = this.generationDate(
+                      item.start_date_,
+                      item.end_date_
+                    )
+                    dArr.forEach((t, n) => {
+                      if (objArr1.hasOwnProperty(t)) {
+                        // const strArr = objArr1[t].name.split(',')
+                        // if (strArr.findIndex(e => e === (item['d' + (n + 1) + '_'] ? item['d' + (n + 1) + '_'] : '')) === -1) {
+                        const mid = item['d' + (n + 1) + '_']
+                          ? item['d' + (n + 1) + '_']
+                          : ''
+                        objArr1[t].name =
+                          objArr1[t].name +
+                          (item['d' + (n + 1) + '_'] !== '' &&
+                          objArr1[t].name !== ''
+                            ? ','
+                            : '') +
+                          mid
+                        objArr1[t].num =
+                          objArr1[t].name === ''
+                            ? 0
+                            : objArr1[t].name.split(',').length
+                        // }
+                      } else {
+                        const name = item['d' + (n + 1) + '_']
+                          ? item['d' + (n + 1) + '_']
+                          : ''
+                        const num = name === '' ? 0 : name.split(',').length
+                        objArr1[t] = { name: name, num: num }
+                      }
+                    })
+                  })
+                }
+                console.log(objArr1)
+                resolve(mid.length + objArr1[time].num)
+              })
+              .catch(() => {})
+            // resolve(data)
+          })
+          .catch(() => {
+            // this.emptyNoticeData = true
           })
-        // resolve(data)
-        }).catch(e => {
-        // this.emptyNoticeData = true
-        })
       })
     },
     // 根据起止日期输出范围内所有日期
     generationDate(start, end, type = 'string') {
       const dateArr = []
-      const startArr = type === 'date' ? this.$common.getFormatDate('string', 10, start).split('-') : start.split('-')
-      const endArr = type === 'date' ? this.$common.getFormatDate('string', 10, end).split('-') : end.split('-')
+      const startArr =
+        type === 'date'
+          ? this.$common.getFormatDate('string', 10, start).split('-')
+          : start.split('-')
+      const endArr =
+        type === 'date'
+          ? this.$common.getFormatDate('string', 10, end).split('-')
+          : end.split('-')
       const db = new Date()
       db.setUTCFullYear(startArr[0], startArr[1] - 1, startArr[2])
       const de = new Date()
@@ -431,7 +510,9 @@ export default {
       let stamp
       const oneDay = 24 * 60 * 60 * 1000
       for (stamp = unixDb; stamp <= unixDe;) {
-        dateArr.push(this.$common.getFormatDate('string', 10, new Date(parseInt(stamp))))
+        dateArr.push(
+          this.$common.getFormatDate('string', 10, new Date(parseInt(stamp)))
+        )
         stamp = stamp + oneDay
       }
       return dateArr