targeted-setting.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <template>
  2. <ie-page bg-color="#F6F8FA" :fix-height="true">
  3. <ie-navbar title="定向刷题" />
  4. <view class="p-32 bg-white flex items-center justify-between">
  5. <view class="">
  6. <text class="text-32 text-fore-title font-bold">添加定向院校</text>
  7. <text class="ml-10 text-32 text-fore-title font-bold">({{ directedSchoolList.length }}/3)</text>
  8. </view>
  9. </view>
  10. <view class="px-48 pt-52 pb-20 flex items-center justify-between">
  11. <view class="text-28 text-fore-title font-bold">当前学习目标</view>
  12. </view>
  13. <template v-if="directedSchoolList.length > 0">
  14. <view class="px-30">
  15. <directed-school-item :data="currentDirectedSchool" :active="true" @choose="handleChoose"
  16. @delete="handleDelete" />
  17. </view>
  18. <view v-if="directedSchoolList.length > 1" class="px-48 pt-40 pb-30">
  19. <view class="text-28 text-fore-title font-bold">其他备选目标</view>
  20. <view class="mt-4 text-24 text-fore-light">切换定向学习院校后将影响为你推荐的学习内容和题目!</view>
  21. </view>
  22. <view class="px-30">
  23. <directed-school-item v-for="(item, index) in otherDirectedSchoolList" :key="index" :data="item"
  24. :active="false" @choose="handleChoose" @delete="handleDelete" />
  25. </view>
  26. </template>
  27. <view v-if="sortList.length === 0" class="flex-1 flex flex-col items-center justify-center gap-y-50">
  28. <ie-image src="/pagesStudy/static/image/icon-empty.png" custom-class="w-364 h-252 mx-auto" mode="aspectFill" />
  29. <text class="text-30 text-fore-light text-center">目前暂无定向院校~</text>
  30. </view>
  31. <view class="m-30 bg-white p-30 rounded-10">
  32. <view class="">
  33. <uv-icon name="info-circle" size="16" color="var(--danger)" :inline="true" />
  34. <text class="text-28 text-fore-tip inline ml-8">2026考纲知识点已更新,可添加3个目标院校与专业,添加后不可修改,请谨慎选择!</text>
  35. </view>
  36. </view>
  37. <ie-safe-toolbar v-if="directedSchoolList.length < 3" :height="84" :shadow="false">
  38. <view class="px-46 pt-24">
  39. <ie-button type="primary" @click="handleAdd">添加</ie-button>
  40. </view>
  41. </ie-safe-toolbar>
  42. </ie-page>
  43. </template>
  44. <script lang="ts" setup>
  45. import DirectedSchoolItem from './components/directed-school-item.vue';
  46. import { useTransferPage } from '@/hooks/useTransferPage';
  47. import { DirectedSchool } from '@/types/study';
  48. import { useUserStore } from '@/store/userStore';
  49. import {routes} from "@/common/routes";
  50. const userStore = useUserStore();
  51. const { transferTo } = useTransferPage();
  52. const loading = ref(true);
  53. const sortList = ref<DirectedSchool[]>([]);
  54. const { directedSchoolList } = toRefs(userStore);
  55. const currentDirectedSchool = computed(() => directedSchoolList.value[0]);
  56. const otherDirectedSchoolList = computed(() => directedSchoolList.value.slice(1));
  57. const handleAdd = () => {
  58. transferTo(routes.universityPicker, {
  59. data: {useRedirect: true}
  60. });
  61. }
  62. const handleChoose = (data: DirectedSchool) => {
  63. const otherList = directedSchoolList.value.filter(item => item.code !== data.code);
  64. const list = [data, ...otherList];
  65. save(list);
  66. }
  67. const handleDelete = (data: DirectedSchool) => {
  68. uni.$ie.showModal({
  69. title: '提示',
  70. content: '如删除该定向记录,关联的数据有变化,是否继续?',
  71. showCancel: true,
  72. confirmText: '确定',
  73. cancelText: '取消'
  74. }).then((confirm: boolean) => {
  75. if (confirm) {
  76. const list = [...directedSchoolList.value];
  77. list.splice(list.indexOf(data), 1);
  78. save(list);
  79. }
  80. });
  81. }
  82. const save = async (list: DirectedSchool[]) => {
  83. uni.$ie.showLoading();
  84. await userStore.saveDirectedSchoolList(list);
  85. await refresh();
  86. uni.$ie.hideLoading();
  87. uni.$ie.showSuccess('设置成功');
  88. loading.value = false;
  89. }
  90. const refresh = async () => {
  91. sortList.value = [...directedSchoolList.value];
  92. }
  93. onShow(() => {
  94. nextTick(() => {
  95. refresh();
  96. });
  97. });
  98. </script>
  99. <style lang="scss" scoped></style>