terminal.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. import { message } from 'antd';
  2. import { routerRedux } from 'dva/router';
  3. import {
  4. deviceUnbound,
  5. queryTerminalList,
  6. createTerminalItem,
  7. updateTerminalItem,
  8. deleteTerminalItem,
  9. querySpecialTerminalList,
  10. querySpecialTerminalItem,
  11. createSpecialTerminalItem,
  12. updateSpecialTerminalItem,
  13. deleteSpecialTerminalItem,
  14. queryTerminalAuthList,
  15. updateTerminalAuth,
  16. queryTerminalTagList,
  17. queryTerminalTagItem,
  18. createTerminalTagItem,
  19. updateTerminalTagItem,
  20. deleteTerminalTagItem,
  21. queryTerminalRecommendCourse,
  22. updateTerminalRecommendCourse,
  23. copyMerchantTag,
  24. queryTerminalLoggedDevice,
  25. } from '../services/terminal';
  26. export default {
  27. namespace: 'terminal',
  28. state: {
  29. list: [],
  30. pageNo: 1,
  31. pageSize: 15,
  32. totalSize: 0,
  33. currentItem: {},
  34. userTagList: [],
  35. userRecCourse: [],
  36. currentUserTagItem: {},
  37. currentUserLoggedRecs: [],
  38. },
  39. effects: {
  40. *fetchTerminalList({ payload }, { call, put }) {
  41. const response = yield call(queryTerminalList, payload);
  42. if (response.success) {
  43. yield put({
  44. type: 'querySuccess',
  45. payload: {
  46. list: response.data.list || [],
  47. pageSize: response.data.pageSize,
  48. totalSize: response.data.totalSize,
  49. pageNo: response.data.pageNo,
  50. },
  51. });
  52. }
  53. },
  54. *createTerminalItem({ payload, state }, { call, put }) {
  55. const response = yield call(createTerminalItem, payload);
  56. if (response.success) {
  57. message.success('创建终端成功');
  58. yield put(routerRedux.push({
  59. state,
  60. pathname: '/terminal/user/list',
  61. }));
  62. }
  63. },
  64. *deleteTerminalItem({ payload, states }, { call, put }) {
  65. const response = yield call(deleteTerminalItem, payload);
  66. if (response.success) {
  67. message.success('禁用终端成功');
  68. yield put({
  69. type: 'fetchTerminalList',
  70. payload: states.Queryers,
  71. });
  72. }
  73. },
  74. *recoverTerminalItem({ payload, states }, { call, put }) {
  75. const response = yield call(updateTerminalItem, payload);
  76. if (response.success) {
  77. message.success('解禁终端成功');
  78. yield put({
  79. type: 'fetchTerminalList',
  80. payload: states.Queryers,
  81. });
  82. }
  83. },
  84. *updateTerminalItem({ payload, states }, { call, put }) {
  85. const response = yield call(updateTerminalItem, payload);
  86. if (response.success) {
  87. message.success('修改终端成功');
  88. yield put(routerRedux.push({
  89. pathname: '/terminal/user/list',
  90. state: states,
  91. }));
  92. }
  93. },
  94. *fetchSpecialTerminalList({ payload }, { call, put }) {
  95. const response = yield call(querySpecialTerminalList, payload);
  96. if (response.success) {
  97. yield put({
  98. type: 'querySuccess',
  99. payload: {
  100. list: response.data.list || [],
  101. pageSize: response.data.pageSize,
  102. totalSize: response.data.totalSize,
  103. pageNo: response.data.pageNo,
  104. },
  105. });
  106. }
  107. },
  108. *fetchSpecialTerminalItem({ payload }, { call, put }) {
  109. const response = yield call(querySpecialTerminalItem, payload);
  110. if (response.success) {
  111. yield put({
  112. type: 'querySuccess',
  113. payload: {
  114. currentItem: response.data,
  115. },
  116. });
  117. }
  118. },
  119. *createSpecialTerminalItem({ payload, states }, { call, put }) {
  120. const response = yield call(createSpecialTerminalItem, payload);
  121. if (response.success) {
  122. message.success('创建白名单用户成功');
  123. yield put(routerRedux.push({
  124. state: states,
  125. pathname: '/terminal/whitelist/list',
  126. }));
  127. }
  128. },
  129. *deleteSpecialTerminalItem({ payload, states }, { call, put }) {
  130. const response = yield call(deleteSpecialTerminalItem, payload);
  131. if (response.success) {
  132. message.success('删除白名单用户成功');
  133. yield put({
  134. type: 'fetchSpecialTerminalList',
  135. payload: states.Queryers,
  136. });
  137. }
  138. },
  139. *updateSpecialTerminalItem({ payload, states }, { call, put }) {
  140. const response = yield call(updateSpecialTerminalItem, payload);
  141. if (response.success) {
  142. message.success('修改白名单用户成功');
  143. yield put(routerRedux.push({
  144. pathname: '/terminal/whitelist/list',
  145. state: states,
  146. }));
  147. }
  148. },
  149. *deviceUnbound({ payload, states }, { call, put }) {
  150. const response = yield call(deviceUnbound, payload);
  151. if (response.success) {
  152. message.success('账号已成功解绑');
  153. yield put({
  154. type: 'fetchTerminalList',
  155. payload: states.Queryers,
  156. });
  157. }
  158. },
  159. *fetchTerminalAuthList({ payload }, { call, put }) {
  160. const response = yield call(queryTerminalAuthList, payload);
  161. if (response.success) {
  162. yield put({
  163. type: 'querySuccess',
  164. payload: {
  165. list: response.data.list || [],
  166. pageSize: response.data.pageSize,
  167. totalSize: response.data.totalSize,
  168. pageNo: response.data.pageNo,
  169. },
  170. });
  171. }
  172. },
  173. *updateTerminalAuth({ payload, states }, { call, put }) {
  174. const response = yield call(updateTerminalAuth, payload);
  175. if (response.success) {
  176. message.success('修改权限时长成功');
  177. yield put({
  178. type: 'fetchTerminalAuthList',
  179. payload: states,
  180. });
  181. }
  182. },
  183. *fetchTerminalTagList({ payload }, { call, put }) {
  184. const response = yield call(queryTerminalTagList, payload);
  185. if (response.success) {
  186. yield put({
  187. type: 'querySuccess',
  188. payload: {
  189. userTagList: response.data || [],
  190. },
  191. });
  192. }
  193. },
  194. *fetchTerminalTagItem({ payload }, { call, put }) {
  195. const response = yield call(queryTerminalTagItem, payload);
  196. if (response.success) {
  197. yield put({
  198. type: 'querySuccess',
  199. payload: {
  200. currentUserTagItem: response.data || {},
  201. },
  202. });
  203. }
  204. },
  205. *createTerminalTagItem({ payload }, { call, put }) {
  206. const response = yield call(createTerminalTagItem, payload);
  207. if (response.success) {
  208. message.success('终端用户标签创建成功');
  209. const { uid } = payload;
  210. yield put({
  211. type: 'fetchTerminalTagList',
  212. payload: { uid },
  213. });
  214. }
  215. },
  216. *updateTerminalTagItem({ payload }, { call, put }) {
  217. const response = yield call(updateTerminalTagItem, payload);
  218. if (response.success) {
  219. message.success('终端用户标签修改成功');
  220. const { uid } = payload;
  221. yield put({
  222. type: 'fetchTerminalTagList',
  223. payload: { uid },
  224. });
  225. }
  226. },
  227. *deleteTerminalTagItem({ payload }, { call, put }) {
  228. const response = yield call(deleteTerminalTagItem, payload);
  229. if (response.success) {
  230. message.success('终端用户标签删除成功');
  231. const { uid } = payload;
  232. yield put({
  233. type: 'fetchTerminalTagList',
  234. payload: { uid },
  235. });
  236. }
  237. },
  238. *copyMerchantTagToUser({ payload }, { call, put }) {
  239. const { uid, ...rest } = payload;
  240. const response = yield call(copyMerchantTag, rest);
  241. if (response.success) {
  242. message.success('复制渠道标签成功');
  243. yield put({
  244. type: 'fetchTerminalTagList',
  245. payload: { uid },
  246. });
  247. }
  248. },
  249. *fetchTerminalRecommendCourse({ payload }, { call, put }) {
  250. const response = yield call(queryTerminalRecommendCourse, payload);
  251. if (response.success) {
  252. yield put({
  253. type: 'querySuccess',
  254. payload: {
  255. userRecCourse: response.data || [],
  256. },
  257. });
  258. }
  259. },
  260. *updateTerminalRecommendCourse({ payload }, { call, put }) {
  261. const response = yield call(updateTerminalRecommendCourse, payload);
  262. if (response.success) {
  263. message.success('修改用户推荐课程成功');
  264. const { uid } = payload;
  265. yield put({
  266. type: 'fetchTerminalRecommendCourse',
  267. payload: { uid },
  268. });
  269. }
  270. },
  271. *fetchTerminalLoggedDevice({ payload }, { call, put }) {
  272. const response = yield call(queryTerminalLoggedDevice, payload);
  273. if (response.success) {
  274. yield put({
  275. type: 'querySuccess',
  276. payload: {
  277. currentUserLoggedRecs: response.data || [],
  278. },
  279. });
  280. }
  281. },
  282. },
  283. reducers: {
  284. querySuccess(state, action) {
  285. return {
  286. ...state,
  287. ...action.payload,
  288. };
  289. },
  290. fixCurrentItem(state, action) {
  291. const { currentItem } = state;
  292. return {
  293. ...state,
  294. currentItem: {
  295. ...currentItem,
  296. ...action.payload,
  297. },
  298. };
  299. },
  300. fixCurrentUserTagItem(state, action) {
  301. const { currentUserTagItem } = state;
  302. return {
  303. ...state,
  304. currentUserTagItem: {
  305. ...currentUserTagItem,
  306. ...action.payload,
  307. },
  308. };
  309. },
  310. fixUserRecCourse(state, action) {
  311. return {
  312. ...state,
  313. userRecCourse: action.payload,
  314. };
  315. },
  316. cleanState(state) {
  317. return {
  318. ...state,
  319. list: [],
  320. pageNo: 1,
  321. pageSize: 15,
  322. totalSize: 0,
  323. userTagList: [],
  324. userRecCourse: [],
  325. currentItem: {},
  326. currentUserTagItem: {},
  327. };
  328. },
  329. resetUserTagItem(state) {
  330. return {
  331. ...state,
  332. currentUserTagItem: {},
  333. };
  334. },
  335. },
  336. };