From c98e45bfac25e9110ad0383faac54a54d98ea9d5 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期四, 18 十一月 2021 20:47:04 +0800
Subject: [PATCH] 2021-11-18

---
 src/components/header/index.jsx |  371 ++++++++++++++++++++++++++++++++++------------------
 1 files changed, 239 insertions(+), 132 deletions(-)

diff --git a/src/components/header/index.jsx b/src/components/header/index.jsx
index 0444ef1..952e442 100644
--- a/src/components/header/index.jsx
+++ b/src/components/header/index.jsx
@@ -4,17 +4,16 @@
 import {connect} from 'react-redux'
 import { is, fromJS } from 'immutable'
 import moment from 'moment'
-import { Dropdown, Menu, Icon, Modal, Form, notification, Switch, Input, Badge } from 'antd'
+import { Dropdown, Menu, Icon, Modal, Form, notification, Switch, Input } from 'antd'
 
 import {
   toggleCollapse,
-  modifyMenuTree,
   modifyMainMenu,
-  modifyTabview,
   initActionPermission,
   initMenuPermission,
   logout
 } from '@/store/action'
+import asyncComponent from '@/utils/asyncComponent'
 import Api from '@/api'
 import MKEmitter from '@/utils/events.js'
 import options from '@/store/options.js'
@@ -22,12 +21,12 @@
 import enUS from '@/locales/en-US/main.js'
 import Utils from '@/utils/utils.js'
 import avatar from '@/assets/img/avatar.jpg'
-import Resetpwd from './resetpwd'
-import LoginForm from './loginform'
 import './index.scss'
 
 const { confirm } = Modal
 const { Search } = Input
