utils.ftl 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. <#function dashedToCamel(str)>
  20. <#assign text=""/>
  21. <#assign strlist = str?split("_")/>
  22. <#list strlist as v>
  23. <#assign text=text+v?cap_first/>
  24. </#list>
  25. <#return text?uncap_first>
  26. </#function>
  27. <#-- 驼峰转下划线 -->
  28. <#function camelToDashed(str, case='normal')>
  29. <#return camelToChar(str, "_", case)>
  30. </#function>
  31. <#---->
  32. <#-- 驼峰转横线 -->
  33. <#function camelToHorizontal(str, case='normal')>
  34. <#return camelToChar(str, "-", case)>
  35. </#function>
  36. <#---->
  37. <#-- 获取 v-model 属性 -->
  38. <#function getVModel po,suffix="">
  39. <#return "v-model=\"queryParam.${po.fieldName}${suffix}\"">
  40. </#function>
  41. <#-- 获取 placeholder 属性 -->
  42. <#function getPlaceholder po,prefix,fillComment=true>
  43. <#if fillComment>
  44. <#return "placeholder=\"${prefix}${po.filedComment}\"">
  45. <#else>
  46. <#return "placeholder=\"${prefix}\"">
  47. </#if>
  48. </#function>
  49. <#-- ** 判断某字段是否配置了校验 * -->
  50. <#function poHasCheck po>
  51. <#if (po.fieldValidType!'')?trim?length gt 0 || po.nullable == 'N'>
  52. <#if po.fieldName != 'id'>
  53. <#if po.nullable == 'N'
  54. || po.fieldValidType == '*'
  55. || po.fieldValidType == 'only'
  56. || po.fieldValidType == 'n6-16'
  57. || po.fieldValidType == '*6-16'
  58. || po.fieldValidType == 's6-18'
  59. || po.fieldValidType == 'url'
  60. || po.fieldValidType == 'e'
  61. || po.fieldValidType == 'm'
  62. || po.fieldValidType == 'p'
  63. || po.fieldValidType == 's'
  64. || po.fieldValidType == 'n'
  65. || po.fieldValidType == 'z'
  66. || po.fieldValidType == 'money'
  67. || po.fieldValidType != ''
  68. >
  69. <#return true>
  70. </#if>
  71. </#if>
  72. </#if>
  73. <#return false>
  74. </#function>
  75. <#-- ** 如果配置了校验就显示 validatorRules * -->
  76. <#function autoWriteRules po>
  77. <#if poHasCheck(po)>
  78. <#return ", validatorRules.${po.fieldName}">
  79. <#else>
  80. <#return "">
  81. </#if>
  82. </#function>
  83. <#-- ** 如果Blob就显示 String * -->
  84. <#function autoStringSuffix po>
  85. <#if po.fieldDbType=='Blob'>
  86. <#return "'${po.fieldName}String'">
  87. <#else>
  88. <#return "'${po.fieldName}'">
  89. </#if>
  90. </#function>
  91. <#-- ** 如果Blob就显示model方式 String * -->
  92. <#function autoStringSuffixForModel po>
  93. <#if po.fieldDbType=='Blob'>
  94. <#return "${po.fieldName}String">
  95. <#else>
  96. <#return "${po.fieldName}">
  97. </#if>
  98. </#function>
  99. <#-- ** 高级查询生成 * -->
  100. <#function superQueryFieldList po>
  101. <#assign superQuery_dictTable="">
  102. <#assign superQuery_dictText="">
  103. <#if po.dictTable?default("")?trim?length gt 1>
  104. <#assign superQuery_dictTable="${po.dictTable}">
  105. </#if>
  106. <#if po.dictText?default("")?trim?length gt 1>
  107. <#assign superQuery_dictText="${po.dictText}">
  108. </#if>
  109. <#if po.classType=="popup">
  110. <#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]}'}}">
  111. <#elseif po.classType=="sel_user" || po.classType=="sel_depart" || po.classType=="datetime" || po.classType=="date" || po.classType=="pca" || po.classType=="switch">
  112. <#return "{type:'${po.classType}',value:'${po.fieldName}',text:'${po.filedComment}'}">
  113. <#else>
  114. <#if po.classType=="sel_search" || po.classType=="list_multi">
  115. <#return "{type:'${po.classType}',value:'${po.fieldName}',text:'${po.filedComment}',dictTable:\"${superQuery_dictTable}\", dictText:'${superQuery_dictText}', dictCode:'${po.dictField}'}">
  116. <#elseif po.dictTable?? && po.dictTable!="" && po.classType!="sel_tree" && po.classType!="cat_tree" && po.classType!="link_down">
  117. <#return "{type:'${po.fieldDbType}',value:'${po.fieldName}',text:'${po.filedComment}',dictCode:\"${po.dictTable},${po.dictText},${po.dictField}\"}">
  118. <#elseif po.dictField?? && po.classType!="sel_tree" && po.classType!="cat_tree" && po.classType!="link_down">
  119. <#return "{type:'${po.fieldDbType}',value:'${po.fieldName}',text:'${po.filedComment}',dictCode:'${po.dictField}'}">
  120. <#elseif po.fieldDbType=="Text">
  121. <#return "{type:'string',value:'${po.fieldName}',text:'${po.filedComment}'}">
  122. <#elseif po.fieldDbType=="Blob">
  123. <#return "{type:'byte',value:'${po.fieldName}',text:'${po.filedComment}'}">
  124. <#elseif po.fieldDbType=="BigDecimal" || po.fieldDbType=="double">
  125. <#return "{type:'number',value:'${po.fieldName}',text:'${po.filedComment}'}">
  126. <#else>
  127. <#return "{type:'${po.fieldDbType}',value:'${po.fieldName}',text:'${po.filedComment}'}">
  128. </#if>
  129. </#if>
  130. </#function>