list-vue.template 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  1. <template>
  2. {{$lens := .table.Columns|len}}
  3. {{$businessName := .table.BusinessName | CaseCamelLower}}
  4. <div class="app-container">
  5. <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
  6. {{range $index, $column := .table.Columns}}
  7. {{if and (eq $column.IsQuery "1") (ne $column.ColumnName "created_by") (ne $column.ColumnName "updated_by") (ne $column.ColumnName "created_at") (ne $column.ColumnName "updated_at") (ne $column.ColumnName "deleted_at")}}
  8. {{if eq $column.HtmlType "input" "textarea"}}
  9. <el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
  10. <el-input
  11. v-model="queryParams.{{$column.HtmlField}}"
  12. placeholder="请输入{{$column.ColumnComment}}"
  13. clearable
  14. size="small"
  15. @keyup.enter.native="handleQuery"
  16. />
  17. </el-form-item>
  18. {{else if and (eq $column.HtmlType "select" "radio" "checkbox") (ne $column.DictType "") }}
  19. <el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
  20. <el-select v-model="queryParams.{{$column.HtmlField}}" placeholder="请选择{{$column.ColumnComment}}" clearable size="small">
  21. <el-option
  22. v-for="dict in {{$column.HtmlField}}Options"
  23. :key="dict.key"
  24. :label="dict.value"
  25. :value="dict.key"
  26. />
  27. </el-select>
  28. </el-form-item>
  29. {{else if eq $column.HtmlType "datetime"}}
  30. <el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
  31. <el-date-picker
  32. clearable size="small" style="width: 200px"
  33. v-model="queryParams.{{$column.HtmlField}}"
  34. type="date"
  35. value-format="yyyy-MM-dd"
  36. placeholder="选择{{$column.ColumnComment}}">
  37. </el-date-picker>
  38. </el-form-item>
  39. {{else if and (eq $column.HtmlType "select" "radio" "checkbox") (ne $column.LinkTableName "")}}
  40. <el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
  41. <el-select v-model="queryParams.{{$column.HtmlField}}" placeholder="请选择{{$column.ColumnComment}}" clearable size="small">
  42. <el-option
  43. v-for="item in {{$column.HtmlField}}Options"
  44. :key="item.key"
  45. :label="item.value"
  46. :value="item.key"
  47. />
  48. </el-select>
  49. </el-form-item>
  50. {{else}}
  51. <el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
  52. <el-select v-model="queryParams.{{$column.HtmlField}}" placeholder="请选择{{$column.ColumnComment}}" clearable size="small">
  53. <el-option label="请选择字典生成" value="" />
  54. </el-select>
  55. </el-form-item>
  56. {{end}}
  57. {{end}}
  58. {{end}}
  59. <el-form-item>
  60. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  61. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  62. </el-form-item>
  63. </el-form>
  64. <el-row :gutter="10" class="mb8">
  65. <el-col :span="1.5">
  66. <el-button
  67. type="primary"
  68. icon="el-icon-plus"
  69. size="mini"
  70. @click="handleAdd"
  71. v-hasPermi="['{{.table.ModuleName}}/{{$businessName}}/add']"
  72. >新增</el-button>
  73. </el-col>
  74. <el-col :span="1.5">
  75. <el-button
  76. type="success"
  77. icon="el-icon-edit"
  78. size="mini"
  79. :disabled="single"
  80. @click="handleUpdate"
  81. v-hasPermi="['{{.table.ModuleName}}/{{$businessName}}/edit']"
  82. >修改</el-button>
  83. </el-col>
  84. <el-col :span="1.5">
  85. <el-button
  86. type="danger"
  87. icon="el-icon-delete"
  88. size="mini"
  89. :disabled="multiple"
  90. @click="handleDelete"
  91. v-hasPermi="['{{.table.ModuleName}}/{{$businessName}}/delete']"
  92. >删除</el-button>
  93. </el-col>
  94. </el-row>
  95. <el-table v-loading="loading" :data="{{$businessName}}List" @selection-change="handleSelectionChange">
  96. <el-table-column type="selection" width="55" align="center" />
  97. {{range $index, $column := .table.Columns}}
  98. {{if eq $column.IsPk "1"}}
  99. <el-table-column label="{{$column.ColumnComment}}" align="center" prop="{{$column.HtmlField}}" />
  100. {{else if and (eq $column.IsList "1") (eq $column.HtmlType "datetime")}}
  101. <el-table-column label="{{$column.ColumnComment}}" align="center" prop="{{$column.HtmlField}}" width="180">
  102. <template slot-scope="scope">
  103. <span>{{VueTag "{{"}} parseTime(scope.row.{{$column.HtmlField}}, '{y}-{m}-{d}') {{VueTag "}}"}}</span>
  104. </template>
  105. </el-table-column>
  106. {{else if and (eq $column.IsList "1") (HasSuffix $column.ColumnName "status")}}
  107. <el-table-column label="{{$column.ColumnComment}}" align="center">
  108. <template slot-scope="scope">
  109. <el-switch
  110. v-model="scope.row.{{$column.HtmlField}}"
  111. :active-value="1"
  112. :inactive-value="0"
  113. @change="{{$column.HtmlField}}Change(scope.row)"
  114. ></el-switch>
  115. </template>
  116. </el-table-column>
  117. {{else if ne $column.LinkTableName ""}}
  118. <el-table-column label="{{$column.ColumnComment}}" align="center" prop="{{$column.HtmlField}}" :formatter="{{$column.HtmlField}}Format" width="100">
  119. <template slot-scope="scope">
  120. {{VueTag "{{" }} {{$column.HtmlField}}Format(scope.row) {{VueTag "}}" }}
  121. </template>
  122. </el-table-column>
  123. {{else if and (eq $column.IsList "1") (ne $column.DictType "")}}
  124. <el-table-column label="{{$column.ColumnComment}}" align="center" prop="{{$column.HtmlField}}" :formatter="{{$column.HtmlField}}Format" />
  125. {{else if and (eq $column.IsList "1") (ne $column.HtmlField "")}}
  126. <el-table-column label="{{$column.ColumnComment}}" align="center" prop="{{$column.HtmlField}}" />
  127. {{end}}{{end}}
  128. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  129. <template slot-scope="scope">
  130. <el-button
  131. size="mini"
  132. type="text"
  133. icon="el-icon-edit"
  134. @click="handleUpdate(scope.row)"
  135. v-hasPermi="['{{.table.ModuleName}}/{{$businessName}}/edit']"
  136. >修改</el-button>
  137. <el-button
  138. size="mini"
  139. type="text"
  140. icon="el-icon-delete"
  141. @click="handleDelete(scope.row)"
  142. v-hasPermi="['{{.table.ModuleName}}/{{$businessName}}/delete']"
  143. >删除</el-button>
  144. </template>
  145. </el-table-column>
  146. </el-table>
  147. <pagination
  148. v-show="total>0"
  149. :total="total"
  150. :page.sync="queryParams.pageNum"
  151. :limit.sync="queryParams.pageSize"
  152. @pagination="getList"
  153. />
  154. <!-- 添加或修改{{.table.FunctionName}}对话框 -->
  155. <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body :close-on-click-modal="false">
  156. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  157. {{range $index, $column := .table.Columns}}
  158. {{if and (eq $column.IsInsert "1") (ne $column.IsPk "1")}}
  159. {{if eq $column.HtmlType "input"}}
  160. <el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
  161. <el-input v-model="form.{{$column.HtmlField}}" placeholder="请输入{{$column.ColumnComment}}" />
  162. </el-form-item>
  163. {{else if eq $column.HtmlType "select" }}
  164. {{if ne $column.LinkTableName ""}}
  165. <el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
  166. <el-select v-model="form.{{$column.HtmlField}}" placeholder="请选择{{$column.ColumnComment}}">
  167. <el-option
  168. v-for="item in {{$column.HtmlField}}Options"
  169. :key="item.key"
  170. :label="item.value"
  171. :value="item.key"
  172. ></el-option>
  173. </el-select>
  174. </el-form-item>
  175. {{else if ne $column.DictType ""}}
  176. <el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
  177. <el-select v-model="form.{{$column.HtmlField}}" placeholder="请选择{{$column.ColumnComment}}">
  178. <el-option
  179. v-for="dict in {{$column.HtmlField}}Options"
  180. :key="dict.key"
  181. :label="dict.value"
  182. {{if eq $column.GoType "Integer"}}
  183. :value="parseInt(dict.key)"
  184. {{else}}
  185. :value="dict.key"
  186. {{end}}
  187. ></el-option>
  188. </el-select>
  189. </el-form-item>
  190. {{else}}
  191. <el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
  192. <el-select v-model="form.{{$column.HtmlField}}" placeholder="请选择{{$column.ColumnComment}}">
  193. <el-option label="请选择字典生成" value="" />
  194. </el-select>
  195. </el-form-item>
  196. {{end}}
  197. {{else if eq $column.HtmlType "radio" }}
  198. {{if ne $column.DictType ""}}
  199. <el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
  200. <el-radio-group v-model="form.{{$column.HtmlField}}">
  201. <el-radio
  202. v-for="dict in {{$column.HtmlField}}Options"
  203. :key="dict.key"
  204. :label="dict.key"
  205. >{{ VueTag "{{" }}dict.value {{VueTag "}}"}}</el-radio>
  206. </el-radio-group>
  207. </el-form-item>
  208. {{else}}
  209. <el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
  210. <el-radio-group v-model="form.{{$column.HtmlField}}">
  211. <el-radio label="1">请选择字典生成</el-radio>
  212. </el-radio-group>
  213. </el-form-item>
  214. {{end}}
  215. {{else if eq $column.HtmlType "datetime"}}
  216. <el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
  217. <el-date-picker clearable size="small" style="width: 200px"
  218. v-model="form.{{$column.HtmlField}}"
  219. type="date"
  220. value-format="yyyy-MM-dd"
  221. placeholder="选择{{$column.ColumnComment}}">
  222. </el-date-picker>
  223. </el-form-item>
  224. {{else if eq $column.HtmlType "textarea"}}
  225. <el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
  226. <el-input v-model="form.{{$column.HtmlField}}" type="textarea" placeholder="请输入{{$column.ColumnComment}}" />
  227. </el-form-item>
  228. {{else if eq $column.HtmlType "checkbox" }}
  229. <el-form-item label="{{$column.ColumnComment}}" prop="{{$column.HtmlField}}">
  230. <el-checkbox-group v-model="form.{{$column.HtmlField}}">
  231. <el-checkbox
  232. v-for="dict in {{$column.HtmlField}}Options"
  233. :key="dict.key"
  234. :label="dict.key"
  235. >{{ VueTag "{{" }}dict.value {{VueTag "}}"}}</el-checkbox>
  236. </el-checkbox-group>
  237. </el-form-item>
  238. {{else if eq $column.HtmlType "richtext"}}
  239. <el-form-item label="{{$column.ColumnComment}}">
  240. <Editor ref="cke" v-model="form.{{$column.HtmlField}}" @setEditContent="set{{$column.GoField}}EditContent"/>
  241. </el-form-item>
  242. {{end}}
  243. {{end}}
  244. {{end}}
  245. </el-form>
  246. <div slot="footer" class="dialog-footer">
  247. <el-button type="primary" @click="submitForm">确 定</el-button>
  248. <el-button @click="cancel">取 消</el-button>
  249. </div>
  250. </el-dialog>
  251. </div>
  252. </template>
  253. <script>
  254. import {
  255. list{{.table.ClassName}},
  256. get{{.table.ClassName}},
  257. del{{.table.ClassName}},
  258. add{{.table.ClassName}},
  259. update{{.table.ClassName}},
  260. {{range $index,$column:= .table.Columns}}
  261. {{if and (HasSuffix $column.ColumnName "status") (eq $column.IsList "1") }}
  262. change{{$.table.ClassName}}{{$column.GoField}},
  263. {{end}}
  264. {{if ne $column.LinkTableName ""}}
  265. list{{$column.LinkTableClass}},
  266. {{end}}
  267. {{end}}
  268. } from "@/api/{{.table.ModuleName}}/{{$businessName}}";
  269. export default {
  270. components:{},
  271. name: "{{.table.ClassName}}",
  272. data() {
  273. return {
  274. // 遮罩层
  275. loading: true,
  276. // 选中数组
  277. ids: [],
  278. // 非单个禁用
  279. single: true,
  280. // 非多个禁用
  281. multiple: true,
  282. // 总条数
  283. total: 0,
  284. // {{.table.FunctionName}}表格数据
  285. {{$businessName}}List: [],
  286. // 弹出层标题
  287. title: "",
  288. // 是否显示弹出层
  289. open: false,
  290. {{range $index, $column := .table.Columns}}
  291. {{if ne $column.DictType ""}}
  292. // {{$column.HtmlField}}Options字典数据
  293. {{$column.HtmlField}}Options: [],
  294. {{else if ne $column.LinkTableName ""}}
  295. // {{$column.HtmlField}}Options关联表数据
  296. {{$column.HtmlField}}Options: [],
  297. {{end}}
  298. {{end}}
  299. // 查询参数
  300. queryParams: {
  301. pageNum: 1,
  302. pageSize: 10,{{range $index, $column := .table.Columns}}{{if eq $column.IsQuery "1"}}
  303. {{$column.HtmlField}}: undefined{{if ne $lens $index}},{{end}}{{end}}{{end}}
  304. },
  305. // 表单参数
  306. form: {},
  307. // 表单校验
  308. rules: { {{range $index, $column := .table.Columns}}{{if eq $column.IsRequired "1"}}
  309. {{$column.HtmlField}} : [
  310. { required: true, message: "{{$column.ColumnComment}}不能为空", trigger: "blur" }
  311. ]{{if ne $lens $index}},{{end}}{{end}}{{end}}
  312. }
  313. };
  314. },
  315. created() {
  316. {{range $index, $column := .table.Columns}}
  317. {{if ne $column.DictType ""}}
  318. this.getDicts("{{$column.DictType}}").then(response => {
  319. this.{{$column.HtmlField}}Options = response.data.values||[];
  320. });
  321. {{else if ne $column.LinkTableName ""}}
  322. this.get{{$column.LinkTableClass}}Items()
  323. {{end}}
  324. {{end}}
  325. this.getList();
  326. },
  327. methods: {
  328. {{$setUpData:=true}}
  329. {{range $index, $column := .table.Columns}}
  330. {{if ne $column.LinkTableName ""}}
  331. //关联{{$column.LinkTableName}}表选项
  332. get{{$column.LinkTableClass}}Items() {
  333. this.getItems(list{{$column.LinkTableClass}}, {pageSize:10000}).then(res => {
  334. this.{{$column.HtmlField}}Options = this.setItems(res, '{{$column.LinkLabelId}}', '{{$column.LinkLabelName}}')
  335. })
  336. },
  337. {{else if and (HasSuffix $column.ColumnName "status") (eq $column.IsList "1")}}
  338. // {{$column.ColumnComment}}修改
  339. {{$column.HtmlField}}Change(row) {
  340. let text = row.{{$column.HtmlField}} === 1 ? "启用" : "停用";
  341. this.$confirm('确认要"' + text + '":吗?', "警告", {
  342. confirmButtonText: "确定",
  343. cancelButtonText: "取消",
  344. type: "warning"
  345. }).then(function() {
  346. return change{{$.table.ClassName}}{{$column.GoField}}(row.{{$.table.PkColumn.ColumnName}}, row.{{$column.HtmlField}});
  347. }).then(() => {
  348. this.msgSuccess(text + "成功");
  349. }).catch(function() {
  350. row.userStatus =row.userStatus === 0 ?1 : 0;
  351. });
  352. },
  353. {{end}}
  354. {{end}}
  355. /** 查询{{.table.FunctionName}}列表 */
  356. getList() {
  357. this.loading = true;
  358. list{{.table.ClassName}}(this.queryParams).then(response => {
  359. this.{{$businessName}}List = response.data.list;
  360. this.total = response.data.total;
  361. this.loading = false;
  362. });
  363. },
  364. {{range $index, $column := .table.Columns}}
  365. {{if ne $column.DictType ""}}
  366. {{if eq $column.HtmlType "checkbox"}}
  367. // {{$column.ColumnComment}}字典翻译
  368. {{$column.HtmlField}}Format(row, column) {
  369. let {{$column.HtmlField}} = row.{{$column.HtmlField}}.split(",")
  370. let data = [];
  371. {{$column.HtmlField}}.map(item=>{
  372. data.push(this.selectDictLabel(this.{{$column.HtmlField}}Options, item))
  373. })
  374. return data.join(",")
  375. },
  376. {{else}}
  377. // {{$column.ColumnComment}}字典翻译
  378. {{$column.HtmlField}}Format(row, column) {
  379. return this.selectDictLabel(this.{{$column.HtmlField}}Options, row.{{$column.HtmlField}});
  380. },
  381. {{end}}
  382. {{else if ne $column.LinkTableName ""}}
  383. // {{$column.ColumnComment}}关联表翻译
  384. {{$column.HtmlField}}Format(row, column) {
  385. return this.selectItemsLabel(this.{{$column.HtmlField}}Options, row.{{$column.HtmlField}});
  386. },
  387. {{end}}
  388. {{end}}
  389. // 取消按钮
  390. cancel() {
  391. this.open = false;
  392. this.reset();
  393. },
  394. // 表单重置
  395. reset() {
  396. this.form = {
  397. {{range $index, $column := .table.Columns}}
  398. {{if eq $column.HtmlType "radio"}}
  399. {{$column.HtmlField}}: "0" ,
  400. {{else if eq $column.HtmlType "checkbox"}}
  401. {{$column.HtmlField}}: [] ,
  402. {{else}}
  403. {{$column.HtmlField}}: undefined,
  404. {{end}}
  405. {{end}}
  406. };
  407. {{range $index, $column := .table.Columns}}
  408. {{if eq $column.HtmlType "imagefile"}}
  409. this.imageUrl{{$column.GoField}} = ''
  410. {{end}}
  411. {{end}}
  412. this.resetForm("form");
  413. },
  414. /** 搜索按钮操作 */
  415. handleQuery() {
  416. this.queryParams.pageNum = 1;
  417. this.getList();
  418. },
  419. /** 重置按钮操作 */
  420. resetQuery() {
  421. this.resetForm("queryForm");
  422. this.handleQuery();
  423. },
  424. // 多选框选中数据
  425. handleSelectionChange(selection) {
  426. this.ids = selection.map(item => item.{{.table.PkColumn.HtmlField}})
  427. this.single = selection.length!=1
  428. this.multiple = !selection.length
  429. },
  430. /** 新增按钮操作 */
  431. handleAdd() {
  432. this.reset();
  433. this.open = true;
  434. this.title = "添加{{.table.FunctionName}}";
  435. },
  436. /** 修改按钮操作 */
  437. handleUpdate(row) {
  438. this.reset();
  439. const {{.table.PkColumn.HtmlField}} = row.{{.table.PkColumn.HtmlField}} || this.ids
  440. get{{.table.ClassName}}({{.table.PkColumn.HtmlField}}).then(response => {
  441. let data = response.data;
  442. {{range $index, $column := .table.Columns}}
  443. {{if eq $column.HtmlType "checkbox"}}
  444. data.{{$column.HtmlField}} = data.{{$column.HtmlField}}.split(",")
  445. {{else if eq $column.HtmlType "radio" "select"}}
  446. data.{{$column.HtmlField}} = ''+data.{{$column.HtmlField}}
  447. {{end}}
  448. {{end}}
  449. this.form = data;
  450. this.open = true;
  451. this.title = "修改{{.table.FunctionName}}";
  452. });
  453. },
  454. /** 提交按钮 */
  455. submitForm: function() {
  456. this.$refs["form"].validate(valid => {
  457. if (valid) {
  458. if (this.form.{{.table.PkColumn.HtmlField}} != undefined) {
  459. update{{.table.ClassName}}(this.form).then(response => {
  460. if (response.code === 0) {
  461. this.msgSuccess("修改成功");
  462. this.open = false;
  463. this.getList();
  464. } else {
  465. this.msgError(response.msg);
  466. }
  467. });
  468. } else {
  469. add{{.table.ClassName}}(this.form).then(response => {
  470. if (response.code === 0) {
  471. this.msgSuccess("新增成功");
  472. this.open = false;
  473. this.getList();
  474. } else {
  475. this.msgError(response.msg);
  476. }
  477. });
  478. }
  479. }
  480. });
  481. },
  482. /** 删除按钮操作 */
  483. handleDelete(row) {
  484. const {{.table.PkColumn.HtmlField}}s = row.{{.table.PkColumn.HtmlField}} || this.ids;
  485. this.$confirm('是否确认删除{{.table.FunctionName}}编号为"' + {{.table.PkColumn.HtmlField}}s + '"的数据项?', "警告", {
  486. confirmButtonText: "确定",
  487. cancelButtonText: "取消",
  488. type: "warning"
  489. }).then(function() {
  490. return del{{.table.ClassName}}({{.table.PkColumn.HtmlField}}s);
  491. }).then(() => {
  492. this.getList();
  493. this.msgSuccess("删除成功");
  494. }).catch(function() {});
  495. }
  496. }
  497. };
  498. </script>