244 lines
6.3 KiB
TypeScript
244 lines
6.3 KiB
TypeScript
import { ptSaveAsDefault, ptResetAsDefault } from '@/api/pt/neConfig';
|
|
import {
|
|
getPtClassStudents,
|
|
stuPtNeConfigApply,
|
|
updatePtNeConfigApply,
|
|
} from '@/api/pt/neConfigApply';
|
|
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
|
|
import { Modal } from 'ant-design-vue/es';
|
|
import { message } from 'ant-design-vue/lib';
|
|
import { computed, reactive } from 'vue';
|
|
|
|
/**
|
|
* 实训教学函数
|
|
* @param param 父级传入 {t,fnActiveConfigNode}
|
|
* @returns
|
|
*/
|
|
export default function usePtOptions({ t, fnActiveConfigNode }: any) {
|
|
const ptConfigState = reactive({
|
|
saveLoading: false,
|
|
restLoading: false,
|
|
applyLoading: false,
|
|
});
|
|
/**(管理员)保存网元下所有配置为示例配置 */
|
|
function ptConfigSave(neType: string) {
|
|
Modal.confirm({
|
|
title: t('common.tipTitle'),
|
|
content: t('views.configManage.configParamForm.ptLoadTip'),
|
|
onOk() {
|
|
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;
|
|
fnActiveConfigNode('#');
|
|
});
|
|
},
|
|
});
|
|
}
|
|
|
|
/**重置网元下所有配置 */
|
|
function ptConfigReset(neType: string) {
|
|
Modal.confirm({
|
|
title: t('common.tipTitle'),
|
|
content: t('views.configManage.configParamForm.ptResetTip'),
|
|
onOk() {
|
|
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: '0' | '1' | '2' | '3',
|
|
student?: string
|
|
) {
|
|
let result: any;
|
|
if (status === '2' || status === '3') {
|
|
let from: {
|
|
neType: string;
|
|
status: string;
|
|
student?: string;
|
|
backInfo?: string;
|
|
} = {
|
|
neType,
|
|
status: '2',
|
|
};
|
|
if (student) {
|
|
if (status === '2') {
|
|
from = { neType, status, student };
|
|
}
|
|
if (status === '3') {
|
|
from = { neType, status, student, backInfo: '请重新检查配置' };
|
|
}
|
|
}
|
|
result = updatePtNeConfigApply(from);
|
|
}
|
|
if (status === '0' || status === '1') {
|
|
result = stuPtNeConfigApply({ neType, status });
|
|
}
|
|
if (!result) return;
|
|
|
|
Modal.confirm({
|
|
title: t('common.tipTitle'),
|
|
content: t('views.configManage.configParamForm.ptApplyStuTip', {
|
|
ne: neType,
|
|
}),
|
|
onOk() {
|
|
ptConfigState.applyLoading = true;
|
|
result
|
|
.then((res: any) => {
|
|
if (res.code === RESULT_CODE_SUCCESS) {
|
|
message.success({
|
|
content: t('common.operateOk'),
|
|
duration: 3,
|
|
});
|
|
// 教师修改学生时改变状态
|
|
if (student) {
|
|
const item = classState.studentOptionsDef.find(
|
|
s => s.value === classState.student
|
|
);
|
|
if (item) {
|
|
item.applyStatus = status;
|
|
}
|
|
}
|
|
} else {
|
|
message.error({
|
|
content: `${res.msg}`,
|
|
duration: 3,
|
|
});
|
|
}
|
|
})
|
|
.finally(() => {
|
|
ptConfigState.applyLoading = false;
|
|
});
|
|
},
|
|
});
|
|
}
|
|
|
|
const classState = reactive<{
|
|
/**学生账号 */
|
|
student: string | undefined;
|
|
/**学生可选择列表 */
|
|
studentOptions: {
|
|
value: string;
|
|
label: string;
|
|
applyId: string;
|
|
applyStatus: string;
|
|
}[];
|
|
studentOptionsDef: {
|
|
value: string;
|
|
label: string;
|
|
applyId: string;
|
|
applyStatus: string;
|
|
}[];
|
|
}>({
|
|
student: undefined,
|
|
studentOptions: [],
|
|
studentOptionsDef: [],
|
|
});
|
|
|
|
/**学生选择搜索 */
|
|
function studentChange(v: any) {
|
|
if (!v) {
|
|
Object.assign(classState.studentOptions, classState.studentOptionsDef);
|
|
}
|
|
fnActiveConfigNode('#');
|
|
}
|
|
|
|
let timeout: any;
|
|
|
|
/**学生选择搜索 */
|
|
function studentSearch(neType: string, val: string) {
|
|
if (timeout) {
|
|
clearTimeout(timeout);
|
|
timeout = null;
|
|
}
|
|
if (!val) {
|
|
Object.assign(classState.studentOptions, classState.studentOptionsDef);
|
|
return;
|
|
}
|
|
timeout = setTimeout(() => classStudents(neType, val), 500);
|
|
}
|
|
|
|
/**班级学生列表 */
|
|
function classStudents(neType: string, val?: string) {
|
|
getPtClassStudents({ neType, userName: val }).then(res => {
|
|
classState.studentOptions = [];
|
|
if (!Array.isArray(res.data) || res.data.length <= 0) {
|
|
return;
|
|
}
|
|
for (const v of res.data) {
|
|
classState.studentOptions.push({
|
|
value: v.userName,
|
|
label: v.userName,
|
|
applyId: v.applyId,
|
|
applyStatus: v.applyStatus,
|
|
});
|
|
// 设为最新状态
|
|
const item = classState.studentOptionsDef.find(
|
|
s => s.value === v.userName
|
|
);
|
|
if (item) {
|
|
item.applyStatus = v.applyStatus;
|
|
}
|
|
}
|
|
if (!val) {
|
|
Object.assign(classState.studentOptionsDef, classState.studentOptions);
|
|
}
|
|
});
|
|
}
|
|
|
|
// 学生状态
|
|
const studentStatus = computed(() => {
|
|
const item = classState.studentOptionsDef.find(
|
|
s => s.value === classState.student
|
|
);
|
|
if (item) return item.applyStatus;
|
|
return '';
|
|
});
|
|
|
|
return {
|
|
ptConfigState,
|
|
ptConfigSave,
|
|
ptConfigReset,
|
|
ptConfigApply,
|
|
classState,
|
|
classStudents,
|
|
studentStatus,
|
|
studentSearch,
|
|
studentChange,
|
|
};
|
|
}
|