mirror of
https://gitee.com/zhijiantianya/ruoyi-vue-pro.git
synced 2025-12-26 00:26:20 +08:00
feat:【infra】移动端 admin uniapp 的代码生成的优化(search-form、list 的模版)
This commit is contained in:
parent
94a1c4636f
commit
2a5ebb5ad1
@ -1,4 +1,5 @@
|
||||
<template>
|
||||
<!-- 搜索框入口 -->
|
||||
<wd-search
|
||||
:placeholder="searchPlaceholder"
|
||||
:hide-cancel="true"
|
||||
@ -6,6 +7,7 @@
|
||||
@click="visible = true"
|
||||
/>
|
||||
|
||||
<!-- 搜索弹窗 -->
|
||||
<wd-popup
|
||||
v-model="visible"
|
||||
position="top"
|
||||
@ -17,14 +19,12 @@
|
||||
<view class="mb-24rpx text-32rpx text-[#333] font-semibold">
|
||||
搜索${table.classComment}
|
||||
</view>
|
||||
|
||||
#set ($hasDict = 0)
|
||||
#foreach ($column in $columns)
|
||||
#if ($hasDict == 0 && $column.listOperation && $column.dictType && "" != $column.dictType)
|
||||
#set ($hasDict = 1)
|
||||
#end
|
||||
#end
|
||||
|
||||
#foreach($column in $columns)
|
||||
#if ($column.listOperation)
|
||||
#set ($dictType = $column.dictType)
|
||||
@ -39,7 +39,6 @@
|
||||
#elseif ($javaType == "Boolean")
|
||||
#set ($dictMethod = "getBoolDictOptions")
|
||||
#end
|
||||
|
||||
#if ($column.htmlType == "input")
|
||||
<view class="mb-24rpx">
|
||||
<view class="mb-12rpx text-28rpx text-[#666]">
|
||||
@ -83,7 +82,6 @@
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
|
||||
<view class="w-full flex justify-center gap-24rpx">
|
||||
<wd-button class="flex-1" plain @click="handleReset">
|
||||
重置
|
||||
@ -97,8 +95,6 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { computed, reactive, ref, watch } from 'vue'
|
||||
|
||||
#set ($hasDict = 0)
|
||||
#set ($hasGetDictOptions = 0)
|
||||
#set ($hasGetIntDictOptions = 0)
|
||||
@ -120,23 +116,25 @@ import { computed, reactive, ref, watch } from 'vue'
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
import { computed, reactive, ref, watch } from 'vue'
|
||||
#if ($hasDict == 1)
|
||||
import { DICT_TYPE } from '@/utils/constants'
|
||||
import {
|
||||
#set ($dictImportNames = "getDictLabel, ")
|
||||
#if ($hasGetDictOptions == 1)
|
||||
getDictOptions,
|
||||
#set ($dictImportNames = "${dictImportNames}getDictOptions, ")
|
||||
#end
|
||||
#if ($hasGetIntDictOptions == 1)
|
||||
getIntDictOptions,
|
||||
#set ($dictImportNames = "${dictImportNames}getIntDictOptions, ")
|
||||
#end
|
||||
#if ($hasGetStrDictOptions == 1)
|
||||
getStrDictOptions,
|
||||
#set ($dictImportNames = "${dictImportNames}getStrDictOptions, ")
|
||||
#end
|
||||
#if ($hasGetBoolDictOptions == 1)
|
||||
getBoolDictOptions,
|
||||
#set ($dictImportNames = "${dictImportNames}getBoolDictOptions, ")
|
||||
#end
|
||||
getDictLabel,
|
||||
} from '@/hooks/useDict'
|
||||
#set ($dictImportNames = $dictImportNames.trim())
|
||||
#set ($dictImportNames = $dictImportNames.substring(0, $dictImportNames.length() - 1))
|
||||
import { $dictImportNames } from '@/hooks/useDict'
|
||||
import { DICT_TYPE } from '@/utils/constants'
|
||||
#end
|
||||
|
||||
/** 搜索表单数据 */
|
||||
@ -185,16 +183,16 @@ const searchPlaceholder = computed(() => {
|
||||
#set ($comment = $column.columnComment)
|
||||
#if ($dictType && "" != $dictType)
|
||||
if (props.searchParams?.${javaField} !== undefined && props.searchParams.${javaField} !== -1) {
|
||||
conditions.push('${comment}:' + getDictLabel(DICT_TYPE.$dictType.toUpperCase(), props.searchParams.${javaField}))
|
||||
conditions.push(`${comment}:#[[${]]#getDictLabel(DICT_TYPE.${dictType.toUpperCase()}, props.searchParams.${javaField})#[[}]]#`)
|
||||
}
|
||||
#else
|
||||
#if(${javaType} == "long" || ${javaType} == "integer" || ${javaType} == "short" || ${javaType} == "double" || ${javaType} == "bigdecimal" || ${javaType} == "byte" || ${javaType} == "boolean")
|
||||
if (props.searchParams?.${javaField} !== undefined) {
|
||||
conditions.push('${comment}:' + props.searchParams.${javaField})
|
||||
conditions.push(`${comment}:#[[${]]#props.searchParams.${javaField}#[[}]]#`)
|
||||
}
|
||||
#else
|
||||
if (props.searchParams?.${javaField}) {
|
||||
conditions.push('${comment}:' + props.searchParams.${javaField})
|
||||
conditions.push(`${comment}:#[[${]]#props.searchParams.${javaField}#[[}]]#`)
|
||||
}
|
||||
#end
|
||||
#end
|
||||
@ -222,6 +220,7 @@ const formData = reactive<SearchFormData>({
|
||||
#end
|
||||
})
|
||||
|
||||
/** 监听弹窗打开,同步外部参数 */
|
||||
watch(visible, (val) => {
|
||||
if (val && props.searchParams) {
|
||||
#foreach($column in $columns)
|
||||
@ -236,11 +235,13 @@ watch(visible, (val) => {
|
||||
}
|
||||
})
|
||||
|
||||
/** 搜索 */
|
||||
function handleSearch() {
|
||||
visible.value = false
|
||||
emit('search', { ...formData } as SearchFormData)
|
||||
}
|
||||
|
||||
/** 重置 */
|
||||
function handleReset() {
|
||||
#foreach($column in $columns)
|
||||
#if ($column.listOperation)
|
||||
|
||||
@ -21,7 +21,7 @@
|
||||
#elseif ($column.javaType == "LocalDateTime")
|
||||
<wd-cell title="${comment}" :value="formatDateTime(formData?.${javaField}) || '-'" />
|
||||
#else
|
||||
<wd-cell title="${comment}" :value="String(formData?.${javaField} ?? '-')" />
|
||||
<wd-cell title="${comment}" :value="formData?.${javaField} ?? '-'" />
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
@ -87,8 +87,8 @@ definePage({
|
||||
|
||||
const { hasAccessByCodes } = useAccess()
|
||||
const toast = useToast()
|
||||
const formData = ref<${simpleClassName}>() // 详情数据
|
||||
const deleting = ref(false) // 删除中
|
||||
const formData = ref<${simpleClassName}>()
|
||||
const deleting = ref(false)
|
||||
|
||||
/** 返回上一页 */
|
||||
function handleBack() {
|
||||
@ -111,7 +111,7 @@ async function getDetail() {
|
||||
/** 编辑${table.classComment} */
|
||||
function handleEdit() {
|
||||
uni.navigateTo({
|
||||
url: `/pages-${table.moduleName}/${table.businessName}/form/index?id=\${props.id}`,
|
||||
url: `/pages-${table.moduleName}/${table.businessName}/form/index?id=#[[${]]#props.id#[[}]]#`,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@ -22,7 +22,6 @@
|
||||
class="mb-24rpx overflow-hidden rounded-12rpx bg-white shadow-sm"
|
||||
@click="handleDetail(item)"
|
||||
>
|
||||
<!-- TODO @AI:下面的 view 部分代码,缩进可能不太对; -->
|
||||
<view class="p-24rpx">
|
||||
#set ($titleField = "")
|
||||
#set ($statusField = "")
|
||||
@ -37,23 +36,38 @@
|
||||
#set ($statusDictType = $column.dictType)
|
||||
#end
|
||||
#end
|
||||
#if ($titleField == "")
|
||||
#set ($titleField = $primaryColumn.javaField)
|
||||
#end
|
||||
<view class="mb-16rpx flex items-center justify-between">
|
||||
<view class="text-32rpx text-[#333] font-semibold">
|
||||
{{ item.#if($titleField != "")${titleField}#else ${primaryColumn.javaField}#end }}
|
||||
{{ item.${titleField} }}
|
||||
</view>
|
||||
#if($statusField != "")
|
||||
<dict-tag :type="DICT_TYPE.$statusDictType.toUpperCase()" :value="item.$statusField" />
|
||||
<dict-tag :type="DICT_TYPE.${statusDictType.toUpperCase()}" :value="item.${statusField}" />
|
||||
#end
|
||||
</view>
|
||||
#set ($infoCount = 0)
|
||||
#foreach($column in $columns)
|
||||
#if ($column.listOperationResult && !$column.primaryKey && $column.javaField != $titleField && $column.javaField != $statusField)
|
||||
#if ($infoCount < 2)
|
||||
<view class="mb-12rpx flex items-center text-28rpx text-[#666]">
|
||||
<text class="mr-8rpx text-[#999]">${column.columnComment}:</text>
|
||||
<text class="line-clamp-1">{{ item.${column.javaField} }}</text>
|
||||
</view>
|
||||
#set ($infoCount = $infoCount + 1)
|
||||
#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>
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
@ -83,6 +97,20 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
#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
|
||||
import type { SearchFormData } from './components/search-form.vue'
|
||||
import type { ${simpleClassName} } from '@/api/${table.moduleName}/${table.businessName}'
|
||||
import type { LoadMoreState } from '@/http/types'
|
||||
@ -91,16 +119,13 @@ import { onMounted, reactive, ref } from 'vue'
|
||||
import { get${simpleClassName}Page } from '@/api/${table.moduleName}/${table.businessName}'
|
||||
import { useAccess } from '@/hooks/useAccess'
|
||||
import { navigateBackPlus } from '@/utils'
|
||||
import SearchForm from './components/search-form.vue'
|
||||
#set ($hasDict = 0)
|
||||
#foreach($column in $columns)
|
||||
#if ($hasDict == 0 && $column.listOperationResult && $column.dictType && "" != $column.dictType)
|
||||
#set ($hasDict = 1)
|
||||
#end
|
||||
#end
|
||||
#if ($hasDict == 1)
|
||||
import { DICT_TYPE } from '@/utils/constants'
|
||||
#end
|
||||
#if ($hasDateTime == 1)
|
||||
import { formatDateTime } from '@/utils/date'
|
||||
#end
|
||||
import SearchForm from './components/search-form.vue'
|
||||
|
||||
definePage({
|
||||
style: {
|
||||
@ -112,8 +137,7 @@ definePage({
|
||||
const { hasAccessByCodes } = useAccess()
|
||||
const total = ref(0)
|
||||
const list = ref<${simpleClassName}[]>([])
|
||||
const loadMoreState = ref<LoadMoreState>('loading') // 加载更多状态
|
||||
|
||||
const loadMoreState = ref<LoadMoreState>('loading')
|
||||
const queryParams = reactive({
|
||||
pageNo: 1,
|
||||
pageSize: 10,
|
||||
@ -201,7 +225,7 @@ function handleAdd() {
|
||||
/** 查看详情 */
|
||||
function handleDetail(item: ${simpleClassName}) {
|
||||
uni.navigateTo({
|
||||
url: '/pages-${table.moduleName}/${table.businessName}/detail/index?id=' + item.${primaryColumn.javaField},
|
||||
url: `/pages-${table.moduleName}/${table.businessName}/detail/index?id=#[[${]]#item.${primaryColumn.javaField}#[[}]]#`,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user