index.vue.vm 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. <template>
  2. <div class="app-container">
  3. <!-- 搜索工作栏 -->
  4. <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
  5. #foreach($column in $columns)
  6. #if ($column.listOperation)
  7. #set ($dictType=$column.dictType)
  8. #set ($javaField = $column.javaField)
  9. #set ($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
  10. #set ($comment=$column.columnComment)
  11. #if ($column.htmlType == "input")
  12. <el-form-item label="${comment}" prop="${javaField}">
  13. <el-input v-model="queryParams.${javaField}" placeholder="请输入${comment}" clearable @keyup.enter.native="handleQuery"/>
  14. </el-form-item>
  15. #elseif ($column.htmlType == "select" || $column.htmlType == "radio")
  16. <el-form-item label="${comment}" prop="${javaField}">
  17. <el-select v-model="queryParams.${javaField}" placeholder="请选择${comment}" clearable size="small">
  18. #if ("" != $dictType)## 设置了 dictType 数据字典的情况
  19. <el-option v-for="dict in this.getDictDatas(DICT_TYPE.$dictType.toUpperCase())"
  20. :key="dict.value" :label="dict.label" :value="dict.value"/>
  21. #else## 未设置 dictType 数据字典的情况
  22. <el-option label="请选择字典生成" value="" />
  23. #end
  24. </el-select>
  25. </el-form-item>
  26. #elseif($column.htmlType == "datetime")
  27. #if ($column.listOperationCondition != "BETWEEN")## 非范围
  28. <el-form-item label="${comment}" prop="${javaField}">
  29. <el-date-picker clearable v-model="queryParams.${javaField}" type="date" value-format="yyyy-MM-dd" placeholder="选择${comment}" />
  30. </el-form-item>
  31. #else## 范围
  32. <el-form-item label="${comment}" prop="${javaField}">
  33. <el-date-picker v-model="queryParams.${javaField}" style="width: 240px" value-format="yyyy-MM-dd HH:mm:ss" type="daterange"
  34. range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="['00:00:00', '23:59:59']" />
  35. </el-form-item>
  36. #end
  37. #end
  38. #end
  39. #end
  40. <el-form-item>
  41. <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
  42. <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
  43. </el-form-item>
  44. </el-form>
  45. <!-- 操作工具栏 -->
  46. <el-row :gutter="10" class="mb8">
  47. <el-col :span="1.5">
  48. <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="openForm(undefined)"
  49. v-hasPermi="['${permissionPrefix}:create']">新增</el-button>
  50. </el-col>
  51. <el-col :span="1.5">
  52. <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" :loading="exportLoading"
  53. v-hasPermi="['${permissionPrefix}:export']">导出</el-button>
  54. </el-col>
  55. ## 特殊:树表专属逻辑
  56. #if ( $table.templateType == 2 )
  57. <el-col :span="1.5">
  58. <el-button type="danger" plain icon="el-icon-sort" size="mini" @click="toggleExpandAll">
  59. 展开/折叠
  60. </el-button>
  61. </el-col>
  62. #end
  63. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  64. </el-row>
  65. ## 特殊:主子表专属逻辑
  66. #if ( $table.templateType == 11 && $subTables && $subTables.size() > 0 )
  67. <el-table
  68. v-loading="loading"
  69. :data="list"
  70. :stripe="true"
  71. :highlight-current-row="true"
  72. :show-overflow-tooltip="true"
  73. @current-change="handleCurrentChange"
  74. >
  75. ## 特殊:树表专属逻辑
  76. #elseif ( $table.templateType == 2 )
  77. <el-table
  78. v-loading="loading"
  79. :data="list"
  80. :stripe="true"
  81. :show-overflow-tooltip="true"
  82. v-if="refreshTable"
  83. row-key="id"
  84. :default-expand-all="isExpandAll"
  85. :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
  86. >
  87. #else
  88. <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
  89. #end
  90. ## 特殊:主子表专属逻辑
  91. #if ( $table.templateType == 12 && $subTables && $subTables.size() > 0 )
  92. <!-- 子表的列表 -->
  93. <el-table-column type="expand">
  94. <template #default="scope">
  95. <el-tabs value="$subClassNameVars.get(0)">
  96. #foreach ($subTable in $subTables)
  97. #set ($index = $foreach.count - 1)
  98. #set ($subClassNameVar = $subClassNameVars.get($index))
  99. #set ($subSimpleClassName = $subSimpleClassNames.get($index))
  100. #set ($subJoinColumn_strikeCase = $subJoinColumn_strikeCases.get($index))
  101. <el-tab-pane label="${subTable.classComment}" name="$subClassNameVar">
  102. <${subSimpleClassName}List :${subJoinColumn_strikeCase}="scope.row.id" />
  103. </el-tab-pane>
  104. #end
  105. </el-tabs>
  106. </template>
  107. </el-table-column>
  108. #end
  109. #foreach($column in $columns)
  110. #if ($column.listOperationResult)
  111. #set ($dictType=$column.dictType)
  112. #set ($javaField = $column.javaField)
  113. #set ($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
  114. #set ($comment=$column.columnComment)
  115. #if ($column.javaType == "LocalDateTime")## 时间类型
  116. <el-table-column label="${comment}" align="center" prop="${javaField}" width="180">
  117. <template v-slot="scope">
  118. <span>{{ parseTime(scope.row.${javaField}) }}</span>
  119. </template>
  120. </el-table-column>
  121. #elseif("" != $column.dictType)## 数据字典
  122. <el-table-column label="${comment}" align="center" prop="${javaField}">
  123. <template v-slot="scope">
  124. <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.${column.javaField}" />
  125. </template>
  126. </el-table-column>
  127. #else
  128. <el-table-column label="${comment}" align="center" prop="${javaField}" />
  129. #end
  130. #end
  131. #end
  132. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  133. <template v-slot="scope">
  134. <el-button size="mini" type="text" icon="el-icon-edit" @click="openForm(scope.row.${primaryColumn.javaField})"
  135. v-hasPermi="['${permissionPrefix}:update']">修改</el-button>
  136. <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
  137. v-hasPermi="['${permissionPrefix}:delete']">删除</el-button>
  138. </template>
  139. </el-table-column>
  140. </el-table>
  141. ## 特殊:树表专属逻辑(树不需要分页)
  142. #if ( $table.templateType != 2 )
  143. <!-- 分页组件 -->
  144. <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
  145. @pagination="getList"/>
  146. #end
  147. <!-- 对话框(添加 / 修改) -->
  148. <${simpleClassName}Form ref="formRef" @success="getList" />
  149. ## 特殊:主子表专属逻辑
  150. #if ( $table.templateType == 11 && $subTables && $subTables.size() > 0 )
  151. <!-- 子表的列表 -->
  152. <el-tabs v-model="subTabsName">
  153. #foreach ($subTable in $subTables)
  154. #set ($index = $foreach.count - 1)
  155. #set ($subClassNameVar = $subClassNameVars.get($index))
  156. #set ($subSimpleClassName = $subSimpleClassNames.get($index))
  157. #set ($subJoinColumn_strikeCase = $subJoinColumn_strikeCases.get($index))
  158. <el-tab-pane label="${subTable.classComment}" name="$subClassNameVar">
  159. <${subSimpleClassName}List v-if="currentRow.id" :${subJoinColumn_strikeCase}="currentRow.id" />
  160. </el-tab-pane>
  161. #end
  162. </el-tabs>
  163. #end
  164. </div>
  165. </template>
  166. <script>
  167. import * as ${simpleClassName}Api from '@/api/${table.moduleName}/${table.businessName}';
  168. import ${simpleClassName}Form from './${simpleClassName}Form.vue';
  169. #if ($hasImageUploadColumn)
  170. import ImageUpload from '@/components/ImageUpload';
  171. #end
  172. #if ($hasFileUploadColumn)
  173. import FileUpload from '@/components/FileUpload';
  174. #end
  175. #if ($hasEditorColumn)
  176. import Editor from '@/components/Editor';
  177. #end
  178. ## 特殊:主子表专属逻辑
  179. #if ( $table.templateType != 10 )
  180. #if ( $subTables && $subTables.size() > 0 )
  181. #foreach ($subSimpleClassName in $subSimpleClassNames)
  182. import ${subSimpleClassName}List from './components/${subSimpleClassName}List.vue';
  183. #end
  184. #end
  185. #end
  186. export default {
  187. name: "${simpleClassName}",
  188. components: {
  189. ${simpleClassName}Form,
  190. ## 特殊:主子表专属逻辑
  191. #if ( $table.templateType != 10 )
  192. #if ( $subTables && $subTables.size() > 0 )
  193. #foreach ($subSimpleClassName in $subSimpleClassNames)
  194. ${subSimpleClassName}List,
  195. #end
  196. #end
  197. #end
  198. #if ($hasImageUploadColumn)
  199. ImageUpload,
  200. #end
  201. #if ($hasFileUploadColumn)
  202. FileUpload,
  203. #end
  204. #if ($hasEditorColumn)
  205. Editor,
  206. #end
  207. },
  208. data() {
  209. return {
  210. // 遮罩层
  211. loading: true,
  212. // 导出遮罩层
  213. exportLoading: false,
  214. // 显示搜索条件
  215. showSearch: true,
  216. ## 特殊:树表专属逻辑(树不需要分页接口)
  217. #if ( $table.templateType != 2 )
  218. // 总条数
  219. total: 0,
  220. #end
  221. // ${table.classComment}列表
  222. list: [],
  223. // 是否展开,默认全部展开
  224. isExpandAll: true,
  225. // 重新渲染表格状态
  226. refreshTable: true,
  227. // 选中行
  228. currentRow: {},
  229. // 查询参数
  230. queryParams: {
  231. ## 特殊:树表专属逻辑(树不需要分页接口)
  232. #if ( $table.templateType != 2 )
  233. pageNo: 1,
  234. pageSize: 10,
  235. #end
  236. #foreach ($column in $columns)
  237. #if ($column.listOperation)
  238. #if ($column.listOperationCondition != 'BETWEEN')
  239. $column.javaField: null,
  240. #end
  241. #if ($column.htmlType == "datetime" && $column.listOperationCondition == "BETWEEN")
  242. $column.javaField: [],
  243. #end
  244. #end
  245. #end
  246. },
  247. ## 特殊:主子表专属逻辑-erp
  248. #if ( $table.templateType == 11)
  249. #if ( $subTables && $subTables.size() > 0 )
  250. /** 子表的列表 */
  251. subTabsName: '$subClassNameVars.get(0)'
  252. #end
  253. #end
  254. };
  255. },
  256. created() {
  257. this.getList();
  258. },
  259. methods: {
  260. /** 查询列表 */
  261. async getList() {
  262. try {
  263. this.loading = true;
  264. ## 特殊:树表专属逻辑(树不需要分页接口)
  265. #if ( $table.templateType == 2 )
  266. const res = await ${simpleClassName}Api.get${simpleClassName}List(this.queryParams);
  267. this.list = this.handleTree(res.data, 'id', '${treeParentColumn.javaField}');
  268. #else
  269. const res = await ${simpleClassName}Api.get${simpleClassName}Page(this.queryParams);
  270. this.list = res.data.list;
  271. this.total = res.data.total;
  272. #end
  273. } finally {
  274. this.loading = false;
  275. }
  276. },
  277. /** 搜索按钮操作 */
  278. handleQuery() {
  279. this.queryParams.pageNo = 1;
  280. this.getList();
  281. },
  282. /** 重置按钮操作 */
  283. resetQuery() {
  284. this.resetForm("queryForm");
  285. this.handleQuery();
  286. },
  287. /** 添加/修改操作 */
  288. openForm(id) {
  289. this.#[[$]]#refs["formRef"].open(id);
  290. },
  291. /** 删除按钮操作 */
  292. async handleDelete(row) {
  293. const ${primaryColumn.javaField} = row.${primaryColumn.javaField};
  294. await this.#[[$modal]]#.confirm('是否确认删除${table.classComment}编号为"' + ${primaryColumn.javaField} + '"的数据项?')
  295. try {
  296. await ${simpleClassName}Api.delete${simpleClassName}(${primaryColumn.javaField});
  297. await this.getList();
  298. this.#[[$modal]]#.msgSuccess("删除成功");
  299. } catch {}
  300. },
  301. /** 导出按钮操作 */
  302. async handleExport() {
  303. await this.#[[$modal]]#.confirm('是否确认导出所有${table.classComment}数据项?');
  304. try {
  305. this.exportLoading = true;
  306. const data = await ${simpleClassName}Api.export${simpleClassName}Excel(this.queryParams);
  307. this.#[[$]]#download.excel(data, '${table.classComment}.xls');
  308. } catch {
  309. } finally {
  310. this.exportLoading = false;
  311. }
  312. },
  313. ## 特殊:主子表专属逻辑
  314. #if ( $table.templateType == 11 )
  315. /** 选中行操作 */
  316. handleCurrentChange(row) {
  317. this.currentRow = row;
  318. #if ( $subTables && $subTables.size() > 0 )
  319. /** 子表的列表 */
  320. this.subTabsName = '$subClassNameVars.get(0)';
  321. #end
  322. },
  323. #end
  324. ## 特殊:树表专属逻辑
  325. #if ( $table.templateType == 2 )
  326. /** 展开/折叠操作 */
  327. toggleExpandAll() {
  328. this.refreshTable = false
  329. this.isExpandAll = !this.isExpandAll
  330. this.$nextTick(function () {
  331. this.refreshTable = true
  332. })
  333. }
  334. #end
  335. }
  336. };
  337. </script>