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