ttk-app-core
Version:
enterprise develop framework
1,306 lines (1,223 loc) • 50 kB
JavaScript
import React from 'react'
import { Menu, Dropdown, Icon } from 'edf-component'
import { action as MetaAction, AppLoader } from 'edf-meta-engine'
import { fromJS } from 'immutable'
import { history, fetch, environment } from 'edf-utils'
import config from './config'
import { log } from 'util';
import moment from 'moment'
import debounce from 'lodash.debounce'
import female from './img/female_t.png'
import male from './img/male_t.png'
import other from './img/other_t.png'
import beta_top from './img/beta_top.png'
import beta_right from './img/beta_right.png'
import qrcodeImg from './img/qrcode.jpg'
// import scrollIntoView from 'dom-scroll-into-view'
// import domAlign from 'dom-align'
//import { childVoucherItems } from '../../gl/app-auxbalancesum-rpt/data'
//import QrCode from '../../ba/app-weixin-share/qrcode'
let loadSplitCss = false
const borwserVersion = environment.getBrowserVersion()
if (borwserVersion.ie && borwserVersion.version < 10) {
loadSplitCss = true
}
class action {
constructor(option) {
this.metaAction = option.metaAction
this.config = config.current
this.webapi = this.config.webapi
this.manageListShow = debounce(this.manageListShow, 500);
}
onInit = ({ component, injections }) => {
this.component = component
this.injections = injections
injections.reduce('init')
//没有token跳转到登录
if (!sessionStorage.getItem('_accessToken')) {
this.component.props.onRedirect(this.config.goAfterLogout)
return
}
//更新皮肤
let skin = localStorage.getItem('skin') || '#1EB5AD'
if (skin != '#1EB5AD') {
this.toggleColor(skin)
}
//根据账号下企业list的情况做跳转
let availableOrg = sessionStorage.getItem('currentOrgStatus')
if (availableOrg == 1 || availableOrg == 2) {
this.metaAction.sf('data.headCtrl', false)
return
}
this.load()
this.getOrgs()
//获取消息数
this.getMsgNum()
//history增加
history.listen('edfx-app-portal', this.listen)
//定义回调
this.tabListens = {}
}
//history增加
listen = (childApp, location, action) => {
const currentAppName = this.metaAction.gf('data.content.appName')
const targetAppName = childApp
if (!targetAppName) {
this.injections.reduce('closeAll')
return
}
if (targetAppName == currentAppName) {
return
}
//this.setContent('', targetAppName, {})
}
componentWillUnmount = () => {
history.unlisten('edfx-app-portal', this.listen)
}
windowClick = (e) => {
if (!document.getElementById('edfx-app-portal-search-id')) return
const dom = document.getElementById('edfx-app-portal-search-id').parentNode
if (!dom.contains(e.target)) {
this.metaAction.sf('data.animation1', 'out')
this.metaAction.sf('data.showPanel', 'none')
}
}
onMenuMouseOver = (e) => {
let flag = this.metaAction.gf('data').toJS()
this.metaAction.sf('data.width', !flag.width)
this.metaAction.sf('data.menuMathRandom', Math.random())
if (flag.width) {
//this.metaAction.sf('data.currentMenuType', 2)
this.injections.reduce('changeMenuType', [])
}
else {
this.injections.reduce('changeMenuType', [1])
}
}
onScrollMouseOver = (e) => {
this.metaAction.sf('data.currentMenuStyle', 'menuscroll')
}
onScrollMouseLeave = () => {
this.metaAction.sf('data.currentMenuStyle', 'nomenuscroll')
}
componentDidMount = () => {
//IE中无CustomEvent
(function () {
if (typeof window.CustomEvent === "function") return false;
function CustomEvent(event, params) {
params = params || { bubbles: false, cancelable: false, detail: undefined };
var evt = document.createEvent('CustomEvent');
evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
return evt;
}
CustomEvent.prototype = window.Event.prototype;
window.CustomEvent = CustomEvent;
})();
(function () {
var throttle = function (type, name, obj) {
obj = obj || window;
var running = false;
var func = function () {
if (running) { return; }
running = true;
requestAnimationFrame(function () {
obj.dispatchEvent(new CustomEvent(name));
running = false;
});
};
if (obj.addEventListener) {
obj.addEventListener(type, func);
}
else if (obj.attachEvent) {
obj.attachEvent(type, func);
}
};
throttle("resize", "optimizedResize");
})();
//注册 resize 事件
//window.addEventListener("optimizedResize", this.resize)
if (window.addEventListener) {
window.addEventListener('optimizedResize', this.resize)
} else if (window.attachEvent) {
window.attachEvent('optimizedResize', this.resize)
}
}
load = async (option) => {
await this.webapi.portal.init()
let response = await this.webapi.portal.portal()
// let manageList = await this.webapi.org.queryList()
// response.manageList = manageList
if (option) {
// let periodDate = response.periodDate
response.org = Object.assign(response.org, option)
// response.org.periodDate = periodDate.periodDate
// response.org.maxClosingPeriod = periodDate.maxClosingPeriod
}
if (response.user) {
this.metaAction.context.set('currentUser', response.user)
//this.metaAction.sf('data.other.currentUser', fromJS(response.user))
}
else {
this.metaAction.context.set('currentUser', undefined)
if (this.component.props.onRedirect && this.config.goAfterLogout) {
this.component.props.onRedirect(this.config.goAfterLogout)
}
}
if (response.org) {
let currentOrg = this.metaAction.context.get("currentOrg")
// if(currentOrg && currentOrg.periodDate){
// response.org.periodDate = currentOrg && currentOrg.periodDate
// }else {
response.org.periodDate = response.periodDate.periodDate
response.org.maxClosingPeriod = response.periodDate.maxClosingPeriod
// }
// if(currentOrg && !currentOrg.maxClosingPeriod){
// response.org.maxClosingPeriod = response.periodDate.maxClosingPeriod
// }
this.metaAction.context.set('currentOrg', response.org)
} else {
this.metaAction.context.set('currentOrg', undefined)
if (this.component.props.onRedirect && this.config.goAfterLogout) {
this.component.props.onRedirect(this.config.goAfterLogout)
}
}
let menuStyle = response.menuTreeMemory.state ? 1 : 2
//let defaultOpenKeys = this.getMenuSelectKeys()
if (response.menu) {
this.injections.reduce('load', { menu: response.menu }, menuStyle)
}
if (response.periodDate) {
let obj = {
maxClosingPeriod: response.periodDate.maxClosingPeriod,
periodDate: moment(response.periodDate.periodDate)
}
this.metaAction.sf('data.periodDate', obj)
}
this.injections.reduce('changeMenuType', [10])
this.metaAction.sfs({
'data.menuMathRandom': Math.random(),
'data.headCtrl': true,
'data.isShowSearch': false,
})
}
getOrgs = async () => {
let manageList = await this.webapi.org.queryList()
this.injections.reduce('manageList', { manageList })
}
manageListShow = (text) => {
let data = this.metaAction.gf('data').toJS(), list = []
if (text == '') {
list = data.manageList
} else {
data.manageList.forEach(function (listData) {
if (listData.name.includes(text)) {
// if(listData.name.indexOf(text) > -1){
list.push(listData)
}
})
};
// $manageListShow(list)
// console.log('挑选出的',list)
this.injections.reduce('manageListShow', list)
}
toggleManage = async (e) => {//切换企业
let data = this.metaAction.gf('data').toJS()
let setManage = data.manageList.filter((data) => {
return e.key == data.name
})
let response = await this.webapi.org.updateCurrentOrg({ "orgId": setManage[0].id })
// this.metaAction.context.set('currentOrg', setManage[0])
this.injections.reduce('closeContentReally', 'toggleManage')
await this.load(setManage[0])
this.setContent('门户首页', 'edfx-app-portal', { isShowMenu: false, isTabsStyle: false })
if (data.manageList.length >= 8) {
document.getElementsByClassName('edfx-app-portal-header-right-menu-deptSearch')[0].children[0].value = ''
}
this.metaAction.sfs({
'data.visible': false,
'data.selectedKeys': ''
})
}
handleVisibleChange = (visible) => {
this.metaAction.sf('data.visible', visible)
}
userVisibleChange = (visible) => {
this.metaAction.sf('data.userMenuVisible', visible)
}
menuControl = async (e) => {//帮助中心控制面板
if (this.metaAction.gf('data.showPanel') == 'block') {
this.metaAction.sf('data.showPanel', 'none')
} else {
this.metaAction.sf('data.showPanel', 'block')
}
this.metaAction.sf('data.animation', 'in')
}
hidePanel = () => {
this.metaAction.sf('data.animation', 'out')
this.metaAction.sf('data.showPanel', 'none')
}
animationEnd = () => {
this.metaAction.gf('data.animation') == 'out' &&
this.metaAction.sf('data.showPanel', 'none')
}
getLogo = () => this.config.logo
getPhoto = () => {
const user = this.getCurrentUser()
if (user) {
if (user.sex == 1) {
return male
} else if (user.sex == 2) {
return female;
} else {
return other
}
}
return other
}
getCurrentUser = () => this.metaAction.context.get('currentUser') || {}
getCurrentOrg = () => this.metaAction.context.get('currentOrg') || {}
getUserNickName = () => {
const user = this.getCurrentUser()
if (user && user.nickname) {
return user.nickname;
} else {
return sessionStorage.getItem('username')
}
return ""
}
getOrgName = () => {
const org = this.getCurrentOrg()
if (org) {
return org.name;
}
return ""
}
resize = () => {
let data = this.metaAction.gf('data').toJS()
window.onresize = () => {
if (data.widthPersonStatus == false) {
let width = window.innerWidth > 1024 ? true : false;
this.metaAction.sf('data.width', width);
}
}
this.metaAction.sf('data.service.mathRandom', Math.random())
}
switchMenu = () => {
let flag = this.metaAction.gf('data').toJS()
// this.metaAction.sf('data.width', !flag.width)
// this.metaAction.sf('data.widthPersonStatus', true)
// this.metaAction.sf('data.menuMathRandom', Math.random())
this.metaAction.sfs({
'data.width': !flag.width,
'data.widthPersonStatus': true,
'data.menuMathRandom': Math.random(),
})
if (flag.width) {
//this.metaAction.sf('data.currentMenuType', 2)
this.injections.reduce('changeMenuType', [])
}
else {
this.injections.reduce('changeMenuType', [1])
}
}
getMenuChildren = () => {
const menu = this.metaAction.gf('data.menu').toJS()
let currentURI = location.href.toUpperCase().indexOf('DEVELOP') > -1
if (currentURI) {
let menuPro1 = {
appName: 'ttk-edf-app-outside',
appProps: '{ "url": "http://124.193.174.170:20000/tplus/BAPView/VoucherList.aspx?fromApp=lv&user=15010365441&pwd=6dbffb7c2d4006ee47bda055b16c5597&accNum=1&menu=GL0105pId=voucherListView&sysId=gl&mId=gl0101&Action=Search&taskID=凭证管理&TaskSessionID=dbc52f7f-9572-ee0d-40ab-c634f0cf1c32" }',
code: '5030',
appParams: {},
id: 5030,
isFolded: 0,
isVisible: 1,
children: [],
key: '5030',
name: 'TPlus凭证管理',
parentId: 50,
requestType: 0,
showOrder: 909,
versionTag: 0,
ts: "2018-07-24 10:03:52.0"
}
let menuPro2 = {
appName: 'ttk-edf-app-iframe',
appParams: { 'src': 'tplus.html' },
code: '5040',
id: 5040,
isFolded: 0,
isVisible: 1,
children: [],
key: '5040',
name: 'TPlus Portal',
parentId: 50,
requestType: 0,
showOrder: 910,
versionTag: 0,
ts: "2018-07-24 10:03:52.0"
}
if (menu[6].children) {
menu[6].children.push(menuPro1)
menu[6].children.push(menuPro2)
}
}
const loop = (children, num) => {
const ret = [];
if (num == 1) {
children.forEach(child => {
if (child.id != "1") {
ret.push({
name: child.key,
key: child.key,
disabled: "{{data.currentMenuType==1?true:false}}",
className: "{{data.currentMenuType==2?(data.width ? 'level-first show-content' : 'level-first hide-content'):(data.width ? 'level-first2 show-content' : 'level-first2 hide-content')}}",
title: child.children.length !== 0 && [{
name: 'title',
component: '::span',
className: 'leftNavMenu',
children: [{
name: 'icon',
component: 'Icon',
fontFamily: 'edficon',
className: 'menu-icon',
type: child.iconFont
}, {
name: 'title',
component: '::span',
className: 'menu-content',
key: Math.random(),
children: child.name
}, {
name: 'badgeImg',
component: '::img',
_visible: child.versionTag == 1,
className: "{{data.width ? 'right_beta' : 'top_beta'}}",
src: "{{$getBeta()}}",
}]
}],
component: child.children.length == 0 ? 'Menu.Item' : 'Menu.SubMenu',
children: child.children.length == 0 ? [{
name: 'icon',
component: 'Icon',
fontFamily: 'edficon',
className: 'menu-icon',
type: child.iconFont //'link'
}, {
name: 'title',
component: '::span',
className: 'menu-content',
children: child.name
}] : loop(child.children, 2)
})
}
})
} else {
children.forEach(child => {
if (!child.children || child.children.length == 0) {
ret.push({
name: child.key,
key: child.key,
//className: child.appName == this.metaAction.gf('data.selectCurrentMenu') ? 'left-menu-submenu-menuitem moji ant-menu-item-selected' : 'left-menu-submenu-menuitem moji',
className: 'left-menu-submenu-menuitem moji',
component: 'Menu.Item',
children: child.name,
})
} else {
ret.push({
name: child.key,
key: child.key,
className: 'left-menu-itemgroup',
title: {
name: 'title',
component: '::span',
children: child.name
},
component: "{{data.currentMenuType==1 ? 'Menu.SubMenu' : 'Menu.ItemGroup'}}",
children: loop(child.children, 2)
})
}
})
}
return ret
}
return {
_isMeta: true,
value: loop(menu, 1)
}
}
//获取beta图片
getBeta = () => {
return this.metaAction.gf('data.width') ? beta_right : beta_top
}
onOpenChange = (item) => {
let newItem = [],
lastSubMenu = []
if (item) {
if (item.length > 0) {
item.map((i) => {
if (i.length == 4) {
lastSubMenu = new Array(i)
}
else {
newItem.push(i)
}
})
}
}
if (newItem.length > 0) {
newItem = newItem.concat(lastSubMenu)
let updateArrList = {
'data.menuMathRandom': Math.random(),
'data.defaultOpenKeys': newItem
}
this.metaAction.sfs(updateArrList)
/*控制MENU滚动条位置 */
let pageY = window.event.pageY || 0,
currentY = $('.mk-layout edfx-app-portal-content-left .menuscroll').scrollTop() || 0
if (currentY > 100) {
window.setTimeout(function () {
$('.mk-layout edfx-app-portal-content-left .menuscroll').scrollTop(parseInt(pageY) + 100)
}, 10)
}
/*
domAlign(document.getElementsByClassName('ant-menu-submenu-open')[3].childNodes[1].childNodes[2].childNodes[0], document.getElementById('menucontainer'), {
offsetTop: 100,
offsetBottom: 0,
offsetLeft: 0,
offsetRight: 0
})*/
}
}
createLink = () => {
let element = document.head.querySelector('.el-element')
// if(element){
// element.parentNode.removeChild(element)
// }
let origin = location.origin
let link = document.createElement('link')
link.className = 'el-element'
link.rel = 'stylesheet'
link.type = 'text/css'
link.id = 'skin'
return link
}
toggleColor = async (color, action) => {
if (loadSplitCss) {
return this.toggleColorforIe(color, action)
}
let origin = location.origin
let link = null
if (document.querySelector("#skin")) {
link = document.querySelector("#skin")
} else {
link = this.createLink()
document.head.appendChild(link)
}
switch (color) {
case '#FF913A':
link.href = origin + '/yellowTheme' + '.css'
break;
case '#00B38A':
link.href = origin + '/greenTheme' + '.css'
break;
case '#416AAA':
link.href = origin + '/blueTheme' + '.css'
break;
case '#1EB5AD':
link.href = origin + '/businessBlueTheme' + '.css'
break;
case '#B4A074':
link.href = origin + '/orangeTheme' + '.css'
break;
case '#414141':
link.href = origin + '/blackTheme' + '.css'
break;
default:
link.href = origin + '/greenTheme' + '.css'
break;
}
if (action && action == 'change') {
this.webapi.user.updateSkin(color)
localStorage['skin'] = color
}
}
toggleColorforIe = async (color, action) => {
//let hash = (__webpack_hash__).slice(0, 8)
for (let i = 1; i < 6; i++) {
let origin = location.origin
let link = null
if (document.querySelector("#skin")) {
link = document.querySelector("#skin")
} else {
link = this.createLink()
document.head.appendChild(link)
}
switch (color) {
case '#FF913A':
link.href = origin + '/splitcss/yellowTheme' + `-${i}` + '.css'
break;
case '#00B38A':
link.href = origin + '/splitcss/greenTheme' + `-${i}` + '.css'
break;
case '#416AAA':
link.href = origin + '/splitcss/blueTheme' + `-${i}` + '.css'
break;
case '#1EB5AD':
link.href = origin + '/splitcss/businessBlueTheme' + `-${i}` + '.css'
break;
case '#B4A074':
link.href = origin + '/splitcss/orangeTheme' + `-${i}` + '.css'
break;
case '#414141':
link.href = origin + '/splitcss/blackTheme' + `-${i}` + '.css'
break;
default:
link.href = origin + '/splitcss/greenTheme' + `-${i}` + '.css'
break;
}
if (action && action == 'change') {
this.webapi.user.updateSkin(color)
localStorage['skin'] = color
}
}
}
topMenuClick = async (e) => {
this.metaAction.sf('data.userMenuVisible', false)
switch (e.key) {
case 'mySetting':
//点击个人设置时先判断当前是否在企业管理和创建企业界面
let currentOpenAppName = this.metaAction.gf('data.content').toJS().appName
if (currentOpenAppName == 'edf-company-manage' || currentOpenAppName == 'edf-company-manage-add') {
this.tabEdit(currentOpenAppName, 'remove')
}
if (!this.config.apps['edfx-app-my-setting'])
throw '不存在edfx-app-my-setting应用,该功能不能使用'
this.metaAction.sf('data.isTabsStyle', true)
this.metaAction.sf('data.isShowMenu', true)
this.setContent('个人设置', 'edfx-app-my-setting')
break;
case 'logout':
if (this.component.props.onRedirect && this.config.goAfterLogout) {
let res = await this.webapi.user.logout()
if (res) {
this.metaAction.context.set('currentUser', undefined)
this.metaAction.context.set('currentOrg', undefined)
sessionStorage.removeItem('mobile')
sessionStorage.removeItem('username')
sessionStorage.removeItem('_accessToken')
sessionStorage.removeItem('password')
this.component.props.onRedirect(this.config.goAfterLogout)
}
}
break;
case 'newGuide':
this.openBeginnerGuidance()
break;
default:
return
}
let selectedKeys = this.metaAction.gf('data.selectedKeys')
if (selectedKeys) {
selectedKeys = selectedKeys.toJS()
selectedKeys[0] = e.key
this.metaAction.sf('data.selectedKeys', fromJS(selectedKeys))
}
}
goRegister = (e) => {
if (e.preventDefault) {
e.preventDefault()
}
if (e.stopPropagation) {
e.stopPropagation()
}
this.setContent('新建企业', 'edf-company-manage-add')
// this.metaAction.sf('data.isTabsStyle', false)
// this.metaAction.sf('data.isShowMenu', false)
// this.metaAction.sf('data.visible', false)
// this.setContent('新建企业', 'edf-company-manage-add', { mark: 'home' })
this.metaAction.sfs({
'data.isTabsStyle': false,
'data.isShowMenu': false,
'data.visible': false,
})
}
goCompanyManage = (e) => {
if (e.preventDefault) {
e.preventDefault()
}
if (e.stopPropagation) {
e.stopPropagation()
}
if (!this.config.apps['edf-company-manage'])
throw 'edf-company-manage应用,该功能不能使用'
this.setContent('企业管理', 'edf-company-manage')
// this.metaAction.sf('data.isTabsStyle', false)
// this.metaAction.sf('data.isShowMenu', false)
// this.metaAction.sf('data.visible', false)
this.metaAction.sfs({
'data.isTabsStyle': false,
'data.isShowMenu': false,
'data.visible': false,
})
}
searchVisibleToogle = (show) => {
this.metaAction.sf('data.isShowSearch', show)
}
searchHidden = () => {
let searchContainer = document.querySelector('.edfx-app-portal-search-container')
searchContainer.className = searchContainer.className.replace('slideInRight', 'fadeOutRight')
}
searchAnimationEnd = (e) => {
let searchContainer = document.querySelector('.edfx-app-portal-search-container')
let flag = searchContainer.className.indexOf('slideInRight') != -1 ? true : false
if (flag) {
let searchInput = document.querySelector('#edfx-app-portal-search-id')
searchInput.focus()
} else {
this.metaAction.sf('data.isShowSearch', false)
}
}
menuClick = (e) => {
if (e.domEvent) {
e.domEvent.stopPropagation()
}
const menu = this.metaAction.gf('data.menu').toJS()
let currentURI = location.href.toUpperCase().indexOf('DEVELOP') > -1
if (currentURI) {
let menuPro1 = {
appName: 'ttk-edf-app-outside',
appProps: '{ "url": "http://124.193.174.170:20000/tplus/BAPView/VoucherList.aspx?fromApp=lv&user=15010365441&pwd=6dbffb7c2d4006ee47bda055b16c5597&accNum=1&menu=GL0105pId=voucherListView&sysId=gl&mId=gl0101&Action=Search&taskID=凭证管理&TaskSessionID=dbc52f7f-9572-ee0d-40ab-c634f0cf1c32" }',
code: '5030',
appParams: {},
id: 5030,
isFolded: 0,
isVisible: 1,
children: [],
key: '5030',
name: 'TPlus凭证管理',
parentId: 50,
requestType: 0,
showOrder: 909,
versionTag: 0,
ts: "2018-07-24 10:03:52.0"
}
let menuPro2 = {
appName: 'ttk-edf-app-iframe',
appParams: { 'src': 'tplus.html' },
code: '5040',
id: 5040,
isFolded: 0,
isVisible: 1,
children: [],
key: '5040',
name: 'TPlus Portal',
parentId: 50,
requestType: 0,
showOrder: 910,
versionTag: 0,
ts: "2018-07-24 10:03:52.0"
}
if (menu[6].children) {
menu[6].children.push(menuPro1)
menu[6].children.push(menuPro2)
}
}
const find = (children) => {
for (let child of children) {
if (child.key == e.key) {
return child
}
if (child.children) {
let o = find(child.children)
if (o) return o
}
}
}
const hit = find(menu)
if (hit.appParams) {
hit.appParams.accessType = 0
hit.appParams.isFolded = hit.isFolded
hit.appParams.isGuide = hit.isGuide || false
hit.appParams.isMenuCode = hit.code
hit.appParams.openType = 'menu'
} else {
hit.appParams = {
accessType: 0,
isFolded: hit.isFolded,
isGuide: hit.isGuide || false,
isMenuCode: hit.code,
openType: 'menu'
}
}
if (!!hit.appProps) {
Object.assign(hit.appParams, JSON.parse(hit.appProps))
}
let needFolded = this.metaAction.gf('data.currentMenuType') == 2
if (needFolded) {
hit.isFolded && hit.isFolded == 1 ? this.metaAction.sf('data.width', false) : this.metaAction.sf('data.width', true)
}
if (hit && hit.requestType == 1) {
let url = hit.appProps && JSON.parse(hit.appProps).url
window.open(url)
} else {
this.setContent(hit.name, hit.appName, hit.appParams)
//埋点
//_hmt && _hmt.push(['_trackEvent', '系统管理', '菜单',hit.name])
}
/*末级点击时二级全部收缩*/
/*点击三级时,二级不收缩 */
if (!needFolded) {
let menuItem = this.metaAction.gf('data.defaultOpenKeys'),
newItem = []
const lastSubMenu = new Array(hit.key)
let parentId = String(hit.parentId)
if (menuItem) {
if (menuItem.length > 0) {
menuItem.map((i) => {
if (i.length == 2) {
newItem.push(i)
}
if (i.length == 4) {
if (lastSubMenu.toString().substr(0, 4) == i) {
newItem.push(i)
} else if (parentId.substr(0, 4) == i) {
newItem.push(i)
}
}
})
}
}
if (newItem.length > 0) {
newItem = newItem.concat(lastSubMenu)
// this.metaAction.sf('data.menuMathRandom', Math.random())
//
// this.metaAction.sf('data.selectedKeys', lastSubMenu)
// this.metaAction.sf('data.defaultOpenKeys', newItem)
this.metaAction.sfs({
'data.menuMathRandom': Math.random(),
'data.selectedKeys': lastSubMenu,
'data.defaultOpenKeys': newItem,
})
}
}
}
tabChange = async (key) => {
if (key == 'more') return
let appName = this.metaAction.gf('data.content').get('appName')
let cb = this.tabListens[appName] && this.tabListens[appName]()
if (cb) {
const ret = await this.metaAction.modal('confirm', {
title: '是否离开',
content: `当前数据尚未保存,还要离开吗?`,
})
if (!ret) {
return
}
}
const openTabs = this.metaAction.gf('data.openTabs')
let curr = openTabs.find(o => o.get('name') == key)
let _app = curr.toJS()
if (_app.appProps) {
_app.appProps.accessType = 0
_app.appProps.openType = 'tabChange'
} else {
_app.appProps = {
accessType: 0,
openType: 'tabChange'
}
}
let needFolded = this.metaAction.gf('data.currentMenuType') == 2
if (needFolded) {
_app.appProps.isFolded && _app.appProps.isFolded == 1 ? this.metaAction.sf('data.width', false) : this.metaAction.sf('data.width', true)
}
curr = fromJS(_app)
this.setContent(curr.get('name'), curr.get('appName'), curr.get('appProps'))
/**set default menu select status */
if (!needFolded) {
this.metaAction.sfs({
'data.selectedKeys': [curr.get('appProps').get('isMenuCode')],
'data.menuMathRandom': Math.random()
})
//this.metaAction.sf('data.selectCurrentMenu', curr.get('appName'))
}
}
onlyCloseContent = (appName) => {
this.injections.reduce('onlyCloseContent', appName)
}
tabEdit = async (key, action) => {
if (key == 'more') return
let that = this
let status = false
let openTabs = this.metaAction.gf('data.openTabs').toJS()
let appName = null
openTabs.forEach(o => {
if (o.name == key) {
status = o.editing
appName = o.appName
}
})
let cb = this.tabListens[appName] && this.tabListens[appName]()
if (action == 'remove') {
if (cb || status) {
const ret = this.metaAction.modal('confirm', {
title: '是否离开',
content: `${key}尚未保存,还要离开吗?`,
onOk() {
that.injections.reduce('closeContent', key)
that.metaAction.sf('data.mathRandom', Math.random())
that.removeTabsListen(appName)
return
},
onCancel() {
return
}
})
} else {
this.injections.reduce('closeContent', key)
this.metaAction.sf('data.mathRandom', Math.random())
// this.reInitContent()
}
}
}
closeTabs = (e) => {
let key = e.key,
name = null,
status = false,
that = this,
content = this.metaAction.gf('data.content').toJS(),
openTabs = this.metaAction.gf('data.openTabs').toJS()
for (let i = 0; i < openTabs.length; i++) {
if (key == 'all') {
if (openTabs[i].editing) {
status = true
name = openTabs[i].name
break
}
} else {
if (openTabs[i].appName == content.appName) {
status = openTabs[i].editing
if (status) name = content.name
break
}
}
}
if (status) {
const ret = this.metaAction.modal('confirm', {
title: '是否离开',
content: `${name}尚未保存,还要离开吗?`,
onOk() {
if (key == 'all') {
that.injections.reduce('closeContent', 'all')
that.metaAction.sf('data.mathRandom', Math.random())
} else {
that.injections.reduce('closeContent', content.name)
that.metaAction.sf('data.mathRandom', Math.random())
}
return
},
onCancel() {
return
}
})
} else {
if (e.key == 'all') {
this.injections.reduce('closeContent', 'all')
this.metaAction.sf('data.mathRandom', Math.random())
} else {
this.injections.reduce('closeContent', content.name)
this.metaAction.sf('data.mathRandom', Math.random())
}
}
}
//获取extraMenuWidth
getExtraMenuWidth = () => {
let style = {}
let content = this.metaAction.gf('data.content').toJS()
if (content.appName == "edfx-app-home") {
style.width = environment.isDevMode() ? "220px" : "auto"
} else {
style.width = environment.isDevMode() ? "auto" : "38px"
}
return style
}
//panel控制
showControlPanel = async () => {
this.metaAction.sf('data.showControlPanel', 'block')
this.metaAction.sf('data.panelAnimation', 'in')
//请求appList
let response = await this.webapi.desktop.queryAppList()
if (response) {
this.metaAction.sf('data.ctrlPanel', response)
this.injections.reduce('appList', response)
}
}
menuSelectChange = (selectItem) => {
if (selectItem == 1) {
selectItem = 2
this.metaAction.sf('data.defaultOpenKeys', [])
}
else {
selectItem = 1
}
this.metaAction.sf('data.currentMenuType', selectItem)
this.metaAction.sf('data.menuMathRandom', Math.random())
this.injections.reduce('changeMenuType', [10])
// localStorage.setItem('menuStyle', selectItem)
this.webapi.portal.menu({ state: selectItem == 1 ? true : false })
}
//切换选中状态
panelCheckChange = (e, index) => {
let appList = this.metaAction.gf('data.desktopAppList').toJS()
appList[index].checked = !appList[index].checked
this.injections.reduce('appList', appList)
}
hidePanelEnd = () => {
let animation = this.metaAction.gf('data.panelAnimation')
if (animation == 'in') return
this.metaAction.sf('data.showControlPanel', 'none')
}
hideCtrlPanel = async (str) => {
this.metaAction.sf('data.panelAnimation', 'out')
if (str == 'save') {
let appList = this.metaAction.gf('data.desktopAppList').toJS()
let response = await this.webapi.desktop.saveAppList(appList)
this.injections.reduce('appList', appList, 'reload')
this.metaAction.sf('data.ctrlPanel', appList)
} else if (str == 'cancel') {
let appList = this.metaAction.gf('data.ctrlPanel')
this.injections.reduce('appList', appList)
}
}
/**
* reinit时调用
* 记录当前打开的所有页签
* 关闭所有后重新打开
*/
reInitContent = async () => {
let content = this.metaAction.gf('data.content')
let openTabs = this.metaAction.gf('data.openTabs')
this.injections.reduce('closeAll')
setTimeout(() => {
this.injections.reduce('reInit', content, openTabs)
}, 0)
}
//从企业管理和创建企业返回时调用
setContent = (name, appName, appProps = {}) => {
this.injections.reduce('setContent', name, appName, appProps)
}
//判断页面是否处于编辑状态
editing = (name, status) => {
this.injections.reduce('editing', name, status)
}
//在线客服,二维码
showQrcode = () => {
this.injections.reduce('weixin', true)
}
hideQrcode = () => {
this.injections.reduce('weixin', false)
}
getQrcode = () => {
return qrcodeImg
}
//获取消息数
getMsgNum = async () => {
let num = await this.webapi.getMsgNum()
this.metaAction.sf('data.msgNum', num)
}
//跳转到直播
jumpToLiveCast = () => {
let url = "https://www.jchl.com/portal/tk/training/page/3/live_course.html"
let xhr = new XMLHttpRequest()
xhr.open('post', '/v1/edf/connector/getcodefromuc', false)
xhr.setRequestHeader('Accept', 'application/json')
xhr.setRequestHeader('Content-Type', 'application/json')
xhr.setRequestHeader('token', sessionStorage.getItem('_accessToken'))
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200) {
let param = JSON.parse(xhr.responseText)
if (param.value == null) {
window.open(url)
} else {
window.open(url + '?' + param.value.replace('&', ''))
}
}
}
xhr.send()
}
//打开新手引导
openBeginnerGuidance = () => {
this.setContent('新手引导', 'ttk-edf-app-beginner-guidance')
}
//关闭popover时取消选中menu
cancelCheckStatus = (visible) => {
if (!visible) {
this.metaAction.sf('data.selectedKeys', fromJS([]))
}
}
foldMenu = () => {
this.metaAction.sf('data.isShowMenu', !this.metaAction.gf('data.isShowMenu'))
setTimeout(function () {
var event = document.createEvent('HTMLEvents')
event.initEvent("resize", true, true)
window.dispatchEvent(event)
}, 0)
}
/**
* dev模式下才显示开发帮助
*/
isDevMode = () => {
return environment.isDevMode()
}
//develop开发管理链接
batchMenuClick = (e) => {
let links = {
'axure': 'http://prototype.aierp.cn:8089',
'jira': 'http://jira.aierp.cn:8089/',
'dictionary': 'http://dic.aierp.cn:8089/',
'Jenkins': 'http://jenkins.aierp.cn:8089/',
'ued': 'http://ued.aierp.cn:8089/',
'k8s': 'http://k8s.aierp.cn:8089/',
'sonar': 'http://sonar.aierp.cn:8089/',
}
if (e.key == 'webapi') {
this.openWebApi()
} else if (e.key == 'deleteAccount') {
let name = prompt("Please enter your mobile", "")
if (name != null && name != "") {
this.webapi.user.deleteUser({ mobile: name })
}
} else {
window.open(links[e.key])
}
}
openWebApi = () => {
this.setContent('api', 'app-common-iframe')
//window.open('http://172.16.10.26/webapi/')
}
addEventListener = (eventName, handler) => {
this.injections.reduce('addEventListener', eventName, handler)
}
removeEventListener = (eventName) => {
this.injections.reduce('removeEventListener', eventName)
}
fold = () => {
if (this.metaAction.gf('data.fold') == 'zhankai') {
let reduceArr = {
'data.isShowMenu': false,
'data.fold': 'shouhui'
}
this.injections.reduce('fold', reduceArr)
}
else {
let reduceArr = {
'data.isShowMenu': true,
'data.fold': 'zhankai'
}
this.injections.reduce('fold', reduceArr)
}
}
//更改期间日期
periodDate = () => {
let day = moment().format("DD"), month = moment().format("MM"), year = moment().format("YYYY"), now = moment(), date
if (day < 15) {
date = moment().set('month', month == 0 ? 11 : month - 1);
}
let currentOrg = this.metaAction.context.get("currentOrg")
if (currentOrg && !currentOrg.periodDate) {
currentOrg.periodDate = year + '-' + month
this.metaAction.context.set('currentOrg', currentOrg)
}
if (currentOrg && (moment() < moment(currentOrg.enabledYear + '-' + currentOrg.enabledMonth))) {
date = moment(currentOrg.enabledYear + '-' + currentOrg.enabledMonth)
}
return date
}
//关闭app内的guide
closeGuide = (appName) => {
this.injections.reduce('closeGuide', appName)
}
//期间日期置灰日期比较
disabledPeriodDate = (current) => {
let currentOrg = this.metaAction.context.get("currentOrg")
return current && current < moment(currentOrg.enabledYear + '-' + currentOrg.enabledMonth)
}
//期间日期更改
periodDateChange = async (moment, str) => {
// let currentOrg = this.metaAction.context.get("currentOrg")
// currentOrg.periodDate = str
// this.metaAction.context.set('currentOrg', currentOrg)
let response = await this.webapi.periodDate({ periodDate: str })
if (response) {
await this.load()
this.setContent('门户首页', 'edfx-app-portal', { isShowMenu: false, isTabsStyle: false })
}
}
//月份渲染
monthCellCustom = (date) => {
let currentOrg = this.metaAction.context.get("currentOrg"),
enableTime = currentOrg.enabledYear + '-' + currentOrg.enabledMonth,
maxClosingPeriod = currentOrg.maxClosingPeriod
// console.log('输出时间0',date.format('YYYY-MM'))
return <DateCellCustom enableTime={enableTime} maxClosingPeriod={maxClosingPeriod} nowTime={date.format('YYYY-MM')}></DateCellCustom>
}
//控制已结账图标
isSettle = () => {
let currentOrg = this.metaAction.context.get("currentOrg"), enableTime
let periodDate = this.metaAction.gf('data.periodDate')
if (!!currentOrg) {
enableTime = currentOrg.enabledYear + '-' + currentOrg.enabledMonth
return (moment(periodDate.periodDate) <= moment(periodDate.maxClosingPeriod)) && (moment(periodDate.periodDate) >= moment(enableTime))
} else {
return false
}
}
//添加tab监听事件
addTabsListen = (appName, fn) => {
this.tabListens[appName] = fn
}
//移除tab监听事件
removeTabsListen = (appName) => {
this.tabListens[appName] && delete this.tabListens[appName]
}
}
class DateCellCustom extends React.Component {
constructor(props) {
super(props)
}
render() {
// console.log('时间',this.props.nowTime,this.props.maxClosingPeriod,this.props.enableTime,(moment(this.props.nowTime) < moment(this.props.maxClosingPeriod)) && (moment(this.props.nowTime) > moment(this.props.enableTime)))
if (this.props.maxClosingPeriod == '') {
return (
<div >
{Number(moment(this.props.nowTime).format('MM'))}月
</div>
)
} else {
if ((moment(this.props.nowTime) <= moment(this.props.maxClosingPeriod)) && (moment(this.props.nowTime) >= moment(this.props.enableTime))) {
return (
<div style={{ position: 'relative' }}>
{Number(moment(this.props.nowTime).format('MM'))}月
<Icon type="duigou"
fontFamily='edficon'
className='iconCustom'
style={{ fontSize: '17px', float: 'right', position: 'absolute', top: '-4px', right: '-12px' }} />
</div>
)
} else {
return (
<div >
{Number(moment(this.props.nowTime).format('MM'))}月
</div>
)
}
}
}
}
export default function creator(option) {
const metaAction = new MetaAction(option),
o = new action({ ...option, metaAction }),
ret = { ...metaAction, ...o }
metaAction.config({ metaHandlers: ret })
return ret
}