importChannel.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. :on-success="successHook"
  20. :on-error="errorHook"
  21. >
  22. <i class="el-icon-upload"></i>
  23. <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
  24. <div class="el-upload__tip" slot="tip">只能上传 csv / xls / xlsx 文件</div>
  25. </el-upload>
  26. </div>
  27. </el-dialog>
  28. <ShowErrorData ref="showErrorData" :gbIds="errorGBIds" :streams="errorStreams" ></ShowErrorData>
  29. </div>
  30. </template>
  31. <script>
  32. import ShowErrorData from './importChannelShowErrorData.vue'
  33. export default {
  34. name: "importChannel",
  35. components: {
  36. ShowErrorData,
  37. },
  38. created() {},
  39. data() {
  40. return {
  41. submitCallback: null,
  42. showDialog: false,
  43. isLoging: false,
  44. isEdit: false,
  45. errorStreams: null,
  46. errorGBIds: null,
  47. uploadUrl: process.env.NODE_ENV === 'development'?`debug/api/push/upload`:`api/push/upload`,
  48. };
  49. },
  50. methods: {
  51. openDialog: function (callback) {
  52. this.showDialog = true;
  53. this.submitCallback = callback;
  54. },
  55. onSubmit: function () {
  56. console.log("onSubmit");
  57. console.log(this.form);
  58. this.$axios({
  59. method:"post",
  60. url:`/api/platform/catalog/${!this.isEdit? "add":"edit"}`,
  61. data: this.form
  62. })
  63. .then((res)=> {
  64. if (res.data.code === 0) {
  65. console.log("添加/修改成功")
  66. if (this.submitCallback)this.submitCallback()
  67. }else {
  68. this.$message({
  69. showClose: true,
  70. message: res.data.msg,
  71. type: "error",
  72. });
  73. }
  74. this.close();
  75. })
  76. .catch((error)=> {
  77. console.log(error);
  78. });
  79. },
  80. close: function () {
  81. this.showDialog = false;
  82. },
  83. successHook: function(response, file, fileList){
  84. if (response.code === 0) {
  85. this.$message({
  86. showClose: true,
  87. message: response.msg,
  88. type: "success",
  89. });
  90. }else if (response.code === 1) {
  91. this.errorGBIds = response.data.gbId
  92. this.errorStreams = response.data.stream
  93. console.log(this.$refs)
  94. console.log(this.$refs.showErrorData)
  95. this.$refs.showErrorData.openDialog()
  96. }else {
  97. this.$message({
  98. showClose: true,
  99. message: response.msg,
  100. type: "error",
  101. });
  102. }
  103. },
  104. errorHook: function (err, file, fileList) {
  105. this.$message({
  106. showClose: true,
  107. message: err,
  108. type: "error",
  109. });
  110. }
  111. },
  112. };
  113. </script>
  114. <style>
  115. .upload-box{
  116. text-align: center;
  117. }
  118. .errDataBox{
  119. max-height: 15rem;
  120. overflow: auto;
  121. }
  122. </style>