+const Resetpwd = asyncComponent(() => import('./resetpwd'))
+const LoginForm = asyncComponent(() => import('./loginform'))
 
 class Header extends Component {
   static propTpyes = {
@@ -40,16 +39,16 @@
     confirmLoading: false,
     userName: sessionStorage.getItem('User_Name'),
     logourl: window.GLOB.mainlogo,
+    appVersion: window.GLOB.appVersion,
     loginVisible: false,
     loginLoading: false,
     avatar: Utils.getrealurl(sessionStorage.getItem('avatar')),
     systems: [],
     searchkey: '',
     thdMenuList: [],
-    oriVersion: '',
-    newVersion: '',
     debug: sessionStorage.getItem('debug') === 'true',
-    navBar: ['linkage_navigation', 'linkage'].includes(window.GLOB.navBar) ? 'topmenu' : ''
+    navBar: ['linkage_navigation', 'linkage', 'menu_board', 'menu_board_navigation'].includes(window.GLOB.navBar) ? 'topmenu' : '',
+    menuType: window.GLOB.navBar
   }
 
   handleCollapse = () => {
@@ -89,9 +88,14 @@
         if (result.status) {
           notification.success({
             top: 92,
-            message: this.state.dict['main.password.resetsuccess'],
+            message: '淇敼鎴愬姛锛岃閲嶆柊鐧诲綍銆�',
             duration: 2
           })
+          setTimeout(() => {
+            sessionStorage.clear()
+            this.props.logout()
+            this.props.history.replace('/login')
+          }, 2000)
         } else {
           notification.warning({
             top: 92,
@@ -138,31 +142,33 @@
     // 鑾峰彇瑙掕壊鏉冮檺
     let roledefer = new Promise(resolve => {
       // edition_type 鎺ュ彛鐗堟湰鎺у埗 ''銆�'Y'銆�'A'
-      Api.getSystemConfig({
-        func: 's_Get_TrdMenu_Role',
-        edition_type: 'A',
-        pro_sys: window.GLOB.systemType === 'production' ? 'Y' : ''
-      }).then(result => {
-        let _permAction = {} // 鎸夐挳鏉冮檺
-
-        if (result && result.status) {
-          if (result.UserRoles_Menu) {
-            result.UserRoles_Menu.forEach(menu => {
-              if (!menu.MenuID) return
-              _permAction[menu.MenuID] = true
+      setTimeout(() => {
+        Api.getSystemConfig({
+          func: 's_Get_TrdMenu_Role',
+          edition_type: 'A',
+          pro_sys: window.GLOB.systemType === 'production' ? 'Y' : ''
+        }).then(result => {
+          let _permAction = {loaded: true} // 鎸夐挳鏉冮檺
+  
+          if (result && result.status) {
+            if (result.UserRoles_Menu) {
+              result.UserRoles_Menu.forEach(menu => {
+                if (!menu.MenuID) return
+                _permAction[menu.MenuID] = true
+              })
+            }
+          } else if (result) {
+            notification.error({
+              top: 92,
+              message: result.message,
+              duration: 10
             })
           }
-        } else if (result) {
-          notification.error({
-            top: 92,
-            message: result.message,
-            duration: 10
-          })
-        }
-
-        this.props.initActionPermission(_permAction)
-        resolve()
-      })
+  
+          this.props.initActionPermission(_permAction)
+          resolve()
+        })
+      }, 50)
     })
 
     // 鑾峰彇涓昏彍鍗曞弬鏁�
@@ -212,9 +218,8 @@
           sessionStorage.removeItem('ThirdMenu')
         }
 
-        this.props.modifyMenuTree(menulist)
         this.props.modifyMainMenu(mainMenu)
-        this.props.initMenuPermission(thdMenuList)
+        this.props.initMenuPermission([...thdMenuList, {MenuID: 'home_page_id', EasyCode: '', MenuName: 'home', type: 'CustomPage'}])
 
         resolve(_menu)
       })
@@ -222,21 +227,12 @@
     
     Promise.all([roledefer, menudefer]).then(response => {
       if (response[1]) {
-        let tabs = fromJS(this.props.tabviews).toJS()
         let menu = fromJS(response[1]).toJS()
 
-        if (this.state.navBar === 'topmenu') {
-          menu.selected = true
-          this.props.modifyTabview([menu])
+        if (this.state.navBar === 'topmenu' && this.state.menuType !== 'menu_board_navigation') {
+          MKEmitter.emit('modifyTabs', menu, 'replace')
         } else {
-          tabs = tabs.map(tab => {
-            tab.selected = false
-            return tab
-          })
-
-          menu.selected = true
-          tabs.push(menu)
-          this.props.modifyTabview(tabs)
+          MKEmitter.emit('modifyTabs', menu, 'plus')
         }
       }
     })
@@ -308,8 +304,9 @@
                 ParentNames: [fst.MenuName, snd.MenuName],
                 MenuNo: trd.MenuNo,
                 EasyCode: trd.EasyCode,
-                type: 'CommonTable',            // 榛樿鍊间负甯哥敤琛�
-                OpenType: 'newtab'              // 鎵撳紑鏂瑰紡
+                type: 'CommonTable',
+                OpenType: 'newtab',
+                hidden: 'false'
               }
   
               if (trd.LinkUrl && iframes.includes(trd.LinkUrl.split('?')[0])) {
@@ -324,6 +321,7 @@
 
                 trdItem.type = trdItem.PageParam.Template || trdItem.type
                 trdItem.OpenType = trdItem.PageParam.OpenType || trdItem.OpenType
+                trdItem.hidden = trdItem.PageParam.hidden || trdItem.hidden
 
                 if (trdItem.type === 'NewPage') {
                   trdItem.src = trdItem.PageParam.url || ''
@@ -338,7 +336,7 @@
                       _param.Full_Name = sessionStorage.getItem('Full_Name')
 
                       trdItem.src = _url + window.btoa(window.encodeURIComponent(JSON.stringify(_param)))
-                    } catch {
+                    } catch (e) {
                       console.warn('鑿滃崟鍙傛暟瑙f瀽閿欒锛�')
                     }
                   }
@@ -357,6 +355,8 @@
             })
           }
 
+          sndItem.children = sndItem.children.filter(item => item.hidden !== 'true')
+
           return sndItem
         })
       }
@@ -371,7 +371,7 @@
     // 淇敼缂栬緫鐘舵��
     let UserID = sessionStorage.getItem('CloudUserID')
     let LoginUID = sessionStorage.getItem('CloudLoginUID')
