vue_crud.template 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. ${$columns:=.table.Columns}
  2. ${$pk:=""}
  3. ${$pkColumnName:=""}
  4. ${range $index, $column := .table.Columns} ${if eq $column.IsPk "1"}
  5. ${$pk = $column.ColumnName}
  6. ${$pkColumnName = $column.ColumnName}
  7. ${end}${end}
  8. <template>
  9. <div class="app-container">
  10. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
  11. ${range $index,$column := $columns}
  12. ${if eq $column.IsQuery "1"}
  13. ${$dictType:=$column.DictType}
  14. ${$AttrName:=$column.ColumnName }
  15. ${$comment:=$column.ColumnComment}
  16. ${if eq $column.HtmlType "input"}
  17. <el-form-item label="${$comment}" prop="${$column.ColumnName}">
  18. <el-input
  19. v-model="queryParams.${$column.ColumnName}"
  20. placeholder="请输入${$comment}"
  21. clearable
  22. size="small"
  23. @keyup.enter.native="handleQuery"
  24. />
  25. </el-form-item>
  26. ${else if and (or (eq $column.HtmlType "select" ) (eq $column.HtmlType "radio")) (ne $dictType "") }
  27. <el-form-item label="${$comment}" prop="${$column.ColumnName}">
  28. <el-select v-model="queryParams.${$column.ColumnName}" placeholder="请选择${$comment}" clearable size="small">
  29. <el-option
  30. v-for="dict in ${$column.HtmlField}Options"
  31. :key="dict.key"
  32. :label="dict.value"
  33. :value="dict.key"
  34. />
  35. </el-select>
  36. </el-form-item>
  37. ${else if and (or (eq $column.HtmlType "select" ) (eq $column.HtmlType "radio")) (eq $dictType "") }
  38. <el-form-item label="${$comment}" prop="${$column.ColumnName}">
  39. <el-select v-model="queryParams.${$column.ColumnName}" placeholder="请选择${$comment}" clearable size="small">
  40. <el-option label="请选择字典生成" value="" />
  41. </el-select>
  42. </el-form-item>
  43. ${else if eq $column.HtmlType "datetime"}
  44. <el-form-item label="${$comment}" prop="${$column.ColumnName}">
  45. <el-date-picker clearable size="small" style="width: 200px"
  46. v-model="queryParams.${$column.ColumnName}"
  47. type="date"
  48. value-format="yyyy-MM-dd"
  49. placeholder="选择${$comment}">
  50. </el-date-picker>
  51. </el-form-item>
  52. ${end}
  53. ${end}
  54. ${end}
  55. <el-form-item>
  56. <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  57. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  58. </el-form-item>
  59. </el-form>
  60. <el-row :gutter="10" class="mb8">
  61. <el-col :span="1.5">
  62. <el-button
  63. type="primary"
  64. icon="el-icon-plus"
  65. size="mini"
  66. @click="handleAdd"
  67. >新增</el-button>
  68. </el-col>
  69. <el-col :span="1.5">
  70. <el-button
  71. type="success"
  72. icon="el-icon-edit"
  73. size="mini"
  74. :disabled="single"
  75. @click="handleUpdate"
  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. >删除</el-button>
  86. </el-col>
  87. </el-row>
  88. <el-table v-loading="loading" :data="${.table.BusinessName}List" @selection-change="handleSelectionChange">
  89. <el-table-column type="selection" width="55" align="center" />
  90. ${range $index,$column := $columns}
  91. ${$ColumnName:=$column.ColumnName}
  92. ${$comment:=$column.ColumnComment}
  93. ${if eq $column.IsPk "1"}
  94. <el-table-column label="${$comment}" align="center" prop="${$ColumnName}" />
  95. ${else if and (eq $column.IsList "1") (eq $column.HtmlType "datetime")}
  96. <el-table-column label="${$comment}" align="center" prop="${$ColumnName}" width="180">
  97. <template slot-scope="scope">
  98. <span>{{ parseTime(scope.row.${$ColumnName}, '{y}-{m}-{d}') }}</span>
  99. </template>
  100. </el-table-column>
  101. ${else if and (eq $column.IsList "1") (ne $column.DictType "")}
  102. <el-table-column label="${$comment}" align="center" prop="${$ColumnName}" :formatter="${$column.HtmlField}Format" />
  103. ${else if and (eq $column.IsList "1") (ne $ColumnName "")}
  104. <el-table-column label="${$comment}" align="center" prop="${$ColumnName}" />
  105. ${end}
  106. ${end}
  107. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  108. <template slot-scope="scope">
  109. <el-button
  110. size="mini"
  111. type="text"
  112. icon="el-icon-edit"
  113. @click="handleUpdate(scope.row)"
  114. >修改</el-button>
  115. <el-button
  116. size="mini"
  117. type="text"
  118. icon="el-icon-delete"
  119. @click="handleDelete(scope.row)"
  120. >删除</el-button>
  121. </template>
  122. </el-table-column>
  123. </el-table>
  124. <pagination
  125. v-show="total>0"
  126. :total="total"
  127. :page.sync="queryParams.pageNum"
  128. :limit.sync="queryParams.pageSize"
  129. @pagination="getList"
  130. />
  131. <!-- 添加或修改${.table.FunctionName}对话框 -->
  132. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  133. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  134. ${range $index,$column := $columns}
  135. ${$field := $column.ColumnName}
  136. ${if and (eq $column.IsInsert "1") (ne $column.IsPk "1") }
  137. ${$comment :=$column.ColumnComment}
  138. ${$dictType := $column.DictType }
  139. ${if eq $column.HtmlType "input"}
  140. <el-form-item label="${$comment}" prop="${$field}">
  141. <el-input v-model="form.${$field}" placeholder="请输入${$comment}" />
  142. </el-form-item>
  143. ${else if and (eq $column.HtmlType "select") (ne $dictType "") }
  144. <el-form-item label="${$comment}">
  145. <el-select v-model="form.${$field}" placeholder="请选择${$comment}">
  146. <el-option
  147. v-for="dict in ${$column.HtmlField}Options"
  148. :key="dict.key"
  149. :label="dict.value"
  150. ${if or (eq $column.GoType "int") (eq $column.GoType "int64")}:value="parseInt(dict.key)"${else}:value="dict.key"${end}
  151. ></el-option>
  152. </el-select>
  153. </el-form-item>
  154. ${else if and (eq $column.HtmlType "select") $dictType}
  155. <el-form-item label="${$comment}">
  156. <el-select v-model="form.${$field}" placeholder="请选择${$comment}">
  157. <el-option label="请选择字典生成" value="" />
  158. </el-select>
  159. </el-form-item>
  160. ${else if and (eq $column.HtmlType "checkbox") (ne $dictType "")}
  161. <el-form-item label="${$comment}">
  162. <el-checkbox-group v-model="form.${$field}">
  163. <el-checkbox
  164. v-for="dict in ${$column.HtmlField}Options"
  165. :key="dict.key"
  166. :label="dict.key">
  167. ${"${"}dict.value${"}"}
  168. </el-checkbox>
  169. </el-checkbox-group>
  170. </el-form-item>
  171. ${else if and (eq $column.HtmlType "checkbox") $dictType }
  172. <el-form-item label="${$comment}">
  173. <el-checkbox-group v-model="form.${$field}">
  174. <el-checkbox>请选择字典生成</el-checkbox>
  175. </el-checkbox-group>
  176. </el-form-item>
  177. ${else if and (eq $column.HtmlType "radio") (ne $dictType "") }
  178. <el-form-item label="${$comment}">
  179. <el-radio-group v-model="form.${$field}">
  180. <el-radio
  181. v-for="dict in ${$column.HtmlField}Options"
  182. :key="dict.key"
  183. ${if or (eq $column.GoType "int") (eq $column.GoType "int64")}:label="parseInt(dict.key)"${else}:label="dict.key"${end}
  184. >${"${"}dict.value${"}"}</el-radio>
  185. </el-radio-group>
  186. </el-form-item>
  187. ${else if and (eq $column.HtmlType "radio") $dictType }
  188. <el-form-item label="${$comment}">
  189. <el-radio-group v-model="form.${$field}">
  190. <el-radio label="1">请选择字典生成</el-radio>
  191. </el-radio-group>
  192. </el-form-item>
  193. ${else if eq $column.HtmlType "datetime"}
  194. <el-form-item label="${$comment}" prop="${$field}">
  195. <el-date-picker clearable size="small" style="width: 200px"
  196. v-model="form.${$field}"
  197. type="date"
  198. value-format="yyyy-MM-dd"
  199. placeholder="选择${$comment}">
  200. </el-date-picker>
  201. </el-form-item>
  202. ${else if eq $column.HtmlType "textarea"}
  203. <el-form-item label="${$comment}" prop="${$field}">
  204. <el-input v-model="form.${$field}" type="textarea" placeholder="请输入内容" />
  205. </el-form-item>
  206. ${end}
  207. ${end}
  208. ${end}
  209. </el-form>
  210. <div slot="footer" class="dialog-footer">
  211. <el-button type="primary" @click="submitForm">确 定</el-button>
  212. <el-button @click="cancel">取 消</el-button>
  213. </div>
  214. </el-dialog>
  215. </div>
  216. </template>
  217. <script>
  218. import { list${.table.BusinessName|UcFirst}, get${.table.BusinessName|UcFirst}, del${.table.BusinessName|UcFirst}, add${.table.BusinessName|UcFirst}, update${.table.BusinessName|UcFirst} } from '@/api/${.table.ModuleName}/${.table.BusinessName}'
  219. export default {
  220. name: "${.table.BusinessName}",
  221. data() {
  222. return {
  223. // 遮罩层
  224. loading: true,
  225. // 选中数组
  226. ids: [],
  227. // 非单个禁用
  228. single: true,
  229. // 非多个禁用
  230. multiple: true,
  231. // 显示搜索条件
  232. showSearch: true,
  233. // 总条数
  234. total: 0,
  235. // ${.table.FunctionName}表格数据
  236. ${.table.BusinessName}List: [],
  237. // 弹出层标题
  238. title: "",
  239. // 是否显示弹出层
  240. open: false,
  241. ${range $index,$column := $columns}
  242. ${$comment :=$column.ColumnComment}
  243. ${if ne $column.DictType ""}
  244. // ${$column.ColumnName}字典
  245. ${$column.HtmlField}Options: [],
  246. ${end}
  247. ${end}
  248. // 查询参数
  249. queryParams: {
  250. pageNum: 1,
  251. pageSize: 10,
  252. ${range $index,$column := $columns}
  253. ${$velocityCount := add $index 1}
  254. ${if eq $column.IsQuery "1"}
  255. ${$column.ColumnName}: null,
  256. ${end}
  257. ${end}
  258. },
  259. // 表单参数
  260. form: {},
  261. // 表单校验
  262. rules: {
  263. ${range $index,$column := $columns}
  264. ${$velocityCount := add $index 1}
  265. ${if and (eq $column.IsRequired "1") (eq $column.IsPk "0")}
  266. ${$comment:=$column.ColumnComment}
  267. ${$column.ColumnName}: [
  268. { required: true, message: "${$comment}不能为空", trigger: "blur" }
  269. ]${if ne $velocityCount (len $columns)},${end}
  270. ${end}
  271. ${end}
  272. }
  273. };
  274. },
  275. created() {
  276. this.getList();
  277. ${range $index,$column := $columns}
  278. ${if ne $column.DictType ""}
  279. this.getDicts("${$column.DictType}").then(response => {
  280. this.${$column.HtmlField}Options = response.data.values || [];
  281. });
  282. ${end}
  283. ${end}
  284. },
  285. methods: {
  286. /** 查询${.table.FunctionName}列表 */
  287. getList() {
  288. this.loading = true;
  289. list${.table.BusinessName|UcFirst}(this.queryParams).then(response => {
  290. this.${.table.BusinessName}List = response.data.list;
  291. this.total = response.data.total;
  292. this.loading = false;
  293. });
  294. },
  295. ${range $index,$column := $columns}
  296. ${if ne $column.DictType ""}
  297. ${$comment:=$column.ColumnComment}
  298. // $comment字典翻译
  299. ${$column.HtmlField}Format(row, column) {
  300. return this.selectDictLabel${if eq $column.HtmlType "checkbox"}s${end}(this.${$column.HtmlField}Options, row.${$column.ColumnName});
  301. },
  302. ${end}
  303. ${end}
  304. // 取消按钮
  305. cancel() {
  306. this.open = false;
  307. this.reset();
  308. },
  309. // 表单重置
  310. reset() {
  311. this.form = {
  312. ${range $index,$column := $columns}
  313. ${$velocityCount := add $index 1}
  314. ${if eq $column.HtmlType "radio"}
  315. ${$column.ColumnName}: ${if or (eq $column.GoType "int") (eq $column.GoType "int64") }0${else}"0"${end} ${if ne $velocityCount (len $columns)},${end}
  316. ${else if eq $column.HtmlType "checkbox"}
  317. ${$column.ColumnName}: []${if ne $velocityCount (len $columns)},${end}
  318. ${else}
  319. ${$column.ColumnName}: null${if ne $velocityCount (len $columns)},${end}
  320. ${end}
  321. ${end}
  322. };
  323. this.resetForm("form");
  324. },
  325. /** 搜索按钮操作 */
  326. handleQuery() {
  327. this.queryParams.pageNum = 1;
  328. this.getList();
  329. },
  330. /** 重置按钮操作 */
  331. resetQuery() {
  332. this.resetForm("queryForm");
  333. this.handleQuery();
  334. },
  335. // 多选框选中数据
  336. handleSelectionChange(selection) {
  337. this.ids = selection.map(item => item.${$pkColumnName})
  338. this.single = selection.length!==1
  339. this.multiple = !selection.length
  340. },
  341. /** 新增按钮操作 */
  342. handleAdd() {
  343. this.reset();
  344. this.open = true;
  345. this.title = "添加${.table.FunctionName}";
  346. },
  347. /** 修改按钮操作 */
  348. handleUpdate(row) {
  349. this.reset();
  350. const ${$pkColumnName} = row.${$pkColumnName} || this.ids
  351. get${.table.BusinessName|UcFirst}(${$pkColumnName}).then(response => {
  352. this.form = response.data;
  353. ${range $index,$column := $columns}
  354. ${if eq $column.HtmlType "checkbox"}
  355. this.form.${$column.ColumnName} = this.form.${$column.ColumnName}.split(",");
  356. ${end}
  357. ${end}
  358. this.open = true;
  359. this.title = "修改${.table.FunctionName}";
  360. });
  361. },
  362. /** 提交按钮 */
  363. submitForm() {
  364. this.$refs["form"].validate(valid => {
  365. if (valid) {
  366. ${range $index,$column := $columns}
  367. ${if eq $column.HtmlType "checkbox"}
  368. this.form.${$column.ColumnName} = this.form.${$column.ColumnName}.join(",");
  369. ${end}
  370. ${end}
  371. if (this.form.${$pkColumnName} != null) {
  372. update${.table.BusinessName|UcFirst}(this.form).then(response => {
  373. if (response.code === 0) {
  374. this.msgSuccess("修改成功");
  375. this.open = false;
  376. this.getList();
  377. }
  378. });
  379. } else {
  380. add${.table.BusinessName|UcFirst}(this.form).then(response => {
  381. if (response.code === 0) {
  382. this.msgSuccess("新增成功");
  383. this.open = false;
  384. this.getList();
  385. }
  386. });
  387. }
  388. }
  389. });
  390. },
  391. /** 删除按钮操作 */
  392. handleDelete(row) {
  393. const ${$pkColumnName}s = row.${$pkColumnName} || this.ids;
  394. this.$confirm('是否确认删除${.table.FunctionName}编号为"' + ${$pkColumnName}s + '"的数据项?', "警告", {
  395. confirmButtonText: "确定",
  396. cancelButtonText: "取消",
  397. type: "warning"
  398. }).then(function() {
  399. return del${.table.BusinessName|UcFirst}(${$pkColumnName}s);
  400. }).then(() => {
  401. this.getList();
  402. this.msgSuccess("删除成功");
  403. }).catch(function() {});
  404. },
  405. } //methods结束
  406. };
  407. </script>