index.vue.vm 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <template>
  2. <view class="yd-page-container">
  3. <!-- 顶部导航栏 -->
  4. <wd-navbar
  5. title="${table.classComment}管理"
  6. left-arrow placeholder safe-area-inset-top fixed
  7. @click-left="handleBack"
  8. />
  9. <!-- 搜索组件 -->
  10. <SearchForm @search="handleQuery" @reset="handleReset" />
  11. <!-- ${table.classComment}列表 -->
  12. <view class="p-24rpx">
  13. <view
  14. v-for="item in list"
  15. :key="item.${primaryColumn.javaField}"
  16. class="mb-24rpx overflow-hidden rounded-12rpx bg-white shadow-sm"
  17. @click="handleDetail(item)"
  18. >
  19. <view class="p-24rpx">
  20. #set ($titleField = "")
  21. #set ($statusField = "")
  22. #set ($statusDictType = "")
  23. #foreach($column in $columns)
  24. #if ($titleField == "" && !$column.primaryKey && $column.listOperationResult)
  25. #set ($titleField = $column.javaField)
  26. #set ($titleComment = $column.columnComment)
  27. #end
  28. #if ($statusField == "" && $column.listOperationResult && $column.dictType && "" != $column.dictType)
  29. #set ($statusField = $column.javaField)
  30. #set ($statusDictType = $column.dictType)
  31. #end
  32. #end
  33. #if ($titleField == "")
  34. #set ($titleField = $primaryColumn.javaField)
  35. #end
  36. <view class="mb-16rpx flex items-center justify-between">
  37. <view class="text-32rpx text-[#333] font-semibold">
  38. {{ item.${titleField} }}
  39. </view>
  40. #if($statusField != "")
  41. <dict-tag :type="DICT_TYPE.${statusDictType.toUpperCase()}" :value="item.${statusField}" />
  42. #end
  43. </view>
  44. #foreach($column in $columns)
  45. #if ($column.listOperationResult && !$column.primaryKey && $column.javaField != $titleField && $column.javaField != $statusField)
  46. #set ($javaField = $column.javaField)
  47. #set ($comment = $column.columnComment)
  48. #set ($dictType = $column.dictType)
  49. #set ($javaType = $column.javaType)
  50. #if ($dictType && "" != $dictType)
  51. <view class="mb-12rpx flex items-center text-28rpx text-[#666]">
  52. <text class="mr-8rpx text-[#999]">${comment}:</text>
  53. <dict-tag :type="DICT_TYPE.${dictType.toUpperCase()}" :value="item.${javaField}" />
  54. </view>
  55. #elseif ($javaType == "LocalDateTime")
  56. <view class="mb-12rpx flex items-center text-28rpx text-[#666]">
  57. <text class="mr-8rpx text-[#999]">${comment}:</text>
  58. <text class="line-clamp-1">{{ formatDateTime(item.${javaField}) || '-' }}</text>
  59. </view>
  60. #else
  61. <view class="mb-12rpx flex items-center text-28rpx text-[#666]">
  62. <text class="mr-8rpx text-[#999]">${comment}:</text>
  63. <text class="line-clamp-1">{{ item.${javaField} }}</text>
  64. </view>
  65. #end
  66. #end
  67. #end
  68. </view>
  69. </view>
  70. <!-- 加载更多 -->
  71. <view v-if="loadMoreState !== 'loading' && list.length === 0" class="py-100rpx text-center">
  72. <wd-status-tip image="content" tip="暂无${table.classComment}数据" />
  73. </view>
  74. <wd-loadmore
  75. v-if="list.length > 0"
  76. :state="loadMoreState"
  77. @reload="loadMore"
  78. />
  79. </view>
  80. <!-- 新增按钮 -->
  81. <wd-fab
  82. v-if="hasAccessByCodes(['${permissionPrefix}:create'])"
  83. position="right-bottom"
  84. type="primary"
  85. :expandable="false"
  86. @click="handleAdd"
  87. />
  88. </view>
  89. </template>
  90. <script lang="ts" setup>
  91. #set ($hasDict = 0)
  92. #foreach($column in $columns)
  93. #if ($hasDict == 0 && $column.listOperationResult && $column.dictType && "" != $column.dictType)
  94. #set ($hasDict = 1)
  95. #end
  96. #end
  97. #set ($hasDateTime = 0)
  98. #foreach($column in $columns)
  99. #if ($column.listOperationResult)
  100. #if ($hasDateTime == 0 && $column.javaType == "LocalDateTime")
  101. #set ($hasDateTime = 1)
  102. #end
  103. #end
  104. #end
  105. import type { ${simpleClassName} } from '@/api/${table.moduleName}/${table.businessName}'
  106. import type { LoadMoreState } from '@/http/types'
  107. import { onReachBottom } from '@dcloudio/uni-app'
  108. import { onMounted, ref } from 'vue'
  109. import { get${simpleClassName}Page } from '@/api/${table.moduleName}/${table.businessName}'
  110. import { useAccess } from '@/hooks/useAccess'
  111. import { navigateBackPlus } from '@/utils'
  112. #if ($hasDict == 1)
  113. import { DICT_TYPE } from '@/utils/constants'
  114. #end
  115. #if ($hasDateTime == 1)
  116. import { formatDateTime } from '@/utils/date'
  117. #end
  118. import SearchForm from './components/search-form.vue'
  119. definePage({
  120. style: {
  121. navigationBarTitleText: '',
  122. navigationStyle: 'custom',
  123. },
  124. })
  125. const { hasAccessByCodes } = useAccess()
  126. const total = ref(0)
  127. const list = ref<${simpleClassName}[]>([])
  128. const loadMoreState = ref<LoadMoreState>('loading')
  129. const queryParams = ref({
  130. pageNo: 1,
  131. pageSize: 10,
  132. })
  133. /** 返回上一页 */
  134. function handleBack() {
  135. navigateBackPlus()
  136. }
  137. /** 查询${table.classComment}列表 */
  138. async function getList() {
  139. loadMoreState.value = 'loading'
  140. try {
  141. const data = await get${simpleClassName}Page(queryParams.value)
  142. list.value = [...list.value, ...data.list]
  143. total.value = data.total
  144. loadMoreState.value = list.value.length >= total.value ? 'finished' : 'loading'
  145. } catch {
  146. queryParams.value.pageNo = queryParams.value.pageNo > 1 ? queryParams.value.pageNo - 1 : 1
  147. loadMoreState.value = 'error'
  148. }
  149. }
  150. /** 搜索按钮操作 */
  151. function handleQuery(data?: Record<string, any>) {
  152. queryParams.value = {
  153. ...data,
  154. pageNo: 1,
  155. pageSize: queryParams.value.pageSize,
  156. }
  157. list.value = []
  158. getList()
  159. }
  160. /** 重置按钮操作 */
  161. function handleReset() {
  162. handleQuery()
  163. }
  164. /** 加载更多 */
  165. function loadMore() {
  166. if (loadMoreState.value === 'finished') {
  167. return
  168. }
  169. queryParams.value.pageNo++
  170. getList()
  171. }
  172. /** 新增${table.classComment} */
  173. function handleAdd() {
  174. uni.navigateTo({
  175. url: '/pages-${table.moduleName}/${table.businessName}/form/index',
  176. })
  177. }
  178. /** 查看详情 */
  179. function handleDetail(item: ${simpleClassName}) {
  180. uni.navigateTo({
  181. url: `/pages-${table.moduleName}/${table.businessName}/detail/index?id=#[[${]]#item.${primaryColumn.javaField}#[[}]]#`,
  182. })
  183. }
  184. /** 触底加载更多 */
  185. onReachBottom(() => {
  186. loadMore()
  187. })
  188. /** 初始化 */
  189. onMounted(() => {
  190. getList()
  191. })
  192. </script>
  193. <style lang="scss" scoped>
  194. </style>