Configure.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <template>
  2. <div>
  3. <el-row id="head">
  4. <el-button type="primary" @click="fetchData">Refresh</el-button>
  5. <el-button type="primary" @click="uploadConfig">Upload</el-button>
  6. </el-row>
  7. <el-input type="textarea" autosize v-model="textarea" placeholder="frpc configrue file, can not be empty..."></el-input>
  8. </div>
  9. </template>
  10. <script>
  11. export default {
  12. data() {
  13. return {
  14. textarea: ''
  15. }
  16. },
  17. created() {
  18. this.fetchData()
  19. },
  20. watch: {
  21. '$route': 'fetchData'
  22. },
  23. methods: {
  24. fetchData() {
  25. fetch('/api/config', {credentials: 'include'})
  26. .then(res => {
  27. return res.text()
  28. }).then(text => {
  29. this.textarea= text
  30. }).catch( err => {
  31. this.$message({
  32. showClose: true,
  33. message: 'Get configure content from frpc failed!',
  34. type: 'warning'
  35. })
  36. })
  37. },
  38. uploadConfig() {
  39. this.$confirm('This operation will upload your frpc configure file content and hot reload it, do you want to continue?', 'Notice', {
  40. confirmButtonText: 'Yes',
  41. cancelButtonText: 'No',
  42. type: 'warning'
  43. }).then(() => {
  44. if (this.textarea == "") {
  45. this.$message({
  46. type: 'warning',
  47. message: 'Configure content can not be empty!'
  48. })
  49. return
  50. }
  51. fetch('/api/config', {
  52. credentials: 'include',
  53. method: 'PUT',
  54. body: this.textarea,
  55. }).then(() => {
  56. fetch('/api/reload', {credentials: 'include'})
  57. .then(() => {
  58. this.$message({
  59. type: 'success',
  60. message: 'Success'
  61. })
  62. }).catch(err => {
  63. this.$message({
  64. showClose: true,
  65. message: 'Reload frpc configure file error, ' + err,
  66. type: 'warning'
  67. })
  68. })
  69. }).catch(err => {
  70. this.$message({
  71. showClose: true,
  72. message: 'Put config to frpc and hot reload failed!',
  73. type: 'warning'
  74. })
  75. })
  76. }).catch(() => {
  77. this.$message({
  78. type: 'info',
  79. message: 'Canceled'
  80. })
  81. })
  82. }
  83. }
  84. }
  85. </script>
  86. <style>
  87. #head {
  88. margin-bottom: 30px;
  89. }
  90. </style>