point.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <template>
  2. <div>
  3. <div class="top">
  4. <el-upload
  5. class="upload-demo"
  6. action="https://jsonplaceholder.typicode.com/posts/"
  7. :on-change="handleChange"
  8. >
  9. <el-button size="small" type="primary">点击上传</el-button>
  10. </el-upload>
  11. <el-select
  12. v-model="value"
  13. placeholder="请选择"
  14. filterable
  15. @change="byTableName"
  16. >
  17. <el-option
  18. v-for="item in tableList"
  19. :key="item.value"
  20. :label="item.label"
  21. :value="item.value"
  22. >
  23. </el-option>
  24. </el-select>
  25. <el-cascader
  26. v-model="value1"
  27. placeholder="试试搜索:指南"
  28. :options="options"
  29. :props="{ multiple: true }"
  30. collapse-tags
  31. filterable
  32. ></el-cascader>
  33. <el-button type="primary" @click="search">查询</el-button>
  34. </div>
  35. <el-table :data="tableData1" style="width: 100%">
  36. <el-table-column
  37. v-for="i in arr"
  38. :key="i"
  39. :prop="i"
  40. :label="i"
  41. width="180"
  42. >
  43. </el-table-column>
  44. </el-table>
  45. </div>
  46. </template>
  47. <script>
  48. import XLSX from "xlsx";
  49. export default {
  50. data() {
  51. return {
  52. props: { multiple: true },
  53. tableData: [{}],
  54. tableData1:[],
  55. arr: [],
  56. value: "",
  57. value1: "",
  58. tableList: [],
  59. options: []
  60. };
  61. },
  62. created() {
  63. this.fetch();
  64. },
  65. mounted() {},
  66. methods: {
  67. fetch() {
  68. this.$http
  69. .get("UnionTable/tableNames")
  70. .then((res) => {
  71. var res = res.data;
  72. for (let i in res) {
  73. var obj = {};
  74. obj.lable = obj.value = res[i];
  75. this.tableList.push(obj);
  76. }
  77. })
  78. .catch(function (error) {
  79. console.log(error);
  80. });
  81. },
  82. byTableName() {
  83. this.$http
  84. .post("UnionTable/columns", this.value)
  85. .then((res) => {
  86. console.log(res);
  87. var res = res.data;
  88. for (let i in res) {
  89. var obj = {};
  90. obj.label = obj.value = res[i];
  91. console.log(obj);
  92. this.options.push(obj);
  93. }
  94. })
  95. .catch(function (error) {
  96. console.log(error);
  97. });
  98. },
  99. search() {
  100. this.$http
  101. .post("UnionTable/tableData",
  102. {
  103. tableName:this.value,
  104. columnsName:this.value1,
  105. excelData:this.tableData
  106. })
  107. .then((res) => {
  108. console.log(res);
  109. })
  110. .catch(function (error) {
  111. console.log(error);
  112. });
  113. },
  114. handleChange(file, fileList) {
  115. const fileReader = new FileReader();
  116. fileReader.onload = (ev) => {
  117. try {
  118. const data = ev.target.result;
  119. const workbook = XLSX.read(data, {
  120. type: "binary",
  121. });
  122. console.log(workbook);
  123. let sheet = Object.keys(workbook.Sheets)[0];
  124. const json = XLSX.utils.sheet_to_json(workbook.Sheets[sheet]); //获得以第一列为键名的sheet数组对象
  125. console.log(json);
  126. var arr = [];
  127. for (let v in json) {
  128. if (v > 100) {
  129. break;
  130. }
  131. for (let k in Object.keys(json[v])) {
  132. if (arr.indexOf(Object.keys(json[v])[k]) == -1) {
  133. arr.push(Object.keys(json[v])[k]);
  134. }
  135. }
  136. }
  137. this.arr = arr;
  138. this.$nextTick(() => {
  139. this.tableData = json;
  140. });
  141. } catch (e) {
  142. console.log(e);
  143. }
  144. };
  145. fileReader.readAsBinaryString(file.raw);
  146. },
  147. },
  148. };
  149. </script>
  150. <style lang="scss" scoped>
  151. .top {
  152. width: 60%;
  153. margin-top: 10px;
  154. display: flex;
  155. justify-content: space-around;
  156. overflow: hidden;
  157. }
  158. </style>