index.vue.vm 23 KB

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