传感器升级文件上传下载功能

This commit is contained in:
zhanghan11 2024-08-12 15:48:38 +08:00
parent 1013deeabf
commit a2a41fc449
13 changed files with 1042 additions and 20 deletions

View File

@ -0,0 +1,179 @@
package com.inspur.web.controller.ipc;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.inspur.common.config.TzipcConfig;
import com.inspur.common.constant.Constants;
import com.inspur.common.utils.StringUtils;
import com.inspur.common.utils.file.FileUtils;
import com.inspur.web.controller.common.CommonController;
import org.apache.commons.io.FilenameUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.inspur.common.annotation.Log;
import com.inspur.common.core.controller.BaseController;
import com.inspur.common.core.domain.AjaxResult;
import com.inspur.common.enums.BusinessType;
import com.inspur.ipc.domain.IpcSensorUpdateFile;
import com.inspur.ipc.service.IIpcSensorUpdateFileService;
import com.inspur.common.utils.poi.ExcelUtil;
import com.inspur.common.core.page.TableDataInfo;
/**
* 传感器升级文件Controller
*
* @author zhanghan11
* @date 2024-08-12
*/
@RestController
@RequestMapping("/ipc/sensorUpdateFile")
public class IpcSensorUpdateFileController extends BaseController
{
private static final Logger log = LoggerFactory.getLogger(CommonController.class);
@Autowired
private IIpcSensorUpdateFileService ipcSensorUpdateFileService;
/**
* 查询传感器升级文件列表
*/
@PreAuthorize("@ss.hasPermi('ipc:sensorUpdateFile:list')")
@GetMapping("/list")
public TableDataInfo list(IpcSensorUpdateFile ipcSensorUpdateFile)
{
startPage();
List<IpcSensorUpdateFile> list = ipcSensorUpdateFileService.selectIpcSensorUpdateFileList(ipcSensorUpdateFile);
return getDataTable(list);
}
/**
* 导出传感器升级文件列表
*/
@PreAuthorize("@ss.hasPermi('ipc:sensorUpdateFile:export')")
@Log(title = "传感器升级文件", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, IpcSensorUpdateFile ipcSensorUpdateFile)
{
List<IpcSensorUpdateFile> list = ipcSensorUpdateFileService.selectIpcSensorUpdateFileList(ipcSensorUpdateFile);
ExcelUtil<IpcSensorUpdateFile> util = new ExcelUtil<IpcSensorUpdateFile>(IpcSensorUpdateFile.class);
util.exportExcel(response, list, "传感器升级文件数据");
}
/**
* 获取传感器升级文件详细信息
*/
@PreAuthorize("@ss.hasPermi('ipc:sensorUpdateFile:query')")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id)
{
return AjaxResult.success(ipcSensorUpdateFileService.selectIpcSensorUpdateFileById(id));
}
/**
* 新增传感器升级文件
*/
@PreAuthorize("@ss.hasPermi('ipc:sensorUpdateFile:add')")
@Log(title = "传感器升级文件", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody IpcSensorUpdateFile ipcSensorUpdateFile)
{
return toAjax(ipcSensorUpdateFileService.insertIpcSensorUpdateFile(ipcSensorUpdateFile));
}
/**
* 修改传感器升级文件
*/
@PreAuthorize("@ss.hasPermi('ipc:sensorUpdateFile:edit')")
@Log(title = "传感器升级文件", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody IpcSensorUpdateFile ipcSensorUpdateFile)
{
return toAjax(ipcSensorUpdateFileService.updateIpcSensorUpdateFile(ipcSensorUpdateFile));
}
/**
* 删除传感器升级文件
*/
@PreAuthorize("@ss.hasPermi('ipc:sensorUpdateFile:remove')")
@Log(title = "传感器升级文件", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids)
{
return toAjax(ipcSensorUpdateFileService.deleteIpcSensorUpdateFileByIds(ids));
}
/**
* 升级文件下载
*
*/
@GetMapping("/downloadUpdateFile")
public void fileDownload( HttpServletResponse response, HttpServletRequest request)
{
try
{
String fileName = ipcSensorUpdateFileService.selectLastestIpcSensorUpdateFile().getPath();
if (!FileUtils.checkAllowDownload(fileName))
{
throw new Exception(StringUtils.format("文件名称({})非法,不允许下载。 ", fileName));
}
String filePath = fileName.replace(Constants.RESOURCE_PREFIX,TzipcConfig.getProfile());
String realFileName = getRealFileName(fileName);
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
FileUtils.setAttachmentResponseHeader(response, realFileName);
FileUtils.writeBytes(filePath, response.getOutputStream());
}
catch (Exception e)
{
log.error("下载文件失败", e);
}
}
/**
* 通用下载请求
*
* @param fileName 文件名称
*/
@GetMapping("/download")
public void fileDownload(String fileName, HttpServletResponse response, HttpServletRequest request)
{
try
{
if (!FileUtils.checkAllowDownload(fileName))
{
throw new Exception(StringUtils.format("文件名称({})非法,不允许下载。 ", fileName));
}
String filePath = fileName.replace(Constants.RESOURCE_PREFIX,TzipcConfig.getProfile());
String realFileName = getRealFileName(fileName);
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
FileUtils.setAttachmentResponseHeader(response, realFileName);
FileUtils.writeBytes(filePath, response.getOutputStream());
}
catch (Exception e)
{
log.error("下载文件失败", e);
}
}
private String getRealFileName(String filePath){
String fileName = FileUtils.getName(filePath);
String realFileName = fileName.substring(0,fileName.lastIndexOf("_"))+ "." + FilenameUtils.getExtension(fileName);
return realFileName;
}
}

