mapdata.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <template>
  2. <div class="mapdata">
  3. <!-- <textarea class="content" v-model="message"></textarea>
  4. <button class="sure" v-on:click="onclick">提交</button> -->
  5. <!-- <input class="" type="file" @change="getFile" /> -->
  6. <div class="file-upload">
  7. <div class="file-upload-text">上传文件</div>
  8. <input
  9. class="file-upload-input"
  10. id="upfile"
  11. type="file"
  12. @change="getFile"
  13. />
  14. </div>
  15. <div class="fileName">{{ fileName }}</div>
  16. <div class="status">{{ status }}</div>
  17. </div>
  18. </template>
  19. <script>
  20. import Vue from "vue";
  21. export default Vue.extend({
  22. data() {
  23. return {
  24. name: "mapdata",
  25. message: null,
  26. fileName: "",
  27. status: "",
  28. };
  29. },
  30. created() {
  31. // console.log(this.name);
  32. },
  33. methods: {
  34. getFile(e) {
  35. debugger;
  36. console.log(e.target.files);
  37. var fileSelect = e.target.files[0];
  38. this.fileName = fileSelect.name;
  39. let reader = new FileReader();
  40. if (typeof FileReader === "undefined") {
  41. console.log("您的浏览器不支持FileReader接口");
  42. return;
  43. }
  44. reader.readAsText(fileSelect, "gb2312"); //注意读取中文的是用这个编码,不是utf-8
  45. const _this = this;
  46. reader.onload = function() {
  47. // console.log(reader.result);
  48. var result = reader.result;
  49. // _this.$nextTick(() => {
  50. // _this.voiceContent = reader.result;
  51. // });
  52. _this.handleStr(result);
  53. };
  54. //console.log(reader);
  55. },
  56. // onclick() {
  57. // console.log(this.message);
  58. // this.handleStr(this.message);
  59. // },
  60. handleStr(mapstr) {
  61. var maparr = mapstr.split("<DIV ");
  62. //console.log("maparr", maparr);
  63. var _this = this;
  64. var allDiv = [];
  65. //debugger;
  66. maparr.map((item) => {
  67. var divobj = {};
  68. var divarr = item.split(" ");
  69. //console.log("divarr", divarr);
  70. divarr.map(function(item) {
  71. if (item.indexOf("id=") > -1) {
  72. var idarr = item.split("=");
  73. // debugger;
  74. var idstr = idarr[1];
  75. divobj.id = idstr;
  76. // console.log("idstr", idstr);
  77. return;
  78. }
  79. });
  80. divobj.height = this.getNum(item, "HEIGHT");
  81. divobj.width = this.getNum(item, "WIDTH");
  82. divobj.left = this.getNum(item, "LEFT");
  83. divobj.top = this.getNum(item, "TOP");
  84. if (divobj.width) {
  85. allDiv.push(divobj);
  86. }
  87. // var hindex = divarr.indexOf("HEIGHT:");
  88. // var windex = divarr.indexOf("WIDTH:");
  89. // var lindex = divarr.indexOf("LEFT:");
  90. // var tindex = divarr.indexOf("TOP:");
  91. //console.log(hindex, windex, lindex, tindex);
  92. });
  93. console.log("allDiv-string", JSON.stringify(allDiv));
  94. this.status = "上传中...";
  95. this.saveMapInfo(allDiv);
  96. },
  97. saveMapInfo(allDiv) {
  98. var _this = this;
  99. this.$axios.post(this.$api.saveMapInfo, allDiv).then((res) => {
  100. console.log("res", res);
  101. if (res.data && res.data.result == "success") {
  102. _this.status = "上传成功";
  103. _this.fileName = "";
  104. document.getElementById("upfile").value = null;
  105. //document.getElementById("upfile").files = nul;
  106. }
  107. });
  108. },
  109. getNum(str, param) {
  110. //debugger;
  111. var paindex = str.indexOf(param);
  112. if (paindex > -1) {
  113. var palength = param.length;
  114. var otherstr = str.substr(paindex + palength);
  115. var pxindex = otherstr.indexOf("px");
  116. var numstr = otherstr.substr(0, pxindex);
  117. numstr = numstr.replace(/:/, "");
  118. return numstr ? Number(numstr) : "";
  119. }
  120. return "";
  121. },
  122. },
  123. });
  124. </script>
  125. <style lang="less" scoped>
  126. .mapdata {
  127. padding: 30px;
  128. position: relative;
  129. // }
  130. // .file-upload {
  131. // width: 90px;
  132. // height: 40px;
  133. // position: relative;
  134. // overflow: hidden;
  135. // border: 1px solid #0f996b;
  136. // display: inline-block;
  137. // border-radius: 4px;
  138. // font-size: 15px;
  139. // color: #000;
  140. // text-align: center;
  141. // line-height: 40px;
  142. // }
  143. // .file-upload-input {
  144. // background-color: transparent;
  145. // position: absolute;
  146. // width: 999px;
  147. // height: 999px;
  148. // top: 0px;
  149. // left: 0px;
  150. // cursor: pointer;
  151. // }
  152. .file-upload {
  153. width: 90px;
  154. height: 36px;
  155. position: relative;
  156. overflow: hidden;
  157. border: 1px solid #0f996b;
  158. display: inline-block;
  159. border-radius: 4px;
  160. font-size: 14px;
  161. color: #0f996b;
  162. text-align: center;
  163. line-height: 36px;
  164. margin: 10px 0 auto auto;
  165. }
  166. .file-upload-input {
  167. background-color: transparent;
  168. position: absolute;
  169. width: 999px;
  170. height: 999px;
  171. top: -100px;
  172. left: -100px;
  173. cursor: pointer;
  174. }
  175. .fileName {
  176. margin-top: 14px;
  177. color: #000000;
  178. font-size: 16px;
  179. }
  180. .status {
  181. margin-top: 14px;
  182. color: red;
  183. }
  184. // .content {
  185. // width: 900px;
  186. // height: 700px;
  187. // }
  188. // .sure {
  189. // display: flex;
  190. // justify-content: center;
  191. // align-items: center;
  192. // cursor: pointer;
  193. // width: 60px;
  194. // height: 40px;
  195. // font-size: 16px;
  196. // color: #575271;
  197. // font-weight: 400;
  198. // line-height: 22px;
  199. // margin-left: 10px;
  200. // background: rgb(126, 216, 116);
  201. // border: 2px solid hsla(0, 0%, 100%, 0.8);
  202. // box-sizing: border-box;
  203. // border-radius: 8px;
  204. // margin-top: 20px;
  205. // }
  206. }
  207. </style>