昨天 8f3bf7050e65fdbe55eaad74fde307c57dab960e
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
<template>
  <view class="yd-page-container yd-page-container-paging">
    <!-- 顶部导航栏 -->
    <wd-navbar
      title="学生管理"
      left-arrow placeholder safe-area-inset-top fixed
      @click-left="handleBack"
    />
 
    <!-- 搜索组件 -->
    <SearchForm @search="handleQuery" @reset="handleReset" />
 
    <!-- 学生列表 -->
    <z-paging
      ref="pagingRef"
      v-model="list"
      :fixed="false"
      class="min-h-0 flex-1"
      :default-page-size="10"
      :refresher-enabled="true"
      :inside-more="true"
      :loading-more-default-as-loading="true"
      empty-view-text="暂无学生数据"
      @query="queryList"
    >
      <view class="p-24rpx">
        <view
          v-for="item in list"
          :key="item.id"
          class="mb-24rpx overflow-hidden rounded-12rpx bg-white shadow-sm"
          @click="handleDetail(item)"
        >
          <view class="p-24rpx">
            <view class="mb-16rpx flex items-center justify-between">
              <view class="text-32rpx text-[#333] font-semibold">
                {{ item.name }}
              </view>
              <dict-tag :type="DICT_TYPE.SYSTEM_USER_SEX" :value="item.sex" />
            </view>
            <view class="mb-12rpx flex items-center text-28rpx text-[#666]">
              <text class="mr-8rpx text-[#999]">简介:</text>
              <text class="line-clamp-1">{{ item.description }}</text>
            </view>
            <view class="mb-12rpx flex items-center text-28rpx text-[#666]">
              <text class="mr-8rpx text-[#999]">出生日期:</text>
              <text class="line-clamp-1">{{ formatDateTime(item.birthday) || '-' }}</text>
            </view>
            <view class="mb-12rpx flex items-center text-28rpx text-[#666]">
              <text class="mr-8rpx text-[#999]">是否有效:</text>
              <dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="item.enabled" />
            </view>
            <view class="mb-12rpx flex items-center text-28rpx text-[#666]">
              <text class="mr-8rpx text-[#999]">头像:</text>
              <text class="line-clamp-1">{{ item.avatar }}</text>
            </view>
            <view class="mb-12rpx flex items-center text-28rpx text-[#666]">
              <text class="mr-8rpx text-[#999]">附件:</text>
              <text class="line-clamp-1">{{ item.video }}</text>
            </view>
            <view class="mb-12rpx flex items-center text-28rpx text-[#666]">
              <text class="mr-8rpx text-[#999]">备注:</text>
              <text class="line-clamp-1">{{ item.memo }}</text>
            </view>
            <view class="mb-12rpx flex items-center text-28rpx text-[#666]">
              <text class="mr-8rpx text-[#999]">创建时间:</text>
              <text class="line-clamp-1">{{ formatDateTime(item.createTime) || '-' }}</text>
            </view>
          </view>
        </view>
      </view>
    </z-paging>
 
    <!-- 新增按钮 -->
    <wd-fab
      v-if="hasAccessByCodes(['infra:student:create'])"
      position="right-bottom"
      type="primary"
      :expandable="false"
      @click="handleAdd"
    />
  </view>
</template>
 
<script lang="ts" setup>
import type { Student } from '@/api/infra/demo'
import { onUnload } from '@dcloudio/uni-app'
import { onMounted, ref } from 'vue'
import { getStudentPage } from '@/api/infra/demo'
import { useAccess } from '@/hooks/useAccess'
import { navigateBackPlus } from '@/utils'
import { DICT_TYPE } from '@/utils/constants'
import { formatDateTime } from '@/utils/date'
import SearchForm from './components/search-form.vue'
 
definePage({
  style: {
    navigationBarTitleText: '',
    navigationStyle: 'custom',
  },
})
 
const { hasAccessByCodes } = useAccess()
const list = ref<Student[]>([]) // 列表数据
const pagingRef = ref<any>() // 分页组件引用
const queryParams = ref<Record<string, any>>({}) // 查询参数
 
/** 返回上一页 */
function handleBack() {
  navigateBackPlus()
}
 
/** 查询学生列表 */
async function queryList(pageNo: number, pageSize: number) {
  try {
    const params = {
      ...queryParams.value,
      pageNo,
      pageSize,
    }
    const data = await getStudentPage(params)
    pagingRef.value?.completeByTotal(data.list, data.total)
  } catch {
    pagingRef.value?.complete(false)
  }
}
 
/** 搜索按钮操作 */
function handleQuery(data?: Record<string, any>) {
  queryParams.value = { ...data }
  reload()
}
 
/** 重置按钮操作 */
function handleReset() {
  handleQuery()
}
 
/** 重新加载 */
function reload() {
  pagingRef.value?.reload()
}
 
/** 新增学生 */
function handleAdd() {
  uni.navigateTo({
    url: '/pages-infra/demo/form/index',
  })
}
 
/** 查看详情 */
function handleDetail(item: Student) {
  uni.navigateTo({
    url: `/pages-infra/demo/detail/index?id=${item.id}`,
  })
}
 
/** 初始化 */
onMounted(() => {
  uni.$on('infra:demo:reload', reload)
})
 
/** 卸载 */
onUnload(() => {
  uni.$off('infra:demo:reload', reload)
})
</script>
 
<style lang="scss" scoped>
</style>