index.vue 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <template>
  2. <div class="h-full bg-white">
  3. <fs-crud v-if="!pageType" ref="crudRef" v-bind="crudBinding" />
  4. <div v-if="pageType" class="wh-full flex-col-center">
  5. <n-card style="width: 1200px" title="编辑班级学员" :bordered="false" size="huge" role="dialog" aria-modal="true">
  6. <n-transfer ref="transfer" v-model:value="classStuList" :options="studentsAll" virtual-scroll />
  7. <n-button-group style="margin-top: 1rem; float: right">
  8. <n-button type="primary" @click="submitGroupStudent">提交</n-button>
  9. <n-button type="primary" @click="pageType = !pageType">取消</n-button>
  10. </n-button-group>
  11. </n-card>
  12. </div>
  13. </div>
  14. </template>
  15. <script setup lang="ts">
  16. import { onMounted, ref } from 'vue';
  17. import { useRouter } from 'vue-router';
  18. import type { Option, OptionValue } from 'naive-ui/es/transfer/src/interface';
  19. import { useFs } from '@fast-crud/fast-crud';
  20. import createCrudOptions from './crud';
  21. import { queryClassStudentById, getAll, submitGroupStudentForm } from './api';
  22. const pageType = ref<boolean>(false);
  23. const classStuList = ref<number[] | undefined>([]);
  24. const studentsAll = ref<Option[]>();
  25. const groupId = ref<number>(0);
  26. const router = useRouter();
  27. async function submitGroupStudent() {
  28. await submitGroupStudentForm(groupId.value, classStuList.value);
  29. window.$message?.success('操作成功!');
  30. pageType.value = !pageType.value;
  31. }
  32. const context: any = {
  33. goToSchedule: (classId: number) => {
  34. router.push({
  35. path: '/lesson/schedule',
  36. query: {
  37. classId
  38. }
  39. });
  40. },
  41. openModel: async (classId: number) => {
  42. groupId.value = classId;
  43. const classStudent = await queryClassStudentById(classId);
  44. const studentAll = await getAll();
  45. classStuList.value = classStudent.data?.map(r => r.studentId);
  46. studentsAll.value = studentAll.data?.map(r => {
  47. return {
  48. label: r.studentName ? r.studentName + r.phone : '',
  49. value: (r.id ?? 0) as OptionValue,
  50. disabled: false
  51. };
  52. });
  53. pageType.value = true;
  54. }
  55. };
  56. const { crudRef, crudBinding, crudExpose } = useFs({ createCrudOptions, context });
  57. onMounted(() => {
  58. crudExpose.doRefresh();
  59. });
  60. </script>
  61. <style scoped></style>