feat: 系统模块初始化

This commit is contained in:
baiqi 2023-06-08 14:28:53 +08:00 committed by fit2-zhao
parent 32f1aa370d
commit 2ed0923b2d
11 changed files with 85 additions and 75 deletions

View File

@ -71,9 +71,11 @@ describe('MS-Table', () => {
test('init table with useTable', async () => { test('init table with useTable', async () => {
const { propsRes, propsEvent, loadList, setProps } = useTable(getTableList, { const { propsRes, propsEvent, loadList, setProps } = useTable(getTableList, {
columns, columns,
scroll: { y: 750, x: 2000 },
selectable: true,
}); });
const wrapper = mount(MsBaseTable, { const wrapper = mount(MsBaseTable as any, {
vOn: propsEvent, vOn: propsEvent,
vBind: propsRes, vBind: propsRes,
}); });
@ -81,7 +83,7 @@ describe('MS-Table', () => {
await nextTick(); await nextTick();
let content = wrapper.find('.arco-table-td-content').element.innerHTML; let content = wrapper.find('.arco-table-td-content').element.innerHTML;
expect(propsRes.value.data.length).toBe(2); expect(propsRes.value.data.length).toBe(20);
expect(content).toBe('e7bd7179-d63a-43a5-1a65-218473ee69ca'); expect(content).toBe('e7bd7179-d63a-43a5-1a65-218473ee69ca');
setProps({}); setProps({});

View File

@ -1,22 +0,0 @@
import MSR from '@/api/http/index';
import type { TableData } from '@arco-design/web-vue/es/table/interface';
export interface ContentDataRecord {
x: string;
y: number;
}
export function queryContentData() {
return MSR.get<ContentDataRecord[]>({ url: '/api/content-data' });
}
export interface PopularRecord {
key: number;
clickNumber: string;
title: string;
increases: number;
}
export function queryPopularList(params: { type: string }) {
return MSR.get<TableData[]>({ url: '/api/popular/list', params });
}

View File

@ -11,23 +11,27 @@
<template v-for="(item, key, i) in slots" :key="i" #[key]="{ record, rowIndex, column }"> <template v-for="(item, key, i) in slots" :key="i" #[key]="{ record, rowIndex, column }">
<slot :name="key" v-bind="{ rowIndex, record, column }"></slot> <slot :name="key" v-bind="{ rowIndex, record, column }"></slot>
</template> </template>
<template v-if="selectCurrent > 0" #footer> </a-table>
<div v-if="selectCurrent > 0" class="mt-[21px]">
<batch-action <batch-action
:select-row-count="selectCurrent" :select-row-count="selectCurrent"
@batch-export="emit('batchExport')" @batch-export="emit('batchExport')"
@batch-edit="emit('batchEdit')" @batch-edit="emit('batchEdit')"
@batch-move="emit('batchMove')" @batch-move="emit('batchMoveTo')"
@batch-copy="emit('batchCopyTo')"
@batch-related="emit('batchRelated')" @batch-related="emit('batchRelated')"
@batch-generate="emit('batchGenerate')"
@batch-add-public="emit('batchAddPublic')"
@batch-delete="emit('batchDelete')" @batch-delete="emit('batchDelete')"
@clear="selectionChange([], true)"
/> />
</template> </div>
</a-table>
</div> </div>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
// eslint-disable no-console // eslint-disable no-console
import { useSlots, useAttrs, computed, ref, onMounted, watchEffect } from 'vue'; import { useSlots, useAttrs, computed, ref, onMounted } from 'vue';
import selectAll from './select-all.vue'; import selectAll from './select-all.vue';
import { MsTabelProps, SelectAllEnum, MsPaginationI } from './type'; import { MsTabelProps, SelectAllEnum, MsPaginationI } from './type';
import BatchAction from './batchAction.vue'; import BatchAction from './batchAction.vue';
@ -43,8 +47,11 @@
(e: 'selectedChange', value: (string | number)[]): void; (e: 'selectedChange', value: (string | number)[]): void;
(e: 'batchExport'): void; (e: 'batchExport'): void;
(e: 'batchEdit'): void; (e: 'batchEdit'): void;
(e: 'batchMove'): void; (e: 'batchMoveTo'): void;
(e: 'batchCopyTo'): void;
(e: 'batchRelated'): void; (e: 'batchRelated'): void;
(e: 'batchGenerate'): void;
(e: 'batchAddPublic'): void;
(e: 'batchDelete'): void; (e: 'batchDelete'): void;
}>(); }>();
const isSelectAll = ref(false); const isSelectAll = ref(false);
@ -54,10 +61,11 @@
const slots = useSlots(); const slots = useSlots();
const attrs = useAttrs(); const attrs = useAttrs();
const { data, rowKey, pagination }: Partial<MsTabelProps> = attrs; const { rowKey, pagination }: Partial<MsTabelProps> = attrs;
// - // -
const selectTotal = computed(() => { const selectTotal = computed(() => {
const { data }: Partial<MsTabelProps> = attrs;
if (pagination) { if (pagination) {
const { pageSize } = pagination as MsPaginationI; const { pageSize } = pagination as MsPaginationI;
return pageSize; return pageSize;
@ -74,6 +82,7 @@
// change // change
const handleChange = (v: string) => { const handleChange = (v: string) => {
const { data }: Partial<MsTabelProps> = attrs;
isSelectAll.value = v === SelectAllEnum.ALL; isSelectAll.value = v === SelectAllEnum.ALL;
if (v === SelectAllEnum.NONE) { if (v === SelectAllEnum.NONE) {
selectionChange([], true); selectionChange([], true);
@ -91,7 +100,7 @@
if (data && data.length > 0) { if (data && data.length > 0) {
selectionChange( selectionChange(
data.map((item: any) => item[rowKey || 'id']), data.map((item: any) => item[rowKey || 'id']),
false true
); );
selectCurrent.value = total; selectCurrent.value = total;
} }

View File

@ -1,13 +1,23 @@
<template> <template>
<div class="ms-table__patch-action"> <div class="ms-table__patch-action">
<span>{{ t('msTable.batch.selected', { count: props.selectRowCount }) }}</span> <span class="title">{{ t('msTable.batch.selected', { count: props.selectRowCount }) }}</span>
<a-button @click="emit('batchExport')">{{ t('msTable.batch.export') }}</a-button> <a-button class="ml-4" type="outline" @click="emit('batchExport')">{{ t('msTable.batch.export') }}</a-button>
<a-button @click="emit('batchEdit')">{{ t('msTable.batch.edit') }}</a-button> <a-button class="ml-3" type="outline" @click="emit('batchEdit')">{{ t('msTable.batch.edit') }}</a-button>
<a-button @click="emit('batchExport')">{{ t('msTable.batch.moveTo') }}</a-button> <a-button class="ml-3" type="outline" @click="emit('batchMoveTo')">{{ t('msTable.batch.moveTo') }}</a-button>
<a-button @click="emit('batchExport')">{{ t('msTable.batch.copyTo') }}</a-button> <a-button class="ml-3" type="outline" @click="emit('batchCopyTo')">{{ t('msTable.batch.copyTo') }}</a-button>
<a-button @click="emit('batchExport')">{{ t('msTable.batch.related') }}</a-button> <div class="relative top-[2px] ml-3 inline-block">
<a-button @click="emit('batchExport')">{{ t('msTable.batch.delete') }}</a-button> <a-dropdown position="tr">
<a-button @click="emit('clear')">{{ t('msTable.batch.clear') }}</a-button> <a-button type="outline"><a-icon-more /></a-button>
<template #content>
<a-doption @click="emit('batchRelated')">{{ t('msTable.batch.related') }}</a-doption>
<a-doption @click="emit('batchGenerate')">{{ t('msTable.batch.generateDep') }}</a-doption>
<a-doption @click="emit('batchAddTo')">{{ t('msTable.batch.addPublic') }}</a-doption>
<a-divider margin="0" />
<a-doption class="delete" @click="emit('batchExport')">{{ t('msTable.batch.delete') }}</a-doption>
</template>
</a-dropdown>
</div>
<a-button class="ml-3" type="text" @click="emit('clear')">{{ t('msTable.batch.clear') }}</a-button>
</div> </div>
</template> </template>
@ -23,9 +33,23 @@
const emit = defineEmits<{ const emit = defineEmits<{
(e: 'batchExport'): void; (e: 'batchExport'): void;
(e: 'batchEdit'): void; (e: 'batchEdit'): void;
(e: 'batchMove'): void; (e: 'batchMoveTo'): void;
(e: 'batchCopyTo'): void;
(e: 'batchRelated'): void; (e: 'batchRelated'): void;
(e: 'batchGenerate'): void;
(e: 'batchAddTo'): void;
(e: 'batchDelete'): void; (e: 'batchDelete'): void;
(e: 'clear'): void; (e: 'clear'): void;
}>(); }>();
</script> </script>
<style lang="less" scoped>
.ms-table__patch-action {
.title {
color: var(--color-text-2);
}
}
.delete {
color: rgb(var(--danger-6));
}
</style>

View File

@ -11,8 +11,8 @@ export default {
moveTo: '移动到', moveTo: '移动到',
copyTo: '复制到', copyTo: '复制到',
related: '关联需求', related: '关联需求',
generate: '生成依赖关系', generateDep: '生成依赖关系',
add: '添加到公用用例库', addPublic: '添加到公用用例库',
clear: 'clear', clear: 'clear',
}, },
}, },

View File

@ -11,8 +11,8 @@ export default {
moveTo: '移动到', moveTo: '移动到',
copyTo: '复制到', copyTo: '复制到',
related: '关联需求', related: '关联需求',
generate: '生成依赖关系', generateDep: '生成依赖关系',
add: '添加到公用用例库', addPublic: '添加到公用用例库',
clear: '清空', clear: '清空',
}, },
}, },

View File

@ -7,6 +7,7 @@ import { ApiTestListI } from '@/models/api-test';
import { TableData } from '@arco-design/web-vue'; import { TableData } from '@arco-design/web-vue';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
import { QueryParams } from '@/models/common'; import { QueryParams } from '@/models/common';
import { useAppStore } from '@/store';
export interface Pagination { export interface Pagination {
current: number; current: number;
@ -16,6 +17,7 @@ export interface Pagination {
} }
type GetListFunc = (v: QueryParams) => Promise<ApiTestListI>; type GetListFunc = (v: QueryParams) => Promise<ApiTestListI>;
const appStore = useAppStore();
export default function useTbleProps(loadListFunc: GetListFunc, props?: Partial<MsTabelProps>) { export default function useTbleProps(loadListFunc: GetListFunc, props?: Partial<MsTabelProps>) {
// 行选择 // 行选择
const rowSelection = { const rowSelection = {
@ -34,9 +36,11 @@ export default function useTbleProps(loadListFunc: GetListFunc, props?: Partial<
columns: [] as MsTableColumn, columns: [] as MsTableColumn,
pagination: { pagination: {
current: 1, current: 1,
pageSize: 20, pageSize: appStore.pageSize,
total: 0, total: 0,
showPageSize: true, showPageSize: appStore.showPageSize,
showTotal: appStore.showTotal,
showJumper: appStore.showJumper,
} as Pagination, } as Pagination,
rowKey: 'id', rowKey: 'id',
selectedKeys: [], selectedKeys: [],
@ -48,6 +52,12 @@ export default function useTbleProps(loadListFunc: GetListFunc, props?: Partial<
// 属性组 // 属性组
const propsRes = ref(defaultProps); const propsRes = ref(defaultProps);
const oldPagination = ref<Pagination>({
current: 1,
pageSize: 20,
total: 0,
showPageSize: true,
});
// 排序 // 排序
const sortItem = ref<object>({}); const sortItem = ref<object>({});
@ -172,11 +182,11 @@ export default function useTbleProps(loadListFunc: GetListFunc, props?: Partial<
// 选择触发 // 选择触发
selectedChange: (arr: (string | number)[]) => { selectedChange: (arr: (string | number)[]) => {
if (arr.length === 0) { if (arr.length === 0) {
propsRes.value.pagination = defaultProps.pagination; propsRes.value.pagination = oldPagination.value;
} else { } else {
oldPagination.value = propsRes.value.pagination as Pagination;
propsRes.value.pagination = false; propsRes.value.pagination = false;
} }
propsRes.value.selectedKeys = arr; propsRes.value.selectedKeys = arr;
}, },
change: (_data: MsTableData) => { change: (_data: MsTableData) => {

View File

@ -4,7 +4,6 @@
<a-space> <a-space>
<svg-icon :width="'43px'" :height="'33px'" :name="'logo'" /> <svg-icon :width="'43px'" :height="'33px'" :name="'logo'" />
<a-divider direction="vertical" /> <a-divider direction="vertical" />
<ProjcetSelection />
<icon-menu-fold <icon-menu-fold
v-if="!topMenu && appStore.device === 'mobile'" v-if="!topMenu && appStore.device === 'mobile'"
style="font-size: 22px; cursor: pointer" style="font-size: 22px; cursor: pointer"
@ -144,7 +143,6 @@
import useUser from '@/hooks/useUser'; import useUser from '@/hooks/useUser';
import Menu from '@/components/pure/menu/index.vue'; import Menu from '@/components/pure/menu/index.vue';
import MessageBox from '../message-box/index.vue'; import MessageBox from '../message-box/index.vue';
import ProjcetSelection from '@/components/pure/project-selection/index.vue';
const appStore = useAppStore(); const appStore = useAppStore();
const userStore = useUserStore(); const userStore = useUserStore();

View File

@ -12,5 +12,9 @@
"globalSettings": false, "globalSettings": false,
"device": "desktop", "device": "desktop",
"tabBar": false, "tabBar": false,
"serverMenu": [] "serverMenu": [],
"pageSize": 10,
"showPageSize": true,
"showTotal": true,
"showJumper": true
} }

View File

@ -1,15 +1,12 @@
<template> <template>
<div class="h-[100vh] bg-white px-[20px] py-[16px] pb-0"> <div class="h-[100vh] bg-white px-[20px] py-[16px] pb-0">
<div class="mb-10">表格</div>
<a-input v-model="queryParmas.name"></a-input>
<a-button @click="handleClick">搜索</a-button>
<ms-base-table v-bind="propsRes" v-on="propsEvent"> </ms-base-table> <ms-base-table v-bind="propsRes" v-on="propsEvent"> </ms-base-table>
</div> </div>
<a-divider /> <a-divider />
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { onMounted, watchEffect, ref } from 'vue'; import { onMounted } from 'vue';
import MsBaseTable from '@/components/pure/ms-table/base-table.vue'; import MsBaseTable from '@/components/pure/ms-table/base-table.vue';
import { MsTableColumn } from '@/components/pure/ms-table/type'; import { MsTableColumn } from '@/components/pure/ms-table/type';
import useTable from '@/components/pure/ms-table/useTable'; import useTable from '@/components/pure/ms-table/useTable';
@ -95,11 +92,7 @@
}, },
]; ];
const queryParmas = ref({ const { propsRes, propsEvent, loadList } = useTable(getTableList, {
name: '',
});
const { propsRes, propsEvent, loadList, setLoadListParams } = useTable(getTableList, {
columns, columns,
scroll: { y: 750, x: 2000 }, scroll: { y: 750, x: 2000 },
selectable: true, selectable: true,
@ -109,15 +102,7 @@
await loadList(); await loadList();
}; };
const handleClick = async () => {
setLoadListParams(queryParmas.value);
await fetchData();
};
onMounted(() => { onMounted(() => {
fetchData(); fetchData();
}); });
watchEffect(() => {
setLoadListParams(queryParmas.value);
});
</script> </script>