增加一个全局的错误提示dialog
This commit is contained in:
parent
de68cf1420
commit
7df81f80b5
47
src/components/errorDialog/errorDialog.vue
Normal file
47
src/components/errorDialog/errorDialog.vue
Normal file
@ -0,0 +1,47 @@
|
||||
<template>
|
||||
<el-dialog
|
||||
title=""
|
||||
:visible="dialogVisible"
|
||||
width="416px"
|
||||
@cancel="handleClose"
|
||||
:closable="false"
|
||||
>
|
||||
<div class="confirm-box">
|
||||
<div class="confirm-title">
|
||||
<span>错误提示</span>
|
||||
</div>
|
||||
<div class="confirm-context"> {{message}}</div>
|
||||
</div>
|
||||
<div slot="footer" class="dialog-footer">
|
||||
<a-button @click="handleClose" type="primary">Close</a-button>
|
||||
</div>
|
||||
</el-dialog>
|
||||
</template>
|
||||
<script>
|
||||
export default {
|
||||
name: "iErrorMessage",
|
||||
data() {
|
||||
return {
|
||||
};
|
||||
},
|
||||
methods:{
|
||||
handleClose(){
|
||||
this.dialogVisible = false
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
.confirm-title{
|
||||
color: #323233;
|
||||
font-weight: 500;
|
||||
font-size: 16px;
|
||||
line-height: 1.4;
|
||||
}
|
||||
.confirm-context{
|
||||
margin-top: 8px;
|
||||
color: #323233;
|
||||
font-size: 14px;
|
||||
padding-left: 21px;
|
||||
}
|
||||
</style>
|
29
src/components/errorDialog/index.js
Normal file
29
src/components/errorDialog/index.js
Normal file
@ -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;
|
25
src/main.js
25
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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user