index.vue.vm 16 KB

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