index.vue.vm 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  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. #if ( $table.templateType == 2 )
  56. <el-col :span="1.5">
  57. <el-button type="danger" plain icon="el-icon-sort" size="mini" @click="toggleExpandAll">
  58. 展开/折叠
  59. </el-button>
  60. </el-col>
  61. #end
  62. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  63. </el-row>
  64. ## 特殊:主子表专属逻辑 TODO puhui999: 普通模式
  65. #if ( $table.templateType == 11 && $subTables && $subTables.size() > 0 )
  66. <el-table
  67. v-loading="loading"
  68. :data="list"
  69. :stripe="true"
  70. :highlight-current-row="true"
  71. :show-overflow-tooltip="true"
  72. @current-change="handleCurrentChange"
  73. >
  74. ## 特殊:树表专属逻辑
  75. #elseif ( $table.templateType == 2 )
  76. <el-table
  77. v-loading="loading"
  78. :data="list"
  79. :stripe="true"
  80. :show-overflow-tooltip="true"
  81. v-if="refreshTable"
  82. row-key="id"
  83. :default-expand-all="isExpandAll"
  84. :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
  85. >
  86. #else
  87. <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
  88. #end
  89. ## 特殊:主子表专属逻辑 TODO puhui999: 内嵌模式
  90. #if ( $table.templateType == 12 && $subTables && $subTables.size() > 0 )
  91. <!-- 子表的列表 -->
  92. <el-table-column type="expand">
  93. <template #default="scope">
  94. <el-tabs value="$subClassNameVars.get(0)">
  95. #foreach ($subTable in $subTables)
  96. #set ($index = $foreach.count - 1)
  97. #set ($subClassNameVar = $subClassNameVars.get($index))
  98. #set ($subSimpleClassName = $subSimpleClassNames.get($index))
  99. #set ($subJoinColumn_strikeCase = $subJoinColumn_strikeCases.get($index))
  100. <el-tab-pane label="${subTable.classComment}" name="$subClassNameVar">
  101. <${subSimpleClassName}List :${subJoinColumn_strikeCase}="scope.row.id" />
  102. </el-tab-pane>
  103. #end
  104. </el-tabs>
  105. </template>
  106. </el-table-column>
  107. #end
  108. #foreach($column in $columns)
  109. #if ($column.listOperationResult)
  110. #set ($dictType=$column.dictType)
  111. #set ($javaField = $column.javaField)
  112. #set ($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
  113. #set ($comment=$column.columnComment)
  114. #if ($column.javaType == "LocalDateTime")## 时间类型
  115. <el-table-column label="${comment}" align="center" prop="${javaField}" width="180">
  116. <template v-slot="scope">
  117. <span>{{ parseTime(scope.row.${javaField}) }}</span>
  118. </template>
  119. </el-table-column>
  120. #elseif("" != $column.dictType)## 数据字典
  121. <el-table-column label="${comment}" align="center" prop="${javaField}">
  122. <template v-slot="scope">
  123. <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.${column.javaField}" />
  124. </template>
  125. </el-table-column>
  126. #else
  127. <el-table-column label="${comment}" align="center" prop="${javaField}" />
  128. #end
  129. #end
  130. #end
  131. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  132. <template v-slot="scope">
  133. <el-button size="mini" type="text" icon="el-icon-edit" @click="openForm(scope.row.${primaryColumn.javaField})"
  134. v-hasPermi="['${permissionPrefix}:update']">修改</el-button>
  135. <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
  136. v-hasPermi="['${permissionPrefix}:delete']">删除</el-button>
  137. </template>
  138. </el-table-column>
  139. </el-table>
  140. <!-- 分页组件 -->
  141. <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
  142. @pagination="getList"/>
  143. <!-- 对话框(添加 / 修改) -->
  144. <${simpleClassName}Form ref="formRef" @success="getList" />
  145. ## 特殊:主子表专属逻辑 TODO puhui999: ERP 模式
  146. #if ( $table.templateType == 11 && $subTables && $subTables.size() > 0 )
  147. <!-- 子表的列表 -->
  148. <el-tabs model-value="$subClassNameVars.get(0)">
  149. #foreach ($subTable in $subTables)
  150. #set ($index = $foreach.count - 1)
  151. #set ($subClassNameVar = $subClassNameVars.get($index))
  152. #set ($subSimpleClassName = $subSimpleClassNames.get($index))
  153. #set ($subJoinColumn_strikeCase = $subJoinColumn_strikeCases.get($index))
  154. <el-tab-pane label="${subTable.classComment}" name="$subClassNameVar">
  155. <${subSimpleClassName}List :${subJoinColumn_strikeCase}="currentRow.id" />
  156. </el-tab-pane>
  157. #end
  158. </el-tabs>
  159. #end
  160. </div>
  161. </template>
  162. <script>
  163. import * as ${simpleClassName}Api from '@/api/${table.moduleName}/${table.businessName}';
  164. import ${simpleClassName}Form from './${simpleClassName}Form.vue';
  165. #if ($hasImageUploadColumn)
  166. import ImageUpload from '@/components/ImageUpload';
  167. #end
  168. #if ($hasFileUploadColumn)
  169. import FileUpload from '@/components/FileUpload';
  170. #end
  171. #if ($hasEditorColumn)
  172. import Editor from '@/components/Editor';
  173. #end
  174. ## 特殊:主子表专属逻辑
  175. #if ( $subTables && $subTables.size() > 0 )
  176. #foreach ($subSimpleClassName in $subSimpleClassNames)
  177. import ${subSimpleClassName}List from './components/${subSimpleClassName}List.vue'
  178. #end
  179. #end
  180. export default {
  181. name: "${simpleClassName}",
  182. components: {
  183. ${simpleClassName}Form,
  184. ## 特殊:主子表专属逻辑
  185. #if ( $subTables && $subTables.size() > 0 )
  186. #foreach ($subSimpleClassName in $subSimpleClassNames)
  187. ${subSimpleClassName}List,
  188. #end
  189. #end
  190. #if ($hasImageUploadColumn)
  191. ImageUpload,
  192. #end
  193. #if ($hasFileUploadColumn)
  194. FileUpload,
  195. #end
  196. #if ($hasEditorColumn)
  197. Editor,
  198. #end
  199. },
  200. data() {
  201. return {
  202. // 遮罩层
  203. loading: true,
  204. // 导出遮罩层
  205. exportLoading: false,
  206. // 显示搜索条件
  207. showSearch: true,
  208. // 总条数
  209. ## 特殊:树表专属逻辑(树不需要分页接口)
  210. #if ( $table.templateType != 2 )
  211. total: 0,
  212. #end
  213. // ${table.classComment}列表
  214. list: [],
  215. // 是否展开,默认全部展开
  216. isExpandAll: true,
  217. // 重新渲染表格状态
  218. refreshTable: true,
  219. // 选中行
  220. currentRow: {},
  221. // 查询参数
  222. queryParams: {
  223. ## 特殊:树表专属逻辑(树不需要分页接口)
  224. #if ( $table.templateType != 2 )
  225. pageNo: 1,
  226. pageSize: 10,
  227. #end
  228. #foreach ($column in $columns)
  229. #if ($column.listOperation)
  230. #if ($column.listOperationCondition != 'BETWEEN')
  231. $column.javaField: null,
  232. #end
  233. #if ($column.htmlType == "datetime" || $column.listOperationCondition == "BETWEEN")
  234. $column.javaField: [],
  235. #end
  236. #end
  237. #end
  238. }
  239. };
  240. },
  241. created() {
  242. this.getList();
  243. },
  244. methods: {
  245. /** 查询列表 */
  246. getList() {
  247. try {
  248. this.loading = true;
  249. ## 特殊:树表专属逻辑(树不需要分页接口)
  250. #if ( $table.templateType == 2 )
  251. ${simpleClassName}Api.get${simpleClassName}List(queryParams).then(response => {
  252. this.list = this.handleTree(response.data, 'id', '${treeParentColumn.javaField}');
  253. })
  254. #else
  255. ${simpleClassName}Api.get${simpleClassName}Page(this.queryParams).then(response => {
  256. this.list = response.data.list;
  257. this.total = response.data.total;
  258. });
  259. #end
  260. } finally {
  261. this.loading = false;
  262. }
  263. },
  264. /** 搜索按钮操作 */
  265. handleQuery() {
  266. this.queryParams.pageNo = 1;
  267. this.getList();
  268. },
  269. /** 重置按钮操作 */
  270. resetQuery() {
  271. this.resetForm("queryForm");
  272. this.handleQuery();
  273. },
  274. /** 添加/修改操作 */
  275. openForm(id) {
  276. this.#[[$]]#refs["formRef"].open(id)
  277. },
  278. /** 删除按钮操作 */
  279. handleDelete(row) {
  280. const that = this;
  281. try {
  282. const ${primaryColumn.javaField} = row.${primaryColumn.javaField};
  283. this.#[[$modal]]#.confirm('是否确认删除${table.classComment}编号为"' + ${primaryColumn.javaField} + '"的数据项?').then(()=>{
  284. return ${simpleClassName}Api.delete${simpleClassName}(${primaryColumn.javaField});
  285. }).then(() => {
  286. that.getList();
  287. that.#[[$modal]]#.msgSuccess("删除成功");
  288. }).catch(() => {});
  289. } catch {}
  290. },
  291. /** 导出按钮操作 */
  292. handleExport() {
  293. const that = this;
  294. try {
  295. this.#[[$modal]]#.confirm('是否确认导出所有${table.classComment}数据项?').then(() => {
  296. that.exportLoading = true;
  297. return ${simpleClassName}Api.export${simpleClassName}Excel(params);
  298. }).then(response => {
  299. that.#[[$]]#download.excel(response, '${table.classComment}.xls');
  300. }));
  301. } catch {
  302. } finally {
  303. that.exportLoading = false;
  304. }
  305. },
  306. ## 特殊:主子表专属逻辑
  307. #if ( $subTables && $subTables.size() > 0 )
  308. /** 选中行操作 */
  309. handleCurrentChange(row) {
  310. this.currentRow = row
  311. },
  312. #end
  313. ## 特殊:树表专属逻辑
  314. #if ( $table.templateType == 2 )
  315. /** 展开/折叠操作 */
  316. toggleExpandAll() {
  317. this.refreshTable = false
  318. this.isExpandAll = !this.isExpandAll
  319. this.$nextTick(function () {
  320. this.refreshTable = true
  321. })
  322. }
  323. #end
  324. }
  325. };
  326. </script>