vue_crud.template 16 KB

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