index.vue.vm 20 KB

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