1234567891011121314151617181920212223242526272829303132333435363738394041 |
- import {ElMessage, ElMessageBox} from "element-plus";
- export const ExceptionEnum = {
- MESSAGE_ERROR: {code: 1001, name: '错误', turnOnHtml: false},
- MESSAGE_HTML_ERROR: {code: 1002, name: '错误', turnOnHtml: true},
- LOGICAL_ERROR: {code: 2001, name: '成功', turnOnHtml: false},
- LOGICAL_HTML_ERROR: {code: 2002, name: '成功', turnOnHtml: true},
- };
- class ExceptionCode {
- code: number;
- name: string;
- turnOnHtml: boolean;
- }
- export const BizException = (code: ExceptionCode, message?: string) => {
- if (code.code > 1000 && code.code < 2000) {
- ElMessage({
- type: 'error',
- message: message,
- dangerouslyUseHTMLString: code.turnOnHtml,
- duration: 2500,
- showClose: true,
- grouping: true,
- })
- } else if (code.code > 2000 && code.code < 3000) {
- ElMessageBox.alert(message, '提示', {
- type: 'error',
- dangerouslyUseHTMLString: code.turnOnHtml,
- }).then(() => {
- }).catch(() => {
- })
- }
- throw new Error(message)
- }
|