index.vue.vm 23 KB

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