mapdata.vue 5.9 KB

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