1
0
mirror of https://github.com/PanJiaChen/vue-element-admin.git synced 2025-08-15 00:15:57 +08:00
Edwin Betancourt 1e837db9e0
fix: Run process notification without session (#413)
* fix: Show notification run process without session.

* close notification after response.
2020-03-24 21:32:22 -04:00

84 lines
1.7 KiB
JavaScript

import { Message, Notification } from 'element-ui'
import language from '@/lang'
import router from '@/router'
export function hasTranslation(text) {
const hasKey = language.te('notifications.' + text)
if (hasKey) {
const translatedText = language.t('notifications.' + text)
return translatedText
}
return text
}
/**
*
* @param {string} type, required
* @param {string} title, required
* @param {object} message
* @param {string} summary
* @param {string} name
* @param {array} logs
*/
export function showNotification({ type, title, message, summary, name, logs = [] }) {
title = hasTranslation(title)
if (message) {
message = hasTranslation(message)
}
// For summary
if (summary) {
if (message) {
message = `${message} <br> ${summary}`
} else {
message = summary
}
}
// For logs
if (logs && logs.length) {
logs.forEach(logResult => {
if (logResult) {
message = `${message} <br> ${logResult.log}`
}
})
}
if (name) {
message = name + message
}
return Notification({
title,
message: `<div style="max-height: 100px; overflow-y: auto;">${message}</div>`,
type,
position: 'bottom-right',
dangerouslyUseHTMLString: true,
onClick() {
router.push({
name: 'ProcessActivity'
})
}
})
}
/**
*
* @param {string} type
* @param {string} message
* @param {number} duration
*/
export function showMessage({ type, message, duration = 0 }) {
let delay = 3000
if (type === 'info') {
delay = 2000
}
if (duration) {
delay = duration
}
return Message({
message,
type,
showClose: true,
duration: delay
})
}