提交 0465bd86 编写于 作者: aaronchen2k2k's avatar aaronchen2k2k

fix code review issues

上级 ccbb954d
...@@ -50,13 +50,6 @@ ...@@ -50,13 +50,6 @@
</div> </div>
</template> </template>
<script lang="ts">
export default {
name: 'TreeNode',
inheritAttrs: false
}
</script>
<script setup lang="ts"> <script setup lang="ts">
import { defineProps, defineEmits, withDefaults, computed, ref } from 'vue'; import { defineProps, defineEmits, withDefaults, computed, ref } from 'vue';
import Toolbar, { ToolbarItemProps } from './Toolbar.vue'; import Toolbar, { ToolbarItemProps } from './Toolbar.vue';
...@@ -65,6 +58,7 @@ import Button from './Button.vue'; ...@@ -65,6 +58,7 @@ import Button from './Button.vue';
export interface TreeNodeData { export interface TreeNodeData {
id: string, id: string,
type: string,
title: string, title: string,
level?: number, level?: number,
indent?: number, indent?: number,
......
...@@ -140,3 +140,4 @@ export function getContextMenuStyle(x, y, height) { ...@@ -140,3 +140,4 @@ export function getContextMenuStyle(x, y, height) {
top: `${top}px`, top: `${top}px`,
} }
} }
/**
* 自定义 request 网络请求工具,基于axios
* @author LiQingSong
*/
import axios, { AxiosPromise, AxiosRequestConfig, AxiosResponse } from 'axios'; import axios, { AxiosPromise, AxiosRequestConfig, AxiosResponse } from 'axios';
import settings from '@/config/settings'; import settings from '@/config/settings';
import i18n from "@/config/i18n"; import i18n from "@/config/i18n";
...@@ -45,9 +41,6 @@ const request = axios.create({ ...@@ -45,9 +41,6 @@ const request = axios.create({
timeout: 0 // 请求超时时间,5000(单位毫秒) / 0 不做限制 timeout: 0 // 请求超时时间,5000(单位毫秒) / 0 不做限制
}); });
// 全局设置 - post请求头
// request.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8';
/** /**
* 请求拦截器 * 请求拦截器
*/ */
...@@ -71,11 +64,6 @@ request.interceptors.request.use( ...@@ -71,11 +64,6 @@ request.interceptors.request.use(
console.log(`currSiteId=${config.params[settings.currSiteId]}, currProductId=${config.params[settings.currProductId]}`) console.log(`currSiteId=${config.params[settings.currSiteId]}, currProductId=${config.params[settings.currProductId]}`)
// if (!config.params[settings.currWorkspace]) {
// const workspacePath = await getCache(settings.currWorkspace);
// config.params = { ...config.params, [settings.currWorkspace]: workspacePath, lang: i18n.global.locale.value };
// }
console.log('=== request ===', config.url, config) console.log('=== request ===', config.url, config)
return config; return config;
}, },
...@@ -90,7 +78,7 @@ request.interceptors.response.use( ...@@ -90,7 +78,7 @@ request.interceptors.response.use(
console.log('=== response ===', axiosResponse.config.url, axiosResponse) console.log('=== response ===', axiosResponse.config.url, axiosResponse)
const data: ResponseData = axiosResponse.data; const data: ResponseData = axiosResponse.data;
const { code, msg } = data; const { code } = data;
// 自定义状态码验证 // 自定义状态码验证
if (code !== 0) { if (code !== 0) {
......
import { RouteRecordRaw, RouteLocationNormalizedLoaded } from 'vue-router';
/** /**
* Route utils * Route utils
* @author LiQingSong
*/ */
/** /**
* 面包屑类型 * 面包屑类型
...@@ -31,13 +32,6 @@ declare module 'vue-router' { ...@@ -31,13 +32,6 @@ declare module 'vue-router' {
roles?: string[]; roles?: string[];
// 标题,路由在菜单、浏览器title 或 面包屑中展示的文字,目前可以使用locales // 标题,路由在菜单、浏览器title 或 面包屑中展示的文字,目前可以使用locales
title: string; title: string;
/**
* 面包屑自定义内容:
* 1、默认不配置按照路由自动读取;
* 2、设置为 false , 按照路由自动读取并不读当前自己;
* 3、配置对应的面包屑格式如下:
*/
breadcrumb?: BreadcrumbType[] | false;
/** /**
* 设置tab导航存储规则类型 * 设置tab导航存储规则类型
* 1、默认不配置按照path(route.path)规则 * 1、默认不配置按照path(route.path)规则
...@@ -64,22 +58,12 @@ declare module 'vue-router' { ...@@ -64,22 +58,12 @@ declare module 'vue-router' {
belongTopMenu?: string; belongTopMenu?: string;
} }
} }
import { RouteRecordRaw, RouteLocationNormalizedLoaded } from 'vue-router';
/** /**
* 自定义重命名 - 路由类型 * 自定义重命名 - 路由类型
*/ */
export type RoutesDataItem = RouteRecordRaw; export type RoutesDataItem = RouteRecordRaw;
/**
* 头部tab导航类型
*/
export interface TabNavItem {
route: RouteLocationNormalizedLoaded,
menu: RoutesDataItem
}
import { isExternal } from './validate'; import { isExternal } from './validate';
import { equalObject } from "./object"; import { equalObject } from "./object";
...@@ -99,7 +83,7 @@ export const getRouteItem = (pathname: string, routesData: RoutesDataItem[]): Ro ...@@ -99,7 +83,7 @@ export const getRouteItem = (pathname: string, routesData: RoutesDataItem[]): Ro
item = element; item = element;
break; break;
} else if (element.path.indexOf(':') > 0) { } else if (element.path.indexOf(':') > 0) {
const reg = new RegExp("(:[^/]+)","gmi"); const reg = /(:[^/]+)/gmi
const path = element.path.replaceAll(reg,".+") const path = element.path.replaceAll(reg,".+")
const pass = new RegExp(path).test(pathname) const pass = new RegExp(path).test(pathname)
...@@ -168,7 +152,7 @@ export const setRoutePathForParent = (pathname: string, parentPath = '/', headSt ...@@ -168,7 +152,7 @@ export const setRoutePathForParent = (pathname: string, parentPath = '/', headSt
return pathname; return pathname;
} }
return pathname.substr(0, headStart.length) === headStart return pathname.substring(0, headStart.length) === headStart
? pathname ? pathname
: `${parentPath}/${pathname}`; : `${parentPath}/${pathname}`;
}; };
...@@ -192,26 +176,6 @@ export const getPathsTheRoutes = ( pathname: string[], routesData: RoutesDataIte ...@@ -192,26 +176,6 @@ export const getPathsTheRoutes = ( pathname: string[], routesData: RoutesDataIte
return routeItem; return routeItem;
}; };
/**
* 获取面包屑对应的 route 数组
* @param route route 当前routeItem
* @param pathname path[]
* @param routesData routes
*/
export const getBreadcrumbRoutes = (route: RoutesDataItem, pathname: string[], routesData: RoutesDataItem[]): BreadcrumbType[] => {
if (!route.breadcrumb) {
const routePaths = getPathsTheRoutes(pathname, routesData);
const ret = route.breadcrumb === false ? routePaths : [...routePaths, route]
return ret;
}
return route.breadcrumb;
};
/** /**
* 获取当前路由选中的侧边栏菜单path * 获取当前路由选中的侧边栏菜单path
* @param route route * @param route route
...@@ -244,7 +208,7 @@ export const vueRoutes = (routesData: RoutesDataItem[], parentPath = '/', headSt ...@@ -244,7 +208,7 @@ export const vueRoutes = (routesData: RoutesDataItem[], parentPath = '/', headSt
const itemChildren = children || []; const itemChildren = children || [];
const newItem: RoutesDataItem = { ...other }; const newItem: RoutesDataItem = { ...other };
newItem.path = setRoutePathForParent(newItem.path, parentPath, headStart); newItem.path = setRoutePathForParent(newItem.path, parentPath, headStart);
if (item.children) { if (item.children) {
newItem.children = [ newItem.children = [
...vueRoutes(itemChildren, newItem.path, headStart), ...vueRoutes(itemChildren, newItem.path, headStart),
...@@ -261,20 +225,18 @@ export const vueRoutes = (routesData: RoutesDataItem[], parentPath = '/', headSt ...@@ -261,20 +225,18 @@ export const vueRoutes = (routesData: RoutesDataItem[], parentPath = '/', headSt
*/ */
export const routesSetMeta = (routesData: RoutesDataItem[]): RoutesDataItem[] => { export const routesSetMeta = (routesData: RoutesDataItem[]): RoutesDataItem[] => {
return routesData.map(item => { return routesData.map(item => {
const { children, tabNavType, meta, ...other } = item; const { children, tabNavType, meta, ...other } = item;
const newItem: RoutesDataItem = { const newItem: RoutesDataItem = {
meta: { meta: {
...meta, ...meta,
// 自定义设置的 meta 值 S // 自定义设置的 meta 值 S
tabNavType: tabNavType || 'path',
tabNavType: tabNavType || 'path',
// 自定义设置的 meta 值 E // 自定义设置的 meta 值 E
}, },
...other ...other
}; };
if (item.children) { if (item.children) {
const itemChildren = children || []; const itemChildren = children || [];
newItem.children = [ newItem.children = [
...@@ -304,7 +266,7 @@ export const hasPermissionRouteRoles = (userRoles: string[], roles?: string | st ...@@ -304,7 +266,7 @@ export const hasPermissionRouteRoles = (userRoles: string[], roles?: string | st
if (typeof roles === 'string') { if (typeof roles === 'string') {
return userRoles.includes(roles); return userRoles.includes(roles);
} }
if(roles instanceof Array && roles.length > 0) { if(roles instanceof Array && roles.length > 0) {
return roles.some(role => userRoles.includes(role)); return roles.some(role => userRoles.includes(role));
...@@ -325,7 +287,6 @@ export const hasPermission = (roles: string[], route: RoutesDataItem): boolean = ...@@ -325,7 +287,6 @@ export const hasPermission = (roles: string[], route: RoutesDataItem): boolean =
if (route.roles) { if (route.roles) {
return route.roles.some(role => roles.includes(role)); return route.roles.some(role => roles.includes(role));
//return roles.some(role => route.roles?.includes(role));
} }
return true; return true;
...@@ -357,28 +318,24 @@ export const getPermissionMenuData = ( roles: string[], routes: RoutesDataItem[] ...@@ -357,28 +318,24 @@ export const getPermissionMenuData = ( roles: string[], routes: RoutesDataItem[]
* @param route1 vue-route * @param route1 vue-route
* @param route2 vue-route * @param route2 vue-route
* @param type 判断规则 * @param type 判断规则
* @returns * @returns
*/ */
export const equalTabNavRoute = (route1: RouteLocationNormalizedLoaded, export const equalTabNavRoute = (route1: RouteLocationNormalizedLoaded,
route2: RouteLocationNormalizedLoaded, route2: RouteLocationNormalizedLoaded,
type: TabNavType = 'path'): boolean=> { type: TabNavType = 'path'): boolean=> {
let is = false; let is = false;
switch (type) { if (type === 'querypath') { // path + query
case 'querypath': // path + query is = equalObject(route1.query, route2.query) && route1.path === route2.path
is = equalObject(route1.query,route2.query) && route1.path === route2.path } else { // path
break; is = route1.path === route2.path
default: // path
is = route1.path === route2.path
if (!is) { if (!is) {
const arr1 = route1.path.split('/') const arr1 = route1.path.split('/')
const arr2 = route2.path.split('/') const arr2 = route2.path.split('/')
is = arr1[1] == '~' && arr2[1] == '~' && arr1[2] == arr2[2] // 同源高亮 is = arr1[1] == '~' && arr2[1] == '~' && arr1[2] == arr2[2] // 同源高亮
} }
break;
} }
return is; return is;
......
import moment from "moment"; import moment from "moment";
import {AutoTestTools, ScriptLanguages, TestTools, BuildTools} from "@/utils/const"; import {AutoTestTools, TestTools, BuildTools} from "@/utils/const";
import request from "@/utils/request";
function addItems(item, list, map) {
const lowerCase = item.toLowerCase()
list.push(lowerCase)
map[lowerCase] = item
}
export function getUnitTestFrameworks(): any { export function getUnitTestFrameworks(): any {
const list = new Array<string>() const list = new Array<string>()
const map = {} const map = {}
TestTools.forEach((item) => { TestTools.forEach((item) => {
const lowerCase = item.toLowerCase() addItems(item, list, map)
list.push(lowerCase)
map[lowerCase] = item
}) })
return {list: list, map: map} return {list: list, map: map}
...@@ -34,9 +37,7 @@ export function getAutoTestTools(): any { ...@@ -34,9 +37,7 @@ export function getAutoTestTools(): any {
const list = new Array<string>() const list = new Array<string>()
const map = {} const map = {}
AutoTestTools.forEach((item) => { AutoTestTools.forEach((item) => {
const lowerCase = item.toLowerCase() addItems(item, list, map)
list.push(lowerCase)
map[lowerCase] = item
}) })
return {list: list, map: map} return {list: list, map: map}
......
...@@ -10,8 +10,7 @@ export async function getLangSettings() { ...@@ -10,8 +10,7 @@ export async function getLangSettings() {
}) })
if (json.code === 0) { if (json.code === 0) {
const data = json.data return json.data
return data
} }
return {languages: [], languageMap: {}} return {languages: [], languageMap: {}}
...@@ -26,8 +25,7 @@ export async function getLangInterpreter(lang) { ...@@ -26,8 +25,7 @@ export async function getLangInterpreter(lang) {
}) })
if (json.code === 0) { if (json.code === 0) {
const data = json.data return json.data
return data
} }
return {path: '', info: ''} return {path: '', info: ''}
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
import { defineComponent } from 'vue' import { defineComponent } from 'vue'
export default defineComponent({ export default defineComponent({
beforeRouteEnter(to, from, next) { beforeRouteEnter(_to, from, next) {
// 在渲染该组件的对应路由被验证前调用 // 在渲染该组件的对应路由被验证前调用
// 不能获取组件实例 `this` ! // 不能获取组件实例 `this` !
// 因为当守卫执行时,组件实例还没被创建! // 因为当守卫执行时,组件实例还没被创建!
......
...@@ -3,7 +3,7 @@ import { StoreModuleType } from "@/utils/store"; ...@@ -3,7 +3,7 @@ import { StoreModuleType } from "@/utils/store";
import { ResponseData } from '@/utils/request'; import { ResponseData } from '@/utils/request';
import { QueryParams, QueryResult } from '@/types/data.d'; import { QueryParams, QueryResult } from '@/types/data.d';
import { import {
list, get, remove,getLastest, list, get, remove,
} from './service'; } from './service';
export interface StateType { export interface StateType {
...@@ -74,7 +74,7 @@ const StoreModel: ModuleType = { ...@@ -74,7 +74,7 @@ const StoreModel: ModuleType = {
return true; return true;
}, },
async delete({ commit , dispatch, state}, data: any ) { async delete({ dispatch}, data: any ) {
try { try {
await remove(data); await remove(data);
dispatch('list', {}) dispatch('list', {})
......
...@@ -38,10 +38,7 @@ ...@@ -38,10 +38,7 @@
import {computed, defineComponent, PropType, ref, Ref} from "vue"; import {computed, defineComponent, PropType, ref, Ref} from "vue";
import {useI18n} from "vue-i18n"; import {useI18n} from "vue-i18n";
import {useStore} from "vuex"; import {useStore} from "vuex";
import {StateType as GlobalData} from "@/store/global";
import {ZentaoData} from "@/store/zentao";
import {ScriptData} from "@/views/script/store"; import {ScriptData} from "@/views/script/store";
import {WorkspaceData} from "@/store/workspace";
export default defineComponent({ export default defineComponent({
name: 'TreeContextMenu', name: 'TreeContextMenu',
......
...@@ -158,7 +158,7 @@ ...@@ -158,7 +158,7 @@
</div> </div>
</template> </template>
<script lang="ts"> <script setup lang="ts">
import { import {
computed, computed,
defineComponent, defineComponent,
...@@ -199,23 +199,12 @@ import {testToolMap} from "@/utils/testing"; ...@@ -199,23 +199,12 @@ import {testToolMap} from "@/utils/testing";
import {ExecStatus} from "@/store/exec"; import {ExecStatus} from "@/store/exec";
import debounce from "lodash.debounce"; import debounce from "lodash.debounce";
import throttle from "lodash.debounce"; import throttle from "lodash.debounce";
import {expandOneKey} from "@/utils/dom";
import TreeContextMenu from "./treeContextMenu.vue" import TreeContextMenu from "./treeContextMenu.vue"
import {ZentaoCasePrefix} from "@/utils/const"; import {ZentaoCasePrefix} from "@/utils/const";
import NameForm from "./nodeName.vue"; import NameForm from "./nodeName.vue";
import {isInArray} from "@/utils/array"; import {isInArray} from "@/utils/array";
export default defineComponent({
name: 'ScriptTreePage',
components: {
CloseOutlined, CheckOutlined,
TreeContextMenu, NameForm, SyncFromZentao,
},
props: {
},
setup(props) {
const { t } = useI18n(); const { t } = useI18n();
const isWin = isWindows() const isWin = isWindows()
...@@ -718,72 +707,14 @@ export default defineComponent({ ...@@ -718,72 +707,14 @@ export default defineComponent({
return false return false
} }
return { const expandOneKey = (treeMap: any, key: string, expandedKeys: string[]) => {
t, if (!expandedKeys.includes(key)) expandedKeys.push(key)
isWin,
currSite,
currProduct,
treeData,
currWorkspace,
testToolMap,
nameFormVisible,
treeDataEmpty,
filerItems,
filerType,
filerValue,
selectFilerType,
selectFilerValue,
replaceFields,
onLoadData,
expandNode,
selectNode,
checkNode,
isRunning,
execSelected,
execStop,
toExecUnit,
checkoutCases,
checkinCases,
isExpand,
showCheckbox,
displayBy,
expandAllOrNot,
showCheckboxOrNot,
onDisplayBy,
tree,
expandedKeys,
selectedKeys,
checkedKeys,
simpleImage: Empty.PRESENTED_IMAGE_SIMPLE,
fromTitle,
fromVisible,
onSave,
onCancel,
noScript,
rightVisible,
contextNode,
menuStyle,
treeDataMap,
editedData,
rightClickedNode,
updateName,
cancelUpdate,
onRightClick,
menuClick,
clearMenu,
createNode,
removeNode,
onDragEnter,
onDrop,
}
}
}) const parentId = treeMap[key].parentId
if (parentId) {
expandOneKey(treeMap, parentId, expandedKeys)
}
}
</script> </script>
<style lang="less"> <style lang="less">
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册