From 7df81f80b55297a014f1a7b6062c20fc832895dc Mon Sep 17 00:00:00 2001 From: CounterFire2023 <136581895+CounterFire2023@users.noreply.github.com> Date: Sat, 13 Apr 2024 16:32:12 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B8=80=E4=B8=AA=E5=85=A8?= =?UTF-8?q?=E5=B1=80=E7=9A=84=E9=94=99=E8=AF=AF=E6=8F=90=E7=A4=BAdialog?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/errorDialog/errorDialog.vue | 47 ++++++++++++++++++++++ src/components/errorDialog/index.js | 29 +++++++++++++ src/main.js | 25 +++++++----- 3 files changed, 90 insertions(+), 11 deletions(-) create mode 100644 src/components/errorDialog/errorDialog.vue create mode 100644 src/components/errorDialog/index.js diff --git a/src/components/errorDialog/errorDialog.vue b/src/components/errorDialog/errorDialog.vue new file mode 100644 index 0000000..9181b0d --- /dev/null +++ b/src/components/errorDialog/errorDialog.vue @@ -0,0 +1,47 @@ + + + \ No newline at end of file diff --git a/src/components/errorDialog/index.js b/src/components/errorDialog/index.js new file mode 100644 index 0000000..3364e53 --- /dev/null +++ b/src/components/errorDialog/index.js @@ -0,0 +1,29 @@ +import Vue from 'vue'; +import confirm from './errorDialog.vue'; +const iErrorMessage = Vue.extend(confirm); +function showErrMsg(err) { + let errmsg = err; + if (typeof err === 'object') { + errmsg = JSON.stringify(err); + } + if (errmsg.indexOf('User denied message signature') > -1) { + errmsg = `User denied message signature`; + } else if (errmsg.indexOf('insufficient funds') > -1) { + errmsg = 'Insufficient funds'; + } + + const _confirm = new iErrorMessage({ + data() { + return { + message: errmsg, + dialogVisible: true, + }; + }, + }); + const element = _confirm.$mount().$el; + document.body.appendChild(element); +} +showErrMsg.install = (Vue) => { + Vue.prototype.$showErr = showErrMsg; +}; +export default showErrMsg; diff --git a/src/main.js b/src/main.js index 19f88d0..bc03638 100644 --- a/src/main.js +++ b/src/main.js @@ -7,10 +7,13 @@ import ElementUI from 'element-ui' import 'element-ui/lib/theme-chalk/index.css' import moment from 'moment' import axios from 'axios' +import iErrorMsg from './components/errorDialog/index.js' Vue.prototype.$axios = axios // import Web3 from 'web3' Vue.use(ElementUI) +// 全局的错误提示, this.$showErr(string|object) +Vue.use(iErrorMsg) import {Message} from 'element-ui' Vue.prototype.$message = Message @@ -19,17 +22,17 @@ Vue.filter('formatDate', function (value) { return moment(value).format('YYYY-MM-DD HH:mm:ss') }) -Vue.config.errorHandler = function(err, vm, info){ - //todo: show error message - console.error('[vue error handler|error]: ', err) - console.error('[vue error handler|VM]: ', vm) - console.warn('[vue error handler|info]: ', info) - Message({ - message: info, - type: 'error', - duration: 3 * 1000 - }) -} +// Vue.config.errorHandler = function(err, vm, info){ +// //todo: show error message +// console.error('[vue error handler|error]: ', err) +// console.error('[vue error handler|VM]: ', vm) +// console.warn('[vue error handler|info]: ', info) +// Message({ +// message: info, +// type: 'error', +// duration: 3 * 1000 +// }) +// } Vue.config.productionTip = false