2026-06-26 20b96473f2520590a0dca6b775b81e3ea06a77a0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
<script lang="ts" setup>
  import type { StudentApi } from '#/api/infra/student';
  import type { VxeTableInstance } from '#/adapter/vxe-table';
 
  import { reactive,ref, h, nextTick,watch,onMounted } from 'vue';
 
  import { DICT_TYPE } from '@vben/constants';
  import { getDictOptions } from '@vben/hooks';
 
  import { DictTag } from '#/components/dict-tag';
  import { getRangePickerDefaultProps } from '#/utils';
  import { VxeColumn, VxeTable } from '#/adapter/vxe-table';
  import { ContentWrap } from '#/components/content-wrap';
 
     import { useVbenModal } from '@vben/common-ui';
    import { useTableToolbar, VbenVxeTableToolbar } from '@vben/plugins/vxe-table';
    import StudentContactForm from './student-contact-form.vue'
    import { Tinymce as RichTextarea } from '#/components/tinymce';
    import { ImageUpload, FileUpload } from "#/components/upload";
    import { ElMessage, ElLoading, ElButton, ElTabs, ElTabPane, ElPagination, ElForm, ElFormItem, ElDatePicker, ElSelect, ElOption, ElInput } from 'element-plus';
    import { Plus, Trash2 } from '@vben/icons';
    import { $t } from '#/locales';
 
     import { deleteStudentContact, deleteStudentContactList, getStudentContactPage } from '#/api/infra/student';
    import { isEmpty } from '@vben/utils';
 
const props = defineProps<{
      studentId?: number // 学生编号(主表的关联字段)
}>()
 
   const [FormModal, formModalApi] = useVbenModal({
    connectedComponent: StudentContactForm,
    destroyOnClose: true,
  });
 
/** 创建学生联系人 */
function handleCreate() {
  if (!props.studentId){
    ElMessage.warning("请先选择一个学生!")
    return
  }
  formModalApi.setData({studentId: props.studentId}).open();
}
 
/** 编辑学生联系人 */
function handleEdit(row: StudentApi.StudentContact) {
  formModalApi.setData(row).open();
}
 
/** 删除学生联系人 */
async function handleDelete(row: StudentApi.StudentContact) {
  const loadingInstance = ElLoading.service({
    text: $t('ui.actionMessage.deleting', [row.id]),
  });
  try {
    await deleteStudentContact(row.id as number);
    ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.id]));
    await getList();
  } finally {
    loadingInstance.close();
  }
}
 
/** 批量删除学生联系人 */
async function handleDeleteBatch() {
  const loadingInstance = ElLoading.service({
    text: $t('ui.actionMessage.deleting'),
  });
  try {
    await deleteStudentContactList(checkedIds.value);
    checkedIds.value = [];
    ElMessage.success($t('ui.actionMessage.deleteSuccess'));
    await getList();
  } finally {
    loadingInstance.close();
  }
}
 
const checkedIds = ref<number[]>([])
function handleRowCheckboxChange({
  records,
}: {
  records: StudentApi.StudentContact[];
}) {
  checkedIds.value = records.map((item) => item.id!);
}
 
  const loading = ref(true) // 列表的加载中
  const list = ref<StudentApi.StudentContact[]>([]) // 列表的数据
   const total = ref(0) // 列表的总页数
   const queryFormRef = ref() // 搜索的表单
  const queryParams = reactive({
      pageNo: 1,
      pageSize: 10,
                      name: undefined,
                      birthday: undefined,
                      birthday: undefined,
                      sex: undefined,
                      enabled: undefined,
                      createTime: undefined,
  })
 
/** 搜索按钮操作 */
function handleQuery() {
  queryParams.pageNo = 1
  getList()
}
 
/** 重置按钮操作 */
function resetQuery() {
  queryFormRef.value.resetFields()
  handleQuery()
}
/** 查询列表 */
async function getList() {
  loading.value = true
  try {
    if (!props.studentId){
      return []
    }
               const params = cloneDeep(queryParams) as any;
                    if (params.birthday && Array.isArray(params.birthday)) {
                      params.birthday = (params.birthday as string[]).join(',');
                    }
                    if (params.createTime && Array.isArray(params.createTime)) {
                      params.createTime = (params.createTime as string[]).join(',');
                    }
        params.studentId = props.studentId;
        const data = await getStudentContactPage(params)
        list.value = data.list
        total.value = data.total
  } finally {
    loading.value = false
  }
}
 
/** 监听主表的关联字段的变化,加载对应的子表数据 */
watch(
    () => props.studentId,
    async (val) => {
      if (!val) {
        return;
      }
      await nextTick();
      await getList()
    },
    { immediate: true },
);
 
 /** 初始化 */
const { hiddenSearchBar, tableToolbarRef, tableRef } = useTableToolbar();
onMounted(() => {
  getList();
});
</script>
 
