ConfigManage.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <template>
  2. <div>
  3. <el-row>
  4. <el-col :span="10">工具</el-col>
  5. <el-col :span="10"></el-col>
  6. <el-col :span="4">
  7. <el-button type="primary" @click="handleNew">新建</el-button>
  8. </el-col>
  9. </el-row>
  10. <hr style="border-top: 2px solid #eee;margin: 10px 0;">
  11. <el-row style="margin-top:10px;">
  12. <el-table :data="configList">
  13. <el-table-column
  14. prop="id"
  15. label="#"
  16. width="48"
  17. ></el-table-column>
  18. <el-table-column
  19. prop="name"
  20. label="名称"
  21. width="108"
  22. ></el-table-column>
  23. <el-table-column
  24. prop="code"
  25. label="编码"
  26. width="108"
  27. ></el-table-column>
  28. <el-table-column
  29. label="配置"
  30. width="180"
  31. >
  32. <template slot-scope="scope">
  33. <el-button @click="handleShow(scope.row)" size="small" type="text">查看</el-button>
  34. </template>
  35. </el-table-column>
  36. <el-table-column
  37. prop="created"
  38. label="创建时间"
  39. width="180"
  40. ></el-table-column>
  41. <el-table-column label="操作" width="180">
  42. <template slot-scope="scope">
  43. <el-button @click="handleEdit(scope.row)" size="small" type="text">编辑</el-button>
  44. <el-button @click="handleDel(scope.row)" size="small" type="text">删除</el-button>
  45. </template>
  46. </el-table-column>
  47. </el-table>
  48. </el-row>
  49. <el-dialog title="修改/添加 配置" :visible.sync="dialogVisible" width="60%">
  50. <el-form label-width="98px" :model="formData">
  51. <el-form-item label="名称:">
  52. <el-input v-model="formData.name" style="width: 220px;"></el-input>
  53. </el-form-item>
  54. <el-form-item label="编码:">
  55. <el-input v-model="formData.code" style="width: 220px;"></el-input>
  56. </el-form-item>
  57. <el-form-item label="配置:">
  58. <el-row
  59. type="flex"
  60. justify="space-between"
  61. :gutter="20"
  62. style="margin-bottom:10px"
  63. v-for="(item,index) in formData.config"
  64. :key="index"
  65. >
  66. <el-col :span="3" style="text-align:right">名称:</el-col>
  67. <el-col :span="7">
  68. <el-input placeholder="请输入内容" v-model="formData.config[index].key"></el-input>
  69. </el-col>
  70. <el-col :span="3" style="text-align:right">值:</el-col>
  71. <el-col :span="7">
  72. <el-input placeholder="请输入内容" v-model="formData.config[index].val"></el-input>
  73. </el-col>
  74. <el-col :span="4">
  75. <el-button
  76. v-show="index==(formData.config.length-1)"
  77. @click="plus"
  78. type="primary"
  79. icon="el-icon-plus"
  80. circle
  81. ></el-button>
  82. <el-button
  83. v-show="index>0"
  84. @click="minus(index)"
  85. type="primary"
  86. icon="el-icon-minus"
  87. circle
  88. ></el-button>
  89. </el-col>
  90. </el-row>
  91. </el-form-item>
  92. </el-form>
  93. <span slot="footer" class="dialog-footer">
  94. <el-button @click="dialogVisible = false">取 消</el-button>
  95. <el-button type="primary" @click="handleSubmit">确 定</el-button>
  96. </span>
  97. </el-dialog>
  98. <el-dialog title="配置属性" :visible.sync="dialogConfig" width="48%">
  99. <el-table :data="configInfo" label-width="100px">
  100. <el-table-column prop="key" label="名称"></el-table-column>
  101. <el-table-column prop="val" label="值"></el-table-column>
  102. </el-table>
  103. </el-dialog>
  104. </div>
  105. </template>
  106. <script>
  107. import { mapActions } from "vuex";
  108. export default {
  109. name: "ConfigManage",
  110. data(){
  111. return {
  112. configList:null,
  113. dialogVisible:false,
  114. dialogConfig:false,
  115. formData:{
  116. name:'',
  117. code:'',
  118. config:[
  119. {
  120. key: "",
  121. val: ""
  122. }
  123. ],
  124. },
  125. configInfo:null
  126. }
  127. },
  128. created() {
  129. this.loadList()
  130. },
  131. methods:{
  132. ...mapActions(["fetch"]),
  133. loadList(){
  134. this.fetch({
  135. api:'/publics/sysconf/list',
  136. success:res=>{
  137. console.log(res)
  138. this.configList = res
  139. }
  140. })
  141. },
  142. handleShow(row){
  143. console.log(row)
  144. this.configInfo = JSON.parse(row.conf.data)
  145. this.dialogConfig=true
  146. },
  147. handleEdit(row){
  148. this.clearForm()
  149. this.formData.id = row.id // 关键
  150. this.formData.name=row.name
  151. this.formData.code=row.code
  152. this.formData.config = JSON.parse(row.conf.data)
  153. this.dialogVisible = true
  154. },
  155. handleDel(row){
  156. this.fetch({
  157. api:'/publics/sysconf/delete',
  158. data:{id:row.id},
  159. success:res=>{
  160. this.$message.info("删除成功")
  161. this.loadList()
  162. },
  163. fail:err=>{
  164. console.log(err)
  165. if(err.errMsg)
  166. this.$message.info(err.errMsg)
  167. }
  168. })
  169. },
  170. handleNew(){
  171. this.clearForm()
  172. this.dialogVisible=true
  173. },
  174. handleSubmit(){
  175. //提交了
  176. let data = {
  177. name:this.formData.name,
  178. code:this.formData.code,
  179. conf:JSON.stringify({data:JSON.stringify(this.formData.config)})
  180. }
  181. let api = "/publics/sysconf/add"
  182. if(this.formData.id) {
  183. api = "/publics/sysconf/update"
  184. data.id=this.formData.id
  185. }
  186. this.fetch({
  187. api,
  188. data,
  189. success:res=>{
  190. //关掉对惶恐
  191. console.log(res)
  192. this.dialogVisible = false
  193. // this.clearForm()
  194. this.loadList()
  195. },
  196. fail:err=>{
  197. console.log(err)
  198. if(err.errMsg)
  199. this.$message.info(err.errMsg)
  200. }
  201. })
  202. },
  203. clearForm(){
  204. if(this.formData.id) delete this.formData.id
  205. this.formData.name=""
  206. this.formData.code =""
  207. this.formData.config=[
  208. {
  209. key: "",
  210. val: ""
  211. }
  212. ]
  213. },
  214. // 配置项增加
  215. plus() {
  216. this.formData.config.push({
  217. key:'',val:''
  218. })
  219. },
  220. // 配置项减少
  221. minus(index) {
  222. this.formData.config.splice(index,1)
  223. }
  224. }
  225. }
  226. </script>
  227. <style scoped>
  228. </style>