ttk-app-core
Version:
enterprise develop framework
142 lines (124 loc) • 3.98 kB
JavaScript
import React from 'react';
import { action as MetaAction, AppLoader } from 'edf-meta-engine';
import config from './config';
import { Carousel } from 'edf-component';
import { Base64 } from 'edf-utils';
class action {
constructor(option) {
this.metaAction = option.metaAction
this.config = config.current
this.webapi = this.config.webapi
}
onInit = async ({ component, injections }) => {
this.component = component
this.injections = injections
injections.reduce('init')
this.getCarouselBg()
};
getCarouselBg = async () => {
let imgs = [{}, {}, {}];
imgs[0].url = await require('./img/a1.jpg')
imgs[1].url = await require('./img/2.jpg')
imgs[2].url = await require('./img/3.png')
this.injections.reduce('load', imgs)
};
renderCal = () => {
const arr = this.metaAction.gf('data.other.imgs').toJS()
const data = this.metaAction.gf('data').toJS()
return (
<Carousel
autoplay={true}
initialSlide={data.other.selectedImgIndex}
dots={true}
// afterChange={this.imgChange}
>
{
arr.map(item => {
return (
<div>
<img src={item.url}/>
<div className="ttk-edf-app-landingpage-content-ad">
</div>
</div>
)
})
}
</Carousel>
)
}
goLogin = () => {
var returnUrl = location.href;
if (!this.config.apps['edfx-app-login']) {
throw '请将这个应用加入到带edfx-app-root和edfx-app-login的网站中,跳转功能才能正常使用'
}
if (this.component.props.onRedirect && this.config.goLogin) {
if(typeof returnUrl == 'string') {
this.config.goLogin.appParams.returnUrl = returnUrl;
this.config.goLogin.appName = 'edfx-app-login?returnUrl=' + returnUrl
}
this.component.props.onRedirect(this.config.goLogin)
}
}
goRegister = () => {
var returnUrl = location.href;
if (!this.config.apps['edfx-app-register']) {
throw '请将这个应用加入到带edfx-app-root和edfx-app-register的网站中,跳转功能才能正常使用'
}
if (this.component.props.onRedirect && this.config.goRegister) {
if(typeof returnUrl == 'string') {
this.config.goRegister.appParams.returnUrl = returnUrl;
this.config.goRegister.appName = 'edfx-app-register?returnUrl=' + returnUrl
}
this.component.props.onRedirect(this.config.goRegister)
}
}
//首页
jumpToIndex = () => {
}
//培训
jumpToPeiXun = () => {
let url = "http://zsfw.jchl.com/portal/tk/training/page/0/index.html"
this.jumpToUrl(url)
}
//资讯
jumpToZiXun = () => {
let url = "http://zsfw.jchl.com/portal/tk/information/index.html"
this.jumpToUrl(url)
}
//专家
jumpToZhuangJia = () => {
let url = "http://zsfw.jchl.com/portal/tk/expert/page/experts_list.html"
this.jumpToUrl(url)
}
//金融
jumpToJinRong = () => {
let url = "http://www.baidu.com"
this.jumpToUrl(url)
}
//公共
jumpToUrl = (url) => {
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()
}
}
export default function creator(option) {
const metaAction = new MetaAction(option),
o = new action({ ...option, metaAction }),
ret = { ...metaAction, ...o };
metaAction.config({ metaHandlers: ret });
return ret;
}