-
+    
     if (!UserID || !LoginUID) {
       this.setState({
         loginVisible: true
@@ -381,9 +381,7 @@
       sessionStorage.setItem('dataM', sessionStorage.getItem('cloudDataM'))
       sessionStorage.setItem('isEditState', 'true')
 
-      this.props.modifyMenuTree([])
       this.props.modifyMainMenu(null)
-      this.props.modifyTabview([])
 
       this.props.history.replace('/design')
     }
@@ -408,10 +406,8 @@
           sessionStorage.setItem('dataM', res.dataM ? 'true' : '')
           sessionStorage.setItem('isEditState', 'true')
 
-          this.props.modifyMenuTree([])
+          this.setSystemFuncs()
           this.props.modifyMainMenu(null)
-          this.props.modifyTabview([])
-
           this.props.history.replace('/design')
         } else {
           if (res.message.indexOf('瀵嗙爜閿欒') > -1) {
@@ -428,6 +424,107 @@
           })
         }
       })
+    })
+  }
+
+  setSystemFuncs = () => {
+    if (!window.GLOB.WebSql && !window.GLOB.IndexDB) {
+      return
+    }
+    this.getfuncTime().then(res => {
+      Api.getSystemFuncs(res.createDate).then(result => {
+        if (!result.status) {
+          notification.error({
+            top: 92,
+            message: result.message,
+            duration: 10
+          })
+          return
+        } else if (result.func_detail && result.func_detail.length > 0) {
+          this.writeFuncs(result.func_detail)
+        }
+      })
+    })
+  }
+
+  writeFuncs = (funcs) => {
+    let timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
+
+    let sys_datetime = sessionStorage.getItem('sys_datetime')
+    let app_datetime = sessionStorage.getItem('app_datetime')
+    if (sys_datetime && app_datetime) {
+      let seconds = Math.floor((new Date().getTime() - app_datetime) / 1000)
+      timestamp = moment(sys_datetime, 'YYYY-MM-DD HH:mm:ss').add(seconds, 'seconds').format('YYYY-MM-DD HH:mm:ss')
+    }
+
+    if (window.GLOB.WebSql) {
+      window.GLOB.WebSql.transaction(tx => {
+        tx.executeSql('DELETE FROM FUNCS')
+
+        funcs.forEach(item => {
+          if (!item.key_sql) return
+          tx.executeSql('INSERT INTO FUNCS (func_code, key_sql) VALUES (?, ?)', [item.func_code, item.key_sql])
+        })
+        tx.executeSql(`UPDATE VERSIONS SET createDate='${timestamp}' where CDefine1='funcs'`)
+      })
+    } else {
+      let objectStore = window.GLOB.IndexDB.transaction(['funcs'], 'readwrite').objectStore('funcs')
+
+      objectStore.clear()
+
+      funcs.forEach(item => {
+        if (!item.key_sql) return
+        item.id = item.func_code
+        objectStore.add(item)
+      })
+
+      let funcStore = window.GLOB.IndexDB.transaction(['version'], 'readwrite').objectStore('version')
+      funcStore.put({id: 'funcs', version: '1.0', createDate: timestamp})
+    }
+  }
+
+  getfuncTime = () => {
+    return new Promise((resolve, reject) => {
+      if (window.GLOB.WebSql) {
+        window.GLOB.WebSql.transaction(tx => {
+          tx.executeSql("SELECT * FROM VERSIONS where CDefine1='funcs'", [], (tx, results) => {
+            let rows = results.rows
+            if (rows.length === 0) {
+              tx.executeSql('DELETE FROM FUNCS')
+              tx.executeSql('INSERT INTO VERSIONS (version, createDate, CDefine1) VALUES (?, ?, ?)', ['1.0', '1970-01-01 14:59:09.000', 'funcs'])
+              resolve({createDate: '1970-01-01 14:59:09.000'})
+            } else {
+              resolve(rows[0])
+            }
+          }, (tx, results) => {
+            reject()
+            console.warn(results)
+          })
+        })
+      } else {
+        let objectStore = window.GLOB.IndexDB.transaction(['version'], 'readwrite').objectStore('version')
+        let request = objectStore.get('funcs')
+
+        request.onerror = (event) => {
+          console.warn(event)
+          reject()
+        }
+
+        request.onsuccess = () => {
+          if (request.result) {
+            resolve(request.result)
+          } else {
+            let add = objectStore.add({id: 'funcs', version: '1.0', createDate: '1970-01-01 14:59:09.000'})
+    
+            add.onerror = () => {
+              reject()
+            }
+            add.onsuccess = () => {
+              resolve({id: 'funcs', version: '1.0', createDate: '1970-01-01 14:59:09.000'})
+            }
+          }
+        }
+      }
     })
   }
 
