refactor: 增加一个 v-tester 指令,当用户只有当前工作空间的只读权限的时候隐藏操作按钮

This commit is contained in:
Captain.B 2020-12-24 13:57:37 +08:00
parent 025a5c5638
commit 838927a321
4 changed files with 420 additions and 402 deletions

View File

@ -39,7 +39,8 @@
:label="$t('api_test.definition.api_type')" :label="$t('api_test.definition.api_type')"
show-overflow-tooltip> show-overflow-tooltip>
<template v-slot:default="scope" class="request-method"> <template v-slot:default="scope" class="request-method">
<el-tag size="mini" :style="{'background-color': getColor(true, scope.row.method), border: getColor(true, scope.row.method)}" class="api-el-tag"> <el-tag size="mini" :style="{'background-color': getColor(true, scope.row.method), border: getColor(true, scope.row.method)}"
class="api-el-tag">
{{ scope.row.method }} {{ scope.row.method }}
</el-tag> </el-tag>
</template> </template>
@ -78,10 +79,10 @@
<el-table-column v-if="!isReadOnly && !isRelevance" :label="$t('commons.operating')" min-width="130" align="center"> <el-table-column v-if="!isReadOnly && !isRelevance" :label="$t('commons.operating')" min-width="130" align="center">
<template v-slot:default="scope"> <template v-slot:default="scope">
<el-button type="text" @click="reductionApi(scope.row)" v-if="trashEnable">恢复</el-button> <el-button type="text" @click="reductionApi(scope.row)" v-if="trashEnable" v-tester>恢复</el-button>
<el-button type="text" @click="editApi(scope.row)" v-else>{{$t('commons.edit')}}</el-button> <el-button type="text" @click="editApi(scope.row)" v-else v-tester>{{ $t('commons.edit') }}</el-button>
<el-button type="text" @click="handleTestCase(scope.row)">{{ $t('api_test.definition.request.case') }}</el-button> <el-button type="text" @click="handleTestCase(scope.row)">{{ $t('api_test.definition.request.case') }}</el-button>
<el-button type="text" @click="handleDelete(scope.row)" style="color: #F56C6C">{{$t('commons.delete')}}</el-button> <el-button type="text" @click="handleDelete(scope.row)" style="color: #F56C6C" v-tester>{{ $t('commons.delete') }}</el-button>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
@ -101,7 +102,6 @@
import MsTableOperator from "../../../../common/components/MsTableOperator"; import MsTableOperator from "../../../../common/components/MsTableOperator";
import MsTableOperatorButton from "../../../../common/components/MsTableOperatorButton"; import MsTableOperatorButton from "../../../../common/components/MsTableOperatorButton";
import MsTableButton from "../../../../common/components/MsTableButton"; import MsTableButton from "../../../../common/components/MsTableButton";
import {LIST_CHANGE, TrackEvent} from "@/business/components/common/head/ListEvent";
import MsTablePagination from "../../../../common/pagination/TablePagination"; import MsTablePagination from "../../../../common/pagination/TablePagination";
import MsTag from "../../../../common/components/MsTag"; import MsTag from "../../../../common/components/MsTag";
import MsApiCaseList from "../case/ApiCaseList"; import MsApiCaseList from "../case/ApiCaseList";
@ -109,7 +109,7 @@
import MsBottomContainer from "../BottomContainer"; import MsBottomContainer from "../BottomContainer";
import ShowMoreBtn from "../../../../track/case/components/ShowMoreBtn"; import ShowMoreBtn from "../../../../track/case/components/ShowMoreBtn";
import MsBatchEdit from "../basis/BatchEdit"; import MsBatchEdit from "../basis/BatchEdit";
import {API_METHOD_COLOUR, REQ_METHOD, API_STATUS} from "../../model/JsonData"; import {API_METHOD_COLOUR, API_STATUS, REQ_METHOD} from "../../model/JsonData";
import {getCurrentProjectID} from "@/common/js/utils"; import {getCurrentProjectID} from "@/common/js/utils";
import {WORKSPACE_ID} from '../../../../../../common/js/constants'; import {WORKSPACE_ID} from '../../../../../../common/js/constants';
import ApiListContainer from "./ApiListContainer"; import ApiListContainer from "./ApiListContainer";

View File

@ -9,9 +9,11 @@
:disabled="item.disabled"> :disabled="item.disabled">
</el-option> </el-option>
</el-select> </el-select>
<el-input class="filter-input" :class="{'read-only': isReadOnly}" :placeholder="$t('test_track.module.search')" v-model="condition.filterText" size="small"> <el-input class="filter-input" :class="{'read-only': isReadOnly}" :placeholder="$t('test_track.module.search')" v-model="condition.filterText"
size="small">
<template v-slot:append> <template v-slot:append>
<el-dropdown v-if="!isReadOnly" size="small" split-button type="primary" class="ms-api-button" @click="handleCommand('add-api')" <el-dropdown v-if="!isReadOnly" size="small" split-button type="primary" class="ms-api-button" @click="handleCommand('add-api')"
v-tester
@command="handleCommand"> @command="handleCommand">
<el-button icon="el-icon-folder-add" @click="addApi"></el-button> <el-button icon="el-icon-folder-add" @click="addApi"></el-button>
<el-dropdown-menu slot="dropdown"> <el-dropdown-menu slot="dropdown">

View File

@ -11,7 +11,7 @@ import YanProgress from 'yan-progress';
import './permission' // permission control import './permission' // permission control
import i18n from "../i18n/i18n"; import i18n from "../i18n/i18n";
import store from "./store"; import store from "./store";
import {permission, roles, xpack} from './permission' import {permission, roles, tester, xpack} from './permission'
import chart from "../common/js/chart"; import chart from "../common/js/chart";
import CalendarHeatmap from "../common/js/calendar-heatmap"; import CalendarHeatmap from "../common/js/calendar-heatmap";
import '../common/css/menu-header.css'; import '../common/css/menu-header.css';
@ -41,6 +41,8 @@ Vue.directive('roles', roles);
Vue.directive('xpack', xpack); Vue.directive('xpack', xpack);
Vue.directive('tester', tester);
new Vue({ new Vue({
el: '#app', el: '#app',
router, router,

View File

@ -1,6 +1,6 @@
import router from './components/common/router/router' import router from './components/common/router/router'
import {TokenKey} from '@/common/js/constants'; import {TokenKey} from '@/common/js/constants';
import {hasLicense, hasRolePermissions, hasRoles} from "@/common/js/utils"; import {checkoutTestManagerOrTestUser, hasLicense, hasRolePermissions, hasRoles} from "@/common/js/utils";
import NProgress from 'nprogress' // progress bar import NProgress from 'nprogress' // progress bar
import 'nprogress/nprogress.css' // progress bar style import 'nprogress/nprogress.css' // progress bar style
const whiteList = ['/login']; // no redirect whitelist const whiteList = ['/login']; // no redirect whitelist
@ -25,6 +25,20 @@ export const xpack = {
} }
}; };
export const tester = {
inserted(el, binding) {
checkTestManagerOrTestUser(el, binding);
}
};
function checkTestManagerOrTestUser(el, binding) {
let v = checkoutTestManagerOrTestUser();
if (!v) {
el.parentNode && el.parentNode.removeChild(el)
}
}
function checkLicense(el, binding, type) { function checkLicense(el, binding, type) {
let v = hasLicense() let v = hasLicense()