index.vue.vm 17 KB

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