page.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. import React from 'react';
  2. import { Form, Button, Row, Col, Upload } from 'antd';
  3. import './index.less';
  4. // import Editor from '@src/components/Editor';
  5. import Page from '@src/containers/Page';
  6. import Block from '@src/components/Block';
  7. // import Radio from '@src/components/Radio';
  8. // import TreeSelect from '@src/components/TreeSelect';
  9. // import EditTableCell from '@src/components/EditTableCell';
  10. import ActionLayout from '@src/layouts/ActionLayout';
  11. import TableLayout from '@src/layouts/TableLayout';
  12. import { formatDate } from '@src/services/Tools';
  13. import { asyncSMessage, asyncForm, asyncDelConfirm } from '@src/services/AsyncTools';
  14. // import { SwitchSelect, DataType } from '../../../../Constant';
  15. // import { User } from '../../../stores/user';
  16. // import { Exercise } from '../../../stores/exercise';
  17. import { Course } from '../../../stores/course';
  18. import { System } from '../../../stores/system';
  19. export default class extends Page {
  20. initState() {
  21. return { history: false };
  22. }
  23. init() {
  24. this.exerciseMap = {};
  25. this.actionList = [{
  26. key: 'addHistory',
  27. type: 'primary',
  28. name: '新增版本',
  29. }];
  30. this.itemList = [{
  31. key: 'id',
  32. type: 'hidden',
  33. }, {
  34. key: 'dataId',
  35. type: 'hidden',
  36. }, {
  37. key: 'time',
  38. type: 'date',
  39. name: '更新时间',
  40. }, {
  41. key: 'position',
  42. type: 'input',
  43. name: '更新位置',
  44. }, {
  45. key: 'originContent',
  46. type: 'input',
  47. name: '原内容',
  48. }, {
  49. key: 'content',
  50. type: 'input',
  51. name: '更改为',
  52. }, {
  53. key: 'version',
  54. type: 'input',
  55. name: '更新至',
  56. }];
  57. this.columns = [{
  58. title: '更新时间',
  59. dataIndex: 'time',
  60. render: (text) => {
  61. return formatDate(text);
  62. },
  63. }, {
  64. title: '版本名称',
  65. dataIndex: 'version',
  66. }, {
  67. title: '位置',
  68. dataIndex: 'position',
  69. }, {
  70. title: '原内容',
  71. dataIndex: 'originContent',
  72. }, {
  73. title: '更正为',
  74. dataIndex: 'content',
  75. }, {
  76. title: '更新至',
  77. dataIndex: 'version',
  78. }, {
  79. title: '操作',
  80. dataIndex: 'handler',
  81. render: (text, record) => {
  82. return <div className="table-button">
  83. {(
  84. <a onClick={() => {
  85. this.changeHistory(record);
  86. }}>编辑</a>
  87. )}
  88. {(
  89. <a onClick={() => {
  90. this.deleteHistory(record);
  91. }}>删除</a>
  92. )}
  93. </div>;
  94. },
  95. }];
  96. }
  97. initData() {
  98. const { id } = this.params;
  99. let handler;
  100. if (id) {
  101. handler = Course.getData({ id });
  102. } else {
  103. handler = Promise.resolve({ structId: 0 });
  104. }
  105. handler
  106. .then(result => {
  107. const { setFieldsValue } = this.props.form;
  108. setFieldsValue(result);
  109. this.setState({ data: result });
  110. this.refreshHistory();
  111. });
  112. }
  113. refreshHistory() {
  114. const { id } = this.params;
  115. Course.listDataHistory({ dataId: id }).then(result => {
  116. this.setState({ list: result.list, total: result.total, history: true });
  117. });
  118. }
  119. addHistoryAction() {
  120. const { id } = this.params;
  121. asyncForm('创建', this.itemList, { dataId: id }, data => {
  122. return Course.addDataHistory(data).then(() => {
  123. asyncSMessage('添加成功!');
  124. this.refreshHistory();
  125. });
  126. });
  127. }
  128. changeHistory(record) {
  129. asyncForm('修改', this.itemList, record, data => {
  130. return Course.editDataHistory(data).then(() => {
  131. asyncSMessage('修改成功!');
  132. this.refreshHistory();
  133. });
  134. });
  135. }
  136. deleteHistory(record) {
  137. asyncDelConfirm('删除确认', '是否删除选中记录?', () => {
  138. return Course.delDataHistory(record).then(() => {
  139. asyncSMessage('删除成功!');
  140. this.refreshHistory();
  141. });
  142. });
  143. }
  144. renderFile() {
  145. const { getFieldDecorator, setFieldsValue, getFieldValue } = this.props.form;
  146. const resource = getFieldValue('resource');
  147. const trailResource = getFieldValue('trailResource');
  148. return <Block>
  149. <h1>资料文件</h1>
  150. <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='正式版本'>
  151. {resource && <a href={resource} target="_blank">访问</a>}
  152. {getFieldDecorator('resource', {
  153. rules: [
  154. { required: true, message: '上传文件' },
  155. ],
  156. })(
  157. <Upload
  158. showUploadList={false}
  159. beforeUpload={(file) => System.uploadImage(file).then((result) => {
  160. setFieldsValue({ resource: result.url });
  161. return Promise.reject();
  162. })}
  163. >
  164. <Button>上传文件</Button>
  165. </Upload>,
  166. )}
  167. </Form.Item>
  168. <Form.Item labelCol={{ span: 5 }} wrapperCol={{ span: 16 }} label='试用版本'>
  169. {trailResource && <a href={trailResource} target="_blank">访问</a>}
  170. {getFieldDecorator('trailResource', {
  171. rules: [
  172. { required: true, message: '上传文件' },
  173. ],
  174. })(
  175. <Upload
  176. showUploadList={false}
  177. beforeUpload={(file) => System.uploadImage(file).then((result) => {
  178. setFieldsValue({ trailResource: result.url });
  179. return Promise.reject();
  180. })}
  181. >
  182. <Button>上传文件</Button>
  183. </Upload>,
  184. )}
  185. </Form.Item>
  186. </Block>;
  187. }
  188. renderHistory() {
  189. return <Block>
  190. <h1>资料版本</h1>
  191. <ActionLayout
  192. itemList={this.actionList}
  193. selectedKeys={this.state.selectedKeys}
  194. onAction={key => this.onAction(key)}
  195. />
  196. <TableLayout
  197. columns={this.tableSort(this.columns)}
  198. list={this.state.list}
  199. pagination={false}
  200. loading={this.props.core.loading}
  201. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  202. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  203. selectedKeys={this.state.selectedKeys}
  204. />
  205. </Block>;
  206. }
  207. renderView() {
  208. const { history } = this.state;
  209. return <div flex>
  210. {this.renderFile()}
  211. {history && this.renderHistory()}
  212. <Row type="flex" justify="center">
  213. <Col>
  214. <Button type="primary" onClick={() => {
  215. this.submit();
  216. }}>保存</Button>
  217. </Col>
  218. </Row>
  219. </div>;
  220. }
  221. }