index.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <template>
  2. <view class="yd-page-container">
  3. <!-- 顶部导航栏 -->
  4. <wd-navbar
  5. title="流程分类管理"
  6. left-arrow placeholder safe-area-inset-top fixed
  7. @click-left="handleBack"
  8. />
  9. <!-- 搜索组件 -->
  10. <SearchForm @search="handleQuery" @reset="handleReset" />
  11. <!-- 流程分类列表 -->
  12. <view class="p-24rpx">
  13. <view
  14. v-for="item in list"
  15. :key="item.id"
  16. class="mb-24rpx overflow-hidden rounded-12rpx bg-white shadow-sm"
  17. @click="handleDetail(item)"
  18. >
  19. <view class="p-24rpx">
  20. <view class="mb-16rpx flex items-center justify-between">
  21. <view class="text-32rpx text-[#333] font-semibold">
  22. {{ item.name }}
  23. </view>
  24. <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="item.status" />
  25. </view>
  26. <view class="mb-12rpx flex items-center text-28rpx text-[#666]">
  27. <text class="mr-8rpx shrink-0 text-[#999]">分类标志:</text>
  28. <text>{{ item.code }}</text>
  29. </view>
  30. <view class="mb-12rpx flex items-center text-28rpx text-[#666]">
  31. <text class="mr-8rpx shrink-0 text-[#999]">分类描述:</text>
  32. <text class="min-w-0 flex-1 truncate">{{ item.description || '-' }}</text>
  33. </view>
  34. <view class="mb-12rpx flex items-center text-28rpx text-[#666]">
  35. <text class="mr-8rpx text-[#999]">分类排序:</text>
  36. <text>{{ item.sort }}</text>
  37. </view>
  38. <view class="mb-12rpx flex items-center text-28rpx text-[#666]">
  39. <text class="mr-8rpx text-[#999]">创建时间:</text>
  40. <text class="line-clamp-1">{{ formatDateTime(item.createTime) }}</text>
  41. </view>
  42. </view>
  43. </view>
  44. <!-- 加载更多 -->
  45. <view v-if="loadMoreState !== 'loading' && list.length === 0" class="py-100rpx text-center">
  46. <wd-status-tip image="content" tip="暂无流程分类数据" />
  47. </view>
  48. <wd-loadmore
  49. v-if="list.length > 0"
  50. :state="loadMoreState"
  51. @reload="loadMore"
  52. />
  53. </view>
  54. <!-- 新增按钮 -->
  55. <wd-fab
  56. v-if="hasAccessByCodes(['bpm:category:create'])"
  57. position="right-bottom"
  58. type="primary"
  59. :expandable="false"
  60. @click="handleAdd"
  61. />
  62. </view>
  63. </template>
  64. <script lang="ts" setup>
  65. import type { Category } from '@/api/bpm/category'
  66. import type { LoadMoreState } from '@/http/types'
  67. import { onReachBottom } from '@dcloudio/uni-app'
  68. import { onMounted, ref } from 'vue'
  69. import { getCategoryPage } from '@/api/bpm/category'
  70. import { useAccess } from '@/hooks/useAccess'
  71. import { navigateBackPlus } from '@/utils'
  72. import { DICT_TYPE } from '@/utils/constants'
  73. import { formatDateTime } from '@/utils/date'
  74. import SearchForm from './components/search-form.vue'
  75. definePage({
  76. style: {
  77. navigationBarTitleText: '',
  78. navigationStyle: 'custom',
  79. },
  80. })
  81. const { hasAccessByCodes } = useAccess()
  82. const total = ref(0)
  83. const list = ref<Category[]>([])
  84. const loadMoreState = ref<LoadMoreState>('loading')
  85. const queryParams = ref({
  86. pageNo: 1,
  87. pageSize: 10,
  88. })
  89. /** 返回上一页 */
  90. function handleBack() {
  91. navigateBackPlus()
  92. }
  93. /** 查询流程分类列表 */
  94. async function getList() {
  95. loadMoreState.value = 'loading'
  96. try {
  97. const data = await getCategoryPage(queryParams.value)
  98. list.value = [...list.value, ...data.list]
  99. total.value = data.total
  100. loadMoreState.value = list.value.length >= total.value ? 'finished' : 'loading'
  101. } catch {
  102. queryParams.value.pageNo = queryParams.value.pageNo > 1 ? queryParams.value.pageNo - 1 : 1
  103. loadMoreState.value = 'error'
  104. }
  105. }
  106. /** 搜索按钮操作 */
  107. function handleQuery(data?: Record<string, any>) {
  108. queryParams.value = {
  109. ...data,
  110. pageNo: 1,
  111. pageSize: queryParams.value.pageSize,
  112. }
  113. list.value = []
  114. getList()
  115. }
  116. /** 重置按钮操作 */
  117. function handleReset() {
  118. handleQuery()
  119. }
  120. /** 加载更多 */
  121. function loadMore() {
  122. if (loadMoreState.value === 'finished') {
  123. return
  124. }
  125. queryParams.value.pageNo++
  126. getList()
  127. }
  128. /** 新增流程分类 */
  129. function handleAdd() {
  130. uni.navigateTo({
  131. url: '/pages-bpm/category/form/index',
  132. })
  133. }
  134. /** 查看详情 */
  135. function handleDetail(item: Category) {
  136. uni.navigateTo({
  137. url: `/pages-bpm/category/detail/index?id=${item.id}`,
  138. })
  139. }
  140. /** 触底加载更多 */
  141. onReachBottom(() => {
  142. loadMore()
  143. })
  144. /** 初始化 */
  145. onMounted(() => {
  146. getList()
  147. })
  148. </script>
  149. <style lang="scss" scoped>
  150. </style>