index.vue.vm 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  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 + '?updateSupport=' + upload.updateSupport"
  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. {% set apiName = to_camel_case(table.class_name, False) %}
  307. {% set ApiName = capitalize_first(apiName) %}
  308. import { list{{ ApiName }}, get{{ ApiName }}, del{{ ApiName }}, add{{ ApiName }}, update{{ ApiName }} } from "@/api/{{ table.module_name }}/{{ table.business_name }}";
  309. import { getToken } from "@/utils/auth";
  310. export default {
  311. name: "{{ table.class_name }}",
  312. {%- set dicts_list = [] %}
  313. {%- for column in table.columns %}
  314. {%- if column.dict_type and column.dict_type != '' %}
  315. {%- if column.dict_type not in dicts_list %}
  316. {%- set _ = dicts_list.append(column.dict_type) %}
  317. {%- endif %}
  318. {%- endif %}
  319. {%- endfor %}
  320. {%- if dicts_list|length > 0 %}
  321. dicts: [{%- for dict_type in dicts_list %}'{{ dict_type }}'{%- if not loop.last %}, {% endif %}{%- endfor %}],
  322. {%- endif %}
  323. data() {
  324. return {
  325. // 遮罩层
  326. loading: true,
  327. // 选中数组
  328. ids: [],
  329. // 非单个禁用
  330. single: true,
  331. // 非多个禁用
  332. multiple: true,
  333. // 显示搜索条件
  334. showSearch: true,
  335. // 总条数
  336. total: 0,
  337. // {{ table.function_name }}表格数据
  338. {{ table.business_name }}List: [],
  339. // 表格列信息
  340. columns: [
  341. {%- for column in table.columns %}
  342. {%- if column.is_list %}
  343. { key: {{ column.list_index }}, label: '{{ column.column_comment }}', visible: true }{% if not loop.last %},{% endif %}
  344. {%- endif %}
  345. {%- endfor %}
  346. ],
  347. // 弹出层标题
  348. title: "",
  349. // 是否显示弹出层
  350. open: false,
  351. {%- for column in table.columns %}
  352. {%- if column.html_type == 'datetime' %}
  353. // {{ column.column_comment }}时间范围
  354. {%- set attr_name = capitalize_first(column.java_field) %}
  355. dateRange{{ attr_name }}: [],
  356. {%- endif %}
  357. {%- endfor %}
  358. // 查询参数
  359. queryParams: {
  360. pageNum: 1,
  361. pageSize: 10,
  362. {%- for column in table.columns %}
  363. {%- if column.is_query %}
  364. {{ column.java_field }}: null{% if not loop.last %},{% endif %}
  365. {%- endif %}
  366. {%- endfor %}
  367. },
  368. // 表单参数
  369. form: {},
  370. // 导入参数
  371. upload: {
  372. // 是否显示弹出层(导入)
  373. open: false,
  374. // 弹出层标题(导入)
  375. title: "",
  376. // 是否禁用上传
  377. isUploading: false,
  378. // 是否更新已经存在的{{ table.function_name }}数据
  379. updateSupport: 0,
  380. // 设置上传的请求头部
  381. headers: { Authorization: "Bearer " + getToken() },
  382. // 上传的地址
  383. url: process.env.VUE_APP_BASE_API + "/{{ table.module_name }}/{{ table.business_name }}/importData"
  384. },
  385. // 表单校验
  386. rules: {
  387. {%- set required_cols = [] %}
  388. {%- for column in table.columns %}
  389. {%- if column.is_required == '1' %}
  390. {%- set _ = required_cols.append(column) %}
  391. {%- endif %}
  392. {%- endfor %}
  393. {%- for column in required_cols %}
  394. {%- set comment = column.column_comment %}
  395. {%- if '(' in comment or '(' in comment %}
  396. {%- if '(' in comment %}
  397. {%- set comment = comment.split('(')[0] %}
  398. {%- elif '(' in comment %}
  399. {%- set comment = comment.split('(')[0] %}
  400. {%- endif %}
  401. {%- endif %}
  402. {{ column.java_field }}: [
  403. { required: true, message: "{{ comment }}不能为空", trigger: {% if column.html_type == 'select' or column.html_type == 'radio' %}"change"{% else %}"blur"{% endif %} }
  404. ]{% if not loop.last %},{% endif %}
  405. {%- endfor %}
  406. }
  407. };
  408. },
  409. created() {
  410. this.getList();
  411. },
  412. methods: {
  413. /** 查询{{ table.function_name }}列表 */
  414. getList() {
  415. this.loading = true;
  416. {%- set has_datetime = false %}
  417. {%- for column in table.columns %}
  418. {%- if column.html_type == 'datetime' %}
  419. {%- if not has_datetime %}
  420. this.queryParams.params = {};
  421. {%- set has_datetime = true %}
  422. {%- endif %}
  423. {%- set attr_name = capitalize_first(column.java_field) %}
  424. if (null != this.dateRange{{ attr_name }} && '' != this.dateRange{{ attr_name }}.toString()) {
  425. this.queryParams.params["begin{{ column.java_field }}"] = this.dateRange{{ attr_name }}[0];
  426. this.queryParams.params["end{{ column.java_field }}"] = this.dateRange{{ attr_name }}[1];
  427. }
  428. {%- endif %}
  429. {%- endfor %}
  430. list{{ ApiName }}(this.queryParams).then(response => {
  431. this.{{ table.business_name }}List = response.rows;
  432. this.total = response.total;
  433. this.loading = false;
  434. });
  435. },
  436. // 取消按钮
  437. cancel() {
  438. this.open = false;
  439. this.reset();
  440. },
  441. // 表单重置
  442. reset() {
  443. this.form = {
  444. {%- for column in table.columns %}
  445. {%- if column.html_type == 'checkbox' %}
  446. {{ column.java_field }}: []{% if not loop.last %},{% endif %}
  447. {%- else %}
  448. {{ column.java_field }}: null{% if not loop.last %},{% endif %}
  449. {%- endif %}
  450. {%- endfor %}
  451. };
  452. this.resetForm("form");
  453. },
  454. /** 搜索按钮操作 */
  455. handleQuery() {
  456. this.queryParams.pageNum = 1;
  457. this.getList();
  458. },
  459. /** 重置按钮操作 */
  460. resetQuery() {
  461. {%- for column in table.columns %}
  462. {%- if column.html_type == 'datetime' %}
  463. {%- set attr_name = capitalize_first(column.java_field) %}
  464. this.dateRange{{ attr_name }} = [];
  465. {%- endif %}
  466. {%- endfor %}
  467. this.resetForm("queryForm");
  468. this.handleQuery();
  469. },
  470. // 多选框选中数据
  471. handleSelectionChange(selection) {
  472. this.ids = selection.map(item => item.{{ table.pk_column.java_field if table.pk_column }})
  473. this.single = selection.length!==1
  474. this.multiple = !selection.length
  475. },
  476. /** 新增按钮操作 */
  477. handleAdd() {
  478. this.reset();
  479. this.open = true;
  480. this.title = "添加{{ table.function_name }}";
  481. },
  482. /** 修改按钮操作 */
  483. handleUpdate(row) {
  484. this.reset();
  485. const {{ table.pk_column.java_field if table.pk_column }} = row.{{ table.pk_column.java_field if table.pk_column }} || this.ids
  486. get{{ ApiName }}({{ table.pk_column.java_field if table.pk_column }}).then(response => {
  487. this.form = response.data;
  488. {%- for column in table.columns %}
  489. {%- if column.html_type == 'checkbox' %}
  490. if (this.form.{{ column.java_field }}) {
  491. this.form.{{ column.java_field }} = this.form.{{ column.java_field }}.split(",");
  492. } else {
  493. this.form.{{ column.java_field }} = [];
  494. }
  495. {%- endif %}
  496. {%- endfor %}
  497. this.open = true;
  498. this.title = "修改{{ table.function_name }}";
  499. });
  500. },
  501. /** 提交按钮 */
  502. submitForm() {
  503. this.$refs["form"].validate(valid => {
  504. if (valid) {
  505. const submitData = this.buildSubmitData();
  506. if (submitData.{{ table.pk_column.java_field if table.pk_column }} != null) {
  507. update{{ ApiName }}(submitData).then(response => {
  508. this.$modal.msgSuccess("修改成功");
  509. this.open = false;
  510. this.getList();
  511. });
  512. } else {
  513. add{{ ApiName }}(submitData).then(response => {
  514. this.$modal.msgSuccess("新增成功");
  515. this.open = false;
  516. this.getList();
  517. });
  518. }
  519. }
  520. });
  521. },
  522. /** 删除按钮操作 */
  523. handleDelete(row) {
  524. const {{ table.business_name }}Ids = row.{{ table.pk_column.java_field if table.pk_column }} || this.ids;
  525. this.$modal.confirm('是否确认删除{{ table.function_name }}编号为"' + {{ table.business_name }}Ids + '"的数据项?').then(function() {
  526. return del{{ ApiName }}({{ table.business_name }}Ids);
  527. }).then(() => {
  528. this.getList();
  529. this.$modal.msgSuccess("删除成功");
  530. }).catch(() => {});
  531. },
  532. /** 导出按钮操作 */
  533. handleExport() {
  534. this.download('{{ table.module_name }}/{{ table.business_name }}/export', {
  535. ...this.queryParams
  536. }, `{{ table.business_name }}_${new Date().getTime()}.xlsx`)
  537. },
  538. /** 导入按钮操作 */
  539. handleImport() {
  540. this.upload.title = "{{ table.function_name }}导入";
  541. this.upload.open = true;
  542. },
  543. /** 下载模板操作 */
  544. importTemplate() {
  545. this.download(
  546. "{{ table.module_name }}/{{ table.business_name }}/importTemplate",
  547. {},
  548. "{{ table.business_name }}_template_" + new Date().getTime() + ".xlsx"
  549. );
  550. },
  551. // 文件上传中处理
  552. handleFileUploadProgress(event, file, fileList) {
  553. this.upload.isUploading = true;
  554. },
  555. // 文件上传成功处理
  556. handleFileSuccess(response, file, fileList) {
  557. this.upload.open = false;
  558. this.upload.isUploading = false;
  559. this.$refs.upload.clearFiles();
  560. this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
  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.$refs.upload.submit();
  592. }
  593. }
  594. };
  595. </script>