index-tree.vue.vm 16 KB

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