index.vue.vm 18 KB

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