• input改造文件上传,el-table的改造,点击上传,拖拽上传,多选上传


    第一个input标签效果

    第二个input标签的效果

    el-table的改造效果

    1. <template>
    2. <div class="outerBox">
    3. <div class="analyze" v-if="status">
    4. <div class="unFile">
    5. <div class="mainBox">
    6. // <img class="picture" src="../../static/images/upload.png" />
    7. <div class="title">上传.log文件进行解析</div>
    8. <div class="clickBtn">
    9. <div class='notisfyWord'>上传内容</div>
    10. <input
    11. type="file"
    12. id="fileInput"
    13. @change="handleFileChange"
    14. accept=".log"
    15. style="width:100%;height:100%;cursor: pointer;opacity:0"
    16. /></div>
    17. </div>
    18. </div>
    19. </div>
    20. <div class="fileBox" v-if="!status">
    21. <div class="upload">
    22. <div>上传.log文件进行解析
    23. <input
    24. type="file"
    25. id="fileInput"
    26. @change="handleFileChange"
    27. accept=".log"
    28. style="width:100%;height:100%;opacity:0;cursor:pointer;position:absolute;top:0;left:0;"
    29. />
    30. </div>
    31. <div class="fileName">{{ fileName }}</div>
    32. </div>
    33. <div class="tableStyle">
    34. <el-table
    35. :data="tableData"
    36. height="70vh"
    37. style="width: 100%"
    38. :header-row-style="{
    39. color: 'white',
    40. }"
    41. :row-style="{
    42. color: 'white',
    43. }"
    44. :cell-style="{
    45. textAlign: 'center',
    46. border: '1px solid #0a1641',
    47. }"
    48. :header-cell-style="{
    49. textAlign: 'center',
    50. background: '#222d54',
    51. border: '1px solid #222d54',
    52. }"
    53. :row-class-name="tableRowClassName"
    54. v-loading="loading"
    55. >
    56. <el-table-column prop="sourceTime" label="时间" width="180">
    57. </el-table-column>
    58. <el-table-column prop="item" label="事项" width="150">
    59. </el-table-column>
    60. <!-- <el-table-column prop="msg" label="描述"> </el-table-column> -->
    61. <el-table-column prop="source" label="来源" width="100">
    62. </el-table-column>
    63. <el-table-column prop="subsystem" label="子系统"> </el-table-column>
    64. <el-table-column prop="level" label="严重等级"> </el-table-column>
    65. <el-table-column prop="value" label="值"> </el-table-column>
    66. </el-table>
    67. <!-- <el-pagination
    68. class="pagination"
    69. @size-change="handleSizeChange"
    70. @current-change="handleCurrentChange"
    71. :current-page.sync="currentPage1"
    72. :page-size="100"
    73. layout="total, prev, pager, next"
    74. :total="1000"
    75. >
    76. </el-pagination> -->
    77. </div>
    78. </div>
    79. </div>
    80. </template>
    81. <script>
    82. export default {
    83. data() {
    84. return {
    85. loading: true,
    86. tableData: [],
    87. fileName: "",
    88. status: true,
    89. tableTotal:'',
    90. pageSize:100,
    91. midTableData: [],
    92. test:[
    93. {item:'qqqqq',unusual:'1'},
    94. {item:'qqqqq',unusual:'0'},
    95. {item:'qqqqq',unusual:'0'},
    96. {item:'qqqqq',unusual:'1'},
    97. ]
    98. };
    99. },
    100. mounted() {
    101. this.tableRowClassName;
    102. },
    103. methods: {
    104. clickBtn() {
    105. document.getElementById("fileInput").click();
    106. },
    107. handleFileChange(event) {
    108. const file = event.target.files[0];
    109. const fileType = file.name.split('.').pop();
    110. //if(fileType != 'log'){
    111. // this.$message.error('请上传.log文件');
    112. // return
    113. // }
    114. // if(file.size > 50 * 1024){
    115. // this.$message.error('最小上传文件大小为50k');
    116. // return
    117. // }
    118. this.fileName = file.name;
    119. this.status = false;
    120. // 模拟异步
    121. setTimeout(()=>{
    122. this.loading = false
    123. this.tableData = this.test;
    124. },2000)
    125. },
    126. tableRowClassName({ row, rowIndex }) {
    127. if (row.unusual === '0') {
    128. return "selected-row";
    129. } else {
    130. return "selected-rows";
    131. }
    132. },
    133. handleCurrentChange(val) {
    134. const start = val * 100
    135. const end = (val + 1) * 100
    136. },
    137. },
    138. };
    139. </script>
    140. <style scoped>
    141. ::v-deep .selected-row {
    142. background-color: #e4d33d !important;
    143. }
    144. ::v-deep .selected-rows {
    145. background-color: #0a1641 !important;
    146. }
    147. .outerBox {
    148. background: linear-gradient(180deg, #eaf4ff 0%, #042f61 100%);
    149. }
    150. .analyze {
    151. width: 100%;
    152. height: 100%;
    153. padding: 0 !important;
    154. display: flex;
    155. justify-content: center;
    156. }
    157. .upload {
    158. margin-top: 10px;
    159. line-height: 40px;
    160. display: flex;
    161. justify-content: center;
    162. align-items: center;
    163. color: white;
    164. font-size: 15px;
    165. background-color: #045fcb;
    166. border-radius: 7px;
    167. margin-bottom: 10px;
    168. position: relative;
    169. cursor: pointer;
    170. }
    171. .selected-row {
    172. background-color: #e4d33d !important;
    173. }
    174. .tableStyle {
    175. width: 100%;
    176. /* background-color: #094b97; */
    177. }
    178. .el-button {
    179. color: white !important;
    180. background: linear-gradient(180deg, #82dde1 0%, #4bb8c0 100%) !important;
    181. }
    182. .exportBtn {
    183. position: absolute;
    184. right: 10px;
    185. bottom: 10px;
    186. }
    187. .unFile {
    188. width: 50%;
    189. height: 40%;
    190. display: flex;
    191. justify-content: center;
    192. align-items: center;
    193. margin-top: 15%;
    194. background-color: #094b97;
    195. border-radius: 10px;
    196. border: 3px dashed #d4e1f3;
    197. overflow: hidden;
    198. }
    199. .picture {
    200. width: 150px;
    201. }
    202. .mainBox {
    203. display: flex;
    204. flex-direction: column;
    205. align-items: center;
    206. }
    207. .title {
    208. color: white;
    209. font-size: 15px;
    210. display: flex;
    211. justify-content: center;
    212. }
    213. .clickBtn {
    214. overflow: hidden;
    215. opacity:1;
    216. color: white;
    217. border-radius: 5px;
    218. background-color: #2188ff;
    219. width:150px;
    220. height:50px;
    221. font-size: 15px;
    222. cursor: pointer;
    223. position: relative;
    224. }
    225. .notisfyWord{
    226. cursor: pointer;
    227. position: absolute;
    228. left:50%;
    229. top:50%;
    230. transform: translate(-50%,-50%);
    231. }
    232. .fileBox {
    233. background-color: #0a1642;
    234. padding: 10px;
    235. }
    236. .fileName {
    237. margin-left: 10px;
    238. }
    239. .pagination {
    240. display: flex;
    241. justify-content: right;
    242. }
    243. ::v-deep .el-table--enable-row-hover .el-table__body tr:hover > td {
    244. color: black !important;
    245. background-color: #0460cb !important;
    246. }
    247. ::v-deep .el-table__empty-text {
    248. color: white !important;
    249. }
    250. ::v-deep .el-table__body-wrapper {
    251. background-color: #0a1641 !important;
    252. }
    253. ::v-deep .el-table::before {
    254. background-color: #0a1642;
    255. }
    256. ::v-deep .el-table .el-table__cell.gutter {
    257. background-color: #0a1642;
    258. }
    259. </style>

    3、input本身支持拖拽上传但要设置opcity为0,不能设置diaplay:none或者visiables

      如果不使用拖拽上传的话,只点击上传可使用如下

    1. <div
    2. class="clickBtn"
    3. @click="clickBtn"
    4. >
    5. 上传内容
    6. </div>
    7. <input
    8. type="file"
    9. id="fileInput"
    10. @change="handleFileChange"
    11. style="display: none"
    12. />
    13. clickBtn(){
    14. console.log("clickFackBtn");
    15. document.getElementById('fileInput').click()
    16. },
    17. handleFileChange(event) {
    18. const file = event.target.files[0];
    19. console.log(file);
    20. },

    input同时也支持多选文件上传

    4、表格效果

    只设置一小框的样式

    1. <el-table
    2. :data="tableData"
    3. height="calc(100vh - 230px)"
    4. style="width: 100%"
    5. :header-row-style="{}"
    6. :row-style="{}"
    7. :header-cell-style="{
    8. textAlign: 'center',
    9. color: 'white',
    10. }"
    11. v-loading="loading"
    12. :cell-style="cellStyle"
    13. >
    14. <el-table-column prop="siteRange" label="站点名称" width="240">
    15. </el-table-column>
    16. <el-table-column prop="carName" label="车号"> </el-table-column>
    17. <el-table-column prop="troubleType" label="告警类型" width="130">
    18. </el-table-column>
    19. <el-table-column prop="troubleLevel" label="严重等级">
    20. </el-table-column>
    21. </el-table>
    1. methods: {
    2. cellStyle({ row, column }) {
    3. if (
    4. column.property === "troubleLevel" &&
    5. row.troubleLevel == "三级告警"
    6. ) {
    7. return {
    8. color: "#F6BD16", // 设置字体颜色
    9. textAlign: "center",
    10. };
    11. } else if (
    12. column.property === "troubleLevel" &&
    13. row.troubleLevel == "二级告警"
    14. ) {
    15. return {
    16. color: "#FF9D4D",
    17. textAlign: "center",
    18. };
    19. } else if (
    20. column.property === "troubleLevel" &&
    21. row.troubleLevel == "一级告警"
    22. ) {
    23. return {
    24. color: "#F6BD16",
    25. textAlign: "center",
    26. };
    27. } else {
    28. return {
    29. color: "white",
    30. textAlign: "center",
    31. };
    32. }
    33. },
    34. },

  • 相关阅读:
    127.0.0.1 和 0.0.0.0 地址的区别
    Java实现在PDF中添加骑缝章
    【LINUX】 LINUX | 提取U盘映像
    【毕业设计】基于单片机的蓝牙相机设计与实现 - 物联网 单片机 嵌入式
    IDEA配置tomcat,快速部署tomcat
    高斯金字塔的秘密(二,加速高斯,c#实现)
    C++面试常见问题 — C++语言基础
    《TCP/IP网络编程》阅读笔记--getsockopt和setsockopt的使用
    apt-get 指令格式以及常用指令
    外贸在谷歌搜索客户,为什么搜索出来的都是同行?
  • 原文地址:https://blog.csdn.net/m0_47999208/article/details/134079482