index.vue.vm 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  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}" v-if="${column.list}"/>
  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 == "uploadImage")
  185. <el-form-item label="${comment}">
  186. <uploadImage v-model="form.${field}"/>
  187. </el-form-item>
  188. #elseif($column.htmlType == "editor")
  189. <el-form-item label="${comment}">
  190. <editor v-model="form.${field}" :min-height="192"/>
  191. </el-form-item>
  192. #elseif($column.htmlType == "select" && "" != $dictType)
  193. <el-form-item label="${comment}" prop="${field}">
  194. <el-select v-model="form.${field}" placeholder="请选择${comment}">
  195. <el-option
  196. v-for="dict in ${field}Options"
  197. :key="dict.dictValue"
  198. :label="dict.dictLabel"
  199. #if($column.javaType == "Integer" || $column.javaType == "Long"):value="parseInt(dict.dictValue)"#else:value="dict.dictValue"#end
  200. ></el-option>
  201. </el-select>
  202. </el-form-item>
  203. #elseif($column.htmlType == "select" && $dictType)
  204. <el-form-item label="${comment}" prop="${field}">
  205. <el-select v-model="form.${field}" placeholder="请选择${comment}">
  206. <el-option label="请选择字典生成" value="" />
  207. </el-select>
  208. </el-form-item>
  209. #elseif($column.htmlType == "checkbox" && "" != $dictType)
  210. <el-form-item label="${comment}">
  211. <el-checkbox-group v-model="form.${field}">
  212. <el-checkbox
  213. v-for="dict in ${field}Options"
  214. :key="dict.dictValue"
  215. :label="dict.dictValue">
  216. {{dict.dictLabel}}
  217. </el-checkbox>
  218. </el-checkbox-group>
  219. </el-form-item>
  220. #elseif($column.htmlType == "checkbox" && $dictType)
  221. <el-form-item label="${comment}">
  222. <el-checkbox-group v-model="form.${field}">
  223. <el-checkbox>请选择字典生成</el-checkbox>
  224. </el-checkbox-group>
  225. </el-form-item>
  226. #elseif($column.htmlType == "radio" && "" != $dictType)
  227. <el-form-item label="${comment}">
  228. <el-radio-group v-model="form.${field}">
  229. <el-radio
  230. v-for="dict in ${field}Options"
  231. :key="dict.dictValue"
  232. #if($column.javaType == "Integer" || $column.javaType == "Long"):label="parseInt(dict.dictValue)"#else:label="dict.dictValue"#end
  233. >{{dict.dictLabel}}</el-radio>
  234. </el-radio-group>
  235. </el-form-item>
  236. #elseif($column.htmlType == "radio" && $dictType)
  237. <el-form-item label="${comment}">
  238. <el-radio-group v-model="form.${field}">
  239. <el-radio label="1">请选择字典生成</el-radio>
  240. </el-radio-group>
  241. </el-form-item>
  242. #elseif($column.htmlType == "datetime")
  243. <el-form-item label="${comment}" prop="${field}">
  244. <el-date-picker clearable size="small"
  245. v-model="form.${field}"
  246. type="date"
  247. value-format="yyyy-MM-dd"
  248. placeholder="选择${comment}">
  249. </el-date-picker>
  250. </el-form-item>
  251. #elseif($column.htmlType == "textarea")
  252. <el-form-item label="${comment}" prop="${field}">
  253. <el-input v-model="form.${field}" type="textarea" placeholder="请输入内容" />
  254. </el-form-item>
  255. #end
  256. #end
  257. #end
  258. #end
  259. </el-form>
  260. <div slot="footer" class="dialog-footer">
  261. <el-button type="primary" @click="submitForm">确 定</el-button>
  262. <el-button @click="cancel">取 消</el-button>
  263. </div>
  264. </el-dialog>
  265. </div>
  266. </template>
  267. <script>
  268. import { list${BusinessName}, get${BusinessName}, del${BusinessName}, add${BusinessName}, update${BusinessName}, export${BusinessName} } from "@/api/${moduleName}/${businessName}";
  269. #foreach($column in $columns)
  270. #if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "uploadImage")
  271. import UploadImage from '@/components/UploadImage';
  272. #break
  273. #end
  274. #end
  275. #foreach($column in $columns)
  276. #if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "editor")
  277. import Editor from '@/components/Editor';
  278. #break
  279. #end
  280. #end
  281. export default {
  282. name: "${BusinessName}",
  283. components: {
  284. #foreach($column in $columns)
  285. #if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "uploadImage")
  286. UploadImage,
  287. #break
  288. #end
  289. #end
  290. #foreach($column in $columns)
  291. #if($column.insert && !$column.superColumn && !$column.pk && $column.htmlType == "editor")
  292. Editor,
  293. #break
  294. #end
  295. #end
  296. },
  297. data() {
  298. return {
  299. // 遮罩层
  300. loading: true,
  301. // 选中数组
  302. ids: [],
  303. // 非单个禁用
  304. single: true,
  305. // 非多个禁用
  306. multiple: true,
  307. // 显示搜索条件
  308. showSearch: true,
  309. // 总条数
  310. total: 0,
  311. // ${functionName}表格数据
  312. ${businessName}List: [],
  313. // 弹出层标题
  314. title: "",
  315. // 是否显示弹出层
  316. open: false,
  317. #foreach ($column in $columns)
  318. #set($parentheseIndex=$column.columnComment.indexOf("("))
  319. #if($parentheseIndex != -1)
  320. #set($comment=$column.columnComment.substring(0, $parentheseIndex))
  321. #else
  322. #set($comment=$column.columnComment)
  323. #end
  324. #if(${column.dictType} != '')
  325. // $comment字典
  326. ${column.javaField}Options: [],
  327. #elseif($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
  328. #set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
  329. // $comment时间范围
  330. daterange${AttrName}: [],
  331. #end
  332. #end
  333. // 查询参数
  334. queryParams: {
  335. pageNum: 1,
  336. pageSize: 10,
  337. #foreach ($column in $columns)
  338. #if($column.query)
  339. $column.javaField: undefined#if($velocityCount != $columns.size()),#end
  340. #end
  341. #end
  342. },
  343. // 表单参数
  344. form: {},
  345. // 表单校验
  346. rules: {
  347. #foreach ($column in $columns)
  348. #if($column.required)
  349. #set($parentheseIndex=$column.columnComment.indexOf("("))
  350. #if($parentheseIndex != -1)
  351. #set($comment=$column.columnComment.substring(0, $parentheseIndex))
  352. #else
  353. #set($comment=$column.columnComment)
  354. #end
  355. $column.javaField: [
  356. { required: true, message: "$comment不能为空", trigger: #if($column.htmlType == "select")"change"#else"blur"#end }
  357. ]#if($velocityCount != $columns.size()),#end
  358. #end
  359. #end
  360. }
  361. };
  362. },
  363. created() {
  364. this.getList();
  365. #foreach ($column in $columns)
  366. #if(${column.dictType} != '')
  367. this.getDicts("${column.dictType}").then(response => {
  368. this.${column.javaField}Options = response.data;
  369. });
  370. #end
  371. #end
  372. },
  373. methods: {
  374. /** 查询${functionName}列表 */
  375. getList() {
  376. this.loading = true;
  377. #foreach ($column in $columns)
  378. #if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
  379. this.queryParams.params = {};
  380. #break
  381. #end
  382. #end
  383. #foreach ($column in $columns)
  384. #if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
  385. #set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
  386. if (null != this.daterange${AttrName} && '' != this.daterange${AttrName}) {
  387. this.queryParams.params["begin${AttrName}"] = this.daterange${AttrName}[0];
  388. this.queryParams.params["end${AttrName}"] = this.daterange${AttrName}[1];
  389. }
  390. #end
  391. #end
  392. list${BusinessName}(this.queryParams).then(response => {
  393. this.${businessName}List = response.rows;
  394. this.total = response.total;
  395. this.loading = false;
  396. });
  397. },
  398. #foreach ($column in $columns)
  399. #if(${column.dictType} != '')
  400. #set($parentheseIndex=$column.columnComment.indexOf("("))
  401. #if($parentheseIndex != -1)
  402. #set($comment=$column.columnComment.substring(0, $parentheseIndex))
  403. #else
  404. #set($comment=$column.columnComment)
  405. #end
  406. // $comment字典翻译
  407. ${column.javaField}Format(row, column) {
  408. return this.selectDictLabel#if($column.htmlType == "checkbox")s#end(this.${column.javaField}Options, row.${column.javaField});
  409. },
  410. #end
  411. #end
  412. // 取消按钮
  413. cancel() {
  414. this.open = false;
  415. this.reset();
  416. },
  417. // 表单重置
  418. reset() {
  419. this.form = {
  420. #foreach ($column in $columns)
  421. #if($column.htmlType == "radio")
  422. $column.javaField: #if($column.javaType == "Integer" || $column.javaType == "Long")0#else"0"#end#if($velocityCount != $columns.size()),#end
  423. #elseif($column.htmlType == "checkbox")
  424. $column.javaField: []#if($velocityCount != $columns.size()),#end
  425. #else
  426. $column.javaField: undefined#if($velocityCount != $columns.size()),#end
  427. #end
  428. #end
  429. };
  430. this.resetForm("form");
  431. },
  432. /** 搜索按钮操作 */
  433. handleQuery() {
  434. this.queryParams.pageNum = 1;
  435. this.getList();
  436. },
  437. /** 重置按钮操作 */
  438. resetQuery() {
  439. #foreach ($column in $columns)
  440. #if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
  441. #set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
  442. this.daterange${AttrName} = [];
  443. #end
  444. #end
  445. this.resetForm("queryForm");
  446. this.handleQuery();
  447. },
  448. // 多选框选中数据
  449. handleSelectionChange(selection) {
  450. this.ids = selection.map(item => item.${pkColumn.javaField})
  451. this.single = selection.length!==1
  452. this.multiple = !selection.length
  453. },
  454. /** 新增按钮操作 */
  455. handleAdd() {
  456. this.reset();
  457. this.open = true;
  458. this.title = "添加${functionName}";
  459. },
  460. /** 修改按钮操作 */
  461. handleUpdate(row) {
  462. this.reset();
  463. const ${pkColumn.javaField} = row.${pkColumn.javaField} || this.ids
  464. get${BusinessName}(${pkColumn.javaField}).then(response => {
  465. this.form = response.data;
  466. #foreach ($column in $columns)
  467. #if($column.htmlType == "checkbox")
  468. this.form.$column.javaField = this.form.${column.javaField}.split(",");
  469. #end
  470. #end
  471. this.open = true;
  472. this.title = "修改${functionName}";
  473. });
  474. },
  475. /** 提交按钮 */
  476. submitForm() {
  477. this.#[[$]]#refs["form"].validate(valid => {
  478. if (valid) {
  479. #foreach ($column in $columns)
  480. #if($column.htmlType == "checkbox")
  481. this.form.$column.javaField = this.form.${column.javaField}.join(",");
  482. #end
  483. #end
  484. if (this.form.${pkColumn.javaField} != null) {
  485. update${BusinessName}(this.form).then(response => {
  486. this.msgSuccess("修改成功");
  487. this.open = false;
  488. this.getList();
  489. });
  490. } else {
  491. add${BusinessName}(this.form).then(response => {
  492. this.msgSuccess("新增成功");
  493. this.open = false;
  494. this.getList();
  495. });
  496. }
  497. }
  498. });
  499. },
  500. /** 删除按钮操作 */
  501. handleDelete(row) {
  502. const ${pkColumn.javaField}s = row.${pkColumn.javaField} || this.ids;
  503. this.$confirm('是否确认删除${functionName}编号为"' + ${pkColumn.javaField}s + '"的数据项?', "警告", {
  504. confirmButtonText: "确定",
  505. cancelButtonText: "取消",
  506. type: "warning"
  507. }).then(function() {
  508. return del${BusinessName}(${pkColumn.javaField}s);
  509. }).then(() => {
  510. this.getList();
  511. this.msgSuccess("删除成功");
  512. })
  513. },
  514. /** 导出按钮操作 */
  515. handleExport() {
  516. const queryParams = this.queryParams;
  517. this.$confirm('是否确认导出所有${functionName}数据项?', "警告", {
  518. confirmButtonText: "确定",
  519. cancelButtonText: "取消",
  520. type: "warning"
  521. }).then(function() {
  522. return export${BusinessName}(queryParams);
  523. }).then(response => {
  524. this.download(response.msg);
  525. })
  526. }
  527. }
  528. };
  529. </script>