index-tree.vue.vm 27 KB

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