From c87458bc23ea8c4f5e531b22c9ab91dc25159dd2 Mon Sep 17 00:00:00 2001 From: TsMask <340112800@qq.com> Date: Wed, 17 Jul 2024 17:03:32 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=8F=82=E6=95=B0=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=95=99=E5=B8=88=E5=BA=94=E7=94=A8=E5=92=8C=E5=88=87=E6=8D=A2?= =?UTF-8?q?=E5=AD=A6=E7=94=9F=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/pt/neClass.ts | 14 -- .../hooks/usePtOptions.ts | 191 +++++++++++------- .../configParamTreeTable/index.vue | 49 ++++- 3 files changed, 158 insertions(+), 96 deletions(-) delete mode 100644 src/api/pt/neClass.ts diff --git a/src/api/pt/neClass.ts b/src/api/pt/neClass.ts deleted file mode 100644 index 448edee5..00000000 --- a/src/api/pt/neClass.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { request } from '@/plugins/http-fetch'; - -/** - * 班级学生列表 (仅教师操作) - * @param params 数据 {neType,paramName} - * @returns object - */ -export function getPtClassStudents(params: Record) { - return request({ - url: `/pt/class/students`, - params, - method: 'get', - }); -} diff --git a/src/views/configManage/configParamTreeTable/hooks/usePtOptions.ts b/src/views/configManage/configParamTreeTable/hooks/usePtOptions.ts index 0a91d1f9..fd8479bb 100644 --- a/src/views/configManage/configParamTreeTable/hooks/usePtOptions.ts +++ b/src/views/configManage/configParamTreeTable/hooks/usePtOptions.ts @@ -1,97 +1,130 @@ -import { getPtClassStudents } from '@/api/pt/neClass'; import { ptSaveAsDefault, ptResetAsDefault } from '@/api/pt/neConfig'; -import { stuPtNeConfigApply } from '@/api/pt/neConfigApply'; +import { + getPtClassStudents, + stuPtNeConfigApply, + updatePtNeConfigApply, +} from '@/api/pt/neConfigApply'; import { RESULT_CODE_SUCCESS } from '@/constants/result-constants'; import { hasRoles } from '@/plugins/auth-user'; import { message } from 'ant-design-vue/lib'; -import { onMounted, reactive } from 'vue'; +import { computed, onMounted, reactive, ref } from 'vue'; /** * 实训教学函数 - * @param param 父级传入 {t} + * @param param 父级传入 {t,fnActiveConfigNode} * @returns */ -export default function usePtOptions({ t }: any) { +export default function usePtOptions({ t, fnActiveConfigNode }: any) { + const ptConfigState = reactive({ + saveLoading: false, + restLoading: false, + applyLoading: false, + }); /**保存网元下所有配置为示例配置 */ function ptConfigSave(neType: string) { - ptSaveAsDefault(neType, '001').then(res => { - if (res.code === RESULT_CODE_SUCCESS) { - message.success({ - content: t('common.operateOk'), - duration: 3, - }); - } else { - message.error({ - content: `${res.msg}`, - duration: 3, - }); - } - }); + ptConfigState.saveLoading = true; + ptSaveAsDefault(neType, '001') + .then(res => { + if (res.code === RESULT_CODE_SUCCESS) { + message.success({ + content: t('common.operateOk'), + duration: 3, + }); + } else { + message.error({ + content: `${res.msg}`, + duration: 3, + }); + } + }) + .finally(() => { + ptConfigState.saveLoading = false; + }); } /**重置网元下所有配置 */ function ptConfigReset(neType: string) { - ptResetAsDefault(neType).then(res => { - if (res.code === RESULT_CODE_SUCCESS) { - message.success({ - content: t('common.operateOk'), - duration: 3, - }); - } else { - message.error({ - content: `${res.msg}`, - duration: 3, - }); - } - }); + ptConfigState.restLoading = true; + ptResetAsDefault(neType) + .then(res => { + if (res.code === RESULT_CODE_SUCCESS) { + message.success({ + content: t('common.operateOk'), + duration: 3, + }); + } else { + message.error({ + content: `${res.msg}`, + duration: 3, + }); + } + }) + .finally(() => { + ptConfigState.restLoading = false; + fnActiveConfigNode('#'); + }); } - /**配置下方应用申请和撤回 */ - function ptConfigApply(neType: string, status: string) { - stuPtNeConfigApply({ neType, status }).then(res => { - if (res.code === RESULT_CODE_SUCCESS) { - message.success({ - content: t('common.operateOk'), - duration: 3, - }); - } else { - message.error({ - content: `${res.msg}`, - duration: 3, - }); - } - }); + /**配置下方应用(学生)申请撤回和(管理/教师)应用退回 */ + function ptConfigApply(neType: string, status: '0' | '1' |'2'| '3' ) { + let result: any; + if (status === '2') { + result = updatePtNeConfigApply({ neType, status: '2' }); + } + if (status === '0') { + result = stuPtNeConfigApply({ neType, status: '0' }); + } + if (!result) return; + ptConfigState.applyLoading = true; + result + .then((res: any) => { + if (res.code === RESULT_CODE_SUCCESS) { + message.success({ + content: t('common.operateOk'), + duration: 3, + }); + } else { + message.error({ + content: `${res.msg}`, + duration: 3, + }); + } + }) + .finally(() => { + ptConfigState.applyLoading = false; + }); } const classState = reactive<{ /**学生账号 */ student: string | undefined; /**学生可选择列表 */ - studentOptions: { value: string; label: string }[]; - studentOptionsDef: { value: string; label: string }[]; + studentOptions: { value: string; label: string; status: string }[]; + studentOptionsDef: { value: string; label: string; status: string }[]; }>({ student: undefined, studentOptions: [], studentOptionsDef: [], }); - /**初始学生列表 */ - function initStudentList() { - getPtClassStudents({ - pageNum: 1, - pageSize: 60, - }).then(res => { - if (!Array.isArray(res.rows) || res.rows.length <= 0) { - return; - } - classState.studentOptions = []; - for (const s of res.rows) { - classState.studentOptions.push({ - value: s.userName, - label: s.userName, - }); - } - Object.assign(classState.studentOptionsDef, classState.studentOptions); + // 仅教师加载 + if (hasRoles(['teacher'])) { + onMounted(() => { + // 初始学生列表 + getPtClassStudents().then(res => { + if (!Array.isArray(res.data) || res.data.length <= 0) { + return; + } + classState.studentOptions = []; + for (const s of res.data) { + classState.studentOptions.push({ + value: s.userName, + label: s.userName, + status: s.applyStatus, + }); + } + Object.assign(classState.studentOptionsDef, classState.studentOptions); + }); }); } @@ -108,35 +141,37 @@ export default function usePtOptions({ t }: any) { return; } function fake() { - getPtClassStudents({ - userName: val, - pageNum: 1, - pageSize: 10, - }).then(res => { + getPtClassStudents({ userName: val }).then(res => { classState.studentOptions = []; - for (const s of res.rows) { + for (const s of res.data) { classState.studentOptions.push({ value: s.userName, label: s.userName, + status: s.applyStatus, }); } }); } timeout = setTimeout(fake, 500); } + - // 仅教师加载 - if (hasRoles(['teacher'])) { - onMounted(() => { - initStudentList(); - }); - } + // 学生状态 + const studentStatus = computed(() => { + const item = classState.studentOptions.find( + s => s.value === classState.student + ); + if (item) return item.status; + return ''; + }); return { + ptConfigState, ptConfigSave, ptConfigReset, ptConfigApply, classState, - studentSearch, + studentStatus, + studentSearch, }; } diff --git a/src/views/configManage/configParamTreeTable/index.vue b/src/views/configManage/configParamTreeTable/index.vue index effe74d1..e76c521d 100644 --- a/src/views/configManage/configParamTreeTable/index.vue +++ b/src/views/configManage/configParamTreeTable/index.vue @@ -2,6 +2,7 @@ import { reactive, ref, onMounted, toRaw, watch } from 'vue'; import { PageContainer } from 'antdv-pro-layout'; import { message } from 'ant-design-vue/lib'; +import { DataNode } from 'ant-design-vue/lib/tree'; import useI18n from '@/hooks/useI18n'; import TableColumnsDnd from '@/components/TableColumnsDnd/index.vue'; import { RESULT_CODE_SUCCESS } from '@/constants/result-constants'; @@ -11,7 +12,6 @@ import usePtOptions from './hooks/usePtOptions'; import useConfigList from './hooks/useConfigList'; import useConfigArray from './hooks/useConfigArray'; import useConfigArrayChild from './hooks/useConfigArrayChild'; -import { DataNode } from 'ant-design-vue/lib/tree'; import { getAllNeConfig } from '@/api/ne/neConfig'; import { getPtNeConfigData } from '@/api/pt/neConfig'; import { hasRoles } from '@/plugins/auth-user'; @@ -329,12 +329,14 @@ watch( ); const { + ptConfigState, ptConfigSave, ptConfigReset, ptConfigApply, classState, + studentStatus, studentSearch, -} = usePtOptions({ t, treeState }); +} = usePtOptions({ t, fnActiveConfigNode }); const { tablePagination, listState, listEdit, listEditClose, listEditOk } = useConfigList({ t, treeState, ruleVerification }); @@ -437,38 +439,77 @@ onMounted(() => { :options="classState.studentOptions" @search="studentSearch" @change="fnActiveConfigNode('#')" - > + > + + + + (管理员/教师) 应用到网元 (管理员)载入网元配置为系统示例 (教师)重置为系统示例 (学生)重置为教师示例 (学生)申请应用到 {{ treeState.neType }}