model.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. import {
  2. fakeSubmitForm,
  3. updateReportInfo,
  4. getExamInfo,
  5. createReportCommon,
  6. createTestCase,
  7. getTestCaseList,
  8. getCaseBugList,
  9. getBugInfo,
  10. updateTestCaseList,
  11. getReportInfo,
  12. createCaseBug,
  13. getRecommendList,
  14. getPathInfo,
  15. getRecommendPath,
  16. goodReport,
  17. badReport,
  18. cancelGoodReport,
  19. cancelBadReport,
  20. recordAction,
  21. uploadImage,
  22. getIdByToken,
  23. forkReport,
  24. recordGoodReport,
  25. recordBadReport,
  26. bugSimilarity
  27. } from './service';
  28. const Model = {
  29. namespace: 'editReport',
  30. state: {
  31. current: 'info',
  32. osType: [],
  33. step: {
  34. payAccount: 'ant-design@alipay.com',
  35. receiverAccount: 'test@example.com',
  36. receiverName: 'Alex',
  37. amount: '500',
  38. },
  39. taskName: '',
  40. collaborative_type:'0',
  41. reportCommonInfo: {},
  42. testCaseList: [],
  43. caseBugList: [],
  44. categories: [],
  45. pathInfo: [],
  46. recommendPath: [],
  47. bugRecommendList: [],
  48. commonId:{
  49. // result:"success",
  50. // roleId:1,
  51. // caseId:"3714",
  52. // examId:"3714",
  53. // beginTime:"1621945823000",
  54. // endTime:"1624291200000",
  55. // userId:"99222",
  56. // case_take_id:"3714-3714",
  57. },
  58. },
  59. effects: {
  60. * submitStepForm({ payload }, { call, put }) {
  61. yield call(fakeSubmitForm, payload);
  62. yield put({
  63. type: 'saveStepFormData',
  64. payload,
  65. });
  66. yield put({
  67. type: 'saveCurrentStep',
  68. payload: 'detail',
  69. });
  70. },
  71. * getOsType({ payload }, { call, put }) {
  72. const { examId } = payload;
  73. const res = yield call(getExamInfo, examId);
  74. let osType = res?.result?.paper_type;
  75. osType = JSON.parse(osType)['subTitles'][2]?.value;
  76. yield put({
  77. type: 'saveOsType',
  78. payload: osType,
  79. });
  80. },
  81. //todo:根据id获取token
  82. * getIdByToken({ payload }, { call, put }) {
  83. const { token } = payload;
  84. let res = yield call(getIdByToken, token)
  85. res['case_take_id'] = res['caseId'] + '-' + res['examId'];
  86. yield put({
  87. type: 'saveCommonId',
  88. payload: res,
  89. });
  90. return res;
  91. },
  92. //todo:更新报告基础信息
  93. * updateReportCommonDetail({ payload }, { call, put }) {
  94. let { formData } = payload;
  95. yield call(updateReportInfo, formData);
  96. let res = yield call(getReportInfo,
  97. formData.get('case_take_id'), formData.get('worker_id'));
  98. yield put({
  99. type: 'saveReportCommonInfo',
  100. payload: res.result,
  101. });
  102. },
  103. //todo:获取三级菜单信息
  104. * getCategories({ payload }, { call, put }) {
  105. const { examId } = payload;
  106. let res = yield call(getExamInfo, examId);
  107. let categories = res?.result?.json;
  108. categories = JSON.parse(categories);
  109. yield put({
  110. type: 'saveCategories',
  111. payload: categories,
  112. });
  113. },
  114. //todo:获取报告用例列表
  115. * getTestCaseList({ payload }, { call, put }) {
  116. const { report_id } = payload;
  117. let res = yield call(getTestCaseList, report_id);
  118. yield put({
  119. type: 'saveTestCaseList',
  120. payload: res.result,
  121. });
  122. return res.result;
  123. },
  124. //todo:获取报告基础信息
  125. * getReportInfo({ payload }, { call, put }) {
  126. const { case_take_id, worker_id } = payload;
  127. let res = yield call(getReportInfo, case_take_id, worker_id);
  128. if (res.status === 200) {
  129. yield put({
  130. type: 'saveReportCommonInfo',
  131. payload: res.result,
  132. });
  133. }
  134. return res;
  135. },
  136. //todo:保存报告基础信息
  137. * saveReportCommonDetail({ payload }, { call, put }) {
  138. let {formData,case_take_id,worker_id} = payload;
  139. yield call(createReportCommon, formData);
  140. //res拿到报告id,组装生成report对象
  141. // let report = { id: res.id };
  142. // for (let key of payload.keys()) {
  143. // report[key] = payload.get(key);
  144. // }
  145. yield put.resolve({
  146. type: 'getReportInfo',
  147. payload: { case_take_id,worker_id },
  148. });
  149. yield put({
  150. type: 'saveCurrentStep',
  151. payload: 'detail',
  152. });
  153. },
  154. //todo:创建新用例
  155. * createTestCase({ payload }, { call, put,select }) {
  156. let { formData, report_id } = payload;
  157. let res = yield call(createTestCase, formData);
  158. yield put.resolve({
  159. type: 'getTestCaseList',
  160. payload: { report_id },
  161. });
  162. const testCaseList = yield select(state => {
  163. return state.editReport.testCaseList;
  164. })
  165. return {res,testCaseList};
  166. },
  167. //todo:更新用例
  168. * updateTestCase({ payload }, { call, put }) {
  169. let { formData, report_id } = payload;
  170. let res = yield call(updateTestCaseList, formData);
  171. yield put({
  172. type: 'getTestCaseList',
  173. payload: { report_id },
  174. });
  175. return res;
  176. },
  177. //todo:获取bug列表
  178. * getCaseBugList({ payload }, { call, put }) {
  179. let bugIdList = yield call(getCaseBugList, payload);//bug id list
  180. yield put({ type: 'getBugInfo', payload: { bugIdList } });
  181. },
  182. //todo:根据bug id获取bug detail
  183. * getBugDetail({ payload }, { call, put }) {
  184. const { id } = payload;
  185. let bugInfo = yield call(getBugInfo, id);//bug id list
  186. return bugInfo;
  187. },
  188. //todo:根据bugIdList获取bug详情
  189. * getBugInfo({ payload }, { call, put }) {
  190. const { bugIdList } = payload;
  191. let newBugList = [];
  192. for (const item of bugIdList) {
  193. let newBugInfo = yield call(getBugInfo, item);
  194. newBugList = [...newBugList, newBugInfo];
  195. }
  196. yield put({
  197. type: 'saveCaseBugList',
  198. payload: newBugList,
  199. });
  200. return newBugList;
  201. },
  202. //todo:保存bug
  203. * createCaseBug({ payload }, { call, put }) {
  204. const { useCase, formData } = payload;
  205. let res = yield call(createCaseBug, formData);
  206. yield put({
  207. type: 'getCaseBugList',
  208. payload: useCase,
  209. });
  210. return res;
  211. },
  212. //todo:获取bug 路径
  213. * getPathInfo({ payload }, { call, put }) {
  214. const { case_take_id, report_id } = payload;
  215. let res = yield call(getPathInfo, case_take_id, report_id);
  216. yield put({
  217. type: 'savePathInfo',
  218. payload: res,
  219. });
  220. },
  221. //todo:获取bug 推荐路径
  222. * getBugRecommendPath({ payload }, { call, put }) {
  223. const { case_take_id, report_id } = payload;
  224. let res = yield call(getRecommendPath, case_take_id, report_id);
  225. yield put({
  226. type: 'saveRecommendPath',
  227. payload: res,
  228. });
  229. return res;
  230. },
  231. //todo:获取bug推荐列表
  232. * getBugRecommendList({ payload }, { call, put }) {
  233. const { case_take_id, report_id } = payload;
  234. let res = yield call(getRecommendList, case_take_id, report_id);
  235. yield put({
  236. type: 'saveBugRecommendList',
  237. payload: res,
  238. });
  239. return res;
  240. },
  241. //todo:点赞bug报告
  242. * goodForReport({ payload }, { call, put }) {
  243. const { id, report_id, user_id, action } = payload;
  244. let res = yield call(goodReport, id, report_id);
  245. if (res.status === 200) {
  246. yield call(recordAction, user_id, id, action);
  247. }
  248. },
  249. //todo:取消点赞bug报告
  250. * cancelGoodForReport({ payload }, { call, put }) {
  251. const { id, report_id } = payload;
  252. yield call(cancelGoodReport, id, report_id);
  253. },
  254. //todo:点踩bug报告
  255. * badForReport({ payload }, { call, put }) {
  256. const { id, report_id, user_id, action } = payload;
  257. let res = yield call(badReport, id, report_id);
  258. if(res.status === 200){
  259. yield call(recordAction, user_id, id, action);
  260. }
  261. },
  262. //todo:取消点踩bug报告
  263. * cancelBadForReport({ payload }, { call, put }) {
  264. const { id, report_id } = payload;
  265. yield call(cancelBadReport, id, report_id);
  266. },
  267. //todo:存储用户行为
  268. * recordAction({ payload }, { call, put }) {
  269. const { user_id, target_id, action } = payload;
  270. yield call(recordAction, user_id, target_id, action);
  271. },
  272. //todo:上传照片
  273. * uploadImg({ payload }, { call, put }) {
  274. const { formData } = payload;
  275. let res = yield call(uploadImage, formData);
  276. return res;
  277. },
  278. //todo:fork report
  279. * forkReport({ payload }, { call, put }) {
  280. const { page1, page2, page3, bug_category, severity, recurrent } = payload;
  281. yield call(forkReport, page1, page2, page3, bug_category, severity, recurrent);
  282. },
  283. //todo:记录点赞行为
  284. * recordGoodReport({ payload }, { call, put }) {
  285. const { user_id, target_id,action } = payload;
  286. yield call(recordGoodReport, user_id, target_id,action);
  287. },
  288. //todo:记录点踩行为
  289. * recordBadReport({ payload }, { call, put }) {
  290. const { user_id, target_id,action } = payload;
  291. yield call(recordBadReport, user_id, target_id,action);
  292. },
  293. //todo:bug相似度计算
  294. * bugSimilarity({ payload }, { call, put }) {
  295. const { case_take_id, type, content } = payload;
  296. const res = yield call(bugSimilarity, case_take_id, type, content);
  297. return res;
  298. },
  299. },
  300. reducers: {
  301. saveCurrentStep(state, { payload }) {
  302. return { ...state, current: payload };
  303. },
  304. saveStepFormData(state, { payload }) {
  305. return { ...state, step: { ...state.step, ...payload } };
  306. },
  307. saveOsType(state, { payload }) {
  308. return { ...state, osType: payload };
  309. },
  310. saveReportCommonInfo(state, { payload }) {
  311. return { ...state, reportCommonInfo: payload };
  312. },
  313. saveTestCaseList(state, { payload }) {
  314. return { ...state, testCaseList: payload };
  315. },
  316. saveCaseBugList(state, { payload }) {
  317. return { ...state, caseBugList: payload };
  318. },
  319. saveCategories(state, { payload }) {
  320. return { ...state, categories: payload };
  321. },
  322. saveBugRecommendList(state, { payload }) {
  323. return { ...state, bugRecommendList: payload };
  324. },
  325. savePathInfo(state, { payload }) {
  326. return { ...state, pathInfo: payload };
  327. },
  328. saveRecommendPath(state, { payload }) {
  329. return { ...state, recommendPath: payload };
  330. },
  331. saveCommonId(state, { payload }){
  332. return { ...state, commonId: payload };
  333. }
  334. },
  335. };
  336. export default Model;