manage.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. import { VueElement } from 'vue';
  2. import {defHttp} from '/@/utils/http/axios';
  3. const api = {
  4. user: '/mock/api/user',
  5. role: '/mock/api/role',
  6. service: '/mock/api/service',
  7. permission: '/mock/api/permission',
  8. permissionNoPager: '/mock/api/permission/no-pager'
  9. }
  10. //post
  11. export function postAction(url, parameter, timeout) {
  12. return defHttp.request({
  13. url: url,
  14. method: 'post',
  15. data: parameter,
  16. timeout: timeout ? timeout : 1000 * 120,
  17. })
  18. }
  19. //post
  20. export function postAction2(url, parameter) {
  21. return defHttp.request({
  22. url: url,
  23. method: 'post',
  24. data: parameter,
  25. headers: {
  26. 'Content-Type': 'application/json'
  27. },
  28. responseType: 'blob'
  29. })
  30. }
  31. //post
  32. export function postAction3(url, parameter) {
  33. return defHttp.request({
  34. url: url,
  35. method: 'post',
  36. data: parameter,
  37. timeout: 1000 * 120,
  38. headers: {
  39. 'Content-Type': 'application/json'
  40. },
  41. })
  42. }
  43. export function postAction4(url, parameter) {
  44. return defHttp.request({
  45. url: url,
  46. method: 'post',
  47. data: parameter,
  48. timeout: 1000 * 60 * 3,
  49. })
  50. }
  51. export function postAction5(url, parameter, timeout) {
  52. return defHttp.request({
  53. url: url,
  54. method: 'post',
  55. data: parameter,
  56. timeout: timeout ? timeout : 1000 * 120,
  57. headers: {
  58. 'Content-Type': 'application/json'
  59. },
  60. })
  61. }
  62. //post method= {post | put}
  63. export function httpAction(url, parameter, method) {
  64. return defHttp.request({
  65. url: url,
  66. method: method,
  67. data: parameter
  68. })
  69. }
  70. //put
  71. export function putAction(url, parameter) {
  72. return defHttp.request({
  73. url: url,
  74. method: 'put',
  75. data: parameter
  76. })
  77. }
  78. //get
  79. export function getAction(url, parameter) {
  80. return defHttp.request({
  81. url: url,
  82. method: 'get',
  83. params: parameter,
  84. timeout: 1000 * 180,
  85. })
  86. }
  87. export function getAction2(url, parameter) {
  88. return axios2({
  89. url: url,
  90. method: 'get',
  91. params: parameter,
  92. timeout: 1000 * 180,
  93. })
  94. }
  95. //deleteAction
  96. export function deleteAction(url, parameter) {
  97. return defHttp.request({
  98. url: url,
  99. method: 'delete',
  100. params: parameter
  101. })
  102. }
  103. export function getUserList(parameter) {
  104. return defHttp.request({
  105. url: api.user,
  106. method: 'get',
  107. params: parameter
  108. })
  109. }
  110. export function getRoleList(parameter) {
  111. return defHttp.request({
  112. url: api.role,
  113. method: 'get',
  114. params: parameter
  115. })
  116. }
  117. export function getServiceList(parameter) {
  118. return defHttp.request({
  119. url: api.service,
  120. method: 'get',
  121. params: parameter
  122. })
  123. }
  124. export function getPermissions(parameter) {
  125. return defHttp.request({
  126. url: api.permissionNoPager,
  127. method: 'get',
  128. params: parameter
  129. })
  130. }
  131. // id == 0 add post
  132. // id != 0 update put
  133. export function saveService(parameter) {
  134. return defHttp.request({
  135. url: api.service,
  136. method: parameter.id == 0 ? 'post' : 'put',
  137. data: parameter
  138. })
  139. }
  140. /**
  141. * 下载文件 用于excel导出
  142. * @param url
  143. * @param parameter
  144. * @returns {*}
  145. */
  146. export function downFile(url, parameter, timeout) {
  147. return defHttp.request({
  148. url: url,
  149. params: parameter,
  150. method: 'get',
  151. timeout: timeout ? timeout : 1000 * 30,
  152. responseType: 'blob'
  153. })
  154. }
  155. /**
  156. * 下载文件
  157. * @param url 文件路径
  158. * @param fileName 文件名
  159. * @param parameter
  160. * @returns {*}
  161. */
  162. export function downloadFile(url, fileName, parameter) {
  163. return downFile(url, parameter).then((data) => {
  164. if (!data || data.size === 0) {
  165. VueElement.prototype['$message'].warning('文件下载失败')
  166. return
  167. }
  168. if (typeof window.navigator.msSaveBlob !== 'undefined') {
  169. window.navigator.msSaveBlob(new Blob([data]), fileName)
  170. } else {
  171. let url = window.URL.createObjectURL(new Blob([data]))
  172. let link = document.createElement('a')
  173. link.style.display = 'none'
  174. link.href = url
  175. link.setAttribute('download', fileName)
  176. document.body.appendChild(link)
  177. link.click()
  178. document.body.removeChild(link) //下载完成移除元素
  179. window.URL.revokeObjectURL(url) //释放掉blob对象
  180. }
  181. })
  182. }
  183. /**
  184. * 文件上传 用于富文本上传图片
  185. * @param url
  186. * @param parameter
  187. * @returns {*}
  188. */
  189. export function uploadAction(url, parameter) {
  190. return defHttp.request({
  191. url: url,
  192. data: parameter,
  193. method: 'post',
  194. headers: {
  195. 'Content-Type': 'multipart/form-data', // 文件上传
  196. },
  197. })
  198. }
  199. /**
  200. * 获取文件服务访问路径
  201. * @param avatar
  202. * @param subStr
  203. * @returns {*}
  204. */
  205. export function getFileAccessHttpUrl(avatar, subStr) {
  206. if (!subStr) subStr = 'http'
  207. try {
  208. if (avatar && avatar.startsWith(subStr)) {
  209. return avatar;
  210. } else {
  211. if (avatar && avatar.length > 0 && avatar.indexOf('[') == -1) {
  212. return window._CONFIG['staticDomainURL'] + "/" + avatar;
  213. }
  214. }
  215. } catch (err) {
  216. return;
  217. }
  218. }