feat: 参数配置教师应用和切换学生功能
This commit is contained in:
@@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user