<template>
       <FormModal @success="getList" />
      <div class="h-[600px]">
        <ContentWrap v-if="!hiddenSearchBar">
          <!-- 搜索工作栏 -->
          <el-form
              :model="queryParams"
              ref="queryFormRef"
              inline
          >
                        <el-form-item label="名字">
                          <el-input
                              v-model="queryParams.name"
                              placeholder="请输入名字"
                              clearable
                              @keyup.enter="handleQuery"
                              class="!w-[240px]"
                          />
                        </el-form-item>
                            <el-form-item label="出生日期">
                              <el-date-picker
                                  v-model="queryParams.birthday"
                                  value-format="YYYY-MM-DD"
                                  placeholder="选择出生日期"
                                  clearable
                                  class="!w-[240px]"
                              />
                            </el-form-item>
                        <el-form-item label="性别">
                          <el-select
                              v-model="queryParams.sex"
                              placeholder="请选择性别"
                              clearable
                              class="!w-[240px]"
                          >
                                <el-option
                                    v-for="dict in getDictOptions(DICT_TYPE.SYSTEM_USER_SEX, 'number')"
                                    :key="dict.value"
                                    :value="dict.value"
                                    :label="dict.label"
                                />
                          </el-select>
                        </el-form-item>
                        <el-form-item label="是否有效">
                          <el-select
                              v-model="queryParams.enabled"
                              placeholder="请选择是否有效"
                              clearable
                              class="!w-[240px]"
                          >
                                <el-option
                                    v-for="dict in getDictOptions(DICT_TYPE.INFRA_BOOLEAN_STRING, 'boolean')"
                                    :key="dict.value"
                                    :value="dict.value"
                                    :label="dict.label"
                                />
                          </el-select>
                        </el-form-item>
                            <el-form-item label="创建时间">
                              <el-date-picker
                                  v-model="queryParams.createTime"
                                  type="daterange"
                                  value-format="YYYY-MM-DD"
                                  range-separator="至"
                                  start-placeholder="开始日期"
                                  end-placeholder="结束日期"
                                  class="!w-[240px]"
                              />
                            </el-form-item>
            <el-form-item>
              <el-button class="ml-2" @click="resetQuery"> 重置 </el-button>
              <el-button class="ml-2" @click="handleQuery" type="primary">
                搜索
              </el-button>
            </el-form-item>
          </el-form>
        </ContentWrap>
 
        <!-- 列表 -->
        <ContentWrap title="学生">
          <template #extra>
            <VbenVxeTableToolbar
                ref="tableToolbarRef"
                v-model:hidden-search="hiddenSearchBar"
            >
              <el-button
                  class="ml-2"
                  :icon="h(Plus)"
                  type="primary"
                  @click="handleCreate"
                  v-access:code="['infra:student:create']"
              >
                {{ $t('ui.actionTitle.create', ['学生']) }}
              </el-button>
                  <el-button
                      :icon="h(Trash2)"
                      type="danger"
                      class="ml-2"
                      :disabled="isEmpty(checkedIds)"
                      @click="handleDeleteBatch"
                      v-access:code="['infra:student:delete']"
                  >
                    批量删除
                  </el-button>
            </TableToolbar>
          </template>
          <vxe-table
              ref="tableRef"
              :data="list"
              show-overflow
              :loading="loading"
              @checkboxAll="handleRowCheckboxChange"
              @checkboxChange="handleRowCheckboxChange"
          >
                <vxe-column type="checkbox" width="40"></vxe-column>
                        <vxe-column field="id" title="编号" align="center" />
                        <vxe-column field="studentId" title="学生编号" align="center" />
                        <vxe-column field="name" title="名字" align="center" />
                        <vxe-column field="description" title="简介" align="center" />
                        <vxe-column field="birthday" title="出生日期" align="center">
                          <template #default="{row}">
                            {{formatDateTime(row.birthday)}}
                          </template>
                        </vxe-column>
                        <vxe-column field="sex" title="性别" align="center">
                          <template #default="{row}">
                            <dict-tag :type="DICT_TYPE.SYSTEM_USER_SEX" :value="row.sex" />
                          </template>
                        </vxe-column>
                        <vxe-column field="enabled" title="是否有效" align="center">
                          <template #default="{row}">
                            <dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="row.enabled" />
                          </template>
                        </vxe-column>
                        <vxe-column field="avatar" title="头像" align="center" />
                        <vxe-column field="video" title="附件" align="center" />
                        <vxe-column field="memo" title="备注" align="center" />
                        <vxe-column field="createTime" title="创建时间" align="center">
                          <template #default="{row}">
                            {{formatDateTime(row.createTime)}}
                          </template>
                        </vxe-column>
            <vxe-column field="operation" title="操作" align="center">
              <template #default="{row}">
                <el-button
                    size="small"
                    type="primary"
                    link
                    @click="handleEdit(row as any)"
                    v-access:code="['infra:student:update']"
                >
                  {{ $t('ui.actionTitle.edit') }}
                </el-button>
                <el-button
                    size="small"
                    type="danger"
                    link
                    class="ml-2"
                    @click="handleDelete(row as any)"
                    v-access:code="['infra:student:delete']"
                >
                  {{ $t('ui.actionTitle.delete') }}
                </el-button>
              </template>
            </vxe-column>
          </vxe-table>
          <!-- 分页 -->
          <div class="mt-2 flex justify-end">
            <el-pagination
                :total="total"
                v-model:current-page="queryParams.pageNo"
                v-model:page-size="queryParams.pageSize"
                :page-sizes="[10, 20, 50, 100]"
                layout="total, sizes, prev, pager, next, jumper"
                @size-change="getList"
                @current-change="getList"
            />
          </div>
        </ContentWrap>
      </div>
</template>