perf: 参数配置页面函数重构

This commit is contained in:
TsMask
2024-07-11 14:49:26 +08:00
parent ecaa0ce077
commit 65c8c6f809
7 changed files with 1077 additions and 835 deletions

View File

@@ -0,0 +1,144 @@
import { getPtClassStudents } from '@/api/pt/neClass';
import { ptSaveAsDefault, ptResetAsDefault } from '@/api/pt/neConfig';
import { stuPtNeConfigApply } from '@/api/pt/neConfigApply';
import { RESULT_CODE_SUCCESS } from '@/constants/result-constants';
import { message } from 'ant-design-vue/lib';
import { onMounted, reactive } from 'vue';
/**
* 实训教学函数
* @param param 父级传入 {t}
* @returns
*/
export default function usePtOptions({t}:any) {
/**保存网元下所有配置为示例配置 */
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,
});
}
});
}
/**重置网元下所有配置 */
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,
});
}
});
}
/**配置下方应用申请和撤回 */
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,
});
}
});
}
const classState = reactive<{
/**学生账号 */
student: string | undefined;
/**学生可选择列表 */
studentOptions: { value: string; label: string }[];
studentOptionsDef: { value: string; label: 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);
});
}
let timeout: any;
/**学生选择搜索 */
function studentSearch(val: string) {
if (timeout) {
clearTimeout(timeout);
timeout = null;
}
if (!val) {
Object.assign(classState.studentOptions, classState.studentOptionsDef);
return;
}
function fake() {
getPtClassStudents({
userName: val,
pageNum: 1,
pageSize: 10,
}).then(res => {
classState.studentOptions = [];
for (const s of res.rows) {
classState.studentOptions.push({
value: s.userName,
label: s.userName,
});
}
});
}
timeout = setTimeout(fake, 500);
}
/**学生选择改变 */
function studentChange(e: any) {
console.log(e);
}
onMounted(() => {
initStudentList();
});
return {
ptConfigSave,
ptConfigReset,
ptConfigApply,
classState,
studentChange,
studentSearch,
};
}