3b8417b46216ada2edde8cc08a127f3d4cb54527.svn-base 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. <template>
  2. <el-dialog class="customs_dialog" :visible.sync="dialogVisible" :before-close="handleClose" title="小水库批量填报">
  3. <div class="upload_div">
  4. <el-upload
  5. ref="upload"
  6. class="upload-demo"
  7. drag
  8. :action="actionUrl"
  9. :on-preview="handlePreview"
  10. :on-remove="handleRemove"
  11. :before-remove="beforeRemove"
  12. :before-upload="beforeAvatarUpload"
  13. :on-success="handleSuccess"
  14. multiple
  15. :limit="1"
  16. :on-exceed="handleExceed"
  17. :auto-upload="false"
  18. :file-list="fileList">
  19. <i class="el-icon-upload"></i>
  20. <div class="el-upload__text">将模板文件拖到此处,或<em>点击选取模板文件</em></div>
  21. </el-upload>
  22. <el-button type="primary" @click="submitUpload" :loading="uploadLoading" >点击上传</el-button>
  23. </div>
  24. <div ref="messageDiv" id="messageDiv" style="width: 100%;margin-top: 10px">
  25. </div>
  26. <!-- 验证数据的弹出框 -->
  27. <shuiKuTianbaoPlVer v-if="showShuiKuTianBaoPlVer"
  28. @closePlVerDialog="closePlVerDialog"
  29. :tableData="tableData"
  30. :uuid="uuid"
  31. :id='id'
  32. ></shuiKuTianbaoPlVer>
  33. <a type="primary" @click="openPlVerDialog" href="javascript:void(0)" v-show="showButton">点击弹框</a>
  34. </el-dialog>
  35. </template>
  36. <script>
  37. import request from '../../utils/gw_ajax_request.js'
  38. import shuiKuTianbaoPlVer from './shuiKuTianbao_piliang_verify'
  39. export default {
  40. props: ['showShuiKuTianBaoPl','id'],
  41. components: {
  42. shuiKuTianbaoPlVer:shuiKuTianbaoPlVer,
  43. },
  44. data(){
  45. return{
  46. dialogVisible:true,
  47. fileList:[],
  48. uuid:1,
  49. actionUrl:'',
  50. socket:null,
  51. showShuiKuTianBaoPlVer:false,
  52. filePath:'',
  53. tableData:[],
  54. showButton:false,
  55. uploadLoading: false,
  56. }
  57. },
  58. mounted:function(){
  59. },
  60. computed: {
  61. persId() {
  62. return localStorage.getItem("userid")
  63. ? localStorage.getItem("userid")
  64. : "1098101939614724096";
  65. }
  66. },
  67. methods:{
  68. handleClose(done) {
  69. this.closeSocket();
  70. this.$parent.getSkDataList();
  71. this.$emit("closePlDialog");
  72. },
  73. handleRemove(file, fileList) {
  74. console.log(file, fileList);
  75. },
  76. handlePreview(file) {
  77. console.log(file);
  78. },
  79. handleExceed(files, fileList) {
  80. this.$message.warning(`当前限制选择 1 个文件,本次选择了 ${files.length} 个文件,共选择了 ${files.length + fileList.length} 个文件`);
  81. },
  82. beforeRemove(file, fileList) {
  83. //return this.$confirm(`确定移除 ${ file.name }?`);
  84. },
  85. beforeAvatarUpload(file) {
  86. let Xls = file.name.split('.');
  87. if(Xls[1] === 'xls'){
  88. return file;
  89. }else {
  90. this.$message.error('请上传编辑后的模板文件!')
  91. return false;
  92. }
  93. },
  94. handleSuccess(res,file,fileList){
  95. let filePath = res.data.key;
  96. this.filePath = filePath;
  97. // 调用解析的接口
  98. request.get(`/dc/impExcel/parseExcel/${this.persId}/${this.uuid}?filePath=${this.filePath}&tid=08&pid=${this.id}`).then(res => {
  99. this.tableData = res.data;
  100. console.log("table:" + this.tableData)
  101. if(this.tableData.length > 0){
  102. this.showButton = true;
  103. this.showShuiKuTianBaoPlVer = true;
  104. }else{
  105. this.$alert('可填报数据条数为0或非本组数据,请确认!', '提示', {
  106. confirmButtonText: '确定',
  107. type: 'warning',
  108. callback: action => {
  109. }
  110. });
  111. }
  112. // 只展示错误数据的逻辑
  113. // if(this.tableData[0].Message == undefined){
  114. // this.showButton = true;
  115. // this.showShuiKuTianBaoPlVer = true;
  116. // }else{
  117. // var message = this.tableData[0].Message;
  118. // if(message == 'success'){
  119. // this.showButton = true;
  120. // this.showShuiKuTianBaoPlVer = true;
  121. // }else {
  122. // this.$alert('可填报数据条数为0或非本组数据,请确认!', '提示', {
  123. // confirmButtonText: '确定',
  124. // type: 'warning',
  125. // callback: action => {
  126. // }
  127. // });
  128. // }
  129. // }
  130. this.uploadLoading = false;
  131. });
  132. },
  133. openSocket() {
  134. if (typeof(WebSocket) == "undefined") {
  135. console.log("您的浏览器不支持WebSocket");
  136. } else {
  137. this.closeSocket();
  138. console.log("您的浏览器支持WebSocket");
  139. console.log("sid:" + this.uuid);
  140. //实例化WebSocket对象,指定要连接的服务器地址与端口 建立连接
  141. // let baseUrl = "localhost:8101";
  142. // 测试服务器
  143. let baseUrl = "10.1.102.136:8100";
  144. // let baseUrl = "sv.goldenwater.com.cn";
  145. // let baseUrl = "localhost:8085/wsbackend";
  146. this.socket = new WebSocket(`ws://${baseUrl}/websocket/${this.uuid}`);
  147. // socket
  148. let socket = this.socket;
  149. //打开事件
  150. socket.onopen = function () {
  151. console.log("Socket 已打开");
  152. //socket.send("这是来自客户端的消息" + location.href + new Date());
  153. };
  154. //获得消息事件
  155. socket.onmessage = function (msg) {
  156. console.log(msg.data);
  157. document.getElementById('messageDiv').innerHTML = document.getElementById('messageDiv').innerHTML
  158. + msg.data + "<br/>"
  159. //发现消息进入 开始处理前端触发逻辑
  160. if(msg.data.indexOf('完成数据校验') > 0){
  161. }
  162. };
  163. //关闭事件
  164. socket.onclose = function () {
  165. console.log("Socket已关闭");
  166. };
  167. //发生了错误事件
  168. socket.onerror = function () {
  169. console.log("Socket发生了错误");
  170. //此时可以尝试刷新页面
  171. };
  172. // 路由跳转时结束websocket链接
  173. this.$router.afterEach(function () {
  174. socket.close()
  175. })
  176. }
  177. },
  178. getUUID (){
  179. request.get('/socket/uuid').then(res => {
  180. if(res.success){
  181. this.uuid = res.data.key;
  182. this.actionUrl = `/pdcApi/dc/impExcel/imp/${this.persId}/${this.uuid}?tid=08`;
  183. }else {
  184. console.log("success不为true")
  185. }
  186. });
  187. },
  188. closeSocket() {
  189. if (this.socket != null) {
  190. this.socket.close();
  191. }
  192. },
  193. submitUpload() {
  194. this.uploadLoading = true;
  195. // 获取uuid
  196. let p1 = new Promise((resolve) => {
  197. resolve(request({
  198. url: `/socket/uuid`,
  199. method: 'get',
  200. }))
  201. });
  202. Promise.all([p1]).then((result)=>{
  203. if(result){
  204. //
  205. let data = result[0];
  206. let uuid = data.data.key;
  207. this.uuid = uuid;
  208. // console.log(this.uuid);
  209. // this.actionUrl = `/pdcApi/dc/impExcel/imp/${this.persId}/${this.uuid}?tid=08`;
  210. this.actionUrl = `/pdcApi/dc/impExcel/uploadExcel/${this.persId}/${this.uuid}?tid=08`;
  211. this.openSocket();
  212. }
  213. }).then(()=>{
  214. this.$refs.messageDiv.innerHTML = '';
  215. this.$refs.upload.submit();
  216. })
  217. },
  218. closePlVerDialog(){
  219. this.showShuiKuTianBaoPlVer = false;
  220. },
  221. openPlVerDialog(){
  222. this.showShuiKuTianBaoPlVer = true;
  223. }
  224. },
  225. watch:{
  226. showShuiKuTianBaoPl(n,o){
  227. // 想用监听得使用v-show,因为v-if会重新渲染DOM,子组件已关闭
  228. // alert("进入监听")
  229. // if(!n){
  230. // alert(this.showShuiKuTianBaoPl)
  231. // this.closeSocket();
  232. // }
  233. },
  234. },
  235. }
  236. </script>
  237. <style>
  238. .title{
  239. font-size: 16px;
  240. }
  241. .el-icon-edit{
  242. margin-right: 10px;
  243. }
  244. .customs_dialog .el-dialog{
  245. width: 40% !important;
  246. }
  247. .customs_dialog .el-dialog__body {
  248. padding: 30px 20px;
  249. color: #606266;
  250. font-size: 14px;
  251. height: 60vh;
  252. overflow: auto;
  253. }
  254. .upload_div {
  255. text-align: center;
  256. }
  257. .upload_div_left {
  258. border:1px solid red;
  259. width:50%;
  260. height:100px;
  261. float:left;
  262. }
  263. .upload_div_right {
  264. border:1px solid red;
  265. width:50%;
  266. height:100%;
  267. float:right;
  268. }
  269. </style>