table.vue.tpl 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. <template>
  2. <div>
  3. <div class="search-term">
  4. <el-form :inline="true" :model="searchInfo" class="demo-form-inline">
  5. {{- range .Fields}} {{- if .FieldSearchType}} {{- if eq .FieldType "bool" }}
  6. <el-form-item label="{{.FieldDesc}}" prop="{{.FieldJson}}">
  7. <el-select v-model="searchInfo.{{.FieldJson}}" clear placeholder="请选择">
  8. <el-option
  9. key="true"
  10. label="是"
  11. value="true">
  12. </el-option>
  13. <el-option
  14. key="false"
  15. label="否"
  16. value="false">
  17. </el-option>
  18. </el-select>
  19. </el-form-item>
  20. {{- else }}
  21. <el-form-item label="{{.FieldDesc}}">
  22. <el-input placeholder="搜索条件" v-model="searchInfo.{{.FieldJson}}"></el-input>
  23. </el-form-item> {{ end }} {{ end }} {{ end }}
  24. <el-form-item>
  25. <el-button @click="onSubmit" type="primary">查询</el-button>
  26. </el-form-item>
  27. <el-form-item>
  28. <el-button @click="openDialog" type="primary">新增{{.Description}}</el-button>
  29. </el-form-item>
  30. <el-form-item>
  31. <el-popover placement="top" v-model="deleteVisible" width="160">
  32. <p>确定要删除吗?</p>
  33. <div style="text-align: right; margin: 0">
  34. <el-button @click="deleteVisible = false" size="mini" type="text">取消</el-button>
  35. <el-button @click="onDelete" size="mini" type="primary">确定</el-button>
  36. </div>
  37. <el-button icon="el-icon-delete" size="mini" slot="reference" type="danger">批量删除</el-button>
  38. </el-popover>
  39. </el-form-item>
  40. </el-form>
  41. </div>
  42. <el-table
  43. :data="tableData"
  44. @selection-change="handleSelectionChange"
  45. border
  46. ref="multipleTable"
  47. stripe
  48. style="width: 100%"
  49. tooltip-effect="dark"
  50. >
  51. <el-table-column type="selection" width="55"></el-table-column>
  52. <el-table-column label="日期" width="180">
  53. <template slot-scope="scope">{{ "{{scope.row.CreatedAt|formatDate}}" }}</template>
  54. </el-table-column>
  55. {{range .Fields}}
  56. {{- if .DictType}}
  57. <el-table-column label="{{.FieldDesc}}" prop="{{.FieldJson}}" width="120">
  58. <template slot-scope="scope">
  59. {{"{{"}}filterDict(scope.row.{{.FieldJson}},"{{.DictType}}"){{"}}"}}
  60. </template>
  61. </el-table-column>
  62. {{- else if eq .FieldType "bool" }}
  63. <el-table-column label="{{.FieldDesc}}" prop="{{.FieldJson}}" width="120">
  64. <template slot-scope="scope">{{ "{{scope.row."}}{{.FieldJson}}{{"|formatBoolean}}" }}</template>
  65. </el-table-column> {{- else }}
  66. <el-table-column label="{{.FieldDesc}}" prop="{{.FieldJson}}" width="120"></el-table-column> {{ end }}
  67. {{ end }}
  68. <el-table-column label="按钮组">
  69. <template slot-scope="scope">
  70. <el-button class="table-button" @click="update{{.StructName}}(scope.row)" size="small" type="primary" icon="el-icon-edit">变更</el-button>
  71. <el-button type="danger" icon="el-icon-delete" size="mini" @click="openComfirm(scope.row)">删除</el-button>
  72. </template>
  73. </el-table-column>
  74. </el-table>
  75. <el-pagination
  76. :current-page="page"
  77. :page-size="pageSize"
  78. :page-sizes="[10, 30, 50, 100]"
  79. :style="{float:'right',padding:'20px'}"
  80. :total="total"
  81. @current-change="handleCurrentChange"
  82. @size-change="handleSizeChange"
  83. layout="total, sizes, prev, pager, next, jumper"
  84. ></el-pagination>
  85. <el-dialog :before-close="closeDialog" :visible.sync="dialogFormVisible" title="弹窗操作">
  86. <el-form :model="formData" label-position="right" label-width="80px">
  87. {{- range .Fields}}
  88. <el-form-item label="{{.FieldDesc}}:">
  89. {{- if eq .FieldType "bool" }}
  90. <el-switch active-color="#13ce66" inactive-color="#ff4949" active-text="是" inactive-text="否" v-model="formData.{{.FieldJson}}" clearable ></el-switch>
  91. {{ end -}}
  92. {{- if eq .FieldType "string" }}
  93. <el-input v-model="formData.{{.FieldJson}}" clearable placeholder="请输入" ></el-input>
  94. {{ end -}}
  95. {{- if eq .FieldType "int" }}
  96. {{- if .DictType}}
  97. <el-select v-model="formData.{{ .FieldJson }}" placeholder="请选择" clearable>
  98. <el-option v-for="(item,key) in {{ .DictType }}Options" :key="key" :label="item.label" :value="item.value"></el-option>
  99. </el-select>
  100. {{ else -}}
  101. <el-input v-model.number="formData.{{ .FieldJson }}" clearable placeholder="请输入"></el-input>
  102. {{ end -}}
  103. {{ end -}}
  104. {{- if eq .FieldType "time.Time" }}
  105. <el-date-picker type="date" placeholder="选择日期" v-model="formData.{{ .FieldJson }}" clearable></el-date-picker>
  106. {{ end -}}
  107. {{- if eq .FieldType "float64" }}
  108. <el-input-number v-model="formData.{{ .FieldJson }}" :precision="2" clearable></el-input-number>
  109. {{ end -}}
  110. </el-form-item>
  111. {{ end -}}
  112. </el-form>
  113. <div class="dialog-footer" slot="footer">
  114. <el-button @click="closeDialog">取 消</el-button>
  115. <el-button @click="enterDialog" type="primary">确 定</el-button>
  116. </div>
  117. </el-dialog>
  118. </div>
  119. </template>
  120. <script>
  121. import {
  122. create{{.StructName}},
  123. delete{{.StructName}},
  124. delete{{.StructName}}ByIds,
  125. update{{.StructName}},
  126. find{{.StructName}},
  127. get{{.StructName}}List
  128. } from "@/api/{{.PackageName}}"; // 此处请自行替换地址
  129. import { formatTimeToStr } from "@/utils/date";
  130. import infoList from "@/mixins/infoList";
  131. export default {
  132. name: "{{.StructName}}",
  133. mixins: [infoList],
  134. data() {
  135. return {
  136. listApi: get{{ .StructName }}List,
  137. dialogFormVisible: false,
  138. visible: false,
  139. type: "",
  140. deleteVisible: false,
  141. multipleSelection: [],
  142. {{- range .Fields}}
  143. {{- if .DictType }}
  144. {{ .DictType }}Options:[],
  145. {{ end -}}
  146. {{end -}}
  147. formData: {
  148. {{range .Fields}}
  149. {{- if eq .FieldType "bool" -}}
  150. {{.FieldJson}}:false,
  151. {{ end -}}
  152. {{- if eq .FieldType "string" -}}
  153. {{.FieldJson}}:"",
  154. {{ end -}}
  155. {{- if eq .FieldType "int" -}}
  156. {{.FieldJson}}:0,
  157. {{ end -}}
  158. {{- if eq .FieldType "time.Time" -}}
  159. {{.FieldJson}}:new Date(),
  160. {{ end -}}
  161. {{- if eq .FieldType "float64" -}}
  162. {{.FieldJson}}:0,
  163. {{ end -}}
  164. {{ end }}
  165. }
  166. };
  167. },
  168. filters: {
  169. formatDate: function(time) {
  170. if (time != null && time != "") {
  171. var date = new Date(time);
  172. return formatTimeToStr(date, "yyyy-MM-dd hh:mm:ss");
  173. } else {
  174. return "";
  175. }
  176. },
  177. formatBoolean: function(bool) {
  178. if (bool != null) {
  179. return bool ? "是" :"否";
  180. } else {
  181. return "";
  182. }
  183. }
  184. },
  185. methods: {
  186. //条件搜索前端看此方法
  187. onSubmit() {
  188. this.page = 1
  189. this.pageSize = 10
  190. {{- range .Fields}} {{- if eq .FieldType "bool" }}
  191. if (this.searchInfo.{{.FieldJson}}==""){
  192. this.searchInfo.{{.FieldJson}}=null
  193. } {{ end }} {{ end }}
  194. this.getTableData()
  195. },
  196. handleSelectionChange(val) {
  197. this.multipleSelection = val
  198. },
  199. openComfirm(row){
  200. this.$confirm('确定要删除吗?', '提示', {
  201. confirmButtonText: '确定',
  202. cancelButtonText: '取消',
  203. type: 'warning'
  204. }).then(() => {
  205. this.delete{{.StructName}}(row);
  206. });
  207. },
  208. async onDelete() {
  209. const ids = []
  210. if(this.multipleSelection.length == 0){
  211. this.$message({
  212. type: 'warning',
  213. message: '请选择要删除的数据'
  214. })
  215. return
  216. }
  217. this.multipleSelection &&
  218. this.multipleSelection.map(item => {
  219. ids.push(item.ID)
  220. })
  221. const res = await delete{{.StructName}}ByIds({ ids })
  222. if (res.code == 0) {
  223. this.$message({
  224. type: 'success',
  225. message: '删除成功'
  226. })
  227. if (this.tableData.length == ids.length) {
  228. this.page--;
  229. }
  230. this.deleteVisible = false
  231. this.getTableData()
  232. }
  233. },
  234. async update{{.StructName}}(row) {
  235. const res = await find{{.StructName}}({ ID: row.ID });
  236. this.type = "update";
  237. if (res.code == 0) {
  238. this.formData = res.data.re{{.Abbreviation}};
  239. this.dialogFormVisible = true;
  240. }
  241. },
  242. closeDialog() {
  243. this.dialogFormVisible = false;
  244. this.formData = {
  245. {{range .Fields}}
  246. {{- if eq .FieldType "bool" -}}
  247. {{.FieldJson}}:false,
  248. {{ end -}}
  249. {{- if eq .FieldType "string" -}}
  250. {{.FieldJson}}:"",
  251. {{ end -}}
  252. {{- if eq .FieldType "int" -}}
  253. {{.FieldJson}}:0,
  254. {{ end -}}
  255. {{- if eq .FieldType "time.Time" -}}
  256. {{.FieldJson}}:new Date(),
  257. {{ end -}}
  258. {{- if eq .FieldType "float64" -}}
  259. {{.FieldJson}}:0,
  260. {{ end -}}
  261. {{ end }}
  262. };
  263. },
  264. async delete{{.StructName}}(row) {
  265. this.visible = false;
  266. const res = await delete{{.StructName}}({ ID: row.ID });
  267. if (res.code == 0) {
  268. this.$message({
  269. type: "success",
  270. message: "删除成功"
  271. });
  272. if (this.tableData.length == 1) {
  273. this.page--;
  274. }
  275. this.getTableData();
  276. }
  277. },
  278. async enterDialog() {
  279. let res;
  280. switch (this.type) {
  281. case "create":
  282. res = await create{{.StructName}}(this.formData);
  283. break;
  284. case "update":
  285. res = await update{{.StructName}}(this.formData);
  286. break;
  287. default:
  288. res = await create{{.StructName}}(this.formData);
  289. break;
  290. }
  291. if (res.code == 0) {
  292. this.$message({
  293. type:"success",
  294. message:"创建/更改成功"
  295. })
  296. this.closeDialog();
  297. this.getTableData();
  298. }
  299. },
  300. openDialog() {
  301. this.type = "create";
  302. this.dialogFormVisible = true;
  303. }
  304. },
  305. async created() {
  306. await this.getTableData();
  307. {{ range .Fields -}}
  308. {{- if .DictType }}
  309. await this.getDict("{{.DictType}}");
  310. {{ end -}}
  311. {{- end }}
  312. }
  313. };
  314. </script>
  315. <style>
  316. </style>