index.vue.vm 17 KB

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