index-tree.vue.vm 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. {%- if table.pk_column %}
  2. {%- set pk_field = table.pk_column.java_field %}
  3. {%- else %}
  4. {%- set pk_field = 'id' %}
  5. {%- endif %}
  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. {%- set dict_type = column.dict_type if column.dict_type else '' %}
  12. {%- set attr_name = capitalize_first(column.java_field) %}
  13. {%- set comment = column.column_comment %}
  14. {%- if '(' in comment or '(' in comment %}
  15. {%- if '(' in comment %}
  16. {%- set comment = comment.split('(')[0] %}
  17. {%- elif '(' in comment %}
  18. {%- set comment = comment.split('(')[0] %}
  19. {%- endif %}
  20. {%- endif %}
  21. {%- if column.html_type == 'input' %}
  22. <el-form-item label="{{ comment }}" prop="{{ column.java_field }}">
  23. <el-input
  24. v-model="queryParams.{{ column.java_field }}"
  25. placeholder="请输入{{ comment }}"
  26. clearable
  27. @keyup.enter.native="handleQuery"
  28. />
  29. </el-form-item>
  30. {%- elif (column.html_type == 'select' or column.html_type == 'radio') and dict_type != '' %}
  31. <el-form-item label="{{ comment }}" prop="{{ column.java_field }}">
  32. <el-select v-model="queryParams.{{ column.java_field }}" placeholder="请选择{{ comment }}" clearable>
  33. <el-option
  34. v-for="dict in dict.type.{{ dict_type }}"
  35. :key="dict.value"
  36. :label="dict.label"
  37. :value="dict.value"
  38. />
  39. </el-select>
  40. </el-form-item>
  41. {%- elif (column.html_type == 'select' or column.html_type == 'radio') and dict_type == '' %}
  42. <el-form-item label="{{ comment }}" prop="{{ column.java_field }}">
  43. <el-select v-model="queryParams.{{ column.java_field }}" placeholder="请选择{{ comment }}" clearable>
  44. <el-option label="请选择字典生成" value="" />
  45. </el-select>
  46. </el-form-item>
  47. {%- elif column.html_type == 'datetime' and column.query_type != 'BETWEEN' %}
  48. <el-form-item label="{{ comment }}" prop="{{ column.java_field }}">
  49. <el-date-picker clearable
  50. v-model="queryParams.{{ column.java_field }}"
  51. type="date"
  52. value-format="yyyy-MM-dd"
  53. placeholder="选择{{ comment }}">
  54. </el-date-picker>
  55. </el-form-item>
  56. {%- elif column.html_type == 'datetime' and column.query_type == 'BETWEEN' %}
  57. <el-form-item label="{{ comment }}">
  58. <el-date-picker
  59. v-model="daterange{{ attr_name }}"
  60. style="width: 240px"
  61. value-format="yyyy-MM-dd"
  62. type="daterange"
  63. range-separator="-"
  64. start-placeholder="开始日期"
  65. end-placeholder="结束日期"
  66. ></el-date-picker>
  67. </el-form-item>
  68. {%- endif %}
  69. {%- endif %}
  70. {%- endfor %}
  71. <el-form-item>
  72. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  73. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  74. </el-form-item>
  75. </el-form>
  76. <el-row :gutter="10" class="mb8">
  77. <el-col :span="1.5">
  78. <el-button
  79. type="primary"
  80. plain
  81. icon="el-icon-plus"
  82. size="mini"
  83. @click="handleAdd"
  84. v-hasPermi="['{{ table.module_name }}:{{ table.business_name }}:add']"
  85. >新增</el-button>
  86. </el-col>
  87. <el-col :span="1.5">
  88. <el-button
  89. type="info"
  90. plain
  91. icon="el-icon-sort"
  92. size="mini"
  93. @click="toggleExpandAll"
  94. >展开/折叠</el-button>
  95. </el-col>
  96. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
  97. </el-row>
  98. <el-table
  99. v-if="refreshTable"
  100. :loading="loading"
  101. :data="{{ table.business_name }}List"
  102. row-key="{{ pk_field }}"
  103. :default-expand-all="isExpandAll"
  104. :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
  105. >
  106. {%- for column in table.columns %}
  107. {%- set java_field = column.java_field %}
  108. {%- set comment = column.column_comment %}
  109. {%- if '(' in comment or '(' in comment %}
  110. {%- if '(' in comment %}
  111. {%- set comment = comment.split('(')[0] %}
  112. {%- elif '(' in comment %}
  113. {%- set comment = comment.split('(')[0] %}
  114. {%- endif %}
  115. {%- endif %}
  116. {%- if column.is_pk == '1' %}
  117. {%- elif column.is_list and column.list_index is not none and column.html_type == 'datetime' %}
  118. <el-table-column label="{{ comment }}" align="center" v-if="columns[{{ column.list_index }}].visible" prop="{{ java_field }}" width="180">
  119. <template slot-scope="scope">
  120. <span>{{ "{{ parseTime(scope.row." }}{{ java_field }}{{ ", '{y}-{m}-{d}') }}" }}</span>
  121. </template>
  122. </el-table-column>
  123. {%- elif column.is_list and column.list_index is not none and column.html_type == 'imageUpload' %}
  124. <el-table-column label="{{ comment }}" align="center" v-if="columns[{{ column.list_index }}].visible" prop="{{ java_field }}" width="100">
  125. <template slot-scope="scope">
  126. <image-preview :src="scope.row.{{ java_field }}" :width="50" :height="50"/>
  127. </template>
  128. </el-table-column>
  129. {%- elif column.is_list and column.list_index is not none and column.html_type == 'fileUpload' %}
  130. <el-table-column label="{{ comment }}" align="center" v-if="columns[{{ column.list_index }}].visible" prop="{{ java_field }}" width="100">
  131. <template slot-scope="scope">
  132. <div v-if="scope.row.{{ java_field }}">
  133. <el-tooltip placement="top" effect="light">
  134. <div slot="content">
  135. <div v-for="(file,index) in scope.row.{{ java_field }}.split(',')"
  136. :key="index"
  137. style="text-align: left;padding: 5px;">
  138. <el-link
  139. :download="getFileName(file)"
  140. :href="getFilePath(file)"
  141. :underline="false"
  142. target="_blank"
  143. style="font-size: 14px"
  144. >
  145. <span style="cursor: pointer;"> {{ "{{ getFileName(file) }}" }} </span>
  146. </el-link>
  147. </div>
  148. </div>
  149. <span style="cursor: pointer; color: #409EFF;">查看文件</span>
  150. </el-tooltip>
  151. </div>
  152. <div v-else>
  153. -
  154. </div>
  155. </template>
  156. </el-table-column>
  157. {%- elif column.is_list and column.list_index is not none and column.dict_type and column.dict_type != '' %}
  158. <el-table-column label="{{ comment }}" align="center" v-if="columns[{{ column.list_index }}].visible" prop="{{ java_field }}">
  159. <template slot-scope="scope">
  160. {%- if column.html_type == 'checkbox' %}
  161. <dict-tag :options="dict.type.{{ column.dict_type }}" :value="scope.row.{{ java_field }} ? scope.row.{{ java_field }}.split(',') : []"/>
  162. {%- else %}
  163. <dict-tag :options="dict.type.{{ column.dict_type }}" :value="scope.row.{{ java_field }}"/>
  164. {%- endif %}
  165. </template>
  166. </el-table-column>
  167. {%- elif column.is_list and column.list_index is not none and java_field %}
  168. {%- if column.list_index == 0 %}
  169. <el-table-column label="{{ comment }}" :show-overflow-tooltip="true" v-if="columns[{{ column.list_index }}].visible" prop="{{ java_field }}" />
  170. {%- else %}
  171. <el-table-column label="{{ comment }}" align="center" :show-overflow-tooltip="true" v-if="columns[{{ column.list_index }}].visible" prop="{{ java_field }}" />
  172. {%- endif %}
  173. {%- endif %}
  174. {%- endfor %}
  175. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  176. <template slot-scope="scope">
  177. <el-button
  178. size="mini"
  179. type="text"
  180. icon="el-icon-edit"
  181. @click="handleUpdate(scope.row)"
  182. v-hasPermi="['{{ table.module_name }}:{{ table.business_name }}:edit']"
  183. >修改</el-button>
  184. <el-button
  185. size="mini"
  186. type="text"
  187. icon="el-icon-plus"
  188. @click="handleAdd(scope.row)"
  189. v-hasPermi="['{{ table.module_name }}:{{ table.business_name }}:add']"
  190. >新增</el-button>
  191. <el-button
  192. size="mini"
  193. type="text"
  194. icon="el-icon-delete"
  195. @click="handleDelete(scope.row)"
  196. v-hasPermi="['{{ table.module_name }}:{{ table.business_name }}:remove']"
  197. >删除</el-button>
  198. </template>
  199. </el-table-column>
  200. </el-table>
  201. <!-- 添加或修改{{ table.function_name }}对话框 -->
  202. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  203. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  204. {%- for column in table.columns %}
  205. {%- set field = column.java_field %}
  206. {%- if column.is_insert and column.is_pk != '1' %}
  207. {%- set comment = column.column_comment %}
  208. {%- if '(' in comment or '(' in comment %}
  209. {%- if '(' in comment %}
  210. {%- set comment = comment.split('(')[0] %}
  211. {%- elif '(' in comment %}
  212. {%- set comment = comment.split('(')[0] %}
  213. {%- endif %}
  214. {%- endif %}
  215. {%- set dict_type = column.dict_type if column.dict_type else '' %}
  216. {%- if column.java_field == tree_parent_field %}
  217. <el-form-item label="{{ comment }}" prop="{{ tree_parent_field }}">
  218. <treeselect v-model="form.{{ tree_parent_field }}" :options="{{ table.business_name }}Options" :normalizer="normalizer" placeholder="请选择{{ comment }}" />
  219. </el-form-item>
  220. {%- elif column.html_type == 'input' %}
  221. <el-form-item label="{{ comment }}" prop="{{ field }}">
  222. <el-input v-model="form.{{ field }}" placeholder="请输入{{ comment }}" />
  223. </el-form-item>
  224. {%- elif column.html_type == 'imageUpload' %}
  225. <el-form-item label="{{ comment }}" prop="{{ field }}">
  226. <image-upload v-model="form.{{ field }}"/>
  227. </el-form-item>
  228. {%- elif column.html_type == 'fileUpload' %}
  229. <el-form-item label="{{ comment }}" prop="{{ field }}">
  230. <file-upload v-model="form.{{ field }}"/>
  231. </el-form-item>
  232. {%- elif column.html_type == 'editor' %}
  233. <el-form-item label="{{ comment }}">
  234. <editor v-model="form.{{ field }}" :min-height="192"/>
  235. </el-form-item>
  236. {%- elif column.html_type == 'select' and dict_type != '' %}
  237. <el-form-item label="{{ comment }}" prop="{{ field }}">
  238. <el-select v-model="form.{{ field }}" placeholder="请选择{{ comment }}">
  239. <el-option
  240. v-for="dict in dict.type.{{ dict_type }}"
  241. :key="dict.value"
  242. :label="dict.label"
  243. {%- if column.java_type == 'Integer' or column.java_type == 'Long' %}
  244. :value="parseInt(dict.value)"
  245. {%- else %}
  246. :value="dict.value"
  247. {%- endif %}
  248. ></el-option>
  249. </el-select>
  250. </el-form-item>
  251. {%- elif column.html_type == 'select' and dict_type == '' %}
  252. <el-form-item label="{{ comment }}" prop="{{ field }}">
  253. <el-select v-model="form.{{ field }}" placeholder="请选择{{ comment }}">
  254. <el-option label="请选择字典生成" value="" />
  255. </el-select>
  256. </el-form-item>
  257. {%- elif column.html_type == 'checkbox' and dict_type != '' %}
  258. <el-form-item label="{{ comment }}" prop="{{ field }}">
  259. <el-checkbox-group v-model="form.{{ field }}">
  260. <el-checkbox
  261. v-for="dict in dict.type.{{ dict_type }}"
  262. :key="dict.value"
  263. :label="dict.value">
  264. {{ "{{dict.label}}" }}
  265. </el-checkbox>
  266. </el-checkbox-group>
  267. </el-form-item>
  268. {%- elif column.html_type == 'checkbox' and dict_type == '' %}
  269. <el-form-item label="{{ comment }}" prop="{{ field }}">
  270. <el-checkbox-group v-model="form.{{ field }}">
  271. <el-checkbox>请选择字典生成</el-checkbox>
  272. </el-checkbox-group>
  273. </el-form-item>
  274. {%- elif column.html_type == 'radio' and dict_type != '' %}
  275. <el-form-item label="{{ comment }}" prop="{{ field }}">
  276. <el-radio-group v-model="form.{{ field }}">
  277. <el-radio
  278. v-for="dict in dict.type.{{ dict_type }}"
  279. :key="dict.value"
  280. {%- if column.java_type == 'Integer' or column.java_type == 'Long' %}
  281. :label="parseInt(dict.value)"
  282. {%- else %}
  283. :label="dict.value"
  284. {%- endif %}
  285. >{{ "{{dict.label}}" }}</el-radio>
  286. </el-radio-group>
  287. </el-form-item>
  288. {%- elif column.html_type == 'radio' and dict_type == '' %}
  289. <el-form-item label="{{ comment }}" prop="{{ field }}">
  290. <el-radio-group v-model="form.{{ field }}">
  291. <el-radio label="1">请选择字典生成</el-radio>
  292. </el-radio-group>
  293. </el-form-item>
  294. {%- elif column.html_type == 'datetime' %}
  295. <el-form-item label="{{ comment }}" prop="{{ field }}">
  296. <el-date-picker clearable
  297. v-model="form.{{ field }}"
  298. type="date"
  299. value-format="yyyy-MM-dd"
  300. placeholder="选择{{ comment }}">
  301. </el-date-picker>
  302. </el-form-item>
  303. {%- elif column.html_type == 'textarea' %}
  304. <el-form-item label="{{ comment }}" prop="{{ field }}">
  305. <el-input v-model="form.{{ field }}" type="textarea" placeholder="请输入内容" />
  306. </el-form-item>
  307. {%- endif %}
  308. {%- endif %}
  309. {%- endfor %}
  310. </el-form>
  311. <div slot="footer" class="dialog-footer">
  312. <el-button type="primary" @click="submitForm">确 定</el-button>
  313. <el-button @click="cancel">取 消</el-button>
  314. </div>
  315. </el-dialog>
  316. </div>
  317. </template>
  318. <script>
  319. {% set apiName = to_camel_case(table.class_name, False) %}
  320. {% set ApiName = capitalize_first(apiName) %}
  321. import { list{{ ApiName }}, get{{ ApiName }}, del{{ ApiName }}, add{{ ApiName }}, update{{ ApiName }} } from "@/api/{{ table.module_name }}/{{ table.business_name }}";
  322. import Treeselect from "@riophae/vue-treeselect";
  323. import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  324. {%- set raw_tree_code = table.tree_code if table.tree_code else 'id' %}
  325. {%- set raw_tree_parent = table.tree_parent_code if table.tree_parent_code else 'parent_id' %}
  326. {%- set raw_tree_name = table.tree_name if table.tree_name else 'name' %}
  327. {%- set tree_code_field = to_camel_case(raw_tree_code, False) %}
  328. {%- set tree_parent_field = to_camel_case(raw_tree_parent, False) %}
  329. {%- set tree_name_field = to_camel_case(raw_tree_name, False) %}
  330. import { getFileName, getFilePath } from '@/utils/ruoyi'
  331. export default {
  332. name: "{{ table.class_name }}",
  333. {%- set dicts_list = [] %}
  334. {%- for column in table.columns %}
  335. {%- if column.dict_type and column.dict_type != '' %}
  336. {%- if column.dict_type not in dicts_list %}
  337. {%- set _ = dicts_list.append(column.dict_type) %}
  338. {%- endif %}
  339. {%- endif %}
  340. {%- endfor %}
  341. {%- if dicts_list|length > 0 %}
  342. dicts: [{%- for dict_type in dicts_list %}'{{ dict_type }}'{%- if not loop.last %}, {% endif %}{%- endfor %}],
  343. {%- endif %}
  344. components: {
  345. Treeselect
  346. },
  347. data() {
  348. return {
  349. //表格展示列
  350. columns: [
  351. {%- for column in table.columns %}
  352. {%- set comment = column.column_comment %}
  353. {%- if '(' in comment or '(' in comment %}
  354. {%- if '(' in comment %}
  355. {%- set comment = comment.split('(')[0] %}
  356. {%- elif '(' in comment %}
  357. {%- set comment = comment.split('(')[0] %}
  358. {%- endif %}
  359. {%- endif %}
  360. {%- if column.is_pk == '1' %}
  361. {%- elif column.is_list and column.list_index is not none %}
  362. { key: {{ column.list_index }}, label: '{{ comment }}', visible: true }{% if not loop.last %},{% endif %}
  363. {%- endif %}
  364. {%- endfor %}
  365. ],
  366. // 遮罩层
  367. loading: true,
  368. // 显示搜索条件
  369. showSearch: true,
  370. // {{ table.function_name }}表格数据
  371. {{ table.business_name }}List: [],
  372. // {{ table.function_name }}树选项
  373. {{ table.business_name }}Options: [],
  374. // 弹出层标题
  375. title: "",
  376. // 是否显示弹出层
  377. open: false,
  378. // 是否展开,默认全部展开
  379. isExpandAll: true,
  380. // 重新渲染表格状态
  381. refreshTable: true,
  382. {%- for column in table.columns %}
  383. {%- if column.html_type == 'datetime' and column.query_type == 'BETWEEN' %}
  384. {%- set attr_name = capitalize_first(column.java_field) %}
  385. {%- set comment = column.column_comment %}
  386. {%- if '(' in comment or '(' in comment %}
  387. {%- if '(' in comment %}
  388. {%- set comment = comment.split('(')[0] %}
  389. {%- elif '(' in comment %}
  390. {%- set comment = comment.split('(')[0] %}
  391. {%- endif %}
  392. {%- endif %}
  393. // {{ comment }}时间范围
  394. daterange{{ attr_name }}: [],
  395. {%- endif %}
  396. {%- endfor %}
  397. // 查询参数
  398. queryParams: {
  399. {%- set query_cols = [] %}
  400. {%- for column in table.columns %}
  401. {%- if column.is_query %}
  402. {%- set _ = query_cols.append(column) %}
  403. {%- endif %}
  404. {%- endfor %}
  405. {%- for column in query_cols %}
  406. {{ column.java_field }}: null{% if not loop.last %},{% endif %}
  407. {%- endfor %}
  408. },
  409. // 表单参数
  410. form: {},
  411. // 表单校验
  412. rules: {
  413. {%- set required_cols = [] %}
  414. {%- for column in table.columns %}
  415. {%- if column.is_required == '1' %}
  416. {%- set _ = required_cols.append(column) %}
  417. {%- endif %}
  418. {%- endfor %}
  419. {%- for column in required_cols %}
  420. {%- set comment = column.column_comment %}
  421. {%- if '(' in comment or '(' in comment %}
  422. {%- if '(' in comment %}
  423. {%- set comment = comment.split('(')[0] %}
  424. {%- elif '(' in comment %}
  425. {%- set comment = comment.split('(')[0] %}
  426. {%- endif %}
  427. {%- endif %}
  428. {{ column.java_field }}: [
  429. { required: true, message: "{{ comment }}不能为空", trigger: {% if column.html_type == 'select' or column.html_type == 'radio' %}"change"{% else %}"blur"{% endif %} }
  430. ]{% if not loop.last %},{% endif %}
  431. {%- endfor %}
  432. }
  433. };
  434. },
  435. created() {
  436. this.getList();
  437. },
  438. methods: {
  439. /** 查询{{ table.function_name }}列表 */
  440. getList() {
  441. this.loading = true;
  442. {%- set has_datetime_between = false %}
  443. {%- for column in table.columns %}
  444. {%- if column.html_type == 'datetime' and column.query_type == 'BETWEEN' %}
  445. {%- if not has_datetime_between %}
  446. this.queryParams.params = {};
  447. {%- set has_datetime_between = true %}
  448. {%- endif %}
  449. {%- set attr_name = capitalize_first(column.java_field) %}
  450. if (null != this.daterange{{ attr_name }} && '' != this.daterange{{ attr_name }}) {
  451. this.queryParams.params["begin{{ attr_name }}"] = this.daterange{{ attr_name }}[0];
  452. this.queryParams.params["end{{ attr_name }}"] = this.daterange{{ attr_name }}[1];
  453. }
  454. {%- endif %}
  455. {%- endfor %}
  456. list{{ ApiName }}(this.queryParams).then(response => {
  457. const list = Array.isArray(response && response.data) ? response.data : (Array.isArray(response && response.rows) ? response.rows : []);
  458. this.{{ table.business_name }}List = this.handleTree(list, "{{ tree_code_field }}", "{{ tree_parent_field }}");
  459. this.loading = false;
  460. });
  461. },
  462. {%- if has_file_upload %}
  463. getFilePath,
  464. getFileName,
  465. {%- endif %}
  466. /** 转换{{ table.function_name }}数据结构 */
  467. normalizer(node) {
  468. if (node.children && !node.children.length) {
  469. delete node.children;
  470. }
  471. return {
  472. id: node.{{ tree_code_field }},
  473. label: node.{{ tree_name_field }},
  474. children: node.children
  475. };
  476. },
  477. /** 查询{{ table.function_name }}下拉树结构 */
  478. getTreeselect() {
  479. list{{ ApiName }}().then(response => {
  480. this.{{ table.business_name }}Options = [];
  481. const data = { {{ tree_code_field }}: 0, {{ tree_name_field }}: '顶级节点', children: [] };
  482. const list = Array.isArray(response && response.data) ? response.data : (Array.isArray(response && response.rows) ? response.rows : []);
  483. data.children = this.handleTree(list, "{{ tree_code_field }}", "{{ tree_parent_field }}");
  484. this.{{ table.business_name }}Options.push(data);
  485. });
  486. },
  487. // 取消按钮
  488. cancel() {
  489. this.open = false;
  490. this.reset();
  491. },
  492. // 表单重置
  493. reset() {
  494. this.form = {
  495. {%- for column in table.columns %}
  496. {%- if column.html_type == 'checkbox' %}
  497. {{ column.java_field }}: []
  498. {%- else %}
  499. {{ column.java_field }}: null
  500. {%- endif %}{% if not loop.last %},{% endif %}
  501. {%- endfor %}
  502. };
  503. this.resetForm("form");
  504. },
  505. /** 搜索按钮操作 */
  506. handleQuery() {
  507. this.getList();
  508. },
  509. /** 重置按钮操作 */
  510. resetQuery() {
  511. {%- for column in table.columns %}
  512. {%- if column.html_type == 'datetime' and column.query_type == 'BETWEEN' %}
  513. {%- set attr_name = capitalize_first(column.java_field) %}
  514. this.daterange{{ attr_name }} = [];
  515. {%- endif %}
  516. {%- endfor %}
  517. this.resetForm("queryForm");
  518. this.handleQuery();
  519. },
  520. /** 新增按钮操作 */
  521. handleAdd(row) {
  522. this.reset();
  523. this.getTreeselect();
  524. if (row != null && row.{{ tree_code_field }}) {
  525. this.form.{{ tree_parent_field }} = row.{{ tree_code_field }};
  526. } else {
  527. this.form.{{ tree_parent_field }} = 0;
  528. }
  529. this.open = true;
  530. this.title = "添加{{ table.function_name }}";
  531. },
  532. /** 展开/折叠操作 */
  533. toggleExpandAll() {
  534. this.refreshTable = false;
  535. this.isExpandAll = !this.isExpandAll;
  536. this.$nextTick(() => {
  537. this.refreshTable = true;
  538. });
  539. },
  540. /** 修改按钮操作 */
  541. handleUpdate(row) {
  542. this.reset();
  543. this.getTreeselect();
  544. if (row != null) {
  545. this.form.{{ tree_parent_field }} = row.{{ tree_parent_field }};
  546. }
  547. get{{ ApiName }}(row.{{ pk_field }}).then(response => {
  548. this.form = response.data;
  549. {%- for column in table.columns %}
  550. {%- if column.html_type == 'checkbox' %}
  551. if (this.form.{{ column.java_field }}) {
  552. this.form.{{ column.java_field }} = this.form.{{ column.java_field }}.split(",");
  553. } else {
  554. this.form.{{ column.java_field }} = [];
  555. }
  556. {%- endif %}
  557. {%- endfor %}
  558. this.open = true;
  559. this.title = "修改{{ table.function_name }}";
  560. });
  561. },
  562. /** 提交按钮 */
  563. submitForm() {
  564. this.$refs["form"].validate(valid => {
  565. if (valid) {
  566. const submitData = this.buildSubmitData();
  567. if (submitData.{{ pk_field }} != null) {
  568. update{{ ApiName }}(submitData).then(response => {
  569. this.$modal.msgSuccess("修改成功");
  570. this.open = false;
  571. this.getList();
  572. });
  573. } else {
  574. add{{ ApiName }}(submitData).then(response => {
  575. this.$modal.msgSuccess("新增成功");
  576. this.open = false;
  577. this.getList();
  578. });
  579. }
  580. }
  581. });
  582. },
  583. buildSubmitData() {
  584. const data = { ...this.form };
  585. {%- for column in table.columns %}
  586. {%- if column.html_type == 'checkbox' %}
  587. if (Array.isArray(data.{{ column.java_field }})) {
  588. data.{{ column.java_field }} = data.{{ column.java_field }}.join(",");
  589. } else if (data.{{ column.java_field }}) {
  590. data.{{ column.java_field }} = String(data.{{ column.java_field }});
  591. }
  592. {%- endif %}
  593. {%- if column.java_type in ['Integer', 'Long', 'Short'] %}
  594. if (data.{{ column.java_field }} !== null && data.{{ column.java_field }} !== undefined && data.{{ column.java_field }} !== "") {
  595. data.{{ column.java_field }} = parseInt(data.{{ column.java_field }}, 10);
  596. } else {
  597. data.{{ column.java_field }} = null;
  598. }
  599. {%- elif column.java_type in ['Float', 'Double', 'BigDecimal', 'Decimal'] %}
  600. if (data.{{ column.java_field }} !== null && data.{{ column.java_field }} !== undefined && data.{{ column.java_field }} !== "") {
  601. data.{{ column.java_field }} = parseFloat(data.{{ column.java_field }});
  602. } else {
  603. data.{{ column.java_field }} = null;
  604. }
  605. {%- endif %}
  606. {%- endfor %}
  607. return data;
  608. },
  609. /** 删除按钮操作 */
  610. handleDelete(row) {
  611. this.$modal.confirm('是否确认删除{{ table.function_name }}编号为"' + row.{{ pk_field }} + '"的数据项?').then(function() {
  612. return del{{ ApiName }}(row.{{ pk_field }});
  613. }).then(() => {
  614. this.getList();
  615. this.$modal.msgSuccess("删除成功");
  616. }).catch(() => {});
  617. }
  618. }
  619. };
  620. </script>