index.vue.vm 17 KB

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