utils.ftl 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <#---->
  2. <#-- freemarker 的一些工具方法 -->
  3. <#---->
  4. <#-- 驼峰转其他字符 -->
  5. <#-- @param str 待转换的文本 -->
  6. <#-- @param character 要转换成的字符 -->
  7. <#-- @param case 转换大小写(normal 不转换,lower 小写,upper 大写) -->
  8. <#function camelToChar(str, character, case='normal')>
  9. <#assign text=str?replace("([a-z])([A-Z]+)","$1${character}$2","r")/>
  10. <#if case=="upper">
  11. <#return text?upper_case>
  12. <#elseif case=="lower">
  13. <#return text?lower_case>
  14. <#else>
  15. <#return text>
  16. </#if>
  17. </#function>
  18. <#---->
  19. <#-- 驼峰转下划线 -->
  20. <#function camelToDashed(str, case='normal')>
  21. <#return camelToChar(str, "_", case)>
  22. </#function>
  23. <#---->
  24. <#-- 驼峰转横线 -->
  25. <#function camelToHorizontal(str, case='normal')>
  26. <#return camelToChar(str, "-", case)>
  27. </#function>
  28. <#---->
  29. <#-- 获取 v-model 属性 -->
  30. <#function getVModel po,suffix="">
  31. <#return "v-model=\"queryParam.${po.fieldName}${suffix}\"">
  32. </#function>
  33. <#-- 获取 placeholder 属性 -->
  34. <#function getPlaceholder po,prefix,fillComment=true>
  35. <#if fillComment>
  36. <#return "placeholder=\"${prefix}${po.filedComment}\"">
  37. <#else>
  38. <#return "placeholder=\"${prefix}\"">
  39. </#if>
  40. </#function>
  41. <#-- ** 判断某字段是否配置了校验 * -->
  42. <#function poHasCheck po>
  43. <#if (po.fieldValidType!'')?trim?length gt 0 || po.nullable == 'N'>
  44. <#if po.fieldName != 'id'>
  45. <#if po.nullable == 'N'
  46. || po.fieldValidType == '*'
  47. || po.fieldValidType == 'only'
  48. || po.fieldValidType == 'n6-16'
  49. || po.fieldValidType == '*6-16'
  50. || po.fieldValidType == 's6-18'
  51. || po.fieldValidType == 'url'
  52. || po.fieldValidType == 'e'
  53. || po.fieldValidType == 'm'
  54. || po.fieldValidType == 'p'
  55. || po.fieldValidType == 's'
  56. || po.fieldValidType == 'n'
  57. || po.fieldValidType == 'z'
  58. || po.fieldValidType == 'money'
  59. || po.fieldValidType != ''
  60. >
  61. <#return true>
  62. </#if>
  63. </#if>
  64. <#elseif po.defaultVal??>
  65. <#return true>
  66. </#if>
  67. <#return false>
  68. </#function>
  69. <#-- ** 如果配置了校验就显示 validatorRules * -->
  70. <#function autoWriteRules po>
  71. <#if poHasCheck(po)>
  72. <#return ", validatorRules.${po.fieldName}">
  73. <#else>
  74. <#return "">
  75. </#if>
  76. </#function>
  77. <#-- ** 如果Blob就显示 String * -->
  78. <#function autoStringSuffix po>
  79. <#if po.fieldDbType=='Blob'>
  80. <#return "'${po.fieldName}String'">
  81. <#else>
  82. <#return "'${po.fieldName}'">
  83. </#if>
  84. </#function>
  85. <#-- ** 高级查询生成 * -->
  86. <#function superQueryFieldList po>
  87. <#assign superQuery_dictTable="">
  88. <#assign superQuery_dictText="">
  89. <#if po.dictTable?default("")?trim?length gt 1>
  90. <#assign superQuery_dictTable="${po.dictTable}">
  91. </#if>
  92. <#if po.dictText?default("")?trim?length gt 1>
  93. <#assign superQuery_dictText="${po.dictText}">
  94. </#if>
  95. <#if po.classType=="popup">
  96. <#return "{type:'${po.classType}',value:'${po.fieldName}',text:'${po.filedComment}', popup:{code:'${po.dictTable}',field:'${po.dictField?split(',')[0]}',orgFields:'${po.dictField?split(',')[0]}',destFields:'${po.dictText?split(',')[0]}'}}">
  97. <#elseif po.classType=="sel_user" || po.classType=="sel_depart" || po.classType=="datetime" || po.classType=="date" || po.classType=="pca" || po.classType=="switch">
  98. <#return "{type:'${po.classType}',value:'${po.fieldName}',text:'${po.filedComment}'}">
  99. <#else>
  100. <#if po.classType=="sel_search" || po.classType=="list_multi">
  101. <#return "{type:'${po.classType}',value:'${po.fieldName}',text:'${po.filedComment}',dictTable:'${superQuery_dictTable}', dictText:'${superQuery_dictText}', dictCode:'${po.dictField}'}">
  102. <#elseif po.dictTable?? && po.dictTable!="" && po.classType!="sel_tree" && po.classType!="cat_tree" && po.classType!="link_down">
  103. <#return "{type:'${po.fieldDbType}',value:'${po.fieldName}',text:'${po.filedComment}',dictCode:'${po.dictTable},${po.dictText},${po.dictField}'}">
  104. <#elseif po.dictField?? && po.classType!="sel_tree" && po.classType!="cat_tree" && po.classType!="link_down">
  105. <#return "{type:'${po.fieldDbType}',value:'${po.fieldName}',text:'${po.filedComment}',dictCode:'${po.dictField}'}">
  106. <#elseif po.fieldDbType=="Text">
  107. <#return "{type:'string',value:'${po.fieldName}',text:'${po.filedComment}'}">
  108. <#elseif po.fieldDbType=="Blob">
  109. <#return "{type:'byte',value:'${po.fieldName}',text:'${po.filedComment}'}">
  110. <#elseif po.fieldDbType=="BigDecimal" || po.fieldDbType=="double">
  111. <#return "{type:'number',value:'${po.fieldName}',text:'${po.filedComment}'}">
  112. <#else>
  113. <#return "{type:'${po.fieldDbType}',value:'${po.fieldName}',text:'${po.filedComment}'}">
  114. </#if>
  115. </#if>
  116. </#function>