ttk-app-core
Version:
enterprise develop framework
126 lines (114 loc) • 4.01 kB
JavaScript
import { action as MetaAction } from 'edf-meta-engine';
import Message from '../ttk-omp-app-message-list/components/Message.js'
import moment from 'moment';
import React from 'react';
import config from './config';
import extend from './extend';
import utils from 'edf-utils';
import { fromJS } from 'immutable'
class action {
constructor(option) {
this.metaAction = option.metaAction;
this.extendAction = option.extendAction;
this.config = config.current;
this.webapi = this.config.webapi;
}
onInit = ({ component, injections }) => {
this.extendAction.gridAction.onInit({ component, injections });
this.component = component;
this.injections = injections;
if (this.component.props.setOkListener) {
this.component.props.setOkListener(this.onOk)
}
injections.reduce('init');
this.load();
};
load = async () => {
let props = this.component.props
if(props && props.buttonList == false){
this.metaAction.sf('data.buttonList', false);
}
if(props && props.messsageData){
// console.log('开水',props.messsageData)
let data = this.metaAction.gf('data').toJS();
data.form.title = props.messsageData.title
data.form.messageType = props.messsageData.messageType
data.select.sendType = props.messsageData.messageType
data.form.versionNum = props.messsageData.versionNum
data.form.content = props.messsageData.content
data.form.sendTime = props.messsageData.sendTime
data.dataState = props.messsageData.content
this.metaAction.sf('data', fromJS(data));
}
let res = await this.webapi.message.getVersion();
if (res) {
this.metaAction.sf('data.other.version', res);
}
this.metaAction.sf('data.form.sendTime', this.date());
this.injections.reduce('load');
};
//创建新消息
create = async () => {
const form = this.metaAction.gf('data.form')
.toJS();
if(form.content.length > 1024){
this.metaAction.toast('warning', '消息内容长度过长!')
return false
}
let res = await this.webapi.message.create(form);
if (res) {
this.metaAction.toast('success', `发送成功!`);
this.injections.reduce('reLoad');
this.clear();
}
};
//清空消息内容
clear = () => {
let obj = document.getElementsByClassName('quillContentClear');
obj && obj[0].click();
};
//获取本地时间
date = () => this.metaAction.momentToString(moment(), 'YYYY-MM-DD');
//预览
preview = () => {
const data = this.metaAction.gf('data').toJS()
let msgContent = data.form.content, modalTitle = data.form.title;
let setContent = this.component.props.setPortalContent
this.metaAction.sf('data.showModal', true);
this.metaAction.sf('data.modalData', <Message setContent={setContent} msgText={msgContent} />);
this.metaAction.sf('data.modalTitle', modalTitle);
// return content = <Message setContent={setContent} msgText={msgContent} />
}
//隐藏预览
hideModal = () => {
this.metaAction.sf('data.showModal', false)
}
onOk = async () => {
const form = this.metaAction.gf('data.form')
.toJS();
if(form.content.length > 1024){
this.metaAction.toast('warning', '消息内容长度过长!')
return false
}
form.isReturnValue = true
form.id = this.component.props.messsageData.id
form.ts = this.component.props.messsageData.ts
delete form.sendTime
let response = await this.webapi.message.update(form);
if (response && response.error) {
this.metaAction.toast('error', response.error.message)
return false
} else {
this.metaAction.toast('success', '保存成功')
return response
}
}
}
export default function creator(option) {
const metaAction = new MetaAction(option),
extendAction = extend.actionCreator({ ...option, metaAction }),
o = new action({ ...option, metaAction, extendAction }),
ret = { ...metaAction, ...extendAction.gridAction, ...o };
metaAction.config({ metaHandlers: ret });
return ret;
}