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