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 8ea17f1..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