importChannel.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template>
  2. <div id="importChannel" v-loading="isLoging">
  3. <el-dialog
  4. title="导入通道数据"
  5. width="30rem"
  6. top="2rem"
  7. :append-to-body="true"
  8. :close-on-click-modal="false"
  9. :visible.sync="showDialog"
  10. :destroy-on-close="true"
  11. @close="close()"
  12. >
  13. <div>
  14. <el-upload
  15. class="upload-box"
  16. drag
  17. :action="uploadUrl"
  18. name="file"
  19. :headers="headers"
  20. :on-success="successHook"
  21. :on-error="errorHook"
  22. >
  23. <i class="el-icon-upload"></i>
  24. <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
  25. <div class="el-upload__tip" slot="tip">只能上传 csv / xls / xlsx 文件</div>
  26. </el-upload>
  27. </div>
  28. </el-dialog>
  29. <ShowErrorData ref="showErrorData" :gbIds="errorGBIds" :streams="errorStreams" ></ShowErrorData>
  30. </div>
  31. </template>
  32. <script>
  33. import ShowErrorData from './importChannelShowErrorData.vue'
  34. import userService from "../service/UserService";
  35. export default {
  36. name: "importChannel",
  37. components: {
  38. ShowErrorData,
  39. },
  40. created() {},
  41. data() {
  42. return {
  43. submitCallback: null,
  44. showDialog: false,
  45. isLoging: false,
  46. isEdit: false,
  47. errorStreams: [],
  48. errorGBIds: [],
  49. headers: {
  50. "access-token": userService.getToken()
  51. },
  52. uploadUrl: process.env.NODE_ENV === 'development'? `http://127.0.0.1:8080/debug/api/push/upload`: (window.baseUrl ? window.baseUrl : "") + `/api/push/upload`,
  53. };
  54. },
  55. methods: {
  56. openDialog: function (callback) {
  57. this.showDialog = true;
  58. this.submitCallback = callback;
  59. },
  60. onSubmit: function () {
  61. console.log("onSubmit");
  62. console.log(this.form);
  63. this.$axios.axios({
  64. method:"post",
  65. url:`/api/platform/catalog/${!this.isEdit? "add":"edit"}`,
  66. data: this.form
  67. })
  68. .then((res)=> {
  69. if (res.data.code === 0) {
  70. console.log("添加/修改成功")
  71. if (this.submitCallback)this.submitCallback()
  72. }else {
  73. this.$message({
  74. showClose: true,
  75. message: res.data.msg,
  76. type: "error",
  77. });
  78. }
  79. this.close();
  80. })
  81. .catch((error)=> {
  82. console.log(error);
  83. });
  84. },
  85. close: function () {
  86. this.showDialog = false;
  87. },
  88. successHook: function(response, file, fileList){
  89. if (response.code === 0) {
  90. this.$message({
  91. showClose: true,
  92. message: response.msg,
  93. type: "success",
  94. });
  95. }else if (response.code === 1) {
  96. this.errorGBIds = response.data.gbId
  97. this.errorStreams = response.data.stream
  98. console.log(this.$refs)
  99. console.log(this.$refs.showErrorData)
  100. this.$refs.showErrorData.openDialog()
  101. }else {
  102. this.$message({
  103. showClose: true,
  104. message: response.msg,
  105. type: "error",
  106. });
  107. }
  108. },
  109. errorHook: function (err, file, fileList) {
  110. this.$message({
  111. showClose: true,
  112. message: err,
  113. type: "error",
  114. });
  115. }
  116. },
  117. };
  118. </script>
  119. <style>
  120. .upload-box{
  121. text-align: center;
  122. }
  123. .errDataBox{
  124. max-height: 15rem;
  125. overflow: auto;
  126. }
  127. </style>