index.vue 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <template>
  2. <div class="body">
  3. <el-card class="box-card">
  4. <div slot="header" class="clearfix">
  5. <el-button
  6. type="primary"
  7. style="float: right"
  8. icon="el-icon-plus"
  9. @click="dialogFormVisible = true"
  10. >新建应用</el-button>
  11. </div>
  12. <div class="text item">
  13. <el-table stripe :data="tableData" border style="width: 100%">
  14. <el-table-column prop="appName" label="应用名称" min-width="100" />
  15. <el-table-column align="center" label="操作" min-width="100" width="500">
  16. <template slot-scope="scope">
  17. <el-link
  18. :underline="false"
  19. style="margin-right:1em"
  20. type="primary"
  21. @click="handeldialog(scope.row.appId)"
  22. >编辑</el-link>
  23. <el-popconfirm
  24. icon="el-icon-info"
  25. icon-color="red"
  26. title="确定要删除该配置吗?"
  27. @onConfirm="handleDelete(scope.row.appId)"
  28. >
  29. <el-link slot="reference" type="danger" :underline="false">删除</el-link>
  30. </el-popconfirm>
  31. </template>
  32. </el-table-column>
  33. </el-table>
  34. <el-pagination
  35. v-show="WxTotal!==0"
  36. style="float:right; margin:20px 0"
  37. :total="WxTotal"
  38. :current-page="currentPage"
  39. :page-size="pageSize"
  40. :page-sizes="[pageSize, 20, 35,40,50,80,100]"
  41. layout="total, prev, pager, next, sizes"
  42. @size-change="handleSizeChange"
  43. @current-change="handleCurrentChange"
  44. />
  45. </div>
  46. </el-card>
  47. <el-dialog
  48. :title="!APP_ID?'新建应用':'修改应用'"
  49. :visible.sync="dialogFormVisible"
  50. :show-close="false"
  51. :close-on-click-modal="false"
  52. >
  53. <el-form
  54. ref="ruleForm"
  55. :model="ruleForm"
  56. :rules="rules"
  57. label-width="10vw"
  58. class="demo-ruleForm"
  59. >
  60. <el-form-item label="应用名称" prop="appName" style="width:30vw">
  61. <el-input v-model="ruleForm.appName" />
  62. </el-form-item>
  63. </el-form>
  64. <div slot="footer" class="dialog-footer">
  65. <el-button type="primary" @click="submitForm('ruleForm')">{{ !APP_ID?'新建应用':'修改应用' }}</el-button>
  66. <el-button @click="closeDialog('ruleForm')">取 消</el-button>
  67. </div>
  68. </el-dialog>
  69. </div>
  70. </template>
  71. <script>
  72. import {
  73. getAppControllerList,
  74. DeleteAppController,
  75. saveAppController,
  76. detailsAppController,
  77. ChangeAppController
  78. } from '@/api/AppControllerApi'
  79. export default {
  80. data() {
  81. return {
  82. APP_ID: '',
  83. ruleForm: {
  84. appName: '',
  85. secret: ''
  86. },
  87. rules: {
  88. appName: [
  89. { required: true, message: '请输入应用名称', trigger: 'blur' }
  90. ]
  91. },
  92. appName: undefined,
  93. dialogFormVisible: false,
  94. tableData: [],
  95. //
  96. pageSize: 10,
  97. currentPage: 1,
  98. WxTotal: 0 // 条目总数
  99. }
  100. },
  101. // -----------模态框事件------------
  102. watch: {
  103. APP_ID: function (newAppID, oldVal) {
  104. detailsAppController(newAppID).then((res) => {
  105. this.ruleForm = res.data
  106. })
  107. }
  108. },
  109. mounted() {
  110. this.onSearch()
  111. if (this.APP_ID) {
  112. detailsAppController(this.APP_ID).then((res) => {
  113. this.ruleForm = res.data
  114. })
  115. }
  116. },
  117. methods: {
  118. // 取消
  119. closeDialog(formName) {
  120. this.APP_ID = ''
  121. this.$refs[formName].resetFields()
  122. this.dialogFormVisible = false
  123. },
  124. // 确定
  125. handeldialog(e) {
  126. this.APP_ID = e
  127. this.dialogFormVisible = true
  128. },
  129. submitForm(formName) {
  130. this.$refs[formName].validate((valid) => {
  131. if (valid) {
  132. if (this.APP_ID == '') {
  133. saveAppController(this.ruleForm)
  134. .then((e) => {
  135. this.$message.success('配置保存成功')
  136. this.dialogFormVisible = false
  137. this.$refs[formName].resetFields()
  138. this.onSearch()
  139. console.log('保存字段', e)
  140. })
  141. .catch((e) => {
  142. this.$message.error('保存失败', e)
  143. })
  144. } else {
  145. ChangeAppController(this.ruleForm, this.APP_ID).then((res) => {
  146. this.$message.success('配置修改成功')
  147. this.dialogFormVisible = false
  148. this.onSearch()
  149. })
  150. }
  151. } else {
  152. return false
  153. }
  154. })
  155. },
  156. // -----------模态框事件结束------------
  157. // 改变每页显示条数
  158. handleSizeChange(val) {
  159. this.pageSize = val
  160. this.changePagination()
  161. },
  162. // 改变页码
  163. handleCurrentChange(val) {
  164. this.currentPage = val
  165. this.changePagination()
  166. },
  167. // 改变分页组件重新查询数据
  168. changePagination() {
  169. getAppControllerList({
  170. pageNum: this.currentPage,
  171. pageSize: this.pageSize
  172. }).then((res) => {
  173. this.tableData = res.data.records
  174. })
  175. },
  176. handleAdd() {
  177. // this.$router.push({ path: 'AppController/Edit' });
  178. this.dialogFormVisible = true
  179. },
  180. handleDelete(APP_DELETE) {
  181. DeleteAppController(APP_DELETE).then(() => {
  182. this.onSearch()
  183. })
  184. },
  185. onSearch() {
  186. getAppControllerList({
  187. pageNum: this.currentPage,
  188. pageSize: this.pageSize
  189. }).then((res) => {
  190. console.log('🚀 ~ file: index.vue ~ line 118 ~ onSearch ~ res', res)
  191. this.tableData = res.data.records
  192. this.WxTotal = res.data.total
  193. })
  194. },
  195. onReset() {
  196. this.appName = ''
  197. this.onSearch()
  198. }
  199. }
  200. }
  201. </script>