template-list.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <view>
  3. <!-- 搜索组件 -->
  4. <TemplateSearchForm @search="handleQuery" @reset="handleReset" />
  5. <!-- 模板列表 -->
  6. <view class="p-24rpx">
  7. <view
  8. v-for="item in list"
  9. :key="item.id"
  10. class="mb-24rpx overflow-hidden rounded-12rpx bg-white shadow-sm"
  11. @click="handleDetail(item)"
  12. >
  13. <view class="p-24rpx">
  14. <view class="mb-16rpx flex items-center justify-between">
  15. <view class="text-32rpx text-[#333] font-semibold">
  16. {{ item.name }}
  17. </view>
  18. <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="item.status" />
  19. </view>
  20. <view class="mb-12rpx flex items-center text-28rpx text-[#666]">
  21. <text class="mr-8rpx shrink-0 text-[#999]">模板编码:</text>
  22. <text class="min-w-0 flex-1 truncate">{{ item.code }}</text>
  23. </view>
  24. <view class="mb-12rpx flex items-center text-28rpx text-[#666]">
  25. <text class="mr-8rpx shrink-0 text-[#999]">短信类型:</text>
  26. <dict-tag :type="DICT_TYPE.SYSTEM_SMS_TEMPLATE_TYPE" :value="item.type" />
  27. </view>
  28. <view class="mb-12rpx flex items-center text-28rpx text-[#666]">
  29. <text class="mr-8rpx shrink-0 text-[#999]">模板内容:</text>
  30. <text class="min-w-0 flex-1 truncate">{{ item.content }}</text>
  31. </view>
  32. <view class="mb-12rpx flex items-center text-28rpx text-[#666]">
  33. <text class="mr-8rpx text-[#999]">创建时间:</text>
  34. <text>{{ formatDateTime(item.createTime) || '-' }}</text>
  35. </view>
  36. </view>
  37. </view>
  38. <!-- 加载更多 -->
  39. <view v-if="loadMoreState !== 'loading' && list.length === 0" class="py-100rpx text-center">
  40. <wd-status-tip image="content" tip="暂无短信模板数据" />
  41. </view>
  42. <wd-loadmore
  43. v-if="list.length > 0"
  44. :state="loadMoreState"
  45. @reload="loadMore"
  46. />
  47. </view>
  48. <!-- 新增按钮 -->
  49. <wd-fab
  50. v-if="hasAccessByCodes(['system:sms-template:create'])"
  51. position="right-bottom"
  52. type="primary"
  53. :expandable="false"
  54. @click="handleAdd"
  55. />
  56. </view>
  57. </template>
  58. <script lang="ts" setup>
  59. import type { SmsTemplate } from '@/api/system/sms/template'
  60. import type { LoadMoreState } from '@/http/types'
  61. import { ref } from 'vue'
  62. import { getSmsTemplatePage } from '@/api/system/sms/template'
  63. import { useAccess } from '@/hooks/useAccess'
  64. import { DICT_TYPE } from '@/utils/constants'
  65. import { formatDateTime } from '@/utils/date'
  66. import TemplateSearchForm from './template-search-form.vue'
  67. const { hasAccessByCodes } = useAccess()
  68. const total = ref(0)
  69. const list = ref<SmsTemplate[]>([])
  70. const loadMoreState = ref<LoadMoreState>('loading')
  71. const queryParams = ref({
  72. pageNo: 1,
  73. pageSize: 10,
  74. })
  75. /** 查询列表 */
  76. async function getList() {
  77. loadMoreState.value = 'loading'
  78. try {
  79. const data = await getSmsTemplatePage(queryParams.value)
  80. list.value = [...list.value, ...data.list]
  81. total.value = data.total
  82. loadMoreState.value = list.value.length >= total.value ? 'finished' : 'loading'
  83. } catch {
  84. queryParams.value.pageNo = queryParams.value.pageNo > 1 ? queryParams.value.pageNo - 1 : 1
  85. loadMoreState.value = 'error'
  86. }
  87. }
  88. /** 搜索按钮操作 */
  89. function handleQuery(data?: Record<string, any>) {
  90. queryParams.value = {
  91. ...data,
  92. pageNo: 1,
  93. pageSize: queryParams.value.pageSize,
  94. }
  95. list.value = []
  96. getList()
  97. }
  98. /** 重置按钮操作 */
  99. function handleReset() {
  100. handleQuery()
  101. }
  102. /** 加载更多 */
  103. function loadMore() {
  104. if (loadMoreState.value === 'finished') {
  105. return
  106. }
  107. queryParams.value.pageNo++
  108. getList()
  109. }
  110. /** 新增 */
  111. function handleAdd() {
  112. uni.navigateTo({
  113. url: '/pages-system/sms/template/form/index',
  114. })
  115. }
  116. /** 查看详情 */
  117. function handleDetail(item: SmsTemplate) {
  118. uni.navigateTo({
  119. url: `/pages-system/sms/template/detail/index?id=${item.id}`,
  120. })
  121. }
  122. /** 触底加载更多 */
  123. onReachBottom(() => {
  124. loadMore()
  125. })
  126. /** 初始化 */
  127. onMounted(() => {
  128. getList()
  129. })
  130. </script>