userService.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. import Http from './http'
  2. import Apis from './api'
  3. //获取用户信息
  4. export const getCurrentUser = (getCurrentUserSuccess, getCurrentUserFail) => {
  5. // const data = {
  6. // userVO: {
  7. // id: 3,
  8. // photo: 'http://www.mooctest.net/assets/img/mooctest.png',
  9. // name: '郭超',
  10. // roleList: ['区域管理员', '个人用户', '企业用户', '测评机构', '系统管理员'],
  11. // mobile: '110',
  12. // email: '12345@qq.com',
  13. // },
  14. // agency: '',
  15. // }
  16. // return new Promise((resolve) => {
  17. // resolve(data)
  18. // })
  19. return Http.get(Apis.USER.GET_CURRENT_USER)
  20. // Http.get(Apis.USER.GET_CURRENT_USER).then((res) => {
  21. // getCurrentUserSuccess(res)
  22. // }).catch((error) => {
  23. // getCurrentUserFail(error)
  24. // })
  25. }
  26. //
  27. export const getRolesPermissions = (roleList) => {
  28. const roles = {
  29. regionManager: 'RegionalManager',
  30. individualUser: 'generalUser',
  31. enterpriseUser: 'enterpriseUser',
  32. agency: 'evaluationAgency',
  33. systemAdministrator: 'SystemAdministrator'
  34. }
  35. const permissions = {
  36. isRegionManager: false,
  37. isIndividualUser: false,
  38. isEnterpriseUser: false,
  39. isAgency: false,
  40. isSystemAdministrator: false
  41. }
  42. if (roleList.includes(roles.regionManager)) {
  43. permissions.isRegionManager = true
  44. permissions.isEnterpriseUser = true
  45. permissions.isIndividualUser = true
  46. }
  47. if (roleList.includes(roles.agency)) {
  48. permissions.isAgency = true
  49. permissions.isEnterpriseUser = true
  50. permissions.isIndividualUser = true
  51. }
  52. if (roleList.includes(roles.enterpriseUser)) {
  53. permissions.isEnterpriseUser = true
  54. }
  55. if (roleList.includes(roles.individualUser)) {
  56. permissions.isIndividualUser = true
  57. }
  58. if (roleList.includes(roles.systemAdministrator)) {
  59. permissions.isSystemAdministrator = true
  60. permissions.isRegionManager = true
  61. permissions.isAgency = true
  62. permissions.isEnterpriseUser = true
  63. permissions.isIndividualUser = true
  64. }
  65. return permissions
  66. }
  67. export const logout = () => {
  68. sessionStorage.removeItem('user')
  69. sessionStorage.removeItem('rolesPermissions')
  70. return Http.get(Apis.USER.LOGOUT)
  71. }
  72. //获取当前角色可访问的url
  73. export const getAuthUrls = () => {
  74. return [
  75. '/', '/home', '/square', '/mine', '/project/create',
  76. '/project/:projectId', '/project/:projectId/task/create',
  77. '/project/:projectId/task/:taskId', '/project/:projectId/analyse',
  78. '/report/create', '/report/:reportId', '/greenChannel/addProject', '/greenChannel/addAgency',
  79. '/authentication/individual', '/authentication/enterprise',
  80. '/authentication/agency', '/authentication/index'
  81. ]
  82. //return Http.get(Apis.USER.GET_AUTH_URLS)
  83. }
  84. //上传个人认证信息
  85. export const uploadIndividualAuthenticationInfo = (userId, userAuthInfo, uploadIndividualAuthenticationInfoSuccess, uploadIndividualAuthenticationInfoFail) => {
  86. Http.post(Apis.USER.SUBMIT_INDIVIDUAL_AUTHENTICATION_INFO.replace('{userId}', userId), userAuthInfo).then((res) => {
  87. uploadIndividualAuthenticationInfoSuccess(res)
  88. }).catch(error => {
  89. uploadIndividualAuthenticationInfoFail(error)
  90. })
  91. }
  92. //上传企业认证信息
  93. export const uploadEnterpriseAuthenticationInfo = (userId, userAuthInfo, uploadEnterpriseAuthenticationInfoSuccess, uploadEnterpriseAuthenticationInfoFail) => {
  94. Http.post(Apis.USER.SUBMIT_ENTERPRISE_AUTHENTICATION_INFO.replace('{userId}', userId), userAuthInfo).then((res) => {
  95. uploadEnterpriseAuthenticationInfoSuccess(res)
  96. }).catch(error => {
  97. uploadEnterpriseAuthenticationInfoFail(error)
  98. })
  99. }
  100. //上传机构认证信息
  101. export const uploadAgencyAuthenticationInfo = (userId, userAuthInfo, uploadAgencyAuthenticationInfoSuccess, uploadAgencyAuthenticationInfoFail) => {
  102. Http.post(Apis.USER.SUBMIT_AGENCY_AUTHENTICATION_INFO.replace('{userId}', userId), userAuthInfo).then((res) => {
  103. uploadAgencyAuthenticationInfoSuccess(res)
  104. }).catch(error => {
  105. uploadAgencyAuthenticationInfoFail(error)
  106. })
  107. }
  108. //获取所有未处理认证消息
  109. export const getAllHandlingAuthInfo = (getAllHandlingAuthInfoSuccess, getAllHandlingAuthInfoFail) => {
  110. Http.get(Apis.USER.GET_ALL_HANDLING_AUTH_INFO).then((res) => {
  111. getAllHandlingAuthInfoSuccess(res)
  112. }).catch((error) => {
  113. getAllHandlingAuthInfoFail(error)
  114. })
  115. }
  116. //获取所有已处理认证消息
  117. export const getAllHandledAuthInfo = (getAllHandledAuthInfoSuccess, getAllHandledAuthInfoFail) => {
  118. Http.get(Apis.USER.GET_ALL_HANDLED_AUTH_INFO).then((res) => {
  119. getAllHandledAuthInfoSuccess(res)
  120. }).catch((error) => {
  121. getAllHandledAuthInfoFail(error)
  122. })
  123. }
  124. export const getCurrentIndividualAuthenInfo = (userId, getCurrentIndividualAuthenInfoSuccess, getCurrentIndividualAuthenInfoFail) => {
  125. Http.get(Apis.USER.GET_INDIVIDUAL_AUTHENTICATION_INFO.replace('{userId}', userId)).then((res) => {
  126. getCurrentIndividualAuthenInfoSuccess(res)
  127. }).catch((error) => {
  128. getCurrentIndividualAuthenInfoFail(error)
  129. })
  130. }
  131. export const getCurrentEnterpriseAuthInfo = (userId, getCurrentEnterpriseAuthInfoSuccess, getCurrentEnterpriseAuthInfoFail) => {
  132. Http.get(Apis.USER.GET_ENTERPRISE_AUTHENTICATION_INFO.replace('{userId}', userId)).then((res) => {
  133. getCurrentEnterpriseAuthInfoSuccess(res)
  134. }).catch((error) => {
  135. getCurrentEnterpriseAuthInfoFail(error)
  136. })
  137. }
  138. export const getCurrentAgencyAuthInfo = (userId, getCurrentEnterpriseAuthInfoSuccess, getCurrentEnterpriseAuthInfoFail) => {
  139. Http.get(Apis.USER.GET_AGENCY_AUTHENTICATION_INFO.replace('{userId}', userId)).then((res) => {
  140. getCurrentEnterpriseAuthInfoSuccess(res)
  141. }).catch((error) => {
  142. getCurrentEnterpriseAuthInfoFail(error)
  143. })
  144. }
  145. export const getAgencyAuthInfoCommon = (userId, getCurrentEnterpriseAuthInfoSuccess, getCurrentEnterpriseAuthInfoFail) => {
  146. Http.get(Apis.USER.GET_AGENCY_AUTHENTICATION_INFO_COMMON.replace('{userId}', userId)).then((res) => {
  147. getCurrentEnterpriseAuthInfoSuccess(res)
  148. }).catch((error) => {
  149. getCurrentEnterpriseAuthInfoFail(error)
  150. })
  151. }
  152. export const getCurrentAuthenInfo = () => {
  153. const individualData = {
  154. type: '个人',//企业、机构、个人
  155. //共有
  156. id: 1,
  157. userId: 3,
  158. bankAccount: '621000999000999000',
  159. address: '江苏科技大厦',
  160. status: '认证失败',
  161. rejectReason: '太强',
  162. createTime: '2019.13.12',
  163. //个人
  164. realName: '李白',
  165. IDCard: '32092111111111',
  166. IDCardPositivePhoto: 'http://www.mooctest.net/assets/img/mooctest.png',
  167. }
  168. const enterpriseData = {
  169. type: '企业',//企业、机构、个人
  170. //共有
  171. id: 1,
  172. userId: 3,
  173. bankAccount: '621000999000999000',
  174. address: '江苏科技大厦1901',
  175. status: '',
  176. rejectReason: '',
  177. createTime: '',
  178. //企业
  179. companyName: '慕测呀',
  180. legalPersonName: '郭超啊',
  181. businessLicensePhoto: null,
  182. unifiedSocialCreditCode: '1900000000086',
  183. }
  184. const agencyData = {
  185. type: '机构',//企业、机构、个人
  186. //共有
  187. id: 1,
  188. userId: 3,
  189. bankAccount: '100000000086',
  190. address: '江苏科技大厦1901',
  191. status: '',
  192. rejectReason: '123123123',
  193. createTime: '',
  194. //机构
  195. evaluationAgencyName: '慕测科技',
  196. evaluationAgencyAbilityList: ['接口测试', '兼容性测试', '可靠性测试', '稳定性测试', '功能测试', '性能测试', '安全测试','易用性测试', '应用故障诊断', '应用漏洞扫描', '代码安全审计', '风险评估', '等保测评', '评估评价', '定制测试'],
  197. evaluationAgencyResourceList: [
  198. {
  199. id: 0,
  200. type: '人力资源',
  201. name: '专家',
  202. totalNum: 100,
  203. availableNum: 3,
  204. },
  205. {
  206. id: 1,
  207. type: '人力资源',
  208. name: '程序员',
  209. totalNum: 100,
  210. availableNum: 3,
  211. }
  212. ],
  213. agencyPhoto: 'http://www.mooctest.net/assets/img/mooctest.png',
  214. }
  215. return new Promise((resolve) => {
  216. resolve(enterpriseData)
  217. })
  218. }
  219. //放弃认证
  220. export const deleteAuthInfo = () => {
  221. const data = {}
  222. return new Promise((resolve) => {
  223. resolve(data)
  224. })
  225. //return Http.get(Apis.GENERAL.GET_ALL_ABILITIES)
  226. }
  227. //
  228. export const updateIndividualAuthInfo = (userId, authInfo, updateIndividualAuthInfoSuccess, updateIndividualAuthInfoFail) => {
  229. // const data = {}
  230. // return new Promise((resolve) => {
  231. // resolve(data)
  232. // })
  233. Http.put(Apis.USER.UPDATE_INDIVIDUAL_AUTHENTICATION_INFO.replace('{userId}', userId), authInfo).then((res) => {
  234. updateIndividualAuthInfoSuccess(res)
  235. }).catch((error) => {
  236. updateIndividualAuthInfoFail(error)
  237. })
  238. }
  239. export const updateAgencyAuthInfo = (userId, authInfo, updateAgencyAuthInfoSuccess, updateAgencyAuthInfoFail) => {
  240. Http.put(Apis.USER.UPDATE_AGENCY_AUTHENTICATION_INFO.replace('{userId}', userId), authInfo).then((res) => {
  241. updateAgencyAuthInfoSuccess(res)
  242. }).catch((error) => {
  243. updateAgencyAuthInfoFail(error)
  244. })
  245. }
  246. export const updateAgencyResourceAndAbility = (userId, authInfo, updateAgencyResourceAndAbilitySuccess, updateAgencyResourceAndAbilityFail) => {
  247. Http.post(Apis.USER.UPDATE_AGENCY_RESOURCE_AND_ABILITY.replace('{userId}', userId), authInfo).then((res) => {
  248. updateAgencyResourceAndAbilitySuccess(res)
  249. }).catch((error) => {
  250. updateAgencyResourceAndAbilityFail(error)
  251. })
  252. }
  253. export const updateEnterpriseAuthInfo = (userId, authInfo, updateEnterpriseAuthInfoSuccess, updateEnterpriseAuthInfoFail) => {
  254. // const data = {}
  255. // return new Promise((resolve) => {
  256. // resolve(data)
  257. // })
  258. Http.put(Apis.USER.UPDATE_ENTERPRISE_AUTHENTICATION_INFO.replace('{userId}', userId), authInfo).then((res) => {
  259. updateEnterpriseAuthInfoSuccess(res)
  260. }).catch((error) => {
  261. updateEnterpriseAuthInfoFail(error)
  262. })
  263. }
  264. export const checkPassAuth = (type, userId, checkPassAuthSuccess, checkPassAuthFail) => {
  265. if (type == 'agency') {
  266. Http.put(Apis.USER.PASS_AGENCY_AUTH.replace('{userId}', userId), {}).then((res) => {
  267. checkPassAuthSuccess(res)
  268. }).catch((error) => {
  269. checkPassAuthFail(error)
  270. })
  271. }
  272. if (type == 'personal') {
  273. Http.put(Apis.USER.PASS_INDIVIDUAL_AUTH.replace('{userId}', userId), {}).then((res) => {
  274. checkPassAuthSuccess(res)
  275. }).catch((error) => {
  276. checkPassAuthFail(error)
  277. })
  278. }
  279. if (type == 'enterprise') {
  280. Http.put(Apis.USER.PASS_ENTERPRISE_AUTH.replace('{userId}', userId), {}).then((res) => {
  281. checkPassAuthSuccess(res)
  282. }).catch((error) => {
  283. checkPassAuthFail(error)
  284. })
  285. }
  286. }
  287. export const checkRejectAuth = (type, userId, data, checkRejectAuthSuccess, checkRejectAuthFail) => {
  288. if (type == 'agency') {
  289. Http.put(Apis.USER.REJECT_AGENCY_AUTH.replace('{userId}', userId), data).then((res) => {
  290. checkRejectAuthSuccess(res)
  291. }).catch((error) => {
  292. checkRejectAuthFail(error)
  293. })
  294. }
  295. if (type == 'personal') {
  296. Http.put(Apis.USER.REJECT_INDIVIDUAL_AUTH.replace('{userId}', userId), data).then((res) => {
  297. checkRejectAuthSuccess(res)
  298. }).catch((error) => {
  299. checkRejectAuthFail(error)
  300. })
  301. }
  302. if (type == 'enterprise') {
  303. Http.put(Apis.USER.REJECT_ENTERPRISE_AUTH.replace('{userId}', userId), data).then((res) => {
  304. checkRejectAuthSuccess(res)
  305. }).catch((error) => {
  306. checkRejectAuthFail(error)
  307. })
  308. }
  309. }