index-tree.vue.vm 16 KB

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