index-tree.vue.vm 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
  4. #foreach($column in $columns)
  5. #if($column.query)
  6. #set($dictType=$column.dictType)
  7. #set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
  8. #set($parentheseIndex=$column.columnComment.indexOf("("))
  9. #if($parentheseIndex != -1)
  10. #set($comment=$column.columnComment.substring(0, $parentheseIndex))
  11. #else
  12. #set($comment=$column.columnComment)
  13. #end
  14. #if($column.htmlType == "input")
  15. <el-form-item label="${comment}" prop="${column.javaField}">
  16. <el-input
  17. v-model="queryParams.${column.javaField}"
  18. placeholder="请输入${comment}"
  19. clearable
  20. size="small"
  21. @keyup.enter.native="handleQuery"
  22. />
  23. </el-form-item>
  24. #elseif(($column.htmlType == "select" || $column.htmlType == "radio") && "" != $dictType)
  25. <el-form-item label="${comment}" prop="${column.javaField}">
  26. <el-select v-model="queryParams.${column.javaField}" placeholder="请选择${comment}" clearable size="small">
  27. <el-option
  28. v-for="dict in ${column.javaField}Options"
  29. :key="dict.dictValue"
  30. :label="dict.dictLabel"
  31. :value="dict.dictValue"
  32. />
  33. </el-select>
  34. </el-form-item>
  35. #elseif(($column.htmlType == "select" || $column.htmlType == "radio") && $dictType)
  36. <el-form-item label="${comment}" prop="${column.javaField}">
  37. <el-select v-model="queryParams.${column.javaField}" placeholder="请选择${comment}" clearable size="small">
  38. <el-option label="请选择字典生成" value="" />
  39. </el-select>
  40. </el-form-item>
  41. #elseif($column.htmlType == "datetime")
  42. <el-form-item label="${comment}" prop="${column.javaField}">
  43. <el-date-picker clearable size="small" style="width: 200px"
  44. v-model="queryParams.${column.javaField}"
  45. type="date"
  46. value-format="yyyy-MM-dd"
  47. placeholder="选择${comment}">
  48. </el-date-picker>
  49. </el-form-item>
  50. #end
  51. #end
  52. #end
  53. <el-form-item>
  54. <el-button
  55. class="filter-item"
  56. type="primary"
  57. icon="el-icon-search"
  58. size="mini"
  59. @click="handleQuery"
  60. >搜索</el-button>
  61. <el-button
  62. class="filter-item"
  63. type="primary"
  64. icon="el-icon-plus"
  65. size="mini"
  66. @click="handleAdd"
  67. v-hasPermi="['${moduleName}:${businessName}:add']"
  68. >新增</el-button>
  69. </el-form-item>
  70. </el-form>
  71. <el-table
  72. v-loading="loading"
  73. :data="${businessName}List"
  74. row-key="${treeCode}"
  75. default-expand-all
  76. :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
  77. >
  78. #foreach($column in $columns)
  79. #set($javaField=$column.javaField)
  80. #set($parentheseIndex=$column.columnComment.indexOf("("))
  81. #if($parentheseIndex != -1)
  82. #set($comment=$column.columnComment.substring(0, $parentheseIndex))
  83. #else
  84. #set($comment=$column.columnComment)
  85. #end
  86. #if($column.pk)
  87. #elseif($column.list && $column.htmlType == "datetime")
  88. <el-table-column label="${comment}" align="center" prop="${javaField}" width="180">
  89. <template slot-scope="scope">
  90. <span>{{ parseTime(scope.row.${javaField}, '{y}-{m}-{d}') }}</span>
  91. </template>
  92. </el-table-column>
  93. #elseif($column.list && "" != $column.dictType)
  94. <el-table-column label="${comment}" align="center" prop="${javaField}" :formatter="${javaField}Format" />
  95. #elseif($column.list && "" != $javaField)
  96. <el-table-column label="${comment}" align="center" prop="${javaField}" />
  97. #end
  98. #end
  99. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  100. <template slot-scope="scope">
  101. <el-button
  102. size="mini"
  103. type="text"
  104. icon="el-icon-edit"
  105. @click="handleUpdate(scope.row)"
  106. v-hasPermi="['${moduleName}:${businessName}:edit']"
  107. >修改</el-button>
  108. <el-button
  109. size="mini"
  110. type="text"
  111. icon="el-icon-delete"
  112. @click="handleDelete(scope.row)"
  113. v-hasPermi="['${moduleName}:${businessName}:remove']"
  114. >删除</el-button>
  115. </template>
  116. </el-table-column>
  117. </el-table>
  118. <!-- 添加或修改${functionName}对话框 -->
  119. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  120. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  121. #foreach($column in $columns)
  122. #set($field=$column.javaField)
  123. #if($column.insert && !$column.pk)
  124. #if(($column.usableColumn) || (!$column.superColumn))
  125. #set($parentheseIndex=$column.columnComment.indexOf("("))
  126. #if($parentheseIndex != -1)
  127. #set($comment=$column.columnComment.substring(0, $parentheseIndex))
  128. #else
  129. #set($comment=$column.columnComment)
  130. #end
  131. #set($dictType=$column.dictType)
  132. #if("" != $treeParentCode && $column.javaField == $treeParentCode)
  133. <el-form-item label="${comment}" prop="${treeParentCode}">
  134. <treeselect v-model="form.${treeParentCode}" :options="${businessName}Options" :normalizer="normalizer" placeholder="请选择${comment}" />
  135. </el-form-item>
  136. #elseif($column.htmlType == "input")
  137. <el-form-item label="${comment}" prop="${field}">
  138. <el-input v-model="form.${field}" placeholder="请输入${comment}" />
  139. </el-form-item>
  140. #elseif($column.htmlType == "select" && "" != $dictType)
  141. <el-form-item label="${comment}">
  142. <el-select v-model="form.${field}" placeholder="请选择${comment}">
  143. <el-option
  144. v-for="dict in ${field}Options"
  145. :key="dict.dictValue"
  146. :label="dict.dictLabel"
  147. #if($column.javaType == "Integer" || $column.javaType == "Long"):value="parseInt(dict.dictValue)"#else:value="dict.dictValue"#end
  148. ></el-option>
  149. </el-select>
  150. </el-form-item>
  151. #elseif($column.htmlType == "select" && $dictType)
  152. <el-form-item label="${comment}">
  153. <el-select v-model="form.${field}" placeholder="请选择${comment}">
  154. <el-option label="请选择字典生成" value="" />
  155. </el-select>
  156. </el-form-item>
  157. #elseif($column.htmlType == "checkbox" && "" != $dictType)
  158. <el-form-item label="${comment}">
  159. <el-checkbox-group v-model="form.${field}">
  160. <el-checkbox
  161. v-for="dict in ${field}Options"
  162. :key="dict.dictValue"
  163. :label="dict.dictValue">
  164. {{dict.dictLabel}}
  165. </el-checkbox>
  166. </el-checkbox-group>
  167. </el-form-item>
  168. #elseif($column.htmlType == "checkbox" && $dictType)
  169. <el-form-item label="${comment}">
  170. <el-checkbox-group v-model="form.${field}">
  171. <el-checkbox>请选择字典生成</el-checkbox>
  172. </el-checkbox-group>
  173. </el-form-item>
  174. #elseif($column.htmlType == "radio" && "" != $dictType)
  175. <el-form-item label="${comment}">
  176. <el-radio-group v-model="form.${field}">
  177. <el-radio
  178. v-for="dict in ${field}Options"
  179. :key="dict.dictValue"
  180. #if($column.javaType == "Integer" || $column.javaType == "Long"):label="parseInt(dict.dictValue)"#else:label="dict.dictValue"#end
  181. >{{dict.dictLabel}}</el-radio>
  182. </el-radio-group>
  183. </el-form-item>
  184. #elseif($column.htmlType == "radio" && $dictType)
  185. <el-form-item label="${comment}">
  186. <el-radio-group v-model="form.${field}">
  187. <el-radio label="1">请选择字典生成</el-radio>
  188. </el-radio-group>
  189. </el-form-item>
  190. #elseif($column.htmlType == "datetime")
  191. <el-form-item label="${comment}" prop="${field}">
  192. <el-date-picker clearable size="small" style="width: 200px"
  193. v-model="form.${field}"
  194. type="date"
  195. value-format="yyyy-MM-dd"
  196. placeholder="选择${comment}">
  197. </el-date-picker>
  198. </el-form-item>
  199. #elseif($column.htmlType == "textarea")
  200. <el-form-item label="${comment}" prop="${field}">
  201. <el-input v-model="form.${field}" type="textarea" placeholder="请输入内容" />
  202. </el-form-item>
  203. #end
  204. #end
  205. #end
  206. #end
  207. </el-form>
  208. <div slot="footer" class="dialog-footer">
  209. <el-button type="primary" @click="submitForm">确 定</el-button>
  210. <el-button @click="cancel">取 消</el-button>
  211. </div>
  212. </el-dialog>
  213. </div>
  214. </template>
  215. <script>
  216. import { list${BusinessName}, get${BusinessName}, del${BusinessName}, add${BusinessName}, update${BusinessName}, export${BusinessName} } from "@/api/${moduleName}/${businessName}";
  217. import Treeselect from "@riophae/vue-treeselect";
  218. import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  219. export default {
  220. name: "${BusinessName}",
  221. components: { Treeselect },
  222. data() {
  223. return {
  224. // 遮罩层
  225. loading: true,
  226. // ${functionName}表格数据
  227. ${businessName}List: [],
  228. // ${functionName}树选项
  229. ${businessName}Options: [],
  230. // 弹出层标题
  231. title: "",
  232. // 是否显示弹出层
  233. open: false,
  234. #foreach ($column in $columns)
  235. #set($parentheseIndex=$column.columnComment.indexOf("("))
  236. #if($parentheseIndex != -1)
  237. #set($comment=$column.columnComment.substring(0, $parentheseIndex))
  238. #else
  239. #set($comment=$column.columnComment)
  240. #end
  241. #if(${column.dictType} != '')
  242. // $comment字典
  243. ${column.javaField}Options: [],
  244. #end
  245. #end
  246. // 查询参数
  247. queryParams: {
  248. #foreach ($column in $columns)
  249. #if($column.query)
  250. $column.javaField: null#if($velocityCount != $columns.size()),#end
  251. #end
  252. #end
  253. },
  254. // 表单参数
  255. form: {},
  256. // 表单校验
  257. rules: {
  258. #foreach ($column in $columns)
  259. #if($column.required)
  260. #set($parentheseIndex=$column.columnComment.indexOf("("))
  261. #if($parentheseIndex != -1)
  262. #set($comment=$column.columnComment.substring(0, $parentheseIndex))
  263. #else
  264. #set($comment=$column.columnComment)
  265. #end
  266. #set($comment=$column.columnComment)
  267. $column.javaField: [
  268. { required: true, message: "$comment不能为空", trigger: "blur" }
  269. ]#if($velocityCount != $columns.size()),#end
  270. #end
  271. #end
  272. }
  273. };
  274. },
  275. created() {
  276. this.getList();
  277. #foreach ($column in $columns)
  278. #if(${column.dictType} != '')
  279. this.getDicts("${column.dictType}").then(response => {
  280. this.${column.javaField}Options = response.data;
  281. });
  282. #end
  283. #end
  284. },
  285. methods: {
  286. /** 查询${functionName}列表 */
  287. getList() {
  288. this.loading = true;
  289. list${BusinessName}(this.queryParams).then(response => {
  290. this.${businessName}List = this.handleTree(response.data, "${treeCode}", "${treeParentCode}");
  291. this.loading = false;
  292. });
  293. },
  294. /** 转换${functionName}数据结构 */
  295. normalizer(node) {
  296. if (node.children && !node.children.length) {
  297. delete node.children;
  298. }
  299. return {
  300. id: node.${treeCode},
  301. label: node.${treeName},
  302. children: node.children
  303. };
  304. },
  305. /** 查询部门下拉树结构 */
  306. getTreeselect() {
  307. list${BusinessName}().then(response => {
  308. this.${businessName}Options = [];
  309. const data = { ${treeCode}: 0, ${treeName}: '顶级节点', children: [] };
  310. data.children = this.handleTree(response.data, "${treeCode}", "${treeParentCode}");
  311. this.${businessName}Options.push(data);
  312. });
  313. },
  314. #foreach ($column in $columns)
  315. #if(${column.dictType} != '')
  316. #set($parentheseIndex=$column.columnComment.indexOf("("))
  317. #if($parentheseIndex != -1)
  318. #set($comment=$column.columnComment.substring(0, $parentheseIndex))
  319. #else
  320. #set($comment=$column.columnComment)
  321. #end
  322. // $comment字典翻译
  323. ${column.javaField}Format(row, column) {
  324. return this.selectDictLabel#if($column.htmlType == "checkbox")s#end(this.${column.javaField}Options, row.${column.javaField});
  325. },
  326. #end
  327. #end
  328. // 取消按钮
  329. cancel() {
  330. this.open = false;
  331. this.reset();
  332. },
  333. // 表单重置
  334. reset() {
  335. this.form = {
  336. #foreach ($column in $columns)
  337. #if($column.htmlType == "radio")
  338. $column.javaField: #if($column.javaType == "Integer" || $column.javaType == "Long")0#else"0"#end#if($velocityCount != $columns.size()),#end
  339. #elseif($column.htmlType == "checkbox")
  340. $column.javaField: []#if($velocityCount != $columns.size()),#end
  341. #else
  342. $column.javaField: null#if($velocityCount != $columns.size()),#end
  343. #end
  344. #end
  345. };
  346. this.resetForm("form");
  347. },
  348. /** 搜索按钮操作 */
  349. handleQuery() {
  350. this.getList();
  351. },
  352. /** 重置按钮操作 */
  353. resetQuery() {
  354. this.resetForm("queryForm");
  355. this.handleQuery();
  356. },
  357. /** 新增按钮操作 */
  358. handleAdd() {
  359. this.reset();
  360. this.getTreeselect();
  361. this.open = true;
  362. this.title = "添加${functionName}";
  363. },
  364. /** 修改按钮操作 */
  365. handleUpdate(row) {
  366. this.reset();
  367. this.getTreeselect();
  368. if (row != null) {
  369. this.form.${treeParentCode} = row.${treeCode};
  370. }
  371. get${BusinessName}(row.${pkColumn.javaField}).then(response => {
  372. this.form = response.data;
  373. #foreach ($column in $columns)
  374. #if($column.htmlType == "checkbox")
  375. this.form.$column.javaField = this.form.${column.javaField}.split(",");
  376. #end
  377. #end
  378. this.open = true;
  379. this.title = "修改${functionName}";
  380. });
  381. },
  382. /** 提交按钮 */
  383. submitForm() {
  384. this.#[[$]]#refs["form"].validate(valid => {
  385. if (valid) {
  386. #foreach ($column in $columns)
  387. #if($column.htmlType == "checkbox")
  388. this.form.$column.javaField = this.form.${column.javaField}.join(",");
  389. #end
  390. #end
  391. if (this.form.${pkColumn.javaField} != null) {
  392. update${BusinessName}(this.form).then(response => {
  393. if (response.code === 200) {
  394. this.msgSuccess("修改成功");
  395. this.open = false;
  396. this.getList();
  397. }
  398. });
  399. } else {
  400. add${BusinessName}(this.form).then(response => {
  401. if (response.code === 200) {
  402. this.msgSuccess("新增成功");
  403. this.open = false;
  404. this.getList();
  405. }
  406. });
  407. }
  408. }
  409. });
  410. },
  411. /** 删除按钮操作 */
  412. handleDelete(row) {
  413. this.$confirm('是否确认删除${functionName}编号为"' + row.${pkColumn.javaField} + '"的数据项?', "警告", {
  414. confirmButtonText: "确定",
  415. cancelButtonText: "取消",
  416. type: "warning"
  417. }).then(function() {
  418. return del${BusinessName}(row.${pkColumn.javaField});
  419. }).then(() => {
  420. this.getList();
  421. this.msgSuccess("删除成功");
  422. }).catch(function() {});
  423. }
  424. }
  425. };
  426. </script>