index.vue.vm 19 KB

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