index.vue.vm 16 KB

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