vue_tree.template 15 KB

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