index.vue.vm 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
  4. #foreach($column in $columns)
  5. #if($column.query)
  6. #set($dictType=$column.dictType)
  7. #set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
  8. #set($parentheseIndex=$column.columnComment.indexOf("("))
  9. #if($parentheseIndex != -1)
  10. #set($comment=$column.columnComment.substring(0, $parentheseIndex))
  11. #else
  12. #set($comment=$column.columnComment)
  13. #end
  14. #if($column.htmlType == "input")
  15. <el-form-item label="${comment}" prop="${column.javaField}">
  16. <el-input
  17. v-model="queryParams.${column.javaField}"
  18. placeholder="请输入${comment}"
  19. clearable
  20. size="small"
  21. @keyup.enter.native="handleQuery"
  22. />
  23. </el-form-item>
  24. #elseif(($column.htmlType == "select" || $column.htmlType == "radio") && "" != $dictType)
  25. <el-form-item label="${comment}" prop="${column.javaField}">
  26. <el-select v-model="queryParams.${column.javaField}" placeholder="请选择${comment}" clearable size="small">
  27. <el-option
  28. v-for="dict in ${column.javaField}Options"
  29. :key="dict.dictValue"
  30. :label="dict.dictLabel"
  31. :value="dict.dictValue"
  32. />
  33. </el-select>
  34. </el-form-item>
  35. #elseif(($column.htmlType == "select" || $column.htmlType == "radio") && $dictType)
  36. <el-form-item label="${comment}" prop="${column.javaField}">
  37. <el-select v-model="queryParams.${column.javaField}" placeholder="请选择${comment}" clearable size="small">
  38. <el-option label="请选择字典生成" value="" />
  39. </el-select>
  40. </el-form-item>
  41. #elseif($column.htmlType == "datetime" && $column.queryType != "BETWEEN")
  42. <el-form-item label="${comment}" prop="${column.javaField}">
  43. <el-date-picker clearable size="small"
  44. v-model="queryParams.${column.javaField}"
  45. type="date"
  46. value-format="yyyy-MM-dd"
  47. placeholder="选择${comment}">
  48. </el-date-picker>
  49. </el-form-item>
  50. #elseif($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
  51. <el-form-item label="${comment}">
  52. <el-date-picker
  53. v-model="daterange${AttrName}"
  54. size="small"
  55. style="width: 240px"
  56. value-format="yyyy-MM-dd"
  57. type="daterange"
  58. range-separator="-"
  59. start-placeholder="开始日期"
  60. end-placeholder="结束日期"
  61. ></el-date-picker>
  62. </el-form-item>
  63. #end
  64. #end
  65. #end
  66. <el-form-item>
  67. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  68. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  69. </el-form-item>
  70. </el-form>
  71. <el-row :gutter="10" class="mb8">
  72. <el-col :span="1.5">
  73. <el-button
  74. type="primary"
  75. plain
  76. icon="el-icon-plus"
  77. size="mini"
  78. @click="handleAdd"
  79. v-hasPermi="['${moduleName}:${businessName}:add']"
  80. >新增</el-button>
  81. </el-col>
  82. <el-col :span="1.5">
  83. <el-button
  84. type="success"
  85. plain
  86. icon="el-icon-edit"
  87. size="mini"
  88. :disabled="single"
  89. @click="handleUpdate"
  90. v-hasPermi="['${moduleName}:${businessName}:edit']"
  91. >修改</el-button>
  92. </el-col>
  93. <el-col :span="1.5">
  94. <el-button
  95. type="danger"
  96. plain
  97. icon="el-icon-delete"
  98. size="mini"
  99. :disabled="multiple"
  100. @click="handleDelete"
  101. v-hasPermi="['${moduleName}:${businessName}:remove']"
  102. >删除</el-button>
  103. </el-col>
  104. <el-col :span="1.5">
  105. <el-button
  106. type="warning"
  107. plain
  108. icon="el-icon-download"
  109. size="mini"
  110. @click="handleExport"
  111. v-hasPermi="['${moduleName}:${businessName}:export']"
  112. >导出</el-button>
  113. </el-col>
  114. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  115. </el-row>
  116. <el-table v-loading="loading" :data="${businessName}List" @selection-change="handleSelectionChange">
  117. <el-table-column type="selection" width="55" align="center" />
  118. #foreach($column in $columns)
  119. #set($javaField=$column.javaField)
  120. #set($parentheseIndex=$column.columnComment.indexOf("("))
  121. #if($parentheseIndex != -1)
  122. #set($comment=$column.columnComment.substring(0, $parentheseIndex))
  123. #else
  124. #set($comment=$column.columnComment)
  125. #end
  126. #if($column.pk)
  127. <el-table-column label="${comment}" align="center" prop="${javaField}" />
  128. #elseif($column.list && $column.htmlType == "datetime")
  129. <el-table-column label="${comment}" align="center" prop="${javaField}" width="180">
  130. <template slot-scope="scope">
  131. <span>{{ parseTime(scope.row.${javaField}, '{y}-{m}-{d}') }}</span>
  132. </template>
  133. </el-table-column>
  134. #elseif($column.list && "" != $column.dictType)
  135. <el-table-column label="${comment}" align="center" prop="${javaField}" :formatter="${javaField}Format" />
  136. #elseif($column.list && "" != $javaField)
  137. <el-table-column label="${comment}" align="center" prop="${javaField}" />
  138. #end
  139. #end
  140. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  141. <template slot-scope="scope">
  142. <el-button
  143. size="mini"
  144. type="text"
  145. icon="el-icon-edit"
  146. @click="handleUpdate(scope.row)"
  147. v-hasPermi="['${moduleName}:${businessName}:edit']"
  148. >修改</el-button>
  149. <el-button
  150. size="mini"
  151. type="text"
  152. icon="el-icon-delete"
  153. @click="handleDelete(scope.row)"
  154. v-hasPermi="['${moduleName}:${businessName}:remove']"
  155. >删除</el-button>
  156. </template>
  157. </el-table-column>
  158. </el-table>
  159. <pagination
  160. v-show="total>0"
  161. :total="total"
  162. :page.sync="queryParams.pageNum"
  163. :limit.sync="queryParams.pageSize"
  164. @pagination="getList"
  165. />
  166. <!-- 添加或修改${functionName}对话框 -->
  167. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  168. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  169. #foreach($column in $columns)
  170. #set($field=$column.javaField)
  171. #if($column.insert && !$column.pk)
  172. #if(($column.usableColumn) || (!$column.superColumn))
  173. #set($parentheseIndex=$column.columnComment.indexOf("("))
  174. #if($parentheseIndex != -1)
  175. #set($comment=$column.columnComment.substring(0, $parentheseIndex))
  176. #else
  177. #set($comment=$column.columnComment)
  178. #end
  179. #set($dictType=$column.dictType)
  180. #if($column.htmlType == "input")
  181. <el-form-item label="${comment}" prop="${field}">
  182. <el-input v-model="form.${field}" placeholder="请输入${comment}" />
  183. </el-form-item>
  184. #elseif($column.htmlType == "imageUpload")
  185. <el-form-item label="${comment}">
  186. <imageUpload v-model="form.${field}"/>
  187. </el-form-item>
  188. #elseif($column.htmlType == "fileUpload")
  189. <el-form-item label="${comment}">
  190. <fileUpload v-model="form.${field}"/>
  191. </el-form-item>
  192. #elseif($column.htmlType == "editor")
  193. <el-form-item label="${comment}">
  194. <editor v-model="form.${field}" :min-height="192"/>
  195. </el-form-item>
  196. #elseif($column.htmlType == "select" && "" != $dictType)
  197. <el-form-item label="${comment}" prop="${field}">
  198. <el-select v-model="form.${field}" placeholder="请选择${comment}">
  199. <el-option
  200. v-for="dict in ${field}Options"
  201. :key="dict.dictValue"
  202. :label="dict.dictLabel"
  203. #if($column.javaType == "Integer" || $column.javaType == "Long"):value="parseInt(dict.dictValue)"#else:value="dict.dictValue"#end
  204. ></el-option>
  205. </el-select>
  206. </el-form-item>
  207. #elseif($column.htmlType == "select" && $dictType)
  208. <el-form-item label="${comment}" prop="${field}">
  209. <el-select v-model="form.${field}" placeholder="请选择${comment}">
  210. <el-option label="请选择字典生成" value="" />
  211. </el-select>
  212. </el-form-item>
  213. #elseif($column.htmlType == "checkbox" && "" != $dictType)
  214. <el-form-item label="${comment}">
  215. <el-checkbox-group v-model="form.${field}">
  216. <el-checkbox
  217. v-for="dict in ${field}Options"
  218. :key="dict.dictValue"
  219. :label="dict.dictValue">
  220. {{dict.dictLabel}}
  221. </el-checkbox>
  222. </el-checkbox-group>
  223. </el-form-item>
  224. #elseif($column.htmlType == "checkbox" && $dictType)
  225. <el-form-item label="${comment}">
  226. <el-checkbox-group v-model="form.${field}">
  227. <el-checkbox>请选择字典生成</el-checkbox>
  228. </el-checkbox-group>
  229. </el-form-item>
  230. #elseif($column.htmlType == "radio" && "" != $dictType)
  231. <el-form-item label="${comment}">
  232. <el-radio-group v-model="form.${field}">
  233. <el-radio
  234. v-for="dict in ${field}Options"
  235. :key="dict.dictValue"
  236. #if($column.javaType == "Integer" || $column.javaType == "Long"):label="parseInt(dict.dictValue)"#else:label="dict.dictValue"#end
  237. >{{dict.dictLabel}}</el-radio>
  238. </el-radio-group>
  239. </el-form-item>
  240. #elseif($column.htmlType == "radio" && $dictType)
  241. <el-form-item label="${comment}">
  242. <el-radio-group v-model="form.${field}">
  243. <el-radio label="1">请选择字典生成</el-radio>
  244. </el-radio-group>
  245. </el-form-item>
  246. #elseif($column.htmlType == "datetime")
  247. <el-form-item label="${comment}" prop="${field}">
  248. <el-date-picker clearable size="small"
  249. v-model="form.${field}"
  250. type="date"
  251. value-format="yyyy-MM-dd"
  252. placeholder="选择${comment}">
  253. </el-date-picker>
  254. </el-form-item>
  255. #elseif($column.htmlType == "textarea")
  256. <el-form-item label="${comment}" prop="${field}">
  257. <el-input v-model="form.${field}" type="textarea" placeholder="请输入内容" />
  258. </el-form-item>
  259. #end
  260. #end
  261. #end
  262. #end
  263. </el-form>
  264. <div slot="footer" class="dialog-footer">
  265. <el-button type="primary" @click="submitForm">确 定</el-button>
  266. <el-button @click="cancel">取 消</el-button>
  267. </div>
  268. </el-dialog>
  269. </div>
  270. </template>
  271. <script>
  272. import { list${BusinessName}, get${BusinessName}, del${BusinessName}, add${BusinessName}, update${BusinessName} } from "@/api/${moduleName}/${businessName}";
  273. #foreach($column in $columns)
  274. #if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "imageUpload")
  275. import ImageUpload from '@/components/ImageUpload';
  276. #break
  277. #end
  278. #end
  279. #foreach($column in $columns)
  280. #if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "fileUpload")
  281. import FileUpload from '@/components/FileUpload';
  282. #break
  283. #end
  284. #end
  285. #foreach($column in $columns)
  286. #if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "editor")
  287. import Editor from '@/components/Editor';
  288. #break
  289. #end
  290. #end
  291. export default {
  292. name: "${BusinessName}",
  293. components: {
  294. #foreach($column in $columns)
  295. #if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "imageUpload")
  296. ImageUpload,
  297. #break
  298. #end
  299. #end
  300. #foreach($column in $columns)
  301. #if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "fileUpload")
  302. FileUpload,
  303. #break
  304. #end
  305. #end
  306. #foreach($column in $columns)
  307. #if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "editor")
  308. Editor,
  309. #break
  310. #end
  311. #end
  312. },
  313. data() {
  314. return {
  315. // 遮罩层
  316. loading: true,
  317. // 选中数组
  318. ids: [],
  319. // 非单个禁用
  320. single: true,
  321. // 非多个禁用
  322. multiple: true,
  323. // 显示搜索条件
  324. showSearch: true,
  325. // 总条数
  326. total: 0,
  327. // ${functionName}表格数据
  328. ${businessName}List: [],
  329. // 弹出层标题
  330. title: "",
  331. // 是否显示弹出层
  332. open: false,
  333. #foreach ($column in $columns)
  334. #set($parentheseIndex=$column.columnComment.indexOf("("))
  335. #if($parentheseIndex != -1)
  336. #set($comment=$column.columnComment.substring(0, $parentheseIndex))
  337. #else
  338. #set($comment=$column.columnComment)
  339. #end
  340. #if(${column.dictType} != '')
  341. // $comment字典
  342. ${column.javaField}Options: [],
  343. #elseif($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
  344. #set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
  345. // $comment时间范围
  346. daterange${AttrName}: [],
  347. #end
  348. #end
  349. // 查询参数
  350. queryParams: {
  351. pageNum: 1,
  352. pageSize: 10,
  353. #foreach ($column in $columns)
  354. #if($column.query)
  355. $column.javaField: null#if($velocityCount != $columns.size()),#end
  356. #end
  357. #end
  358. },
  359. // 表单参数
  360. form: {},
  361. // 表单校验
  362. rules: {
  363. #foreach ($column in $columns)
  364. #if($column.required)
  365. #set($parentheseIndex=$column.columnComment.indexOf("("))
  366. #if($parentheseIndex != -1)
  367. #set($comment=$column.columnComment.substring(0, $parentheseIndex))
  368. #else
  369. #set($comment=$column.columnComment)
  370. #end
  371. $column.javaField: [
  372. { required: true, message: "$comment不能为空", trigger: #if($column.htmlType == "select")"change"#else"blur"#end }
  373. ]#if($velocityCount != $columns.size()),#end
  374. #end
  375. #end
  376. }
  377. };
  378. },
  379. created() {
  380. this.getList();
  381. #foreach ($column in $columns)
  382. #if(${column.dictType} != '')
  383. this.getDicts("${column.dictType}").then(response => {
  384. this.${column.javaField}Options = response.data;
  385. });
  386. #end
  387. #end
  388. },
  389. methods: {
  390. /** 查询${functionName}列表 */
  391. getList() {
  392. this.loading = true;
  393. #foreach ($column in $columns)
  394. #if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
  395. this.queryParams.params = {};
  396. #break
  397. #end
  398. #end
  399. #foreach ($column in $columns)
  400. #if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
  401. #set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
  402. if (null != this.daterange${AttrName} && '' != this.daterange${AttrName}) {
  403. this.queryParams.params["begin${AttrName}"] = this.daterange${AttrName}[0];
  404. this.queryParams.params["end${AttrName}"] = this.daterange${AttrName}[1];
  405. }
  406. #end
  407. #end
  408. list${BusinessName}(this.queryParams).then(response => {
  409. this.${businessName}List = response.rows;
  410. this.total = response.total;
  411. this.loading = false;
  412. });
  413. },
  414. #foreach ($column in $columns)
  415. #if(${column.dictType} != '')
  416. #set($parentheseIndex=$column.columnComment.indexOf("("))
  417. #if($parentheseIndex != -1)
  418. #set($comment=$column.columnComment.substring(0, $parentheseIndex))
  419. #else
  420. #set($comment=$column.columnComment)
  421. #end
  422. // $comment字典翻译
  423. ${column.javaField}Format(row, column) {
  424. return this.selectDictLabel#if($column.htmlType == "checkbox")s#end(this.${column.javaField}Options, row.${column.javaField});
  425. },
  426. #end
  427. #end
  428. // 取消按钮
  429. cancel() {
  430. this.open = false;
  431. this.reset();
  432. },
  433. // 表单重置
  434. reset() {
  435. this.form = {
  436. #foreach ($column in $columns)
  437. #if($column.htmlType == "radio")
  438. $column.javaField: #if($column.javaType == "Integer" || $column.javaType == "Long")0#else"0"#end#if($velocityCount != $columns.size()),#end
  439. #elseif($column.htmlType == "checkbox")
  440. $column.javaField: []#if($velocityCount != $columns.size()),#end
  441. #else
  442. $column.javaField: null#if($velocityCount != $columns.size()),#end
  443. #end
  444. #end
  445. };
  446. this.resetForm("form");
  447. },
  448. /** 搜索按钮操作 */
  449. handleQuery() {
  450. this.queryParams.pageNum = 1;
  451. this.getList();
  452. },
  453. /** 重置按钮操作 */
  454. resetQuery() {
  455. #foreach ($column in $columns)
  456. #if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
  457. #set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
  458. this.daterange${AttrName} = [];
  459. #end
  460. #end
  461. this.resetForm("queryForm");
  462. this.handleQuery();
  463. },
  464. // 多选框选中数据
  465. handleSelectionChange(selection) {
  466. this.ids = selection.map(item => item.${pkColumn.javaField})
  467. this.single = selection.length!==1
  468. this.multiple = !selection.length
  469. },
  470. /** 新增按钮操作 */
  471. handleAdd() {
  472. this.reset();
  473. this.open = true;
  474. this.title = "添加${functionName}";
  475. },
  476. /** 修改按钮操作 */
  477. handleUpdate(row) {
  478. this.reset();
  479. const ${pkColumn.javaField} = row.${pkColumn.javaField} || this.ids
  480. get${BusinessName}(${pkColumn.javaField}).then(response => {
  481. this.form = response.data;
  482. #foreach ($column in $columns)
  483. #if($column.htmlType == "checkbox")
  484. this.form.$column.javaField = this.form.${column.javaField}.split(",");
  485. #end
  486. #end
  487. this.open = true;
  488. this.title = "修改${functionName}";
  489. });
  490. },
  491. /** 提交按钮 */
  492. submitForm() {
  493. this.#[[$]]#refs["form"].validate(valid => {
  494. if (valid) {
  495. #foreach ($column in $columns)
  496. #if($column.htmlType == "checkbox")
  497. this.form.$column.javaField = this.form.${column.javaField}.join(",");
  498. #end
  499. #end
  500. if (this.form.${pkColumn.javaField} != null) {
  501. update${BusinessName}(this.form).then(response => {
  502. this.msgSuccess("修改成功");
  503. this.open = false;
  504. this.getList();
  505. });
  506. } else {
  507. add${BusinessName}(this.form).then(response => {
  508. this.msgSuccess("新增成功");
  509. this.open = false;
  510. this.getList();
  511. });
  512. }
  513. }
  514. });
  515. },
  516. /** 删除按钮操作 */
  517. handleDelete(row) {
  518. const ${pkColumn.javaField}s = row.${pkColumn.javaField} || this.ids;
  519. this.$confirm('是否确认删除${functionName}编号为"' + ${pkColumn.javaField}s + '"的数据项?', "警告", {
  520. confirmButtonText: "确定",
  521. cancelButtonText: "取消",
  522. type: "warning"
  523. }).then(function() {
  524. return del${BusinessName}(${pkColumn.javaField}s);
  525. }).then(() => {
  526. this.getList();
  527. this.msgSuccess("删除成功");
  528. })
  529. },
  530. /** 导出按钮操作 */
  531. handleExport() {
  532. this.download('${moduleName}/${businessName}/export', {
  533. ...this.queryParams
  534. }, `${moduleName}_${businessName}.xlsx`)
  535. }
  536. }
  537. };
  538. </script>