You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

313 lines
10 KiB

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