index.vue.vm 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  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. #if($table.sub)
  264. <el-divider content-position="center">${subTable.functionName}信息</el-divider>
  265. <el-row :gutter="10" class="mb8">
  266. <el-col :span="1.5">
  267. <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAdd${subClassName}">添加</el-button>
  268. </el-col>
  269. <el-col :span="1.5">
  270. <el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDelete${subClassName}">删除</el-button>
  271. </el-col>
  272. </el-row>
  273. <el-table :data="${subclassName}List" :row-class-name="row${subClassName}Index" @selection-change="handle${subClassName}SelectionChange" ref="${subclassName}">
  274. <el-table-column type="selection" width="50" align="center" />
  275. <el-table-column label="序号" align="center" prop="index" width="50"/>
  276. #foreach($column in $subTable.columns)
  277. #set($javaField=$column.javaField)
  278. #set($parentheseIndex=$column.columnComment.indexOf("("))
  279. #if($parentheseIndex != -1)
  280. #set($comment=$column.columnComment.substring(0, $parentheseIndex))
  281. #else
  282. #set($comment=$column.columnComment)
  283. #end
  284. #if($column.pk || $javaField == ${subTableFkclassName})
  285. #elseif($column.list && "" != $javaField)
  286. <el-table-column label="$comment" prop="${javaField}">
  287. <template slot-scope="scope">
  288. <el-input v-model="scope.row.$javaField" placeholder="请输入$comment" />
  289. </template>
  290. </el-table-column>
  291. #end
  292. #end
  293. </el-table>
  294. #end
  295. </el-form>
  296. <div slot="footer" class="dialog-footer">
  297. <el-button type="primary" @click="submitForm">确 定</el-button>
  298. <el-button @click="cancel">取 消</el-button>
  299. </div>
  300. </el-dialog>
  301. </div>
  302. </template>
  303. <script>
  304. import { list${BusinessName}, get${BusinessName}, del${BusinessName}, add${BusinessName}, update${BusinessName} } from "@/api/${moduleName}/${businessName}";
  305. export default {
  306. name: "${BusinessName}",
  307. data() {
  308. return {
  309. // 遮罩层
  310. loading: true,
  311. // 选中数组
  312. ids: [],
  313. #if($table.sub)
  314. // 子表选中数据
  315. checked${subClassName}: [],
  316. #end
  317. // 非单个禁用
  318. single: true,
  319. // 非多个禁用
  320. multiple: true,
  321. // 显示搜索条件
  322. showSearch: true,
  323. // 总条数
  324. total: 0,
  325. // ${functionName}表格数据
  326. ${businessName}List: [],
  327. #if($table.sub)
  328. // ${subTable.functionName}表格数据
  329. ${subclassName}List: [],
  330. #end
  331. // 弹出层标题
  332. title: "",
  333. // 是否显示弹出层
  334. open: false,
  335. #foreach ($column in $columns)
  336. #set($parentheseIndex=$column.columnComment.indexOf("("))
  337. #if($parentheseIndex != -1)
  338. #set($comment=$column.columnComment.substring(0, $parentheseIndex))
  339. #else
  340. #set($comment=$column.columnComment)
  341. #end
  342. #if(${column.dictType} != '')
  343. // $comment字典
  344. ${column.javaField}Options: [],
  345. #elseif($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
  346. #set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
  347. // $comment时间范围
  348. daterange${AttrName}: [],
  349. #end
  350. #end
  351. // 查询参数
  352. queryParams: {
  353. pageNum: 1,
  354. pageSize: 10,
  355. #foreach ($column in $columns)
  356. #if($column.query)
  357. $column.javaField: null#if($velocityCount != $columns.size()),#end
  358. #end
  359. #end
  360. },
  361. // 表单参数
  362. form: {},
  363. // 表单校验
  364. rules: {
  365. #foreach ($column in $columns)
  366. #if($column.required)
  367. #set($parentheseIndex=$column.columnComment.indexOf("("))
  368. #if($parentheseIndex != -1)
  369. #set($comment=$column.columnComment.substring(0, $parentheseIndex))
  370. #else
  371. #set($comment=$column.columnComment)
  372. #end
  373. $column.javaField: [
  374. { required: true, message: "$comment不能为空", trigger: #if($column.htmlType == "select")"change"#else"blur"#end }
  375. ]#if($velocityCount != $columns.size()),#end
  376. #end
  377. #end
  378. }
  379. };
  380. },
  381. created() {
  382. this.getList();
  383. #foreach ($column in $columns)
  384. #if(${column.dictType} != '')
  385. this.getDicts("${column.dictType}").then(response => {
  386. this.${column.javaField}Options = response.data;
  387. });
  388. #end
  389. #end
  390. },
  391. methods: {
  392. /** 查询${functionName}列表 */
  393. getList() {
  394. this.loading = true;
  395. #foreach ($column in $columns)
  396. #if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
  397. this.queryParams.params = {};
  398. #break
  399. #end
  400. #end
  401. #foreach ($column in $columns)
  402. #if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
  403. #set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
  404. if (null != this.daterange${AttrName} && '' != this.daterange${AttrName}) {
  405. this.queryParams.params["begin${AttrName}"] = this.daterange${AttrName}[0];
  406. this.queryParams.params["end${AttrName}"] = this.daterange${AttrName}[1];
  407. }
  408. #end
  409. #end
  410. list${BusinessName}(this.queryParams).then(response => {
  411. this.${businessName}List = response.rows;
  412. this.total = response.total;
  413. this.loading = false;
  414. });
  415. },
  416. #foreach ($column in $columns)
  417. #if(${column.dictType} != '')
  418. #set($parentheseIndex=$column.columnComment.indexOf("("))
  419. #if($parentheseIndex != -1)
  420. #set($comment=$column.columnComment.substring(0, $parentheseIndex))
  421. #else
  422. #set($comment=$column.columnComment)
  423. #end
  424. // $comment字典翻译
  425. ${column.javaField}Format(row, column) {
  426. return this.selectDictLabel#if($column.htmlType == "checkbox")s#end(this.${column.javaField}Options, row.${column.javaField});
  427. },
  428. #end
  429. #end
  430. // 取消按钮
  431. cancel() {
  432. this.open = false;
  433. this.reset();
  434. },
  435. // 表单重置
  436. reset() {
  437. this.form = {
  438. #foreach ($column in $columns)
  439. #if($column.htmlType == "radio")
  440. $column.javaField: #if($column.javaType == "Integer" || $column.javaType == "Long")0#else"0"#end#if($velocityCount != $columns.size()),#end
  441. #elseif($column.htmlType == "checkbox")
  442. $column.javaField: []#if($velocityCount != $columns.size()),#end
  443. #else
  444. $column.javaField: null#if($velocityCount != $columns.size()),#end
  445. #end
  446. #end
  447. };
  448. #if($table.sub)
  449. this.${subclassName}List = [];
  450. #end
  451. this.resetForm("form");
  452. },
  453. /** 搜索按钮操作 */
  454. handleQuery() {
  455. this.queryParams.pageNum = 1;
  456. this.getList();
  457. },
  458. /** 重置按钮操作 */
  459. resetQuery() {
  460. #foreach ($column in $columns)
  461. #if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
  462. #set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
  463. this.daterange${AttrName} = [];
  464. #end
  465. #end
  466. this.resetForm("queryForm");
  467. this.handleQuery();
  468. },
  469. // 多选框选中数据
  470. handleSelectionChange(selection) {
  471. this.ids = selection.map(item => item.${pkColumn.javaField})
  472. this.single = selection.length!==1
  473. this.multiple = !selection.length
  474. },
  475. /** 新增按钮操作 */
  476. handleAdd() {
  477. this.reset();
  478. this.open = true;
  479. this.title = "添加${functionName}";
  480. },
  481. /** 修改按钮操作 */
  482. handleUpdate(row) {
  483. this.reset();
  484. const ${pkColumn.javaField} = row.${pkColumn.javaField} || this.ids
  485. get${BusinessName}(${pkColumn.javaField}).then(response => {
  486. this.form = response.data;
  487. #foreach ($column in $columns)
  488. #if($column.htmlType == "checkbox")
  489. this.form.$column.javaField = this.form.${column.javaField}.split(",");
  490. #end
  491. #end
  492. #if($table.sub)
  493. this.${subclassName}List = response.data.${subclassName}List;
  494. #end
  495. this.open = true;
  496. this.title = "修改${functionName}";
  497. });
  498. },
  499. /** 提交按钮 */
  500. submitForm() {
  501. this.#[[$]]#refs["form"].validate(valid => {
  502. if (valid) {
  503. #foreach ($column in $columns)
  504. #if($column.htmlType == "checkbox")
  505. this.form.$column.javaField = this.form.${column.javaField}.join(",");
  506. #end
  507. #end
  508. #if($table.sub)
  509. this.form.${subclassName}List = this.${subclassName}List;
  510. #end
  511. if (this.form.${pkColumn.javaField} != null) {
  512. update${BusinessName}(this.form).then(response => {
  513. this.msgSuccess("修改成功");
  514. this.open = false;
  515. this.getList();
  516. });
  517. } else {
  518. add${BusinessName}(this.form).then(response => {
  519. this.msgSuccess("新增成功");
  520. this.open = false;
  521. this.getList();
  522. });
  523. }
  524. }
  525. });
  526. },
  527. /** 删除按钮操作 */
  528. handleDelete(row) {
  529. const ${pkColumn.javaField}s = row.${pkColumn.javaField} || this.ids;
  530. this.$confirm('是否确认删除${functionName}编号为"' + ${pkColumn.javaField}s + '"的数据项?', "警告", {
  531. confirmButtonText: "确定",
  532. cancelButtonText: "取消",
  533. type: "warning"
  534. }).then(function() {
  535. return del${BusinessName}(${pkColumn.javaField}s);
  536. }).then(() => {
  537. this.getList();
  538. this.msgSuccess("删除成功");
  539. }).catch(() => {});
  540. },
  541. #if($table.sub)
  542. /** ${subTable.functionName}序号 */
  543. row${subClassName}Index({ row, rowIndex }) {
  544. row.index = rowIndex + 1;
  545. },
  546. /** ${subTable.functionName}添加按钮操作 */
  547. handleAdd${subClassName}() {
  548. let obj = {};
  549. #foreach($column in $subTable.columns)
  550. #if($column.pk || $column.javaField == ${subTableFkclassName})
  551. #elseif($column.list && "" != $javaField)
  552. obj.$column.javaField = "";
  553. #end
  554. #end
  555. this.${subclassName}List.push(obj);
  556. },
  557. /** ${subTable.functionName}删除按钮操作 */
  558. handleDelete${subClassName}() {
  559. if (this.checked${subClassName}.length == 0) {
  560. this.$alert("请先选择要删除的${subTable.functionName}数据", "提示", { confirmButtonText: "确定", });
  561. } else {
  562. this.${subclassName}List.splice(this.checked${subClassName}[0].index - 1, 1);
  563. }
  564. },
  565. /** 单选框选中数据 */
  566. handle${subClassName}SelectionChange(selection) {
  567. if (selection.length > 1) {
  568. this.$refs.${subclassName}.clearSelection();
  569. this.$refs.${subclassName}.toggleRowSelection(selection.pop());
  570. } else {
  571. this.checked${subClassName} = selection;
  572. }
  573. },
  574. #end
  575. /** 导出按钮操作 */
  576. handleExport() {
  577. this.download('${moduleName}/${businessName}/export', {
  578. ...this.queryParams
  579. }, `${moduleName}_${businessName}.xlsx`)
  580. }
  581. }
  582. };
  583. </script>