base.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. import store from '@/store'
  2. import {
  3. MessageBox,
  4. Message
  5. } from 'element-ui'
  6. import { State } from '@/constant'
  7. import request from '@/utils/request'
  8. import {
  9. showLoading,
  10. closeLoading
  11. } from '@/utils/pop'
  12. export function addTenant (data = {}) {
  13. if (data.tenant && store.getters.isSuperAdmin) {
  14. return data
  15. }
  16. return {
  17. ...data,
  18. tenant: store.getters.tenant
  19. }
  20. }
  21. export function addOrg (data = {}) {
  22. return {
  23. ...data,
  24. org: store.getters.org
  25. }
  26. }
  27. export function addTenantAndOrg (data = {}) {
  28. return {
  29. ...data,
  30. tenant: store.getters.tenant,
  31. org: store.getters.org
  32. }
  33. }
  34. export function addTenantOrOrg (data = {}) {
  35. return store.getters.isTopGroup
  36. ? {
  37. ...data,
  38. tenant: store.getters.tenant
  39. }
  40. : {
  41. ...data,
  42. org: store.getters.org
  43. }
  44. }
  45. export function addUser (data = {}) {
  46. return {
  47. ...data,
  48. user: store.getters.userId
  49. }
  50. }
  51. export function addScope (data) {
  52. return store.getters.isGroupAdmin
  53. ? addTenantOrOrg(data)
  54. : addUser(data)
  55. }
  56. const Status = {
  57. [State.READY]: [-1, 0],
  58. [State.SUBMITTED]: [1],
  59. [State.RESOLVED]: [2],
  60. [State.REJECTED]: [3, 4, 5],
  61. [State.REVIEW_ASSET]: [0, 1],
  62. [State.AVAILABLE]: [0, 1, 2],
  63. [State.DRAFT_CONTENT]: [-1, 0, 3, 4, 5]
  64. }
  65. export function addStatus ({ status, ...data }) {
  66. data.statusList = Status[status]
  67. return data
  68. }
  69. export function addStatusScope ({ status, ...data }) {
  70. switch (status) {
  71. case State.RESOLVED:
  72. return {
  73. ...addTenant(data),
  74. status
  75. }
  76. case State.AVAILABLE:
  77. return {
  78. ...addTenantOrOrg(data),
  79. status
  80. }
  81. default:
  82. return {
  83. ...addUser(data),
  84. status
  85. }
  86. }
  87. }
  88. export function send (config, service = request) {
  89. const loading = showLoading()
  90. return service(config).finally(() => {
  91. closeLoading(loading)
  92. })
  93. }
  94. export function messageSend (config, message, service = request) {
  95. return (config.onUploadProgress ? service(config) : send(config, service)).then(data => {
  96. message && Message({
  97. type: 'success',
  98. message: `${message}成功`
  99. })
  100. return data
  101. })
  102. }
  103. export function confirm (message) {
  104. return MessageBox.confirm(
  105. message,
  106. '操作确认',
  107. { type: 'warning' }
  108. )
  109. }
  110. export function confirmAndSend (type, tip, config, service = request) {
  111. return confirm(
  112. tip ? `${type} ${tip} ?` : `${type}?`
  113. ).then(() => messageSend(config, type, service))
  114. }
  115. export function add (config, service = request) {
  116. return messageSend(config, '新增', service)
  117. }
  118. export function update (config, message, service = request) {
  119. return messageSend(config, message || '更新', service)
  120. }
  121. export function submit (config, tip, service = request) {
  122. return confirmAndSend('提交', tip, config, service)
  123. }
  124. export function del (config, tip, service = request) {
  125. return confirmAndSend('删除', tip, config, service)
  126. }
  127. export function resolve (config, tip, service = request) {
  128. return confirmAndSend('通过', tip, config, service)
  129. }
  130. export function reject (config, tip, service = request) {
  131. return confirmAndSend('驳回', tip, config, service)
  132. }