From 82c2e20fce04e70100e802d2f896b9f0ee8a8435 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Chuailei000=E2=80=9D?= <2280131253@qq.com> Date: Thu, 16 Mar 2023 11:19:19 +0800 Subject: [PATCH] perf: message --- src/main.js | 4 ++-- src/utils/Message.js | 8 ++++---- src/utils/request.js | 4 ++-- src/utils/startup.js | 4 ++-- src/views/assets/const.js | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/main.js b/src/main.js index 9f915da55..0423c2979 100644 --- a/src/main.js +++ b/src/main.js @@ -19,7 +19,7 @@ import VueLogger from 'vuejs-logger' import loggerOptions from './utils/logger' import ECharts from 'vue-echarts' import service from '@/utils/request' -import { Message } from '@/utils/Message' +import { message } from '@/utils/message' import xss from '@/utils/xss' /** @@ -60,7 +60,7 @@ Vue.prototype.$axios = service window._ = require('lodash') // Vue.set(Vue.prototype, '_', _) -Vue.prototype.$message = Message +Vue.prototype.$message = message Vue.prototype.$xss = xss diff --git a/src/utils/Message.js b/src/utils/Message.js index af44719d1..ecb9fbf73 100644 --- a/src/utils/Message.js +++ b/src/utils/Message.js @@ -2,7 +2,7 @@ import { Message as elMessage } from 'element-ui' let messageDom = null -const Message = (options) => { +const message = (options) => { // 判断弹窗是否已存在, 若存在则关闭 if (messageDom) messageDom.close() messageDom = elMessage(options) @@ -10,11 +10,11 @@ const Message = (options) => { const typeArray = ['success', 'error', 'warning', 'info'] typeArray.forEach(type => { - Message[type] = options => { + message[type] = options => { if (typeof options === 'string') options = { message: options } options.type = type - return Message(options) + return message(options) } }) -export { Message } +export { message } diff --git a/src/utils/request.js b/src/utils/request.js index e449e4887..fc7d73e4d 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -4,7 +4,7 @@ import { getTokenFromCookie } from '@/utils/auth' import { getErrorResponseMsg } from '@/utils/common' import { refreshSessionIdAge } from '@/api/users' import { MessageBox } from 'element-ui' -import { Message } from '@/utils/Message' +import { message } from '@/utils/message' import store from '@/store' import axiosRetry from 'axios-retry' import router from '@/router' @@ -93,7 +93,7 @@ export function flashErrorMsg({ response, error }) { if (!response.config.disableFlashErrorMsg) { const responseErrorMsg = getErrorResponseMsg(error) const msg = responseErrorMsg || error.message - Message({ + message({ message: msg, type: 'error', duration: 5 * 1000 diff --git a/src/utils/startup.js b/src/utils/startup.js index ac1a84a20..0110e91b3 100644 --- a/src/utils/startup.js +++ b/src/utils/startup.js @@ -3,7 +3,7 @@ import store from '@/store' import router, { resetRouter } from '@/router' import Vue from 'vue' import VueCookie from 'vue-cookie' -import { Message } from '@/utils/Message' +import { message } from '@/utils/message' import orgUtil from '@/utils/org' import orgs from '@/api/orgs' import { getPropView, isViewHasOrgs } from '@/utils/jms' @@ -119,7 +119,7 @@ export async function generatePageRoutes({ to, from, next }) { } catch (error) { // remove token and go to login page to re-login // await store.dispatch('user/resetToken') - Message.error(error || 'Has Error') + message.error(error || 'Has Error') Vue.$log.error('Error occur: ', error) } } diff --git a/src/views/assets/const.js b/src/views/assets/const.js index 177893c7c..9ce68ac7e 100644 --- a/src/views/assets/const.js +++ b/src/views/assets/const.js @@ -3,7 +3,7 @@ import ProtocolSelector from '@/components/FormFields/ProtocolSelector' import AssetAccounts from '@/views/assets/Asset/AssetCreateUpdate/components/AssetAccounts' import rules from '@/components/DataForm/rules' import { Select2 } from '@/components/FormFields' -import { Message } from '@/utils/Message' +import { message } from '@/utils/message' export const filterSelectValues = (values) => { if (!values) return @@ -19,7 +19,7 @@ export const filterSelectValues = (values) => { const inputValue = { name, value } selects.push(inputValue) } else { - Message.error(i18n.t('assets.LabelInputFormatValidation')) + message.error(i18n.t('assets.LabelInputFormatValidation')) } } })