manage.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. import { defHttp } from '/@/utils/http/axios';
  2. const api = {
  3. user: '/mock/api/user',
  4. role: '/mock/api/role',
  5. service: '/mock/api/service',
  6. permission: '/mock/api/permission',
  7. permissionNoPager: '/mock/api/permission/no-pager'
  8. }
  9. //post
  10. export function postAction(url, parameter, timeout) {
  11. return defHttp.post({
  12. url: url,
  13. method: 'post',
  14. data: parameter,
  15. timeout: timeout ? timeout : 1000 * 120,
  16. }, { isTransformResponse: false, successMessageMode: 'none' })
  17. }
  18. //post
  19. export function postActionBlob(url, parameter) {
  20. return defHttp.request({
  21. url: url,
  22. method: 'post',
  23. data: parameter,
  24. headers: {
  25. 'Content-Type': 'application/json'
  26. },
  27. responseType: 'blob'
  28. })
  29. }
  30. //post
  31. export function postAction3(url, parameter) {
  32. return defHttp.request({
  33. url: url,
  34. method: 'post',
  35. data: parameter,
  36. timeout: 1000 * 120,
  37. headers: {
  38. 'Content-Type': 'application/json'
  39. },
  40. })
  41. }
  42. export function postActionForm(url, parameter) {
  43. return defHttp.post({
  44. url: url,
  45. params: parameter,
  46. timeout: 1000 * 120,
  47. headers: {
  48. 'Content-Type': 'multipart/form-data'
  49. },
  50. }, { isTransformResponse: false, successMessageMode: 'none' })
  51. }
  52. export function postAction5(url, parameter, timeout) {
  53. return defHttp.request({
  54. url: url,
  55. method: 'post',
  56. data: parameter,
  57. timeout: timeout ? timeout : 1000 * 120,
  58. headers: {
  59. 'Content-Type': 'application/json'
  60. },
  61. })
  62. }
  63. //post method= {post | put}
  64. export function httpAction(url, parameter, method) {
  65. return defHttp.request({
  66. url: url,
  67. method: method,
  68. data: parameter
  69. })
  70. }
  71. //put
  72. export function putAction(url, parameter) {
  73. return defHttp.request({
  74. url: url,
  75. method: 'put',
  76. data: parameter
  77. },{ isTransformResponse: false, successMessageMode: 'none' })
  78. }
  79. //get
  80. export function getAction(url, parameter) {
  81. return defHttp.get({
  82. url: url,
  83. method: 'get',
  84. params: parameter,
  85. timeout: 1000 * 180,
  86. }, { isTransformResponse: false, successMessageMode: 'none' })
  87. }
  88. //deleteAction
  89. export function deleteAction(url, parameter) {
  90. return defHttp.request({
  91. url: url,
  92. method: 'delete',
  93. params: parameter
  94. })
  95. }
  96. export function getUserList(parameter) {
  97. return defHttp.request({
  98. url: api.user,
  99. method: 'get',
  100. params: parameter
  101. })
  102. }
  103. export function getRoleList(parameter) {
  104. return defHttp.request({
  105. url: api.role,
  106. method: 'get',
  107. params: parameter
  108. })
  109. }
  110. export function getServiceList(parameter) {
  111. return defHttp.request({
  112. url: api.service,
  113. method: 'get',
  114. params: parameter
  115. })
  116. }
  117. export function getPermissions(parameter) {
  118. return defHttp.request({
  119. url: api.permissionNoPager,
  120. method: 'get',
  121. params: parameter
  122. })
  123. }
  124. // id == 0 add post
  125. // id != 0 update put
  126. export function saveService(parameter) {
  127. return defHttp.request({
  128. url: api.service,
  129. method: parameter.id == 0 ? 'post' : 'put',
  130. data: parameter
  131. })
  132. }
  133. /**
  134. * 下载文件 用于excel导出
  135. * @param url
  136. * @param parameter
  137. * @returns {*}
  138. */
  139. export function downFile(url, parameter) {
  140. return defHttp.request({
  141. url: url,
  142. params: parameter,
  143. method: 'get',
  144. responseType: 'blob'
  145. })
  146. }
  147. /**
  148. * 文件上传 用于富文本上传图片
  149. * @param url
  150. * @param parameter
  151. * @returns {*}
  152. */
  153. export function uploadAction(url, parameter) {
  154. return defHttp.request({
  155. url: url,
  156. data: parameter,
  157. method: 'post',
  158. headers: {
  159. 'Content-Type': 'multipart/form-data', // 文件上传
  160. },
  161. })
  162. }
  163. /**
  164. * 获取文件服务访问路径
  165. * @param avatar
  166. * @param subStr
  167. * @returns {*}
  168. */
  169. export function getFileAccessHttpUrl(avatar, subStr) {
  170. if (!subStr) subStr = 'http'
  171. try {
  172. if (avatar && avatar.startsWith(subStr)) {
  173. return avatar;
  174. } else {
  175. if (avatar && avatar.length > 0 && avatar.indexOf('[') == -1) {
  176. return window._CONFIG['staticDomainURL'] + "/" + avatar;
  177. }
  178. }
  179. } catch (err) {
  180. return;
  181. }
  182. }