index.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <!-- 引入样式 -->
  6. <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
  7. <style type="text/css">
  8. .upload-demo{text-align: center;margin-top: 80px;}
  9. </style>
  10. </head>
  11. <body>
  12. <div id="app">
  13. <el-upload
  14. class="upload-demo"
  15. drag
  16. action="/api/common/update_file"
  17. :on-success="uploadFileSuc"
  18. :data="fileData"
  19. multiple>
  20. <i class="el-icon-upload"></i>
  21. <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
  22. <div class="el-upload__tip" slot="tip">请上传固件文件</div>
  23. </el-upload>
  24. <el-form ref="form" :model="form" label-width="100px" style="margin: 50px auto;display: block;width: 1200px;">
  25. <el-form-item label="设备类型:">
  26. <el-select v-model="form.devType" placeholder="请选择设备类型">
  27. <el-option label="网关" value="0"></el-option>
  28. <el-option label="Light" value="1"></el-option>
  29. <el-option label="Circadian light" value="2"></el-option>
  30. </el-select>
  31. </el-form-item>
  32. <el-form-item label="固件版本:">
  33. <el-input v-model="form.version" style="width: 200px;display: inline-block;" placeholder="请输入固件版本"></el-input>
  34. </el-form-item>
  35. <el-form-item>
  36. <el-button type="primary" @click="onSubmit" :loading="isLoading">提交固件</el-button>
  37. </el-form-item>
  38. </el-form>
  39. </div>
  40. </body>
  41. <!-- 先引入 Vue -->
  42. <script src="https://unpkg.com/vue/dist/vue.js"></script>
  43. <!-- 引入组件库 -->
  44. <script src="https://unpkg.com/element-ui/lib/index.js"></script>
  45. <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
  46. <script>
  47. new Vue({
  48. el: '#app',
  49. data: function() {
  50. return {
  51. form: {
  52. version: '',
  53. path: '',
  54. devType: '0'
  55. },
  56. isLoading: false,
  57. fileData: {fileType:1}
  58. }
  59. },
  60. methods: {
  61. onSubmit: function(){
  62. if (this.form.path == "") {
  63. this.$message({
  64. message: '请上传固件文件',
  65. type: 'warning'
  66. });
  67. return;
  68. }
  69. if (this.form.version == "") {
  70. this.$message({
  71. message: '请填写固件版本',
  72. type: 'warning'
  73. });
  74. return;
  75. }
  76. this.isLoading = true
  77. var t = this
  78. axios.post('/api/common/uploadFilewalld', this.form)
  79. .then(function (response) {
  80. t.isLoading = false
  81. if (response.data.code == '0000') {
  82. t.form.path = '';
  83. t.form.version = '';
  84. t.$message({
  85. message: '上传成功',
  86. type: 'success'
  87. });
  88. }else{
  89. t.$message.error(response.data.msg);
  90. }
  91. })
  92. .catch(function (error) {
  93. console.log(error);
  94. });
  95. },
  96. clearData: function(){
  97. this.form.backInfo = ''
  98. },
  99. uploadFileSuc:function(response, file, fileList){
  100. var path = response.data.path;
  101. this.form.path = path;
  102. console.log(path);
  103. },
  104. get_time: function() {
  105. var myDate = new Date();
  106. var year = myDate.getFullYear();
  107. var month = myDate.getMonth() + 1;
  108. month = month < 10 ? '0'+month : month;
  109. var day = myDate.getDate();
  110. day = day < 10 ? '0'+day : day;
  111. var h = myDate.getHours();
  112. h = h < 10 ? '0'+h : h;
  113. var m = myDate.getMinutes();
  114. m = m < 10 ? '0'+m : m;
  115. var s = myDate.getSeconds();
  116. s = s < 10 ? '0'+s : s;
  117. return year+'-'+month+'-'+day+' '+h+':'+m+':'+s;
  118. }
  119. }
  120. })
  121. </script>
  122. </html>