index-tree.vue.vm 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  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. <el-col :span="1.5">
  97. <el-button
  98. type="warning"
  99. plain
  100. icon="el-icon-download"
  101. size="mini"
  102. @click="handleExport"
  103. v-hasPermi="['{{ table.module_name }}:{{ table.business_name }}:export']"
  104. >导出</el-button>
  105. </el-col>
  106. <el-col :span="1.5">
  107. <el-button
  108. type="info"
  109. plain
  110. icon="el-icon-upload2"
  111. size="mini"
  112. @click="handleImport"
  113. v-hasPermi="['{{ table.module_name }}:{{ table.business_name }}:import']"
  114. >导入</el-button>
  115. </el-col>
  116. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
  117. </el-row>
  118. <el-table
  119. v-if="refreshTable"
  120. :loading="loading"
  121. :data="{{ table.business_name }}List"
  122. row-key="{{ pk_field }}"
  123. :default-expand-all="isExpandAll"
  124. :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
  125. >
  126. {%- for column in table.columns %}
  127. {%- set java_field = column.java_field %}
  128. {%- set comment = column.column_comment %}
  129. {%- if '(' in comment or '(' in comment %}
  130. {%- if '(' in comment %}
  131. {%- set comment = comment.split('(')[0] %}
  132. {%- elif '(' in comment %}
  133. {%- set comment = comment.split('(')[0] %}
  134. {%- endif %}
  135. {%- endif %}
  136. {%- if column.is_pk == '1' %}
  137. {%- elif column.is_list and column.list_index is not none and column.html_type == 'datetime' %}
  138. <el-table-column label="{{ comment }}" align="center" v-if="columns[{{ column.list_index }}].visible" prop="{{ java_field }}" width="180">
  139. <template slot-scope="scope">
  140. <span>{{ "{{ parseTime(scope.row." }}{{ java_field }}{{ ", '{y}-{m}-{d}') }}" }}</span>
  141. </template>
  142. </el-table-column>
  143. {%- elif column.is_list and column.list_index is not none and column.html_type == 'imageUpload' %}
  144. <el-table-column label="{{ comment }}" align="center" v-if="columns[{{ column.list_index }}].visible" prop="{{ java_field }}" width="100">
  145. <template slot-scope="scope">
  146. <image-preview :src="scope.row.{{ java_field }}" :width="50" :height="50"/>
  147. </template>
  148. </el-table-column>
  149. {%- elif column.is_list and column.list_index is not none and column.html_type == 'fileUpload' %}
  150. <el-table-column label="{{ comment }}" align="center" v-if="columns[{{ column.list_index }}].visible" prop="{{ java_field }}" width="100">
  151. <template slot-scope="scope">
  152. <div v-if="scope.row.{{ java_field }}">
  153. <el-tooltip placement="top" effect="light">
  154. <div slot="content">
  155. <div v-for="(file,index) in scope.row.{{ java_field }}.split(',')"
  156. :key="index"
  157. style="text-align: left;padding: 5px;">
  158. <el-link
  159. :download="getFileName(file)"
  160. :href="getFilePath(file)"
  161. :underline="false"
  162. target="_blank"
  163. style="font-size: 14px"
  164. >
  165. <span style="cursor: pointer;"> {{ "{{ getFileName(file) }}" }} </span>
  166. </el-link>
  167. </div>
  168. </div>
  169. <span style="cursor: pointer; color: #409EFF;">查看文件</span>
  170. </el-tooltip>
  171. </div>
  172. <div v-else>
  173. -
  174. </div>
  175. </template>
  176. </el-table-column>
  177. {%- elif column.is_list and column.list_index is not none and column.dict_type and column.dict_type != '' %}
  178. <el-table-column label="{{ comment }}" align="center" v-if="columns[{{ column.list_index }}].visible" prop="{{ java_field }}">
  179. <template slot-scope="scope">
  180. {%- if column.html_type == 'checkbox' %}
  181. <dict-tag :options="dict.type.{{ column.dict_type }}" :value="scope.row.{{ java_field }} ? scope.row.{{ java_field }}.split(',') : []"/>
  182. {%- else %}
  183. <dict-tag :options="dict.type.{{ column.dict_type }}" :value="scope.row.{{ java_field }}"/>
  184. {%- endif %}
  185. </template>
  186. </el-table-column>
  187. {%- elif column.is_list and column.list_index is not none and java_field %}
  188. {%- if column.list_index == 0 %}
  189. <el-table-column label="{{ comment }}" :show-overflow-tooltip="true" v-if="columns[{{ column.list_index }}].visible" prop="{{ java_field }}" />
  190. {%- else %}
  191. <el-table-column label="{{ comment }}" align="center" :show-overflow-tooltip="true" v-if="columns[{{ column.list_index }}].visible" prop="{{ java_field }}" />
  192. {%- endif %}
  193. {%- endif %}
  194. {%- endfor %}
  195. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  196. <template slot-scope="scope">
  197. <el-button
  198. size="mini"
  199. type="text"
  200. icon="el-icon-edit"
  201. @click="handleUpdate(scope.row)"
  202. v-hasPermi="['{{ table.module_name }}:{{ table.business_name }}:edit']"
  203. >修改</el-button>
  204. <el-button
  205. size="mini"
  206. type="text"
  207. icon="el-icon-plus"
  208. @click="handleAdd(scope.row)"
  209. v-hasPermi="['{{ table.module_name }}:{{ table.business_name }}:add']"
  210. >新增</el-button>
  211. <el-button
  212. size="mini"
  213. type="text"
  214. icon="el-icon-delete"
  215. @click="handleDelete(scope.row)"
  216. v-hasPermi="['{{ table.module_name }}:{{ table.business_name }}:remove']"
  217. >删除</el-button>
  218. </template>
  219. </el-table-column>
  220. </el-table>
  221. <!-- 添加或修改{{ table.function_name }}对话框 -->
  222. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  223. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  224. {%- for column in table.columns %}
  225. {%- set field = column.java_field %}
  226. {%- if column.is_insert and column.is_pk != '1' %}
  227. {%- set comment = column.column_comment %}
  228. {%- if '(' in comment or '(' in comment %}
  229. {%- if '(' in comment %}
  230. {%- set comment = comment.split('(')[0] %}
  231. {%- elif '(' in comment %}
  232. {%- set comment = comment.split('(')[0] %}
  233. {%- endif %}
  234. {%- endif %}
  235. {%- set dict_type = column.dict_type if column.dict_type else '' %}
  236. {%- if column.java_field == tree_parent_field %}
  237. <el-form-item label="{{ comment }}" prop="{{ tree_parent_field }}">
  238. <treeselect v-model="form.{{ tree_parent_field }}" :options="{{ table.business_name }}Options" :normalizer="normalizer" placeholder="请选择{{ comment }}" />
  239. </el-form-item>
  240. {%- elif column.html_type == 'input' %}
  241. <el-form-item label="{{ comment }}" prop="{{ field }}">
  242. <el-input v-model="form.{{ field }}" placeholder="请输入{{ comment }}" />
  243. </el-form-item>
  244. {%- elif column.html_type == 'imageUpload' %}
  245. <el-form-item label="{{ comment }}" prop="{{ field }}">
  246. <image-upload v-model="form.{{ field }}"/>
  247. </el-form-item>
  248. {%- elif column.html_type == 'fileUpload' %}
  249. <el-form-item label="{{ comment }}" prop="{{ field }}">
  250. <file-upload v-model="form.{{ field }}"/>
  251. </el-form-item>
  252. {%- elif column.html_type == 'editor' %}
  253. <el-form-item label="{{ comment }}">
  254. <editor v-model="form.{{ field }}" :min-height="192"/>
  255. </el-form-item>
  256. {%- elif column.html_type == 'select' and dict_type != '' %}
  257. <el-form-item label="{{ comment }}" prop="{{ field }}">
  258. <el-select v-model="form.{{ field }}" placeholder="请选择{{ comment }}">
  259. <el-option
  260. v-for="dict in dict.type.{{ dict_type }}"
  261. :key="dict.value"
  262. :label="dict.label"
  263. {%- if column.java_type == 'Integer' or column.java_type == 'Long' %}
  264. :value="parseInt(dict.value)"
  265. {%- else %}
  266. :value="dict.value"
  267. {%- endif %}
  268. ></el-option>
  269. </el-select>
  270. </el-form-item>
  271. {%- elif column.html_type == 'select' and dict_type == '' %}
  272. <el-form-item label="{{ comment }}" prop="{{ field }}">
  273. <el-select v-model="form.{{ field }}" placeholder="请选择{{ comment }}">
  274. <el-option label="请选择字典生成" value="" />
  275. </el-select>
  276. </el-form-item>
  277. {%- elif column.html_type == 'checkbox' and dict_type != '' %}
  278. <el-form-item label="{{ comment }}" prop="{{ field }}">
  279. <el-checkbox-group v-model="form.{{ field }}">
  280. <el-checkbox
  281. v-for="dict in dict.type.{{ dict_type }}"
  282. :key="dict.value"
  283. :label="dict.value">
  284. {{ "{{dict.label}}" }}
  285. </el-checkbox>
  286. </el-checkbox-group>
  287. </el-form-item>
  288. {%- elif column.html_type == 'checkbox' and dict_type == '' %}
  289. <el-form-item label="{{ comment }}" prop="{{ field }}">
  290. <el-checkbox-group v-model="form.{{ field }}">
  291. <el-checkbox>请选择字典生成</el-checkbox>
  292. </el-checkbox-group>
  293. </el-form-item>
  294. {%- elif column.html_type == 'radio' and dict_type != '' %}
  295. <el-form-item label="{{ comment }}" prop="{{ field }}">
  296. <el-radio-group v-model="form.{{ field }}">
  297. <el-radio
  298. v-for="dict in dict.type.{{ dict_type }}"
  299. :key="dict.value"
  300. {%- if column.java_type == 'Integer' or column.java_type == 'Long' %}
  301. :label="parseInt(dict.value)"
  302. {%- else %}
  303. :label="dict.value"
  304. {%- endif %}
  305. >{{ "{{dict.label}}" }}</el-radio>
  306. </el-radio-group>
  307. </el-form-item>
  308. {%- elif column.html_type == 'radio' and dict_type == '' %}
  309. <el-form-item label="{{ comment }}" prop="{{ field }}">
  310. <el-radio-group v-model="form.{{ field }}">
  311. <el-radio label="1">请选择字典生成</el-radio>
  312. </el-radio-group>
  313. </el-form-item>
  314. {%- elif column.html_type == 'datetime' %}
  315. <el-form-item label="{{ comment }}" prop="{{ field }}">
  316. <el-date-picker clearable
  317. v-model="form.{{ field }}"
  318. type="date"
  319. value-format="yyyy-MM-dd"
  320. placeholder="选择{{ comment }}">
  321. </el-date-picker>
  322. </el-form-item>
  323. {%- elif column.html_type == 'textarea' %}
  324. <el-form-item label="{{ comment }}" prop="{{ field }}">
  325. <el-input v-model="form.{{ field }}" type="textarea" placeholder="请输入内容" />
  326. </el-form-item>
  327. {%- endif %}
  328. {%- endif %}
  329. {%- endfor %}
  330. </el-form>
  331. <div slot="footer" class="dialog-footer">
  332. <el-button type="primary" @click="submitForm">确 定</el-button>
  333. <el-button @click="cancel">取 消</el-button>
  334. </div>
  335. </el-dialog>
  336. <!-- 导入对话框 -->
  337. <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
  338. <el-upload
  339. ref="upload"
  340. :limit="1"
  341. accept=".xlsx, .xls"
  342. :headers="upload.headers"
  343. :action="upload.url + '?updateSupport=' + upload.updateSupport"
  344. :disabled="upload.isUploading"
  345. :on-progress="handleFileUploadProgress"
  346. :on-success="handleFileSuccess"
  347. :auto-upload="false"
  348. drag
  349. >
  350. <i class="el-icon-upload"></i>
  351. <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
  352. <div class="el-upload__tip text-center" slot="tip">
  353. <div class="el-upload__tip" slot="tip">
  354. <el-checkbox v-model="upload.updateSupport" /> 是否更新已经存在的{{ table.function_name }}数据
  355. </div>
  356. <span>仅允许导入xls、xlsx格式文件。</span>
  357. <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;" @click="importTemplate">下载模板</el-link>
  358. </div>
  359. </el-upload>
  360. <div slot="footer" class="dialog-footer">
  361. <el-button type="primary" @click="submitFileForm">确 定</el-button>
  362. <el-button @click="upload.open = false">取 消</el-button>
  363. </div>
  364. </el-dialog>
  365. </div>
  366. </template>
  367. <script>
  368. {% set apiName = to_camel_case(table.class_name, False) %}
  369. {% set ApiName = capitalize_first(apiName) %}
  370. import { list{{ ApiName }}, get{{ ApiName }}, del{{ ApiName }}, add{{ ApiName }}, update{{ ApiName }}} from "@/api/{{ table.module_name }}/{{ table.business_name }}";
  371. import Treeselect from "@riophae/vue-treeselect";
  372. import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  373. import { getToken } from "@/utils/auth";
  374. {%- set raw_tree_code = table.tree_code if table.tree_code else 'id' %}
  375. {%- set raw_tree_parent = table.tree_parent_code if table.tree_parent_code else 'parent_id' %}
  376. {%- set raw_tree_name = table.tree_name if table.tree_name else 'name' %}
  377. {%- set tree_code_field = to_camel_case(raw_tree_code, False) %}
  378. {%- set tree_parent_field = to_camel_case(raw_tree_parent, False) %}
  379. {%- set tree_name_field = to_camel_case(raw_tree_name, False) %}
  380. export default {
  381. name: "{{ table.class_name }}",
  382. {%- set dicts_list = [] %}
  383. {%- for column in table.columns %}
  384. {%- if column.dict_type and column.dict_type != '' %}
  385. {%- if column.dict_type not in dicts_list %}
  386. {%- set _ = dicts_list.append(column.dict_type) %}
  387. {%- endif %}
  388. {%- endif %}
  389. {%- endfor %}
  390. {%- if dicts_list|length > 0 %}
  391. dicts: [{%- for dict_type in dicts_list %}'{{ dict_type }}'{%- if not loop.last %}, {% endif %}{%- endfor %}],
  392. {%- endif %}
  393. components: {
  394. Treeselect
  395. },
  396. data() {
  397. return {
  398. //表格展示列
  399. columns: [
  400. {%- for column in table.columns %}
  401. {%- set comment = column.column_comment %}
  402. {%- if '(' in comment or '(' in comment %}
  403. {%- if '(' in comment %}
  404. {%- set comment = comment.split('(')[0] %}
  405. {%- elif '(' in comment %}
  406. {%- set comment = comment.split('(')[0] %}
  407. {%- endif %}
  408. {%- endif %}
  409. {%- if column.is_pk == '1' %}
  410. {%- elif column.is_list and column.list_index is not none %}
  411. { key: {{ column.list_index }}, label: '{{ comment }}', visible: true }{% if not loop.last %},{% endif %}
  412. {%- endif %}
  413. {%- endfor %}
  414. ],
  415. // 遮罩层
  416. loading: true,
  417. // 显示搜索条件
  418. showSearch: true,
  419. // {{ table.function_name }}表格数据
  420. {{ table.business_name }}List: [],
  421. // {{ table.function_name }}树选项
  422. {{ table.business_name }}Options: [],
  423. // 弹出层标题
  424. title: "",
  425. // 是否显示弹出层
  426. open: false,
  427. // 是否展开,默认全部展开
  428. isExpandAll: true,
  429. // 重新渲染表格状态
  430. refreshTable: true,
  431. {%- for column in table.columns %}
  432. {%- if column.html_type == 'datetime' and column.query_type == 'BETWEEN' %}
  433. {%- set attr_name = capitalize_first(column.java_field) %}
  434. {%- set comment = column.column_comment %}
  435. {%- if '(' in comment or '(' in comment %}
  436. {%- if '(' in comment %}
  437. {%- set comment = comment.split('(')[0] %}
  438. {%- elif '(' in comment %}
  439. {%- set comment = comment.split('(')[0] %}
  440. {%- endif %}
  441. {%- endif %}
  442. // {{ comment }}时间范围
  443. daterange{{ attr_name }}: [],
  444. {%- endif %}
  445. {%- endfor %}
  446. // 查询参数
  447. queryParams: {
  448. {%- set query_cols = [] %}
  449. {%- for column in table.columns %}
  450. {%- if column.is_query %}
  451. {%- set _ = query_cols.append(column) %}
  452. {%- endif %}
  453. {%- endfor %}
  454. {%- for column in query_cols %}
  455. {{ column.java_field }}: null{% if not loop.last %},{% endif %}
  456. {%- endfor %}
  457. },
  458. // 表单参数
  459. form: {},
  460. // 导入参数
  461. upload: {
  462. open: false,
  463. title: "",
  464. isUploading: false,
  465. updateSupport: 0,
  466. headers: { Authorization: "Bearer " + getToken() },
  467. url: process.env.VUE_APP_BASE_API + "/{{ table.module_name }}/{{ table.business_name }}/importData"
  468. },
  469. // 表单校验
  470. rules: {
  471. {%- set required_cols = [] %}
  472. {%- for column in table.columns %}
  473. {%- if column.is_required == '1' %}
  474. {%- set _ = required_cols.append(column) %}
  475. {%- endif %}
  476. {%- endfor %}
  477. {%- for column in required_cols %}
  478. {%- set comment = column.column_comment %}
  479. {%- if '(' in comment or '(' in comment %}
  480. {%- if '(' in comment %}
  481. {%- set comment = comment.split('(')[0] %}
  482. {%- elif '(' in comment %}
  483. {%- set comment = comment.split('(')[0] %}
  484. {%- endif %}
  485. {%- endif %}
  486. {{ column.java_field }}: [
  487. { required: true, message: "{{ comment }}不能为空", trigger: {% if column.html_type == 'select' or column.html_type == 'radio' %}"change"{% else %}"blur"{% endif %} }
  488. ]{% if not loop.last %},{% endif %}
  489. {%- endfor %}
  490. }
  491. };
  492. },
  493. created() {
  494. this.getList();
  495. },
  496. methods: {
  497. /** 查询{{ table.function_name }}列表 */
  498. getList() {
  499. this.loading = true;
  500. {%- set has_datetime_between = false %}
  501. {%- for column in table.columns %}
  502. {%- if column.html_type == 'datetime' and column.query_type == 'BETWEEN' %}
  503. {%- if not has_datetime_between %}
  504. this.queryParams.params = {};
  505. {%- set has_datetime_between = true %}
  506. {%- endif %}
  507. {%- set attr_name = capitalize_first(column.java_field) %}
  508. if (null != this.daterange{{ attr_name }} && '' != this.daterange{{ attr_name }}) {
  509. this.queryParams.params["begin{{ attr_name }}"] = this.daterange{{ attr_name }}[0];
  510. this.queryParams.params["end{{ attr_name }}"] = this.daterange{{ attr_name }}[1];
  511. }
  512. {%- endif %}
  513. {%- endfor %}
  514. list{{ ApiName }}(this.queryParams).then(response => {
  515. const list = Array.isArray(response && response.data) ? response.data : (Array.isArray(response && response.rows) ? response.rows : []);
  516. this.{{ table.business_name }}List = this.handleTree(list, "{{ tree_code_field }}", "{{ tree_parent_field }}");
  517. this.loading = false;
  518. });
  519. },
  520. {%- if has_file_upload %}
  521. getFilePath,
  522. getFileName,
  523. {%- endif %}
  524. /** 转换{{ table.function_name }}数据结构 */
  525. normalizer(node) {
  526. if (node.children && !node.children.length) {
  527. delete node.children;
  528. }
  529. return {
  530. id: node.{{ tree_code_field }},
  531. label: node.{{ tree_name_field }},
  532. children: node.children
  533. };
  534. },
  535. /** 查询{{ table.function_name }}下拉树结构 */
  536. getTreeselect() {
  537. list{{ ApiName }}().then(response => {
  538. this.{{ table.business_name }}Options = [];
  539. const data = { {{ tree_code_field }}: 0, {{ tree_name_field }}: '顶级节点', children: [] };
  540. const list = Array.isArray(response && response.data) ? response.data : (Array.isArray(response && response.rows) ? response.rows : []);
  541. data.children = this.handleTree(list, "{{ tree_code_field }}", "{{ tree_parent_field }}");
  542. this.{{ table.business_name }}Options.push(data);
  543. });
  544. },
  545. // 取消按钮
  546. cancel() {
  547. this.open = false;
  548. this.reset();
  549. },
  550. // 表单重置
  551. reset() {
  552. this.form = {
  553. {%- for column in table.columns %}
  554. {%- if column.html_type == 'checkbox' %}
  555. {{ column.java_field }}: []
  556. {%- else %}
  557. {{ column.java_field }}: null
  558. {%- endif %}{% if not loop.last %},{% endif %}
  559. {%- endfor %}
  560. };
  561. this.resetForm("form");
  562. },
  563. /** 搜索按钮操作 */
  564. handleQuery() {
  565. this.getList();
  566. },
  567. /** 重置按钮操作 */
  568. resetQuery() {
  569. {%- for column in table.columns %}
  570. {%- if column.html_type == 'datetime' and column.query_type == 'BETWEEN' %}
  571. {%- set attr_name = capitalize_first(column.java_field) %}
  572. this.daterange{{ attr_name }} = [];
  573. {%- endif %}
  574. {%- endfor %}
  575. this.resetForm("queryForm");
  576. this.handleQuery();
  577. },
  578. /** 新增按钮操作 */
  579. handleAdd(row) {
  580. this.reset();
  581. this.getTreeselect();
  582. if (row != null && row.{{ tree_code_field }}) {
  583. this.form.{{ tree_parent_field }} = row.{{ tree_code_field }};
  584. } else {
  585. this.form.{{ tree_parent_field }} = 0;
  586. }
  587. this.open = true;
  588. this.title = "添加{{ table.function_name }}";
  589. },
  590. /** 展开/折叠操作 */
  591. toggleExpandAll() {
  592. this.refreshTable = false;
  593. this.isExpandAll = !this.isExpandAll;
  594. this.$nextTick(() => {
  595. this.refreshTable = true;
  596. });
  597. },
  598. /** 修改按钮操作 */
  599. handleUpdate(row) {
  600. this.reset();
  601. this.getTreeselect();
  602. if (row != null) {
  603. this.form.{{ tree_parent_field }} = row.{{ tree_parent_field }};
  604. }
  605. get{{ ApiName }}(row.{{ pk_field }}).then(response => {
  606. this.form = response.data;
  607. {%- for column in table.columns %}
  608. {%- if column.html_type == 'checkbox' %}
  609. if (this.form.{{ column.java_field }}) {
  610. this.form.{{ column.java_field }} = this.form.{{ column.java_field }}.split(",");
  611. } else {
  612. this.form.{{ column.java_field }} = [];
  613. }
  614. {%- endif %}
  615. {%- endfor %}
  616. this.open = true;
  617. this.title = "修改{{ table.function_name }}";
  618. });
  619. },
  620. /** 提交按钮 */
  621. submitForm() {
  622. this.$refs["form"].validate(valid => {
  623. if (valid) {
  624. const submitData = this.buildSubmitData();
  625. if (submitData.{{ pk_field }} != null) {
  626. update{{ ApiName }}(submitData).then(response => {
  627. this.$modal.msgSuccess("修改成功");
  628. this.open = false;
  629. this.getList();
  630. });
  631. } else {
  632. add{{ ApiName }}(submitData).then(response => {
  633. this.$modal.msgSuccess("新增成功");
  634. this.open = false;
  635. this.getList();
  636. });
  637. }
  638. }
  639. });
  640. },
  641. buildSubmitData() {
  642. const data = { ...this.form };
  643. {%- for column in table.columns %}
  644. {%- if column.html_type == 'checkbox' %}
  645. if (Array.isArray(data.{{ column.java_field }})) {
  646. data.{{ column.java_field }} = data.{{ column.java_field }}.join(",");
  647. } else if (data.{{ column.java_field }}) {
  648. data.{{ column.java_field }} = String(data.{{ column.java_field }});
  649. }
  650. {%- endif %}
  651. {%- if column.java_type in ['Integer', 'Long', 'Short'] %}
  652. if (data.{{ column.java_field }} !== null && data.{{ column.java_field }} !== undefined && data.{{ column.java_field }} !== "") {
  653. data.{{ column.java_field }} = parseInt(data.{{ column.java_field }}, 10);
  654. } else {
  655. data.{{ column.java_field }} = null;
  656. }
  657. {%- elif column.java_type in ['Float', 'Double', 'BigDecimal', 'Decimal'] %}
  658. if (data.{{ column.java_field }} !== null && data.{{ column.java_field }} !== undefined && data.{{ column.java_field }} !== "") {
  659. data.{{ column.java_field }} = parseFloat(data.{{ column.java_field }});
  660. } else {
  661. data.{{ column.java_field }} = null;
  662. }
  663. {%- endif %}
  664. {%- endfor %}
  665. return data;
  666. },
  667. /** 删除按钮操作 */
  668. handleDelete(row) {
  669. this.$modal.confirm('是否确认删除{{ table.function_name }}编号为"' + row.{{ pk_field }} + '"的数据项?').then(function() {
  670. return del{{ ApiName }}(row.{{ pk_field }});
  671. }).then(() => {
  672. this.getList();
  673. this.$modal.msgSuccess("删除成功");
  674. }).catch(() => {});
  675. },
  676. /** 导出按钮操作 */
  677. handleExport() {
  678. this.download('{{ table.module_name }}/{{ table.business_name }}/export', {
  679. ...this.queryParams
  680. }, `{{ table.business_name }}_${new Date().getTime()}.xlsx`)
  681. },
  682. /** 导入按钮操作 */
  683. handleImport() {
  684. this.upload.title = "{{ table.function_name }}导入";
  685. this.upload.open = true;
  686. },
  687. /** 下载模板操作 */
  688. importTemplate() {
  689. this.download(
  690. "{{ table.module_name }}/{{ table.business_name }}/importTemplate",
  691. {},
  692. "{{ table.business_name }}_template_" + new Date().getTime() + ".xlsx"
  693. );
  694. },
  695. // 文件上传中处理
  696. handleFileUploadProgress(event, file, fileList) {
  697. this.upload.isUploading = true;
  698. },
  699. // 文件上传成功处理
  700. handleFileSuccess(response, file, fileList) {
  701. this.upload.open = false;
  702. this.upload.isUploading = false;
  703. this.$refs.upload.clearFiles();
  704. this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
  705. this.getList();
  706. },
  707. // 提交上传文件
  708. submitFileForm() {
  709. this.$refs.upload.submit();
  710. }
  711. }
  712. };
  713. </script>