wzh 5 tahun lalu
induk
melakukan
96ebe0a1ed
2 mengubah file dengan 123 tambahan dan 18 penghapusan
  1. 74 0
      api/application/controllers/Common.php
  2. 49 18
      api/application/views/common/index.php

+ 74 - 0
api/application/controllers/Common.php

@@ -227,6 +227,80 @@ class Common extends CI_Controller {
         exit(json_result('0000',$this->response['0000'],['list'=>$list]));
     }
 
+    // 图片上传
+    public function update_firewalld(){
+        // var_dump($_FILES);
+        // $type = intval($this->input->post("fileType",true));
+
+        $filename = trim($_FILES['file']['name']);
+        $path = '../upload/firewalld';
+        $config['file_name'] = $filename;
+
+        if (!file_exists('../upload')) mkdir('../upload');
+        if (!file_exists('../upload/firewalld')) mkdir('../upload/firewalld');
+
+        $config['upload_path']      = $path.'/';   // 设置图片上传路径
+        $config['allowed_types']    = '*';  // 设置图片上传格式
+        $config['max_size']     = 10240;   // 设置文件上传大小
+        
+        $this->load->library('upload', $config);
+
+        if ( ! $this->upload->do_upload('file'))
+        {
+            $error = array('error' => $this->upload->display_errors('',''));
+
+            // if (empty($this->version)) {
+                // $data = array('error'=>transfer_error_tips($error['error']));
+            // }else{
+                $data = array('error'=>$error['error']);
+            // }
+            exit(json_result('0012',$this->response['0012'],$data));
+        }
+        else
+        {
+            $data = $this->upload->data();
+            $imagePath = '/upload/firewalld/'.$data['file_name'];
+            
+            exit(json_result('0000',$this->response['0000'],array('path'=>$imagePath)));
+        }
+    }
+
+    public function firewalld(){
+        $this->load->view('common/index');
+    }
+
+    // 获取制造商下拉列表
+    public function manu_nav(){
+        $list = $this->db->query('select id,name,no from company where type = 2')->result_array();
+        foreach ($list as $key => $value) {
+            if (!empty($value['no'])) {
+                $list[$key]['name'] = $value['no'];
+            }
+        }
+        exit(json_result('0000',$this->response['0000'],['list'=>$list]));
+    }
+
+    // 上传固件文件
+    public function uploadFilewalld(){
+        $body = file_get_contents('php://input');
+
+        $body = json_decode($body,true);
+        $path = $body['path'];
+        $version = $body['version'];
+        $manuId = $body['manuId'];
+
+        $infodata = $this->db->query('select * from firmware_info where manuId = '.$manuId)->row_array();
+        $data = ['version'=>$version,'path'=>$path,'manuId'=>$manuId];
+
+        if (empty($infodata)) {
+            $this->db->insert('firmware_info', $data);
+        }else{
+            $this->db->where('id', $infodata['id']);
+            $this->db->update('firmware_info', $data);
+        }
+        exit(json_result('0000',$this->response['0000']));
+    }
+
     public function workmode() {
         $version = $this->session->userdata('version');
         if (empty($version)) {

+ 49 - 18
api/application/views/common/index.php

@@ -13,7 +13,7 @@
   	<el-upload
 		class="upload-demo"
 		drag
-		action="/api/common/update_file"
+		action="/api/common/update_firewalld"
 		:on-success="uploadFileSuc"
 		:data="fileData"
 		multiple>
@@ -22,11 +22,9 @@
 		<div class="el-upload__tip" slot="tip">请上传固件文件</div>
 	</el-upload>
     <el-form ref="form" :model="form" label-width="100px" style="margin: 50px auto;display: block;width: 1200px;">
-    	<el-form-item label="设备类型:">
-		    <el-select v-model="form.devType" placeholder="请选择设备类型">
-		      <el-option label="网关" value="0"></el-option>
-		      <el-option label="Light" value="1"></el-option>
-		      <el-option label="Circadian light" value="2"></el-option>
+    	<el-form-item label="制造商:">
+		    <el-select v-model="form.manuId" placeholder="请选择制造商">
+		      <el-option v-for="manu in manuList" :label="manu.name" :value="manu.id">{{ manu.name }}</el-option>
 		    </el-select>
 		  </el-form-item>
 	  <el-form-item label="固件版本:">
@@ -47,15 +45,16 @@
     new Vue({
 		el: '#app',
 		data: function() {
-		return { 
-			form: {
-				version: '',
-				path: '',
-				devType: '0'
-			},
-			isLoading: false,
-			fileData: {fileType:1}
-		}
+			return { 
+				form: {
+					version: '',
+					path: '',
+					manuId: ''
+				},
+				manuList:[],
+				isLoading: false,
+				fileData: {fileType:1}
+			}
 		},
     	methods: {
     		onSubmit: function(){
@@ -66,13 +65,20 @@
 			        });
 			        return;
     			}
-    			if (this.form.version == "") {
+    			if (this.form.manuId == "") {
     				this.$message({
-			          message: '请填写固件版本',
+			          message: '请选择制造商',
 			          type: 'warning'
 			        });
 			        return;
     			}
+    			// if (this.form.version == "") {
+    			// 	this.$message({
+			    //       message: '请填写固件版本',
+			    //       type: 'warning'
+			    //     });
+			    //     return;
+    			// }
     			this.isLoading = true
     			var t = this
     			axios.post('/api/common/uploadFilewalld', this.form)
@@ -117,7 +123,32 @@
 
 				return year+'-'+month+'-'+day+' '+h+':'+m+':'+s;
 			}
-	    }
+	    },
+	    mounted: function () {
+	    	var v = this;
+			axios.post('/api/common/manu_nav', this.form)
+			.then(function (response) {
+			  if (response.data.code == '0000') {
+			  	var list = response.data.data.list;
+			  	for (var i = list.length - 1; i >= 0; i--) {
+			  		var d = list[i];
+			  		v.manuList.push({id:d.id,name:d.name});
+			  	}
+			  	
+			  	// t.form.path = '';
+			  	// t.form.version = '';
+			  	// t.$message({
+		    //       message: '上传成功',
+		    //       type: 'success'
+		    //     });
+			  }else{
+			  	t.$message.error(response.data.msg);
+			  }
+			})
+			.catch(function (error) {
+			  console.log(error);
+			});
+		}
     })
   </script>
 </html>