import React from 'react'; import { Button, Icon, Modal } from 'antd'; import { WeaTools, WeaLocaleProvider, WeaTop, WeaDialog, WeaSearchGroup, WeaFormItem, WeaInput, WeaCheckbox, WeaBrowser, WeaInputNumber, WeaSelect, WeaUpload, WeaRichText, WeaFieldTemplateSelect, WeaHelpfulTip, WeaAvatar, } from 'ecCom'; import { WeaForm, WeaSwitch } from 'comsMobx'; import { addContentPath } from '../util/pathUtil'; const getLabel = WeaLocaleProvider.getLabel; const basicToolBar = { toolbar: [ { name: 'paragraph', items: ['JustifyLeft', 'JustifyCenter', 'JustifyRight'] }, { name: 'styles', items: ['Font', 'FontSize'] }, { name: 'colors', items: ['TextColor'] }, ], }; class WeaSystemSetting extends React.Component { state = { loading: false, data: {}, wmSetting: {}, textVisible: false, textTemp: { wmwidth: '', wmheight: '', wmcontent: '' }, imgTemp: { wmwidth: '', wmheight: '' }, labelList: [], textEdited: false, clientTypeValue: '', optionList: [], avatarCondition: [], avatarForm: {}, avatarValue: '', mBackColor: '', mFontColor: '', fBackColor: '', fFontColor: '', ffixedimageid: '', mfixedimageid: '', mPreview: '', fPreview: '', headPreview: '', canEdit: '', }; constructor(props) { super(props); this.getButtons = this.getButtons.bind(this); this.onChange = this.onChange.bind(this); this.onWmChange = this.onWmChange.bind(this); this.onSave = this.onSave.bind(this); this.onCancel = this.onCancel.bind(this); this.onLoad = this.onLoad.bind(this); this.setImageSize = this.setImageSize.bind(this); this.getPreviewHref = this.getPreviewHref.bind(this); this.onSaveTextDailog = this.onSaveTextDailog.bind(this); this.setScrolledHeight = this.setScrolledHeight.bind(this); this.getPluginSettings = this.getPluginSettings.bind(this); } componentWillMount() { const { display, visible } = this.props; if (display == 'page' || visible) { this.onLoad(); } } componentDidMount() { this.getPluginSettings(); } render() { const { display, visible, style = {} } = this.props; const { loading, data, textVisible, textTemp, labelList, wmSetting, textEdited, clientTypeValue, optionList, avatarForm, avatarCondition, } = this.state; const { canEdit = false, oaaddress, licenseRemind, remindUserNames, remindDays, picturePath, filesystem, filesystembackup, filesystembackuptime, needzip, isaesencrypt, unsystem_help, } = data; const { isopen, mobileisopen, watermarktype, opacity, rotate, imageid } = wmSetting; const { wmcontent } = textTemp; const disabled = !canEdit; const colProps = { labelCol: { span: 8 }, wrapperCol: { span: 16 } }; const Content = ( this.onChange({ oaaddress: value })} /> {canEdit ? ( this.onChange({ licenseRemind: value })} /> ) : ( '' )} {canEdit && licenseRemind == '1' ? ( this.onChange({ remindUsers: ids, remindUserNames: datas })} /> ) : ( '' )} {canEdit && licenseRemind == '1' ? ( this.onChange({ remindDays: value })} /> ) : ( '' )} {canEdit ? ( this.onChange({ unsystem_help: value })} /> ) : ( '' )} this.onChange({ picturePath: value })} /> this.onChange({ filesystem: value })} /> this.onChange({ filesystembackup: value })} /> this.onChange({ filesystembackuptime: value })} /> this.onChange({ needzip: value })} /> this.onChange({ isaesencrypt: value })} /> {getLabel(30986, '保存')} , ]} onCancel={() => this.setState({ textVisible: false, textTemp: { wmwidth: wmSetting.wmwidth, wmheight: wmSetting.wmheight, wmcontent: wmSetting.wmcontent, }, }) } > this.setState({ textTemp: { ...textTemp, wmwidth: value } })} /> this.setState({ textTemp: { ...textTemp, wmheight: value } })} />
this.setScrolledHeight(ref)} ckConfig={basicToolBar} value={textTemp.wmcontent} onChange={v => this.setState({ textTemp: { ...textTemp, wmcontent: v } })} />
this.richText.insertHTML(key)} />
this.onWmChange({ isopen: value })} /> {canEdit && Number(isopen) === 1 && [ this.onWmChange({ mobileisopen: value })} /> , ]} {canEdit && [ { let fix = {}; if (v == '1') { fix = { wmwidth: textTemp.wmwidth, wmheight: textTemp.wmheight, }; } this.onWmChange({ watermarktype: Number(v), ...fix }); }} /> , {watermarktype === 2 ? (
{imageid && imageid != -1 ? (
this.setImageSize(e.target)} width={50} src={addContentPath(`/weaver/weaver.file.FileDownload?fileid=${imageid}`)} atl="" /> this.onWmChange({ imageid: '' })} />
) : ( this.onWmChange({ imageid: ids[0] })} /> )} {imageid && imageid != -1 ? this.getPreviewHref() : Number(isopen) === 1 ? : null}
) : (
)}
, this.onWmChange({ opacity: value })} /> , this.onWmChange({ rotate: value })} /> , , ); } return buttons; } setScrolledHeight(ref) { // 计算变量关键字列表高度,使其与富文本等高 this.richText = ref; if (!ref || this.scrolledHeight > 0) return; let height = 0; if (ref && ref.refs.wrap) { const top = 37 + 4; height = ref.refs.wrap.clientHeight - top; } this.scrolledHeight = height; } setImageSize(img) { // 获取图片的原始尺寸 if (img) { let fix = { wmwidth: img.naturalWidth > 200 ? img.naturalWidth : 200, wmheight: img.naturalHeight > 150 ? img.naturalHeight : 150, }; this.setState({ imgTemp: fix }); this.onWmChange(fix); } } getPreviewHref() { const { wmSetting } = this.state; let href = '/cloudstore/resource/pc/watermark/preview.html'; let params = '?'; Object.keys(wmSetting || {}).forEach((key) => { params += `${key}=${encodeURIComponent(wmSetting[key])}&`; }); href += params; return ( {getLabel(221, '预览')} ); } onSaveTextDailog() { const { textTemp } = this.state; const { wmcontent, wmwidth, wmheight } = textTemp; let isWMCEmpty = !wmcontent; if (!isWMCEmpty) { const element = window.CKEDITOR.dom.element.createFromHtml(wmcontent); isWMCEmpty = element.getText().replace(/[\s\n]/g, '') === ''; } if (!isWMCEmpty && wmwidth && wmheight) { this.onWmChange(textTemp); this.setState({ textVisible: false, textEdited: true }); } else { let content = ''; if (!wmwidth) { content = getLabel(520158, '请输入水印宽度'); } else if (!wmheight) { content = getLabel(520159, '请输入水印高度'); } else if (isWMCEmpty) { content = getLabel(504467, '请输入文本水印内容'); } Modal.error({ content }); } } onWmChange(obj) { const { wmSetting } = this.state; this.setState({ wmSetting: { ...wmSetting, ...obj } }); } onChange(obj) { const { data } = this.state; this.setState({ data: { ...data, ...obj } }); } onSave() { const { onSave ,callbackFn } = this.props; const { data, wmSetting, clientTypeValue } = this.state; if ( (wmSetting.isopen === 1 || wmSetting.isopen === '1') && (!wmSetting.watermarktype || (wmSetting.watermarktype === 1 && !wmSetting.wmcontent) || (wmSetting.watermarktype === 2 && (!(wmSetting.imageid && wmSetting.imageid != -1)))) ) { // 水印必填处理 Modal.error({ content: wmSetting.watermarktype === 2 ? getLabel(504466, '请选择水印图片') : getLabel(504467, '请输入文本水印内容'), }); return; } // 验证备份目录内容 if (data.filesystembackup == '' || data.filesystembackuptime == '') { Modal.error({ content: getLabel(509065, '请输入必填项'), }); return; } if (data.filesystembackuptime > 1440 || data.filesystembackuptime < 60 || isNaN(data.filesystembackuptime)) { Modal.error({ content: getLabel(514463, '备份周期只能在60分钟到1440分钟之间'), }); return; } this.setState({ visible: true, loading: true }); let done = 0; let cb = () => { done += 1; if (done === 2) { // 修改水印 WeaTools.watermark.getSystemSetting(); this.onCancel(); if (onSave && typeof onSave == 'function') onSave(); if (callbackFn && typeof callbackFn == 'function') callbackFn(data); } }; WeaTools.callApi('/api/portal/systemInfo/saveSettingData', 'POST', { ...data }) .then(() => { this.setState({ loading: false }); WeaTools.callApi('/api/systeminfo/othersetting/getHelp', 'GET', {}).then((result) => { WeaTools.ls.set('showHelp', { showHelp: result.helpmenu }); }); }) .then(cb); WeaTools.callApi('/api/doc/console/wmsystemsetting/savewmsetting', 'POST', { ...wmSetting }).then(cb); WeaTools.callApi('/api/odoc/odocPluginSettings/savePluginSettings', 'POST', { clientType: clientTypeValue }).then(cb); // 头像设置保存 const { avatarForm } = this.state; const params = avatarForm.getFormParams(); WeaTools.callApi('/api/hrm/systemAvatarSetting/saveAvatarSetting', 'POST', { ...params }); } onCancel() { this.props.onShow(false); } onLoad() { this.setState({ loading: true }); WeaTools.callApi('/api/portal/systemInfo/getSettingData', 'GET', {}).then((result) => { const { data } = result; // 备份目录为空值时设置默认值 data.filesystembackup == '' && (data.filesystembackup = '/oa/weaver/ecology/filesystembackup'); // 备份周期为空为0及大于24小时的都改为一天 (data.filesystembackuptime == '' || data.filesystembackuptime == 0 || data.filesystembackuptime > 1440) && (data.filesystembackuptime = 1440); this.setState({ loading: false, data }); }); // 获取水印设置 WeaTools.callApi('/api/doc/console/wmsystemsetting/getwmsetting', 'GET', {}).then((result) => { const { wmSetting } = result; if (wmSetting) { const { wmwidth, wmheight, wmcontent } = wmSetting; this.setState({ wmSetting, imgTemp: { wmwidth, wmheight }, textTemp: { wmwidth, wmheight, wmcontent }, textEdited: !!wmcontent }); } }); // 获取文本水印变量 WeaTools.callApi('/api/doc/console/wmsystemsetting/getwmtextparam', 'GET', {}).then((result) => { const { labelList } = result; this.setState({ labelList }); }); // 头像设置 WeaTools.callApi('/api/hrm/systemAvatarSetting/getAvatarSettingForm', 'GET', {}).then((resp) => { // const { avatarForm, avatarCondition, canEdit } = this.state; const form = new WeaForm(); form.initFormFields(resp.condition); const { isFormInit } = form; if (isFormInit) { this.setState({ avatarCondition: resp.condition, avatarForm: form, canEdit: resp.canEdit, }); this.getViewStyle(); } }); } // 渲染表单 getWriteForm = (form, condition) => { // form.initFormFields(condition); // condition = toJS(condition); const { isFormInit } = form; const formParams = form.getFormParams(); let group = []; isFormInit && condition && condition.map((c) => { let items = []; c.items.map((fields) => { items.push({ com: ( ), colSpan: 1, }); }); items.push({ com: ( {this.renderViewImage()} ), colSpan: 1, }); group.push( {c.title} )} />, ); }); return group; }; // 调用样式设置的dialog showDialog = (title, url, style, callback, onCancel) => { style = style || { width: 800, height: 600 }; const dialog = WeaTools.createDialog({ moduleName: 'hrm', title, url, style, callback, onCancel, hasScroll: true }); dialog.show(); }; // 默认头像格式选择 onChangeAvatar = (data) => { this.setState({ avatarValue: data.headformat.value, }); }; // 获取预览的样式信息 getViewStyle = () => { WeaTools.callApi('/api/hrm/systemAvatarSetting/getStyleSettingData', 'GET', {}).then((resp) => { this.state.avatarForm.updateFields({ headformat: { value: resp.headformat, }, }); this.setState({ mBackColor: resp.mheadbackcolor, mFontColor: resp.mheadfontcolor, fBackColor: resp.fheadbackcolor, fFontColor: resp.fheadfontcolor, ffixedimageid: resp.ffixedimageid, mfixedimageid: resp.mfixedimageid, mPreview: resp.mPreview, fPreview: resp.fPreview, headPreview: resp.headPreview, avatarValue: resp.headformat, }); }); }; // 渲染头像预览图片 renderViewImage = () => { const { avatarValue, mBackColor, mFontColor, fBackColor, fFontColor, ffixedimageid, mfixedimageid, mPreview, fPreview, headPreview, canEdit } = this.state; const url = '/spa/hrm/engine.html#/hrmengine/avatarSetting'; if (avatarValue == 1) { // 首字 return ( {mPreview} {fPreview} {canEdit && ( this.showDialog(getLabel('514308', '默认头像样式设置'), url, { width: 800, height: 600 }, this.getViewStyle)} > {getLabel('128334', '样式设置')} )} ); } if (avatarValue == 2) { // 默认头像 return ( {mfixedimageid == 0 ? ( ) : ( )} {ffixedimageid == 0 ? ( ) : ( )} {canEdit && ( this.showDialog(getLabel('514308', '默认头像样式设置'), url, { width: 800, height: 600 }, this.getViewStyle)} > {getLabel('128334', '样式设置')} )} ); } if (avatarValue == 3) { // 后两字 return ( {headPreview} {headPreview} {canEdit && ( this.showDialog(getLabel('514308', '默认头像样式设置'), url, { width: 800, height: 600 }, this.getViewStyle)} > {getLabel('128334', '样式设置')} )} ); } }; getPluginSettings() { // 获取插件列表 WeaTools.callApi('/api/odoc/odocPluginSettings/getPluginSettings', 'POST', {}).then((result) => { const { pluginSetting } = result; if (pluginSetting) { const { clientTypeValue, optionList } = pluginSetting; this.setState({ clientTypeValue, optionList, }); } }); } } export default WeaSystemSetting;