Skip to content

Commit

Permalink
fix: 前端eslint代码规范 --story=119540612
Browse files Browse the repository at this point in the history
# Reviewed, transaction id: 17761
  • Loading branch information
ywywZhou committed Sep 9, 2024
1 parent 508f065 commit 225e247
Show file tree
Hide file tree
Showing 27 changed files with 132 additions and 145 deletions.
2 changes: 1 addition & 1 deletion frontend/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = {
browser: true,
},
// https://github.com/standard/standard/blob/master/docs/RULES-en.md
extends: ['@tencent/eslint-config-tencent', 'plugin:vue/recommended'],
extends: ['eslint-config-tencent', 'plugin:vue/recommended'],
// required to lint *.vue files
plugins: [
'vue',
Expand Down
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"@babel/plugin-transform-runtime": "^7.14.3",
"@babel/preset-env": "^7.0.0",
"@babel/runtime": "^7.7.6",
"@tencent/eslint-config-tencent": "^1.0.4",
"eslint-config-tencent": "^1.0.4",
"@vue/babel-preset-jsx": "^1.4.0",
"autoprefixer": "^7.1.4",
"babel-cli": "^6.26.0",
Expand Down
14 changes: 7 additions & 7 deletions frontend/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@
siteUrl: state => state.site_url,
isIframe: state => state.isIframe,
}),
spaceId () {
spaceId() {
const { params, query } = this.$route;
return params.spaceId || query.space_id
}
return params.spaceId || query.space_id;
},
},
watch: {
'$route'(val, oldVal) {
Expand All @@ -85,10 +85,10 @@
}
// 路由发生变化时清空失败message列表
if (val.name !== oldVal.name && this.errorMsgList.length) {
this.errorMsgList.forEach(msgInstance => {
msgInstance.close()
})
this.errorMsgList = []
this.errorMsgList.forEach((msgInstance) => {
msgInstance.close();
});
this.errorMsgList = [];
}
},
spaceId: {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/api/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ axios.interceptors.response.use(
const successUrl = `${window.location.origin}${window.SITE_URL}static/bkflow/login_success.html`;
let [loginUrl] = data.login_url.split('?');
loginUrl = `${loginUrl}?c_url=${encodeURIComponent(successUrl)}`;

showLoginModal({ loginUrl });
}
}
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/components/common/modal/home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
:src="image4"
alt="">
<p class="project-presentation">
<i18n tag="div" path="projectPresentationTips">
<i18n
tag="div"
path="projectPresentationTips">
<span class="highlight">{{ $t('高效') }}</span>
<span class="highlight">{{ $t('灵活') }}</span>
<span class="highlight">{{ $t('流程执行') }}</span>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/layout/MenuSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
});
await this.getSpaceList();
// 如果没有空间列表则打开空间申请弹框
this.isVisible = !this.spaceList.length && (this.isAdmin || this.isSpaceSuperuser)
this.isVisible = !this.spaceList.length && (this.isAdmin || this.isSpaceSuperuser);
},
methods: {
...mapActions([
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/layout/Navigation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
isNeedMenu() {
const { name, meta } = this.$route;
let isShow = meta.admin || this.isAdmin || this.isCurSpaceSuperuser;
isShow = isShow && name && name !== 'home'
return isShow
isShow = isShow && name && name !== 'home';
return isShow;
},
appName() {
const { i18n, name } = this.platformInfo;
Expand Down
12 changes: 6 additions & 6 deletions frontend/src/components/layout/NavigationHeadLeft.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
isAdmin: state => state.isAdmin,
isSpaceSuperuser: state => state.isSpaceSuperuser,
}),
headerList () {
headerList() {
return [
{
name: this.$t('空间管理'),
Expand All @@ -41,21 +41,21 @@
id: 'system-manager',
show: this.isAdmin,
},
]
}
];
},
},
watch: {
'$route.name': {
handler(val) {
if (!val || val === 'home') {
this.navActive = ''
return
this.navActive = '';
return;
}
this.navActive = val === 'systemAdmin' ? 'system-manager' : 'space-manager';
},
deep: true,
immediate: true,
}
},
},
methods: {
onHandleNavClick(nav) {
Expand Down
28 changes: 16 additions & 12 deletions frontend/src/components/layout/NavigationHeadRight.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,22 @@
</div>
<!-- 用户icon -->
<div
class="user-avatar"
v-bk-tooltips="{
...basicTipsConfig,
distance: 25,
extCls: 'logout-tips',
content: '#logout-html'
}">
}"
class="user-avatar">
{{ username }}
<i class="bk-icon icon-down-shape"></i>
<i class="bk-icon icon-down-shape" />
</div>
<div id="logout-html">
<div class="operate-item" @click="handleLogout">{{ $t('退出登录') }}</div>
<div
class="operate-item"
@click="handleLogout">
{{ $t('退出登录') }}
</div>
</div>
<!-- 日志组件 -->
<version-log
Expand Down Expand Up @@ -102,7 +106,7 @@
distance: 17,
theme: 'light',
hideOnClick: false,
}
},
};
},
computed: {
Expand Down Expand Up @@ -191,17 +195,17 @@
const version = data[0];
this.loadLogDetail(version);
},
async handleLogout () {
async handleLogout() {
try {
await this.logout()
await this.logout();
} catch (error) {
console.warn(error)
console.warn(error);
} finally {
let loginUrl = window.LOGIN_URL
loginUrl = /\/$/.test(loginUrl) ? loginUrl : `${loginUrl}/`
window.location.replace(`${loginUrl}?is_from_logout=1&c_url=${window.location.href}`)
let loginUrl = window.LOGIN_URL;
loginUrl = /\/$/.test(loginUrl) ? loginUrl : `${loginUrl}/`;
window.location.replace(`${loginUrl}?is_from_logout=1&c_url=${window.location.href}`);
}
}
},
},
};
</script>
Expand Down
12 changes: 6 additions & 6 deletions frontend/src/components/layout/NavigationMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@
},
created() {
bus.$on('cancelRoute', () => {
const { name } = this.$route
const { name } = this.$route;
if (name !== this.currentNav) {
this.setNavigationTitle(this.$route)
this.randomKey = new Date().getTime()
this.setNavigationTitle(this.$route);
this.randomKey = new Date().getTime();
}
})
});
},
methods: {
setNavigationTitle(route) {
Expand All @@ -141,8 +141,8 @@
return;
}
if (route.name === 'EnginePanel') {
this.currentNav = route.query.type || 'task'
return
this.currentNav = route.query.type || 'task';
return;
}
this.routerList.some((item) => {
if (item.subRoutes?.includes(route.name)) {
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/config/i18n/cn.js
Original file line number Diff line number Diff line change
Expand Up @@ -897,10 +897,10 @@ const cn = {
请求成功: '请求成功',
'请求异常(外部系统错误或非法操作)': '请求异常(外部系统错误或非法操作)',
'请求异常(内部系统发生未知错误)': '请求异常(内部系统发生未知错误)',
'秒': '秒 | {n} 秒 | {n} 秒',
'分钟': '分钟 | {n} 分钟 | {n} 分钟',
'小时': '小时 | {n} 小时 | {n} 小时',
'天': '天 | {n} 天 | {n} 天',
: '秒 | {n} 秒 | {n} 秒',
分钟: '分钟 | {n} 分钟 | {n} 分钟',
小时: '小时 | {n} 小时 | {n} 小时',
: '天 | {n} 天 | {n} 天',
新建全局变量: '新建全局变量',
error_handle_秒: '秒',
};
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const store = new Vuex.Store({
token: '',
spaceId: '',
spaceList: [],
isAdmin: false,
isAdmin: false,
isSpaceSuperuser: false, // 是否为某个空间下的管理员
isCurSpaceSuperuser: false, // 是否为当前空间管理员
hasAlertNotice: false,
Expand Down Expand Up @@ -329,8 +329,8 @@ const store = new Vuex.Store({
return resp;
},
// 退出登录
logout () {
return axios.get('logout').then(response => response.data)
logout() {
return axios.get('logout').then(response => response.data);
},
},
});
Expand Down
57 changes: 28 additions & 29 deletions frontend/src/utils/errorNotify.js
Original file line number Diff line number Diff line change
@@ -1,63 +1,62 @@
// 接口异常通知提示
import i18n from '@/config/i18n/index.js'
import bus from '@/utils/bus.js'
import i18n from '@/config/i18n/index.js';
import bus from '@/utils/bus.js';
export default class ErrorNotify {
constructor(errorInfo, vueInstance) {
const { msg, type, traceId, errorSource, title } = errorInfo
this.type = type
const { msg, type, traceId, errorSource, title } = errorInfo;
this.type = type;
// 标题
const msgTitle = title || this.getTitleAndContent(msg, true, errorSource)
const msgTitle = title || this.getTitleAndContent(msg, true, errorSource);

// 详情
let details = {}
const msgLabel = type === 'success' ? 'success_msg' : 'error_msg'
details[msgLabel] = this.getTitleAndContent(msg, false, errorSource)
let details = {};
const msgLabel = type === 'success' ? 'success_msg' : 'error_msg';
details[msgLabel] = this.getTitleAndContent(msg, false, errorSource);
if (traceId) {
details.trace_id = traceId
details.trace_id = traceId;
}
details = JSON.stringify(details)
details = JSON.stringify(details);

// 助手
const helperUrl = type === 'success' ? '' : window.MESSAGE_HELPER_URL || ''
const helperUrl = type === 'success' ? '' : window.MESSAGE_HELPER_URL || '';

// 工具列表
const actions = [
{ id: 'assistant', disabled: !helperUrl },
{ id: 'details' },
{ id: 'fix' },
{ id: 'close' }
]
{ id: 'close' },
];
const errorMsgInstance = vueInstance.$bkMessage({
message: {
title: msgTitle,
details,
assistant: helperUrl,
type: 'key-value'
type: 'key-value',
},
actions,
theme: type,
ellipsisLine: 2,
ellipsisCopy: true,
extCls: 'interface-exception-notify-message',
onClose: () => {
const index = window.msg_list.findIndex(item => item.msg === msg)
const index = window.msg_list.findIndex(item => item.msg === msg);
if (index > -1) {
window.msg_list.splice(index, 1)
window.msg_list.splice(index, 1);
}
bus.$emit('onCloseErrorNotify', details)
}
})
vueInstance.errorMsgList.push(errorMsgInstance)
bus.$emit('onCloseErrorNotify', details);
},
});
vueInstance.errorMsgList.push(errorMsgInstance);
}
getTitleAndContent (info, isTitle, errorSource) {
let content = isTitle ? '' : info
getTitleAndContent(info, isTitle, errorSource) {
let content = isTitle ? '' : info;
if (isTitle && !content) {
content = this.type === 'success'
? i18n.t('请求成功')
: errorSource === 'result'
? i18n.t('请求异常(外部系统错误或非法操作)')
: i18n.t('请求异常(内部系统发生未知错误)')
content = errorSource === 'result'
? i18n.t('请求异常(外部系统错误或非法操作)')
: i18n.t('请求异常(内部系统发生未知错误)');
content = this.type === 'success' ? i18n.t('请求成功') : content;
}
return content
return content;
}
}
}
4 changes: 2 additions & 2 deletions frontend/src/views/admin/Space/SpaceConfig/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@
required: true,
message: this.$t('必填项'),
trigger: 'change',
}]
}
}],
},
};
},
computed: {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/views/admin/Space/Task/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@
params: {
spaceId: this.spaceId,
},
query: { type: this.$route.query.activeTab }
query: { type: this.$route.query.activeTab },
});
},
},
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/views/admin/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
...mapState({
isAdmin: state => state.isAdmin,
isSpaceSuperuser: state => state.isSpaceSuperuser,
})
}),
},
beforeRouteEnter(to, from, next) {
next((vm) => {
if (vm.isAdmin || vm.isSpaceSuperuser) return
if (vm.isAdmin || vm.isSpaceSuperuser) return;
// 没任何权限下,如果从首页路由进来则打开空间申请弹框,否则重定向home
if (from.name === 'home') {
vm.isVisible = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@
<full-code-editor
:value="JSON.stringify(output.value, null, 4)" />
</td>
<td v-else class="output-value">
<td
v-else
class="output-value">
{{ output.value }}
</td>
</tr>
Expand Down
Loading

0 comments on commit 225e247

Please sign in to comment.