dashboard.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. import { message } from 'antd'
  2. import * as service from '../services/index'
  3. import URLS from '../constants/url'
  4. export default {
  5. namespace: 'dashboard',
  6. state: {
  7. list: [],
  8. filterLabel: '',
  9. groupList: [],
  10. currentGroup: [{
  11. code: 'all',
  12. label: '全部分组'
  13. }],
  14. groupDirty: false,
  15. },
  16. reducers: {
  17. list(state, action) {
  18. let list = action.list;
  19. return Object.assign({}, state, {list});
  20. },
  21. setFilterLabel(state, action) {
  22. let { label } = action;
  23. return Object.assign({}, state, {filterLabel: label});
  24. }
  25. },
  26. effects: {
  27. *fetchList(action, {select, call, put}) {
  28. try {
  29. const dashboard = yield select(state => state.present.dashboard);
  30. if(!action.mandatory && dashboard.list.length > 0) {
  31. return;
  32. }
  33. const res = yield call(service.fetch, {
  34. url: URLS.DASHBOARD_LIST
  35. });
  36. if(!res.err && res.data.code > 0) {
  37. const resData = res.data.data;
  38. let list = resData.map(d => {
  39. let items = d.bdConfiguration ? JSON.parse(d.bdConfiguration) : [];
  40. return {
  41. code: d.id+'',
  42. name: d.bdName,
  43. items: items,
  44. description: d.bdNote || '',
  45. thumbnail: d.thumbnail,
  46. creator: d.createBy,
  47. createTime: d.createDate,
  48. }
  49. })
  50. console.log('请求看板列表', list);
  51. yield put({ type: 'list', list: list });
  52. }else {
  53. message.error('请求看板列表失败: ' + res.err || res.data.msg);
  54. }
  55. }catch(e) {
  56. console.log(e);
  57. message.error('请求看板列表失败')
  58. }
  59. },
  60. *remoteDetail(action, { select, call, put }) {
  61. const code = action.code;
  62. if(!code){
  63. return
  64. }
  65. try {
  66. const res = yield call(service.fetch, {
  67. url: URLS.DASHBOARD_DETAIL,
  68. body: code
  69. });
  70. console.log('解析看板数据', code, res);
  71. if(!res.err && res.data.code > 0) {
  72. const resData = res.data.data;
  73. let items = resData.bdConfiguration ? JSON.parse(resData.bdConfiguration) : [];
  74. let data = {
  75. code: resData.id+'',
  76. name: resData.bdName,
  77. items: items,
  78. description: resData.bdNote || '',
  79. thumbnail: resData.thumbnail,
  80. creator: resData.createBy,
  81. createTime: resData.createDate,
  82. }
  83. let fields = [];
  84. for(let key in data) {
  85. fields.push({
  86. name: key,
  87. value: data[key]
  88. })
  89. }
  90. yield put({ type: 'dashboardDesigner/silentSetFields', fields: fields });
  91. }else {
  92. message.error('解析看板错误: ' + (res.err || res.data.msg));
  93. }
  94. }catch(e) {
  95. console.log(e);
  96. message.error('解析看板错误');
  97. }
  98. },
  99. *remoteAdd(action, { select, call, put }) {
  100. try {
  101. const dashboardDesigner = yield select(state => state.present.dashboardDesigner);
  102. const { name, items, thumbnail } = dashboardDesigner;
  103. let body = {
  104. bdName: name,
  105. bdNote: '',
  106. bdConfiguration: JSON.stringify(items),
  107. thumbnail: thumbnail,
  108. createBy: 'zhuth'
  109. }
  110. console.log('新增看板', body);
  111. const res = yield call(service.fetch, {
  112. url: URLS.DASHBOARD_ADD,
  113. body: body
  114. });
  115. console.log('新增看板', body, res);
  116. if(!res.err && res.data.code > 0) {
  117. yield put({ type: 'fetchList', mandatory: true });
  118. message.success('保存成功');
  119. }else {
  120. message.error('保存失败: ' + (res.err || res.data.msg));
  121. }
  122. }catch(e) {
  123. console.log(e);
  124. message.error('保存失败');
  125. }
  126. },
  127. *remoteQucikAdd(action, { select, call, put }) {
  128. try {
  129. const dashboardDesigner = yield select(state => state.present.dashboardDesigner);
  130. const { name, items } = dashboardDesigner;
  131. let body = {
  132. bdName: name,
  133. bdNote: '',
  134. bdConfiguration: JSON.stringify(items),
  135. thumbnail: '',
  136. createBy: 'zhuth'
  137. }
  138. console.log('快速新增看板', body);
  139. const res = yield call(service.fetch, {
  140. url: URLS.DASHBOARD_ADD,
  141. body: body
  142. });
  143. console.log('快速新增看板', body, res);
  144. if(!res.err && res.data.code > 0) {
  145. yield put({ type: 'fetchList', mandatory: true });
  146. yield put({ type: 'main/redirect', path: '/dashboard/' + res.data.data });
  147. }else {
  148. message.error('保存失败: ' + (res.err || res.data.msg));
  149. }
  150. }catch(e) {
  151. console.log(e);
  152. message.error('保存失败');
  153. }
  154. },
  155. *remoteModify(action, { select, call, put }) {
  156. try {
  157. const dashboardDesigner = yield select(state => state.present.dashboardDesigner);
  158. const { code, name, items, thumbnail } = dashboardDesigner;
  159. let body = {
  160. id: code,
  161. bdName: name,
  162. bdNote: '',
  163. bdConfiguration: JSON.stringify(items),
  164. thumbnail: thumbnail,
  165. createBy: 'zhuth'
  166. }
  167. console.log('修改看板', body);
  168. const res = yield call(service.fetch, {
  169. url: URLS.DASHBOARD_UPDATE,
  170. body: body
  171. });
  172. console.log('修改看板', body, res);
  173. if(!res.err && res.data.code > 0) {
  174. yield put({ type: 'fetchList', mandatory: true });
  175. yield put({ type: 'dashboardDesigner/silentSetField', name: 'dirty', value: false });
  176. message.success('保存成功');
  177. }else {
  178. message.error('保存失败: ' + (res.err || res.data.msg));
  179. }
  180. }catch(e) {
  181. console.log(e);
  182. message.error('保存失败');
  183. }
  184. },
  185. *remoteDelete(action, { select, call, put }) {
  186. const dashboard = yield select(state => state.present.dashboard);
  187. const code = action.code;
  188. let list = dashboard.list;
  189. try {
  190. const res = yield call(service.fetch, {
  191. url: URLS.DASHBOARD_DELETE,
  192. body: [code]
  193. });
  194. console.log('删除看板', [code], res);
  195. if(!res.err && res.data.code > 0) {
  196. for(let i = 0; i < list.length; i++) {
  197. if(list[i].code === code) {
  198. list.splice(i, 1);
  199. break;
  200. }
  201. }
  202. yield put({ type: 'list', list: list });
  203. message.success('删除成功');
  204. }else {
  205. message.error('删除失败: ' + (res.err || res.data.msg));
  206. }
  207. }catch(e) {
  208. console.log(e);
  209. message.error('删除失败');
  210. }
  211. },
  212. *transfer(action, { put, call, select }) {
  213. const { userCode, dashboardCode } = action;
  214. const body = {
  215. userId: userCode,
  216. id: dashboardCode
  217. };
  218. try {
  219. // const res = yield call(service.fetch, {
  220. // url: URLS.DASHBOARD_TRANSFER,
  221. // body
  222. // });
  223. // console.log('看板移交', body, res);
  224. const res = {data:{code:1}};
  225. if(!res.err && res.data.code > 0) {
  226. const dashboard = yield select(state => state.present.dashboard);
  227. const list = dashboard.list;
  228. for(let i = 0; i < list.length; i++) {
  229. if(list[i].code === dashboardCode) {
  230. list.splice(i, 1);
  231. break;
  232. }
  233. }
  234. yield put({ type: 'list', list });
  235. message.success('移交成功');
  236. }else {
  237. console.log(body, res.err || res.data.msg);
  238. message.error('移交失败: ' + res.err || res.data.msg);
  239. }
  240. }catch(e) {
  241. console.log(body, e);
  242. message.error('移交失败');
  243. }
  244. }
  245. },
  246. subscriptions: {
  247. setup({ dispatch, history}) {
  248. return history.listen(({pathname}) => {}
  249. )}
  250. }
  251. }