Blame view

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