| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- import store from '@/store'
- import {
- MessageBox,
- Message
- } from 'element-ui'
- import { State } from '@/constant'
- import request from '@/utils/request'
- import {
- showLoading,
- closeLoading
- } from '@/utils/pop'
- export function addTenant (data = {}) {
- if (data.tenant && store.getters.isSuperAdmin) {
- return data
- }
- return {
- ...data,
- tenant: store.getters.tenant
- }
- }
- export function addOrg (data = {}) {
- return {
- ...data,
- org: store.getters.org
- }
- }
- export function addTenantAndOrg (data = {}) {
- return {
- ...data,
- tenant: store.getters.tenant,
- org: store.getters.org
- }
- }
- export function addTenantOrOrg (data = {}) {
- return store.getters.isTopGroup
- ? {
- ...data,
- tenant: store.getters.tenant
- }
- : {
- ...data,
- org: store.getters.org
- }
- }
- export function addUser (data = {}) {
- return {
- ...data,
- user: store.getters.userId
- }
- }
- export function addScope (data) {
- return store.getters.isGroupAdmin
- ? addTenantOrOrg(data)
- : addUser(data)
- }
- const Status = {
- [State.READY]: [-1, 0],
- [State.SUBMITTED]: [1],
- [State.RESOLVED]: [2],
- [State.REJECTED]: [3, 4, 5],
- [State.REVIEW_ASSET]: [0, 1],
- [State.AVAILABLE]: [0, 1, 2],
- [State.DRAFT_CONTENT]: [-1, 0, 3, 4, 5]
- }
- export function addStatus ({ status, ...data }) {
- data.statusList = Status[status]
- return data
- }
- export function addStatusScope ({ status, ...data }) {
- switch (status) {
- case State.RESOLVED:
- return {
- ...addTenant(data),
- status
- }
- case State.AVAILABLE:
- return {
- ...addTenantOrOrg(data),
- status
- }
- default:
- return {
- ...addUser(data),
- status
- }
- }
- }
- export function send (config, service = request) {
- const loading = showLoading()
- return service(config).finally(() => {
- closeLoading(loading)
- })
- }
- export function messageSend (config, message, service = request) {
- return (config.onUploadProgress ? service(config) : send(config, service)).then(data => {
- message && Message({
- type: 'success',
- message: `${message}成功`
- })
- return data
- })
- }
- export function confirm (message) {
- return MessageBox.confirm(
- message,
- '操作确认',
- { type: 'warning' }
- )
- }
- export function confirmAndSend (type, tip, config, service = request) {
- return confirm(
- tip ? `${type} ${tip} ?` : `${type}?`
- ).then(() => messageSend(config, type, service))
- }
- export function add (config, service = request) {
- return messageSend(config, '新增', service)
- }
- export function update (config, message, service = request) {
- return messageSend(config, message || '更新', service)
- }
- export function submit (config, tip, service = request) {
- return confirmAndSend('提交', tip, config, service)
- }
- export function del (config, tip, service = request) {
- return confirmAndSend('删除', tip, config, service)
- }
- export function resolve (config, tip, service = request) {
- return confirmAndSend('通过', tip, config, service)
- }
- export function reject (config, tip, service = request) {
- return confirmAndSend('驳回', tip, config, service)
- }
|