From dfda1222c4854af93d48a348f5ce7b4ee639d5bd Mon Sep 17 00:00:00 2001 From: Chengliang <1546584672@qq.com> Date: Fri, 16 Sep 2022 18:11:28 +0800 Subject: [PATCH] fixed --- pc4mobx/organization/apis/fieldDefined.js | 2 + pc4mobx/organization/apis/importDialog.js | 16 ++ pc4mobx/organization/apis/resourceCard.js | 0 pc4mobx/organization/components/Home.js | 1 - .../organization/components/ImportDialog.js | 240 ++++++++++++++++++ .../fieldDefinedSet/FieldDefined.js | 2 +- .../components/resource/ResourceCard.js | 0 .../organization/components/staff/Staff.js | 21 +- pc4mobx/organization/stores/fieldDefined.js | 18 +- pc4mobx/organization/stores/importDialog.js | 202 +++++++++++++++ pc4mobx/organization/stores/index.js | 8 +- pc4mobx/organization/stores/newImport.js | 2 +- pc4mobx/organization/stores/resourceCard.js | 231 +++++++++++++++++ 13 files changed, 729 insertions(+), 14 deletions(-) create mode 100644 pc4mobx/organization/apis/importDialog.js create mode 100644 pc4mobx/organization/apis/resourceCard.js create mode 100644 pc4mobx/organization/components/ImportDialog.js create mode 100644 pc4mobx/organization/components/resource/ResourceCard.js create mode 100644 pc4mobx/organization/stores/importDialog.js create mode 100644 pc4mobx/organization/stores/resourceCard.js diff --git a/pc4mobx/organization/apis/fieldDefined.js b/pc4mobx/organization/apis/fieldDefined.js index 0d550c1..122308d 100644 --- a/pc4mobx/organization/apis/fieldDefined.js +++ b/pc4mobx/organization/apis/fieldDefined.js @@ -7,6 +7,8 @@ import { * @param {Object} params [description] * @return {[type]} [description] */ + export const getHasRight = (moduleName, params = {}) => WeaTools.callApi(`/api/bs/hrmorganization/fieldDefined/${moduleName}/getHasRight`, 'GET', params) + export const getTabInfo = (moduleName, params = {}) => WeaTools.callApi(`/api/bs/hrmorganization/fieldDefined/${moduleName}/getTabInfo`, 'GET', params) export const getFieldDefinedInfo = (moduleName, params = {}) => WeaTools.callApi(`/api/bs/hrmorganization/fieldDefined/${moduleName}/getFieldDefinedInfo`, 'GET', params) diff --git a/pc4mobx/organization/apis/importDialog.js b/pc4mobx/organization/apis/importDialog.js new file mode 100644 index 0000000..9f5f60c --- /dev/null +++ b/pc4mobx/organization/apis/importDialog.js @@ -0,0 +1,16 @@ +import { WeaTools } from 'ecCom' + +//获取导入表单 +export const getImportForm = (params) => { + return WeaTools.callApi(`/api/bs/hrmorganization/commonimport/getCommonForm`, 'GET', params); + } + + //导入文件提交 +export const saveImport = (params) => { + return WeaTools.callApi(`/api/bs/hrmorganization/commonimport/saveCommonImport`, 'POST', params); +} + + //获取导入结果 +export const getImportResult = (params) => { + return WeaTools.callApi(`/api/bs/hrmorganization/commonimport/getImportResult`, 'GET', params); +} \ No newline at end of file diff --git a/pc4mobx/organization/apis/resourceCard.js b/pc4mobx/organization/apis/resourceCard.js new file mode 100644 index 0000000..e69de29 diff --git a/pc4mobx/organization/components/Home.js b/pc4mobx/organization/components/Home.js index 9e68164..669915c 100644 --- a/pc4mobx/organization/components/Home.js +++ b/pc4mobx/organization/components/Home.js @@ -67,7 +67,6 @@ class Home extends React.Component {
- {/* */} {this.props.children} diff --git a/pc4mobx/organization/components/ImportDialog.js b/pc4mobx/organization/components/ImportDialog.js new file mode 100644 index 0000000..6f11810 --- /dev/null +++ b/pc4mobx/organization/components/ImportDialog.js @@ -0,0 +1,240 @@ +import { + WeaNewScroll, + WeaSearchGroup, + WeaMoreButton, + WeaDialog +} from 'ecCom' +import { + inject, + observer, +} from 'mobx-react' +import { + Spin, + Button, + Pagination, + Steps, + Upload, + Icon, + Row, + Col, + Progress +} from 'antd' + +import { + WeaSwitch, + WeaTableNew +} from 'comsMobx' + +import { + i18n +} from '../public/i18n'; +import { addContentPath } from '../util/index.js' + +const Step = Steps.Step; +const Dragger = Upload.Dragger; +const WeaTable = WeaTableNew.WeaTable; + + +@inject("importDialog") +@observer +export default class ImportDialog extends React.Component { + constructor(props) { + super(props); + this.state = { + width: 800, + height: 600, + title: '数据导入', + } + } + + getCircle() { + let style = { + width: 20, + height: 20, + backgroundColor: '#D8D8D8', + webkitBorderRadius: 10, + mozBorderRadius: 10, + msBorderRadius: 10, + oBorderRadius: 10, + borderRadius: 10, + //paddingLeft: 6, + textAlign: 'center', + } + return style; + } + + getIllustration(val, url, index, link) { + let p; + if (index == 0) { + p = (

{i18n.label.downLoadTemplete()}: {i18n.label.importTemplate()}

); + } else { + p = (

); + } + return p; + } + + next() { + const { importDialog } = this.props; + let { current, steps } = importDialog; + current = current + 1; + if (current === steps.length) { + current = 0; + importDialog.init(); + } + importDialog.current = current; + current === steps.length - 1 && importDialog.startImport(); + } + + getForm() { + const { + importDialog + } = this.props; + const { + condition + } = importDialog; + let _arr = []; + + condition.map((c, i) => { + let arr = []; + c.items.map((field, index) => { + arr.push({ + com: ( +
+ + +
+
{index + 1}
+
+ + + {this.getIllustration(field.value, field.link, index, field)} + + +
+
+ ), + colSpan: 1 + }) + }) + _arr.push(
) + + }); + return _arr; + } + + setFileId(fileInfo) { + const { importDialog } = this.props; + fileInfo.file.response && importDialog.setExcelfile(fileInfo.file.response.data.fileid); + importDialog.filelist = fileInfo.fileList; + } + + reRenderColumns(c) { + c.forEach(item => { + if (item.dataIndex == 'operatedetail') { + item.render = function (text, record) { + return {text} + } + } + }); + } + + render() { + const { + importDialog + } = this.props, { + importVisible,steps,current, pvisable, percent, failnum, succnum, importResultTip, importResultStore, importStatus, loading, date + } = importDialog, { + width, + height, + title + } = this.state; + + const buttons = [ + (), + ]; + + + const props = { + name: 'file', + action: '/api/doc/upload/uploadFile', + accept: '.xls,.xlsx', + multiple:false + + }; + + return ( + importDialog.init()} + buttons={buttons} + style={{ width: width, height: height }} + > +
+ + {steps.map((s, i) => )} + +
+
+ { + current == 0 && + { + this.setFileId(fileInfo) + } + } + > +
+

+ +

+

点击或将文件拖拽到此区域上传

+

支持单个或批量上传,严禁上传公司内部资料及其他违禁文件

+
+
+ {this.getForm()} +
+ } + { + current == 1 &&
+ { + importStatus == 'over' &&
+
0 ? '#54D3A2' : '#FF0000' }}> + 0 ? 'check' : 'cross'} style={{ color: '#fff' }} /> +
{importResultTip} +
+ } + { + failnum > 0 && + this.reRenderColumns(c)} + /> + } + importDialog.pvisable = false} + visible={pvisable} + style={{ width: 300, height: 50 }} + > +
+ +
+
+
+ } +
+ +
+ ) + } +} \ No newline at end of file diff --git a/pc4mobx/organization/components/fieldDefinedSet/FieldDefined.js b/pc4mobx/organization/components/fieldDefinedSet/FieldDefined.js index 26239ac..c25e4f5 100644 --- a/pc4mobx/organization/components/fieldDefinedSet/FieldDefined.js +++ b/pc4mobx/organization/components/fieldDefinedSet/FieldDefined.js @@ -186,7 +186,7 @@ export default class FieldDefined extends Component { } return ( -
+ hasRight &&
{children}
) diff --git a/pc4mobx/organization/components/resource/ResourceCard.js b/pc4mobx/organization/components/resource/ResourceCard.js new file mode 100644 index 0000000..e69de29 diff --git a/pc4mobx/organization/components/staff/Staff.js b/pc4mobx/organization/components/staff/Staff.js index 37fbfd0..5a0ce31 100644 --- a/pc4mobx/organization/components/staff/Staff.js +++ b/pc4mobx/organization/components/staff/Staff.js @@ -32,6 +32,7 @@ import { import '../../style/common.less'; import NewAndEditDialog from '../NewAndEditDialog'; +import ImportDialog from '../ImportDialog'; import { renderNoright } from '../../util'; @@ -42,6 +43,7 @@ const WeaTable = WeaTableNew.WeaTable; @inject('staff') +@inject('importDialog') @observer export default class Staff extends React.Component { constructor(props) { @@ -118,6 +120,16 @@ export default class Staff extends React.Component { staff.getForm(); } + import() { + const { + importDialog + } = this.props; + importDialog.importVisible=true; + importDialog.importModule='staff'; + importDialog.current = 0; + importDialog.getImportForm(); + } + log = () => { window.setLogViewProp({ @@ -221,14 +233,11 @@ export default class Staff extends React.Component { form2 } = staff; staff.setStaffName(val); - //!this.isEmptyObject(form2.getFormParams()) && staff.updateFields(val); } reRenderColumns(columns) { let _this = this; - // columns.forEach((c, index) => { - - // }) + return columns; } getTree = () => { @@ -461,12 +470,13 @@ export default class Staff extends React.Component { render() { const { - staff + staff,importDialog } = this.props; const { isPanelShow, form2, staffName, conditionNum, tableStore, nEdialogTitle, visible, condition, form, dialogLoading, isEdit, date, hasRight } = staff; + const {importVisible} = importDialog; if (hasRight === false) { return renderNoright(); @@ -529,6 +539,7 @@ export default class Staff extends React.Component { moduleName={"staff"} bindChangeEnvent={val => staff.updateConditions(val)} /> + {importVisible && }
) } diff --git a/pc4mobx/organization/stores/fieldDefined.js b/pc4mobx/organization/stores/fieldDefined.js index 037e602..d67de8a 100644 --- a/pc4mobx/organization/stores/fieldDefined.js +++ b/pc4mobx/organization/stores/fieldDefined.js @@ -1,7 +1,7 @@ /** * @Author: 程亮 * @Date: 2022-06-09 10:16:00 - * @LastEditTime: 2022-09-06 09:43:39 + * @LastEditTime: 2022-09-16 11:49:18 * @Description: * @FilePath: /trunk/src4js/pc4mobx/organization/stores/fieldDefined.js */ @@ -672,7 +672,6 @@ export class FieldDefinedStore extends HrmBaseStore { * @param {String} key [tabKey] * @return {null} */ - @observable hasRight = ''; @action setActiveTab = (tabConfig, key) => { tabConfig.activeTabKey = key || tabConfig.tabs[0].viewCondition; const tabIndex = this.getTabIndex(this.tabConfig.tabs, key); @@ -698,7 +697,6 @@ export class FieldDefinedStore extends HrmBaseStore { datas, selectedData } = this.convertData(res.data.data, 'fieldDef'); - this.hasRight = res.data.hasRight; this.encryptEnable = res.data.encryptEnable; this.tableEditConfig.fieldDef.datas = datas; this.tableEditConfig.fieldDef.columns = this.getColumns(); @@ -1377,11 +1375,25 @@ export class FieldDefinedStore extends HrmBaseStore { return this.selectedTreeNodeInfo && this.selectedTreeNodeInfo.domid == '-1'; } + @observable hasRight = ''; @action initResourceData = (module) => { this.selectedTreeNodeInfo = null; this.dropdownSelectedKey = '1'; this.moduleName = module; this.treeConfig.treeExpandKeys.length = 0; + api.getHasRight(this.moduleName).then(res => { + if (res.code === 200) { + this.hasRight = res.data.hasRight; + res.data.hasRight && this.initPage(); + } else { + message.error(res.msg); + } + }, error => { }) + + + } + + initPage = () => { api.getTree(this.moduleName).then(res => { if (res.code === 200) { // this.containerInitFinished = { diff --git a/pc4mobx/organization/stores/importDialog.js b/pc4mobx/organization/stores/importDialog.js new file mode 100644 index 0000000..210967c --- /dev/null +++ b/pc4mobx/organization/stores/importDialog.js @@ -0,0 +1,202 @@ +import { + observable, + action, + computed + } from 'mobx'; + import { + WeaForm + } from 'comsMobx'; + + import * as API from '../apis/importDialog'; + import * as Util from '../util/index'; + import { + validate, + getFormParamValue + } from '../util' + import { + message, + Modal, + Button + } from 'antd'; + import { + WeaTableNew + } from 'comsMobx' + import * as mobx from 'mobx'; + import isEmpty from 'lodash/isEmpty'; + import { + has + } from 'lodash'; + const toJS = mobx.toJS; + const { + TableStore + } = WeaTableNew; + const confirm = Modal.confirm; + import { + i18n + } from '../public/i18n'; + import { + findIndex + } from 'lodash'; + + export class ImportDialogStore { + + @observable importVisible = false; + @observable importModule = ''; //导入模块 + + + + /********************* importDialog *********************/ + + steps = [ + { title: '上传文件'}, + { title: '导入结果' } + ]; + + @observable importType = ''; + @observable current = 0; + @observable buttonTitle = ''; + @observable pvisable = false; + + + /********************* importContent *********************/ + @observable data = []; + + + @observable condition = []; + @observable filelist = []; //文件信息 + @observable excelfile = ''; //文件id + @observable templetName = "导入模板"; + @observable percent = 0; + @observable failnum = 0; //失败数量 + @observable succnum = 0; //成功数量 + @observable importResultTip = ''; //导入结果提示 + @observable importResultStore = new TableStore(); + @observable importStatus = 'importing'; //导入状态 + @observable loading = true; + @observable date = ''; + @observable pId = '';//导入记录 + + interval + + @action("获取导入表单") getImportForm() { + + const params = { + importModule: this.importModule, + } + API.getImportForm(params).then(res => { + if (res.code == 200) { + this.condition = res.data.condition; + } else { + message.warning(res.msg); + } + }, error => { + message.warning(error.msg); + }) + } + + @action("开始导入") startImport() { + if(this.filelist.length == 0) { + message.error("请上传需要导入的文件!") + this.current = this.current - 1; + return; + } + this.pvisable = true; + //导入文件提交 + let params = { + importModule: this.importModule, + excelfile:this.excelfile + } + if (this.otherParams != null) { + Object.assign(params, { + otherParams: JSON.stringify(this.otherParams) + }) + } + this.doImport(params) + this.interval = setInterval(() => this.getImportProcess(), 200); + + } + + @action("文件提交") doImport(params) { + API.saveImport(params).then(res => { + if(res.code == 200) { + this.pId = res.data.pId; + }else { + clearInterval(this.interval); + this.pvisable = false; + message.error("文件导入失败") + } + }) + } + + + + @action("获取导入进度") getImportProcess() { + if(this.pId != '') { + clearInterval(this.interval); + this.percent = 100; + const _this = this; + setTimeout(function(){ + _this.pvisable = false; + _this.getImportResult(); + },1000) + }else { + //调用导入进度api + let max = 95; + let min = this.percent; + if(this.percent < max) { + this.percent = Math.floor(Math.random() * (max - min)) + min; + } + + } + } + + @action("获取导入结果") getImportResult() { + let params = { + pId:this.pId + } + API.getImportResult(params).then((res) => { + if (res.code == 200) { + this.failnum = res.data.failnum; + this.succnum = res.data.succnum; + this.importStatus = res.data.importStatus; + if (this.failnum > 0) { + let info = i18n.label.importResourceResultInfo(); + info = info.replace('{rownum}', this.succnum + this.failnum).replace('{succnum}', this.succnum); + this.importResultTip = info; + this.importResultStore.getDatas(res.data.datas, 1); + } else { + let info = i18n.label.importResourceResultInfo1(); + info = info.replace('{rownum}', this.succnum); + this.importResultTip = info; + } + } else { + message.warning(res.msg); + } + }, error => { + message.warning(error.msg); + }) + } + + @action init(){ + this.filelist = []; + this.excelfile = ''; + this.importVisible = false; + this.percent = 0; + this.failnum = 0; + this.succnum = 0; + this.importResultTip = ''; + this.importResultStore = new TableStore(); + this.importStatus = 'importing'; + this.data = []; + this.condition = []; + this.pId = ''; + } + + + setExcelfile(field) { + this.excelfile = field; + } + + + + } \ No newline at end of file diff --git a/pc4mobx/organization/stores/index.js b/pc4mobx/organization/stores/index.js index 9648672..5c00af0 100644 --- a/pc4mobx/organization/stores/index.js +++ b/pc4mobx/organization/stores/index.js @@ -22,8 +22,9 @@ import {DatasImportStore} from "./datasImport"; import {HrmImportResource} from "./importresource"; import {HrmImportCommon} from "./importCommon"; import {HrmBasicDataImport} from "./import"; -import {newImportStore} from "./newImport"; -import {ResourceBasicInfoStore} from "./reserouseBasicInfo" +import {NewImportStore} from "./newImport"; +import {ResourceBasicInfoStore} from "./reserouseBasicInfo"; +import {ImportDialogStore} from "./importDialog"; module.exports = { @@ -51,6 +52,7 @@ module.exports = { hrmImportResource:new HrmImportResource(), hrmImportCommon:new HrmImportCommon(), hrmBasicDataImport:new HrmBasicDataImport(), - newImport: new newImportStore(), + newImport: new NewImportStore(), resourceBasicInfo: new ResourceBasicInfoStore(), + importDialog: new ImportDialogStore() }; diff --git a/pc4mobx/organization/stores/newImport.js b/pc4mobx/organization/stores/newImport.js index 220dd76..8fe6448 100644 --- a/pc4mobx/organization/stores/newImport.js +++ b/pc4mobx/organization/stores/newImport.js @@ -38,7 +38,7 @@ import { findIndex } from 'lodash'; -export class newImportStore { +export class NewImportStore { @observable hasRight = ''; @action getHasRight(){ diff --git a/pc4mobx/organization/stores/resourceCard.js b/pc4mobx/organization/stores/resourceCard.js new file mode 100644 index 0000000..de4b4a6 --- /dev/null +++ b/pc4mobx/organization/stores/resourceCard.js @@ -0,0 +1,231 @@ +import { observable, action, toJS } from "mobx"; +import isEmpty from 'lodash/isEmpty' +import { Modal, message } from "antd"; +import { i18n } from "../public/i18n"; +import forEach from 'lodash/forEach' +import * as Api from '../apis/resourceCard'; // 引入API接口文件 + + +export class ResourceExtendStore { + @observable form = new WeaForm(); + @observable tableInfo = [] + @observable conditions = []; + @observable isEditor = false; + @observable isNew = true; + @observable loading = true; + @observable tabInfo = []; + @observable selectedKey = '0'; + @observable detailSelectedKey = '0'; + @observable topTab = []; + @observable buttons = {}; + @observable id = ''; //人员id + @observable date = ''; + @observable personalEditTables; + @observable tabkey = '0' + + + @observable selectedRowKeys = []; + @observable selectedRows = []; + + @action onRowSelect = (keys) => { + this.setSelectedRowKeys(keys); + } + + @action setSelectedRowKeys = (keys) => { + this.selectedRowKeys = keys; + } + + + @action + edit = () => { + this.isEditor = true; + this.getData(); + this.getTabInfo(); + this.detailSelectedKey = '0' + } + + init = () => { + this.detailSelectedKey = '0' + this.isEditor = false; + } + + save = () => { + if (this.loading) + return; + this.form.validateForm().then(f => { + if (f.isValid) { + this.loading = true; + if (this.personalEditTables) { + const targetDatas = this.tableInfo[this.detailSelectedKey].tabinfo.datas, + isPass = (targetDatas.length > 0) ? this.personalEditTables.refs.edit.doRequiredCheck().pass : true + if (isPass) { + this.editResource() + } else { + this.loading = false; + } + } else { + this.editResource(); + } + } else { + f.showErrors(); + this.setDate(new Date()); + this.loading = false; + } + }) + } + + editResource = () => { + let pDatas = this.form.getFormParams(); + Api.editResource({ ...{ + id: this.id + }, + ...pDatas, + ...this.getTableEditParams() + }).then(data => { + if (data.code == 200) { + message.success(i18n.message.saveSuccess()); + this.init(); + this.getData(); + this.selectedRowKeys = []; + } else { + message.warning(data.message); + } + this.loading = false; + }, error => { + message.warning(error.message); + this.loading = false; + }) + } + + getTableEditParams = () => { + const params = {}; + this.tableInfo && this.tableInfo.forEach(t => { + t.tabinfo.datas = t.tabinfo.datas || []; + params[t.tabinfo.rownum] = t.tabinfo.datas.length; + t.tabinfo && t.tabinfo.datas && t.tabinfo.datas.forEach((item, index) => { + !isEmpty(item) && forEach(item, (value, key) => { + Object.assign(params, { + [`${key}_${index}`]: value + }); + }) + }) + }) + return params + } + + + + getData = () => { + this.setLoading(true); + let params = { + viewAttr: this.isEditor ? 2 : 1, + id: this.id, + viewCondition:this.selectedKey + } + Api.getResourceExtendForm(params).then((res) => { + if (res.code === 200) { + res.data.result.conditions && this.form.initFormFields(res.data.result.conditions); + res.data.result.conditions && this.setConditions(res.data.result.conditions); + this.tableInfo = this.handleTable(res.data.result.tables); + this.getTabInfo(); + res.data.result.buttons && this.setButtons(res.data.result.buttons); + res.data.result.tabInfo && this.setTopTab(res.data.result.tabInfo); + this.isEditor && this.getSelectedRows(); + this.setLoading(false); + + } else { + message.warning(res.msg); + } + }, error => { + message.warning(error.msg); + }) + } + + handleTable = (datas) => { + return datas && datas.map(data => { + const { tabinfo: { columns } } = data; + const length = columns.length; + columns.map(c => { + c.width = `${95 / length}%` + }) + return data + }) + } + + getTabInfo = () => { + this.tabInfo = []; + this.tableInfo && this.tableInfo.forEach((c, idx) => { + if (!c.hide) { + this.tabInfo.push({ + key: `${idx}`, + title: c.tabname, + }) + } + }) + //if (!isEmpty(this.tabInfo)) this.tabkey = this.tabInfo[0].key; + if (!isEmpty(this.tabInfo)) this.detailSelectedKey = this.tabInfo[0].key; + } + + setLoading(val) { + this.loading = val; + } + + + updateTabKey = (key) => { + this.tabKey = key; + } + + updateDetailSelectedKey =(key) => { + this.detailSelectedKey = key; + } + + updateTableInfo = (data) => { + this.tableInfo = data + } + + setSelectedKey = (key) => { + this.selectedKey = key; + } + + getSelectedRows = () => { + const selectedRows = []; + this.tableInfo.forEach(t => { + const singleTableRows = []; + t.tabinfo.datas.forEach((data, i) => { + if (data.viewAttr === 1) { + singleTableRows.push(i); + } + }); + selectedRows.push(singleTableRows); + }) + this.selectedRows = selectedRows; + } + + + setTopTab(topTab) { + this.topTab = topTab; + } + + changeData(key) { + this.setSelectedKey(key); + this.getData(); + } + + setId(id) { + this.id = id; + } + + setPersonalEditTables = (ref) => { + this.personalEditTables = ref; + } + + setConditions(conditions) { + this.conditions = conditions; + } + + setButtons(buttons) { + this.buttons = buttons; + } + + +}