index.vue.vm 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  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}">
  136. <template slot-scope="scope">
  137. <dict-tag :options="${javaField}Options" :value="scope.row.${javaField}"/>
  138. </template>
  139. </el-table-column>
  140. #elseif($column.list && "" != $javaField)
  141. <el-table-column label="${comment}" align="center" prop="${javaField}" />
  142. #end
  143. #end
  144. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  145. <template slot-scope="scope">
  146. <el-button
  147. size="mini"
  148. type="text"
  149. icon="el-icon-edit"
  150. @click="handleUpdate(scope.row)"
  151. v-hasPermi="['${moduleName}:${businessName}:edit']"
  152. >修改</el-button>
  153. <el-button
  154. size="mini"
  155. type="text"
  156. icon="el-icon-delete"
  157. @click="handleDelete(scope.row)"
  158. v-hasPermi="['${moduleName}:${businessName}:remove']"
  159. >删除</el-button>
  160. </template>
  161. </el-table-column>
  162. </el-table>
  163. <pagination
  164. v-show="total>0"
  165. :total="total"
  166. :page.sync="queryParams.pageNum"
  167. :limit.sync="queryParams.pageSize"
  168. @pagination="getList"
  169. />
  170. <!-- 添加或修改${functionName}对话框 -->
  171. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  172. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  173. #foreach($column in $columns)
  174. #set($field=$column.javaField)
  175. #if($column.insert && !$column.pk)
  176. #if(($column.usableColumn) || (!$column.superColumn))
  177. #set($parentheseIndex=$column.columnComment.indexOf("("))
  178. #if($parentheseIndex != -1)
  179. #set($comment=$column.columnComment.substring(0, $parentheseIndex))
  180. #else
  181. #set($comment=$column.columnComment)
  182. #end
  183. #set($dictType=$column.dictType)
  184. #if($column.htmlType == "input")
  185. <el-form-item label="${comment}" prop="${field}">
  186. <el-input v-model="form.${field}" placeholder="请输入${comment}" />
  187. </el-form-item>
  188. #elseif($column.htmlType == "imageUpload")
  189. <el-form-item label="${comment}">
  190. <imageUpload v-model="form.${field}"/>
  191. </el-form-item>
  192. #elseif($column.htmlType == "fileUpload")
  193. <el-form-item label="${comment}">
  194. <fileUpload v-model="form.${field}"/>
  195. </el-form-item>
  196. #elseif($column.htmlType == "editor")
  197. <el-form-item label="${comment}">
  198. <editor v-model="form.${field}" :min-height="192"/>
  199. </el-form-item>
  200. #elseif($column.htmlType == "select" && "" != $dictType)
  201. <el-form-item label="${comment}" prop="${field}">
  202. <el-select v-model="form.${field}" placeholder="请选择${comment}">
  203. <el-option
  204. v-for="dict in ${field}Options"
  205. :key="dict.dictValue"
  206. :label="dict.dictLabel"
  207. #if($column.javaType == "Integer" || $column.javaType == "Long"):value="parseInt(dict.dictValue)"#else:value="dict.dictValue"#end
  208. ></el-option>
  209. </el-select>
  210. </el-form-item>
  211. #elseif($column.htmlType == "select" && $dictType)
  212. <el-form-item label="${comment}" prop="${field}">
  213. <el-select v-model="form.${field}" placeholder="请选择${comment}">
  214. <el-option label="请选择字典生成" value="" />
  215. </el-select>
  216. </el-form-item>
  217. #elseif($column.htmlType == "checkbox" && "" != $dictType)
  218. <el-form-item label="${comment}">
  219. <el-checkbox-group v-model="form.${field}">
  220. <el-checkbox
  221. v-for="dict in ${field}Options"
  222. :key="dict.dictValue"
  223. :label="dict.dictValue">
  224. {{dict.dictLabel}}
  225. </el-checkbox>
  226. </el-checkbox-group>
  227. </el-form-item>
  228. #elseif($column.htmlType == "checkbox" && $dictType)
  229. <el-form-item label="${comment}">
  230. <el-checkbox-group v-model="form.${field}">
  231. <el-checkbox>请选择字典生成</el-checkbox>
  232. </el-checkbox-group>
  233. </el-form-item>
  234. #elseif($column.htmlType == "radio" && "" != $dictType)
  235. <el-form-item label="${comment}">
  236. <el-radio-group v-model="form.${field}">
  237. <el-radio
  238. v-for="dict in ${field}Options"
  239. :key="dict.dictValue"
  240. #if($column.javaType == "Integer" || $column.javaType == "Long"):label="parseInt(dict.dictValue)"#else:label="dict.dictValue"#end
  241. >{{dict.dictLabel}}</el-radio>
  242. </el-radio-group>
  243. </el-form-item>
  244. #elseif($column.htmlType == "radio" && $dictType)
  245. <el-form-item label="${comment}">
  246. <el-radio-group v-model="form.${field}">
  247. <el-radio label="1">请选择字典生成</el-radio>
  248. </el-radio-group>
  249. </el-form-item>
  250. #elseif($column.htmlType == "datetime")
  251. <el-form-item label="${comment}" prop="${field}">
  252. <el-date-picker clearable size="small"
  253. v-model="form.${field}"
  254. type="date"
  255. value-format="yyyy-MM-dd"
  256. placeholder="选择${comment}">
  257. </el-date-picker>
  258. </el-form-item>
  259. #elseif($column.htmlType == "textarea")
  260. <el-form-item label="${comment}" prop="${field}">
  261. <el-input v-model="form.${field}" type="textarea" placeholder="请输入内容" />
  262. </el-form-item>
  263. #end
  264. #end
  265. #end
  266. #end
  267. #if($table.sub)
  268. <el-divider content-position="center">${subTable.functionName}信息</el-divider>
  269. <el-row :gutter="10" class="mb8">
  270. <el-col :span="1.5">
  271. <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAdd${subClassName}">添加</el-button>
  272. </el-col>
  273. <el-col :span="1.5">
  274. <el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDelete${subClassName}">删除</el-button>
  275. </el-col>
  276. </el-row>
  277. <el-table :data="${subclassName}List" :row-class-name="row${subClassName}Index" @selection-change="handle${subClassName}SelectionChange" ref="${subclassName}">
  278. <el-table-column type="selection" width="50" align="center" />
  279. <el-table-column label="序号" align="center" prop="index" width="50"/>
  280. #foreach($column in $subTable.columns)
  281. #set($javaField=$column.javaField)
  282. #set($parentheseIndex=$column.columnComment.indexOf("("))
  283. #if($parentheseIndex != -1)
  284. #set($comment=$column.columnComment.substring(0, $parentheseIndex))
  285. #else
  286. #set($comment=$column.columnComment)
  287. #end
  288. #if($column.pk || $javaField == ${subTableFkclassName})
  289. #elseif($column.list && "" != $javaField)
  290. <el-table-column label="$comment" prop="${javaField}">
  291. <template slot-scope="scope">
  292. <el-input v-model="scope.row.$javaField" placeholder="请输入$comment" />
  293. </template>
  294. </el-table-column>
  295. #end
  296. #end
  297. </el-table>
  298. #end
  299. </el-form>
  300. <div slot="footer" class="dialog-footer">
  301. <el-button type="primary" @click="submitForm">确 定</el-button>
  302. <el-button @click="cancel">取 消</el-button>
  303. </div>
  304. </el-dialog>
  305. </div>
  306. </template>
  307. <script>
  308. import { list${BusinessName}, get${BusinessName}, del${BusinessName}, add${BusinessName}, update${BusinessName} } from "@/api/${moduleName}/${businessName}";
  309. export default {
  310. name: "${BusinessName}",
  311. data() {
  312. return {
  313. // 遮罩层
  314. loading: true,
  315. // 选中数组
  316. ids: [],
  317. #if($table.sub)
  318. // 子表选中数据
  319. checked${subClassName}: [],
  320. #end
  321. // 非单个禁用
  322. single: true,
  323. // 非多个禁用
  324. multiple: true,
  325. // 显示搜索条件
  326. showSearch: true,
  327. // 总条数
  328. total: 0,
  329. // ${functionName}表格数据
  330. ${businessName}List: [],
  331. #if($table.sub)
  332. // ${subTable.functionName}表格数据
  333. ${subclassName}List: [],
  334. #end
  335. // 弹出层标题
  336. title: "",
  337. // 是否显示弹出层
  338. open: false,
  339. #foreach ($column in $columns)
  340. #set($parentheseIndex=$column.columnComment.indexOf("("))
  341. #if($parentheseIndex != -1)
  342. #set($comment=$column.columnComment.substring(0, $parentheseIndex))
  343. #else
  344. #set($comment=$column.columnComment)
  345. #end
  346. #if(${column.dictType} != '')
  347. // $comment字典
  348. ${column.javaField}Options: [],
  349. #elseif($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
  350. #set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
  351. // $comment时间范围
  352. daterange${AttrName}: [],
  353. #end
  354. #end
  355. // 查询参数
  356. queryParams: {
  357. pageNum: 1,
  358. pageSize: 10,
  359. #foreach ($column in $columns)
  360. #if($column.query)
  361. $column.javaField: null#if($velocityCount != $columns.size()),#end
  362. #end
  363. #end
  364. },
  365. // 表单参数
  366. form: {},
  367. // 表单校验
  368. rules: {
  369. #foreach ($column in $columns)
  370. #if($column.required)
  371. #set($parentheseIndex=$column.columnComment.indexOf("("))
  372. #if($parentheseIndex != -1)
  373. #set($comment=$column.columnComment.substring(0, $parentheseIndex))
  374. #else
  375. #set($comment=$column.columnComment)
  376. #end
  377. $column.javaField: [
  378. { required: true, message: "$comment不能为空", trigger: #if($column.htmlType == "select")"change"#else"blur"#end }
  379. ]#if($velocityCount != $columns.size()),#end
  380. #end
  381. #end
  382. }
  383. };
  384. },
  385. created() {
  386. this.getList();
  387. #foreach ($column in $columns)
  388. #if(${column.dictType} != '')
  389. this.getDicts("${column.dictType}").then(response => {
  390. this.${column.javaField}Options = response.data;
  391. });
  392. #end
  393. #end
  394. },
  395. methods: {
  396. /** 查询${functionName}列表 */
  397. getList() {
  398. this.loading = true;
  399. #foreach ($column in $columns)
  400. #if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
  401. this.queryParams.params = {};
  402. #break
  403. #end
  404. #end
  405. #foreach ($column in $columns)
  406. #if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
  407. #set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
  408. if (null != this.daterange${AttrName} && '' != this.daterange${AttrName}) {
  409. this.queryParams.params["begin${AttrName}"] = this.daterange${AttrName}[0];
  410. this.queryParams.params["end${AttrName}"] = this.daterange${AttrName}[1];
  411. }
  412. #end
  413. #end
  414. list${BusinessName}(this.queryParams).then(response => {
  415. this.${businessName}List = response.rows;
  416. this.total = response.total;
  417. this.loading = false;
  418. });
  419. },
  420. // 取消按钮
  421. cancel() {
  422. this.open = false;
  423. this.reset();
  424. },
  425. // 表单重置
  426. reset() {
  427. this.form = {
  428. #foreach ($column in $columns)
  429. #if($column.htmlType == "radio")
  430. $column.javaField: #if($column.javaType == "Integer" || $column.javaType == "Long")0#else"0"#end#if($velocityCount != $columns.size()),#end
  431. #elseif($column.htmlType == "checkbox")
  432. $column.javaField: []#if($velocityCount != $columns.size()),#end
  433. #else
  434. $column.javaField: null#if($velocityCount != $columns.size()),#end
  435. #end
  436. #end
  437. };
  438. #if($table.sub)
  439. this.${subclassName}List = [];
  440. #end
  441. this.resetForm("form");
  442. },
  443. /** 搜索按钮操作 */
  444. handleQuery() {
  445. this.queryParams.pageNum = 1;
  446. this.getList();
  447. },
  448. /** 重置按钮操作 */
  449. resetQuery() {
  450. #foreach ($column in $columns)
  451. #if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
  452. #set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
  453. this.daterange${AttrName} = [];
  454. #end
  455. #end
  456. this.resetForm("queryForm");
  457. this.handleQuery();
  458. },
  459. // 多选框选中数据
  460. handleSelectionChange(selection) {
  461. this.ids = selection.map(item => item.${pkColumn.javaField})
  462. this.single = selection.length!==1
  463. this.multiple = !selection.length
  464. },
  465. /** 新增按钮操作 */
  466. handleAdd() {
  467. this.reset();
  468. this.open = true;
  469. this.title = "添加${functionName}";
  470. },
  471. /** 修改按钮操作 */
  472. handleUpdate(row) {
  473. this.reset();
  474. const ${pkColumn.javaField} = row.${pkColumn.javaField} || this.ids
  475. get${BusinessName}(${pkColumn.javaField}).then(response => {
  476. this.form = response.data;
  477. #foreach ($column in $columns)
  478. #if($column.htmlType == "checkbox")
  479. this.form.$column.javaField = this.form.${column.javaField}.split(",");
  480. #end
  481. #end
  482. #if($table.sub)
  483. this.${subclassName}List = response.data.${subclassName}List;
  484. #end
  485. this.open = true;
  486. this.title = "修改${functionName}";
  487. });
  488. },
  489. /** 提交按钮 */
  490. submitForm() {
  491. this.#[[$]]#refs["form"].validate(valid => {
  492. if (valid) {
  493. #foreach ($column in $columns)
  494. #if($column.htmlType == "checkbox")
  495. this.form.$column.javaField = this.form.${column.javaField}.join(",");
  496. #end
  497. #end
  498. #if($table.sub)
  499. this.form.${subclassName}List = this.${subclassName}List;
  500. #end
  501. if (this.form.${pkColumn.javaField} != null) {
  502. update${BusinessName}(this.form).then(response => {
  503. this.msgSuccess("修改成功");
  504. this.open = false;
  505. this.getList();
  506. });
  507. } else {
  508. add${BusinessName}(this.form).then(response => {
  509. this.msgSuccess("新增成功");
  510. this.open = false;
  511. this.getList();
  512. });
  513. }
  514. }
  515. });
  516. },
  517. /** 删除按钮操作 */
  518. handleDelete(row) {
  519. const ${pkColumn.javaField}s = row.${pkColumn.javaField} || this.ids;
  520. this.$confirm('是否确认删除${functionName}编号为"' + ${pkColumn.javaField}s + '"的数据项?', "警告", {
  521. confirmButtonText: "确定",
  522. cancelButtonText: "取消",
  523. type: "warning"
  524. }).then(function() {
  525. return del${BusinessName}(${pkColumn.javaField}s);
  526. }).then(() => {
  527. this.getList();
  528. this.msgSuccess("删除成功");
  529. }).catch(() => {});
  530. },
  531. #if($table.sub)
  532. /** ${subTable.functionName}序号 */
  533. row${subClassName}Index({ row, rowIndex }) {
  534. row.index = rowIndex + 1;
  535. },
  536. /** ${subTable.functionName}添加按钮操作 */
  537. handleAdd${subClassName}() {
  538. let obj = {};
  539. #foreach($column in $subTable.columns)
  540. #if($column.pk || $column.javaField == ${subTableFkclassName})
  541. #elseif($column.list && "" != $javaField)
  542. obj.$column.javaField = "";
  543. #end
  544. #end
  545. this.${subclassName}List.push(obj);
  546. },
  547. /** ${subTable.functionName}删除按钮操作 */
  548. handleDelete${subClassName}() {
  549. if (this.checked${subClassName}.length == 0) {
  550. this.msgError("请先选择要删除的${subTable.functionName}数据");
  551. } else {
  552. const ${subclassName}List = this.${subclassName}List;
  553. const checked${subClassName} = this.checked${subClassName};
  554. this.${subclassName}List = ${subclassName}List.filter(function(item) {
  555. return checked${subClassName}.indexOf(item.index) == -1
  556. });
  557. }
  558. },
  559. /** 复选框选中数据 */
  560. handle${subClassName}SelectionChange(selection) {
  561. this.checked${subClassName} = selection.map(item => item.index)
  562. },
  563. #end
  564. /** 导出按钮操作 */
  565. handleExport() {
  566. this.download('${moduleName}/${businessName}/export', {
  567. ...this.queryParams
  568. }, `${moduleName}_${businessName}.xlsx`)
  569. }
  570. }
  571. };
  572. </script>