@@ -477,23 +574,10 @@
     this.getRolesMenu()
   }
 
-  UNSAFE_componentWillReceiveProps (nextProps) {
-    if (!is(fromJS(this.props.menuTree), fromJS(nextProps.menuTree)) && !is(fromJS(this.state.menulist), fromJS(nextProps.menuTree))) {
-      this.setState({
-        menulist: nextProps.menuTree
-      })
-    }
-  }
-
   componentDidMount () {
     // 鑾峰彇绯荤粺鐨勭増鏈俊鎭紝寤舵椂鏌ヨ
     setTimeout(() => {
-      Api.getAppVersion().then(res => {
-        this.setState({
-          oriVersion: res.oldVersion,
-          newVersion: res.newVersion
-        })
-      }, () => {})
+      Api.getAppVersion().then(() => {}, () => {})
     }, 1000)
   }
 
@@ -508,38 +592,6 @@
     this.setState = () => {
       return
     }
-  }
-
-  verup = () => {
-    const { oriVersion, newVersion } = this.state
-    const _this = this
-
-    confirm({
-      title: this.state.dict['main.verup'],
-      content: `鏈�鏂扮増鏈�${newVersion}锛屽綋鍓嶇増鏈�${oriVersion}`,
-      onOk() {
-        return new Promise(resolve => {
-          if (!window.GLOB.WebSql) {
-            notification.warning({
-              top: 92,
-              message: '鍗囩骇澶辫触锛岃鍒锋柊椤甸潰閲嶈瘯锛�',
-              duration: 2
-            })
-            resolve()
-          } else {
-            Api.updateAppVersion(newVersion)
-            notification.success({
-              top: 92,
-              message: '鍗囩骇鎴愬姛锛�',
-              duration: 2
-            })
-            _this.setState({oriVersion: newVersion})
-            resolve()
-          }
-        })
-      },
-      onCancel() {}
-    })
   }
 
   gotoDoc = () => {
@@ -563,27 +615,11 @@
       if (menu.OpenType === 'newpage' || menu.OpenType === 'NewPage') { // NewPage涓烘墦寮�澶栭儴椤甸潰鍦板潃锛宯ewpage涓烘墦寮�绯荤粺鑿滃崟
         window.open(menu.src)
       } else if (menu.OpenType === 'blank') {
-        menu.selected = true
-        this.props.modifyTabview([menu])
-      } else if (this.state.navBar === 'topmenu') {
-        menu.selected = true
-        this.props.modifyTabview([menu])
+        MKEmitter.emit('modifyTabs', menu, 'replace')
+      } else if (this.state.navBar === 'topmenu' && this.state.menuType !== 'menu_board_navigation') {
+        MKEmitter.emit('modifyTabs', menu, 'replace')
       } else {
-        let tabs = fromJS(this.props.tabviews).toJS()
-        tabs = tabs.filter(tab => {
-          tab.selected = false
-          return tab.MenuID !== menu.MenuID
-        })
-  
-        if (this.props.tabviews.length > tabs.length) {
-          this.props.modifyTabview(fromJS(tabs).toJS())
-        }
-  
-        this.setState({}, () => {
-          menu.selected = true
-          tabs.push(menu)
-          this.props.modifyTabview(tabs)
-        })
+        MKEmitter.emit('modifyTabs', menu, 'plus')
       }
   
       if (window.GLOB.systemType === 'production') {
@@ -592,9 +628,45 @@
     }
   }
 
+  verup = () => {
+    confirm({
+      title: '椤甸潰鏇存柊',
+      content: '閲嶆柊鍔犺浇搴旂敤淇℃伅',
+      onOk() {
+        return new Promise(resolve => {
+          if (!window.GLOB.WebSql && !window.GLOB.IndexDB) {
+            notification.warning({
+              top: 92,
+              message: '鏇存柊澶辫触锛岃鍒锋柊椤甸潰閲嶈瘯锛�',
+              duration: 2
+            })
+            resolve()
+          } else {
+            Api.updateAppVersion()
+            setTimeout(() => {
+              notification.success({
+                top: 92,
+                message: '鏇存柊鎴愬姛锛�',
+                duration: 2
+              })
+              resolve()
+            }, 1000)
+          }
+        })
+      },
+      onCancel() {}
+    })
+  }
+
+  about = () => {
+    Modal.success({
+      title: '绯荤粺鐗堟湰v' + this.state.appVersion
+    })
+  }
+
   render () {
     const { mainMenu, collapse } = this.props
-    const { thdMenuList, searchkey, oriVersion, newVersion, debug, menulist, navBar } = this.state
+    const { thdMenuList, searchkey, debug, menulist, navBar, menuType, appVersion } = this.state
 
     const menu = (
       <Menu className="header-dropdown">
@@ -609,8 +681,11 @@
           ))}
         </Menu.SubMenu> : null}
         <Menu.Item key="doc" onClick={this.gotoDoc}>{this.state.dict['main.doc']}</Menu.Item>
