index.vue.vm 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  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}) }}</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">
  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. :value="dict.dictValue"
  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 == "radio" && "" != $dictType)
  184. <el-form-item label="${comment}">
  185. <el-radio-group v-model="form.${field}">
  186. <el-radio
  187. v-for="dict in ${field}Options"
  188. :key="dict.dictValue"
  189. :label="dict.dictValue"
  190. >{{dict.dictLabel}}</el-radio>
  191. </el-radio-group>
  192. </el-form-item>
  193. #elseif($column.htmlType == "radio" && $dictType)
  194. <el-form-item label="${comment}">
  195. <el-radio-group v-model="form.${field}">
  196. <el-radio label="1">请选择字典生成</el-radio>
  197. </el-radio-group>
  198. </el-form-item>
  199. #elseif($column.htmlType == "datetime")
  200. <el-form-item label="${comment}" prop="${field}">
  201. <el-date-picker clearable size="small" style="width: 200px"
  202. v-model="form.${field}"
  203. type="date"
  204. value-format="yyyy-MM-dd"
  205. placeholder="选择${comment}">
  206. </el-date-picker>
  207. </el-form-item>
  208. #elseif($column.htmlType == "textarea")
  209. <el-form-item label="${comment}" prop="${field}">
  210. <el-input v-model="form.${field}" type="textarea" placeholder="请输入内容" />
  211. </el-form-item>
  212. #end
  213. #end
  214. #end
  215. #end
  216. </el-form>
  217. <div slot="footer" class="dialog-footer">
  218. <el-button type="primary" @click="submitForm">确 定</el-button>
  219. <el-button @click="cancel">取 消</el-button>
  220. </div>
  221. </el-dialog>
  222. </div>
  223. </template>
  224. <script>
  225. import { list${BusinessName}, get${BusinessName}, del${BusinessName}, add${BusinessName}, update${BusinessName}, export${BusinessName} } from "@/api/${moduleName}/${businessName}";
  226. export default {
  227. data() {
  228. return {
  229. // 遮罩层
  230. loading: true,
  231. // 选中数组
  232. ids: [],
  233. // 非单个禁用
  234. single: true,
  235. // 非多个禁用
  236. multiple: true,
  237. // 总条数
  238. total: 0,
  239. // ${functionName}表格数据
  240. ${businessName}List: [],
  241. // 弹出层标题
  242. title: "",
  243. // 是否显示弹出层
  244. open: false,
  245. #foreach ($column in $columns)
  246. #set($parentheseIndex=$column.columnComment.indexOf("("))
  247. #if($parentheseIndex != -1)
  248. #set($comment=$column.columnComment.substring(0, $parentheseIndex))
  249. #else
  250. #set($comment=$column.columnComment)
  251. #end
  252. #if(${column.dictType} != '')
  253. // $comment字典
  254. ${column.javaField}Options: []#if($velocityCount != $columns.size()),#end
  255. #end
  256. #end
  257. // 查询参数
  258. queryParams: {
  259. pageNum: 1,
  260. pageSize: 10,
  261. #foreach ($column in $columns)
  262. #if($column.query)
  263. $column.javaField: undefined#if($velocityCount != $columns.size()),#end
  264. #end
  265. #end
  266. },
  267. // 表单参数
  268. form: {},
  269. // 表单校验
  270. rules: {
  271. #foreach ($column in $columns)
  272. #if($column.required)
  273. #set($parentheseIndex=$column.columnComment.indexOf("("))
  274. #if($parentheseIndex != -1)
  275. #set($comment=$column.columnComment.substring(0, $parentheseIndex))
  276. #else
  277. #set($comment=$column.columnComment)
  278. #end
  279. #set($comment=$column.columnComment)
  280. $column.javaField: [
  281. { required: true, message: "$comment不能为空", trigger: "blur" }
  282. ]#if($velocityCount != $columns.size()),#end
  283. #end
  284. #end
  285. }
  286. };
  287. },
  288. created() {
  289. this.getList();
  290. #foreach ($column in $columns)
  291. #if(${column.dictType} != '')
  292. this.getDicts("${column.dictType}").then(response => {
  293. this.${column.javaField}Options = response.data;
  294. });
  295. #end
  296. #end
  297. },
  298. methods: {
  299. /** 查询${functionName}列表 */
  300. getList() {
  301. this.loading = true;
  302. list${BusinessName}(this.queryParams).then(response => {
  303. this.${businessName}List = response.rows;
  304. this.total = response.total;
  305. this.loading = false;
  306. });
  307. },
  308. #foreach ($column in $columns)
  309. #if(${column.dictType} != '')
  310. #set($parentheseIndex=$column.columnComment.indexOf("("))
  311. #if($parentheseIndex != -1)
  312. #set($comment=$column.columnComment.substring(0, $parentheseIndex))
  313. #else
  314. #set($comment=$column.columnComment)
  315. #end
  316. // $comment字典翻译
  317. ${column.javaField}Format(row, column) {
  318. return this.selectDictLabel(this.${column.javaField}Options, row.${column.javaField});
  319. },
  320. #end
  321. #end
  322. // 取消按钮
  323. cancel() {
  324. this.open = false;
  325. this.reset();
  326. },
  327. // 表单重置
  328. reset() {
  329. this.form = {
  330. #foreach ($column in $columns)
  331. #if($column.htmlType == "radio")
  332. $column.javaField: "0"#if($velocityCount != $columns.size()),#end
  333. #else
  334. $column.javaField: undefined#if($velocityCount != $columns.size()),#end
  335. #end
  336. #end
  337. };
  338. this.resetForm("form");
  339. },
  340. /** 搜索按钮操作 */
  341. handleQuery() {
  342. this.queryParams.pageNum = 1;
  343. this.getList();
  344. },
  345. /** 重置按钮操作 */
  346. resetQuery() {
  347. this.resetForm("queryForm");
  348. this.handleQuery();
  349. },
  350. // 多选框选中数据
  351. handleSelectionChange(selection) {
  352. this.ids = selection.map(item => item.${pkColumn.javaField})
  353. this.single = selection.length!=1
  354. this.multiple = !selection.length
  355. },
  356. /** 新增按钮操作 */
  357. handleAdd() {
  358. this.reset();
  359. this.open = true;
  360. this.title = "添加${functionName}";
  361. },
  362. /** 修改按钮操作 */
  363. handleUpdate(row) {
  364. this.reset();
  365. const ${pkColumn.javaField} = row.${pkColumn.javaField} || this.ids
  366. get${BusinessName}(${pkColumn.javaField}).then(response => {
  367. this.form = response.data;
  368. this.open = true;
  369. this.title = "修改${functionName}";
  370. });
  371. },
  372. /** 提交按钮 */
  373. submitForm: function() {
  374. this.#[[$]]#refs["form"].validate(valid => {
  375. if (valid) {
  376. if (this.form.${pkColumn.javaField} != undefined) {
  377. update${BusinessName}(this.form).then(response => {
  378. if (response.code === 200) {
  379. this.msgSuccess("修改成功");
  380. this.open = false;
  381. this.getList();
  382. } else {
  383. this.msgError(response.msg);
  384. }
  385. });
  386. } else {
  387. add${BusinessName}(this.form).then(response => {
  388. if (response.code === 200) {
  389. this.msgSuccess("新增成功");
  390. this.open = false;
  391. this.getList();
  392. } else {
  393. this.msgError(response.msg);
  394. }
  395. });
  396. }
  397. }
  398. });
  399. },
  400. /** 删除按钮操作 */
  401. handleDelete(row) {
  402. const ${pkColumn.javaField}s = row.${pkColumn.javaField} || this.ids;
  403. this.$confirm('是否确认删除${functionName}编号为"' + ${pkColumn.javaField}s + '"的数据项?', "警告", {
  404. confirmButtonText: "确定",
  405. cancelButtonText: "取消",
  406. type: "warning"
  407. }).then(function() {
  408. return del${BusinessName}(${pkColumn.javaField}s);
  409. }).then(() => {
  410. this.getList();
  411. this.msgSuccess("删除成功");
  412. }).catch(function() {});
  413. },
  414. /** 导出按钮操作 */
  415. handleExport() {
  416. const queryParams = this.queryParams;
  417. this.$confirm('是否确认导出所有${functionName}数据项?', "警告", {
  418. confirmButtonText: "确定",
  419. cancelButtonText: "取消",
  420. type: "warning"
  421. }).then(function() {
  422. return export${BusinessName}(queryParams);
  423. }).then(response => {
  424. this.download(response.msg);
  425. }).catch(function() {});
  426. }
  427. }
  428. };
  429. </script>