page.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. import React from 'react';
  2. import './index.less';
  3. import Page from '@src/containers/Page';
  4. import Block from '@src/components/Block';
  5. import FilterLayout from '@src/layouts/FilterLayout';
  6. // import ActionLayout from '@src/layouts/ActionLayout';
  7. import TableLayout from '@src/layouts/TableLayout';
  8. import { bindSearch, formatDate } from '@src/services/Tools';
  9. import { asyncSMessage, asyncDelConfirm } from '@src/services/AsyncTools';
  10. // import { QuestionType, AnswerStatus, MoneyRange, SwitchSelect, AskTarget } from '../../../../Constant';
  11. import { User } from '../../../stores/user';
  12. export default class extends Page {
  13. init() {
  14. this.filterForm = [{
  15. key: 'userId',
  16. type: 'select',
  17. allowClear: true,
  18. name: '用户',
  19. select: [],
  20. number: true,
  21. placeholder: '请输入',
  22. }, {
  23. key: 'totalAlert',
  24. type: 'number',
  25. allowClear: true,
  26. name: '警告次数',
  27. number: true,
  28. }, {
  29. key: 'time',
  30. type: 'daterange',
  31. name: '注册时间',
  32. }];
  33. this.columns = [{
  34. title: '登录时间',
  35. dataIndex: 'createTime',
  36. render: (text) => {
  37. return formatDate(text, 'YYYY-MM-DD HH:mm:ss');
  38. },
  39. }, {
  40. title: '用户id',
  41. dataIndex: 'user.id',
  42. }, {
  43. title: '手机号',
  44. dataIndex: 'user.mobile',
  45. }, {
  46. title: '昵称',
  47. dataIndex: 'user.nickname',
  48. }, {
  49. title: '注册时间',
  50. dataIndex: 'user.createTime',
  51. render: (text) => {
  52. return formatDate(text, 'YYYY-MM-DD HH:mm:ss');
  53. },
  54. }, {
  55. title: '注册ip',
  56. dataIndex: 'user.registerIp',
  57. }, {
  58. title: '注册地',
  59. dataIndex: 'user.registerCity',
  60. }, {
  61. title: '本次登录ip',
  62. dataIndex: 'loginIp',
  63. }, {
  64. title: '本次登录地',
  65. dataIndex: 'loginCity',
  66. }, {
  67. title: '累计警告次数',
  68. dataIndex: 'user.totalAlert',
  69. }, {
  70. title: '操作',
  71. dataIndex: 'handler',
  72. render: (text, record) => {
  73. return <div className="table-button">
  74. {!!record.isIgnore && '已忽略'}
  75. {!!record.isAlert && '已警告'}
  76. {!!record.user.isFrozen && (
  77. <a onClick={() => {
  78. this.noFrozenAction(record);
  79. }}>取消封禁</a>
  80. )}
  81. {!record.user.isFrozen && (
  82. <a onClick={() => {
  83. this.frozenAction(record);
  84. }}>封禁</a>
  85. )}
  86. {!record.isIgnore && !record.isAlert && (
  87. <a onClick={() => {
  88. this.alertAction(record);
  89. }}>警告</a>
  90. )}
  91. {!record.isIgnore && !record.isAlert && (
  92. <a onClick={() => {
  93. this.ignoreAction(record);
  94. }}>忽略</a>
  95. )}
  96. </div>;
  97. },
  98. }];
  99. bindSearch(this.filterForm, 'userId', this, (search) => {
  100. return User.list(search);
  101. }, (row) => {
  102. return {
  103. title: `${row.nickname}(${row.mobile})`,
  104. value: row.id,
  105. };
  106. }, this.state.search.userId ? Number(this.state.search.userId) : null, null);
  107. }
  108. initData() {
  109. const { search } = this.state;
  110. const data = Object.assign({}, search);
  111. if (data.time) {
  112. data.startTime = data.time[0] || '';
  113. data.endTime = data.time[1] || '';
  114. }
  115. User.listAbnormal(data).then(result => {
  116. this.setTableData(result.list, result.total);
  117. });
  118. }
  119. alertAction(row) {
  120. asyncDelConfirm('警告确认', '是否警告选中记录?', () => {
  121. return User.handleAbnormal({ id: row.id, isAlert: 1 }).then(() => {
  122. asyncSMessage('操作成功!');
  123. this.refresh();
  124. });
  125. });
  126. }
  127. ignoreAction(row) {
  128. asyncDelConfirm('忽略确认', '是否忽略选中记录?', () => {
  129. return User.handleAbnormal({ id: row.id, isIgnore: 1 }).then(() => {
  130. asyncSMessage('操作成功!');
  131. this.refresh();
  132. });
  133. });
  134. }
  135. frozenAction(row) {
  136. asyncDelConfirm('封禁确认', '是否封禁选中用户?', () => {
  137. return User.frozen({ id: row.userId }).then(() => {
  138. asyncSMessage('操作成功!');
  139. this.refresh();
  140. });
  141. });
  142. }
  143. noFrozenAction(row) {
  144. asyncDelConfirm('取消封禁确认', '是否取消封禁选中用户?', () => {
  145. return User.noFrozen({ id: row.userId }).then(() => {
  146. asyncSMessage('操作成功!');
  147. this.refresh();
  148. });
  149. });
  150. }
  151. renderView() {
  152. return <Block flex>
  153. <FilterLayout
  154. show
  155. itemList={this.filterForm}
  156. data={this.state.search}
  157. onChange={data => {
  158. if (data.time.length > 0) {
  159. data.time = [data.time[0].format('YYYY-MM-DD 00:00:00'), data.time[1].format('YYYY-MM-DD 23:59:59')];
  160. }
  161. data.page = 1;
  162. this.search(data);
  163. }} />
  164. {/* <ActionLayout
  165. itemList={this.actionList}
  166. selectedKeys={this.state.selectedKeys}
  167. onAction={key => this.onAction(key)}
  168. /> */}
  169. <TableLayout
  170. select
  171. columns={this.tableSort(this.columns)}
  172. list={this.state.list}
  173. pagination={this.state.page}
  174. loading={this.props.core.loading}
  175. onChange={(pagination, filters, sorter) => this.tableChange(pagination, filters, sorter)}
  176. onSelect={(keys, rows) => this.tableSelect(keys, rows)}
  177. selectedKeys={this.state.selectedKeys}
  178. />
  179. </Block>;
  180. }
  181. }