page.js 6.2 KB

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