index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. <template>
  2. <!-- 弹窗开关 -->
  3. <el-form
  4. class="switch-form"
  5. :inline="true"
  6. label-width="200px"
  7. >
  8. <el-form-item label="是否开启导师弹窗" v-if="userInfo?.userType === '4' ">
  9. <el-switch v-model="popData.isSupervisor" :active-value="1" :inactive-value="0" @change="(val) => handleSwitchChange(popData.id, 'isSupervisor', val)" />
  10. </el-form-item>
  11. <el-form-item label="是否开启学生弹窗" v-if="userInfo?.userType === '4'">
  12. <el-switch v-model="popData.isStudent" :active-value="1" :inactive-value="0" @change="(val) => handleSwitchChange(popData.id, 'isStudent', val)" />
  13. </el-form-item>
  14. </el-form>
  15. <ContentWrap>
  16. <!-- 搜索工作栏 -->
  17. <el-form
  18. class="-mb-15px"
  19. :model="queryParams"
  20. ref="queryFormRef"
  21. :inline="true"
  22. label-width="100px"
  23. >
  24. <el-form-item label="项目名称" prop="projectName">
  25. <el-input
  26. v-model="queryParams.projectName"
  27. placeholder="请输入项目名称"
  28. clearable
  29. @keyup.enter="handleQuery"
  30. class="!w-240px"
  31. />
  32. </el-form-item>
  33. <el-form-item label="学生开始时间" prop="studentStartTime">
  34. <el-date-picker
  35. v-model="queryParams.studentStartTime"
  36. value-format="YYYY-MM-DD HH:mm:ss"
  37. type="datetime"
  38. placeholder="选择学生开始时间"
  39. class="!w-220px"
  40. />
  41. </el-form-item>
  42. <el-form-item label="导师截止时间" prop="supervisorConfirmDeadline">
  43. <el-date-picker
  44. v-model="queryParams.supervisorConfirmDeadline"
  45. value-format="YYYY-MM-DD HH:mm:ss"
  46. type="datetime"
  47. placeholder="选择导师截止时间"
  48. clearable
  49. class="!w-220px"
  50. />
  51. </el-form-item>
  52. <el-form-item label="参与学生年级" prop="studentGrade">
  53. <el-select
  54. v-model="queryParams.studentGrade"
  55. placeholder="请选择参与学生年级"
  56. clearable
  57. @change="handleQuery"
  58. class="!w-240px"
  59. >
  60. <el-option
  61. v-for="year in gradeOptions"
  62. :key="year"
  63. :label="year"
  64. :value="year"
  65. />
  66. </el-select>
  67. </el-form-item>
  68. <el-form-item label="创建时间" prop="createTime">
  69. <el-date-picker
  70. v-model="queryParams.createTime"
  71. value-format="YYYY-MM-DD HH:mm:ss"
  72. type="daterange"
  73. start-placeholder="开始日期"
  74. end-placeholder="结束日期"
  75. :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
  76. class="!w-220px"
  77. />
  78. </el-form-item>
  79. <el-form-item>
  80. <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
  81. <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
  82. <el-button
  83. type="primary"
  84. plain
  85. @click="openForm('create')"
  86. v-hasPermi="['system:student-selection-project:create']"
  87. >
  88. <Icon icon="ep:plus" class="mr-5px" /> 新增
  89. </el-button>
  90. <el-button
  91. type="success"
  92. plain
  93. @click="handleExport"
  94. :loading="exportLoading"
  95. v-hasPermi="['system:student-selection-project:export']"
  96. >
  97. <Icon icon="ep:download" class="mr-5px" /> 导出
  98. </el-button>
  99. </el-form-item>
  100. </el-form>
  101. </ContentWrap>
  102. <!-- 列表 -->
  103. <ContentWrap>
  104. <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
  105. <el-table-column type="index" width="50" />
  106. <el-table-column label="项目名称" align="center" prop="projectName" />
  107. <el-table-column
  108. label="学生开始时间"
  109. align="center"
  110. prop="studentStartTime"
  111. :formatter="dateFormatter"
  112. width="180px"
  113. />
  114. <el-table-column
  115. label="导师截止时间"
  116. align="center"
  117. prop="supervisorConfirmDeadline"
  118. :formatter="dateFormatter"
  119. width="180px"
  120. />
  121. <el-table-column label="参与学生年级" align="center" prop="studentGrade" />
  122. <el-table-column
  123. label="创建时间"
  124. align="center"
  125. prop="createTime"
  126. :formatter="dateFormatter"
  127. width="180px"
  128. />
  129. <el-table-column label="操作" align="center" min-width="120px">
  130. <template #default="scope">
  131. <!-- 校内导师查看项目详情,互选记录-->
  132. <el-button type="text" v-if="userInfo?.userType === '3'" @click="openStudentSelectSupervisorRecord(scope.row.id)" v-hasPermi="['system:student-select-supervisor-record:query']">
  133. <Icon icon="ep:bell" />
  134. 详情
  135. </el-button>
  136. <!-- 学院或者学生查看详情,导师名额设置页面-->
  137. <el-button type="text" v-if="userInfo?.userType === '4' || userInfo?.userType === '1'" @click="openSupervisorSelectionSetting(scope.row.id)" v-hasPermi="['system:supervisor-selection-setting:query']" >
  138. <Icon icon="ep:bell" />
  139. 详情
  140. </el-button>
  141. <el-button
  142. link
  143. type="primary"
  144. @click="openForm('update', scope.row.id)"
  145. v-hasPermi="['system:student-selection-project:update']"
  146. v-if="userInfo?.userType === '4'"
  147. >
  148. 编辑
  149. </el-button>
  150. <el-button
  151. link
  152. type="danger"
  153. @click="handleDelete(scope.row.id)"
  154. v-hasPermi="['system:student-selection-project:delete']"
  155. >
  156. 删除
  157. </el-button>
  158. </template>
  159. </el-table-column>
  160. </el-table>
  161. <!-- 分页 -->
  162. <Pagination
  163. :total="total"
  164. v-model:page="queryParams.pageNo"
  165. v-model:limit="queryParams.pageSize"
  166. @pagination="getList"
  167. />
  168. </ContentWrap>
  169. <!-- 表单弹窗:添加/修改 -->
  170. <studentSelectionProjectForm ref="formRef" @success="getList" />
  171. </template>
  172. <script setup lang="ts">
  173. import { dateFormatter } from '@/utils/formatTime'
  174. import download from '@/utils/download'
  175. import { studentSelectionProjectApi, studentSelectionProjectVO } from '@/api/system/studentSelectionProject'
  176. import studentSelectionProjectForm from './studentSelectionProjectForm.vue'
  177. import { ref } from 'vue'
  178. import { getUserProfile, ProfileVO } from '@/api/system/user/profile'
  179. import { getPopData, updateIsPop,PopDo } from '@/api/system/user/pop'
  180. /** 师生互选项目 列表 */
  181. defineOptions({ name: 'StudentSelectionProject' })
  182. const message = useMessage() // 消息弹窗
  183. const { t } = useI18n() // 国际化
  184. const isPopDataLoaded = ref(false); // 标志,用于防止初始时更新
  185. const popData = ref<PopDo>({
  186. id: 1,
  187. isStudent: undefined,
  188. isSupervisor: undefined
  189. });
  190. const loading = ref(true) // 列表的加载中
  191. const list = ref<studentSelectionProjectVO[]>([]) // 列表的数据
  192. const total = ref(0) // 列表的总页数
  193. const queryParams = reactive({
  194. pageNo: 1,
  195. pageSize: 10,
  196. projectName: undefined,
  197. studentStartTime: [],
  198. supervisorConfirmDeadline: undefined,
  199. studentGrade: undefined, // 年级属性绑定到 queryParams
  200. createTime: [],
  201. })
  202. const queryFormRef = ref() // 搜索的表单
  203. const exportLoading = ref(false) // 导出的加载中
  204. /** 查询列表 */
  205. const getList = async () => {
  206. loading.value = true
  207. try {
  208. const data = await studentSelectionProjectApi.getStudentSelectionProjectPage(queryParams)
  209. list.value = data.list
  210. total.value = data.total
  211. } finally {
  212. loading.value = false
  213. }
  214. }
  215. //获取登录人员信息
  216. const userInfo = ref({} as ProfileVO)
  217. const getUserInfo = async () => {
  218. const users = await getUserProfile()
  219. userInfo.value = users
  220. // userType.value = Number(users.userType)
  221. }
  222. /** 搜索按钮操作 */
  223. const handleQuery = () => {
  224. queryParams.pageNo = 1
  225. getList()
  226. }
  227. /** 重置按钮操作 */
  228. const resetQuery = () => {
  229. queryFormRef.value.resetFields()
  230. handleQuery()
  231. }
  232. /** 添加/修改操作 */
  233. const formRef = ref()
  234. const openForm = (type: string, id?: number) => {
  235. formRef.value.open(type, id)
  236. }
  237. /** 删除按钮操作 */
  238. const handleDelete = async (id: number) => {
  239. try {
  240. // 删除的二次确认
  241. await message.delConfirm()
  242. // 发起删除
  243. await studentSelectionProjectApi.deleteStudentSelectionProject(id)
  244. message.success(t('common.delSuccess'))
  245. // 刷新列表
  246. await getList()
  247. } catch {}
  248. }
  249. /** 导出按钮操作 */
  250. const handleExport = async () => {
  251. try {
  252. // 导出的二次确认
  253. await message.exportConfirm()
  254. // 发起导出
  255. exportLoading.value = true
  256. const data = await studentSelectionProjectApi.exportStudentSelectionProject(queryParams)
  257. download.excel(data, '师生互选项目.xls')
  258. } catch {
  259. } finally {
  260. exportLoading.value = false
  261. }
  262. }
  263. const currentYear = new Date().getFullYear(); // 获取当前年份
  264. const gradeOptions = computed(() => {
  265. return [
  266. currentYear + '级', // 今年
  267. currentYear - 1 + '级', // 去年
  268. currentYear - 2 + '级', // 前年
  269. currentYear - 3 + '级', // 大前年
  270. currentYear - 4 + '级', // 大大前年
  271. ];
  272. });
  273. //不同人员跳转不同页面
  274. const router = useRouter()
  275. const openStudentSelectSupervisorRecord = (id) => {
  276. router.push({ name: 'studentSelectSupervisorRecord', query: { projectId: id} });
  277. }
  278. const openSupervisorSelectionSetting = (id) => {
  279. router.push({ name: 'supervisorSelectionSetting', query: { projectId: id} });
  280. }
  281. // 更新导师,学生开关
  282. const handleSwitchChange = async (id: number, field: string, value: number) => {
  283. if (!isPopDataLoaded.value) return; // 如果尚未加载弹窗数据,阻止更新
  284. try {
  285. popData.value[field] = value;
  286. console.log(popData.value)
  287. updateIsPop(popData.value); // 确保传递的是popData.value
  288. message.success(t('common.updateSuccess'));
  289. } catch (error) {
  290. message.error(t('common.updateError'));
  291. }
  292. };
  293. // 获取弹窗数据
  294. const getPopDataFunction = async () => {
  295. loading.value = true;
  296. try {
  297. popData.value = await getPopData();
  298. isPopDataLoaded.value = true; // 更新标志
  299. } finally {
  300. loading.value = false;
  301. }
  302. }
  303. /** 初始化 **/
  304. onMounted(async () => {
  305. getList();
  306. await getUserInfo(); // 等待用户信息加载完成
  307. if (userInfo.value.userType === '4') {
  308. getPopDataFunction();
  309. }
  310. });
  311. </script>
  312. <style>
  313. .switch-form {
  314. background-color: white; /* 设置白色背景 */
  315. padding: 10px; /* 根据需要添加内边距 */
  316. border-radius: 4px; /* 根据需要添加边框圆角 */
  317. box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1); /* 根据需要添加阴影 */
  318. font-size: 16px; /* 增大字体大小 */
  319. margin-bottom: 10px; /* 增加元素之间的间距 */
  320. }
  321. .switch-form.switch-form{
  322. padding: 10px 20px; /* 增大按钮内边距 */
  323. }
  324. </style>