2019-06-23 03:35:23 -07:00
|
|
|
import { Notification } from 'element-ui';
|
|
|
|
import { ElNotificationOptions } from 'element-ui/types/notification';
|
2021-05-05 17:46:33 -07:00
|
|
|
import mixins from 'vue-typed-mixins';
|
|
|
|
|
|
|
|
import { externalHooks } from '@/components/mixins/externalHooks';
|
|
|
|
|
|
|
|
export const showMessage = mixins(externalHooks).extend({
|
2019-06-23 03:35:23 -07:00
|
|
|
methods: {
|
2021-06-12 08:06:56 -07:00
|
|
|
$showMessage(messageData: ElNotificationOptions) {
|
2019-06-23 03:35:23 -07:00
|
|
|
messageData.dangerouslyUseHTMLString = true;
|
|
|
|
if (messageData.position === undefined) {
|
|
|
|
messageData.position = 'bottom-right';
|
|
|
|
}
|
|
|
|
|
|
|
|
return Notification(messageData);
|
|
|
|
},
|
2021-06-12 08:06:56 -07:00
|
|
|
|
2021-06-22 10:33:07 -07:00
|
|
|
$showError(error: Error, title: string, message?: string) {
|
|
|
|
const messageLine = message ? `${message}<br/>` : '';
|
2019-06-23 03:35:23 -07:00
|
|
|
this.$showMessage({
|
|
|
|
title,
|
2021-06-12 08:06:56 -07:00
|
|
|
message: `
|
2021-06-22 10:33:07 -07:00
|
|
|
${messageLine}
|
2021-06-12 08:06:56 -07:00
|
|
|
<i>${error.message}</i>
|
|
|
|
${this.collapsableDetails(error)}`,
|
2019-06-23 03:35:23 -07:00
|
|
|
type: 'error',
|
|
|
|
duration: 0,
|
|
|
|
});
|
2021-06-12 08:06:56 -07:00
|
|
|
|
|
|
|
this.$externalHooks().run('showMessage.showError', {
|
|
|
|
title,
|
|
|
|
message,
|
|
|
|
errorMessage: error.message,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
collapsableDetails({ description, node }: Error) {
|
|
|
|
if (!description) return '';
|
|
|
|
|
|
|
|
const errorDescription =
|
|
|
|
description.length > 500
|
|
|
|
? `${description.slice(0, 500)}...`
|
|
|
|
: description;
|
|
|
|
|
|
|
|
return `
|
|
|
|
<br>
|
|
|
|
<br>
|
|
|
|
<details>
|
|
|
|
<summary
|
|
|
|
style="color: #ff6d5a; font-weight: bold; cursor: pointer;"
|
|
|
|
>
|
|
|
|
Show Details
|
|
|
|
</summary>
|
|
|
|
<p>${node.name}: ${errorDescription}</p>
|
|
|
|
</details>
|
|
|
|
`;
|
2019-06-23 03:35:23 -07:00
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|