-        {oriVersion ? <Menu.Item key="verup" onClick={this.verup}>
-          <Badge dot={oriVersion !== newVersion}>{this.state.dict['main.verup']}</Badge>
+        <Menu.Item key="verup" onClick={this.verup}>
+          椤甸潰鏇存柊
+        </Menu.Item>
+        {appVersion ? <Menu.Item key="version" onClick={this.about}>
+          鍏充簬
         </Menu.Item> : null}
         <Menu.Item key="logout" onClick={this.logout}>{this.state.dict['main.logout']}</Menu.Item>
       </Menu>
@@ -634,8 +709,7 @@
             })}
           </ul> : null
         }
-        {/* 姝e父鑿滃崟 */}
-        {navBar === 'topmenu' && menulist ?
+        {navBar === 'topmenu' && menuType !== 'menu_board' && menuType !== 'menu_board_navigation' && menulist ?
           <ul className="header-menu vertical-menu">{
             menulist.map(item => {
               if (item.children && item.children.length > 0) {
@@ -662,6 +736,44 @@
                         }
                       })}
                     </Menu>
+                  }>
+                    <li>
+                      <span>{item.MenuName}</span>
+                    </li>
+                  </Dropdown>
+                )
+              } else {
+                return (
+                  <li key={item.MenuID} onClick={() => {this.changeVerMenu(item, 'first')}}>
+                    <span>{item.MenuName}</span>
+                  </li>
+                )
+              }
+            })}
+          </ul> : null
+        }
+        {navBar === 'topmenu' && (menuType === 'menu_board' || menuType === 'menu_board_navigation') && menulist ?
+          <ul className="header-menu vertical-menu">{
+            menulist.map(item => {
+              if (item.children && item.children.length > 0) {
+                return (
+                  <Dropdown key={item.MenuID} placement="bottomCenter" overlayClassName="vertical-dropdown-menu" overlay={
+                    <div className="menu-board">
+                      {item.children.map(cell => {
+                        return (
+                          <div className="menu-wrap" key={cell.MenuID}>
+                            <div className="title" onClick={e => e.stopPropagation()}>{cell.MenuName}</div>
+                            <div className="menu-detail">
+                              {cell.children && cell.children.map(m => (
+                                <div key={m.MenuID} title={m.MenuName} onClick={() => {this.changeVerMenu(m)}}>
+                                  {m.MenuName}
+                                </div>
+                              ))}
+                            </div>
+                          </div>
+                        )
+                      })}
+                    </div>
                   }>
                     <li>
                       <span>{item.MenuName}</span>
@@ -753,19 +865,14 @@
 
 const mapStateToProps = (state) => {
   return {
-    tabviews: state.tabviews,
     collapse: state.collapse,
-    menuTree: state.menuTree,
-    mainMenu: state.mainMenu,
-    permAction: state.permAction,
+    mainMenu: state.mainMenu
   }
 }
 
 const mapDispatchToProps = (dispatch) => {
   return {
     toggleCollapse: (collapse) => dispatch(toggleCollapse(collapse)),
-    modifyTabview: (tabviews) => dispatch(modifyTabview(tabviews)),
-    modifyMenuTree: (menuTree) => dispatch(modifyMenuTree(menuTree)),
     modifyMainMenu: (mainMenu) => dispatch(modifyMainMenu(mainMenu)),
     initActionPermission: (permAction) => dispatch(initActionPermission(permAction)),
     initMenuPermission: (permMenus) => dispatch(initMenuPermission(permMenus)),

--
Gitblit v1.8.0