list-vue.template 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  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. {{$plugin:=""}}
  255. {{if ContainsI $.table.PackageName "plugins"}}
  256. {{$plugin = "plugins/"}}
  257. {{end}}
  258. import {
  259. list{{.table.ClassName}},
  260. get{{.table.ClassName}},
  261. del{{.table.ClassName}},
  262. add{{.table.ClassName}},
  263. update{{.table.ClassName}},
  264. {{range $index,$column:= .table.Columns}}
  265. {{if and (HasSuffix $column.ColumnName "status") (eq $column.IsList "1") }}
  266. change{{$.table.ClassName}}{{$column.GoField}},
  267. {{end}}
  268. {{if ne $column.LinkTableName ""}}
  269. list{{$column.LinkTableClass}},
  270. {{end}}
  271. {{end}}
  272. } from "@/api/{{$plugin}}{{.table.ModuleName}}/{{$businessName}}";
  273. export default {
  274. components:{},
  275. name: "{{.table.ClassName}}",
  276. data() {
  277. return {
  278. // 遮罩层
  279. loading: true,
  280. // 选中数组
  281. ids: [],
  282. // 非单个禁用
  283. single: true,
  284. // 非多个禁用
  285. multiple: true,
  286. // 总条数
  287. total: 0,
  288. // {{.table.FunctionName}}表格数据
  289. {{$businessName}}List: [],
  290. // 弹出层标题
  291. title: "",
  292. // 是否显示弹出层
  293. open: false,
  294. {{range $index, $column := .table.Columns}}
  295. {{if ne $column.DictType ""}}
  296. // {{$column.HtmlField}}Options字典数据
  297. {{$column.HtmlField}}Options: [],
  298. {{else if ne $column.LinkTableName ""}}
  299. // {{$column.HtmlField}}Options关联表数据
  300. {{$column.HtmlField}}Options: [],
  301. {{end}}
  302. {{end}}
  303. // 查询参数
  304. queryParams: {
  305. pageNum: 1,
  306. pageSize: 10,{{range $index, $column := .table.Columns}}{{if eq $column.IsQuery "1"}}
  307. {{$column.HtmlField}}: undefined{{if ne $lens $index}},{{end}}{{end}}{{end}}
  308. },
  309. // 表单参数
  310. form: {},
  311. // 表单校验
  312. rules: { {{range $index, $column := .table.Columns}}{{if eq $column.IsRequired "1"}}
  313. {{$column.HtmlField}} : [
  314. { required: true, message: "{{$column.ColumnComment}}不能为空", trigger: "blur" }
  315. ]{{if ne $lens $index}},{{end}}{{end}}{{end}}
  316. }
  317. };
  318. },
  319. created() {
  320. {{range $index, $column := .table.Columns}}
  321. {{if ne $column.DictType ""}}
  322. this.getDicts("{{$column.DictType}}").then(response => {
  323. this.{{$column.HtmlField}}Options = response.data.values||[];
  324. });
  325. {{else if ne $column.LinkTableName ""}}
  326. this.get{{$column.LinkTableClass}}Items()
  327. {{end}}
  328. {{end}}
  329. this.getList();
  330. },
  331. methods: {
  332. {{$setUpData:=true}}
  333. {{range $index, $column := .table.Columns}}
  334. {{if ne $column.LinkTableName ""}}
  335. //关联{{$column.LinkTableName}}表选项
  336. get{{$column.LinkTableClass}}Items() {
  337. this.getItems(list{{$column.LinkTableClass}}, {pageSize:10000}).then(res => {
  338. this.{{$column.HtmlField}}Options = this.setItems(res, '{{$column.LinkLabelId}}', '{{$column.LinkLabelName}}')
  339. })
  340. },
  341. {{else if and (HasSuffix $column.ColumnName "status") (eq $column.IsList "1")}}
  342. // {{$column.ColumnComment}}修改
  343. {{$column.HtmlField}}Change(row) {
  344. let text = row.{{$column.HtmlField}} === 1 ? "启用" : "停用";
  345. this.$confirm('确认要"' + text + '":吗?', "警告", {
  346. confirmButtonText: "确定",
  347. cancelButtonText: "取消",
  348. type: "warning"
  349. }).then(function() {
  350. return change{{$.table.ClassName}}{{$column.GoField}}(row.{{$.table.PkColumn.HtmlField}}, row.{{$column.HtmlField}});
  351. }).then(() => {
  352. this.msgSuccess(text + "成功");
  353. }).catch(function() {
  354. row.userStatus =row.userStatus === 0 ?1 : 0;
  355. });
  356. },
  357. {{end}}
  358. {{end}}
  359. /** 查询{{.table.FunctionName}}列表 */
  360. getList() {
  361. this.loading = true;
  362. list{{.table.ClassName}}(this.queryParams).then(response => {
  363. this.{{$businessName}}List = response.data.list;
  364. this.total = response.data.total;
  365. this.loading = false;
  366. });
  367. },
  368. {{range $index, $column := .table.Columns}}
  369. {{if ne $column.DictType ""}}
  370. {{if eq $column.HtmlType "checkbox"}}
  371. // {{$column.ColumnComment}}字典翻译
  372. {{$column.HtmlField}}Format(row, column) {
  373. let {{$column.HtmlField}} = row.{{$column.HtmlField}}.split(",")
  374. let data = [];
  375. {{$column.HtmlField}}.map(item=>{
  376. data.push(this.selectDictLabel(this.{{$column.HtmlField}}Options, item))
  377. })
  378. return data.join(",")
  379. },
  380. {{else}}
  381. // {{$column.ColumnComment}}字典翻译
  382. {{$column.HtmlField}}Format(row, column) {
  383. return this.selectDictLabel(this.{{$column.HtmlField}}Options, row.{{$column.HtmlField}});
  384. },
  385. {{end}}
  386. {{else if ne $column.LinkTableName ""}}
  387. // {{$column.ColumnComment}}关联表翻译
  388. {{$column.HtmlField}}Format(row, column) {
  389. return this.selectItemsLabel(this.{{$column.HtmlField}}Options, row.{{$column.HtmlField}});
  390. },
  391. {{end}}
  392. {{end}}
  393. // 取消按钮
  394. cancel() {
  395. this.open = false;
  396. this.reset();
  397. },
  398. // 表单重置
  399. reset() {
  400. this.form = {
  401. {{range $index, $column := .table.Columns}}
  402. {{if eq $column.HtmlType "radio"}}
  403. {{$column.HtmlField}}: "0" ,
  404. {{else if eq $column.HtmlType "checkbox"}}
  405. {{$column.HtmlField}}: [] ,
  406. {{else}}
  407. {{$column.HtmlField}}: undefined,
  408. {{end}}
  409. {{end}}
  410. };
  411. {{range $index, $column := .table.Columns}}
  412. {{if eq $column.HtmlType "imagefile"}}
  413. this.imageUrl{{$column.GoField}} = ''
  414. {{end}}
  415. {{end}}
  416. this.resetForm("form");
  417. },
  418. /** 搜索按钮操作 */
  419. handleQuery() {
  420. this.queryParams.pageNum = 1;
  421. this.getList();
  422. },
  423. /** 重置按钮操作 */
  424. resetQuery() {
  425. this.resetForm("queryForm");
  426. this.handleQuery();
  427. },
  428. // 多选框选中数据
  429. handleSelectionChange(selection) {
  430. this.ids = selection.map(item => item.{{.table.PkColumn.HtmlField}})
  431. this.single = selection.length!=1
  432. this.multiple = !selection.length
  433. },
  434. /** 新增按钮操作 */
  435. handleAdd() {
  436. this.reset();
  437. this.open = true;
  438. this.title = "添加{{.table.FunctionName}}";
  439. },
  440. /** 修改按钮操作 */
  441. handleUpdate(row) {
  442. this.reset();
  443. const {{.table.PkColumn.HtmlField}} = row.{{.table.PkColumn.HtmlField}} || this.ids
  444. get{{.table.ClassName}}({{.table.PkColumn.HtmlField}}).then(response => {
  445. let data = response.data;
  446. {{range $index, $column := .table.Columns}}
  447. {{if eq $column.HtmlType "checkbox"}}
  448. data.{{$column.HtmlField}} = data.{{$column.HtmlField}}.split(",")
  449. {{else if eq $column.HtmlType "radio" "select"}}
  450. data.{{$column.HtmlField}} = ''+data.{{$column.HtmlField}}
  451. {{end}}
  452. {{end}}
  453. this.form = data;
  454. this.open = true;
  455. this.title = "修改{{.table.FunctionName}}";
  456. });
  457. },
  458. /** 提交按钮 */
  459. submitForm: function() {
  460. this.$refs["form"].validate(valid => {
  461. if (valid) {
  462. if (this.form.{{.table.PkColumn.HtmlField}} != undefined) {
  463. update{{.table.ClassName}}(this.form).then(response => {
  464. if (response.code === 0) {
  465. this.msgSuccess("修改成功");
  466. this.open = false;
  467. this.getList();
  468. } else {
  469. this.msgError(response.msg);
  470. }
  471. });
  472. } else {
  473. add{{.table.ClassName}}(this.form).then(response => {
  474. if (response.code === 0) {
  475. this.msgSuccess("新增成功");
  476. this.open = false;
  477. this.getList();
  478. } else {
  479. this.msgError(response.msg);
  480. }
  481. });
  482. }
  483. }
  484. });
  485. },
  486. /** 删除按钮操作 */
  487. handleDelete(row) {
  488. const {{.table.PkColumn.HtmlField}}s = row.{{.table.PkColumn.HtmlField}} || this.ids;
  489. this.$confirm('是否确认删除{{.table.FunctionName}}编号为"' + {{.table.PkColumn.HtmlField}}s + '"的数据项?', "警告", {
  490. confirmButtonText: "确定",
  491. cancelButtonText: "取消",
  492. type: "warning"
  493. }).then(function() {
  494. return del{{.table.ClassName}}({{.table.PkColumn.HtmlField}}s);
  495. }).then(() => {
  496. this.getList();
  497. this.msgSuccess("删除成功");
  498. }).catch(function() {});
  499. }
  500. }
  501. };
  502. </script>