|
function modalInstance(modal) {
|
const vm = modal.vm
|
const type = modal.type
|
const title = modal.title
|
const content = '<p>' + modal.message + '</p>'
|
|
switch (type) {
|
case 'info':
|
vm.$alert(content, title || '提示', {
|
confirmButtonText: '确定',
|
type: 'info',
|
dangerouslyUseHTMLString: true,
|
callback: action => {
|
}
|
})
|
break
|
case 'success':
|
vm.$alert(content, title || '成功', {
|
confirmButtonText: '确定',
|
dangerouslyUseHTMLString: true,
|
type: 'success',
|
callback: action => {
|
}
|
})
|
break
|
case 'warning':
|
vm.$alert(content, title || '警告', {
|
confirmButtonText: '确定',
|
dangerouslyUseHTMLString: true,
|
type: 'warning',
|
callback: action => {
|
}
|
})
|
|
break
|
case 'error':
|
vm.$alert(content, title || '错误', {
|
confirmButtonText: '确定',
|
dangerouslyUseHTMLString: true,
|
type: 'error',
|
callback: action => {
|
|
}
|
})
|
break
|
}
|
}
|
|
function noticeInstance(notice) {
|
const vm = notice.vm
|
const type = notice.type
|
const title = notice.title
|
const content = notice.message
|
switch (type) {
|
case 'info':
|
vm.$notify.info({
|
title: title || '提示',
|
message: content
|
})
|
break
|
case 'success':
|
vm.$notify.success({
|
title: title || '成功',
|
message: content
|
})
|
break
|
case 'warning':
|
vm.$notify.warning({
|
title: title || '警告',
|
message: content
|
})
|
break
|
case 'error':
|
vm.$notify.error({
|
title: title || '错误',
|
message: content,
|
duration: 40
|
})
|
break
|
}
|
}
|
|
function confirmInstance(modal) {
|
const vm = modal.vm
|
const title = modal.title
|
const content = modal.message
|
const okAction = modal.okAction
|
const cancelAction = modal.cancelAction
|
const okText = modal.okText
|
const cancelText = modal.cancelText
|
vm.$confirm('<p>' + content + '</p>', title || '提示', {
|
confirmButtonText: '确定',
|
cancelButtonText: '取消',
|
dangerouslyUseHTMLString: true,
|
type: 'warning'
|
}).then(() => {
|
vm.$message({
|
type: 'success',
|
message: '删除成功!'
|
})
|
}).catch(() => {
|
vm.$message({
|
type: 'info',
|
message: '已取消删除'
|
})
|
})
|
}
|
|
export function parseError(parseParam) {
|
const vm = parseParam.vm
|
const error = parseParam.error
|
const timeoutMessage = parseParam.timeoutMessage
|
const defaultMessage = parseParam.defaultMessage
|
let type = parseParam.type
|
if (!type) {
|
type = 'modalInstance'
|
}
|
if (error) {
|
const errorStr = error + ''
|
if (errorStr.search('timeout') != -1) {
|
vm.$message.error({
|
content: timeoutMessage || error,
|
duration: 10
|
})
|
} else if (errorStr.search('token is expired') != -1 || errorStr.search('token is invalid') != -1) {
|
const modal = {
|
'vm': vm,
|
'message': 'Token已失效,请重新登录...',
|
'okText': '重新登录',
|
'okAction': function() {
|
vm.$router.push({
|
name: 'logout'
|
})
|
},
|
'cancelAction': function() {
|
vm.$message.info('Clicked cancel')
|
}
|
}
|
confirmInstance(modal)
|
} else if (error.response) {
|
const status = error.response.status
|
if (status == 403) {
|
const modal = {
|
'vm': vm,
|
'message': 'Token已失效,请重新登录...',
|
'okText': '重新登录',
|
'okAction': function() {
|
vm.$router.push({
|
name: 'logout'
|
})
|
},
|
'cancelAction': function() {
|
vm.$message.info('Clicked cancel')
|
}
|
}
|
confirmInstance(modal)
|
} else if (status == 401) {
|
modalInstance({ type: 'error', message: '没有权限操作', vm: vm })
|
} else {
|
modalInstance({ type: 'error', message: defaultMessage || error, vm: vm })
|
}
|
} else {
|
if (type == 'modalInstance') {
|
modalInstance({ type: 'error', message: error, vm: vm })
|
} else {
|
noticeInstance({ type: 'error', message: error, vm: vm })
|
}
|
}
|
} else {
|
modalInstance({ type: 'error', message: String(error), vm: vm })
|
}
|
}
|