|
@@ -5,59 +5,60 @@
|
|
<n-space class="pb-14px" justify="space-between">
|
|
<n-space class="pb-14px" justify="space-between">
|
|
<!-- 加入查询组件 -->
|
|
<!-- 加入查询组件 -->
|
|
<n-space>
|
|
<n-space>
|
|
- <n-button type="primary" @click="addTableData">
|
|
|
|
|
|
+ <n-button type="primary" @click="addTableData">
|
|
<icon-ic-round-plus class="mr-4px text-20px" />
|
|
<icon-ic-round-plus class="mr-4px text-20px" />
|
|
新增
|
|
新增
|
|
</n-button>
|
|
</n-button>
|
|
- <n-button type="error" @click="deleteTableData" @update:checked-row-keys="handleCheck">
|
|
|
|
|
|
+ <n-button type="error" @click="deleteTableData" >
|
|
<icon-ic-round-delete class="mr-4px text-20px" />
|
|
<icon-ic-round-delete class="mr-4px text-20px" />
|
|
删除
|
|
删除
|
|
</n-button>
|
|
</n-button>
|
|
<!-- 添加查询按钮 -->
|
|
<!-- 添加查询按钮 -->
|
|
- <n-button type="primary" @click="handleOpenSearch">
|
|
|
|
|
|
+ <n-button type="primary" @click="">
|
|
<icon-simple-line-icons:magnifier class="mr-4px text-16px" />
|
|
<icon-simple-line-icons:magnifier class="mr-4px text-16px" />
|
|
查询
|
|
查询
|
|
</n-button>
|
|
</n-button>
|
|
- <n-input-group>
|
|
|
|
- <n-input :style="{ width: '100%', }" placeholder="请输入id查询..." @clear="searchClear" @change="handleChange"
|
|
|
|
- @keyup.enter="handleSearch" v-model="searchId" clearable />
|
|
|
|
- <n-button type="primary" ghost @click="handleSearch">
|
|
|
|
- 搜索
|
|
|
|
- </n-button>
|
|
|
|
- </n-input-group>
|
|
|
|
<div class="mr-5px"></div>
|
|
<div class="mr-5px"></div>
|
|
<n-input-group>
|
|
<n-input-group>
|
|
- <span class="w-40px mr-5px line-height-33.99px">页码</span>
|
|
|
|
- <n-input-number :style="{ width: '48%', marginRight: '2%' }" placeholder="请输入页码..." clearable v-model="pagination.page"
|
|
|
|
- @update:value="searchPage" @clear="searchConClear"/>
|
|
|
|
- <span class="w-40px mr-5px line-height-33.99px">条数</span>
|
|
|
|
- <n-input-number :style="{ width: '48%' }" placeholder="请输入数据条数..." clearable v-model="pagination.pageSize"
|
|
|
|
- @update:value="searchSize" @clear="searchConClear" />
|
|
|
|
- <n-button type="primary" ghost @click="searchCondition">
|
|
|
|
|
|
+ <n-input-number :style="{ width: '98%', marginRight: '2%' }" v-model:value="conditionParams.id"
|
|
|
|
+ placeholder="请输入ID..." clearable />
|
|
|
|
+ <n-input :style="{ width: '98%', marginRight: '2%' }" :value="conditionParams.name"
|
|
|
|
+ @input="event => conditionParams.name = event" placeholder="请输入学科名称..." clearable />
|
|
|
|
+ <n-input :style="{ width: '98%', marginRight: '2%' }" :value="conditionParams.description"
|
|
|
|
+ @input="event => conditionParams.description = event" placeholder="请输入学科描述..." clearable />
|
|
|
|
+ <n-input-number :style="{ width: '120%', marginRight: '2%' }" v-model:value="conditionParams.createUid"
|
|
|
|
+ placeholder="请输入用户ID..." clearable />
|
|
|
|
+ <n-input :style="{ width: '98%', marginRight: '2%' }" v-model:value="conditionParams.createTime"
|
|
|
|
+ @input="event => conditionParams.createTime = event" placeholder="请输入创建时间..." clearable />
|
|
|
|
+ <n-input :style="{ width: '98%', marginRight: '2%' }" v-model:value="conditionParams.modifyTime"
|
|
|
|
+ @input="event => conditionParams.modifyTime = event" placeholder="请输入修改时间..." clearable/>
|
|
|
|
+ <n-select :options="userStatusOptions" :style="{ width: '98%', marginRight: '2%' }"
|
|
|
|
+ v-model:value="conditionParams.disabled" @input="event => conditionParams.disabled = event"
|
|
|
|
+ placeholder="输入查询状态..." clearable />
|
|
|
|
+ <n-button type="primary" ghost @click="searchCondition()">
|
|
搜索
|
|
搜索
|
|
</n-button>
|
|
</n-button>
|
|
</n-input-group>
|
|
</n-input-group>
|
|
- <!-- <column-search v-if="showSearch" v-model:columns="columns" /> -->
|
|
|
|
</n-space>
|
|
</n-space>
|
|
<n-space align="center" :size="18">
|
|
<n-space align="center" :size="18">
|
|
- <n-button size="small" type="primary" @click="getTableData">
|
|
|
|
|
|
+ <n-button size="small" type="primary" @click="searchCondition">
|
|
<icon-mdi-refresh class="mr-4px text-16px" :class="{ 'animate-spin': loading }" />
|
|
<icon-mdi-refresh class="mr-4px text-16px" :class="{ 'animate-spin': loading }" />
|
|
刷新表格
|
|
刷新表格
|
|
</n-button>
|
|
</n-button>
|
|
</n-space>
|
|
</n-space>
|
|
</n-space>
|
|
</n-space>
|
|
- <n-data-table v-if="searchForm.length > 0" :columns="createColumns" :data="searchForm" :loading="loading"
|
|
|
|
- :pagination="pagination" :row-key="rowKey" @update:checked-row-keys="handleCheck" />
|
|
|
|
- <n-data-table v-if="searchForm.length <= 0" :columns="createColumns" :data="tableData" :loading="loading"
|
|
|
|
- :pagination="pagination" :row-key="rowKey" @update:checked-row-keys="handleCheck" />
|
|
|
|
- <table-action-add v-model:visible="visible" :type="modalType" :edit-data="editData" />
|
|
|
|
|
|
+ <n-data-table :columns="columns" :data="tableData" :loading="loading" :row-key="rowKey" @update:checked-row-keys="handleCheck"
|
|
|
|
+ :pagination="pagination" />
|
|
|
|
+ <table-action-add v-model:visible="visible" :type="modalType" @searchCondition="searchCondition"
|
|
|
|
+ :pagination="pagination" :edit-data="(editData as SelectByCondition_1Params)" />
|
|
</n-card>
|
|
</n-card>
|
|
</n-scrollbar>
|
|
</n-scrollbar>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
</template>
|
|
|
|
|
|
<script setup lang="tsx" >
|
|
<script setup lang="tsx" >
|
|
-import { ref } from 'vue'
|
|
|
|
|
|
+import { userStatusOptions } from '@/constants';
|
|
|
|
+import { ref, Ref, reactive ,watch} from 'vue'
|
|
import { NButton, NSpace, NTag, NPopconfirm } from 'naive-ui';
|
|
import { NButton, NSpace, NTag, NPopconfirm } from 'naive-ui';
|
|
import type { DataTableColumns, PaginationProps } from 'naive-ui';
|
|
import type { DataTableColumns, PaginationProps } from 'naive-ui';
|
|
import { useBoolean, useLoading } from '@/hooks';
|
|
import { useBoolean, useLoading } from '@/hooks';
|
|
@@ -65,40 +66,39 @@ import type { DataTableRowKey } from 'naive-ui'
|
|
import TableActionAdd from './components/table-action-add.vue'
|
|
import TableActionAdd from './components/table-action-add.vue'
|
|
import type { ModalType } from './components/table-action-add.vue';
|
|
import type { ModalType } from './components/table-action-add.vue';
|
|
import { userStatusLabels } from '@/constants';
|
|
import { userStatusLabels } from '@/constants';
|
|
-import { selectAll_1, deleteById, selectById_1 } from '~/src/service/api/sort';
|
|
|
|
-import { selectByCondition_1 } from '~/src/service/api/sort';
|
|
|
|
|
|
+import { deleteById,selectAll_1 } from '~/src/service/api/sort';
|
|
|
|
+import { selectByCondition_1} from '~/src/service/api/sort';
|
|
import type { SelectByCondition_1Params } from '~/src/service/api/sort';
|
|
import type { SelectByCondition_1Params } from '~/src/service/api/sort';
|
|
|
|
+
|
|
type RowData = {
|
|
type RowData = {
|
|
- key: number
|
|
|
|
|
|
+ key: string
|
|
id: number
|
|
id: number
|
|
name: string
|
|
name: string
|
|
description: string
|
|
description: string
|
|
createTime: string
|
|
createTime: string
|
|
modifyTime: string
|
|
modifyTime: string
|
|
- createUid: number
|
|
|
|
|
|
+ createUid: string
|
|
disabled: string
|
|
disabled: string
|
|
}
|
|
}
|
|
|
|
+const conditionParams: SelectByCondition_1Params = reactive({
|
|
|
|
+ id: null,
|
|
|
|
+ name: null,
|
|
|
|
+ description: null,
|
|
|
|
+ createUid: null,
|
|
|
|
+ createTime: null,
|
|
|
|
+ modifyTime: null,
|
|
|
|
+ disabled: null
|
|
|
|
+});
|
|
|
|
+
|
|
const { loading, startLoading, endLoading } = useLoading(false);
|
|
const { loading, startLoading, endLoading } = useLoading(false);
|
|
const { bool: visible, setTrue: openModal } = useBoolean();
|
|
const { bool: visible, setTrue: openModal } = useBoolean();
|
|
-const tableData = ref<any[]>([]);
|
|
|
|
-const searchInput = ref([]) as any;
|
|
|
|
-const searchForm = ref([]) as any;
|
|
|
|
-const searchId = ref<number>(0); // 定义为数字类型,默认值为0
|
|
|
|
-// const searchData = ref<any[]>([]);
|
|
|
|
-const searchConData = ref<any[]>([]);
|
|
|
|
-const searchpagedata = ref<number>(0)
|
|
|
|
-const searchpagesize = ref<number>(0)
|
|
|
|
|
|
+const tableData = ref<SelectByCondition_1Params[]>([]);
|
|
|
|
|
|
-function searchPage(v: number | null) {
|
|
|
|
- searchpagedata.value = Number(v)
|
|
|
|
-}
|
|
|
|
-function searchSize(v: number | null) {
|
|
|
|
- searchpagesize.value = Number(v)
|
|
|
|
-}
|
|
|
|
const pagination: PaginationProps = ref({
|
|
const pagination: PaginationProps = ref({
|
|
page: 1,
|
|
page: 1,
|
|
pageSize: 10,
|
|
pageSize: 10,
|
|
showSizePicker: true,
|
|
showSizePicker: true,
|
|
|
|
+ itemCount:1,
|
|
pageSizes: [10, 20, 50],
|
|
pageSizes: [10, 20, 50],
|
|
onChange: (page: number) => {
|
|
onChange: (page: number) => {
|
|
// 处理页码变化
|
|
// 处理页码变化
|
|
@@ -111,100 +111,50 @@ const pagination: PaginationProps = ref({
|
|
}
|
|
}
|
|
}).value;
|
|
}).value;
|
|
|
|
|
|
-function searchCondition() {
|
|
|
|
- const pageNum = searchpagedata.value as number;
|
|
|
|
- const pageSize = searchpagesize.value as number;
|
|
|
|
- const params: SelectByCondition_1Params = {};
|
|
|
|
- if(pageNum && pageSize){
|
|
|
|
- selectByCondition_1(pageNum, pageSize, params).then(res => {
|
|
|
|
- searchConData.value = res.data as [];
|
|
|
|
- pagination.page =searchpagedata.value
|
|
|
|
- pagination.pageSize=searchpagesize.value
|
|
|
|
- window.$message?.success('查询成功');
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
- else if(!pageNum && !pageSize) {
|
|
|
|
- searchpagedata.value =0;
|
|
|
|
- searchpagesize.value=0;
|
|
|
|
- window.$message?.warning('请输入页码和条数进行查询');
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-export async function getTableData() {
|
|
|
|
|
|
+async function searchCondition() {
|
|
startLoading();
|
|
startLoading();
|
|
- selectAll_1().then(res => {
|
|
|
|
- setTimeout(() => {
|
|
|
|
|
|
+ // 检查 conditionParams 对象中的值是否存在不为空的条件 some 检查数组中是否有至少一个元素满足指定的条件 检查每个值是否不为 null 且不为空字符串
|
|
|
|
+ const hasConditions = Object.values(conditionParams).some(value => value !== null && value !== '');
|
|
|
|
+ if(hasConditions){
|
|
|
|
+ const res = await selectByCondition_1(pagination.page as number, pagination.pageSize as number, conditionParams);
|
|
tableData.value = res.data as [];
|
|
tableData.value = res.data as [];
|
|
|
|
+ pagination.itemCount = Number(res.total);
|
|
|
|
+ // 如果满足条件的数据超出当前页的数据范围,则重新查询所有满足条件的数据
|
|
|
|
+ if (pagination.itemCount > (pagination.page - 1) * pagination.pageSize + tableData.value.length) {
|
|
|
|
+ const allRes = await selectByCondition_1(1, pagination.itemCount, conditionParams);
|
|
|
|
+ tableData.value = allRes.data as [];
|
|
|
|
+ pagination.itemCount = Number(allRes.total);
|
|
|
|
+ // 调整分页参数
|
|
|
|
+ pagination.page = Math.ceil(allRes.total / pagination.pageSize);
|
|
|
|
+ } else {
|
|
|
|
+ const allRes = await selectByCondition_1(1, pagination.itemCount, conditionParams);
|
|
|
|
+ tableData.value = allRes.data as [];
|
|
|
|
+ }
|
|
endLoading();
|
|
endLoading();
|
|
- }, 1000);
|
|
|
|
- });
|
|
|
|
- checkedRowKeysRef.value=[]
|
|
|
|
|
|
+ }
|
|
|
|
+ else{
|
|
|
|
+ const res = await selectAll_1();
|
|
|
|
+ tableData.value = res.data as [];
|
|
|
|
+ pagination.itemCount = tableData.value.length;
|
|
|
|
+ endLoading();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
function init() {
|
|
function init() {
|
|
- getTableData();
|
|
|
|
|
|
+ searchCondition();
|
|
}
|
|
}
|
|
|
|
+// 在条件改变时立即触发搜索
|
|
|
|
+watch(conditionParams, () => {
|
|
|
|
+ if (Object.values(conditionParams).every(value => value === '' || value === null)) {
|
|
|
|
+ // 如果所有条件参数都为空,则查询所有数据
|
|
|
|
+ searchCondition();
|
|
|
|
+ }
|
|
|
|
+ searchCondition();
|
|
|
|
+});
|
|
// 初始化
|
|
// 初始化
|
|
init();
|
|
init();
|
|
|
|
|
|
-function searchConClear(){
|
|
|
|
- searchConData.value.length = 0
|
|
|
|
- searchpagedata.value =0;
|
|
|
|
- searchpagesize.value=0;
|
|
|
|
- getTableData();
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-const showSearch = ref(false)
|
|
|
|
-function handleOpenSearch() {
|
|
|
|
-// 点击查询时显示搜索框
|
|
|
|
- showSearch.value = !showSearch.value;
|
|
|
|
-}
|
|
|
|
-// 输入数据
|
|
|
|
-function handleChange(v: string) {
|
|
|
|
- searchId.value = Number(v)
|
|
|
|
-}
|
|
|
|
-// 根据id查询数据
|
|
|
|
-async function handleSearch() {
|
|
|
|
- if (searchId.value) {
|
|
|
|
- await selectById_1(searchId.value)
|
|
|
|
- .then(res => {
|
|
|
|
- // 更新数据
|
|
|
|
- searchInput.value = res.data as [];
|
|
|
|
- const filteredItems = tableData.value.filter(item => item.id === searchInput.value.id)
|
|
|
|
- searchForm.value = filteredItems;
|
|
|
|
- window.$message?.success('查询成功');
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
- else {
|
|
|
|
- searchForm.value.length = 0
|
|
|
|
- window.$message?.warning('请输入有效的ID进行查询');
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-function searchClear() {
|
|
|
|
- searchForm.value.length = 0
|
|
|
|
- getTableData();
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
const checkedRowKeysRef = ref<DataTableRowKey[]>([])
|
|
const checkedRowKeysRef = ref<DataTableRowKey[]>([])
|
|
- const s = ref<DataTableRowKey[]>([])
|
|
|
|
-// 根据id进行删除
|
|
|
|
-async function deleteTableData() {
|
|
|
|
- const ids = checkedRowKeysRef.value.filter((item)=>!s.value?.includes(item));
|
|
|
|
- s.value=checkedRowKeysRef.value
|
|
|
|
- if (ids.length !== 0) {
|
|
|
|
- console.log(ids);
|
|
|
|
- for (const id of ids) {
|
|
|
|
- // 调用删除接口
|
|
|
|
- await deleteById(id as number)
|
|
|
|
- .then((res) => {
|
|
|
|
- window.$message?.success('删除成功!');
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
- getTableData(); // 删除完成后刷新表格数据
|
|
|
|
- } else {
|
|
|
|
- // 没有选择任何行时的操作
|
|
|
|
- window.$message?.error('未选择要删除的行');
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
|
|
+const s = ref<DataTableRowKey[]>([])
|
|
|
|
|
|
const modalType = ref<ModalType>('add' || 'edit');
|
|
const modalType = ref<ModalType>('add' || 'edit');
|
|
|
|
|
|
@@ -217,31 +167,47 @@ function addTableData() {
|
|
setModalType('add');
|
|
setModalType('add');
|
|
}
|
|
}
|
|
|
|
|
|
-const editData = ref<UserManagement.User | null>(null);
|
|
|
|
-function setEditData(data: UserManagement.User | null) {
|
|
|
|
|
|
+const editData = ref<SelectByCondition_1Params | null>(null);
|
|
|
|
+function setEditData(data: SelectByCondition_1Params | null) {
|
|
editData.value = data;
|
|
editData.value = data;
|
|
}
|
|
}
|
|
-console.log(tableData.value);
|
|
|
|
-function handleEditTable(rowId: number | null) {
|
|
|
|
|
|
+function handleEditTable(rowId: number) {
|
|
const findItem = tableData.value.find(item => item.id === rowId);
|
|
const findItem = tableData.value.find(item => item.id === rowId);
|
|
setModalType('edit');
|
|
setModalType('edit');
|
|
openModal();
|
|
openModal();
|
|
if (findItem) {
|
|
if (findItem) {
|
|
setEditData(findItem);
|
|
setEditData(findItem);
|
|
}
|
|
}
|
|
- getTableData(); // 编辑完成后刷新表格数据
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-function handleDeleteTable(rowId: number | null) {
|
|
|
|
- const findItem = tableData.value.find(item => item.id === rowId);
|
|
|
|
- if (findItem) {
|
|
|
|
- deleteById(findItem.id).then((r) => {
|
|
|
|
- getTableData(); // 编辑完成后刷新表格数据
|
|
|
|
- })
|
|
|
|
|
|
+function handleDeleteTable(rowId: number) {
|
|
|
|
+ const rowIdNumber = Number(rowId);
|
|
|
|
+ deleteById(rowIdNumber).then(() => {
|
|
|
|
+ searchCondition(); // 删除完成后刷新表格数据
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+const rowKey = (row: RowData) => row.id
|
|
|
|
+function handleCheck(rowKeys: DataTableRowKey[]) {
|
|
|
|
+ checkedRowKeysRef.value = rowKeys
|
|
|
|
+}
|
|
|
|
+async function deleteTableData() {
|
|
|
|
+ const ids = checkedRowKeysRef.value.filter((item) => !s.value?.includes(item));
|
|
|
|
+ s.value = checkedRowKeysRef.value
|
|
|
|
+ if (ids.length !== 0) {
|
|
|
|
+ for (const id of ids) {
|
|
|
|
+ await deleteById(id as number).then((res)=>{
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ window.$message?.success('删除成功!');
|
|
|
|
+ searchCondition(); // 删除完成后刷新表格数据
|
|
|
|
+ } else {
|
|
|
|
+ // 没有选择任何行时的操作
|
|
|
|
+ window.$message?.error('未选择要删除的行');
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-const createColumns = (): DataTableColumns<UserManagement.User> => [
|
|
|
|
|
|
+const columns: Ref<DataTableColumns<UserManagement.User>> = ref([
|
|
{
|
|
{
|
|
type: 'selection',
|
|
type: 'selection',
|
|
align: 'center',
|
|
align: 'center',
|
|
@@ -312,23 +278,6 @@ const createColumns = (): DataTableColumns<UserManagement.User> => [
|
|
</NSpace>
|
|
</NSpace>
|
|
);
|
|
);
|
|
}
|
|
}
|
|
-
|
|
|
|
},
|
|
},
|
|
-]
|
|
|
|
-
|
|
|
|
-const rowKey= (row: RowData) => row.id
|
|
|
|
-function handleCheck(rowKeys: DataTableRowKey[]) {
|
|
|
|
- checkedRowKeysRef.value = rowKeys
|
|
|
|
-}
|
|
|
|
- // handleKeyDown(event:KeyboardEvent) {
|
|
|
|
- // if (event.key === 'Backspace' && searchId.value===0) {
|
|
|
|
- // // 处理删除键按下且输入框为空的情况
|
|
|
|
- // // 执行刷新操作,例如调用 API 获取原来的列表数据
|
|
|
|
- // getTableData()
|
|
|
|
- // }
|
|
|
|
- // console.log(1);
|
|
|
|
- // },
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+])
|
|
</script>
|
|
</script>
|