index.vue.vm 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. <template>
  2. <div class="app-container">
  3. <ProTable
  4. ref="proTableRef"
  5. :api="tableApi"
  6. :columns="columns"
  7. :searchFields="searchFields"
  8. :initialSearchParams="initialSearchParams"
  9. :exportConfig="exportConfig"
  10. #if($tplCategory == 'tree')
  11. :isTreeTable="true"
  12. #end
  13. rowKey="${pkColumn.javaField}"
  14. >
  15. <!-- 自定义操作按钮 -->
  16. <template #actions="{ selectedRowKeys, selectedRows }">
  17. #set($isInsert=0)
  18. #set($isEdit=0)
  19. #foreach($column in $columns)
  20. #if($column.insert)
  21. #set($isInsert=1)
  22. #end
  23. #if($column.edit)
  24. #set($isEdit=1)
  25. #end
  26. #end
  27. #if($isInsert == 1)
  28. <a-button type="primary" @click="handleAdd" v-hasPermi="['${moduleName}:${businessName}:add']">
  29. <BearJiaIcon icon="plus-outlined" />
  30. 新增
  31. </a-button>
  32. #end
  33. #if($isEdit == 1)
  34. <a-button
  35. type="primary"
  36. :disabled="selectedRowKeys.length !== 1"
  37. @click="handleEdit(selectedRows[0])"
  38. v-hasPermi="['${moduleName}:${businessName}:edit']"
  39. >
  40. <BearJiaIcon icon="edit-outlined" />
  41. 修改
  42. </a-button>
  43. #end
  44. <a-button
  45. type="primary"
  46. danger
  47. :disabled="selectedRowKeys.length === 0"
  48. @click="handleDelete(selectedRowKeys)"
  49. v-hasPermi="['${moduleName}:${businessName}:remove']"
  50. >
  51. <BearJiaIcon icon="delete-outlined" />
  52. 删除
  53. </a-button>
  54. </template>
  55. <!-- 自定义列渲染 -->
  56. <template #bodyCell="{ column, record }">
  57. #foreach($column in $columns)
  58. #set($javaField=$column.javaField)
  59. #if($column.list && $column.htmlType == "datetime")
  60. <template v-if="column.dataIndex === '${javaField}'">
  61. {{ BearJiaUtil.formatTime(record.${javaField}) }}
  62. </template>
  63. #elseif($column.list && "" != $column.dictType)
  64. <template v-if="column.dataIndex === '${javaField}'">
  65. <dict-tag :options="${column.javaField}Options" :value="record.${javaField}" />
  66. </template>
  67. #end
  68. #end
  69. <!-- 操作列 -->
  70. <template v-if="column.dataIndex === 'action'">
  71. <TableActionBar
  72. :hasDelete="false"
  73. :hasEdit="true"
  74. :hasView="true"
  75. :record="record"
  76. @edit="handleEdit"
  77. @view="handleView"/>
  78. </template>
  79. </template>
  80. </ProTable>
  81. #if($isInsert == 1 || $isEdit == 1)
  82. <!-- 新增/编辑弹窗 -->
  83. <AddUpdateModal
  84. ref="addUpdateModalRef"
  85. #foreach ($column in $columns)
  86. #if(${column.dictType} != '')
  87. :${column.javaField}Options="${column.javaField}Options"
  88. #end
  89. #end
  90. #if($tplCategory == 'tree')
  91. :${businessName}Options="${businessName}Options"
  92. #end
  93. @success="refreshTable"
  94. />
  95. #end
  96. <!-- 详情弹窗 -->
  97. <DetailModal ref="detailModalRef" />
  98. </div>
  99. </template>
  100. <script setup>
  101. import { getCurrentInstance, ref, computed } from 'vue';
  102. import { message } from 'ant-design-vue';
  103. import ProTable from '@/components/BearJiaProTable/index.vue';
  104. import TableActionBar from '@/components/TableActionBar/index.vue';
  105. import { BearJiaIcon } from '@/utils/BearJiaIcon.js';
  106. import BearJiaUtil from '@/utils/BearJiaUtil.js';
  107. #if($isInsert == 1 || $isEdit == 1)
  108. import AddUpdateModal from './addUpdateModal.vue';
  109. #end
  110. import DetailModal from './detailModal.vue';
  111. import { list${BusinessName}, del${BusinessName} } from '@/api/${moduleName}/${businessName}';
  112. // 获取当前实例
  113. const { proxy } = getCurrentInstance();
  114. // 字典数据
  115. #if(${dicts} != '')
  116. const { ${dicts} } = proxy.useDict(${dicts});
  117. #end
  118. #foreach ($column in $columns)
  119. #if(${column.dictType} != '')
  120. const ${column.javaField}Options = ref(${column.javaField});
  121. #end
  122. #end
  123. // 组件引用
  124. const proTableRef = ref();
  125. const addUpdateModalRef = ref();
  126. const detailModalRef = ref();
  127. #if($tplCategory == 'tree')
  128. // 树形数据选项
  129. const ${businessName}Options = ref([]);
  130. #end
  131. // 表格API配置
  132. const tableApi = {
  133. list: list${BusinessName},
  134. delete: del${BusinessName},
  135. #if($tplCategory == 'tree')
  136. processListData: (data) => {
  137. return BearJiaUtil.handleTree(data, '${treeCode}', '${treeParentCode}', 'children');
  138. }
  139. #end
  140. };
  141. // 初始搜索参数
  142. const initialSearchParams = {
  143. #foreach($column in $columns)
  144. #if($column.query)
  145. ${column.javaField}: null,
  146. #end
  147. #end
  148. };
  149. // 导出配置
  150. const exportConfig = {
  151. url: '${moduleName}/${businessName}/export',
  152. fileName: '${functionName}数据'
  153. };
  154. // 搜索字段配置
  155. const searchFields = computed(() => [
  156. #foreach($column in $columns)
  157. #if($column.query)
  158. #set($dictType=$column.dictType)
  159. #set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
  160. #set($parentheseIndex=$column.columnComment.indexOf("("))
  161. #if($parentheseIndex != -1)
  162. #set($comment=$column.columnComment.substring(0, $parentheseIndex))
  163. #else
  164. #set($comment=$column.columnComment)
  165. #end
  166. #if($column.htmlType == "input")
  167. {name: '${column.javaField}', label: '${comment}', type: 'input'},
  168. #elseif(($column.htmlType == "select" || $column.htmlType == "radio") && "" != $dictType)
  169. {name: '${column.javaField}', label: '${comment}', type: 'select', options: ${column.javaField}.value},
  170. #elseif($column.htmlType == "datetime" && $column.queryType != "BETWEEN")
  171. {name: '${column.javaField}', label: '${comment}', type: 'date'},
  172. {name: '${column.javaField}', label: '${comment}', type: 'daterange'},
  173. #end
  174. #end
  175. #end
  176. ]);
  177. // 表格列配置
  178. const columns = [
  179. #foreach($column in $columns)
  180. #set($javaField=$column.javaField)
  181. #set($parentheseIndex=$column.columnComment.indexOf("("))
  182. #if($parentheseIndex != -1)
  183. #set($comment=$column.columnComment.substring(0, $parentheseIndex))
  184. #else
  185. #set($comment=$column.columnComment)
  186. #end
  187. #if($column.list)
  188. {
  189. title: '${comment}',
  190. dataIndex: '${javaField}',
  191. key: '${javaField}',
  192. #if($column.pk)
  193. width: 80,
  194. #end
  195. align: 'center',
  196. ellipsis: true
  197. },
  198. #end
  199. #end
  200. {
  201. title: '操作',
  202. dataIndex: 'action',
  203. key: 'action',
  204. width: 200,
  205. align: 'center',
  206. fixed: 'right'
  207. }
  208. ];
  209. // 新增
  210. const handleAdd = () => {
  211. #if($isInsert == 1)
  212. addUpdateModalRef.value.open('add');
  213. #end
  214. };
  215. // 编辑
  216. const handleEdit = (record) => {
  217. #if($isEdit == 1)
  218. addUpdateModalRef.value.open('edit', record);
  219. #end
  220. };
  221. #if($tplCategory == 'tree' && $isInsert == 1)
  222. // 新增下级
  223. const handleAddChild = (record) => {
  224. addUpdateModalRef.value.open('add', { ${treeParentCode}: record.${treeCode} });
  225. };
  226. #end
  227. // 查看详情
  228. const handleView = (record) => {
  229. detailModalRef.value.open(record);
  230. };
  231. // 删除
  232. const handleDelete = async (ids) => {
  233. try {
  234. await del${BusinessName}(ids.join(','));
  235. message.success('删除成功');
  236. refreshTable();
  237. } catch (error) {
  238. console.error('删除失败:', error);
  239. }
  240. };
  241. // 刷新表格
  242. const refreshTable = () => {
  243. proTableRef.value.reload();
  244. };
  245. #if($tplCategory == 'tree')
  246. // 获取树形选择数据
  247. const getTreeSelect = async () => {
  248. try {
  249. const response = await list${BusinessName}();
  250. const treeData = BearJiaUtil.handleTree(response.data || response, '${treeCode}', '${treeParentCode}', 'children');
  251. ${businessName}Options.value = [
  252. {
  253. ${treeCode}: 0,
  254. ${treeName}: '顶级节点',
  255. children: treeData
  256. }
  257. ];
  258. } catch (error) {
  259. console.error('获取树形数据失败:', error);
  260. }
  261. };
  262. // 初始化时获取树形数据
  263. getTreeSelect();
  264. #end
  265. </script>
  266. <style lang="less" scoped>
  267. .app-container {
  268. padding: 16px;
  269. }
  270. </style>