index.vue.vm 16 KB

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