|
@@ -0,0 +1,377 @@
|
|
|
+<template>
|
|
|
+ <div class="h-full overflow-hidden">
|
|
|
+ <n-card title="课程管理" :bordered="false" class="rounded-16px shadow-sm">
|
|
|
+ <n-space class="pb-12px" justify="space-between">
|
|
|
+ <n-space>
|
|
|
+ <n-button type="primary" @click="handleAddTable">
|
|
|
+ <icon-ic-round-plus class="mr-4px text-20px" />
|
|
|
+ 新增
|
|
|
+ </n-button>
|
|
|
+ <n-button type="error" @click="deleteSubjectsList">
|
|
|
+ <icon-ic-round-delete class="mr-4px text-20px" />
|
|
|
+ 删除
|
|
|
+ </n-button>
|
|
|
+ <n-input-group>
|
|
|
+
|
|
|
+ <n-input :style="{ width: '50%' }" @keyup="serchForm" @change="handleChange" placeholder="输入id查询..." />
|
|
|
+ <n-button type="primary" ghost @click="serchForm()">
|
|
|
+ 搜索
|
|
|
+ </n-button>
|
|
|
+ </n-input-group>
|
|
|
+ <n-input-group>
|
|
|
+ <n-input-number :style="{ width: '33%' }" @input="handleInput1" />
|
|
|
+ <n-input-number :style="{ width: '33%' }" @input="handleInput2" />
|
|
|
+ <n-button type="primary" @click="serchCondition()">
|
|
|
+ 搜索
|
|
|
+ </n-button>
|
|
|
+ </n-input-group>
|
|
|
+ </n-space>
|
|
|
+ </n-space>
|
|
|
+ <n-data-table v-if="serchFormEr.length > 0 && inputValue !== 0" :columns="columns" :data="serchFormEr"
|
|
|
+ :loading="loading" :pagination="pagination" :row-key="rowKey" @update:checked-row-keys="handleCheck" />
|
|
|
+ <n-data-table v-if="serchFormEr.length <= 0 || inputValue === 0" :columns="columns" :data="pageDate"
|
|
|
+ :loading="loading" :pagination="pagination" :row-key="rowKey" @update:checked-row-keys="handleCheck" />
|
|
|
+ <table-action-modal v-model:visible="visible" :type="modalType" :edit-data="editData" />
|
|
|
+ </n-card>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script lang="tsx">
|
|
|
+import { reactive, ref, defineComponent } from 'vue';
|
|
|
+import type { Ref } from 'vue';
|
|
|
+import { useBoolean, useLoading } from '@/hooks';
|
|
|
+import TableActionModal from './component/table-action-modal.vue';
|
|
|
+import type { ModalType } from './component/table-action-modal.vue';
|
|
|
+import { selectAll, deleteSubjects, selectById, selectByCondition } from '~/src/service/api/crouse';
|
|
|
+import type { SelectByConditionParams } from '~/src/service/api/crouse'
|
|
|
+import { PaginationProps, DataTableColumns, DataTableRowKey, NButton, NPopconfirm, NSpace } from 'naive-ui';
|
|
|
+import { fetchUserList } from '@/service';
|
|
|
+import { number } from 'echarts';
|
|
|
+
|
|
|
+// import { selectByCondition } from '../../../service/api/crouse.ts';
|
|
|
+// import AddView from '~/src/views/management/crouse/component/AddView.vue';
|
|
|
+// const useSelect: SelectByConditionParams = {};
|
|
|
+// const { loading } = useLoading(false);
|
|
|
+const conditionParams: SelectByConditionParams = {};
|
|
|
+const { loading, startLoading, endLoading } = useLoading(false);
|
|
|
+const { bool: visible, setTrue: openModal } = useBoolean();
|
|
|
+// input的值
|
|
|
+const inputValue = ref(0);
|
|
|
+// 接收查询返回的数组
|
|
|
+const serchInput = ref([]) as any;
|
|
|
+const serchFormEr = ref([]);
|
|
|
+// 根据条件查询
|
|
|
+const inputPageNum1 = ref(0);
|
|
|
+const inputPageNum2 = ref(0);
|
|
|
+console.log(inputValue.value)
|
|
|
+const pagination: PaginationProps = reactive({
|
|
|
+ page: 1 || number,
|
|
|
+ pageSize: 10 || number,
|
|
|
+ showSizePicker: true,
|
|
|
+ pageSizes: [10, 15, 20, 25, 30] || number,
|
|
|
+ // onChange: (page: number) => {
|
|
|
+ // pagination.page = page;
|
|
|
+ // },
|
|
|
+ onUpdatePageSize: (pageSize: number) => {
|
|
|
+ pagination.pageSize = pageSize;
|
|
|
+ },
|
|
|
+ onUpdatePage: (page: number) =>{
|
|
|
+ pagination.page = page;
|
|
|
+ }
|
|
|
+});
|
|
|
+
|
|
|
+const pageDate = ref([]);
|
|
|
+type RowData = {
|
|
|
+ key: number;
|
|
|
+ id: number;
|
|
|
+ select: string;
|
|
|
+ name: string;
|
|
|
+ description: string;
|
|
|
+ categoryId: string;
|
|
|
+ createTime: string;
|
|
|
+ modifyTime: string;
|
|
|
+ createUid: number;
|
|
|
+ disabled: string;
|
|
|
+};
|
|
|
+const columns: Ref<DataTableColumns<UserManagement1.User>> = ref([
|
|
|
+ {
|
|
|
+ type: 'selection',
|
|
|
+ align: 'center'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ key: 'id',
|
|
|
+ title: 'id',
|
|
|
+ align: 'center'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ key: 'name',
|
|
|
+ title: '学科名称',
|
|
|
+ align: 'center'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ key: 'description',
|
|
|
+ title: '学科描述',
|
|
|
+ align: 'center'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ key: 'categoryId',
|
|
|
+ title: '学科分类',
|
|
|
+ align: 'center'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ key: 'createTime',
|
|
|
+ title: '创建时间',
|
|
|
+ align: 'center'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ key: 'modifyTime',
|
|
|
+ title: '修改时间',
|
|
|
+ align: 'center'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ key: 'createUid',
|
|
|
+ title: '创建用户ID',
|
|
|
+ align: 'center'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ key: 'disabled',
|
|
|
+ title: '状态',
|
|
|
+ align: 'center'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ key: 'actions',
|
|
|
+ title: '操作',
|
|
|
+ align: 'center',
|
|
|
+ render: row => {
|
|
|
+ function handleDeleteTable(value: never[]): any {
|
|
|
+ throw new Error('Function not implemented.');
|
|
|
+ }
|
|
|
+
|
|
|
+ return (
|
|
|
+ <NSpace justify={'center'}>
|
|
|
+ <NButton size={'small'} onClick={() => handleEditTable(row.id)}>
|
|
|
+ 编辑
|
|
|
+ </NButton>
|
|
|
+ <NPopconfirm onPositiveClick={() => handleDeleteTable(pageDate.value)}>
|
|
|
+ {{
|
|
|
+ default: () => '确认删除',
|
|
|
+ trigger: () => <NButton size={'small'}>删除</NButton>
|
|
|
+ }}
|
|
|
+ </NPopconfirm>
|
|
|
+ </NSpace>
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+]) as Ref<DataTableColumns<UserManagement1.User>>;
|
|
|
+// selectByCondition(pagination.page, pagination.pageSize, useSelect).then(r => {
|
|
|
+// console.log(r);
|
|
|
+// });
|
|
|
+// eslint-disable-next-line import/no-duplicates
|
|
|
+// import { selectAll } from '../../../service/api/crouse.ts';
|
|
|
+// selectAll().then(r => {
|
|
|
+// console.log(r);
|
|
|
+// });
|
|
|
+// const useAdd: AddSubjectParams = {
|
|
|
+// id: 2,
|
|
|
+// name: '物理',
|
|
|
+// description: '很难',
|
|
|
+// categoryId: '理学',
|
|
|
+// createTime: '',
|
|
|
+// modifyTime: '',
|
|
|
+// createUid: 2,
|
|
|
+// disabled: '1'
|
|
|
+// } as any;
|
|
|
+// 重新加载
|
|
|
+// function handleRefresh() {
|
|
|
+// const isCached = routeStore.cacheRoutes.includes(String(route.name));
|
|
|
+// if (isCached) {
|
|
|
+// routeStore.removeCacheRoute(route.name as AuthRoute.AllRouteKey);
|
|
|
+// }
|
|
|
+// startLoading();
|
|
|
+// app.reloadPage();
|
|
|
+// setTimeout(() => {
|
|
|
+// if (isCached) {
|
|
|
+// routeStore.addCacheRoute(route.name as AuthRoute.AllRouteKey);
|
|
|
+// }
|
|
|
+// endLoading();
|
|
|
+// }, 1000);
|
|
|
+// }
|
|
|
+function handleAddTable() {
|
|
|
+ openModal();
|
|
|
+ setModalType('add');
|
|
|
+ init();
|
|
|
+}
|
|
|
+// 编辑
|
|
|
+const editData = ref<UserManagement1.User | null>(null);
|
|
|
+function setEditData(data: UserManagement1.User | null) {
|
|
|
+ editData.value = data;
|
|
|
+ console.log(editData.value)
|
|
|
+}
|
|
|
+function handleEditTable(rowId: number) {
|
|
|
+ console.log(rowId)
|
|
|
+ // selectAll().then(r => {
|
|
|
+ // pageDate.value = r.data as [];
|
|
|
+ // });
|
|
|
+ const findItem = pageDate.value.find(item => item.id === rowId);
|
|
|
+ console.log(findItem, pageDate.value)
|
|
|
+ if (findItem) {
|
|
|
+ setEditData(findItem);
|
|
|
+ }
|
|
|
+ setModalType('edit');
|
|
|
+ openModal();
|
|
|
+}
|
|
|
+
|
|
|
+const modalType = ref<ModalType>('add' || 'edit');
|
|
|
+function setModalType(type: ModalType) {
|
|
|
+ modalType.value = type;
|
|
|
+ console.log(modalType.value)
|
|
|
+}
|
|
|
+
|
|
|
+selectAll().then(r => {
|
|
|
+ console.log(r)
|
|
|
+ pageDate.value = r.data as [];
|
|
|
+});
|
|
|
+// addSubject(useAdd).then(() => {
|
|
|
+// selectAll();
|
|
|
+// });
|
|
|
+// const tableData = ref<RowData[]>([]);
|
|
|
+// function setTableData(data: RowData[]) {
|
|
|
+// tableData.value = data;
|
|
|
+// }
|
|
|
+// 删除
|
|
|
+const s = ref([]) as any;
|
|
|
+const d = ref([]) as any
|
|
|
+function deleteSubjectsList() {
|
|
|
+ if (s.value.length !== 0) {
|
|
|
+ for (let i = 0; i < s.value.length; i++) {
|
|
|
+ deleteSubjects(s.value[i]).then((r) => {
|
|
|
+ // handleRefresh();
|
|
|
+ console.log(r)
|
|
|
+ console.log(s.value.length)
|
|
|
+ d.value.id = s.value[i].id
|
|
|
+ // for(let j = 0;j<d.value.length;j++){
|
|
|
+ // if(d.value[j].id === s.value[j].id){
|
|
|
+ // s.value.length = 0
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ console.log(s.value[i].id)
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ s.value = [];
|
|
|
+ console.log(s.value.length)
|
|
|
+ if (s.value.length == 0) {
|
|
|
+ console.log(s.value.length)
|
|
|
+ window.$message?.success('删除成功!');
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ init();
|
|
|
+}
|
|
|
+// function handleDeleteTable(rowId) {
|
|
|
+// window.$message?.info(`点击了删除,rowId为${rowId}`);
|
|
|
+// }
|
|
|
+
|
|
|
+async function getTableData() {
|
|
|
+ startLoading();
|
|
|
+ const { data } = await fetchUserList();
|
|
|
+ if (data) {
|
|
|
+ setTimeout(() => {
|
|
|
+ // setTableData(data);
|
|
|
+ selectAll().then((r) => [
|
|
|
+ pageDate.value = r.data as []
|
|
|
+ ]);
|
|
|
+ endLoading();
|
|
|
+ }, 1000);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// deleteSubjects(r: RowData)
|
|
|
+export default defineComponent({
|
|
|
+ components: { TableActionModal },
|
|
|
+ setup() {
|
|
|
+ // console.log(pageDate.value)
|
|
|
+ const checkedRowKeysRef = ref<DataTableRowKey[]>([]);
|
|
|
+ return {
|
|
|
+ columns,
|
|
|
+ inputPageNum1,
|
|
|
+ inputPageNum2,
|
|
|
+ loading,
|
|
|
+ inputValue,
|
|
|
+ NButton,
|
|
|
+ NPopconfirm,
|
|
|
+ NSpace,
|
|
|
+ conditionParams,
|
|
|
+ serchInput,
|
|
|
+ pageDate,
|
|
|
+ checkedRowKeys: checkedRowKeysRef,
|
|
|
+ pagination,
|
|
|
+ deleteSubjects,
|
|
|
+ deleteSubjectsList,
|
|
|
+ handleEditTable,
|
|
|
+ // handleRefresh,
|
|
|
+ visible,
|
|
|
+ serchFormEr,
|
|
|
+ editData,
|
|
|
+ modalType,
|
|
|
+ handleAddTable,
|
|
|
+ openModal,
|
|
|
+ setModalType,
|
|
|
+ useBoolean, useLoading,
|
|
|
+ rowKey: (row: RowData) => row.id,
|
|
|
+ handleCheck(rowKeys: DataTableRowKey[]) {
|
|
|
+ checkedRowKeysRef.value = rowKeys;
|
|
|
+ // rowKeys.splice(0);
|
|
|
+ // console.log(rowKeys)
|
|
|
+ s.value = checkedRowKeysRef.value
|
|
|
+ // rowKeys = []
|
|
|
+ // d.length = 0
|
|
|
+ // rowKeys.length = 0
|
|
|
+ },
|
|
|
+ // 根据条件查询
|
|
|
+ handleInput1(v: number) {
|
|
|
+ inputPageNum1.value = v;
|
|
|
+ // pagination.page = inputPageNum1.value.data;
|
|
|
+
|
|
|
+ },
|
|
|
+ handleInput2(v: number) {
|
|
|
+ inputPageNum2.value = v;
|
|
|
+ // pagination.pageSize = inputPageNum2.value.data;
|
|
|
+ },
|
|
|
+ // 根据id查询
|
|
|
+ handleChange(v: string) {
|
|
|
+ inputValue.value = Number(v)
|
|
|
+ },
|
|
|
+ async serchForm() {
|
|
|
+ await selectById(inputValue.value).then(r => {
|
|
|
+ console.log(inputValue.value)
|
|
|
+ serchInput.value = r.data as [];
|
|
|
+ const filteredItems = Object.values(pageDate.value.filter(item => item.id === serchInput.value.id))
|
|
|
+ // console.log(filteredItems,Array.isArray(filteredItems))
|
|
|
+ serchFormEr.value = filteredItems;
|
|
|
+ console.log(serchFormEr.value)
|
|
|
+ })
|
|
|
+ },
|
|
|
+ async serchCondition() {
|
|
|
+ await selectByCondition(inputPageNum1.value.data, inputPageNum2.value.data, conditionParams).then(r => {
|
|
|
+ console.log(r)
|
|
|
+ pageDate.value = r.data as [];
|
|
|
+ pagination.page = inputPageNum1.value.data;
|
|
|
+ pagination.pageSize = inputPageNum2.value.data;
|
|
|
+ // console.log(inputPageNum1.value.data, pagination.page)
|
|
|
+ })
|
|
|
+ // console.log(inputPageNum1.value.data, inputPageNum2.value.data)
|
|
|
+ }
|
|
|
+ };
|
|
|
+ }
|
|
|
+});
|
|
|
+export function init() {
|
|
|
+ getTableData();
|
|
|
+}
|
|
|
+
|
|
|
+// 初始化
|
|
|
+init();
|
|
|
+</script>
|
|
|
+
|
|
|
+<style scoped></style>
|