View File

@ -2,11 +2,10 @@ package com.inspur.common.utils.file;
/**
* 媒体类型工具类
*
*
* @author inspur
*/
public class MimeTypeUtils
{
public class MimeTypeUtils {
public static final String IMAGE_PNG = "image/png";
public static final String IMAGE_JPG = "image/jpg";
@ -16,15 +15,15 @@ public class MimeTypeUtils
public static final String IMAGE_BMP = "image/bmp";
public static final String IMAGE_GIF = "image/gif";
public static final String[] IMAGE_EXTENSION = { "bmp", "gif", "jpg", "jpeg", "png" };
public static final String[] FLASH_EXTENSION = { "swf", "flv" };
public static final String[] IMAGE_EXTENSION = {"bmp", "gif", "jpg", "jpeg", "png"};
public static final String[] MEDIA_EXTENSION = { "swf", "flv", "mp3", "wav", "wma", "wmv", "mid", "avi", "mpg",
"asf", "rm", "rmvb" };
public static final String[] FLASH_EXTENSION = {"swf", "flv"};
public static final String[] VIDEO_EXTENSION = { "mp4", "avi", "rmvb" };
public static final String[] MEDIA_EXTENSION = {"swf", "flv", "mp3", "wav", "wma", "wmv", "mid", "avi", "mpg",
"asf", "rm", "rmvb"};
public static final String[] VIDEO_EXTENSION = {"mp4", "avi", "rmvb"};
public static final String[] DEFAULT_ALLOWED_EXTENSION = {
// 图片
@ -36,12 +35,13 @@ public class MimeTypeUtils
// 视频格式
"mp4", "avi", "rmvb",
// pdf
"pdf" };
"pdf",
// 传感器升级文件
"bin"
};
public static String getExtension(String prefix)
{
switch (prefix)
{
public static String getExtension(String prefix) {
switch (prefix) {
case IMAGE_PNG:
return "png";
case IMAGE_JPG:

View File

@ -109,7 +109,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
// 过滤请求
.authorizeRequests()
// 对于登录login 注册register 验证码captchaImage 允许匿名访问
.antMatchers("/login", "/register", "/captchaImage","/systemName","/sharedKeys").anonymous()
.antMatchers("/login", "/register", "/captchaImage","/systemName","/sharedKeys","/ipc/sensorUpdateFile/downloadUpdateFile").anonymous()
// 数据接收接口允许匿名访问
.antMatchers("/ipc/dataReceive/plcData","/ipc/dataReceive/sensorData").permitAll()
// 静态资源可匿名访问

View File

@ -65,7 +65,6 @@ public class IpcBg4gszhp01tempdata extends BaseEntity
private String WData;
/** 版本号 */
// TODO 待确认参数名称
@Excel(name = "版本号")
@JsonProperty(value="Ver")
private String Ver;

View File

@ -0,0 +1,80 @@
package com.inspur.ipc.domain;
import com.inspur.common.annotation.Excel;
import com.inspur.common.core.domain.BaseEntity;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
/**
* 传感器升级文件对象 ipc_sensor_update_file
*
* @author zhanghan11
* @date 2024-08-12
*/
public class IpcSensorUpdateFile extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 主键 */
private Long id;
/** 版本号 */
@Excel(name = "版本号")
private String ver;
/** 文件路径 */
@Excel(name = "文件路径")
private String path;
/** 是否删除 */
private String delFlag;
public void setId(Long id)
{
this.id = id;
}
public Long getId()
{
return id;
}
public void setVer(String ver)
{
this.ver = ver;
}
public String getVer()
{
return ver;
}
public void setPath(String path)
{
this.path = path;
}
public String getPath()
{
return path;
}
public void setDelFlag(String delFlag)
{
this.delFlag = delFlag;
}
public String getDelFlag()
{
return delFlag;
}
@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
.append("id", getId())
.append("ver", getVer())
.append("path", getPath())
.append("remark", getRemark())
.append("createTime", getCreateTime())
.append("delFlag", getDelFlag())
.toString();
}
}

View File

@ -0,0 +1,68 @@
package com.inspur.ipc.mapper;
import java.util.List;
import com.inspur.ipc.domain.IpcSensorUpdateFile;
/**
* 传感器升级文件Mapper接口
*
* @author zhanghan11
* @date 2024-08-12
*/
public interface IpcSensorUpdateFileMapper
{
/**
* 查询最新传感器升级文件
*
* @return 传感器升级文件
*/
public IpcSensorUpdateFile selectLastestIpcSensorUpdateFile();
/**
* 查询传感器升级文件
*
* @param id 传感器升级文件主键
* @return 传感器升级文件
*/
public IpcSensorUpdateFile selectIpcSensorUpdateFileById(Long id);
/**
* 查询传感器升级文件列表
*
* @param ipcSensorUpdateFile 传感器升级文件
* @return 传感器升级文件集合
*/
public List<IpcSensorUpdateFile> selectIpcSensorUpdateFileList(IpcSensorUpdateFile ipcSensorUpdateFile);
/**
* 新增传感器升级文件
*
* @param ipcSensorUpdateFile 传感器升级文件
* @return 结果
*/
public int insertIpcSensorUpdateFile(IpcSensorUpdateFile ipcSensorUpdateFile);
/**
* 修改传感器升级文件
*
* @param ipcSensorUpdateFile 传感器升级文件
* @return 结果
*/
public int updateIpcSensorUpdateFile(IpcSensorUpdateFile ipcSensorUpdateFile);
/**
* 删除传感器升级文件
*
* @param id 传感器升级文件主键
* @return 结果
*/
public int deleteIpcSensorUpdateFileById(Long id);
/**
* 批量删除传感器升级文件
*
* @param ids 需要删除的数据主键集合
* @return 结果
*/
public int deleteIpcSensorUpdateFileByIds(Long[] ids);
}

View File

@ -0,0 +1,68 @@
package com.inspur.ipc.service;
import java.util.List;
import com.inspur.ipc.domain.IpcSensorUpdateFile;
/**
* 传感器升级文件Service接口
*
* @author zhanghan11
* @date 2024-08-12
*/
public interface IIpcSensorUpdateFileService
{
/**
* 查询最新传感器升级文件
*
* @return 传感器升级文件
*/
public IpcSensorUpdateFile selectLastestIpcSensorUpdateFile();
/**
* 查询传感器升级文件
*
* @param id 传感器升级文件主键
* @return 传感器升级文件
*/
public IpcSensorUpdateFile selectIpcSensorUpdateFileById(Long id);
/**
* 查询传感器升级文件列表
*
* @param ipcSensorUpdateFile 传感器升级文件
* @return 传感器升级文件集合
*/
public List<IpcSensorUpdateFile> selectIpcSensorUpdateFileList(IpcSensorUpdateFile ipcSensorUpdateFile);
/**
* 新增传感器升级文件
*
* @param ipcSensorUpdateFile 传感器升级文件
* @return 结果
*/
public int insertIpcSensorUpdateFile(IpcSensorUpdateFile ipcSensorUpdateFile);
/**
* 修改传感器升级文件
*
* @param ipcSensorUpdateFile 传感器升级文件
* @return 结果
*/
public int updateIpcSensorUpdateFile(IpcSensorUpdateFile ipcSensorUpdateFile);
/**
* 批量删除传感器升级文件
*
* @param ids 需要删除的传感器升级文件主键集合
* @return 结果
*/
public int deleteIpcSensorUpdateFileByIds(Long[] ids);
/**
* 删除传感器升级文件信息
*
* @param id 传感器升级文件主键
* @return 结果
*/
public int deleteIpcSensorUpdateFileById(Long id);
}

View File

@ -0,0 +1,104 @@
package com.inspur.ipc.service.impl;
import java.util.List;
import com.inspur.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.inspur.ipc.mapper.IpcSensorUpdateFileMapper;
import com.inspur.ipc.domain.IpcSensorUpdateFile;
import com.inspur.ipc.service.IIpcSensorUpdateFileService;
/**
* 传感器升级文件Service业务层处理
*
* @author zhanghan11
* @date 2024-08-12
*/
@Service
public class IpcSensorUpdateFileServiceImpl implements IIpcSensorUpdateFileService
{
@Autowired
private IpcSensorUpdateFileMapper ipcSensorUpdateFileMapper;
/**
* 查询最新传感器升级文件
*
* @return 传感器升级文件
*/
@Override
public IpcSensorUpdateFile selectLastestIpcSensorUpdateFile(){
return ipcSensorUpdateFileMapper.selectLastestIpcSensorUpdateFile();
}
/**
* 查询传感器升级文件
*
* @param id 传感器升级文件主键
* @return 传感器升级文件
*/
@Override
public IpcSensorUpdateFile selectIpcSensorUpdateFileById(Long id)
{
return ipcSensorUpdateFileMapper.selectIpcSensorUpdateFileById(id);
}
/**
* 查询传感器升级文件列表
*
* @param ipcSensorUpdateFile 传感器升级文件
* @return 传感器升级文件
*/
@Override
public List<IpcSensorUpdateFile> selectIpcSensorUpdateFileList(IpcSensorUpdateFile ipcSensorUpdateFile)
{
return ipcSensorUpdateFileMapper.selectIpcSensorUpdateFileList(ipcSensorUpdateFile);
}
/**
* 新增传感器升级文件
*
* @param ipcSensorUpdateFile 传感器升级文件
* @return 结果
*/
@Override
public int insertIpcSensorUpdateFile(IpcSensorUpdateFile ipcSensorUpdateFile)
{
ipcSensorUpdateFile.setCreateTime(DateUtils.getNowDate());
return ipcSensorUpdateFileMapper.insertIpcSensorUpdateFile(ipcSensorUpdateFile);
}
/**
* 修改传感器升级文件
*
* @param ipcSensorUpdateFile 传感器升级文件
* @return 结果
*/
@Override
public int updateIpcSensorUpdateFile(IpcSensorUpdateFile ipcSensorUpdateFile)
{
return ipcSensorUpdateFileMapper.updateIpcSensorUpdateFile(ipcSensorUpdateFile);
}
/**
* 批量删除传感器升级文件
*
* @param ids 需要删除的传感器升级文件主键
* @return 结果
*/
@Override
public int deleteIpcSensorUpdateFileByIds(Long[] ids)
{
return ipcSensorUpdateFileMapper.deleteIpcSensorUpdateFileByIds(ids);
}
/**
* 删除传感器升级文件信息
*
* @param id 传感器升级文件主键
* @return 结果
*/
@Override
public int deleteIpcSensorUpdateFileById(Long id)
{
return ipcSensorUpdateFileMapper.deleteIpcSensorUpdateFileById(id);
}
}

View File

@ -116,14 +116,12 @@ public class SysConfigServiceImpl implements ISysConfigService
*/
@Override
public Map<String,Object> selectSharedKeys(){
Map<String,Object> parameter = new HashMap<>();
Map<String,Object> returnMap = new HashMap<>();
Map<String,Object> map = new HashMap<>();
map.put("time",Integer.parseInt(selectConfigByKey("shared.time")));
map.put("otaflag",selectConfigByKey("shared.otaflag"));
map.put("ver",selectConfigByKey("shared.ver"));
parameter.put("parameter",map);
Map<String,Object> returnMap = new HashMap<>();
returnMap.put("shared",parameter);
returnMap.put("shared",map);
return returnMap;
}

View File

@ -0,0 +1,88 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.inspur.ipc.mapper.IpcSensorUpdateFileMapper">
<resultMap type="com.inspur.ipc.domain.IpcSensorUpdateFile" id="IpcSensorUpdateFileResult">
<result property="id" column="id"/>
<result property="ver" column="ver"/>
<result property="path" column="path"/>
<result property="remark" column="remark"/>
<result property="createTime" column="create_time"/>
<result property="delFlag" column="del_flag"/>
</resultMap>
<sql id="selectIpcSensorUpdateFileVo">
select id, ver, path, remark, create_time, del_flag
from ipc_sensor_update_file
</sql>
<select id="selectIpcSensorUpdateFileList" parameterType="com.inspur.ipc.domain.IpcSensorUpdateFile"
resultMap="IpcSensorUpdateFileResult">
<include refid="selectIpcSensorUpdateFileVo"/>
<where>
del_flag = '0'
<if test="ver != null and ver != ''">and ver like concat('%', #{ver}, '%')</if>
<if test="path != null and path != ''">and path = #{path}</if>
</where>
order by id desc
</select>
<select id="selectLastestIpcSensorUpdateFile" parameterType="Long" resultMap="IpcSensorUpdateFileResult">
<include refid="selectIpcSensorUpdateFileVo"/>
where del_flag = '0'
order by id desc limit 1
</select>
<select id="selectIpcSensorUpdateFileById" parameterType="Long" resultMap="IpcSensorUpdateFileResult">
<include refid="selectIpcSensorUpdateFileVo"/>
where id = #{id}
</select>
<insert id="insertIpcSensorUpdateFile" parameterType="com.inspur.ipc.domain.IpcSensorUpdateFile">
insert into ipc_sensor_update_file
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">id,</if>
<if test="ver != null">ver,</if>
<if test="path != null">path,</if>
<if test="remark != null">remark,</if>
<if test="createTime != null">create_time,</if>
<if test="delFlag != null">del_flag,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">#{id},</if>
<if test="ver != null">#{ver},</if>
<if test="path != null">#{path},</if>
<if test="remark != null">#{remark},</if>
<if test="createTime != null">#{createTime},</if>
<if test="delFlag != null">#{delFlag},</if>
</trim>
</insert>
<update id="updateIpcSensorUpdateFile" parameterType="com.inspur.ipc.domain.IpcSensorUpdateFile">
update ipc_sensor_update_file
<trim prefix="SET" suffixOverrides=",">
<if test="ver != null">ver = #{ver},</if>
<if test="path != null">path = #{path},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="delFlag != null">del_flag = #{delFlag},</if>
</trim>
where id = #{id}
</update>
<update id="deleteIpcSensorUpdateFileById" parameterType="Long">
update ipc_sensor_update_file
set del_flag='2'
where id = #{id}
</update>
<update id="deleteIpcSensorUpdateFileByIds" parameterType="String">
update ipc_sensor_update_file set del_flag='2' where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</update>
</mapper>

View File

@ -0,0 +1,44 @@
import request from '@/utils/request'
// 查询传感器升级文件列表
export function listSensorUpdateFile(query) {
return request({
url: '/ipc/sensorUpdateFile/list',
method: 'get',
params: query
})
}
// 查询传感器升级文件详细
export function getSensorUpdateFile(id) {
return request({
url: '/ipc/sensorUpdateFile/' + id,
method: 'get'
})
}
// 新增传感器升级文件
export function addSensorUpdateFile(data) {
return request({
url: '/ipc/sensorUpdateFile',
method: 'post',
data: data
})
}
// 修改传感器升级文件
export function updateSensorUpdateFile(data) {
return request({
url: '/ipc/sensorUpdateFile',
method: 'put',
data: data
})
}
// 删除传感器升级文件
export function delSensorUpdateFile(id) {
return request({
url: '/ipc/sensorUpdateFile/' + id,
method: 'delete'
})
}

View File

@ -8,6 +8,24 @@ import { blobValidate } from "@/utils/tzipc";
const baseURL = process.env.VUE_APP_BASE_API;
export default {
downloadUpdateFile(name) {
var url =
baseURL + "/ipc/sensorUpdateFile/download?fileName=" + encodeURI(name);
axios({
method: "get",
url: url,
responseType: "blob",
headers: { Authorization: "Bearer " + getToken() },
}).then(async (res) => {
const isLogin = await blobValidate(res.data);
if (isLogin) {
const blob = new Blob([res.data]);
this.saveAs(blob, decodeURI(res.headers["download-filename"]));
} else {
this.printErrMsg(res.data);
}
});
},
name(name, isDelete = true) {
var url =
baseURL +

View File

@ -0,0 +1,376 @@
<template>
<div class="app-container">
<el-form
:model="queryParams"
ref="queryForm"
size="small"
:inline="true"
v-show="showSearch"
label-width="68px"
>
<el-form-item
label="版本号"
prop="ver"
>
<el-input
v-model="queryParams.ver"
placeholder="请输入版本号"
clearable
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item>
<el-button
type="primary"
icon="el-icon-search"
size="mini"
@click="handleQuery"
>搜索</el-button>
<el-button
icon="el-icon-refresh"
size="mini"
@click="resetQuery"
>重置</el-button>
</el-form-item>
</el-form>
<el-row
:gutter="10"
class="mb8"
>
<el-col :span="1.5">
<el-button
type="primary"
plain
icon="el-icon-plus"
size="mini"
@click="handleAdd"
v-hasPermi="['ipc:sensorUpdateFile:add']"
>新增</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="success"
plain
icon="el-icon-edit"
size="mini"
:disabled="single"
@click="handleUpdate"
v-hasPermi="['ipc:sensorUpdateFile:edit']"
>修改</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="danger"
plain
icon="el-icon-delete"
size="mini"
:disabled="multiple"
@click="handleDelete"
v-hasPermi="['ipc:sensorUpdateFile:remove']"
>删除</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="warning"
plain
icon="el-icon-download"
size="mini"
@click="handleExport"
v-hasPermi="['ipc:sensorUpdateFile:export']"
>导出</el-button>
</el-col>
<right-toolbar
:showSearch.sync="showSearch"
@queryTable="getList"
></right-toolbar>
</el-row>
<el-table
v-loading="loading"
:data="sensorUpdateFileList"
@selection-change="handleSelectionChange"
>
<el-table-column
type="selection"
width="55"
align="center"
/>
<el-table-column
label="版本号"
align="center"
prop="ver"
width="300"
show-overflow-tooltip
/>
<!-- <el-table-column
label="文件路径"
align="center"
prop="path"
show-overflow-tooltip
/> -->
<el-table-column
label="备注"
align="center"
prop="remark"
show-overflow-tooltip
/>
<el-table-column
label="操作"
align="center"
class-name="small-padding fixed-width"
>
<template slot-scope="scope">
<el-button
size="mini"
type="text"
icon="el-icon-edit"
@click="handleUpdate(scope.row)"
v-hasPermi="['ipc:sensorUpdateFile:edit']"
>修改</el-button>
<el-button
size="mini"
type="text"
icon="el-icon-delete"
@click="handleDelete(scope.row)"
v-hasPermi="['ipc:sensorUpdateFile:remove']"
>删除</el-button>
<el-button
size="mini"
type="text"
icon="el-icon-download"
@click="handleDownload(scope.row)"
v-hasPermi="['ipc:sensorUpdateFile:edit']"
>下载</el-button>
</template>
</el-table-column>
</el-table>
<pagination
v-show="total>0"
:total="total"
:page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize"
@pagination="getList"
/>
<!-- 添加或修改传感器升级文件对话框 -->
<el-dialog
:title="title"
:visible.sync="open"
width="500px"
append-to-body
>
<el-form
ref="form"
:model="form"
:rules="rules"
label-width="80px"
>
<el-form-item
label="版本号"
prop="ver"
>
<el-input
v-model="form.ver"
placeholder="请输入版本号"
/>
</el-form-item>
<el-form-item label="文件路径">
<file-upload
:fileType="fileType"
v-model="form.path"
/>
</el-form-item>
<el-form-item
label="备注"
prop="remark"
>
<el-input
v-model="form.remark"
type="textarea"
placeholder="请输入内容"
/>
</el-form-item>
</el-form>
<div
slot="footer"
class="dialog-footer"
>
<el-button
type="primary"
@click="submitForm"
> </el-button>
<el-button @click="cancel"> </el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import {
listSensorUpdateFile,
getSensorUpdateFile,
delSensorUpdateFile,
addSensorUpdateFile,
updateSensorUpdateFile,
} from "@/api/ipc/sensorUpdateFile";
export default {
name: "SensorUpdateFile",
data() {
return {
fileType: ["bin"],
//
loading: true,
//
ids: [],
vers: [],
//
single: true,
//
multiple: true,
//
showSearch: true,
//
total: 0,
//
sensorUpdateFileList: [],
//
title: "",
//
open: false,
//
queryParams: {
pageNum: 1,
pageSize: 10,
ver: null,
path: null,
},
//
form: {},
//
rules: {
ver: [
{ required: true, message: "版本号不能为空", trigger: "blur" },
{ max: 100, message: "版本号长度不能大于50", trigger: "blur" },
],
remark: [{ max: 100, message: "备注长度不能大于100", trigger: "blur" }],
},
};
},
created() {
this.getList();
},
methods: {
/** 查询传感器升级文件列表 */
getList() {
this.loading = true;
listSensorUpdateFile(this.queryParams).then((response) => {
this.sensorUpdateFileList = response.rows;
this.total = response.total;
this.loading = false;
});
},
//
cancel() {
this.open = false;
this.reset();
},
//
reset() {
this.form = {
id: null,
ver: null,
path: null,
remark: null,
createTime: null,
delFlag: null,
};
this.resetForm("form");
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm("queryForm");
this.handleQuery();
},
//
handleSelectionChange(selection) {
this.ids = selection.map((item) => item.id);
this.vers = selection.map((item) => item.ver);
this.single = selection.length !== 1;
this.multiple = !selection.length;
},
/** 新增按钮操作 */
handleAdd() {
this.reset();
this.open = true;
this.title = "添加传感器升级文件";
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
const id = row.id || this.ids;
getSensorUpdateFile(id).then((response) => {
this.form = response.data;
this.open = true;
this.title = "修改传感器升级文件";
});
},
/** 下载按钮操作 */
handleDownload(row) {
this.$download.downloadUpdateFile(row.path);
},
/** 提交按钮 */
submitForm() {
this.$refs["form"].validate((valid) => {
if (valid) {
if (this.form.id != null) {
updateSensorUpdateFile(this.form).then((response) => {
this.$modal.msgSuccess("修改成功");
this.open = false;
this.getList();
});
} else {
addSensorUpdateFile(this.form).then((response) => {
this.$modal.msgSuccess("新增成功");
this.open = false;
this.getList();
});
}
}
});
},
/** 删除按钮操作 */
handleDelete(row) {
const ids = row.id || this.ids;
const vers = row.ver || this.vers;
this.$modal
.confirm('是否确认删除版本号为"' + vers + '"的传感器升级文件?')
.then(function () {
return delSensorUpdateFile(ids);
})
.then(() => {
this.getList();
this.$modal.msgSuccess("删除成功");
})
.catch(() => {});
},
/** 导出按钮操作 */
handleExport() {
this.download(
"ipc/sensorUpdateFile/export",
{
...this.queryParams,
},
`sensorUpdateFile_${new Date().getTime()}.xlsx`
);
},
},
};
</script>